利用进程的内存读写,替换系统函数~~
//如果直接替换会报地址访问错误~~
procedure ReplaceShowMessage(const Msg: string);
begin
Form1.Memo1.Lines.Add(Msg);
ShowMessagePos(Msg, -1, -1);
end;
procedure NewShowMessage(const Msg: string);
type
TShowMessage = procedure(const Msg: string);
begin
TShowMessage(@ReplaceShowMessage)(Msg);
end;
procedure EndNewShowMessage;
begin
end;
procedure TForm1.FormCreate(Sender: TObject);
var
vProcess: THandle;
vNumberOfBytesRead: DWORD;
begin
vProcess := OpenProcess(PROCESS_ALL_ACCESS, True, GetCurrentProcessId);
try
WriteProcessMemory(vProcess, @ShowMessage, @NewShowMessage,
Integer(@EndNewShowMessage) - Integer(@NewShowMessage),
vNumberOfBytesRead);
finally
CloseHandle(vProcess);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('Hello');
end;