Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Reading/Writing in other process memory

Posted on 2004-12-01
1
Medium Priority
?
914 Views
Last Modified: 2012-05-05
1. i have this code that shows a chunk of memory in delphi. This was just a test before i can use it on a game but i ran into some problems. earlier i was able to read from it and after restarting i get an error about access violation. what could have caused this. im using windows xp sp2

2. Also looking at r:='gg';, when i just put r:=''; it wont show the read memory. why?

3. currently i can only access proccesses that have names like "delphi 7" on application but not the processes in ctrl+alt+del. how can i also read memory from proccess list in windows process manager

any help would be great. thank you. a sample code of reading and writing in other process memory would be really great that will work on windows xp sp2

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Button1: TButton;
    Button2: TButton;
    Label5: TLabel;
    Label6: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
  r: String;
  HandleWindow, mez, len, c2: cardinal;
  ThreadId, ProcessId,WindowName : integer;
    { Public declarations }
  end;

var
  Form1: TForm1;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin
WindowName := FindWindow(nil,'Delphi 7');
If WindowName = 0 then
Label3.Caption := 'not found'
else
begin
ThreadId := GetWindowThreadProcessId(WindowName,@ProcessId);
Label3.Caption := '' + InttoStr(ThreadId);
HandleWindow := OpenProcess(PROCESS_ALL_ACCESS,False,ProcessId);
Label4.Caption := '' + InttoStr(HandleWindow);
Label6.Caption := '' + InttoStr(HandleWindow);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
result: boolean;
addr: pointer;
begin
result := false;
r:='gg';
len := 50;
addr := ptr($00400050);
result := ReadProcessMemory(HandleWindow,addr,pointer(r),len,len);
Label6.Caption := r;
end;
end.
0
Comment
Question by:pogimez
1 Comment
 
LVL 20

Accepted Solution

by:
Madshi earned 500 total points
ID: 12723975
You're reading in 50 bytes. But where to? You're giving in "pointer(r)" as the address where to write to. That's ok, but there must be enough space so that you don't overwrite other important variables. Use SetLength(r, 50) before calling ReadProcessMemory, that should solve the problem.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question