Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6645093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:14:39+00:00 2026-05-26T00:14:39+00:00

Unit FastCodePatch.pas works in Win32 platform. Delphi XE2 supports Win64 platform, any ideas how

  • 0

Unit FastCodePatch.pas works in Win32 platform. Delphi XE2 supports Win64 platform, any ideas how to make FastCodePatch works in Win64 platform?

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.

The solution provided by Ville Krumlinde doesn’t work on 64 bits package. It works on Standalone .exe application only.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:14:39+00:00Added an answer on May 26, 2026 at 12:14 am

    The following code works for both Win32 – Standalone and Package, Win64 – Standalone and Package:

    type
      TNativeUInt = {$if CompilerVersion < 23}Cardinal{$else}NativeUInt{$ifend};
    
      PJump = ^TJump;
      TJump = packed record
        OpCode: Byte;
        Distance: integer;
      end;
    
    function GetActualAddr(Proc: Pointer): Pointer;
    type
      PAbsoluteIndirectJmp = ^TAbsoluteIndirectJmp;
      TAbsoluteIndirectJmp = packed record
        OpCode: Word;   //$FF25(Jmp, FF /4)
        Addr: Cardinal;
      end;
    var J: PAbsoluteIndirectJmp;
    begin
      J := PAbsoluteIndirectJmp(Proc);
      if (J.OpCode = $25FF) then
        {$ifdef Win32}Result := PPointer(J.Addr)^{$endif}
        {$ifdef Win64}Result := PPointer(TNativeUInt(Proc) + J.Addr + 6{Instruction Size})^{$endif}
      else
        Result := Proc;
    end;
    
    procedure FastcodeAddressPatch(const ASource, ADestination: Pointer);
    const
      Size = SizeOf(TJump);
    var
      NewJump: PJump;
      OldProtect: Cardinal;
      P: Pointer;
    begin
      P := GetActualAddr(ASource);
      if VirtualProtect(P, Size, PAGE_EXECUTE_READWRITE, OldProtect) then
      begin
        NewJump := PJump(P);
        NewJump.OpCode := $E9;
        NewJump.Distance := TNativeUInt(ADestination) - TNativeUInt(P) - Size;
    
        FlushInstructionCache(GetCurrentProcess, P, SizeOf(TJump));
        VirtualProtect(P, Size, OldProtect, @OldProtect);
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Unit testing sounds great to me, but I'm not sure I should spend any
This unit fails to compile in XE2 Update 3 with error Internal Error: SY6315.
Duplicate: Unit Testing the Views? Is there any way to unit test View? I
I unit test my classes by giving all my classes an interface. These interfaces
unit Unit7; interface uses Classes; type TListener = class(TThread) procedure Execute; override; end; TMyClass
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IdTCPClient;
unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
Unit testing and ASP.NET web applications are an ambiguous point in my group. More
Unit testing is, roughly speaking, testing bits of your code in isolation with test
Unit tests are cheaper to write and maintain, but they don't cover all scenarios.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.