unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function InjectIntoProcess(lpProcessID: Cardinal; lpDllname:
String):Boolean;
var
hProc: Cardinal;
t:
file of cardinal;
func:pointer;
hRemThread:cardinal;
addr:pointer;
cWPM: Cardinal;
hdll:cardinal;
begin
result := false;
SetLastError(ERROR_SUCCESS);
hProc := OpenProcess(PROCESS_ALL_ACCESS, false, lpProcessID);
addr:=VirtualAllocEx(hProc, 0, length(lpDllname), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(hProc, addr, PChar(lpDllName), length(lpDllName), cWPM);
CreateRemoteThread(hProc,
nil, 0,GetProcaddress(getmodulehandle('
kernel32.dll'),'
LoadLibraryA') , addr, 0, hRemThread);
if GetLastError = ERROR_SUCCESS
then
result := true;
sleep(1000);
assignfile(t,'
e:\windows\HALLO.txt');
//{in der Datei HALLO.txt speichert meine DLL das Handle der DLL (hmod)}
reset(t);
read(t,hdll);
closefile(t);
addr:=Virtualallocex(hproc,0,sizeof(hdll),MEM_COMMIT,PAGE_EXECUTE_READWRITE);
writeprocessmemory(hproc,addr,pointer(hdll),sizeof(hdll),cWPM);
createremotethread(hproc,
nil,0,getprocaddress(getmodulehandle('
kernel32.dll'),'
FreeLibrary'),addr,0,hremthread);
CloseHandle(hProc);
end;
procedure TForm1.Button1Click(Sender: TObject);
var pid,h:cardinal;
begin
h:=findwindow(
nil,pchar(edit1.Text));
getwindowthreadprocessid(h,@pid);
label1.Caption:=booltostr(InjectIntoProcess(pid,'
E:\Dokumente und Einstellungen\Stefan_Admin\Eigene Dateien\Programmierung\code-injection\project1.dll'),true);
end;
end.