单元FastCodePatch.pas在Win32平台上工作. Delphi XE2支持Win64平台,任何想法如何使FastCodePatch在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,OldProtect,@OldProtect); end; end; end.
Ville Krumlinde提供的解决方案不适用于64位软件包.它仅适用于独立的.exe应用程序.
解决方法
对于FastcodeAddresspatch功能,当我尝试时,此版本的工作在32位和64位.关键是将“指针”改为“整数”,因为Intel相对跳转指令($E9)在64位模式下仍然使用32位偏移量.
type PJump = ^TJump; TJump = packed record OpCode: Byte; distance: integer; end; procedure FastcodeAddresspatch(const ASource,OldProtect) then begin NewJump := PJump(ASource); NewJump.OpCode := $E9; NewJump.distance := NativeInt(ADestination) - NativeInt(ASource) - Size; FlushInstructionCache(GetCurrentProcess,@OldProtect); end; end; procedure Test; begin MessageBox(0,'Original','',0); end; procedure NewTest; begin MessageBox(0,'Patched',0); end; procedure TForm5.FormCreate(Sender: TObject); begin FastcodeAddresspatch(@Test,@NewTest); Test; end;
我不知道其他功能是什么,但是我猜这应该是这样的:
function FastcodeGetAddress(AStub: Pointer): Pointer; begin if PBYTE(AStub)^ = $E8 then begin Inc(NativeInt(AStub)); Result := Pointer(NativeInt(AStub) + SizeOf(integer) + PInteger(AStub)^); end else Result := nil; end;
原文地址:https://www.jb51.cc/delphi/102440.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。