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

Solved Calling constructors from server binary?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nosoop
Veteran Member
Join Date: Aug 2014
Old 03-21-2018 , 09:53   Calling constructors from server binary?
Reply With Quote #1

Hey there.
I'm trying to experiment with hooking some NextBot-related function calls in TF2 (and figuring out C++ in the process).

Right now I have a hook on a function CTFBotScenarioMonitor::DesiredScenarioAndClassAction, which expects a return type Action<CTFBot>. I'd like to return an instance of one of the other actions present in the game.

Is there a way to manually get the size of a class, or to instantiate an instance of that class without an explicit size declaration? I'm able to allocate memory and call the ctor of something like CTFBotSeekAndDestroy, but so far I'm manually inputting the amount to allocate based on existing references. Was wondering if there were any other approaches (or something available to extensions that I didn't find).

Thanks!
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 03-22-2018 at 22:37. Reason: added a question mark to the title
nosoop is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 03-21-2018 , 12:57   Re: Calling constructors from server binary?
Reply With Quote #2

The compiler would have the definition of the class and so would know the size whenever you construct one. If you look at the disassembly for an object constructed on the heap, you'll see a call to new with its size (unless it's placement new, I guess).

I guess you could try to sigscan for a call to new that you know is for a class you want to get the size at runtime. I don't really have any other ideas besides maintaining your own definition of the class.
Fyren is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 03-22-2018 , 22:37   Re: Calling constructors from server binary?
Reply With Quote #3

Yeah, that makes sense.

IDA's free offering seems to be sufficient in finding cross references to constructor calls, and it looks like the call to new is being made. (I'm not too concerned about non-Linux platforms at the moment.)

Creating my own class definitions for these classes is a little too complicated for me at the moment (for a full recreation anyways, I have some classes declared with bytes padded), so this will do. Thanks for the help!
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 03-22-2018 at 23:40.
nosoop is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 03-23-2018 , 14:31   Re: Calling constructors from server binary?
Reply With Quote #4

Creating your own definition can make accessing members easier since you wouldn't have to do any pointer math/casting yourself. You would only need to fill it in so the size is correct and the placement of any members you care about are correct. class Foo { char pad[36]; int intICareAbout; char pad2[16]; } for example.
Fyren is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 03-24-2018 , 01:56   Re: Calling constructors from server binary?
Reply With Quote #5

Got it. At the moment I don't need access to member variables, but I'll probably take advantage of it if / when the project's more fleshed out (probably when I leverage sigsegv's reverse engineering work).
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
Reply


Thread Tools
Display Modes

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:24.


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