1
0
Fork 0
mirror of https://gitlab.com/niansa/PolicyToolLib.git synced 2025-03-06 20:48:27 +01:00
PolicyToolLib/modules/LibInherit.hpp
2023-01-18 15:57:01 +01:00

46 lines
2.3 KiB
C++

#include "../main.h"
#include "ModuleBase.hpp"
#include <windows.h>
#include <detours.h>
class LibInherit : public ModuleBase {
inline static decltype(&CreateProcessA) TrueCreateProcessA;
inline static decltype(&CreateProcessW) TrueCreateProcessW;
static
BOOL WINAPI DetourCreateProcessA(_In_opt_ LPCSTR lpApplicationName, _Inout_opt_ LPSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles, _In_ DWORD dwCreationFlags, _In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCSTR lpCurrentDirectory, _In_ LPSTARTUPINFOA lpStartupInfo, _Out_ LPPROCESS_INFORMATION lpProcessInformation
) {
return DetourCreateProcessWithDllExA(lpApplicationName, lpCommandLine, lpProcessAttributes,
lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory,
lpStartupInfo, lpProcessInformation, sDetourLibrary, TrueCreateProcessA);
}
static
BOOL WINAPI DetourCreateProcessW(_In_opt_ LPCWSTR lpApplicationName, _Inout_opt_ LPWSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles, _In_ DWORD dwCreationFlags, _In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCWSTR lpCurrentDirectory, _In_ LPSTARTUPINFOW lpStartupInfo, _Out_ LPPROCESS_INFORMATION lpProcessInformation
) {
return DetourCreateProcessWithDllExW(lpApplicationName, lpCommandLine, lpProcessAttributes,
lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory,
lpStartupInfo, lpProcessInformation, sDetourLibrary, TrueCreateProcessW);
}
public:
LibInherit() {
TrueCreateProcessA = CreateProcessA;
TrueCreateProcessW = CreateProcessW;
DetourAttach(&reinterpret_cast<PVOID&>(TrueCreateProcessA), reinterpret_cast<void*>(DetourCreateProcessA));
DetourAttach(&reinterpret_cast<PVOID&>(TrueCreateProcessW), reinterpret_cast<void*>(DetourCreateProcessW));
}
~LibInherit() {
DetourDetach(&reinterpret_cast<PVOID&>(TrueCreateProcessA), reinterpret_cast<void*>(DetourCreateProcessA));
DetourDetach(&reinterpret_cast<PVOID&>(TrueCreateProcessW), reinterpret_cast<void*>(DetourCreateProcessW));
}
};