简体   繁体   中英

LoadLibraryA Remote Thread Injection succeeds but doesnt load dll

The code I am using is:

if(hwndMSWP && hProc && hProc != INVALID_HANDLE_VALUE && filePath.size() > 20) {
        QByteArray const path = filePath.toLocal8Bit(); // < filePath definitely has the right path with backslashes
        LPVOID const allocMemAddr = VirtualAllocEx(hProc, 0, MAX_PATH, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
        if(!allocMemAddr) {
            MessageBoxA(0, "ERROR: Couldn't allocate memory!", "Injection Error", 0);
            return;
        }
        if(!WriteProcessMemory(hProc, allocMemAddr, (LPVOID)path.constData(), path.size(), 0)) {
            MessageBoxA(0, "ERROR: Couldn't write memory!", "Injection Error", 0);
            clean(allocMemAddr);
            return;
        }
        FARPROC libraryAddress = GetProcAddress(GetModuleHandle(L"kernel32"), "LoadLibraryA");
        if(!libraryAddress) {
            MessageBoxA(0, "ERROR: Couldn't get kernel32 export function address!", "Injection Error", 0);
            clean(allocMemAddr);
            return;
        }
        DWORD dwThreadId;
        HANDLE hRemoteThread = CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)libraryAddress, allocMemAddr, 0, &dwThreadId);
        if(!hRemoteThread || hRemoteThread == INVALID_HANDLE_VALUE) {
            dwThreadId = 0;
            clean(allocMemAddr);
            MessageBoxA(0, "ERROR: Couldn't create remote thread!", "Injection Error", 0);
            return;
        }
        WaitForSingleObject(hRemoteThread, INFINITE);
        CloseHandle(hRemoteThread);
        clean(allocMemAddr);
        MessageBoxA(0, "Injected successfully!", "Injection Successfull", 0);
    }

everything is defined and properly setup. ive also debugged using x64dbg. it shows a new thread being created. but i also set a breakpoint at LoadLibraryA, which doesnt get hit.

Ive been working on this one single error over the course of the last hour and i hope that you have a different sight on this.

I was building my injector exe into a x64 executable. Qt 6.0 and up dont provide x86 compilers. I switched my release build to x86 and then the injecting worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM