单位FastCodePatch.pas在Win32平台中工作。 Delphi XE2支持Win64平台,有什么想法让FastCodePatch在Win64平台下工作?如何使FastCodePatch在Delphi XE2 Win64平台上工作?
unit FastcodePatch;
interface
function FastcodeGetAddress(AStub: Pointer): Pointer;
procedure FastcodeAddressPatch(const ASource, ADestination: Pointer);
implementation
uses
Windows;
type
PJump = ^TJump;
TJump = packed record
OpCode: Byte;
Distance: Pointer;
end;
function FastcodeGetAddress(AStub: Pointer): Pointer;
begin
if PBYTE(AStub)^ = $E8 then
begin
Inc(Integer(AStub));
Result := Pointer(Integer(AStub) + SizeOf(Pointer) + PInteger(AStub)^);
end
else
Result := nil;
end;
procedure FastcodeAddressPatch(const ASource, ADestination: Pointer);
const
Size = SizeOf(TJump);
var
NewJump: PJump;
OldProtect: Cardinal;
begin
if VirtualProtect(ASource, Size, PAGE_EXECUTE_READWRITE, OldProtect) then
begin
NewJump := PJump(ASource);
NewJump.OpCode := $E9;
NewJump.Distance := Pointer(Integer(ADestination) - Integer(ASource) - 5);
FlushInstructionCache(GetCurrentProcess, ASource, SizeOf(TJump));
VirtualProtect(ASource, Size, OldProtect, @OldProtect);
end;
end;
end.
由Ville Krumlinde提供的解决方案不适用于64位软件包。它仅适用于独立.exe应用程序。
这实际上是Ville回答了你原来的问题,软件包中的修补功能是一个不同的游戏,你所提供的代码也需要在32位目标上。 –
伟大的代码!我确认它可以在32/64位Windows 7下使用Delphi 10.1(柏林)完美工作,即使启用了“DEP”也是如此。 –