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

Portable Allpurpose Detour Class [Hooking Non-Virtual funcs]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vancelorgin
Senior Member
Join Date: Dec 2004
Location: san frandisco
Old 01-26-2006 , 15:22   Portable Allpurpose Detour Class [Hooking Non-Virtual funcs]
Reply With Quote #1

Dunno if I posted this earlier somewhere, dunno if SourceMM can do this yet, but what the hell, I'm here now.

This will hook, on x86, any function in your process space. It can be modified to work on linux with, again, just VirtualProtect translations. An example's included.

If you use this anywhere, just please give me credit for it. That's the only license.
Attached Files
File Type: zip cdetour.zip (15.8 KB, 331 views)
__________________
Avoid like the plague.
vancelorgin is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 01-26-2006 , 18:47  
Reply With Quote #2

There you are vance !

There are a few things I needed to ask you once upon a time, but when you said you didnt have much time I decided best not to ask.

Would you mind a pm if I can remember what they were ?
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 03-21-2006 , 01:33  
Reply With Quote #3

Ok, i have managed to incorporate it and get it to work.

But I have one feature which isn't currently available in this version.
The ability for different function types, void is all that is catered for.

If that was added, this would be one of the sickest classes I've ever seen =)
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
showdax
Senior Member
Join Date: Dec 2004
Old 03-21-2006 , 12:15  
Reply With Quote #4

Was there any reason all of those crazy win32 types were used instead of cross-platform types?

Also, MSVC8 absolutely blows up at your code. And when I compiled it with MSVC7 and ran it, DEP killed the program, though I guess that's to be expected.
showdax is offline
Send a message via MSN to showdax
BAILOPAN
Join Date: Jan 2004
Old 03-21-2006 , 17:24  
Reply With Quote #5

If you use VirtualAlloc properly you should be able to get around DEP.
__________________
egg
BAILOPAN is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 03-22-2006 , 09:07  
Reply With Quote #6

Meh, I got it to work fine. It wouldnt work as a stand alone project in MSVC without adding all the type definitions, but once I moved it into a S:MM project, Valve have already defined all those types.

So, right now im working on a version which takes a Template, much like CUtlVector, so the hooked functions can have a return type
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
vancelorgin
Senior Member
Join Date: Dec 2004
Location: san frandisco
Old 05-11-2006 , 13:57  
Reply With Quote #7

Glad to see people using it.

About all the win specific types, BYTE and the like, I had a reason, but I've long since forgotten. char* away.

As for the return types, it supports anything really. On x86's, the only real return value is passed in eax, so cast .Org to whatever you want, forcefully. entity* pEnt = (entity*)Det.Org(index); etc. As for functions that return full classes, that's obviously not merely stored in eax (usually a ptr to a class in the calling func's stack space to hold the return val is passed as an arg - disasm/debug there to make sure).

And the new visual studios have gotten less and less welcoming to my code. I guess they're trying to ween us off languages capable of writing a competing OS
__________________
Avoid like the plague.
vancelorgin is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 05-11-2006 , 17:40  
Reply With Quote #8

vance, i meant more a long the lines of returning to the engine.

I could successfully hook a function and not call the Orig() function, but if i called Orig() the engine crashed.

Ex: I was hooking CreateEntityByName as a quick test, when I called Orig() the engine errored with a "Cannot Create Entity with classname 'RANDOM SHITE HERE'" error.
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 05-29-2006 , 14:14  
Reply With Quote #9

Code:
CDetourDis.cpp: In member function `unsigned char* CDetourDis::CopyF6(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)':
CDetourDis.cpp:335: error: argument of type `unsigned char*(CDetourDis::)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)' does not match `unsigned char*(CDetourDis::*)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)'
CDetourDis.cpp:347: error: argument of type `unsigned char*(CDetourDis::)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)' does not match `unsigned char*(CDetourDis::*)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)'
CDetourDis.cpp: In member function `unsigned char* CDetourDis::CopyF7(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)':
CDetourDis.cpp:357: error: argument of type `unsigned char*(CDetourDis::)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)' does not match `unsigned char*(CDetourDis::*)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)'
CDetourDis.cpp:369: error: argument of type `unsigned char*(CDetourDis::)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)' does not match `unsigned char*(CDetourDis::*)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)'
CDetourDis.cpp: In member function `unsigned char* CDetourDis::CopyFF(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)':
CDetourDis.cpp:397: error: argument of type `unsigned char*(CDetourDis::)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)' does not match `unsigned char*(CDetourDis::*)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)'
CDetourDis.cpp: At global scope:
CDetourDis.cpp:681: error: argument of type `unsigned char*(CDetourDis::)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)' does not match `unsigned char*(CDetourDis::*)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)'
CDetourDis.cpp:942: error: argument of type `unsigned char*(CDetourDis::)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)' does not match `unsigned char*(CDetourDis::*)(const CDetourDis::COPYENTRY*, unsigned char*, unsigned char*)'
These are the last couple of errors Im left with while converting to work on linux.
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
para
New Member
Join Date: May 2006
Old 05-30-2006 , 15:37  
Reply With Quote #10

Normally I would never dream of writing a post like this, and I hope Bail doesn't blow up on me ( ), but for those interested I thought I'd say something.

I've recently taken the time to write a generic non-virtual function hooker from scratch, inspired by the interesting concept of SourceHook.

Likewise, I've researched Detours a bit, and the Intel x86 instruction set documentation, and I feel I've come up with a solution similar to SH -- by that I mean a system of hooking a single function several times, and handling invocation with an internal function pointer list.

I don't write HL2 mods so I don't know how well or how crappy it will work in conjunction with SourceHook (it seems to be a desired thing though), so it may be interesting to see how well it pans out.

Since this was really just my personal research project, it may or may not be further developed, but I hope it will be of use to someone.

It is meant to be loaded as a DLL and used as a normal library would, so there is one header to include and one .c to link with a project using it. I thought this might be the easiest way of including it in a project given the limitations of the compiliation issues (it did require some ridiculous assembly hacks).

Released under the GPL at http://uhook.net
__________________
para 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 19:27.


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