chore: change VEH env var, add var to enable full dumps

This commit is contained in:
goaaats 2022-05-18 18:33:34 +02:00
parent 74fd48c5cb
commit 524d100bdc
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
3 changed files with 35 additions and 9 deletions

View file

@ -33,12 +33,31 @@ bool is_running_on_linux()
bool is_veh_enabled() bool is_veh_enabled()
{ {
size_t required_size; size_t required_size;
getenv_s(&required_size, nullptr, 0, "DALAMUD_IS_STAGING"); getenv_s(&required_size, nullptr, 0, "DALAMUD_IS_VEH");
if (required_size > 0) if (required_size > 0)
{ {
if (char* is_no_veh = static_cast<char*>(malloc(required_size * sizeof(char)))) if (char* is_no_veh = static_cast<char*>(malloc(required_size * sizeof(char))))
{ {
getenv_s(&required_size, is_no_veh, required_size, "DALAMUD_IS_STAGING"); getenv_s(&required_size, is_no_veh, required_size, "DALAMUD_IS_VEH");
auto result = _stricmp(is_no_veh, "true");
free(is_no_veh);
if (result == 0)
return true;
}
}
return false;
}
bool is_full_dumps()
{
size_t required_size;
getenv_s(&required_size, nullptr, 0, "DALAMUD_IS_VEH_FULL");
if (required_size > 0)
{
if (char* is_no_veh = static_cast<char*>(malloc(required_size * sizeof(char))))
{
getenv_s(&required_size, is_no_veh, required_size, "DALAMUD_IS_VEH_FULL");
auto result = _stricmp(is_no_veh, "true"); auto result = _stricmp(is_no_veh, "true");
free(is_no_veh); free(is_no_veh);
if (result == 0) if (result == 0)
@ -91,7 +110,7 @@ DllExport DWORD WINAPI Initialize(LPVOID lpParam)
} }
else if (is_veh_enabled()) else if (is_veh_enabled())
{ {
if (veh::add_handler()) if (veh::add_handler(is_full_dumps()))
printf("Done!\n"); printf("Done!\n");
else printf("Failed!\n"); else printf("Failed!\n");
} }

View file

@ -2,6 +2,9 @@
#include "veh.h" #include "veh.h"
PVOID g_veh_handle = nullptr;
bool g_veh_do_full_dump = false;
bool is_whitelist_exception(const DWORD code) bool is_whitelist_exception(const DWORD code)
{ {
switch (code) switch (code)
@ -251,8 +254,12 @@ LONG exception_handler(EXCEPTION_POINTERS* ex)
ex_info.ExceptionPointers = ex; ex_info.ExceptionPointers = ex;
ex_info.ThreadId = GetCurrentThreadId(); ex_info.ThreadId = GetCurrentThreadId();
auto miniDumpType = MiniDumpWithDataSegs;
if (g_veh_do_full_dump)
miniDumpType = MiniDumpWithFullMemory;
HANDLE file = CreateFileW(dmp_path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); HANDLE file = CreateFileW(dmp_path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), file, MiniDumpWithDataSegs, &ex_info, nullptr, nullptr); MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), file, miniDumpType, &ex_info, nullptr, nullptr);
CloseHandle(file); CloseHandle(file);
void* fn; void* fn;
@ -282,15 +289,15 @@ LONG exception_handler(EXCEPTION_POINTERS* ex)
return EXCEPTION_CONTINUE_SEARCH; return EXCEPTION_CONTINUE_SEARCH;
} }
bool veh::add_handler(bool doFullDump)
PVOID g_veh_handle = nullptr;
bool veh::add_handler()
{ {
if (g_veh_handle) if (g_veh_handle)
return false; return false;
g_veh_handle = AddVectoredExceptionHandler(1, exception_handler); g_veh_handle = AddVectoredExceptionHandler(1, exception_handler);
SetUnhandledExceptionFilter(nullptr); SetUnhandledExceptionFilter(nullptr);
g_veh_do_full_dump = doFullDump;
return g_veh_handle != nullptr; return g_veh_handle != nullptr;
} }

View file

@ -2,6 +2,6 @@
namespace veh namespace veh
{ {
bool add_handler(); bool add_handler(bool doFullDump);
bool remove_handler(); bool remove_handler();
} }