Busti Posted August 19, 2007 Share Posted August 19, 2007 (edited) Hi all, i need some help at rewriting a C++ function, i hope you can help me this time again. expandcollapse popupVOID AxlDetourFunction( LPVOID F, /// function to detour LPVOID H, /// my new function LPVOID* pG) /// old function { LPVOID pv; DWORD dw, ul; MEMORY_BASIC_INFORMATION mbi; /// find out about F's segment VirtualQuery(F,&mbi,sizeof(mbi)); /// allocate a new writable segment pv = VirtualAlloc(NULL,mbi.RegionSize, MEM_COMMIT,PAGE_READWRITE); /// copy F's segment to the new one MoveMemory(pv,mbi.BaseAddress,mbi.RegionSize); /// make the new segment read/exec-only VirtualProtect(pv,mbi.RegionSize, PAGE_EXECUTE_READ,&dw); /// the old function starts at the same offset /// in the new segment where it started in the old one *pG = (LPBYTE)pv + ((LPBYTE)F - (LPBYTE)mbi.BaseAddress); /// make F's segment writable VirtualProtect(mbi.BaseAddress,mbi.RegionSize, PAGE_EXECUTE_READWRITE,&dw); /// write the jump opcode ((LPBYTE)F)[0] = (BYTE)0xE9; /// calculate the jump offset ul = (LPBYTE)H - &((LPBYTE)F)[6]; /// write the jump offset (since there is no guarantee /// that the offset's DWORD is DWORD aligned, this is /// safer even if not really needed on modern CPUs) MoveMemory(((LPBYTE)F)[1],&ul,sizeof(ul)); /// protected F's segment as it was before VirtualProtect(mbi.BaseAddress, mbi.RegionSize,dw,&dw); } Edited August 19, 2007 by Busti My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
cppman Posted August 19, 2007 Share Posted August 19, 2007 First of all, why in the world would you need this in autoit? Miva OS Project Link to comment Share on other sites More sharing options...
Busti Posted August 19, 2007 Author Share Posted August 19, 2007 (edited) I have to hook a programm, and need the detours function, but i dont think somebody translatet them yet to autoit so i googled and found this Edited August 19, 2007 by Busti My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now