Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses tlhelp32;
- type
- TByteArr = array of byte;
- function WriteProcessMemoryString(name_process:string; offset:DWORD; text_string:string; len:integer):boolean;
- var
- hProc, PID : DWORD;
- ipBase: ^dword;
- text:string;
- ArByte : TByteArr;
- write: SIZE_T;
- function GetPid(name_process: string): Integer;
- var
- hSnap: THandle;
- pe: TProcessEntry32;
- pid: DWORD;
- begin
- pe.dwSize := SizeOf(pe);
- hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if Process32First(hSnap, pe) then
- while Process32Next(hSnap, pe) do
- if ExtractFileName(pe.szExeFile) = name_process then
- Result := pe.th32ProcessID;
- end;
- function StrToByte(const Value: String): TByteArr;
- var
- I: integer;
- begin
- SetLength(Result, Length(Value));
- for I := 0 to Length(Value) - 1 do
- begin
- Result[I] := ord(Value[I + 1]);
- end;
- end;
- begin
- PID := GetPid(name_process);
- hProc:=OpenProcess(PROCESS_ALL_ACCESS, False, PID);
- if hProc <> 0 then
- begin
- try
- ipBase:=ptr(offset);
- ArByte := StrToByte(text_string);
- WriteProcessMemory(hProc, ipBase, ArByte, len, write);
- Result := True;
- finally
- CloseHandle(hProc);
- end;
- end;
- end;
- //Use so
- if WriteProcessMemoryString('Testxxx.exe', $01522F30, 'testtest', 8) = True then
- begin
- ShowMessage('OK!');
- end;
- //(process name, virtual offset, text, write length)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement