returns FALSE if need to block execution
| 2739 | |
| 2740 | // returns FALSE if need to block execution |
| 2741 | BOOL CShellProc::OnCreateProcessA(LPCSTR* asFile, LPCSTR* asCmdLine, LPCSTR* asDir, DWORD* anCreationFlags, LPSTARTUPINFOA* ppStartupInfo) |
| 2742 | { |
| 2743 | if (!ppStartupInfo || !*ppStartupInfo || !IsInterceptionEnabled()) |
| 2744 | { |
| 2745 | LogShellString(L"OnCreateProcessA skipped"); |
| 2746 | return TRUE; // don't intercept, pass to kernel |
| 2747 | } |
| 2748 | |
| 2749 | const size_t cbLocalStartupInfoSize = std::max<size_t>(sizeof(STARTUPINFOA), (*ppStartupInfo)->cb); |
| 2750 | m_lpStartupInfoA.reset(static_cast<LPSTARTUPINFOA>(calloc(1, cbLocalStartupInfoSize))); |
| 2751 | if (!m_lpStartupInfoA) |
| 2752 | { |
| 2753 | LogShellString(L"OnCreateProcessW failed"); |
| 2754 | return TRUE; // don't intercept, pass to kernel |
| 2755 | } |
| 2756 | auto* lpSi = m_lpStartupInfoA.get(); |
| 2757 | if ((*ppStartupInfo)->cb) |
| 2758 | memmove_s(lpSi, cbLocalStartupInfoSize, *ppStartupInfo, (*ppStartupInfo)->cb); |
| 2759 | else |
| 2760 | lpSi->cb = sizeof(*lpSi); |
| 2761 | |
| 2762 | mpwsz_TempFile = str2wcs(asFile ? *asFile : nullptr, mn_CP); |
| 2763 | mpwsz_TempParam = str2wcs(asCmdLine ? *asCmdLine : nullptr, mn_CP); |
| 2764 | const CEStr lsDir(str2wcs(asDir ? *asDir : nullptr, mn_CP)); |
| 2765 | |
| 2766 | _ASSERTEX(!mpwsz_TempRetFile && !mpwsz_TempRetParam && !mpwsz_TempRetDir); |
| 2767 | |
| 2768 | // Preprocess flags and options |
| 2769 | auto state = OnCreateProcessPrepare(anCreationFlags, lpSi->dwFlags, lpSi->wShowWindow, lpSi->dwX, lpSi->dwY); |
| 2770 | |
| 2771 | const auto prepareResult = PrepareExecuteParams(eCreateProcess, |
| 2772 | nullptr, mpwsz_TempFile, mpwsz_TempParam, lsDir, |
| 2773 | nullptr, anCreationFlags, &lpSi->dwFlags, &state.showCmd, |
| 2774 | &lpSi->hStdInput, &lpSi->hStdOutput, &lpSi->hStdError, |
| 2775 | mpwsz_TempRetFile, mpwsz_TempRetParam, mpwsz_TempRetDir); |
| 2776 | if (prepareResult == PrepareExecuteResult::Restrict) |
| 2777 | return false; |
| 2778 | |
| 2779 | const bool changed = (prepareResult == PrepareExecuteResult::Modified); |
| 2780 | |
| 2781 | // patch flags and variables based on decision |
| 2782 | if (OnCreateProcessResult(prepareResult, state, anCreationFlags, lpSi->wShowWindow, lpSi->dwFlags)) |
| 2783 | *ppStartupInfo = lpSi; |
| 2784 | |
| 2785 | // Patch modified strings (wide to ansi/oem) |
| 2786 | |
| 2787 | if (mpwsz_TempRetFile && *mpwsz_TempRetFile) |
| 2788 | { |
| 2789 | mpsz_TempRetFile = wcs2str(mpwsz_TempRetFile, mn_CP); |
| 2790 | if (asFile) |
| 2791 | *asFile = mpsz_TempRetFile; |
| 2792 | else if (mpsz_TempRetFile && *mpsz_TempRetFile) |
| 2793 | return false; // something went wrong |
| 2794 | } |
| 2795 | else if (changed) |
| 2796 | { |
| 2797 | if (asFile) |
| 2798 | *asFile = nullptr; |