int main(int argc, char *argv[]) { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); ZeroMemory(&pi, sizeof(pi)); si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_SHOW; if (!DetourCreateProcessWithDllEx("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe", NULL, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,// | CREATE_SUSPENDED, NULL, NULL, &si, &pi, "C:\\Users\\Itay\\Documents\\Visual Studio 2013\\Projects\\19.5 try\\HookDll\\Debug\\HookDll.dll", NULL)) MessageBox(0, "failed", 0, 0); else MessageBox(0, "success", 0, 0); ResumeThread(pi.hThread); WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(&si); CloseHandle(&pi); return EXIT_SUCCESS; }
bool MapleLauncher::StartProcess() { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); ZeroMemory(&pi, sizeof(pi)); QString dllPath; dllPath = qApp->applicationDirPath() + "/Client.dll"; std::string dll = dllPath.toStdString(); std::vector<CHAR> V( dll.length() + 1); for (int i=0;i< (int)dll.length();i++) V[i] = dll[i]; if(!DetourCreateProcessWithDllEx(this->strProcess.c_str(), NULL, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi, &V[0], NULL) ) { return false; } WaitForInputIdle(pi.hProcess, INFINITE); this->hProcess = pi.hProcess; this->dwProcessId = pi.dwProcessId; return true; }
BOOL APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { PCHAR pszDllPath = "Accelerator.dll"; CHAR szDllPath[1024]; PCHAR pszFilePart = NULL; if (!GetFullPathName(pszDllPath, ARRAYSIZE(szDllPath), szDllPath, &pszFilePart)) { MessageBoxA(NULL, "GetFullPathName Failed\n", "Error", MB_OK); return false; } HMODULE hDll = LoadLibraryEx(pszDllPath, NULL, DONT_RESOLVE_DLL_REFERENCES); if (hDll == NULL) { MessageBoxA(NULL, "Failed to load dll\n", "Error", MB_OK); return false; } ExportContext ec; ec.fHasOrdinal1 = FALSE; ec.nExports = 0; DetourEnumerateExports(hDll, &ec, ExportCallback); FreeLibrary(hDll); if (!ec.fHasOrdinal1) { MessageBoxA(NULL, "This dll does not export ordinal #1.\n", "Error", MB_OK); return false; } ////////////////////////////////////////////////////////////////////////////////// STARTUPINFO si; PROCESS_INFORMATION pi; CHAR szCommand[2048]; CHAR szExe[1024]; CHAR szFullExe[1024] = "\0"; PCHAR pszFileExe = NULL; ZeroMemory(&si, sizeof(si)); ZeroMemory(&pi, sizeof(pi)); si.cb = sizeof(si); szCommand[0] = L'\0'; strcpy(szExe, "LOVESICK_PUPPIES.exe"); strcpy(szCommand, "LOVESICK_PUPPIES.exe"); ////////////////////////////////////////////////////////////////////////////////// DWORD dwFlags = CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED; SetLastError(0); SearchPath(NULL, szExe, ".exe", ARRAYSIZE(szFullExe), szFullExe, &pszFileExe); if (!DetourCreateProcessWithDllEx(szFullExe[0] ? szFullExe : NULL, szCommand, NULL, NULL, TRUE, dwFlags, NULL, NULL, &si, &pi, szDllPath, NULL)) { DWORD dwError = GetLastError(); MessageBoxA(NULL, "DetourCreateProcessWithDllEx failed\n", "Error", MB_OK); if (dwError == ERROR_INVALID_HANDLE) { #if DETOURS_64BIT MessageBoxA(NULL, " Can't detour a 32-bit target process from a 64-bit parent process.\n", "Error", MB_OK); #else MessageBoxA(NULL, " Can't detour a 64-bit target process from a 32-bit parent process.\n", "Error", MB_OK); #endif } ExitProcess(9009); } ResumeThread(pi.hThread); WaitForSingleObject(pi.hProcess, INFINITE); DWORD dwResult = 0; if (!GetExitCodeProcess(pi.hProcess, &dwResult)) { MessageBoxA(NULL, "GetExitCodeProcess failed\n", "Error", MB_OK); return false; } return true; }
//////////////////////////////////////////////////////////////////////// main. // int CDECL main(int argc, char **argv) { BOOLEAN fNeedHelp = FALSE; BOOLEAN fVerbose = FALSE; PCHAR pszDllPath = NULL; int arg = 1; for (; arg < argc && (argv[arg][0] == '-' || argv[arg][0] == '/'); arg++) { CHAR *argn = argv[arg] + 1; CHAR *argp = argn; while (*argp && *argp != ':' && *argp != '=') argp++; if (*argp == ':' || *argp == '=') *argp++ = '\0'; switch (argn[0]) { case 'd': // Set DLL Name case 'D': pszDllPath = argp; break; case 'v': // Verbose case 'V': fVerbose = TRUE; break; case '?': // Help fNeedHelp = TRUE; break; default: fNeedHelp = TRUE; printf("withdll.exe: Bad argument: %s\n", argv[arg]); break; } } if (arg >= argc) { fNeedHelp = TRUE; } if (pszDllPath == NULL) { fNeedHelp = TRUE; } if (fNeedHelp) { PrintUsage(); return 9001; } /////////////////////////////////////////////////////////// Validate DLLs. // CHAR szDllPath[1024]; PCHAR pszFilePart = NULL; if (!GetFullPathName(pszDllPath, ARRAYSIZE(szDllPath), szDllPath, &pszFilePart)) { printf("withdll.exe: Error: %s is not a valid path name..\n", pszDllPath); return 9002; } HMODULE hDll = LoadLibraryEx(pszDllPath, NULL, DONT_RESOLVE_DLL_REFERENCES); if (hDll == NULL) { printf("withdll.exe: Error: %s failed to load (error %d).\n", pszDllPath, GetLastError()); return 9003; } ExportContext ec; ec.fHasOrdinal1 = FALSE; ec.nExports = 0; DetourEnumerateExports(hDll, &ec, ExportCallback); FreeLibrary(hDll); if (!ec.fHasOrdinal1) { printf("withdll.exe: Error: %s does not export ordinal #1.\n", pszDllPath); printf(" See help entry DetourCreateProcessWithDllEx in Detours.chm.\n"); return 9004; } ////////////////////////////////////////////////////////////////////////// STARTUPINFO si; PROCESS_INFORMATION pi; CHAR szCommand[2048]; CHAR szExe[1024]; CHAR szFullExe[1024] = "\0"; PCHAR pszFileExe = NULL; ZeroMemory(&si, sizeof(si)); ZeroMemory(&pi, sizeof(pi)); si.cb = sizeof(si); szCommand[0] = L'\0'; #ifdef _CRT_INSECURE_DEPRECATE strcpy_s(szExe, sizeof(szExe), argv[arg]); #else strcpy(szExe, argv[arg]); #endif for (; arg < argc; arg++) { if (strchr(argv[arg], ' ') != NULL || strchr(argv[arg], '\t') != NULL) { #ifdef _CRT_INSECURE_DEPRECATE strcat_s(szCommand, sizeof(szCommand), "\""); strcat_s(szCommand, sizeof(szCommand), argv[arg]); strcat_s(szCommand, sizeof(szCommand), "\""); #else strcat(szCommand, "\""); strcat(szCommand, argv[arg]); strcat(szCommand, "\""); #endif } else { #ifdef _CRT_INSECURE_DEPRECATE strcat_s(szCommand, sizeof(szCommand), argv[arg]); #else strcat(szCommand, argv[arg]); #endif } if (arg + 1 < argc) { #ifdef _CRT_INSECURE_DEPRECATE strcat_s(szCommand, sizeof(szCommand), " "); #else strcat(szCommand, " "); #endif } } printf("withdll.exe: Starting: `%s'\n", szCommand); printf("withdll.exe: with `%s'\n", szDllPath); fflush(stdout); DWORD dwFlags = CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED; SetLastError(0); SearchPath(NULL, szExe, ".exe", ARRAYSIZE(szFullExe), szFullExe, &pszFileExe); if (!DetourCreateProcessWithDllEx(szFullExe[0] ? szFullExe : NULL, szCommand, NULL, NULL, TRUE, dwFlags, NULL, NULL, &si, &pi, szDllPath, NULL)) { DWORD dwError = GetLastError(); printf("withdll.exe: DetourCreateProcessWithDllEx failed: %d\n", dwError); if (dwError == ERROR_INVALID_HANDLE) { #if DETOURS_64BIT printf("withdll.exe: Can't detour a 32-bit target process from a 64-bit parent process.\n"); #else printf("withdll.exe: Can't detour a 64-bit target process from a 32-bit parent process.\n"); #endif } ExitProcess(9009); } if (fVerbose) { DumpProcess(pi.hProcess); } ResumeThread(pi.hThread); WaitForSingleObject(pi.hProcess, INFINITE); DWORD dwResult = 0; if (!GetExitCodeProcess(pi.hProcess, &dwResult)) { printf("withdll.exe: GetExitCodeProcess failed: %d\n", GetLastError()); return 9010; } return dwResult; }