[DELPHI] Read/Write String Value

Posts 14 of 4 · Page 1 of 1
[DELPHI] Read/Write String Value
Help me. im Noob

how to write/Read string value on delphi using WriteProcessMemory

im using Edit1.Text for writing value:


please some help me.
Quote Originally Posted by fiqhpratama View Post
Help me. im Noob

how to write/Read string value on delphi using WriteProcessMemory

im using Edit1.Text for writing value:


please some help me.
i hate it there is no Delphi Section!
The Windows API return LPRSTR which is a PChar in Delphi.
A String in Delphi saves the Memory Position of the CharArray in Slot 0 of the Array, so the char array is beginning is at 1
Code:
var
  PlayerNameSlot1: string;
begin
  SetLength(PlayerNameSlot1, 32);
  ReadProcessMemory(GameHandle, Pointer(GTA5.exe + $268A9F4 + $88),   @playernameSlot1[1], sizeof(PlayerNameSlot1), FByteBuffer); 
end;
Code:
begin
 WriteProcessMemory(GameHandle, Pointer(Address), @edIT1.Text[1], sizeof(Edit1.Text), FByteBuffer);  
end;
Thanks for replay my post

how about ansiString Writing?

- - - Updated - - -

i test writing with Edit1, but
the output is a Unicode string,.
how to write Ansi String?

- - - Updated - - -

Quote Originally Posted by MikeRohsoft View Post
i hate it there is no Delphi Section!
The Windows API return LPRSTR which is a PChar in Delphi.
A String in Delphi saves the Memory Position of the CharArray in Slot 0 of the Array, so the char array is beginning is at 1
Code:
var
  PlayerNameSlot1: string;
begin
  SetLength(PlayerNameSlot1, 32);
  ReadProcessMemory(GameHandle, Pointer(GTA5.exe + $268A9F4 + $88),   @playernameSlot1[1], sizeof(PlayerNameSlot1), FByteBuffer); 
end;
Code:
begin
 WriteProcessMemory(GameHandle, Pointer(Address), @edIT1.Text[1], sizeof(Edit1.Text), FByteBuffer);  
end;
wow, its work, i just convert Unicode to AnsiString.
Thanks for your Reply, your code is very helpfull...
Quote Originally Posted by fiqhpratama View Post
wow, its work, i just convert Unicode to AnsiString.
Thanks for your Reply, your code is very helpfull...
I'm writing a Wrapper Class at the Moment for the Memory Stuff, if you want to play arround with that you can contact me on Skype or by PM.
If i penetrate it enough, i will make it public anyway.
It can already handle to read and write nearly all basic types, AOB Pattern Scan and dll Injection.

And i found out if you use my example you can only read 4 or 8 bytes depending on WOW or / and Plattform (64 Bit = 8 byte, 32 Bit = 4 byte) because the sizeof() return only the Size of the type, you should use Magic Function Length() for it.

Anyway, if you read a String from Memory, but you don't know how big it will be, you read more then you have to.
If you do that your String will maybe have "cryptic Characters" at the end, because a String in Delphi isn't NULL Terminated.
You can Trim it after it by yourself or you use a workarround with PChar, because PChar is what "Char*" in C is (Pointer to array of Char) and this is NULL Terminated:
Code:
var
  BytesRead: SIZE_T;
  Str: string; // Here we want the Memory Read Output as clean String
  Buffer: array of char; // This we use to read the bytes, you could use 
  //Buffer: array of byte; // You can switch this line with the above, we don't care
  StrBuffer: PChar absolute Buffer; // this PChar points already to Buffer now
  len: integer; // How many we want to read
begin
  len := 255;
  SetLength(Buffer, len); // set the char array length
  ReadProcessMemory(ProccessHandle, Pointer(addr), @ Buffer[0], len, BytesRead);
  Str := AnsiString(StrBuffer); // PChar to String 
  SetLength(Buffer, 0); // clean up, after we filled our String
end;
Posts 14 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?