log.txt: some of the text is correct, other - trash (attached picture - text from standart control TEdit), why?
Help me please!!!
Code: Select all
library hook;
{$IMAGEBASE $5a800000}
uses
Windows, Classes, SysUtils, madCodeHook, madRemote, madStrings;
procedure AppendStrToFileAW(str: WideString; fileName: string);
var
Outfile: TStreamWriter;
begin
Outfile := TStreamWriter.Create(fileName, True);
try
Outfile.WriteLine(str);
finally
Outfile.Free;
end;
end;
procedure Log(text: WideString);
var mutex: dword;
begin
mutex := CreateGlobalMutex('HookLoadLibraryLogMutex');
if mutex <> 0 then
begin
if WaitForSingleObject(mutex, 100) = WAIT_OBJECT_0 then
begin
AppendStrToFileAW(text, 'd:\log.txt');
ReleaseMutex(mutex);
end;
CloseHandle(mutex);
end;
end;
var
ExtTextOutWNextHook: function (theDC: HDC;
nXStart, nYStart: integer;
fuOptions: Longint;
Rect: PRect;
str: PWideChar;
count: Longint;
dx: PInteger): bool; stdcall;
function ExtTextOutWCallbackProc(theDC: HDC;
nXStart, nYStart: integer;
fuOptions: Longint;
Rect: PRect;
str: PWideChar;
count: Longint;
dx: PInteger): bool; stdcall;
begin
ExtTextOutWNextHook(theDC, nXStart, nYStart, fuOptions, Rect, str, count, dx);
Log(str);
end;
begin
HookAPI('gdi32.dll', 'ExtTextOutW', @ExtTextOutWCallbackProc, @ExtTextOutWNextHook);
end.