mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-09-21 12:49:40 +08:00
frontend: Merge Windows process mitigation functions
We already started using SetProcessMitigationPolicy before #5164 got merged and we dropped Windows 7 support, so we can do away with the runtime detection too.
This commit is contained in:
committed by
Ryan Foster
parent
f6495d0017
commit
091dbeec81
+20
-33
@@ -811,38 +811,6 @@ static void load_debug_privilege(void)
|
||||
|
||||
CloseHandle(token);
|
||||
}
|
||||
|
||||
static void set_process_mitigations(void)
|
||||
{
|
||||
// SetProcessMitigationPolicy is Windows 8+
|
||||
typedef BOOL(WINAPI * PFN_SetProcessMitigationPolicy)(PROCESS_MITIGATION_POLICY, PVOID, SIZE_T);
|
||||
PFN_SetProcessMitigationPolicy pSetProcessMitigationPolicy;
|
||||
|
||||
pSetProcessMitigationPolicy = (PFN_SetProcessMitigationPolicy)GetProcAddress(GetModuleHandle(L"KERNEL32"),
|
||||
"SetProcessMitigationPolicy");
|
||||
|
||||
if (pSetProcessMitigationPolicy) {
|
||||
PROCESS_MITIGATION_DEP_POLICY dep = {0};
|
||||
dep.DisableAtlThunkEmulation = 1;
|
||||
dep.Enable = 1;
|
||||
dep.Permanent = TRUE;
|
||||
pSetProcessMitigationPolicy(ProcessDEPPolicy, &dep, sizeof(dep));
|
||||
|
||||
PROCESS_MITIGATION_ASLR_POLICY aslr = {0};
|
||||
aslr.EnableBottomUpRandomization = 1;
|
||||
aslr.EnableHighEntropy = 1;
|
||||
aslr.EnableForceRelocateImages = 1;
|
||||
aslr.DisallowStrippedImages = 1;
|
||||
pSetProcessMitigationPolicy(ProcessASLRPolicy, &aslr, sizeof(aslr));
|
||||
|
||||
#ifdef _DEBUG
|
||||
PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY hcheck = {0};
|
||||
hcheck.RaiseExceptionOnInvalidHandleReference = 1;
|
||||
hcheck.HandleExceptionsPermanentlyEnabled = 1;
|
||||
pSetProcessMitigationPolicy(ProcessStrictHandleCheckPolicy, &hcheck, sizeof(hcheck));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline bool arg_is(const char *arg, const char *long_form, const char *short_form)
|
||||
@@ -882,6 +850,26 @@ static void set_process_mitigation_policies()
|
||||
PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {};
|
||||
policy.PreferSystem32Images = 1;
|
||||
SetProcessMitigationPolicy(ProcessImageLoadPolicy, &policy, sizeof(policy));
|
||||
|
||||
PROCESS_MITIGATION_DEP_POLICY dep = {0};
|
||||
dep.DisableAtlThunkEmulation = 1;
|
||||
dep.Enable = 1;
|
||||
dep.Permanent = TRUE;
|
||||
SetProcessMitigationPolicy(ProcessDEPPolicy, &dep, sizeof(dep));
|
||||
|
||||
PROCESS_MITIGATION_ASLR_POLICY aslr = {0};
|
||||
aslr.EnableBottomUpRandomization = 1;
|
||||
aslr.EnableHighEntropy = 1;
|
||||
aslr.EnableForceRelocateImages = 1;
|
||||
aslr.DisallowStrippedImages = 1;
|
||||
SetProcessMitigationPolicy(ProcessASLRPolicy, &aslr, sizeof(aslr));
|
||||
|
||||
#ifdef _DEBUG
|
||||
PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY hcheck = {0};
|
||||
hcheck.RaiseExceptionOnInvalidHandleReference = 1;
|
||||
hcheck.HandleExceptionsPermanentlyEnabled = 1;
|
||||
SetProcessMitigationPolicy(ProcessStrictHandleCheckPolicy, &hcheck, sizeof(hcheck));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -951,7 +939,6 @@ int main(int argc, char *argv[])
|
||||
SetDllDirectoryW(L"");
|
||||
load_debug_privilege();
|
||||
base_set_crash_handler(main_crash_handler, nullptr);
|
||||
set_process_mitigations();
|
||||
|
||||
/* Shutdown priority value is a range from 0 - 4FF with higher values getting first priority.
|
||||
* 000 - 0FF and 400 - 4FF are reserved system ranges.
|
||||
|
||||
Reference in New Issue
Block a user