Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HMODULE LoadStupidDll()
- {
- char szFakeCmdLine[] = "-c";
- char *pOriginal = nullptr;
- char **pGlobalCmdLine = nullptr;
- HMODULE hModule = nullptr;
- // Get GetCommandLineA address
- HMODULE hKernelBase = GetModuleHandle("kernelbase.dll");
- assert(hKernelBase != nullptr);
- FARPROC pGetCommandLineA = GetProcAddress(hKernelBase, "GetCommandLineA");
- assert(pGetCommandLineA != nullptr);
- // Remove memory protections
- DWORD oldProtect;
- assert(VirtualProtect(pGetCommandLineA, 64, PAGE_EXECUTE_READWRITE, &oldProtect));
- // Save original pointer
- pGlobalCmdLine = *reinterpret_cast<char***>((char*)pGetCommandLineA + 1);
- pOriginal = *pGlobalCmdLine;
- // Replace pointer with our fake cmd line
- *pGlobalCmdLine = szFakeCmdLine;
- // Load stupid DLL
- hModule = LoadLibrary(STUPID_DLL_NAME);
- // Restore original string
- *pGlobalCmdLine = pOriginal;
- // Restore memory protection
- assert(VirtualProtect(pGetCommandLineA, 64, oldProtect, &oldProtect));
- return hModule;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement