feat: bemanitools 6 initial refactoring drop, alpha 1
**THIS IS A HIGHLY WORK/DEVELOPMENT IN PROGRESS VERSION**
**THINGS ARE BROKEN AND EVERYTHING IS SUBJECT TO CHANGE**
First cut after massive refactoring with most critical and fundamental changes implemented.
We need to start somewhere, and this might be as good as anything else, so we can get started
with testing, bug fixing and iterating for the next releases.
The following list is non-exhaustive, does not guarantee anything does work, yet, and is supposed
to give a high level idea of what all of this is about. Updated documentation will reflect all of
this at some later point in time in more detail.
* A common "core" now abstracts logging, thread, property and configuration infrastructure and
provides a common interface. This is used by bemanitools internally as well as all tools, hooks
and APIs provided and don't depend on the game, version of the game or AVS version available
anymore
* New bemanitools (public) API
* Versioned API allowing for handling incremental API changes as well as breaking changes by
providing a new/different version when necessary
* Unified interfaces for bemanitools core API, i.e. logging, threads, configuration
* SDK with examples (TBD)
* Dogfooding approach: Bemanitools uses its own (public) API to implement and provide fundamental
features like configurable keyboard implementations for IO or hooks for different games and
versions
* All bemanitools hooks and IO libraries have been or are about to be re-worked to use the new APIs
* New hook API allows for more fine grained runtime control when stages of the hook are to be
executed, i.e. pre AVS, before main game, iat hooking instead of relying purely on DllMain
(which is still a compatible option though)
* launcher as a replacement for bootstrap: Bring it significantly closer to the original bootstrap
by supporting completely vanilla data and bootstrap.xml configurations to run the games. Note
that bemanitools does not include any code or means to run DRM'd data, only decrypted
* inject is also being reworked to use as much of the same "infrastructure" as launcher to provide
a more seamless bootstrapping process for games that keeps pre-eapki data as vanilla as possible
Summary:
Test Plan:
Summary:
Test Plan:
Summary:
Test Plan:
Summary:
Test Plan:
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
dlls += exceptiontrace
|
||||
|
||||
libs_exceptiontrace := \
|
||||
core \
|
||||
hook \
|
||||
util \
|
||||
|
||||
src_exceptiontrace := \
|
||||
dllmain.c \
|
||||
@@ -0,0 +1,6 @@
|
||||
#include <windows.h>
|
||||
|
||||
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
#define LOG_MODULE "exceptiontrace"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "core/log.h"
|
||||
|
||||
#include "imports/dwarfstack.h"
|
||||
|
||||
#include "util/debug.h"
|
||||
|
||||
#define log_exception(...) _debug_exception_msg("exception", __VA_ARGS__)
|
||||
|
||||
static core_log_message_t _debug_exception_msg;
|
||||
|
||||
static void _debug_stacktrace_printer(
|
||||
uint64_t addr,
|
||||
const char *filename,
|
||||
int lineno,
|
||||
const char *funcname,
|
||||
void *context,
|
||||
int columnno)
|
||||
{
|
||||
int *count;
|
||||
const char *delim;
|
||||
void *ptr;
|
||||
char buffer[512];
|
||||
char *buffer_ptr;
|
||||
|
||||
count = context;
|
||||
delim = strrchr(filename, '/');
|
||||
|
||||
if (delim) {
|
||||
filename = delim + 1;
|
||||
}
|
||||
|
||||
delim = strrchr(filename, '\\');
|
||||
|
||||
if (delim) {
|
||||
filename = delim + 1;
|
||||
}
|
||||
|
||||
ptr = (void *) (uintptr_t) addr;
|
||||
|
||||
switch (lineno) {
|
||||
case DWST_BASE_ADDR:
|
||||
log_exception("base address: 0x%p (%s)", ptr, filename);
|
||||
break;
|
||||
|
||||
case DWST_NOT_FOUND:
|
||||
case DWST_NO_DBG_SYM:
|
||||
case DWST_NO_SRC_FILE:
|
||||
log_exception(
|
||||
" stack %02d: 0x%p (%s)", (*count)++, ptr, filename);
|
||||
break;
|
||||
|
||||
default:
|
||||
buffer_ptr = buffer;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
|
||||
if (ptr) {
|
||||
buffer_ptr += sprintf(
|
||||
buffer_ptr, " stack %02d: 0x%p", (*count)++, ptr);
|
||||
} else {
|
||||
buffer_ptr += sprintf(
|
||||
buffer_ptr,
|
||||
" %*s",
|
||||
(int) sizeof(void *) * 2,
|
||||
"");
|
||||
}
|
||||
|
||||
buffer_ptr += sprintf(buffer_ptr, " (%s:%d", filename, lineno);
|
||||
|
||||
if (columnno > 0) {
|
||||
buffer_ptr += sprintf(buffer_ptr, ":%d", columnno);
|
||||
}
|
||||
|
||||
buffer_ptr += sprintf(buffer_ptr, ")");
|
||||
|
||||
if (funcname) {
|
||||
buffer_ptr += sprintf(buffer_ptr, " [%s]", funcname);
|
||||
}
|
||||
|
||||
log_exception(buffer);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static LONG WINAPI _debug_unhandled_exception_filter(LPEXCEPTION_POINTERS ep)
|
||||
{
|
||||
DWORD code;
|
||||
const char *desc;
|
||||
ULONG_PTR flag;
|
||||
ULONG_PTR addr;
|
||||
int count;
|
||||
|
||||
log_exception("==========================================================");
|
||||
log_exception("The application has crashed due to an unhandled exception!");
|
||||
|
||||
code = ep->ExceptionRecord->ExceptionCode;
|
||||
desc = debug_exception_code_to_str(code);
|
||||
|
||||
log_exception("code: 0x%08lX", code);
|
||||
log_exception("desc: %s", desc);
|
||||
|
||||
if (code == EXCEPTION_ACCESS_VIOLATION &&
|
||||
ep->ExceptionRecord->NumberParameters == 2) {
|
||||
flag = ep->ExceptionRecord->ExceptionInformation[0];
|
||||
addr = ep->ExceptionRecord->ExceptionInformation[1];
|
||||
|
||||
log_exception(
|
||||
"%s violation at 0x%p",
|
||||
flag == 8 ? "data execution prevention" :
|
||||
(flag ? "write access" : "read access"),
|
||||
(void *) addr);
|
||||
}
|
||||
|
||||
log_exception("stacktrace:");
|
||||
|
||||
count = 0;
|
||||
|
||||
dwstOfException(ep->ContextRecord, &_debug_stacktrace_printer, &count);
|
||||
|
||||
log_exception("End of stacktrace");
|
||||
log_exception("==========================================================");
|
||||
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
|
||||
void debug_init(core_log_message_t exception_msg)
|
||||
{
|
||||
_debug_exception_msg = exception_msg;
|
||||
SetUnhandledExceptionFilter(_debug_unhandled_exception_filter);
|
||||
|
||||
log_info("Initialized");
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
LIBRARY exceptiontrace
|
||||
|
||||
EXPORTS
|
||||
DllMain@12 @1 NONAME
|
||||
btapi_hook_core_thread_impl_set
|
||||
btapi_hook_core_log_impl_set
|
||||
btapi_hook_main_init
|
||||
btapi_hook_main_fini
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef EXCEPTIONTRACE_EXCEPTIONTRACE_H
|
||||
#define EXCEPTIONTRACE_EXCEPTIONTRACE_H
|
||||
|
||||
#include "core/log.h"
|
||||
|
||||
void exceptiontrace_init(core_log_message_t exception_msg);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
#define LOG_MODULE "exceptiontrance-hook"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "core/log.h"
|
||||
#include "core/thread.h"
|
||||
|
||||
#include "exceptiontrace/exceptiontrace.h"
|
||||
|
||||
void btapi_hook_core_thread_impl_set(
|
||||
btapi_thread_create_t create,
|
||||
btapi_thread_join_t join,
|
||||
btapi_thread_destroy_t destroy)
|
||||
{
|
||||
core_thread_impl_set(create, join, destroy);
|
||||
}
|
||||
|
||||
void btapi_hook_core_log_impl_set(
|
||||
btapi_log_formatter_t misc,
|
||||
btapi_log_formatter_t info,
|
||||
btapi_log_formatter_t warning,
|
||||
btapi_log_formatter_t fatal)
|
||||
{
|
||||
core_log_impl_set(misc, info, warning, fatal);
|
||||
}
|
||||
|
||||
bool btapi_hook_main_init(
|
||||
HMODULE game_module, struct property_node *property_node_config)
|
||||
{
|
||||
exceptiontrace_init(core_log_fatal_impl_get());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void btapi_hook_main_fini()
|
||||
{
|
||||
// noop
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef EXCEPTIONTRACE_HOOK_H
|
||||
#define EXCEPTIONTRACE_HOOK_H
|
||||
|
||||
#include "btapi/hook-core.h"
|
||||
#include "btapi/hook-main.h"
|
||||
|
||||
void btapi_hook_core_thread_impl_set(
|
||||
btapi_thread_create_t create,
|
||||
btapi_thread_join_t join,
|
||||
btapi_thread_destroy_t destroy);
|
||||
void btapi_hook_core_log_impl_set(
|
||||
btapi_log_formatter_t misc,
|
||||
btapi_log_formatter_t info,
|
||||
btapi_log_formatter_t warning,
|
||||
btapi_log_formatter_t fatal);
|
||||
bool btapi_hook_main_init(
|
||||
HMODULE game_module, struct property_node *property_node_config);
|
||||
void btapi_hook_main_fini();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user