Exetools

Exetools (https://forum.exetools.com/index.php)
-   General Discussion (https://forum.exetools.com/forumdisplay.php?f=2)
-   -   C++ Help (Hooking a function) (https://forum.exetools.com/showthread.php?t=5172)

Peter[Pan] 08-30-2004 18:44

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 :)

Sergey Nameless 08-30-2004 21:53

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

next7 08-31-2004 00:49

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?

Peter[Pan] 08-31-2004 01:43

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.

GrosTuba 08-31-2004 16:17

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

LaDidi 08-31-2004 17:04

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 !

Peter[Pan] 08-31-2004 18:58

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 :)

ReDucTor 08-31-2004 19:02

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)

Peter[Pan] 08-31-2004 20:37

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 :)


All times are GMT +8. The time now is 14:27.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX