I just doing my first steps with madCodeHook and want to write a own small application. Inside this project I want to convert an existing and functioning Hook-DLL from C to Delphi. But there is an failure in my code, which I can't find. The target application which uses the hooked-DLL crashes imedeatly, whenn I start my own application. Here is the code of original hook-library
Code: Select all
void* g_pDataBlockToMessage = NULL;
// ?DataBlockToMessage@@YAPAVMessage_t@@IPAX@Z
// is named DataBlockToMessage, returns a Message_t*,
// and takes an int and a void* as parameters.
//Message_t is actually a unknown class
// But just to define a pointer on it,
// we don't need to know what it is.
typedef void Message_t;
Message_t* ( * pOriginalDataBlockToMessage )( int _Size, void* _pDataBlock );
Message_t* DataBlockToMessageHook( int _Size, void* _pDataBlock )
{
/// Do something with the data.......
return pOriginalDataBlockToMessage( _Size, _pDataBlock );
}
Code: Select all
sucess:=InjectLibrary(ALL_SESSIONS or SYSTEM_PROCESSES, 'Hook.dll');
Code: Select all
OriginalDataBlockToMessage : function (size: Integer; datablock: Pointer) :Pointer; cdecl;
function DataBlockToMessageHook(size : Integer; datablock: Pointer) :Pointer; stdcall;
begin
// Do something with the data..... (e.g. write to file)
result:=OriginalDataBlockToMessage(size,datablock);
end;
begin
HookAPI('path_to_dll','?DataBlockToMessage@@YAPAVMessage_t@@IPAX@Z',@DataBlockToMessageHook,@OriginalDataBlockToMessage);
end.