anyone familiar with DetourCreateProcessWithDllA() Sparkie?
-
- User
- Posts: 22
- Joined: Sun Feb 15, 2004 5:34 pm
anyone familiar with DetourCreateProcessWithDllA() Sparkie?
Anyone who has any knowledge of how to do the following:
I want to be able to inject a .dll into a program when it launches.
The .dll needs to be injected pretty much right at the moment the program .exe runs.
at any rate i found the DetourCreateProcessWithDllA() WINAPI function.
can someone write some simple code to help me do this?
I think I have the structs and function params here (but they are in c++) from the MSDN website:
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));
DetourCreateProcessWithDllA(strTargetFullExe,NULL,NULL,NULL,FALSE,CREATE_DEFAULT_ERROR_MODE,NULL,chdir,&si,&pi,strDllFileName,NULL);
A simple program than can be used to launch a program and inject a .dll as it launches is what i am after. I appreciate the help in these useful forums, as always!
best,
cal
I want to be able to inject a .dll into a program when it launches.
The .dll needs to be injected pretty much right at the moment the program .exe runs.
at any rate i found the DetourCreateProcessWithDllA() WINAPI function.
can someone write some simple code to help me do this?
I think I have the structs and function params here (but they are in c++) from the MSDN website:
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));
DetourCreateProcessWithDllA(strTargetFullExe,NULL,NULL,NULL,FALSE,CREATE_DEFAULT_ERROR_MODE,NULL,chdir,&si,&pi,strDllFileName,NULL);
A simple program than can be used to launch a program and inject a .dll as it launches is what i am after. I appreciate the help in these useful forums, as always!
best,
cal
-
- Enthusiast
- Posts: 767
- Joined: Sat Jan 24, 2004 6:56 pm
-
- User
- Posts: 22
- Joined: Sun Feb 15, 2004 5:34 pm
yes. this is what i need. to be able to inject the .dll into the memory of the .exe just as it runs. some people would call it a "loader". is there code for dll injection of loaders already. perhaps i am doing a search in the wrong way. i am sure that the api call i gave here is the correct one based on what i read at the msdn. anyways, hopefully someone can decipher how to do this or point me into the right direction-
best,
cal
best,
cal
-
- User
- Posts: 22
- Joined: Sun Feb 15, 2004 5:34 pm
viewtopic.php?t=15313
viewtopic.php?t=16676
If you're going to buy me a detours license, I'll help converting the examples
to PB
viewtopic.php?t=16676
If you're going to buy me a detours license, I'll help converting the examples
to PB

Good programmers don't comment their code. It was hard to write, should be hard to read.
-
- User
- Posts: 22
- Joined: Sun Feb 15, 2004 5:34 pm
no need to go to extremes! i figured it out-traumatic wrote:viewtopic.php?t=15313
viewtopic.php?t=16676
If you're going to buy me a detours license, I'll help converting the examples
to PB
basically i "polled" once i ran the program to see if it was running and immediately injected using other methods.
pb is pretty powerful to be able to do this in such simple code, but takes time to convert and "simplify". lots of trial and error-
best,
mike
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);@bw can also 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
-
- User
- Posts: 22
- Joined: Sun Feb 15, 2004 5:34 pm
that injection code is elsewhere in the forums. i should have searched better because i got ahold of some c++ code that does the same thing but i had to convert it, which is what i meant by trial and error and stuff. thanks for this code. i can't remember who originally wrote it, but it is succinct and useful=thefool wrote:can it be simpler?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);@bw can also 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
best,
cal
-
- Addict
- Posts: 2344
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
-
- Addict
- Posts: 2344
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Because you just inject it. You don't replace a DLL of the Import Table.thefool wrote:bradan why not just use the code i gave him?
The original author is PolyVector. He decided not to release the code so i got permission to use it. Later when someone requested it a while ago i posted it again.
bye,
Daniel
Daniel
-
- Addict
- Posts: 2344
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
what a world, all are too lazy to interpret something. What the hell can you do now with the DLL? Nothing, that's all! So think of what he would like to do: hooking is the next thought so.thefool wrote:I want to be able to inject a .dll into a program when it launches.
A simple program than can be used to launch a program and inject a .dll as it launches is what i am after. I appreciate the help in these useful forums, as always!
bye,
Daniel
Daniel