MCPcopy Create free account
hub / github.com/ConEmu/ConEmu / OnShellExecuteA

Method OnShellExecuteA

src/ConEmuHk/ShellProcessor.cpp:2369–2430  ·  view source on GitHub ↗

returns FALSE if need to block execution

Source from the content-addressed store, hash-verified

2367
2368// returns FALSE if need to block execution
2369BOOL CShellProc::OnShellExecuteA(LPCSTR* asAction, LPCSTR* asFile, LPCSTR* asParam, LPCSTR* asDir, DWORD* anFlags, DWORD* anShowCmd)
2370{
2371 if (!IsInterceptionEnabled())
2372 {
2373 LogShellString(L"OnShellExecuteA skipped");
2374 return TRUE; // don't intercept, pass to kernel
2375 }
2376
2377 if (GetCurrentThreadId() == gnHookMainThreadId)
2378 {
2379 mb_InShellExecuteEx = TRUE;
2380 gnInShellExecuteEx ++;
2381 }
2382
2383 mpwsz_TempAction = str2wcs(asAction ? *asAction : nullptr, mn_CP);
2384 mpwsz_TempFile = str2wcs(asFile ? *asFile : nullptr, mn_CP);
2385 mpwsz_TempParam = str2wcs(asParam ? *asParam : nullptr, mn_CP);
2386 const CEStr lsDir(str2wcs(asDir ? *asDir : nullptr, mn_CP));
2387
2388 _ASSERTEX(!mpwsz_TempRetFile && !mpwsz_TempRetParam && !mpwsz_TempRetDir);
2389
2390 const auto prepareResult = PrepareExecuteParams(eShellExecute,
2391 mpwsz_TempAction, mpwsz_TempFile, mpwsz_TempParam, lsDir,
2392 anFlags, nullptr, nullptr, anShowCmd,
2393 nullptr, nullptr, nullptr, // *StdHandles
2394 mpwsz_TempRetFile, mpwsz_TempRetParam, mpwsz_TempRetDir);
2395 if (prepareResult == PrepareExecuteResult::Restrict)
2396 return false;
2397
2398 const bool changed = (prepareResult == PrepareExecuteResult::Modified);
2399
2400 if (mpwsz_TempRetFile && *mpwsz_TempRetFile)
2401 {
2402 mpsz_TempRetFile = wcs2str(mpwsz_TempRetFile, mn_CP);
2403 if (asFile)
2404 *asFile = mpsz_TempRetFile;
2405 else if (mpsz_TempRetFile && *mpsz_TempRetFile)
2406 return false; // something went wrong
2407 }
2408 else if (changed)
2409 {
2410 if (asFile)
2411 *asFile = nullptr;
2412 }
2413
2414 if (changed || mpwsz_TempRetParam)
2415 {
2416 mpsz_TempRetParam = wcs2str(mpwsz_TempRetParam, mn_CP);
2417 if (asParam)
2418 *asParam = mpsz_TempRetParam;
2419 else if (mpsz_TempRetParam && *mpsz_TempRetParam)
2420 return false; // something went wrong
2421 }
2422
2423 if (mpwsz_TempRetDir && asDir)
2424 {
2425 mpsz_TempRetDir = wcs2str(mpwsz_TempRetDir, mn_CP);
2426 *asDir = mpsz_TempRetDir;

Callers 2

OnShellExecuteAFunction · 0.80
TEST_FFunction · 0.80

Calls

no outgoing calls

Tested by 1

TEST_FFunction · 0.64