Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. uses tlhelp32;
  2.  
  3. type
  4. TStringArray = array of string;
  5. function AddressSearchByValue(name_pocess:string; value:DWord):TStringArray;
  6. var
  7. ProcessID, Addr: DWord;
  8. ProcessHandle: THandle;
  9. Mbi: TMemoryBasicInformation;
  10. i: Cardinal;
  11. Buf: PChar;
  12. BytesRead : Size_T;
  13. Count:Integer;
  14. function GetPid(name_process: string): Integer;
  15. var
  16. hSnap: THandle;
  17. pe: TProcessEntry32;
  18. pid: DWORD;
  19. begin
  20. pe.dwSize := SizeOf(pe);
  21. hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  22. if Process32First(hSnap, pe) then
  23. while Process32Next(hSnap, pe) do
  24. if ExtractFileName(pe.szExeFile) = name_process then
  25. Result := pe.th32ProcessID;
  26. end;
  27. begin
  28. ProcessID := GetPid(name_pocess);
  29. ProcessHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_ALL_ACCESS or PROCESS_VM_OPERATION, false, ProcessID);
  30. if ProcessHandle <> 0 then
  31. try
  32. Addr := 0;
  33. Count := 0;
  34. while VirtualQueryEx(ProcessHandle, Pointer(Addr), Mbi, SizeOf(Mbi)) <> 0 do
  35. begin
  36. if (Mbi.State = MEM_COMMIT) and not ((Mbi.Protect and PAGE_GUARD) = PAGE_GUARD) then
  37. begin
  38. GetMem(Buf, Mbi.RegionSize);
  39. try
  40. if ReadProcessMemory(ProcessHandle, Mbi.BaseAddress, Buf, Mbi.RegionSize, BytesRead) then
  41. begin
  42. for i := 0 to BytesRead - SizeOf(Value) do
  43. begin
  44. if PDWord(@Buf[i])^ = Value then
  45. begin
  46. SetLength(result, Count + 1);
  47. Result[Count] := '$' + IntToHex(Integer(Cardinal(Mbi.BaseAddress) + i + i), 8);
  48. Inc(Count);
  49. end;
  50. end;
  51. end;
  52. FreeMem(Buf);
  53. except
  54. on e: Exception do
  55. begin
  56. FreeMem(Buf);
  57. Application.ProcessMessages;
  58. end;
  59. end;
  60. end;
  61. Addr := Addr + Mbi.RegionSize;
  62. end;
  63. finally
  64. CloseHandle(ProcessHandle);
  65. end;
  66. end;
  67.  
  68.  
  69. // Use it like this, displays all addresses in Memo1 that contain the numeric value 21000
  70. procedure TForm1.Button5Click(Sender: TObject);
  71. var
  72. arr: TStringArray;
  73. i: Integer;
  74. begin
  75. arr := AddressSearchByValue('h3blade.exe', 21000);
  76. Memo1.Clear;
  77. for i := 0 to High(arr) do
  78. Memo1.Lines.Add(arr[i]);
  79. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement