Recent

Author Topic: [Help] How do we call functions like ReadProcessMemory(), WriteProcessMemory()  (Read 5190 times)

shonay

  • Full Member
  • ***
  • Posts: 169
Like the subject line says, how do we call these functions in delphi/ Lazarus. I would like to learn.
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
in short: uses Windows; call functions

shonay

  • Full Member
  • ***
  • Posts: 169
in short: uses Windows; call functions
In c++,the function should look like this

Code: [Select]
ReadProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, lpBackup, 6, 0);

WriteProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, jmp, 6, 0);

Now I was needing. The same in Delphi. Lazarus to be very precise.
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
if it's already wrapped in existing units, use that. Otherwise, create a wrapper.

shonay

  • Full Member
  • ***
  • Posts: 169
I like to be more affirmative in whatever I am doing, sorry if I ask too many Questions.

When I compiled the code yesterday

Code: [Select]
program MessageBoxHookNew;

{$mode delphi}{$H+}

uses
  Windows;

procedure hook(tFunc, nFunc: Pointer);
var
  jumpTo: DWord;
  oldProtect: cardinal;

  MainMessageBox: function(hWnd: HWND; lpText, lpCaption: PAnsiChar;
    uType: UINT): integer; stdcall;
  HookMessageBox: function(hWnd: HWND; lpText, lpCaption: PAnsiChar;
    uType: UINT): integer; stdcall;
begin
  jumpTo := DWord(nFunc) - DWord(tFunc) - 5;
  VirtualProtect(tFunc, 5, PAGE_EXECUTE_READWRITE, @oldProtect);
  pbyte(tFunc)^ := $e9;
  pdword(DWord(tFunc) + 1)^ := jumpTo;
end;

function HookMessageBox(hWnd: HWND; lpText, lpCaption: PAnsiChar; uType: UINT): integer; stdcall;
begin
  Result := MessageBox(0,'test','Hooked',MB_OK);
end;

begin
  hook(GetProcAddress(GetModuleHandle('user32.dll'), 'MessageBoxW'), @HookMessageBox);

  MessageBoxW(0,'A','B',0);//<--- Test
end.

It showed me the Hooked I was looking for, now I was thinking, is it necessary to use 0readProcessMemory() and WriteProcessMemory() to create a hook function in delphi, likei see in c++
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Depending on your needs, I don't think a hook that does not read/write process memory needs them.

 

TinyPortal © 2005-2018