Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReadProcessMemory only returns 1 byte

Status
Not open for further replies.

y0ker

Programmer
Nov 25, 2008
3
SE
Windows xp sp3
Delphi 7

Trying to read strings from another process memory but I m only getting 1 byte back from the read operation.

The findprocess() function is predefined in an include btw

----------
var
Window: integer;
dat: array[0..500] of Char;
read: cardinal;
Str: String;
begin
Window := FindProcess('blaha.exe');
Window := openprocess(PROCESS_ALL_ACCESS,false,Window);
ReadProcessMemory(Window,pointer($0A6D84F4), @dat,500,read);
Str := String(dat);
Edit1.Text := Str;
----------

Now, according to my own comprehension, 500 bytes should get dumped into 'dat' but it would seem only 1 byte make it back alive, ie I only get the first letter in return from the string in memory im trying to read at the specified adress.

Argh! Why is that?
 
'read' returns 500, indicating that 500 bytes was read from the specified offset, yet I only get one character back from the operation, or 1 byte, however you like it.
 
Yep, as it seems, the string is coped alright, only it displays it s 1st element in the edit box.

If i iterate like so; dat[1], dat[2] etc all characters show up in proper sequence, but only one at a time. :p

How could I make the whole string appear and not just the individual elements of the 'dat' char array?

excuse my noobness.
 
As is the case, it's not a string type, it's just 501 bytes of data. Read from Dat[0] and process it as "just data" (as you described) into Str.

----------
Measurement is not management.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top