MCPcopy Create free account
hub / github.com/acl-dev/acl / DetourProcessViaHelperDllsA

Function DetourProcessViaHelperDllsA

lib_fiber/cpp/src/detours/creatwth.cpp:1343–1432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1341
1342
1343BOOL WINAPI DetourProcessViaHelperDllsA(_In_ DWORD dwTargetPid,
1344 _In_ DWORD nDlls,
1345 _In_reads_(nDlls) LPCSTR *rlpDlls,
1346 _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA)
1347{
1348 BOOL Result = FALSE;
1349 PROCESS_INFORMATION pi;
1350 STARTUPINFOA si;
1351 CHAR szExe[MAX_PATH];
1352 CHAR szCommand[MAX_PATH];
1353 PDETOUR_EXE_HELPER helper = NULL;
1354 HRESULT hr;
1355 DWORD nLen = GetEnvironmentVariableA("WINDIR", szExe, ARRAYSIZE(szExe));
1356
1357 DETOUR_TRACE(("DetourProcessViaHelperDlls(pid=%lu,dlls=%lu)\n", dwTargetPid, nDlls));
1358 if (nDlls < 1 || nDlls > 4096) {
1359 SetLastError(ERROR_INVALID_PARAMETER);
1360 goto Cleanup;
1361 }
1362 if (!AllocExeHelper(&helper, dwTargetPid, nDlls, rlpDlls)) {
1363 goto Cleanup;
1364 }
1365
1366 if (nLen == 0 || nLen >= ARRAYSIZE(szExe)) {
1367 goto Cleanup;
1368 }
1369
1370#if DETOURS_OPTION_BITS
1371#if DETOURS_32BIT
1372 hr = StringCchCatA(szExe, ARRAYSIZE(szExe), "\\sysnative\\rundll32.exe");
1373#else // !DETOURS_32BIT
1374 hr = StringCchCatA(szExe, ARRAYSIZE(szExe), "\\syswow64\\rundll32.exe");
1375#endif // !DETOURS_32BIT
1376#else // DETOURS_OPTIONS_BITS
1377 hr = StringCchCatA(szExe, ARRAYSIZE(szExe), "\\system32\\rundll32.exe");
1378#endif // DETOURS_OPTIONS_BITS
1379 if (!SUCCEEDED(hr)) {
1380 goto Cleanup;
1381 }
1382
1383 //for East Asia languages and so on, like Chinese, print format with "%hs" can not work fine before user call _tsetlocale(LC_ALL,_T(".ACP"));
1384 //so we can't use "%hs" in format string, because the dll that contain this code would inject to any process, even not call _tsetlocale(LC_ALL,_T(".ACP")) before
1385 hr = StringCchPrintfA(szCommand, ARRAYSIZE(szCommand),
1386 "rundll32.exe \"%s\",#1", &helper->rDlls[0]);
1387 if (!SUCCEEDED(hr)) {
1388 goto Cleanup;
1389 }
1390
1391 ZeroMemory(&pi, sizeof(pi));
1392 ZeroMemory(&si, sizeof(si));
1393 si.cb = sizeof(si);
1394
1395 DETOUR_TRACE(("DetourProcessViaHelperDlls(\"%hs\", \"%hs\")\n", szExe, szCommand));
1396 if (pfCreateProcessA(szExe, szCommand, NULL, NULL, FALSE, CREATE_SUSPENDED,
1397 NULL, NULL, &si, &pi)) {
1398
1399 if (!DetourCopyPayloadToProcess(pi.hProcess,
1400 DETOUR_EXE_HELPER_GUID,

Callers 2

DetourProcessViaHelperAFunction · 0.85

Calls 4

AllocExeHelperFunction · 0.85
StringCchCatAFunction · 0.85
FreeExeHelperFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…