Windows stacktrace fix (#925)

* fix the windows hook exceptions

* update tuliphook

* update tuliphook

* remove old code

---------

Co-authored-by: altalk23 <45172705+altalk23@users.noreply.github.com>
Co-authored-by: dankmeme01 <42031238+dankmeme01@users.noreply.github.com>
Co-authored-by: mat <26722564+matcool@users.noreply.github.com>
This commit is contained in:
Fleeym 2024-06-19 23:03:32 +03:00 committed by GitHub
parent 815c4a31d8
commit 70fe096724
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 4 deletions

View file

@ -239,7 +239,7 @@ if (DEFINED GEODE_TULIPHOOK_REPO_PATH)
message(STATUS "Using ${GEODE_TULIPHOOK_REPO_PATH} for TulipHook")
add_subdirectory(${GEODE_TULIPHOOK_REPO_PATH} ${GEODE_TULIPHOOK_REPO_PATH}/build)
else()
CPMAddPackage("gh:geode-sdk/TulipHook#1ecee12")
CPMAddPackage("gh:geode-sdk/TulipHook#e15aaee")
endif()
set(CMAKE_WARN_DEPRECATED ON CACHE BOOL "" FORCE)

View file

@ -144,10 +144,13 @@ static void printAddr(std::ostream& stream, void const* addr, bool fullPath = tr
}
}
PVOID CustomFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase);
// https://stackoverflow.com/a/50208684/9124836
static std::string getStacktrace(PCONTEXT context) {
std::stringstream stream;
STACKFRAME64 stack;
static STACKFRAME64 stack;
static PCONTEXT pcontext = context;
memset(&stack, 0, sizeof(STACKFRAME64));
auto process = GetCurrentProcess();
@ -159,7 +162,7 @@ static std::string getStacktrace(PCONTEXT context) {
#else
stack.AddrPC.Offset = context->Rip;
stack.AddrStack.Offset = context->Rsp;
stack.AddrFrame.Offset = context->Rbp;
stack.AddrFrame.Offset = context->Rdi;
#endif
stack.AddrPC.Mode = AddrModeFlat;
@ -170,7 +173,21 @@ static std::string getStacktrace(PCONTEXT context) {
while (true) {
if (!StackWalk64(
IMAGE_FILE_MACHINE_AMD64, process, thread, &stack, context, nullptr,
SymFunctionTableAccess64, SymGetModuleBase64, nullptr
+[](HANDLE hProcess, DWORD64 AddrBase) {
auto ret = CustomFunctionTableAccess64(hProcess, AddrBase);
if (ret) {
return ret;
}
return SymFunctionTableAccess64(hProcess, AddrBase);
},
+[](HANDLE hProcess, DWORD64 dwAddr) -> DWORD64 {
auto ret = CustomFunctionTableAccess64(hProcess, dwAddr);
if (ret) {
return dwAddr & (~0xffffull);
}
return SymGetModuleBase64(hProcess, dwAddr);
}
, nullptr
))
break;