- // La fonction d'injection
-
- function InjectDLL( DLLSource : string; ProcessDestination : string ) : Boolean;
- var
- LibName : Pointer;
- hProcess : THandle;
- ThreadHandle: THandle;
- OctEcrit : Cardinal;
- TheadID : DWORD;
- begin
- Result := False;
-
- AjustePrivileges; // voir dans le Zip pour cette fonction
-
- hProcess := OpenProcess( PROCESS_ALL_ACCESS, FALSE, FindProcess( ProcessDestination ) );
- if (hProcess = 0) then Exit;
-
- LibName := VirtualAllocEx( hProcess, nil, Length(DLLSource) + 1, MEM_COMMIT, PAGE_READWRITE );
- if ( LibName <> nil ) then
- begin
- WriteProcessMemory( hProcess, LibName, PChar(DLLSource), Length(DLLSource) + 1, OctEcrit );
- if ( (Length(DLLSource) + 1) <> OctEcrit ) then Exit;
- le process
- ThreadHandle := CreateRemoteThread( hProcess, nil, 0, GetProcAddress( LoadLibrary('kernel32.dll'), 'LoadLibraryA' ), LibName, 0, TheadID );
- Result := ( ThreadHandle <> 0 );
- WaitForSingleObject( ThreadHandle, INFINITE );
- end else Result := False;
- VirtualFreeEx( hProcess, LibName, 0, MEM_RELEASE );
- CloseHandle( hProcess );
- end;
// La fonction d'injection
function InjectDLL( DLLSource : string; ProcessDestination : string ) : Boolean;
var
LibName : Pointer;
hProcess : THandle;
ThreadHandle: THandle;
OctEcrit : Cardinal;
TheadID : DWORD;
begin
Result := False;
AjustePrivileges; // voir dans le Zip pour cette fonction
hProcess := OpenProcess( PROCESS_ALL_ACCESS, FALSE, FindProcess( ProcessDestination ) );
if (hProcess = 0) then Exit;
LibName := VirtualAllocEx( hProcess, nil, Length(DLLSource) + 1, MEM_COMMIT, PAGE_READWRITE );
if ( LibName <> nil ) then
begin
WriteProcessMemory( hProcess, LibName, PChar(DLLSource), Length(DLLSource) + 1, OctEcrit );
if ( (Length(DLLSource) + 1) <> OctEcrit ) then Exit;
le process
ThreadHandle := CreateRemoteThread( hProcess, nil, 0, GetProcAddress( LoadLibrary('kernel32.dll'), 'LoadLibraryA' ), LibName, 0, TheadID );
Result := ( ThreadHandle <> 0 );
WaitForSingleObject( ThreadHandle, INFINITE );
end else Result := False;
VirtualFreeEx( hProcess, LibName, 0, MEM_RELEASE );
CloseHandle( hProcess );
end;