1
0
mirror of synced 2024-11-30 16:14:28 +01:00

Prefix logs with exe name

This commit is contained in:
Bottersnike 2023-04-04 17:31:03 +01:00
parent 09bd2e4792
commit 69cc1ce5b7
No known key found for this signature in database
7 changed files with 44 additions and 23 deletions

View File

@ -7,6 +7,7 @@
#include "hooks/_hooks.h"
WCHAR exeName[MAX_PATH + 1];
char exeNameC[MAX_PATH + 1];
DWORD imageOffset;
#define WIN32_EXE_BASE 0x00400000
@ -61,9 +62,6 @@ void apply_patches(HMODULE hModule) {
}
imageOffset = (DWORD)hModule - imageBase;
char exeNameC[MAX_PATH + 1];
WideCharToMultiByte(CP_ACP, 0, exeName, -1, exeNameC, sizeof exeNameC, NULL, NULL);
if (!load_patches(MiceConfig.mice.patches_file, exeNameC)) {
log_error(plfBoot, "Failed to load patches file %s", MiceConfig.mice.patches_file);
return;
@ -98,15 +96,17 @@ void prebind_hooks() {
hook_all();
install_devices();
// TODO: Figure out why we're needing to call this manually (medium priority)
if (wcscmp(exeName, L"ALLNetProc.exe") == 0) {
log_warning(plfBoot, "Making explicit call to OPENSSL_add_all_algorithms_noconf");
// if (wcscmp(exeName, L"ALLNetProc.exe") == 0) {
// log_warning(plfBoot, "Making explicit call to OPENSSL_add_all_algorithms_noconf");
// OPENSSL_add_all_algorithms_noconf
((void (*)(void))(0x00459770))();
}
// // OPENSSL_add_all_algorithms_noconf
// ((void (*)(void))(0x00459770))();
// }
}
void init_injection(HMODULE hModule) {
WideCharToMultiByte(CP_ACP, 0, exeName, -1, exeNameC, sizeof exeNameC, NULL, NULL);
// Make sure our CRC32 tables are ready for anything that might want to use them
amiCrc32RInit();
@ -114,6 +114,7 @@ void init_injection(HMODULE hModule) {
// We're in a new context now, so need to reconfigure
setup_logging();
MiceSetLogBasename(exeNameC);
log_info(plfBoot, "Handover complete. Now executing within %ls", exeName);
init_com_devices();

View File

@ -164,13 +164,22 @@ void init_nv_storage() {
void dump_nv_storage() {
FILE* fp;
fopen_s(&fp, "dev/kc/nvram.bin", "wb");
if (fopen_s(&fp, "dev/kc/nvram.bin", "wb")) {
log_error(plfMxParallel, "Failed to open nvram.bin");
return;
}
fwrite(nvram, 1, sizeof nvram, fp);
fclose(fp);
fopen_s(&fp, "dev/kc/eeprom.bin", "wb");
if (fopen_s(&fp, "dev/kc/eeprom.bin", "wb")) {
log_error(plfMxParallel, "Failed to open eeprom.bin");
return;
}
fwrite(eeprom, 1, sizeof eeprom, fp);
fclose(fp);
fopen_s(&fp, "dev/kc/flash.bin", "wb");
if (fopen_s(&fp, "dev/kc/flash.bin", "wb")) {
log_error(plfMxParallel, "Failed to open flash.bin");
return;
}
fwrite(flash, 1, sizeof flash, fp);
fclose(fp);
}

View File

@ -76,6 +76,11 @@ void* Win32HotpatchHook(PVOID src, PVOID dst) {
// We don't need a gateway; we can just jump right in
return bSrc + 2;
}
#define CMP2(x, a, b) (x[0] == 0x##a && x[1] == 0x##b)
#define CMP3(x, a, b, c) (CMP2(x, a, b) && x[2] == 0x##c)
#define CMP4(x, a, b, c, d) (CMP3(x, a, b, c) && x[3] == 0x##d)
#define CMP5(x, a, b, c, d, e) (CMP4(x, a, b, c, d) && x[4] == 0x##e)
void* CreateHook32(PVOID src, PVOID dst) {
LPBYTE bSrc = (LPBYTE)src;
@ -89,7 +94,7 @@ void* CreateHook32(PVOID src, PVOID dst) {
// This is a very crude way to identify common instruction patterns
// to select or patch length.
if (bSrc[0] == 0xff && bSrc[1] == 0x25) {
if (CMP2(bSrc, ff, 25)) {
// jmp DWORD PTR ds:0x........
len = 6;
} else if (bSrc[0] == 0x6a && bSrc[2] == 0x68) {
@ -103,24 +108,24 @@ void* CreateHook32(PVOID src, PVOID dst) {
} else if (bSrc[0] == 0x68) {
// push 0x... (dword)
len = 5;
} else if (bSrc[0] == 0x55 && bSrc[1] == 0x8B && bSrc[2] == 0xEC && bSrc[3] == 0x83 &&
bSrc[4] == 0xE4) {
} else if (CMP5(bSrc, 55, 8B, EC, 83, E4)) {
// pusb ebp
// mov ebp,esp
// and esp,ffffff**
len = 6;
} else if (bSrc[0] == 0x55 && bSrc[1] == 0x8B && bSrc[2] == 0xEC && bSrc[3] == 0x8b &&
bSrc[4] == 0x45) {
} else if (CMP5(bSrc, 55, 8B, EC, 8B, 45)) {
// pusb ebp
// mov ebp,esp
// mov eax,DWORD PTR [...]
len = 6;
} else if (bSrc[0] == 0x55 && bSrc[1] == 0x8B && bSrc[2] == 0xEC && bSrc[3] == 0x80 &&
bSrc[4] == 0x3D) {
} else if (CMP5(bSrc, 55, 8B, EC, 80, 3D)) {
// pusb ebp
// mov ebp,esp
// cmd BYTE PTR ds:0x...,0x...
len = 10;
} else if (CMP5(bSrc, B8, 00, 10, 00, 00)) {
// mov eax,0x1000
len = 5;
} else {
log_error(plfHooks, "Unable to identify gateway length! Function peek:");
for (int i = 0; i < 16; i++) {

View File

@ -20,12 +20,14 @@
static BOOL logIsMaster = FALSE;
extern WCHAR exeName[MAX_PATH + 1];
CHAR logBasename[MAX_PATH + 1] = { 0 };
extern DWORD imageOffset;
extern BOOL(WINAPI* TrueWriteFile)(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped);
void MiceSetLogBasename(char* baseName) { strcpy_s(logBasename, sizeof logBasename, baseName); }
char _log_prelude[64];
char* log_prelude() {
time_t rawtime;
@ -34,7 +36,9 @@ char* log_prelude() {
time(&rawtime);
localtime_s(&timeinfo, &rawtime);
strftime(_log_prelude, sizeof _log_prelude, "[%Y/%m/%d %H:%M:%S] ", &timeinfo);
size_t offset = strftime(_log_prelude, sizeof _log_prelude, "[%Y/%m/%d %H:%M:%S] ", &timeinfo);
if (logBasename[0])
sprintf_s(_log_prelude + offset, sizeof _log_prelude - offset, "%s:", logBasename);
return _log_prelude;
}

View File

@ -22,6 +22,8 @@ extern PLOG_FACILITY plfNetwork;
extern CRITICAL_SECTION logger_lock;
void MiceSetLogBasename(char* baseName);
int _log_trace(PLOG_FACILITY facility, const char* format, ...);
int _log_misc(PLOG_FACILITY facility, const char* format, ...);
int _log_info(PLOG_FACILITY facility, const char* format, ...);

View File

@ -6,7 +6,8 @@ void mdkPcpStatus(pcpa_t* stream, void* data) { pcpaSetSendPacket(stream, KC_STA
void mdkPcpAbGameId(pcpa_t* stream, void* data) {
// TODO: Can we do better?
pcpaSetSendPacket(stream, AB_GAMEID, "----");
// pcpaSetSendPacket(stream, AB_GAMEID, "----");
pcpaSetSendPacket(stream, AB_GAMEID, "SDEY");
}
void mdkPcpAbSystemFlag(pcpa_t* stream, void* data) {
// systemflag 24 = billing + allnet, which should suffice for everything

View File

@ -4,11 +4,10 @@ mxmaster.exe: mxmaster.patch
mxgfetcher.exe: mxgfetcher.patch
ORIG_mxsegaboot.exe: mxsegaboot.patch
mxsegaboot.exe: mxsegaboot.patch
ALLNetProc_win.exe: ALLNetProc.patch
ALLNetProc.exe: ALLNetProc.patch
Game.exe: Game.patch
mxnetwork.exe: mxnetwork.patch
maimai_dump_.exe: maimai_dump_.patch
RingGame.exe: UnderNightInBirthExLate[st].patch
nxAuth.exe: nxAuth.patch
ALLNetProc_Win.exe: ALLNetProc_Win.patch
ALLNetProc.exe: ALLNetProc_Win.patch