From 80bcc4f900f5442b3ff5223111d39224d5be558a Mon Sep 17 00:00:00 2001 From: yellows111 Date: Wed, 14 Aug 2024 17:34:00 +0100 Subject: [PATCH] semi-dynamic way to specify re-directions This started with an experimental branch, if you was wondering. --- MSNRedirector/MSNRedirector.def | 1 + MSNRedirector/dllmain.cpp | 48 ++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/MSNRedirector/MSNRedirector.def b/MSNRedirector/MSNRedirector.def index 2eb451a..77e28be 100644 --- a/MSNRedirector/MSNRedirector.def +++ b/MSNRedirector/MSNRedirector.def @@ -2,3 +2,4 @@ LIBRARY MSNRedirector.dll EXPORTS ImportThis @1 + ImportMe @2 diff --git a/MSNRedirector/dllmain.cpp b/MSNRedirector/dllmain.cpp index 375d99d..68197ff 100644 --- a/MSNRedirector/dllmain.cpp +++ b/MSNRedirector/dllmain.cpp @@ -9,6 +9,8 @@ const char* MESSENGERSERVICE_DEFAULT = "vm9.computernewb.com"; char* MESSENGERSERVICE = NULL; +HKEY REGISTRYROOT; + HINTERNET(WINAPI * Real_InternetConnectA) (HINTERNET hInternet, LPCSTR lpszServerName, INTERNET_PORT nServerPort, LPCSTR lpszUserName, LPCSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext) = InternetConnectA; HINTERNET(WINAPI * Real_InternetConnectW) (HINTERNET hInternet, LPCWSTR lpszServerName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName, LPCWSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContect) = InternetConnectW; @@ -16,22 +18,20 @@ hostent * (WSAAPI * Real_gethostbyname) (const char *name) = gethostbyname; INT(WSAAPI * Real_getaddrinfo) (PCSTR pNodeName, PCSTR pServiceName, const ADDRINFOA *pHints, PADDRINFOA *ppResult) = getaddrinfo; BOOL ServerNeedsPatching(const char* server) { - return ( - /* msn live domains, commonly used */ - strcmp(server, "nexus.passport.com") == 0 || - strcmp(server, "messenger.hotmail.com") == 0 || - strcmp(server, "loginnet.passport.com") == 0 || - strcmp(server, "config.messenger.msn.com") == 0 || - /* msn internal domains, rarely used, common in betas */ - strcmp(server, "nexus.passport-int.com") == 0 || - strcmp(server, "messenger.hotmail-int.com") == 0 || - strcmp(server, "config.messenger.msn-int.com") == 0 /* || */ - /* msn pre-production environment domains, very rarely used */ - /*strcmp(server, "nexus.passport-ppe.com") == 0 || - strcmp(server, "nexus.passporttest.com") == 0 || - strcmp(server, "messenger.hotmail-ppe.com") == 0 || - strcmp(server, "config.messenger.msn-ppe.com") == 0*/ - ); + if(strcmp(server, MESSENGERSERVICE) == 0) { + return false; + } + DWORD type; + DWORD size; + LSTATUS status = RegQueryValueExA(REGISTRYROOT, server, NULL, &type, NULL, &size); + if (status == ERROR_SUCCESS) { + MessageBoxA(NULL, "did it", "eys", MB_OK | MB_ICONERROR); + //byte* data = (byte*)malloc(size); + //status2 = RegQueryValueExA(key, "Server", NULL, NULL, data, &size); + return true; + } + MessageBoxA(NULL, "nope", "NO", MB_OK | MB_ICONERROR); + return false; } HINTERNET WINAPI Patched_InternetConnectA(HINTERNET hInternet, LPCSTR lpszServerName, INTERNET_PORT nServerPort, LPCSTR lpszUserName, LPCSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext) { @@ -80,6 +80,7 @@ VOID LoadURL() { SetFallbackService(); return; } + REGISTRYROOT = key; DWORD type; DWORD size; // Get size @@ -87,20 +88,20 @@ VOID LoadURL() { if (status == ERROR_FILE_NOT_FOUND) { SetFallbackService(); RegSetValueExA(key, "Server", 0, REG_SZ, (byte*)MESSENGERSERVICE, strlen(MESSENGERSERVICE)); - RegCloseKey(key); + //RegCloseKey(key); return; } if (status != ERROR_SUCCESS) { char c[128]; sprintf_s(c, "Reading MSNRedirector Server from registry failed with system error %d\nFalling back to default", status); MessageBoxA(NULL, c, "Computernewb MSNRedirector", MB_OK | MB_ICONERROR); - RegCloseKey(key); + //RegCloseKey(key); SetFallbackService(); return; } if (type != REG_SZ) { MessageBoxA(NULL, "Reading MSNRedirector Server from registry failed because the value is not a string.\nFalling back to default", "Computernewb MSNRedirector", MB_OK | MB_ICONERROR); - RegCloseKey(key); + //RegCloseKey(key); SetFallbackService(); return; } @@ -112,11 +113,11 @@ VOID LoadURL() { sprintf_s(c, "Reading MSNRedirector Server from registry failed with system error %d\nFalling back to default", status); MessageBoxA(NULL, c, "Computernewb MSNRedirector", MB_OK | MB_ICONERROR); free(data); - RegCloseKey(key); + //RegCloseKey(key); SetFallbackService(); return; } - RegCloseKey(key); + //RegCloseKey(key); MESSENGERSERVICE = (char*)data; return; } @@ -152,6 +153,8 @@ BOOL APIENTRY DllMain( HMODULE hModule, //DetourDetach(&(PVOID&)Real_gethostbyname, Patched_gethostbyname); DetourDetach(&(PVOID&)Real_getaddrinfo, Patched_getaddrinfo); + RegCloseKey(REGISTRYROOT); + DetourTransactionCommit(); break; } @@ -159,4 +162,5 @@ BOOL APIENTRY DllMain( HMODULE hModule, return TRUE; } -__declspec(dllexport) void WINAPI ImportThis() {} \ No newline at end of file +__declspec(dllexport) void WINAPI ImportThis() {} +__declspec(dllexport) void WINAPI ImportMe() {} \ No newline at end of file