2010-05-02 53 views
0

我正在寻找如何注入一个DLL到程序(EXE,或DLL等)。我一直在googleing dll注入,但我还没有发现任何非常有用的:(我没有与dll工作非常多,所以我不知道该怎么办,我真的可以在这方面使用一些帮助。我唯一真正发现的是setwindowshookex,但我找不到任何例子,我不知道如何使用它。任何问题只是问,我会尽力帮助。是谷歌搜索,这看起来像一些关于DLL注入值得一看,但我不能让代码运行:\(How to hook external process with SetWindowsHookEx and WH_KEYBOARD如何使用dll注入?

回答

0

我最熟悉的方法是w如Jefferey Richter在Programming Applications for Microsoft Windows中所述。我提到这一点,因为即使你没有亲手书本身,也可能有浮动的示例代码。我想他可能也写了一些期刊文章。他还提到了一些替代方法,其中我将只从内存中描述一种方法。他也可能写了一些相关的MSJ/MSDN文章。

无论如何,基本的想法是导致您想要加载DLL的进程发出致电LoadLibrary的进程。这是通过使用CreateRemoteThread来完成的,地址为LoadLibary,对于lpStartAddress以及命名您的DLL的字符串地址为lpParameter。安排和定位字符串是通过使用VirtualAllocEx在远程进程中分配一些内存,并使用WriteProcessMemory来填充字符串。

伪代码:

void InjectDllIntoProcess(DWORD processId, char *dllName) 
{ 
    HANDLE hRemoteProcess = OpenProcess(

    // Assumes that dll and function addresses are the same in different processes 
    // on the same system. I think that this is true even with ASLR, only issue I 
    // can think of is to make sure that the source and target process are both 32 
    // or both 64 bit, not a mixture. 
    // Note that it is asking for the ASCII version 
    HMODULE hDll = LoadLibrary(_T("Kernel32.dll")); 
    void *loadLibAddr = GetProcAddress(hDll, _T("LoadLibraryA")); 


    // Inject the DLL name 
    char * remoteAddr = 
     (char *)VirtualAllocEx(hRemoteProcess, NULL, strlen(dllName) + 1, ... 
    WriteProcessMemory(hRemoteProcess, remoteAddr, dllName, strlen(dllName) + 1 ... 

    CreateRemoteThread(hRemoteProcess, ??, 0, loadLibAddr, remoteAddr, ... 
} 
+0

确定,所以如果它加载我的DLL它将运行我的代码,如果它是它自己的? – blood 2010-05-02 01:05:09

+0

它只会加载库。这确实意味着它会调用DLL的DllMain进行初始化。从那里你可以做任何你需要的其他安排。一旦LoadLibrary调用返回,您创建的用于调用LoadLibrary的线程将会死亡。 – torak 2010-05-02 01:12:37

+0

嗯不错xD这也是这本书里的所有内容吧? http://www.amazon.com/Programming-Applications-Microsoft-Windows-General/dp/1572319968 我可能会购买它,如果它具有所有这一切,它还有什么? – blood 2010-05-02 01:14:46