간단한 dll를 지정한 프로세스에 주입

1926 단어 VC
//         DLL 
//  ID         
BOOL LoadDll(DWORD dwProcessId, LPSTR lpszDllName)
{
    HANDLE	hProcess = NULL;
    HANDLE	hThread = NULL;
    PSTR	pszDllFile = NULL;
    //     
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
    if (hProcess == NULL)
    {
        printf("     %d   !

", dwProcessId); return FALSE; } printf(" %d !

", dwProcessId); // int cch = 1 + strlen(lpszDllName); pszDllFile = (PSTR)VirtualAllocEx(hProcess, NULL, cch, MEM_COMMIT, PAGE_READWRITE); if (pszDllFile == NULL) return FALSE; printf(" !

"); // DLL if ((WriteProcessMemory(hProcess, (PVOID)pszDllFile, (PVOID)lpszDllName, cch, NULL)) == FALSE) { return FALSE; } printf(" !

"); // LoadLibrary PTHREAD_START_ROUTINE pfnThreadRtn = (PTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandleA("kernel32"), "LoadLibraryA"); // , LoadLibraryA , //PTHREAD_START_ROUTINE pfnThreadRtn = (PTHREAD_START_ROUTINE)LoadLibraryA; if (pfnThreadRtn == NULL) return FALSE; printf(" LoadLibrary !

"); // hThread = CreateRemoteThread(hProcess, NULL, 0, pfnThreadRtn, (PVOID)pszDllFile, 0, NULL); if (hThread == NULL) return FALSE; printf(" !

"); // , //system("pause"); WaitForSingleObject(hThread, INFINITE); VirtualFreeEx(hProcess, (PVOID)pszDllFile, 0, MEM_RELEASE); CloseHandle(hThread); CloseHandle(hProcess); return TRUE; } // dllmain DLL_PROCESS_ATTACH

비고: 간단한 동적 라이브러리 주입 실현, 학습 참고만

좋은 웹페이지 즐겨찾기