From 9497e2ab7a66e13f0eeca0de365d8a250d93a870 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Fri, 25 Feb 2022 15:30:46 +0100 Subject: [PATCH] More DW stuff --- src/client/component/demonware.cpp | 124 +++++++++++++++--- .../game/demonware/servers/auth3_server.cpp | 16 +++ 2 files changed, 125 insertions(+), 15 deletions(-) diff --git a/src/client/component/demonware.cpp b/src/client/component/demonware.cpp index e4ceb6f9..c41cd43b 100644 --- a/src/client/component/demonware.cpp +++ b/src/client/component/demonware.cpp @@ -142,6 +142,40 @@ namespace demonware return 0; } + int getpeername_stub(const SOCKET s, sockaddr* addr, socklen_t* addrlen) + { + auto* server = find_server(s); + + if (server) + { + auto in_addr = reinterpret_cast(addr); + in_addr->sin_addr.s_addr = server->get_address(); + in_addr->sin_family = AF_INET; + *addrlen = sizeof(sockaddr); + + return 0; + } + + return getpeername(s, addr, addrlen); + } + + int getsockname_stub(const SOCKET s, sockaddr* addr, socklen_t* addrlen) + { + auto* server = find_server(s); + + if (server) + { + auto in_addr = reinterpret_cast(addr); + in_addr->sin_addr.s_addr = server->get_address(); + in_addr->sin_family = AF_INET; + *addrlen = sizeof(sockaddr); + + return 0; + } + + return getsockname(s, addr, addrlen); + } + hostent* gethostbyname_stub(const char* name) { #ifdef DEBUG @@ -369,23 +403,60 @@ namespace demonware void bd_logger_stub(char* a1, void* a2, void* a3, void* a4, const char* function, ...) { - static const auto* enabled = dvars::register_bool("bd_logger_enabled", false, game::DVAR_FLAG_SAVED, true); - if (!enabled->current.enabled) - { - return; - } - - /*char buffer[2048]; - - va_list ap; - va_start(ap, msg); - - vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap); - printf("%s: %s\n", function, buffer); - - va_end(ap);*/ } + +#ifdef DEBUG + void a(unsigned int n) + { + printf("bdAuth: Auth task failed with HTTP code [%u]\n", n); + } + + void b(unsigned int n) + { + printf("bdAuth: Decoded client ticket of unexpected size [%u]\n", n); + } + + void c(unsigned int n) + { + printf("bdAuth: Decoded server ticket of unexpected size [%u]\n", n); + } + + void d() + { + printf("bdAuth: Auth ticket magic number mismatch\n"); + } + + void e() + { + printf("bdAuth: Cross Authentication completed\n"); + } + + void f() + { + printf("bdAuth: Auth task reply contains invalid data / format\n"); + } + + void g(unsigned int n) + { + printf("bdAuth: Auth task returned with error code [%u]\n", n); + } + + void h(unsigned int n) + { + printf("bdAuth: Invalid or No Task ID [%u] in Auth reply\n", n); + } + + void i() + { + printf("bdAuth: Received reply from DemonWare Auth server\n"); + } + + void l() + { + printf("bdAuth: Unknown error\n"); + } +#endif } class component final : public component_interface @@ -417,8 +488,11 @@ namespace demonware { if (library == "WS2_32.dll") { + printf("%s\n", function.data()); if (function == "#3") return io::closesocket_stub; if (function == "#4") return io::connect_stub; + if (function == "#5") return io::getpeername_stub; + if (function == "#6") return io::getsockname_stub; if (function == "#10") return io::ioctlsocket_stub; if (function == "#16") return io::recv_stub; if (function == "#17") return io::recvfrom_stub; @@ -461,10 +535,30 @@ namespace demonware utils::hook::inject(0x14006DDA9, "http://prod.umbrella.demonware.net/v1.0/"); // ---> [H1MP1.4 - S1X: 0x14003852E] utils::hook::inject(0x14006E11C, "http://prod.umbrella.demonware.net/v1.0/"); // ---> [H1MP1.4 - S1X: 0x14003884F] utils::hook::inject(0x14006E2FB, "http://prod.umbrella.demonware.net/v1.0/"); // ---> [H1MP1.4 - S1X: 0x140038A07] + utils::hook::inject(0x14006E9A9, "http://prod.uno.demonware.net/v1.0/"); + utils::hook::inject(0x14006ED49, "http://prod.uno.demonware.net/v1.0/"); utils::hook::inject(0x140728170, "http://%s:%d/auth/"); utils::hook::set(0x14047F290, 0xC3); // SV_SendMatchData H1MP64(1.4) utils::hook::set(0x140598990, 0xC3); // Live_CheckForFullDisconnect H1MP64(1.4) + +#ifdef DEBUG + // yes + utils::hook::call(0x140727BEB, l); + utils::hook::call(0x140727AFC, i); + utils::hook::call(0x140727E49, h); + utils::hook::call(0x140727E30, g); + utils::hook::call(0x140727E37, f); + utils::hook::call(0x140727DF2, e); + utils::hook::call(0x140727DF9, d); + utils::hook::call(0x140727CFC, c); + utils::hook::call(0x140727C82, b); + utils::hook::call(0x140727E6A, a); +#endif + // Checks X-Signature header or something + utils::hook::set(0x140728380, 0xC301B0); + // Checks extended_data and extra_data in json object + utils::hook::set(0x140728E90, 0xC301B0); } void pre_destroy() override diff --git a/src/client/game/demonware/servers/auth3_server.cpp b/src/client/game/demonware/servers/auth3_server.cpp index 4f35d427..601e7511 100644 --- a/src/client/game/demonware/servers/auth3_server.cpp +++ b/src/client/game/demonware/servers/auth3_server.cpp @@ -49,6 +49,10 @@ namespace demonware std::string identity{}; std::string token{}; +#ifdef DEBUG + printf("%s\n", packet.data()); +#endif + rapidjson::Document j; j.Parse(packet.data(), packet.size()); @@ -62,6 +66,11 @@ namespace demonware iv_seed = std::stoul(j["iv_seed"].GetString()); } + if (j.HasMember("identity") && j["identity"].IsString()) + { + identity = j["identity"].GetString(); + } + if (j.HasMember("extra_data") && j["extra_data"].IsString()) { rapidjson::Document extra_data; @@ -127,6 +136,9 @@ namespace demonware auto seed = std::to_string(iv_seed); doc.AddMember("iv_seed", rapidjson::StringRef(seed.data(), seed.size()), doc.GetAllocator()); +#ifndef DEBUG + doc.AddMember("identity", rapidjson::StringRef(identity.data(), identity.size()), doc.GetAllocator()); +#endif doc.AddMember("client_ticket", rapidjson::StringRef(ticket_b64.data(), ticket_b64.size()), doc.GetAllocator()); doc.AddMember("server_ticket", rapidjson::StringRef(auth_data_b64.data(), auth_data_b64.size()), doc.GetAllocator()); @@ -153,6 +165,10 @@ namespace demonware result.append(buffer.GetString(), buffer.GetLength()); raw_reply reply(result); + +#ifdef DEBUG + printf("sending reply: %s\n", result.data()); +#endif this->send_reply(&reply); #ifdef DEBUG