Raised This Month: $51 Target: $400
 12% 

[TS] Finding offsets with IDA?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Infest
Member
Join Date: Mar 2005
Old 09-19-2016 , 22:57   [TS] Finding offsets with IDA?
Reply With Quote #1

I have read some information about this subject here: https://wiki.alliedmods.net/Finding_Virtual_Offsets

For example, I want to be able to find the offset of TSSpace (Slots). I already indirectly know I can set this value with:
PHP Code:
set_pdata_int(id33386// id, offset, slots 
But I want to find out how I can determine the offset is 333 for myself, so I can then understand how to find different offsets.

I am not sure if I am on the right path or not, but I load mp.dll with IDA, find 'aTsspace' in the names window, and load graph view:
http://i.imgur.com/HaaS3xI.png

I have attached mp.dll in case it is required.
Attached Files
File Type: dll mp.dll (748.0 KB, 216 views)

Last edited by Infest; 09-19-2016 at 22:57.
Infest is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-20-2016 , 01:52   Re: [TS] Finding offsets with IDA?
Reply With Quote #2

Good question, would be nice if somebody will explain in more details about this ( maybe even make a small tuto )
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-20-2016 , 08:32   Re: [TS] Finding offsets with IDA?
Reply With Quote #3

Seems like pahole can extract quite a bit of data, but you'll need Linux (boot to one, use a virtual machine or use LSW on Windows 10).

First download the package containing pahole:
Code:
sudo apt-get install dwarfs
(use package manager that your distro uses)

And then execute it as such:
Code:
pahole --nr_members --show_only_data_members --rel_offset --class_name CBasePlayer cs.so > CBasePlayer.txt
This is sample output:
Spoiler


Remember that most fakemeta pdata functions aren't byte-addressable, meaning that you should divide the offset by 4 to use it properly.
So for example, for m_idrowndmg that is 1400 in pahole's output, you should use 1400 / 4 = 350 (-5 for Windows in this case, it depends on the class, so experiment with it) in pdata natives.
klippy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-20-2016 , 08:59   Re: [TS] Finding offsets with IDA?
Reply With Quote #4

TS 3.0 doesn't have any DWARF informations unfortunately.
__________________
Arkshine is offline
Infest
Member
Join Date: Mar 2005
Old 09-20-2016 , 10:11   Re: [TS] Finding offsets with IDA?
Reply With Quote #5

Thanks KliPPy, even if this cannot gather offsets for TS I'm sure people will still find your information useful.

Quote:
Originally Posted by Arkshine View Post
TS 3.0 doesn't have any DWARF informations unfortunately.
Drats. Is there a method of getting these offsets for TS?
Infest is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-20-2016 , 10:26   Re: [TS] Finding offsets with IDA?
Reply With Quote #6

You should always try to open the linux binary in IDA first, because generally, it contains the functions symbols and if you're lucky some debug information.
EDIT: As KliPPy said, if you know the binary contains DWARF informations, then you should use pahole.

TSSpace is a game event. I did not understand at first why you were talking about an offset but I got it once you check out the references.

Usually, when you don't know where to look, you try to find reference of a string related to what you want to search.
Here, it's TSSpace, luckily it exists in the strings list:



Once you double-click on it, you see if there are references of it.
Here, there is only one reference in the LinkUserMessages() function.



Once you double-click on it, you will jump to the disassembled code from where it's referenced:



If you have the decompiler available, you can hit f5 and you will get a pseudo-C code, more easy to understand.
Note: It's possible to improve decompiler output by providing structures, I think there is a tuto about it.



At this point, if you don't understand what does this LinkUserMessages, you should always try to see if such function exists in the original HLSDK.
Here, you can find it: https://github.com/alliedmodders/hls....cpp#L193-L240
You understand this function is about registering game events and save an handle into a global variable, here gmsgTSSpace.
A game message looks like this (begin + arguments + end):
Code:
MESSAGE_BEGIN(MSG_ONE, gmsgScoreInfo, NULL, edict());
	WRITE_BYTE(i);
	WRITE_SHORT(static_cast<int>(pev->frags));
	WRITE_SHORT(m_iDeaths); // This is a member of class
	WRITE_SHORT(pev->team);
MESSAGE_END();
From that, what you want to do now, is to find reference of gmsgTSSpace, because you have likely a member of class used as argument that you want to retrieve its offset.

From the disassembled code, click on gmsgTSSpace_ptr to select it, then to get the references, you either hit the X key or you click right.
Note: Depending how it's compiled, you might get a pointer to a global variable. That's why you see "_ptr". If you try to get references from the decompiled output with gmsgTSSpace, it will give you gmsgTSSpace_ptr first, then you need to repeat the operation to get the actual references.





You get two references, one from where it's registered and the other where it's actually used.
Double-click on CBasePlayer::UpdateClientData().



Again, check on HLSDK how game messages are handled.
You can be sure TSSpace is handled similar to https://github.com/alliedmodders/hls...pp#L3977-L3984.

What you're looking for:
  • From the disassembled code, it's not easy if you don't have a bit of experience. You want ebp+54Ch and ebp+548h. You can click right (or hit H key) on the number to get the decimal value. The real byte-based offsets are 1352 and 1356. The int-based are 338 and 339 (int = 4 bytes usually, so you divide by 4).
  • From the decompiled code, it's much more easy. You see code is similar to the link above. You want *(this + 338) and *(this + 339). A class member offset will be always in the form *(base + offset). this is the object, a pointer to CBasePlayer class. You notice that the decompiled code gives already the int-based offset value, it's because IDA had already the information that this is a pointer of a class. If you want the byte-based offset, you can click right on this and select reset pointer type.

What you got is the linux offset.

Usually, for most of mods, from a windows-based offset to get the linux one, you would need to add some extra offset.
It's because of the pfn* members, like m_pfnThink which takes 8 bytes under linux.
You have 4 pfn defined in CBaseEntity: https://github.com/alliedmodders/hls...se.h#L210-L213
You have 1 pfn defined in CBaseAnimating: https://github.com/alliedmodders/hls...s/cbase.h#L528
This means any offset defined after m_pfnBlocked and any offsets of classes derivated from CBaseEntity, you need to add +16 (byte-based) or +4 (int-based).
This means any offset defined after m_pfnCallWhenMoveDone and any offsets of classes derivated from CBaseAnimating, you need to add +20 (bytečbased) or +5 (int-based).

In our situation, we're working with a player's offset. CBasePlayer is derivated from CBaseMonster > CBaseToggle > CBaseAnimating. This means +20 or +5.
Since we got the linux offset, the windows offset will be: 1352 - 20 = 1332 (or 338 - 5 = 333) and 1356 - 20 = 1336 (or 339 - 5 = 334).
Code:
                      windows      linux
m_iSomething        333 (1332)   338 (1352)
m_iClientSomething  334 (1336)   339 (1356)
Looking the decompiled code and HLSDK, you can imagine the code would looks like:

Code:
if (m_iSomething != m_iClientSomething)
{
	m_iClientSomething = m_iSomething;

	MESSAGE_BEGIN(MSG_ONE, gmsgTSSpace, NULL, pev);
		WRITE_BYTE(m_iSomething);
	MESSAGE_END();
}
There is likely thing you won't understand at first because not everything is explained properly, so don't hesitate to ask.
__________________

Last edited by Arkshine; 09-20-2016 at 10:39.
Arkshine is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-20-2016 , 10:37   Re: [TS] Finding offsets with IDA?
Reply With Quote #7

You can do the same under windows, but without symbols, you need to wild guess more, though it's pretty similar in our situation.
Here the steps in image only:













__________________

Last edited by Arkshine; 09-20-2016 at 10:40.
Arkshine is offline
Infest
Member
Join Date: Mar 2005
Old 09-21-2016 , 08:53   Re: [TS] Finding offsets with IDA?
Reply With Quote #8

Thanks Arkshine, very good information indeed. I will give this a go when I have some free time
Infest is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 08-07-2017 , 03:11   Re: [TS] Finding offsets with IDA?
Reply With Quote #9

KliPPy
I tried your way because it looked rather easy
But I do not get a result What is the problem?
Attached Thumbnails
Click image for larger version

Name:	offset.PNG
Views:	281
Size:	6.8 KB
ID:	164680  
__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-07-2017 , 04:55   Re: [TS] Finding offsets with IDA?
Reply With Quote #10

The output has been saved in CBasePlayer.txt.
__________________
Arkshine is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode