Skip to content

Commit

Permalink
hotfix: Titanfall_alt.exe not being updated by installer + mitigation…
Browse files Browse the repository at this point in the history
… applying failure error being displayed for non-CET CPUs
  • Loading branch information
p0358 committed May 31, 2024
1 parent 011c41d commit 4dfe8b1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bme_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1b11
1b12
2 changes: 1 addition & 1 deletion installer/installer_simple2.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions loader_launcher_exe/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#include <wtypes.h>
#include <stdio.h>
#include <Shlwapi.h>

#include <string>
#include <system_error>
#include <Shlwapi.h>
#include <unordered_map>

#define ERROR_MESSAGE_CAPTION "BME Launcher EXE error"

Expand Down Expand Up @@ -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<PROCESS_MITIGATION_POLICY, const char*> g_mitigationPolicyNames = {
{ ProcessASLRPolicy, "ProcessASLRPolicy" },
{ ProcessDynamicCodePolicy, "ProcessDynamicCodePolicy" },
{ ProcessExtensionPointDisablePolicy, "ProcessExtensionPointDisablePolicy" },
{ ProcessControlFlowGuardPolicy, "ProcessControlFlowGuardPolicy" },
{ ProcessSignaturePolicy, "ProcessSignaturePolicy" },
{ ProcessImageLoadPolicy, "ProcessImageLoadPolicy" },
{ ProcessUserShadowStackPolicy, "ProcessUserShadowStackPolicy" },
};

void SetMitigationPolicies()
{
auto kernel32 = GetModuleHandleW(L"kernel32.dll");
Expand All @@ -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);
}
};
Expand Down
24 changes: 23 additions & 1 deletion loader_launcher_proxy/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <string>
#include <system_error>
#include <unordered_map>

#define ERROR_MESSAGE_CAPTION "BME Launcher DLL Error"

Expand Down Expand Up @@ -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<PROCESS_MITIGATION_POLICY, const char*> g_mitigationPolicyNames = {
{ ProcessASLRPolicy, "ProcessASLRPolicy" },
{ ProcessDynamicCodePolicy, "ProcessDynamicCodePolicy" },
{ ProcessExtensionPointDisablePolicy, "ProcessExtensionPointDisablePolicy" },
{ ProcessControlFlowGuardPolicy, "ProcessControlFlowGuardPolicy" },
{ ProcessSignaturePolicy, "ProcessSignaturePolicy" },
{ ProcessImageLoadPolicy, "ProcessImageLoadPolicy" },
{ ProcessUserShadowStackPolicy, "ProcessUserShadowStackPolicy" },
};

void SetMitigationPolicies()
{
auto kernel32 = GetModuleHandleW(L"kernel32.dll");
Expand All @@ -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);
}
};
Expand Down

0 comments on commit 4dfe8b1

Please sign in to comment.