# Include <iostream>
# Include <windows. h>
Using namespace std;
Class C;
C * g_pC = NULL;
Typedef void (* pFUN )();
# Pragma pack (push, 1)
// Structure to store the machine code
Struct Thunk
{
BYTE m_jmp; // op code of jmp instruction
DWORD m_relproc; // relative jmp
};
# Pragma pack (pop)
Class C
{
Public:
Thunk m_thunk;
Void Init (pFUN pFun, void * pThis)
{
// Op code of jump instruction
M_thunk.m_jmp = 0xe9;
// Address of the appripriate Function
M_thunk.m_relproc = (INT) pfun-(INT) This + sizeof (Thunk ));
Flushinstructioncache (getcurrentprocess (),
& M_thunk, sizeof (m_thunk ));
}
// This is Cour call back function
Static void callbackfun ()
{
C * Pc = g_pc;
// Initilize the thunk
PC-> Init (StaticFun, pC );
// Get the address of thunk code
PFUN pFun = (pFUN) & (pC-> m_thunk );
// Start executing thunk code which will call StaticFun
PFun ();
Cout <"C: CallBackFun" <endl;
}
Static void StaticFun ()
{
Cout <"C: StaticFun" <endl;
}
};
Int main ()
{
C objC;
G_pC = & objC;
C: CallBackFun ();
Return 0;
}
Execution result:
C: StaticFun
C: CallBackFun
Keep the code in question and try again later!