Registriert seit: 28. Jan 2006
Ort: Görlitz / Sachsen
489 Beiträge
Delphi 2007 Professional
|
CPP nach Delphi Übersetzung
11. Feb 2010, 15:04
Delphi-Quellcode:
BOOL GetProcessOf( char exename[], PROCESSENTRY32 *process )
{
process->dwSize = sizeof( PROCESSENTRY32 );
HANDLE handle = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if ( Process32First( handle, process ) )
while ( Process32Next( handle, process ) )
if ( strcmpi( process->szExeFile, exename ) == 0 )
{
CloseHandle( handle );
return TRUE;
}
CloseHandle( handle );
return FALSE;
}
DWORD GetModuleBaseAddress( DWORD dwProcID, char* szModule )
{
MODULEENTRY32 xModule;
HANDLE hSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwProcID );
xModule.dwSize = sizeof( MODULEENTRY32 );
if( Module32First( hSnap, &xModule ) )
while( Module32Next( hSnap, &xModule ) )
if( strcmp( xModule.szModule, szModule ) == 0 )
{
CloseHandle( hSnap );
return (DWORD)*xModule.modBaseAddr;
}
CloseHandle( hSnap );
return 0;
}
hab ich versucht mit
Delphi-Quellcode:
Function GetProcessOf(process: PROCESSENTRY32;exename: Array of Char): Boolean;
var
HANDLE: THANDLE;
begin
Result := FALSE;
process.dwSize := sizeof(PROCESSENTRY32);
HANDLE := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32First( HANDLE, process)) then
while (Process32Next( HANDLE, process)) do
if (strcomp(process.szExeFile, @exename) = 0) then
Begin
CloseHandle( HANDLE);
Result := TRUE;
End;
CloseHandle( HANDLE);
Result := FALSE;
End;
Function GetModuleBaseAddress(dwProcID: Dword;szModule: Array of Char): Dword;
var
xModule: MODULEENTRY32;
hSnap: THANDLE;
begin
hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcID);
xModule.dwSize := sizeof(MODULEENTRY32);
if (Module32First(hSnap, &xModule)) then
while (Module32Next(hSnap, &xModule)) do
if (strcomp(xModule.szModule, @szModule) = 0) then
Begin
CloseHandle(hSnap);
Result := Dword (xModule.modBaseAddr);
End;
CloseHandle(hSnap);
Result := 0;
end;
zu übersetzen
aufgerufen werden soll das ganze So
Delphi-Quellcode:
procedure TForm2.Button1Click(Sender: TObject);
var
pe32 : PROCESSENTRY32;
dwEngineBase,dwClientBase,dwBytes,dwProcID : Dword;
hProcess : THandle;
begin
while not ( GetProcessOf('hl2.exe', &pe32)) Sleep(100);
dwProcID := pe32.th32ProcessID;
hProcess := OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
if (hProcess = INVALID_HANDLE_VALUE)then Exit;//zeige Fehler
// This seems to crash on Vista, which I'm running atm. works on XP.
dwEngineBase := GetModuleBaseAddress( dwProcID, 'engine.dll' );
dwClientBase := GetModuleBaseAddress( dwProcID, 'client.dll' );
// Putting manual addresses right now instead.
//dwEngineBase := $20000000;
//dwClientBase := $24000000;
dwBytes := 0;
end;
kann sich das Bitte mal jemand anschauen was da nicht rundläuft bei den beiden Funktionen
Marcel
|
|
Zitat
|