Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 08-30-2004, 18:44
Peter[Pan]
 
Posts: n/a
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 ) )
{

}
Now, i want to hook the NotifyOnline with my own function so i define.

Code:
typedef void (*NotifyOnlineOrig)(DATE *,int);
and my function:
Code:
void NotifyOnlineNew ( DATE *pDate, int ChkSum)
{
     NotifyOnlineOrig(pDate,ChkSum);
}
and try this inside the function.
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;
}
of course the = parts dont work, how can i achive this, (its not a real sdk, so plz dont ask)

Thanks
Reply With Quote
  #2  
Old 08-30-2004, 21:53
Sergey Nameless
 
Posts: n/a
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
Reply With Quote
  #3  
Old 08-31-2004, 00:49
next7
 
Posts: n/a
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?
Reply With Quote
  #4  
Old 08-31-2004, 01:43
Peter[Pan]
 
Posts: n/a
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.
Reply With Quote
  #5  
Old 08-31-2004, 16:17
GrosTuba
 
Posts: n/a
A typedef problem, maybe...

Hi

When you write
Code:
typedef void (*NotifyOnlineOrig)(DATE *,int);
, you are defining a type that is then recognized by the compiler, you are not declaring a variable at all.

You may try something like
Code:
typedef void (*t_NotifyOnlineOrig)(DATE *,int);
t_NotifyOnlineOrig NotifyOnlineOrig;
This way, you define a type AND a variable of this type that can be used to store a pointer to the old Notify routine. Of course, you may have to add or remove a few pointer indirections, but the basic idea is here...

Have a nice day

Tuba
Reply With Quote
  #6  
Old 08-31-2004, 17:04
LaDidi LaDidi is offline
VIP
 
Join Date: Aug 2004
Posts: 211
Rept. Given: 2
Rept. Rcvd 11 Times in 10 Posts
Thanks Given: 47
Thanks Rcvd at 41 Times in 24 Posts
LaDidi Reputation: 11
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 !
Reply With Quote
  #7  
Old 08-31-2004, 18:58
Peter[Pan]
 
Posts: n/a
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. ) 
{

}
Thanks for all the help
Reply With Quote
  #8  
Old 08-31-2004, 19:02
ReDucTor
 
Posts: n/a
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)
Reply With Quote
  #9  
Old 08-31-2004, 20:37
Peter[Pan]
 
Posts: n/a
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;
1000+ Thank You's
Reply With Quote
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 Off
HTML code is Off


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


All times are GMT +8. The time now is 02:34.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )