c++ - DLLMain() is not being executed after injection -
i have written dll , injector in c++. dll code given below:
#include <cstdio> #include <stdio.h> #include <windows.h> #include <string> #include <fstream> #include <winsock.h> using namespace std; #pragma comment(lib, "wsock32.lib") extern "c" __declspec(dllexport) void uploadfile() { ..... } int apientry dllmain(hmodule hinstdll, dword fdwreason, lpvoid lpreserved) { switch(fdwreason) { case dll_process_attach: messagebox(0,"process attach","info",mb_ok); uploadfile(); break; case dll_thread_attach: messagebox(0,"thread attach","info",mb_ok); uploadfile(); break; case dll_process_detach: break; case dll_thread_detach: break; default: break; } return true; } the dll uploads particular file server. able inject dll "notepad.exe" using loadlibrary() , createremotethread() not being executed. not dllmain() function. dont know wrong.
as dirk has stated, dll entry point named dllmain(), not dllmain(). signature dllmain() is:
bool winapi dllmain( hinstance hinstdll, dword fdwreason, lpvoid lpvreserved ); from best practices creating dlls , should never perform following tasks within dllmain():
...call functions in user32.dll or gdi32.dll. functions load dll, may not initialized...
messagebox() implemented in user32.dll may possible cause of dllmain() appearing not invoked.
it unwise perform time consuming tasks dllmain() prevent application loading other dlls requires, loader lock held when inside dllmain(). instead, spawn thread perform time consuming task. linked document advises against using createthread() if synchronization involved.
Comments
Post a Comment