From 64d2f02ad9e8020947fe7c0a2bc9de25d29ce210 Mon Sep 17 00:00:00 2001 From: BroGamer <64546358+BroGamer4256@users.noreply.github.com> Date: Fri, 16 Sep 2022 08:38:53 +1200 Subject: [PATCH] Add amauth EMU --- Makefile | 2 + patches/{what_the_fuck => amauth}/Makefile | 10 +- patches/amauth/dllmain.cpp | 374 +++++++++++++++++++++ patches/what_the_fuck/dllmain.cpp | 280 --------------- src/dllmain.c | 2 +- src/helpers.h | 6 + 6 files changed, 388 insertions(+), 286 deletions(-) rename patches/{what_the_fuck => amauth}/Makefile (79%) create mode 100644 patches/amauth/dllmain.cpp delete mode 100644 patches/what_the_fuck/dllmain.cpp diff --git a/Makefile b/Makefile index e7e39a4..5ca8a16 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,7 @@ ${OUT}: dirs ${DEPS} ${OBJ} fmt: @cd src && clang-format -i *.h *.c -style=file @cd patches/8.18 && clang-format -i *.c -style=file + @cd patches/amauth && clang-format -i *.c -style=file .PHONY: clean clean: @@ -50,6 +51,7 @@ clean: .PHONY: patches patches: make -C patches/8.18 + make -C patches/amauth .PHONY: dist-no-7z dist-no-7z: options ${OUT} patches diff --git a/patches/what_the_fuck/Makefile b/patches/amauth/Makefile similarity index 79% rename from patches/what_the_fuck/Makefile rename to patches/amauth/Makefile index 8682804..c5733b5 100644 --- a/patches/what_the_fuck/Makefile +++ b/patches/amauth/Makefile @@ -1,19 +1,19 @@ -OUT = what_the_fuck +OUT = amauth CXX := x86_64-w64-mingw32-g++ TARGET := x86_64-pc-windows-gnu SRC = dllmain.cpp -OBJ = ${addprefix ../../${TARGET}/patches/what_the_fuck/,${SRC:.cpp=.o}} +OBJ = ${addprefix ../../${TARGET}/patches/amauth/,${SRC:.cpp=.o}} EXTERN_SRC = src/helpers.c tomlc99/toml.c minhook/src/buffer.c minhook/src/hook.c minhook/src/trampoline.c minhook/src/hde/hde32.c minhook/src/hde/hde64.c EXTERN_OBJ = ${addprefix ../../${TARGET}/,${EXTERN_SRC:.c=.o}} CXXFLAGS = -std=c++11 -I../../src -I../../minhook/include -I../../tomlc99 -Wall -Ofast -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=_WIN32_WINNT_WIN7 LDFLAGS := -shared -static -static-libgcc -s -LIBS := -lmingw32 -luuid -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lsetupapi -lversion -pthread +LIBS := -lmingw32 -luuid -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lsetupapi -lversion -lws2_32 -pthread all: options ${OUT} .PHONY: dirs dirs: - @mkdir -p ../../${TARGET}/patches/what_the_fuck + @mkdir -p ../../${TARGET}/patches/amauth .PHONY: options options: @@ -21,7 +21,7 @@ options: @echo "LDFLAGS = ${LDFLAGS}" @echo "CXX = ${CXX}" -../../${TARGET}/patches/what_the_fuck/%.o: %.cpp +../../${TARGET}/patches/amauth/%.o: %.cpp @echo BUILD $@ @${CXX} -c ${CXXFLAGS} $< -o $@ diff --git a/patches/amauth/dllmain.cpp b/patches/amauth/dllmain.cpp new file mode 100644 index 0000000..0eba59d --- /dev/null +++ b/patches/amauth/dllmain.cpp @@ -0,0 +1,374 @@ +// Here be lions +#include +#include +#include +#include +#include +#include +#include +// Needs to be after for DEFINE_GUID +#include "helpers.h" + +DWORD reg = 0; +char server_ip[0x10]; +char *server_hostname; + +DEFINE_GUID (IID_CAuthFactory, 0x4603BB03, 0x058D, 0x43D9, 0xB9, 0x6F, 0x63, 0x9B, 0xE9, 0x08, 0xC1, 0xED); +DEFINE_GUID (IID_CAuth, 0x045A5150, 0xD2B3, 0x4590, 0xA3, 0x8B, 0xC1, 0x15, 0x86, 0x78, 0xE1, 0xAC); + +class CAuth : public IUnknown { + public: + STDMETHODIMP + QueryInterface (REFIID riid, LPVOID *ppvObj) { + wchar_t *iid_str; + StringFromCLSID (riid, &iid_str); + printf ("QueryInterface %ls\n", iid_str); + + if (riid == IID_IUnknown || riid == IID_CAuth) { + *ppvObj = this; + this->AddRef (); + return 0; + } else { + *ppvObj = 0; + return E_NOINTERFACE; + } + } + STDMETHODIMP_ (ULONG) AddRef () { return this->refCount++; } + STDMETHODIMP_ (ULONG) Release () { + this->refCount--; + if (this->refCount <= 0) { + delete this; + return 0; + } + return this->refCount; + } + + virtual i64 + Unk3 (u32 a1) { + return 1; + } + virtual i64 + Unk4 () { + return 1; + } + virtual i32 + Unk5 () { + return 0; + } + virtual i64 + Unk6 () { + return 1; + } + virtual i32 + Unk7 () { + return 0; + } + virtual i32 + Unk8 () { + return 0; + } + virtual i32 + Unk9 (i32 *a1) { + memset (a1, 0, sizeof (i32) * 0x30); + a1[0] = 15; + a1[2] = 2; + a1[3] = 1; + a1[6] = 9; + a1[8] = 2; + a1[9] = 1; + a1[10] = 27; + a1[11] = 33; + a1[12] = 41; + a1[13] = 50; + a1[14] = 59; + a1[15] = 1179656; + a1[30] = 1; + a1[46] = 1; + a1[47] = 3; + a1[48] = 9; + return 0; + } + virtual i32 + Unk10 (char *a1) { + memset (a1, 0, 0xA8); + strncpy_s (a1, 0x10, "STANDALONE", 0xF); + strncpy_s (a1 + 0x10, 0x10, "ABLN1080001", 0xF); + strncpy_s (a1 + 0x20, 0x10, "284111080001", 0xF); + strncpy_s (a1 + 0x30, 0x10, server_ip, 0xF); + strncpy_s (a1 + 0x40, 0x10, server_ip, 0xF); + strncpy_s (a1 + 0x50, 0x10, server_ip, 0xF); + strncpy_s (a1 + 0x60, 0x10, "255.255.255.0", 0xF); + strncpy_s (a1 + 0x70, 0x10, "192.168.0.1", 0xF); + strncpy_s (a1 + 0x80, 0x8, "8.8.8.8", 0x7); + return 0; + } + virtual i32 + Unk11 (char *a1) { + memset (a1, 0, 0x13C); + strncpy_s (a1, 4, "1", 3); + strncpy_s (a1 + 4, 0x10, "ALLNET", 0xF); + strncpy_s (a1 + 20, 8, "SWBY", 7); + strncpy_s (a1 + 28, 8, "12.00", 7); + strncpy_s (a1 + 36, 8, "S121", 7); + strncpy_s (a1 + 44, 8, "08.18", 7); + strncpy_s (a1 + 52, 4, "0", 3); + strncpy_s (a1 + 56, 4, "PCB", 3); + char *mucha_url = (char *)malloc (0x100); + strcat (mucha_url, server_hostname); + strcat (mucha_url, ":10122/mucha_front/"); + strncpy_s (a1 + 60, 0x100, mucha_url, 0xFF); + free (mucha_url); + return 0; + } + virtual i32 + Unk12 () { + return 1; + } + virtual i32 + Unk13 () { + return 1; + } + virtual i32 + Unk14 (char *a1) { + memset (a1, 0, 0x8A2); + strncpy_s (a1, 0x101, server_hostname, 0x100); + strncpy_s (a1 + 0x101, 0x101, server_hostname, 0x100); + strncpy_s (a1 + 0x202, 0x100, "NAMCO", 0xFF); + strncpy_s (a1 + 0x302, 0x100, "NAMCO", 0xFF); + strncpy_s (a1 + 0x402, 0x10, "1", 0xF); + strncpy_s (a1 + 0x412, 0x100, "NAMCO", 0xFF); + strncpy_s (a1 + 0x512, 0x100, "X", 0xFF); + strncpy_s (a1 + 0x612, 0x100, "Y", 0xFF); + strncpy_s (a1 + 0x712, 0x100, "Z", 0xFF); + strncpy_s (a1 + 0x812, 0x10, "JPN0123", 0xF); + strncpy_s (a1 + 0x822, 0x10, "", 0xF); + strncpy_s (a1 + 0x832, 0x10, "JPN", 0xF); + strncpy_s (a1 + 0x842, 0x10, "002,00", 0xF); + strncpy_s (a1 + 0x842, 0x10, "PowerOnResponseVer2", 0xF); + return 0; + } + virtual i32 + Unk15 () { + return 0; + } + virtual i32 + Unk16 () { + return 0; + } + virtual i32 + Unk17 () { + return 0; + } + virtual i32 + Unk18 (void *a1) { + return 0; + } + virtual i32 + Unk19 (u8 *a1) { + memset (a1, 0, 0x38); + a1[0] = 1; + return 1; + } + virtual i32 + Unk20 () { + return 0; + } + virtual i32 + Unk21 () { + return 1; + } + virtual i32 + Unk22 () { + return 0; + } + virtual i32 + Unk23 () { + return 0; + } + virtual i32 + Unk24 () { + return 0; + } + virtual i32 + Unk25 () { + return 1; + } + virtual i32 + Unk26 () { + return 0; + } + virtual i32 + Unk27 () { + return 1; + } + virtual i32 + Unk28 () { + return 0; + } + virtual i32 + Unk29 () { + return 0; + } + virtual i32 + Unk30 () { + return 0; + } + virtual i32 + PrintDebugInfo () { + return 0; + } + virtual i32 + Unk32 (void *a1) { + return 0; + } + virtual void + Unk33 () {} + + public: + CAuth () {} + virtual ~CAuth () {} + + private: + i32 refCount = 0; +}; + +class CAuthFactory : public IClassFactory { + public: + STDMETHODIMP + QueryInterface (REFIID riid, LPVOID *ppvObj) { + wchar_t *iid_str; + StringFromCLSID (riid, &iid_str); + printf ("QueryInterface %ls\n", iid_str); + + if (riid == IID_IUnknown || riid == IID_IClassFactory || riid == IID_CAuthFactory) { + *ppvObj = this; + this->AddRef (); + return 0; + } else { + *ppvObj = 0; + return E_NOINTERFACE; + } + } + STDMETHODIMP_ (ULONG) AddRef () { return 2; } + STDMETHODIMP_ (ULONG) Release () { return 1; } + virtual HRESULT + CreateInstance (IUnknown *outer, REFIID riid, void **object) { + if (outer != 0) return CLASS_E_NOAGGREGATION; + wchar_t *iid_str; + StringFromCLSID (riid, &iid_str); + printf ("CreateInstance %ls\n", iid_str); + if (riid == IID_CAuth) { + CAuth *auth = new CAuth (); + return auth->QueryInterface (riid, object); + } else { + *object = 0; + return E_NOINTERFACE; + } + } + virtual HRESULT + LockServer (i32 lock) { + return 0; + } +}; + +extern "C" { +void +Init () { + CoInitializeEx (0, 0); + CoRegisterClassObject (IID_CAuthFactory, (IUnknown *)new CAuthFactory (), 4, 1, ®); + toml_table_t *config = openConfig (configPath ((char *)"config.toml")); + if (config) { + server_hostname = readConfigString (config, (char *)"server", server_hostname); + struct addrinfo *res = 0; + getaddrinfo (server_hostname, "", 0, &res); + for (struct addrinfo *i = res; i != 0; i = i->ai_next) { + if (res->ai_addr->sa_family != AF_INET) { continue; } + struct sockaddr_in *p = (struct sockaddr_in *)res->ai_addr; + inet_ntop (AF_INET, &p->sin_addr, server_ip, 0x10); + break; + } + } +} + +void +Exit () { + CoRevokeClassObject (reg); + CoUninitialize (); +} + +void +Test () { + i32 res; + CoInitializeEx (0, 0); + CAuth *auth; + res = CoCreateInstance (IID_CAuthFactory, 0, 4, IID_CAuth, (void **)&auth); + if (res != S_OK) { + printf ("AMAuthd not running %llx\n", res); + CoUninitialize (); + return; + } + auth->AddRef (); + + i32 *unk9 = (i32 *)malloc (sizeof (i32) * 0x50); + memset (unk9, 0, sizeof (i32) * 0x50); + res = auth->Unk9 (unk9); + printf ("unk9: %d\n", res); + for (int i = 0; i < 0x50; i++) { + printf ("%d\n", unk9[i]); + } + free (unk9); + + char *unk14 = (char *)malloc (0x8A2); + res = auth->Unk14 (unk14); + printf ("unk14: %d\n", res); + printf ("unk14 %s\n", unk14); + printf ("unk14 + 0x101 %s\n", unk14 + 0x101); + printf ("unk14 + 0x202 %s\n", unk14 + 0x202); + printf ("unk14 + 0x302 %s\n", unk14 + 0x302); + printf ("unk14 + 0x402 %s\n", unk14 + 0x402); + printf ("unk14 + 0x412 %s\n", unk14 + 0x412); + printf ("unk14 + 0x512 %s\n", unk14 + 0x512); + printf ("unk14 + 0x512 %s\n", unk14 + 0x612); + printf ("unk14 + 0x712 %s\n", unk14 + 0x712); + printf ("unk14 + 0x812 %s\n", unk14 + 0x812); + printf ("unk14 + 0x822 %s\n", unk14 + 0x822); + printf ("unk14 + 0x832 %s\n", unk14 + 0x832); + printf ("unk14 + 0x842 %s\n", unk14 + 0x842); + printf ("unk14 + 0x862 %s\n", unk14 + 0x862); + free (unk14); + + char *unk11 = (char *)malloc (0x13C); + res = auth->Unk11 (unk11); + printf ("unk11: %d\n", res); + printf ("%s\n", unk11); + printf ("%s\n", unk11 + 4); + printf ("%s\n", unk11 + 20); + printf ("%s\n", unk11 + 28); + printf ("%s\n", unk11 + 36); + printf ("%s\n", unk11 + 44); + printf ("%s\n", unk11 + 52); + printf ("%s\n", unk11 + 56); + printf ("%s\n", unk11 + 60); + free (unk11); + + char *unk10 = (char *)malloc (0xA8); + res = auth->Unk10 (unk10); + printf ("unk10: %d\n", res); + FILE *unk10fp = fopen ("unk10.bin", "w"); + fwrite (unk10, 0xA8, 1, unk10fp); + fclose (unk10fp); + free (unk10); + + u8 *unk19 = (u8 *)malloc (0x40); + memset (unk19, 0xFF, 0x40); + res = auth->Unk19 (unk19); + printf ("unk19: %d\n", res); + FILE *unk19fp = fopen ("unk19.bin", "w"); + fwrite (unk19, 0x40, 1, unk19fp); + fclose (unk19fp); + free (unk19); + + auth->Release (); + CoUninitialize (); +} +} diff --git a/patches/what_the_fuck/dllmain.cpp b/patches/what_the_fuck/dllmain.cpp deleted file mode 100644 index 970d2cc..0000000 --- a/patches/what_the_fuck/dllmain.cpp +++ /dev/null @@ -1,280 +0,0 @@ -// Here be lions -#include -#include -#include -#include -#include -#include -// Needs to be after for DEFINE_GUID -#include "helpers.h" - -extern "C" { - -DWORD reg = 0; - -DEFINE_GUID (IID_CAuthFactory, 0x4603BB03, 0x058D, 0x43D9, 0xB9, 0x6F, 0x63, 0x9B, 0xE9, 0x08, 0xC1, 0xED); -DEFINE_GUID (IID_CAuth, 0x045A5150, 0xD2B3, 0x4590, 0xA3, 0x8B, 0xC1, 0x15, 0x86, 0x78, 0xE1, 0xAC); - -class CAuth : public IUnknown { - public: - STDMETHODIMP - QueryInterface (REFIID riid, LPVOID *ppvObj) { - wchar_t *iid_str; - StringFromCLSID (riid, &iid_str); - printf ("QueryInterface %ls\n", iid_str); - - if (riid == IID_IUnknown || riid == IID_CAuth) { - *ppvObj = this; - this->AddRef (); - return 0; - } else { - *ppvObj = 0; - return E_NOINTERFACE; - } - } - STDMETHODIMP_ (ULONG) AddRef () { return this->refCount++; } - STDMETHODIMP_ (ULONG) Release () { - this->refCount--; - if (this->refCount <= 0) { - delete this; - return 0; - } - return this->refCount; - } - - // Seems to verify that local network is valid? - virtual i64 - Unk3 (u32 a1) { - return 1; - } - virtual i64 - Unk4 () { - return 1; - } - // Seems to check a config field, something to do with server/client - virtual i32 - Unk5 () { - return 0; - } - // Seems to check that some config field is valid - virtual i64 - Unk6 () { - return 1; - } - // Sets a random global to 1 - virtual i32 - Unk7 () { - return 0; - } - // Set some global vars - virtual i32 - Unk8 () { - return 0; - } - // Puts some globals into a1 - virtual i32 - Unk9 (i32 *a1) { - printf ("Unk9\n"); - a1[0x28] = 0; - a1[1] = 1; - a1[7] = 1; - a1[0x2C] = 1; - a1[0x2A] = 1; - a1[0x2E] = 1; - a1[0x31] = 0x11; - a1[0x30] = 1; - a1[0x2F] = 1; - return 0; - } - // Copies from a global to a1 - virtual i32 - Unk10 (void *a1) { - printf ("Unk10\n"); - memset (a1, 0, 0xA8); - return 0; - } - // Lotsa fancy stuff here - virtual i32 - Unk11 (char *a1) { - printf ("Unk11\n"); - memset (a1, 0, 0x13C); - strncpy_s (a1, 4, "1", 3); - strncpy_s (a1 + 4, 0x10, "ALLNET", 0xF); - strncpy_s (a1 + 20, 8, "SWBY", 7); - strncpy_s (a1 + 28, 8, "12.00", 7); - strncpy_s (a1 + 36, 8, "S121", 7); - strncpy_s (a1 + 44, 8, "08.18", 7); - strncpy_s (a1 + 52, 4, "0", 3); - strncpy_s (a1 + 56, 4, "PCB", 3); - strncpy_s (a1 + 60, 0x100, "https://divamodarchive.com/", 0xFF); - return 0; - } - // Some config stuff, unsure if true or false wanted - virtual i32 - Unk12 () { - return 1; - } - virtual i32 - Unk13 () { - return 1; - } - // Seems to be some kind of copy? Can return E_FAIL and E_ACCESSDENIED - virtual i32 - Unk14 (void *a1) { - printf ("Unk14\n"); - memset (a1, 0, 0x8A2); - return 0; - } - // Can return E_FAIL E_ABORT E_UNEXPECTED - virtual i32 - Unk15 () { - return 0; - } - // Config stuff - virtual i32 - Unk16 () { - return 0; - } - virtual i32 - Unk17 () { - return 0; - } - // Seems to be some kind of copy? Can return E_FAIL and E_ACCESSDENIED - virtual i32 - Unk18 (void *a1) { - printf ("Unk18\n"); - return 0; - } - // Fancy stuff happening here - virtual i32 - Unk19 (void *a1) { - printf ("Unk19\n"); - return 0; - } - // Can return E_FAIL E_ABORT E_UNEXPECTED E_NOTIMPL - // Something to do with MH - virtual i32 - Unk20 () { - printf ("Unk20\n"); - return 0; - } - // Can return E_FAIL E_ABORT E_UNEXPECTED E_NOTIMPL - // Something to do with a list - // Maybe an init function - virtual i32 - Unk21 () { - return 1; - } - virtual i32 - Unk22 () { - return 0; - } - virtual i32 - Unk23 () { - return 0; - } - // E_FAIL E_NOTIMPL - virtual i32 - Unk24 () { - return 0; - } - // E_FAIL E_UNEXPECTED E_NOTIMPL - virtual i32 - Unk25 () { - return 1; - } - // E_FAIL E_NOTIMPL - virtual i32 - Unk26 () { - return 0; - } - // E_FAIL E_UNEXPECTED E_NOTIMPL - virtual i32 - Unk27 () { - return 1; - } - // E_FAIL E_NOTIMPL - virtual i32 - Unk28 () { - return 0; - } - // E_FAIL E_ACCESSDENIED - virtual i32 - Unk29 () { - return 0; - } - virtual i32 - Unk30 () { - return 0; - } - // nothing special - virtual i32 - PrintDebugInfo () { - return 0; - } - virtual i32 - Unk32 (void *a1) { - return 0; - } - virtual void - Unk33 () {} - - public: - CAuth () { printf ("CAuth\n"); } - virtual ~CAuth () {} - - private: - i32 refCount = 0; -}; - -class CAuthFactory : public IClassFactory { - public: - STDMETHODIMP - QueryInterface (REFIID riid, LPVOID *ppvObj) { - wchar_t *iid_str; - StringFromCLSID (riid, &iid_str); - printf ("QueryInterface %ls\n", iid_str); - - if (riid == IID_IUnknown || riid == IID_IClassFactory || riid == IID_CAuthFactory) { - *ppvObj = this; - this->AddRef (); - return 0; - } else { - *ppvObj = 0; - return E_NOINTERFACE; - } - } - STDMETHODIMP_ (ULONG) AddRef () { return 2; } - STDMETHODIMP_ (ULONG) Release () { return 1; } - virtual HRESULT - CreateInstance (IUnknown *outer, REFIID riid, void **object) { - if (outer != 0) return CLASS_E_NOAGGREGATION; - wchar_t *iid_str; - StringFromCLSID (riid, &iid_str); - printf ("CreateInstance %ls\n", iid_str); - if (riid == IID_CAuth) { - CAuth *auth = new CAuth (); - return auth->QueryInterface (riid, object); - } else { - *object = 0; - return E_NOINTERFACE; - } - } - virtual HRESULT - LockServer (i32 lock) { - return 0; - } -}; - -void -Init () { - CoInitializeEx (0, 0); - CoRegisterClassObject (IID_CAuthFactory, (IUnknown *)new CAuthFactory (), 4, 1, ®); -} - -void -Exit () { - CoRevokeClassObject (reg); - CoUninitialize (); -} -} diff --git a/src/dllmain.c b/src/dllmain.c index 15d21c0..693547b 100644 --- a/src/dllmain.c +++ b/src/dllmain.c @@ -12,7 +12,7 @@ char accessCode2[21] = "00000000000000000002"; char chipId1[33] = "00000000000000000000000000000001"; char chipId2[33] = "00000000000000000000000000000002"; -char *server = "vsapi.taiko-p.jp"; +char *server = ""; typedef i32 (*callbackAttach) (i32, i32, i32 *); typedef void (*callbackTouch) (i32, i32, u8[168], u64); diff --git a/src/helpers.h b/src/helpers.h index 75031b8..f52f289 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -104,6 +104,9 @@ typedef void event (); #define printWarning(format, ...) printColour (WARNING_COLOUR, format, __VA_ARGS__) #define printError(format, ...) printColour (ERROR_COLOUR, format, __VA_ARGS__) +#ifdef __cplusplus +extern "C" { +#endif char *configPath (char *name); toml_table_t *openConfig (char *configFilePath); toml_table_t *openConfigSection (toml_table_t *config, char *sectionName); @@ -111,3 +114,6 @@ bool readConfigBool (toml_table_t *table, char *key, bool notFoundValue); int64_t readConfigInt (toml_table_t *table, char *key, int64_t notFoundValue); char *readConfigString (toml_table_t *table, char *key, char *notFoundValue); void printColour (int colour, const char *format, ...); +#ifdef __cplusplus +} +#endif