Code: Select all
Procedure InjectDLL(DllFileName$,ProcessID.l)
Protected Result.l,DllFileName$,Size.l,Process.l,RemoteMem.l,BytesWritten.l,LoadLibrary_Address.l,hThread.l
Result=#False
Size=Len(DllFileName$)+1
Process=OpenProcess_(#PROCESS_ALL_ACCESS,0,ProcessID)
If Process
RemoteMem=VirtualAllocEx_(Process,#Null,Size,#MEM_COMMIT,#PAGE_READWRITE)
If RemoteMem
WriteProcessMemory_(Process,RemoteMem,DllFileName$,Size,@BytesWritten);BytesWritten can be #Null....
If BytesWritten=>Size
If OpenLibrary(0,"Kernel32.dll")
LoadLibrary_Address=IsFunction(0,"LoadLibraryA")
CloseLibrary(0)
If LoadLibrary_Address
hThread=CreateRemoteThread_(Process,#Null,#Null,LoadLibrary_Address,RemoteMem,#Null,#Null)
If hThread
WaitForSingleObject_(hThread, #INFINITE)
GetExitCodeThread_(hThread,@Result)
EndIf
EndIf
EndIf
EndIf
VirtualFreeEx_(Process,RemoteMem,Size,#MEM_DECOMMIT)
EndIf
CloseHandle_(Process)
EndIf
ProcedureReturn Result
EndProcedure
[/size]
it does not get posted correctly. Code is by Polyvector. Notice to have an attachprocess() procedure! read about that in the pb help file.!
edit: when i copy & paste the code to jaPBe the code is correct again. it just doesnt show correctly here.