Files
djhackersdev_bemanitools/src/main/launcher/stubs.c
T
icex2andShiz 24e7dd508a refactor(launcher): Major re-work of launcher
Kudos to Shiz for providing the groundwork for this.

Fundamentally re-think how launcher operates and
bootstrapping the games is managed and configured.

This brings it significantly closer to how the original
bootstrap is doing the job: launcher now utilizes the
data (structures) provided by the bootstrap.xml configuration
file. This creates compatibility with vanilla data dumps
and original stock images. Note that bemanitools does not
include any code or means to run DRM'd data, only decrypted.

But, this allows users to keep decrypted dumps as stock as
possible which means:

* No copying around of property files anymore
* Keep the modules/ folder with the binaries
* Have bemanitools binaries separate in the data
* No need to edit/customize the original configuration files

A list of key features of the "new" launcher:

* Boostrap games by following the configuration provided by
  stock game's bootstrap.xml files
* Custom launcher.xml configuration file that adds further
  launcher configurable features, composability of
  bootstrap.xml configuration(s) as well as configuration
  overriding/stacking of selected types of configurations,
  e.g. eamuse config, avs-config. The latter eliminates
  the need for modifying stock config files in the prop/
  folder
* Unified logging system: launcher and AVS logging uses
  the same logger, all output can now be in a single file
* Original features such as various hook types still
  available

Due to the significant architectural changes, this also
breaks with any backwards compatibility to existing
launcher setups. Thus, users need to migrate by re-applying
the new configuration format and migrating their config
parameters accordingly.

Further migration instructions and updated documentation
will be provided upon release.

Co-authored-by: Shiz <hi@shiz.me>
2024-02-03 15:19:20 +01:00

162 lines
3.8 KiB
C

#define LOG_MODULE "stubs"
#include <windows.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include "hook/table.h"
#include "launcher/stubs.h"
#include "util/defs.h"
#include "util/log.h"
struct ikey_status {
uint32_t field_0;
uint8_t field_4;
uint8_t field_5;
uint8_t field_6;
uint8_t field_7;
uint32_t cert_valid_start;
uint32_t cert_valid_end;
};
struct stub {
const char *name;
void *proc;
};
typedef void (*bt_get_fucked_t)(uint32_t /* even in 64-bit */ context);
static HMODULE STDCALL my_GetModuleHandleA(const char *name);
static HMODULE STDCALL my_GetModuleHandleW(const wchar_t *name);
static void *STDCALL my_GetProcAddress(HMODULE dll, const char *name);
static void bt_get_ikey_status(struct ikey_status *ik);
#if AVS_VERSION >= 1509
static void bt_get_fucked(bt_get_fucked_t callback, uint32_t ctx);
#endif
static void bt_fcheck_init(void);
static void *bt_fcheck_main(void *unknown);
static void bt_fcheck_finish(void);
static HMODULE(STDCALL *real_GetModuleHandleA)(const char *name);
static HMODULE(STDCALL *real_GetModuleHandleW)(const wchar_t *name);
static void *(STDCALL *real_GetProcAddress)(HMODULE dll, const char *name);
static struct stub stub_list[] = {
#if AVS_VERSION >= 1509
{"k_bt0001", bt_get_ikey_status},
{"k_bt0002", bt_get_fucked},
#else
{"bt_get_ikey_status", bt_get_ikey_status},
#endif
{"bt_fcheck_init", bt_fcheck_init},
{"bt_fcheck_main", bt_fcheck_main},
{"bt_fcheck_finish", bt_fcheck_finish},
};
static struct hook_symbol stub_hook_syms[] = {
{.name = "GetModuleHandleA",
.patch = my_GetModuleHandleA,
.link = (void *) &real_GetModuleHandleA},
{.name = "GetModuleHandleW",
.patch = my_GetModuleHandleW,
.link = (void *) &real_GetModuleHandleW},
{.name = "GetProcAddress",
.patch = my_GetProcAddress,
.link = (void *) &real_GetProcAddress},
};
static HMODULE STDCALL my_GetModuleHandleA(const char *name)
{
/* Check name for null because winio32 calls this with null parameters
when the module is loaded on win xp (doesn't happen on win 7) */
if (name != NULL &&
(_stricmp(name, "kbt.dll") == 0 || _stricmp(name, "kld.dll") == 0)) {
name = NULL;
}
return real_GetModuleHandleA(name);
}
static HMODULE STDCALL my_GetModuleHandleW(const wchar_t *name)
{
/* Check name for null because winio32 calls this with null parameters
when the module is loaded on win xp (doesn't happen on win 7) */
if (name != NULL &&
(wcsicmp(name, L"kbt.dll") == 0 || wcsicmp(name, L"kld.dll") == 0)) {
name = NULL;
}
return real_GetModuleHandleW(name);
}
static void *STDCALL my_GetProcAddress(HMODULE dll, const char *name)
{
size_t i;
if (dll != real_GetModuleHandleA(NULL)) {
return real_GetProcAddress(dll, name);
}
for (i = 0; i < lengthof(stub_list); i++) {
if (strcmp(stub_list[i].name, name) == 0) {
return stub_list[i].proc;
}
}
log_warning("Request for unknown stub %s", name);
return NULL;
}
void stubs_init(void)
{
log_info("Init");
hook_table_apply(
NULL, "kernel32.dll", stub_hook_syms, lengthof(stub_hook_syms));
}
static void bt_get_ikey_status(struct ikey_status *ik)
{
memset(ik, 0, sizeof(*ik) * 2);
ik[0].field_4 = true;
ik[0].field_6 = true;
ik[1].field_4 = true;
ik[1].field_6 = true;
/* Not strictly necessary */
ik[0].cert_valid_end = -1;
ik[1].cert_valid_end = -1;
}
#if AVS_VERSION >= 1509
static void bt_get_fucked(bt_get_fucked_t callback, uint32_t ctx)
{
log_info(">>> k_bt0002");
callback(ctx);
log_info("<<< k_bt0002");
}
#endif
static void bt_fcheck_init(void)
{
}
static void *bt_fcheck_main(void *unknown)
{
return 0;
}
static void bt_fcheck_finish(void)
{
}