#1
|
|||
|
|||
C++ Help (Hooking a function)
Say i have the sdk of a application with such a function defined.
Code:
void Check_Registration ( int Registered, int Licenses, int LicenseType, int ChkSum, int RESERVEDA, int ( *Callback_CheckDate )( DATE *pDATE ), void ( *Callback_NotifyOnline)( DATE *pDate, int ChkSum ) ) { } Code:
typedef void (*NotifyOnlineOrig)(DATE *,int); Code:
void NotifyOnlineNew ( DATE *pDate, int ChkSum) { NotifyOnlineOrig(pDate,ChkSum); } Code:
void Check_Registration ( int Registered, int Licenses, int LicenseType, int ChkSum, int RESERVEDA, int ( *Callback_CheckDate )( DATE *pDATE ), void ( *Callback_NotifyOnline)( DATE *pDate, int ChkSum ) ) { NotifyOnlineOrig=Callback_NotifyOnline; Callback_NotifyOnline=NotifyOnlineNew; } Thanks |
#2
|
|||
|
|||
I may be wrong, but:
Callback_NotifyOnline passed by *, not **, so you can't modify it, if it would be ** you could do *Callback_NotifyOnline=NotifyOnlineNew |
#3
|
|||
|
|||
Is it the library that calls Check_Registration (to be filled by you)? Or is Check_Registration part of the library and should be called by your application code?
|
#4
|
|||
|
|||
Check_Registration is part of the application a function, and is being replaced hooked by me, so now i can use that function, so inside it i want to hook the callback one, but whatever i try doesnt seem to work for it.
Sergey Nameless: thanks it works for the latter but not filling the original part so i will have no way to call the original. |
#5
|
|||
|
|||
A typedef problem, maybe...
Hi
When you write Code:
typedef void (*NotifyOnlineOrig)(DATE *,int); You may try something like Code:
typedef void (*t_NotifyOnlineOrig)(DATE *,int); t_NotifyOnlineOrig NotifyOnlineOrig; Have a nice day Tuba |
#6
|
|||
|
|||
I think you can but...
If I understand, you want to hook the call of Check_Registration done by another ?
Check_Registration use a function pointer to a callback_function. So, inside its body, you have a call like : Callback_NotifyOnline ( , ); If this API is in a DLL (like its_SDK.dll) and if you want to hook this call : 1. you need to export the same API in your library (my_SDK.DLL) with the same protoype 2. call the old API inside your API (export OR LoadLibrary, GetProcAddress) 3. rename my_SDK to its_SDK and its_SDD to Original_SDK If this API isn't in a DLL ie resolved by compiler, you have the source so you can do anything ! |
#7
|
|||
|
|||
Yea like that, but i already have hooked Check_Registration, and inside the sdk they can use like you said: Callback_NotifyOnline();
now i want to hook also Callback_NotifyOnline();, but looking thru the sdk, its not defined nowhere except in the routine its self here: Code:
void Check_Registration ( int Registered, int Licenses, int LicenseType, int ChkSum, int RESERVEDA, int ( *Callback_CheckDate )( DATE *pDATE ), void ( *Callback_NotifyOnline)( DATE *pDate, int ChkSum ) // Only time its defined. ) { } |
#8
|
|||
|
|||
Is the function exported? If not you may have to find the address your self, by searching for certain fragments or memory or using the exact address/offset of it (how ever this can fail if the file gets changed)
|
#9
|
|||
|
|||
Solved! thanks, it was a combination of the multiple post here:
i ended up doing: Code:
Info Code: typedef void (*func_Callback_NotifyOnline)(DATE *,int); static func_Callback_NotifyOnline orig_Callback_NotifyOnline; Hook Code: orig_Callback_NotifyOnline = (func_Callback_NotifyOnline)0xMEMORYLOCATION; |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Windows Api Hooking | user1 | Source Code | 12 | 12-24-2022 09:57 |
API Hooking | thomasantony | General Discussion | 5 | 04-22-2005 11:44 |
API-hooking | MaRKuS-DJM | General Discussion | 11 | 03-25-2005 13:27 |