Raised This Month: $ Target: $400
 0% 

Dynamic detouring library


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
your-name-here
Member
Join Date: May 2007
Old 04-25-2010 , 21:23   Dynamic detouring library
Reply With Quote #1

Hey everyone,

I've been researching/working on a dynamic detouring library for the past few months.

Link here. It's windows only for now, until I can get it completely stable.

I've currently got it so someone can actually bind the library to any language they want. All he/she would need to do is inherit from ICallBack and provide an implementation of the required methods.

I've got a test_cdecl.cpp (test_thiscall.cpp coming sometime) on the repo if anyone wants to see some examples.

PS: I actually have this bound to python right now. I've been able to hook member functions of a class and modify their parameters.
PPS: I have no idea why my name switches on the repo, it's probably me being absent minded and forgetting to keep my name consistent across machines

Let me know what you guys think (/me looks at BAIL).

Last edited by your-name-here; 04-25-2010 at 21:33.
your-name-here is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 04-28-2010 , 11:12   Re: Dynamic detouring library
Reply With Quote #2

Forgive my ignorance, but does this mean you can dynamically call DECLARE_HOOK from a function, instead of having to globally declare it like CDetour?
You still call it globally in your test code, but your sentence about Python implies you can.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
your-name-here
Member
Join Date: May 2007
Old 04-28-2010 , 18:24   Re: Dynamic detouring library
Reply With Quote #3

Quote:
Originally Posted by DJ Tsunami View Post
Forgive my ignorance, but does this mean you can dynamically call DECLARE_HOOK from a function, instead of having to globally declare it like CDetour?
You still call it globally in your test code, but your sentence about Python implies you can.
DECLARE_HOOK was really a macro I wrote for making my life easier, so it's not a "function".

To answer your question, yes you can hook functions dynamically without hardcoding the prototypes for them. This can be done with any scripting language you can bind DynDetours to

You can block the function call and override the return value, or you can modify the parameters of the function and call the original. All dynamically without hardcoding

Last edited by your-name-here; 04-28-2010 at 18:32.
your-name-here is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 04-29-2010 , 02:52   Re: Dynamic detouring library
Reply With Quote #4

Did I mention I love you?
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-29-2010 , 10:56   Re: Dynamic detouring library
Reply With Quote #5

Quote:
Originally Posted by DJ Tsunami View Post
Did I mention I love you?
I agree with ツツ, I haven't played with sigscanning/detouring yet (it's high on my list), but this library looks very nice.

Good Job =D
__________________
asherkin is offline
raydanhk
New Member
Join Date: Sep 2005
Old 04-29-2010 , 10:42   Re: Dynamic detouring library
Reply With Quote #6

someone already start making this thing in sourcmod?
raydanhk is offline
BAILOPAN
Join Date: Jan 2004
Old 04-30-2010 , 04:07   Re: Dynamic detouring library
Reply With Quote #7

Quote:
Originally Posted by raydanhk View Post
someone already start making this thing in sourcmod?
generic interop and sourcepawn don't mix. the type system is too weak to do structure/class or pointer interop in any sane way. this is why bug 2616 is basically WONTFIX for now, despite SourceHook being able to generate hooks dynamically.

you're better off finding functions which you need to detour. if none need interop, then exposing dynamic API to scripts can win. otherwise, it's very complicated to get right.
__________________
egg

Last edited by BAILOPAN; 04-30-2010 at 04:21.
BAILOPAN is offline
your-name-here
Member
Join Date: May 2007
Old 04-30-2010 , 09:59   Re: Dynamic detouring library
Reply With Quote #8

Quote:
Originally Posted by BAILOPAN View Post
generic interop and sourcepawn don't mix. the type system is too weak to do structure/class or pointer interop in any sane way. this is why bug 2616 is basically WONTFIX for now, despite SourceHook being able to generate hooks dynamically.

you're better off finding functions which you need to detour. if none need interop, then exposing dynamic API to scripts can win. otherwise, it's very complicated to get right.
Ok fair enough BAIL. It's unfortunate that we have to resort to using x86, but I don't think there is any other way to detour. I couldn't manage to find a single detour library that was "dynamic" in this sense, so I took on the task of writing my own.

On a side note: If you've have any suggestions at all feel free to tell me.

@Tsunami:

Anyway, this was really a pet project of mine, and I was surprised I could even get anywhere with it. If anyone wants to use it in an extension, you are free to do so. I'd love to hear what you do with it.

The only problem I've got right now is I haven't even begun to test this on Linux yet

Thanks for the comments so far guys.

EDIT: I've been reading through bug 2616. You've got some great discussion going on there BAIL. It shows that I need to put more thought into how I'm engineering my library.

Last edited by your-name-here; 04-30-2010 at 10:22.
your-name-here is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 04-30-2010 , 05:31   Re: Dynamic detouring library
Reply With Quote #9

I came across Orpheu recently though, which seems to make dynamic hooking possible for AMX Mod X. Unfortunately that code just made my head spin. Now I know Source is not the same as GoldSrc, but it still seems to be possible. Indeed the question remains if that's a sane way of doing it.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-04-2010 , 03:38   Re: Dynamic detouring library
Reply With Quote #10

Quote:
Originally Posted by DJ Tsunami View Post
I came across Orpheu recently though, which seems to make dynamic hooking possible for AMX Mod X. Unfortunately that code just made my head spin. Now I know Source is not the same as GoldSrc, but it still seems to be possible. Indeed the question remains if that's a sane way of doing it.
Ignore the code, the concept is easy. A base class that defines the virtual functions related to convert "between a C++ type and a pawn type" and vice versa. Implemented in a class per type for types like CBaseEntity, entvars_s, edict, "string", etc. Then, depending on how the function is described in a file, an array of objects of each type is created like:

Code:
[0] = CBaseEntity object
[1] = String object
[2] = Float object
Then, with inline assembly code (so functions can be given a variable number of arguments) the array is iterated to convert from pawn to C++ or vice-versa and pass them from plugin to module or vice-versa.

The bigger problems that I had were creating the code to handle all types because float por example uses different processor registers so I had to do some stuff and strings are returned by reference, etc. But I had no prior assembly and C++ experience (had C experience tough) so I know you can do it with less problems that I had (edit: if you do it, try to use this idea. I wish I had it before making it since now it's a pain to make all over again)

I don't know how sourcepawn or sourcemod works but I guess you can apply the same concept to it.

About what David Bailopan said, don't be scared. What he is saying is that since he produces base tools they have to be under solid grounds (like, when having errors failing the sooner possible) and this concept can never be that solid per se (from the few I know). But in the end a tool like this is for more experienced users so the unsafeness is not a big problem. And since what it let's people do can't be achieved otherwise is nice to have it and the approved plugins using it are the proof of that (And two that bailopan banned ).

To end this post, sorry for making it so long but it's the first time I talked about this with someone that has more knowledge than me with this stuff and I didn't send this as PM because I hope that someone might give me some insight of how I can improve the stuff I did using another concept for example (namely, the thread author).

Note to Bailopan: In the Modules section there are many modules stickied less useful than Orpheu.
__________________

Last edited by joaquimandrade; 05-04-2010 at 03:48.
joaquimandrade 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:20.


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