Skip to content

Commit

Permalink
Fix 108+ Crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
mpamxl committed Oct 15, 2023
1 parent 7f25dbb commit 55dc4dd
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/green.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,36 @@ NET_API_STATUS WINAPI MyNetUserGetInfo(
return ret;
}

#define PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_ON (0x00000001ui64 << 44)

typedef BOOL(WINAPI *pUpdateProcThreadAttribute)(
LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList,
DWORD dwFlags,
DWORD_PTR Attribute,
PVOID lpValue,
SIZE_T cbSize,
PVOID lpPreviousValue,
PSIZE_T lpReturnSize);

pUpdateProcThreadAttribute RawUpdateProcThreadAttribute = nullptr;

BOOL WINAPI MyUpdateProcThreadAttribute(
__inout LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList,
__in DWORD dwFlags,
__in DWORD_PTR Attribute,
__in_bcount_opt(cbSize) PVOID lpValue,
__in SIZE_T cbSize,
__out_bcount_opt(cbSize) PVOID lpPreviousValue,
__in_opt PSIZE_T lpReturnSize)
{
if (Attribute == PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY && cbSize >= sizeof(DWORD64))
{
PDWORD64 policy_value_1 = &((PDWORD64)lpValue)[0];
*policy_value_1 &= ~PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_ON;
}
return RawUpdateProcThreadAttribute(lpAttributeList, dwFlags, Attribute, lpValue, cbSize, lpPreviousValue, lpReturnSize);
}

void MakeGreen()
{
HMODULE kernel32 = LoadLibraryW(L"kernel32.dll");
Expand Down Expand Up @@ -247,4 +277,16 @@ void MakeGreen()
DebugLog(L"MH_CreateHook NetUserGetInfo failed:%d", status);
}
}

LPVOID ppUpdateProcThreadAttribute = nullptr;
MH_STATUS status = MH_CreateHookApiEx(L"kernel32", "UpdateProcThreadAttribute",
&MyUpdateProcThreadAttribute, (LPVOID *)&RawUpdateProcThreadAttribute, &ppUpdateProcThreadAttribute);
if (status == MH_OK)
{
MH_EnableHook(ppUpdateProcThreadAttribute);
}
else
{
DebugLog(L"MH_CreateHookApiEx UpdateProcThreadAttribute failed: %d", status);
}
}

0 comments on commit 55dc4dd

Please sign in to comment.