Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Change code of Internalfor External Pascal ( delphi )

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
eloiton
How do I cheat?
Reputation: 0

Joined: 06 May 2021
Posts: 3
Location: Brasil

PostPosted: Thu Sep 08, 2022 2:03 pm    Post subject: Change code of Internalfor External Pascal ( delphi ) Reply with quote

Does anyone know how to make this change from DLL to Exe?

This DLL
Code:
procedure HookFunc(NewFunc:Pointer; LocalAddr:DWORD);
var
  Old : DWORD;
begin
  VirtualProtect(Pointer(LocalAddr), 5, PAGE_EXECUTE_READWRITE, Old);
  PBYTE(LocalAddr)^:= $E9;
  PDWORD(LocalAddr+1)^:= DWORD(NewFunc) - DWORD(LocalAddr) - 5;
  VirtualProtect(Pointer(LocalAddr), 5, Old, Old);
end;
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Thu Sep 08, 2022 2:09 pm    Post subject: Reply with quote

Code:

procedure HookFunc(processHandle: THandle; NewFunc:Pointer; LocalAddr:DWORD);
var
  Old : DWORD;
  bytes: array [0..4] of byte;
  bw: ptruint;
begin
  VirtualProtectEx(processHandle, Pointer(LocalAddr), 5, PAGE_EXECUTE_READWRITE, Old);
  bytes[0]:=$e9;
  pdword(@bytes[1]]^:=DWORD(NewFunc)-DWORD(LocalAddr)-5;
  WriteProcessMemory(processHandle, pointer(LocalAddr), @bytes[0], 5, bw);
  VirtualProtectEx(processHandle, Pointer(LocalAddr), 5, Old, Old);
end;


just make sure that newfunc is an address inside the target process, and not inside your EXE.............

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
eloiton
How do I cheat?
Reputation: 0

Joined: 06 May 2021
Posts: 3
Location: Brasil

PostPosted: Thu Sep 08, 2022 3:07 pm    Post subject: Reply with quote

Dark Byte wrote:
Code:

procedure HookFunc(processHandle: THandle; NewFunc:Pointer; LocalAddr:DWORD);
var
  Old : DWORD;
  bytes: array [0..4] of byte;
  bw: ptruint;
begin
  VirtualProtectEx(processHandle, Pointer(LocalAddr), 5, PAGE_EXECUTE_READWRITE, Old);
  bytes[0]:=$e9;
  pdword(@bytes[1]]^:=DWORD(NewFunc)-DWORD(LocalAddr)-5;
  WriteProcessMemory(processHandle, pointer(LocalAddr), @bytes[0], 5, bw);
  VirtualProtectEx(processHandle, Pointer(LocalAddr), 5, Old, Old);
end;


just make sure that newfunc is an address inside the target process, and not inside your EXE.............



Thank you so much for answering me!
I made some changes the code does the JUMP but does not write after the Jump could you help me?

Code:
 procedure code; assembler;
asm
    add eax,100       // i want add eax
   mov [edi+$000000D8],eax   //original code
end;
procedure HookFunc(NewFunc:Pointer; LocalAddr:DWORD);
var
  Old : DWORD;
  bytes: array [0..4] of byte;
  //bw: ptruint;
begin
  PID:= GetPidByName('game.exe');
  hProc:= OpenProcess(PROCESS_ALL_ACCESS,false,PID);

  VirtualProtectEx(hProc, Pointer(LocalAddr), 5, PAGE_EXECUTE_READWRITE, Old);
  bytes[0]:=$e9;
  pdword(@bytes[1])^:=DWORD(NewFunc)-DWORD(LocalAddr)-5;
  WriteProcessMemory(hProc, pointer(LocalAddr), @bytes[0], 5, Written);
  VirtualProtectEx(hProc, Pointer(LocalAddr), 5, Old, Old);

end;
Back to top
View user's profile Send private message
eloiton
How do I cheat?
Reputation: 0

Joined: 06 May 2021
Posts: 3
Location: Brasil

PostPosted: Mon Aug 28, 2023 10:11 am    Post subject: Re: Change code of Internalfor External Pascal ( delphi ) Reply with quote

eloiton wrote:
Does anyone know how to make this change from DLL to Exe?

This DLL
Code:
procedure HookFunc(NewFunc:Pointer; LocalAddr:DWORD);
var
  Old : DWORD;
begin
  VirtualProtect(Pointer(LocalAddr), 5, PAGE_EXECUTE_READWRITE, Old);
  PBYTE(LocalAddr)^:= $E9;
  PDWORD(LocalAddr+1)^:= DWORD(NewFunc) - DWORD(LocalAddr) - 5;
  VirtualProtect(Pointer(LocalAddr), 5, Old, Old);
end;


after a long time I resolved and understood about this function. I'll leave a part of the solution for anyone who has this same problem.
this code of mine is far from perfect but it will serve as a basis.
and I will post the same code in C# as it is the language I am currently using.

Code:
  procedure JMP(quem:dword;aonde:dword);
  var
      difference, difference2: Integer;
      i: Integer;
      lpBaseAddress: dword;
  dwAddress, dwArgument: DWORD;
  instruction: array[0..0] of Byte;
  argumentBytes: array[0..3] of Byte;
  instructionBytes: array of Byte;
  begin

      difference := Integer(quem) - Integer(Baseaddress);  // Baseaddress is the = module of process
      difference2 := Integer(aonde) - Integer(Baseaddress); // Baseaddress is the = module of process
      lpBaseAddress := difference;

      dwAddress := Cardinal(difference2);
      dwArgument := dwAddress - (Cardinal(lpBaseAddress) + 5);

      instruction[0] := $E9;
      Move(dwArgument, argumentBytes, SizeOf(dwArgument));
       setlength(instructionBytes,5);
      for i := Low(instruction) to High(instruction) do
        instructionBytes[i] := instruction[i];
      for i := Low(argumentBytes) to High(argumentBytes) do
        instructionBytes[Length(instruction) + i] := argumentBytes[i];
      WriteMByteOffse(difference,instructionBytes);

  end;


this is the C#
Code:
        private static void JMP(IntPtr quem, IntPtr aonde)
        {
            unchecked
            {
                int Argument = (int)IntPtr.Subtract(aonde, (int)modBaseP) - ((int)IntPtr.Subtract(quem, (int)modBaseP) + 5);
                byte[] instruction = { 0xE9 };
                byte[] argumentBytes = BitConverter.GetBytes(Argument);
                byte[] instructionBytes = instruction.Concat(argumentBytes).ToArray();
                WriteMByte(quem, instructionBytes);
            }
        }
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites