Skip to content

Commit

Permalink
Remove dynamic code optouts.
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhngtu committed Dec 31, 2023
1 parent cdfb104 commit bfe08d9
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 55 deletions.
48 changes: 0 additions & 48 deletions NanaZip.Shared/Mitigations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,6 @@ namespace
dwLength);
}

static BOOL SetThreadInformationWrapper(
_In_ HANDLE hThread,
_In_ THREAD_INFORMATION_CLASS ThreadInformationClass,
_In_ LPVOID ThreadInformation,
_In_ DWORD ThreadInformationSize)
{
static FARPROC CachedProcAddress = ([]() -> FARPROC
{
HMODULE ModuleHandle = ::GetKernel32ModuleHandle();
if (ModuleHandle)
{
return ::GetProcAddress(
ModuleHandle,
"SetThreadInformation");
}
return nullptr;
}());

if (!CachedProcAddress)
{
return FALSE;
}

using ProcType = decltype(::SetThreadInformation)*;

return reinterpret_cast<ProcType>(CachedProcAddress)(
hThread,
ThreadInformationClass,
ThreadInformation,
ThreadInformationSize);
}

static bool IsWindows8OrLater()
{
static bool CachedResult = ::MileIsWindowsVersionAtLeast(6, 2, 0);
Expand Down Expand Up @@ -127,7 +95,6 @@ EXTERN_C BOOL WINAPI NanaZipEnableMitigations()
{
PROCESS_MITIGATION_DYNAMIC_CODE_POLICY Policy = { 0 };
Policy.ProhibitDynamicCode = 1;
Policy.AllowThreadOptOut = 1;
if (!::SetProcessMitigationPolicyWrapper(
ProcessDynamicCodePolicy,
&Policy,
Expand All @@ -154,18 +121,3 @@ EXTERN_C BOOL WINAPI NanaZipEnableMitigations()

return TRUE;
}

EXTERN_C BOOL WINAPI NanaZipThreadDynamicCodeAllow()
{
if (!::IsWindows8Point1OrLater())
{
return TRUE;
}

DWORD ThreadPolicy = THREAD_DYNAMIC_CODE_ALLOW;
return ::SetThreadInformationWrapper(
::GetCurrentThread(),
ThreadDynamicCodePolicy,
&ThreadPolicy,
sizeof(DWORD));
}
1 change: 0 additions & 1 deletion NanaZip.Shared/Mitigations.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
#include <Windows.h>

EXTERN_C BOOL WINAPI NanaZipEnableMitigations();
EXTERN_C BOOL WINAPI NanaZipThreadDynamicCodeAllow();

#endif // !NANAZIP_SHARED_MITIGATIONS
6 changes: 0 additions & 6 deletions NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/FileManager/FM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,12 +688,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
ErrorMessage("Cannot enable security mitigations");
}

#ifdef NDEBUG
// opt out of dynamic code policy on UI thread to prevent Explorer extension incompatibility
// ignore errors since they shouldn't be fatal
::NanaZipThreadDynamicCodeAllow();
#endif

try
{
try
Expand Down

0 comments on commit bfe08d9

Please sign in to comment.