D Dll injection problem

maarten van damme maartenvd1994 at gmail.com
Wed Apr 11 06:26:11 PDT 2012


I went ahead and went back to as far as 2.045 and I still couldn't get a
working dll. This would suggest something is wrong with my dll injection
code but I've tested with a few other random dll's and that appears to
work. according to my debugger the problem is an access violation while
executing the main function of the D dll.
the code I use for injecting is

/**
* injectDLL injects a dll in a given process using the CreateRemoteThread
function.
*
* arguments:
*  HANDLE proc = A HANDLE to the process
*  string dllName = A string containting the name of the dll
**/
void injectDLL(HANDLE proc,string  dllName)
{
//first we need to get a pointer to the loadlibrary function
LPVOID LoadLibAddy =
cast(LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
 //The problem is that we need to pass an argument(string) but that string
is in our memory space
//so we have to allocate space to write our dllName to using
writeprocessmemory
LPVOID RemoteString = VirtualAllocEx(proc,null,dllName.length,MEM_COMMIT |
MEM_RESERVE,PAGE_READWRITE);
 //write the dllName
WriteProcessMemory(proc,RemoteString,toStringz(dllName),dllName.length,null);
 //create a thread in the remote process loading the dll
CreateRemoteThread(proc, null, 0, cast(LPTHREAD_START_ROUTINE)LoadLibAddy,
cast(LPVOID)RemoteString, 0, null);
}

Op 28 maart 2012 13:13 schreef Trass3r <un at known.com> het volgende:

> this works on every dll I try to inject apart from dll's written in D
>> (starting with dmd version 2,054 or something like that).
>>
>
> If this is a regression, please narrow it down to the exact version.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20120411/dc091db6/attachment.html>


More information about the Digitalmars-d-learn mailing list