From 4dfe8b15b3e230c35d0e7fcd59b15d4eb9287b2d Mon Sep 17 00:00:00 2001 From: p0358 Date: Fri, 31 May 2024 07:53:58 +0200 Subject: [PATCH] hotfix: Titanfall_alt.exe not being updated by installer + mitigation applying failure error being displayed for non-CET CPUs --- bme_version.txt | 2 +- installer/installer_simple2.iss | 2 +- loader_launcher_exe/main.cpp | 26 ++++++++++++++++++++++++-- loader_launcher_proxy/dllmain.cpp | 24 +++++++++++++++++++++++- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/bme_version.txt b/bme_version.txt index caf1cc4..ce2ef70 100644 --- a/bme_version.txt +++ b/bme_version.txt @@ -1 +1 @@ -1b11 \ No newline at end of file +1b12 \ No newline at end of file diff --git a/installer/installer_simple2.iss b/installer/installer_simple2.iss index 2725f5f..cb9f4c5 100644 --- a/installer/installer_simple2.iss +++ b/installer/installer_simple2.iss @@ -79,7 +79,7 @@ Source: "source\bme\crashpad_wer.dll"; DestDir: "{app}\bme"; Flags: ignoreversio Source: "source\r1\media\fov_video_15ms_480x400.bik"; DestDir: "{app}\r1\media"; Flags: ignoreversion onlyifdoesntexist Source: "{app}\bin\x64_retail\launcher.dll"; DestDir: "{app}\bin\x64_retail"; DestName: "launcher.org.dll"; Flags: external skipifsourcedoesntexist onlyifdoesntexist uninsneveruninstall Source: "source\bin\x64_retail\launcher.dll"; DestDir: "{app}\bin\x64_retail"; Flags: ignoreversion uninsneveruninstall -Source: "source\Titanfall_alt.exe"; DestDir: "{app}"; Flags: ignoreversion onlyifdoesntexist +Source: "source\Titanfall_alt.exe"; DestDir: "{app}"; Flags: ignoreversion [InstallDelete] ; old loaders from beta diff --git a/loader_launcher_exe/main.cpp b/loader_launcher_exe/main.cpp index f73c706..75eac4e 100644 --- a/loader_launcher_exe/main.cpp +++ b/loader_launcher_exe/main.cpp @@ -3,10 +3,11 @@ #include #include +#include #include #include -#include +#include #define ERROR_MESSAGE_CAPTION "BME Launcher EXE error" @@ -52,6 +53,23 @@ bool IsAnyIMEInstalled() return false; } +bool DoesCpuSupportCetShadowStack() +{ + int cpuInfo[4] = { 0, 0, 0, 0 }; + __cpuidex(cpuInfo, 7, 0); + return (cpuInfo[2] & (1 << 7)) != 0; // Check bit 7 in ECX (cpuInfo[2]) +} + +std::unordered_map g_mitigationPolicyNames = { + { ProcessASLRPolicy, "ProcessASLRPolicy" }, + { ProcessDynamicCodePolicy, "ProcessDynamicCodePolicy" }, + { ProcessExtensionPointDisablePolicy, "ProcessExtensionPointDisablePolicy" }, + { ProcessControlFlowGuardPolicy, "ProcessControlFlowGuardPolicy" }, + { ProcessSignaturePolicy, "ProcessSignaturePolicy" }, + { ProcessImageLoadPolicy, "ProcessImageLoadPolicy" }, + { ProcessUserShadowStackPolicy, "ProcessUserShadowStackPolicy" }, +}; + void SetMitigationPolicies() { auto kernel32 = GetModuleHandleW(L"kernel32.dll"); @@ -66,8 +84,12 @@ void SetMitigationPolicies() bool result = SetProcessMitigationPolicy(MitigationPolicy, lpBuffer, dwLength); if (!result) { + if (MitigationPolicy == ProcessUserShadowStackPolicy && !DoesCpuSupportCetShadowStack()) + return; auto lastError = GetLastError(); - MessageBoxA(0, ("Failed mitigation: " + std::to_string(MitigationPolicy) + ", error: " + std::to_string(lastError)).c_str(), + MessageBoxA(0, ("Failed mitigation: " + + (g_mitigationPolicyNames.contains(MitigationPolicy) ? g_mitigationPolicyNames[MitigationPolicy] : std::to_string(MitigationPolicy)) + + ", error: " + std::to_string(lastError) + "\n\nThis is a non-fatal error.").c_str(), "BME: SetProcessMitigationPolicy failed", 0); } }; diff --git a/loader_launcher_proxy/dllmain.cpp b/loader_launcher_proxy/dllmain.cpp index cb8de53..404efc0 100644 --- a/loader_launcher_proxy/dllmain.cpp +++ b/loader_launcher_proxy/dllmain.cpp @@ -5,6 +5,7 @@ #include #include +#include #define ERROR_MESSAGE_CAPTION "BME Launcher DLL Error" @@ -81,6 +82,23 @@ bool IsAnyIMEInstalled() return false; } +bool DoesCpuSupportCetShadowStack() +{ + int cpuInfo[4] = { 0, 0, 0, 0 }; + __cpuidex(cpuInfo, 7, 0); + return (cpuInfo[2] & (1 << 7)) != 0; // Check bit 7 in ECX (cpuInfo[2]) +} + +std::unordered_map g_mitigationPolicyNames = { + { ProcessASLRPolicy, "ProcessASLRPolicy" }, + { ProcessDynamicCodePolicy, "ProcessDynamicCodePolicy" }, + { ProcessExtensionPointDisablePolicy, "ProcessExtensionPointDisablePolicy" }, + { ProcessControlFlowGuardPolicy, "ProcessControlFlowGuardPolicy" }, + { ProcessSignaturePolicy, "ProcessSignaturePolicy" }, + { ProcessImageLoadPolicy, "ProcessImageLoadPolicy" }, + { ProcessUserShadowStackPolicy, "ProcessUserShadowStackPolicy" }, +}; + void SetMitigationPolicies() { auto kernel32 = GetModuleHandleW(L"kernel32.dll"); @@ -95,8 +113,12 @@ void SetMitigationPolicies() bool result = SetProcessMitigationPolicy(MitigationPolicy, lpBuffer, dwLength); if (!result) { + if (MitigationPolicy == ProcessUserShadowStackPolicy && !DoesCpuSupportCetShadowStack()) + return; auto lastError = GetLastError(); - MessageBoxA(0, ("Failed mitigation: " + std::to_string(MitigationPolicy) + ", error: " + std::to_string(lastError)).c_str(), + MessageBoxA(0, ("Failed mitigation: " + + (g_mitigationPolicyNames.contains(MitigationPolicy) ? g_mitigationPolicyNames[MitigationPolicy] : std::to_string(MitigationPolicy)) + + ", error: " + std::to_string(lastError) + "\n\nThis is a non-fatal error.").c_str(), "BME: SetProcessMitigationPolicy failed", 0); } };