Hooking function, log file shows garbage

c++ / delphi package - dll injection and api hooking
Post Reply
PInvoke
Posts: 25
Joined: Sun Jan 16, 2005 4:32 am

Hooking function, log file shows garbage

Post by PInvoke »

Hi,
I have the following:

Code: Select all

function GetIncomingMessageCallBack(pSrc: Pointer; szMsg: PChar): boolean; cdecl;
var
  MyMsg: PChar;
begin

  Result := GetIncomingMessageNext(pSrc,szMsg);
  GetMem(MyMsg,StrLen(szMsg));
  try
    CopyMemory(MyMsg,szMsg,StrLen(szMsg));
    WriteLog(MyMsg);
  finally
    FreeMem(MyMsg);
  end;
end;
When i look at the log file i'm writing to i get the following:

Code: Select all

〰ⰸ潃湮捥楴湯攠瑳扡楬桳摥ฬ漀湮捥楴湯攠瑳扡楬桳摥 㠰〬㄰䔬〬䰬ㄬ㌲ⰴⱈ摫湵慬㉰唬欬畤汮灡ㄬ㈬㌬ⰬⰬⰬⰬⰬⰬⰬ〰ⰸ〱ⰷⱅⰰⱌ㈱㐳䠬欬畤汮灡ⰲⱕ摫湵慬Ɒ 㠰ㄬ㠰䔬〬䰬ㄬ㌲ⰴⱈ摫湵慬㉰唬欬畤汮灡,〰ⰸ〰ⰷⱅⰰⱌ㈱㐳䠬欬畤汮灡ⰲⱕ摫湵慬Ɒ 㠰〬㔰䔬〬䰬ㄬ㌲ⰴⱈ摫湵慬㉰唬欬畤汮灡䤬ㄬ㌲㔴㜶㤸㔶㌴ㄲㄬ㈬㌬ⰬⰬⰬⰬⰬⰬⰬ 㠰〬㈰䔬〬䰬ㄬ㌲ⰴⱈ摫湵慬㉰唬欬畤汮灡ㄬ㈬㌬ⰬⰬⰬⰬⰬⰬⰬ〰ⰸ潃湮捥楴湯挠潬敳Ɽ漀湮捥楴湯䌠潬敳⁤3
Where the log file should be similar to: 3343,Connection established



Here is the actual C++ function:

Code: Select all

__declspec(dllexport) BOOL GetIncomingMessageEx(void* pSrc, char* szMsg)
Any ideas what might be happening?
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Some comments:

(1) boolean is 1 byte, bool is 4 byte.

(2) Why doing it so complicated? Just do "WriteLog(szMsg);" and get rid of MyMsg.

(3) No idea why the log contains trash. Maybe the log function is bad? Try "WriteLog('test');". Does that work correctly?
Post Reply