Raised This Month: $ Target: $400
 0% 

Virtual Functions & Symbol Tables


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Psi
Junior Member
Join Date: Aug 2009
Old 08-18-2009 , 22:59   Virtual Functions & Symbol Tables
Reply With Quote #1

Hi there,

maybe this is not directly sourcemm related but anyway i found something about virtual functions in AMWiki.

To use those funcs i need to know the offset of any specific function as described in http://wiki.alliedmods.net/CCSPlayer...Strike:_Source for example.

If I am not wrong those offsets may change after any srcds update so I would like to know HOW to find out these offsets.

...would be glad if anybody can help me.

greetz
Psi
Psi is offline
BAILOPAN
Join Date: Jan 2004
Old 08-18-2009 , 23:07   Re: Virtual Functions & Symbol Tables
Reply With Quote #2

You need to use a disassembler that can understand symbolic information, as well as a binary that has symbolic information available (Linux binaries usually do).

The ones on the wiki were generated by IDA using an IDA script in our source tree.
__________________
egg
BAILOPAN is offline
Psi
Junior Member
Join Date: Aug 2009
Old 08-19-2009 , 00:34   Re: Virtual Functions & Symbol Tables
Reply With Quote #3

Hi BAILOPAN,

thanks for the quick response. I have two last questions about that:

1) afaik, IDA is windows only, so the offsets i receive there are shifted by 1 in comparison to linux binaries, is that correct?

2) which file to disassemble? server.dll?

thanks for your help again

greetz
Psi

[edit]
ok, IDA is available for linux as well ;)

Disassembling "server.dll" i just get 4 exported routines, this can't be correct...

Last edited by Psi; 08-19-2009 at 00:42.
Psi is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 08-19-2009 , 01:11   Re: Virtual Functions & Symbol Tables
Reply With Quote #4

Nah, load up the server_i486.so in IDA. Once the file is analyzed you will be able to find the vtable... section and export those offsets.
Keeper is offline
Psi
Junior Member
Join Date: Aug 2009
Old 08-19-2009 , 01:20   Re: Virtual Functions & Symbol Tables
Reply With Quote #5

Hi Keeper,

thanks alot, I tried the windows version of IDA, I will test it with the linux one (if i find it).

greetz
Psi

[edit]
hmm, there seems to be no linux version of IDA although wikipedia says something different... any good DA for linux?

Last edited by Psi; 08-19-2009 at 01:22.
Psi is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 08-19-2009 , 01:36   Re: Virtual Functions & Symbol Tables
Reply With Quote #6

If you cant use windows, then install Wine. IDA is a windows only application.
__________________
CrimsonGT is offline
Psi
Junior Member
Join Date: Aug 2009
Old 08-19-2009 , 01:52   Re: Virtual Functions & Symbol Tables
Reply With Quote #7

now i know why i got confused...

IDA (a windows only DA) has to disassemle a linux shared object binary.
What i did not expect: it worked.

But now i have a new problem: i don't find a vtable. i get a list of exports that shows the addresses of the functions but not their offset. where is this ominous vtable display? neither "functions display" nor "exports" lead to a correct result OR - if they do - i have no idea on how to calculate the offset.

also the function names look a bit cryptic... no idea on how to find out the correct class::function names...

Last edited by Psi; 08-19-2009 at 01:54.
Psi is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 08-19-2009 , 08:32   Re: Virtual Functions & Symbol Tables
Reply With Quote #8

The function names get mangled so that
Code:
void class::func1 ( int a )
is different from
Code:
void class::func1 ( float a )
There is an option in IDA to demangle the names. Check the Options->Demangle Names dialog.

Then if you click in the "Names" window, you can type what you want to get to the symbol you want. Start typing `vtable for'CBaseCombatWeapon( or whatever class you want ). Once it shows up in the names area, double click on it. That will bring the code up in the IDA View-A window
Quote:
.data.rel.ro:00D826C0 ; `vtable for'CBaseCombatWeapon
Then you load up the script Bail was talking about and export that list to a text file. You can find the script here: http://hg.alliedmods.net/sourcemod-c...ls/ida_scripts ( URL might change due to updates in mercurial.

Load it from the File->IDC file... in the menu and click on the idc file you downloaded. A dialog should pop up that you can press one of two choices ... choose the one with the gear and it will ask you where you want to export to. That will produce the list like you saw on the wiki.
Keeper is offline
Psi
Junior Member
Join Date: Aug 2009
Old 08-19-2009 , 15:59   Re: Virtual Functions & Symbol Tables
Reply With Quote #9

Very nice explanation, many thanks.
Psi is offline
Psi
Junior Member
Join Date: Aug 2009
Old 08-19-2009 , 19:04   Re: Virtual Functions & Symbol Tables
Reply With Quote #10

Hm, maybe i'm doing something wrong, but the names window does not contain any entry beginning with "vtable". also a search within the code for "vtable" returns no results.

what's my mistake?

[EDIT]
Ok i found the mistake -.- After changing the demangling settings you have to refresh the names window (i never worked with IDA that intensively). Maybe it is a product of my demangling setup, but i had to search for `vtable` (the leading ` is the difference). Anyway i now got what i was searching for, thanks to everyone here helping me.

Greetz
Psi

Last edited by Psi; 08-19-2009 at 19:34.
Psi 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 02:39.


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