Skip to content

Commit

Permalink
use custom function table access
Browse files Browse the repository at this point in the history
  • Loading branch information
Prevter authored Jun 20, 2024
1 parent c474202 commit 8df1e78
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
19 changes: 17 additions & 2 deletions src/analyzer/analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,21 @@ namespace analyzer {
return nullptr;
}

/// @brief Import a TulipHook function
PVOID GeodeFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase);

PVOID CustomSymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase) {
auto ret = GeodeFunctionTableAccess64(hProcess, AddrBase);
if (ret) return ret;
return SymFunctionTableAccess64(hProcess, AddrBase);
}

DWORD64 CustomSymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr) {
auto ret = GeodeFunctionTableAccess64(hProcess, dwAddr);
if (ret) return dwAddr & (~0xffffull);
return SymGetModuleBase64(hProcess, dwAddr);
}

const std::vector<StackTraceLine> &Analyzer::getStackTrace() {
if (!stackTrace.empty())
return stackTrace;
Expand Down Expand Up @@ -523,8 +538,8 @@ namespace analyzer {
HANDLE process = GetCurrentProcess();
HANDLE thread = GetCurrentThread();

while (StackWalk64(machineType, process, thread, &stackFrame, ctx, nullptr, SymFunctionTableAccess64,
SymGetModuleBase64, nullptr)) {
while (StackWalk64(machineType, process, thread, &stackFrame, ctx, nullptr,
CustomSymFunctionTableAccess64, CustomSymGetModuleBase64, nullptr)) {
if (stackFrame.AddrPC.Offset == 0) {
break;
}
Expand Down
14 changes: 4 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,6 @@ LONG WINAPI HandleCrash(LPEXCEPTION_POINTERS ExceptionInfo) {
return result;
}

inline bool isWine() {
HMODULE hModule = GetModuleHandleA("ntdll.dll");
if (!hModule) return false;
FARPROC func = GetProcAddress(hModule, "wine_get_version");
return func != nullptr;
}

LONG WINAPI ContinueHandler(LPEXCEPTION_POINTERS info) {
if (info->ExceptionRecord->ExceptionCode == EH_EXCEPTION_NUMBER) {
HandleCrash(info);
Expand Down Expand Up @@ -392,8 +385,9 @@ inline std::string getBindingsUrl() {
}

geode::log::info("Setting up crash handler...");
AddVectoredExceptionHandler(0, ExceptionHandler);
AddVectoredContinueHandler(0, ContinueHandler);
if (isWine()) SetUnhandledExceptionFilter(ContinueHandler);
// AddVectoredExceptionHandler(0, ExceptionHandler);
// AddVectoredContinueHandler(0, ContinueHandler);
// if (isWine()) SetUnhandledExceptionFilter(ContinueHandler);
SetUnhandledExceptionFilter(ExceptionHandler);
}

23 changes: 21 additions & 2 deletions src/utils/geode-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace utils::geode {
auto problems = ::geode::Loader::get()->getProblems();

message = fmt::format(
"- Working Directory: {}\n"
"- Working Directory: {}\n{}"
"- Loader Version: {} (Geometry Dash v{})\n"
"- Loader Commit: {}\n"
"- Bindings Commit: {}\n"
Expand All @@ -94,7 +94,8 @@ namespace utils::geode {
"- 4GB Patch: {}\n"
#endif
"- Problems: {}{}",
wd, getLoaderVersion(), getGameVersion(),
wd, isWine() ? "- Wine detected\n" : "",
getLoaderVersion(), getGameVersion(),
about::getLoaderCommitHash(), about::getBindingsCommitHash(),
getModCount(), getLoadedModCount(), getEnabledModCount(),
#ifndef _WIN64
Expand Down Expand Up @@ -281,4 +282,22 @@ namespace utils::geode {
return it == functions.end() ? std::make_pair(methodStart, "") : *it;
}

bool isWine() {
static bool checked = false;
static bool result = false;

if (checked) return result;

HMODULE hModule = GetModuleHandleA("ntdll.dll");
if (!hModule) {
checked = true;
return false;
}

FARPROC func = GetProcAddress(hModule, "wine_get_version");
checked = true;
result = func != nullptr;
return result;
}

}
3 changes: 3 additions & 0 deletions src/utils/geode-util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@ namespace utils::geode {
/// @param address The address to search for
/// @param moduleBase The base address of the module
std::pair<uintptr_t, std::string> getFunctionAddress(uintptr_t address, uintptr_t moduleBase);

/// @brief Check whether current system is running Wine.
bool isWine();
}

0 comments on commit 8df1e78

Please sign in to comment.