delphi4arab منتديات دلفي للعرب

نسخة كاملة : ما هي اسرع الطرق لبحث عن بايتات في الذاكرة ؟
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
الصفحات : 1 2 3
هذه الدالة :
PHP كود :
type
  DWORDOfArray 
= Array of Cardinal;
  
ByteOfArray = array of byte;
function 
FindVale_Byte(dwProcessID, dwStartAddress, dwEndAddress : Cardinal; Value : Byte; ProgressSearching : TGauge): DWORDOfArray;
var
  
I, Len, iCount : Integer;
  
NumReadBytes : NativeUInt;
  
TempAddress, hProcess : Cardinal;
  
aResult : ByteOfArray;
  
ImageBase, ImageSize : Cardinal;
begin
  iCount 
:= 0;
  
SetLength(Result,iCount + 1);
  
Result[iCount] := 0;
  if 
dwProcessID = 0  then Exit;
  
hProcess := OpenProcess(PROCESS_VM_READ,False,dwProcessID);
  
ImageBase := GetBaseAddress(dwProcessID,PWideChar(GetNameFromPID(dwProcessID)));
  
ImageSize := GetBaseSize(dwProcessID,PWideChar(GetNameFromPID(dwProcessID))) + ImageBase;
  if 
dwStartAddress > dwEndAddress then
  begin
    TempAddress 
:= dwEndAddress;
    
dwEndAddress := dwStartAddress;
    
dwStartAddress := TempAddress;
  
end;

  if 
dwStartAddress < ImageBase then
    dwStartAddress 
:= ImageBase;
  if 
dwEndAddress > ImageSize then
    dwEndAddress 
:= ImageSize;

  
Len := (dwEndAddress - dwStartAddress) + 1;
  
SetLength(aResult,Len);
  
ReadProcessMemory(hProcess,Pointer(dwStartAddress),aResult,Len,NumReadBytes);
  
ProgressSearching.MaxValue := NumReadBytes;
  
ProgressSearching.Progress := 0;
  
ProgressSearching.MinValue := ProgressSearching.Progress;
  for 
I := 0 to NumReadBytes do
  
begin
    
if aResult[i] = Value then
    begin
      Inc
(iCount);
      
SetLength(Result,iCount);
      
Result[iCount-1] := dwStartAddress + i;
    
end;
    
ProgressSearching.Progress := i;
  
end;
end; 

وهذه دوال جلب الـ ImageBase و ImageBaseSize ... طبعاً تستطيع إستعمال دوال آخر ...:
PHP كود :
function GetBaseAddress(ProcessId:Cardinal; pModuleName: PChar): DWord;
var
  
FSnapshotHandle: THandle;
  
FModuleEntry32 : TModuleEntry32;
  
ContinueLoop   : Boolean;
  
dwProcessID: DWord;
begin
  Result 
:= 0;
  
dwProcessID := ProcessId;
  if (
dwProcessID = 0) then
    
Exit;
  
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,dwProcessID);
  
FModuleEntry32.dwSize := Sizeof(FModuleEntry32);
  
ContinueLoop := Module32First(FSnapshotHandle,FModuleEntry32);
  while 
ContinueLoop do
  
begin
    
if (Pos(UpperCase(pModuleName),UpperCase(FModuleEntry32.szModule)) > 0) then
      Result 
:= FModuleEntry32.hModule;
    
ContinueLoop := Module32Next(FSnapshotHandle,FModuleEntry32);
  
end;
  
CloseHandle(FSnapshotHandle);
end;

function 
GetBaseSize(ProcessId:Cardinal; pModuleName: PChar): DWord;
var
  
FSnapshotHandle: THandle;
  
FModuleEntry32 : TModuleEntry32;
  
ContinueLoop   : Boolean;
  
dwProcessID: DWord;
begin
  Result 
:= 0;
  
dwProcessID := ProcessId;
  if (
dwProcessID = 0) then
    
Exit;
  
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,dwProcessID);
  
FModuleEntry32.dwSize := Sizeof(FModuleEntry32);
  
ContinueLoop := Module32First(FSnapshotHandle,FModuleEntry32);
  while 
ContinueLoop do
  
begin
    
if (Pos(UpperCase(pModuleName),UpperCase(FModuleEntry32.szModule)) > 0) then
      Result 
:= FModuleEntry32.modBaseSize;
    
ContinueLoop := Module32Next(FSnapshotHandle,FModuleEntry32);
  
end;
  
CloseHandle(FSnapshotHandle);
end; 
والسلام عليكم ورحمة الله وبركاتة
الصفحات : 1 2 3