Add support for loading server from registry

This commit is contained in:
Elijah 2024-05-31 13:55:44 -04:00
parent 9a961d8ace
commit c9f2f0da19

View file

@ -4,7 +4,10 @@
#pragma comment (lib, "wininet.lib")
#pragma comment (lib, "Ws2_32.lib")
const char* PASSPORTNEXUS_HOST = "vm9.computernewb.com";
// Used as a fallback if server cannot be read from the registry
const char* MESSENGERSERVICE_DEFAULT = "vm9.computernewb.com";
char* MESSENGERSERVICE = NULL;
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;
@ -14,32 +17,89 @@ INT(WSAAPI * Real_getaddrinfo) (PCSTR pNodeName, PCSTR pServiceName, const ADDRI
HINTERNET WINAPI Patched_InternetConnectA(HINTERNET hInternet, LPCSTR lpszServerName, INTERNET_PORT nServerPort, LPCSTR lpszUserName, LPCSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext) {
if (strcmp(lpszServerName, "nexus.passport.com") == 0 || strcmp(lpszServerName, "messenger.hotmail.com") == 0) {
return Real_InternetConnectA(hInternet, PASSPORTNEXUS_HOST, nServerPort, lpszUserName, lpszPassword, dwService, dwFlags, dwContext);
return Real_InternetConnectA(hInternet, MESSENGERSERVICE, nServerPort, lpszUserName, lpszPassword, dwService, dwFlags, dwContext);
}
return Real_InternetConnectA(hInternet, lpszServerName, nServerPort, lpszUserName, lpszPassword, dwService, dwFlags, dwContext);
}
HINTERNET WINAPI Patched_InternetConnectW(HINTERNET hInternet, LPCWSTR lpszServerName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName, LPCWSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext) {
if (lstrcmpW(lpszServerName, L"nexus.passport.com") == 0 || lstrcmpW(lpszServerName, L"messenger.hotmail.com") == 0) {
return Real_InternetConnectW(hInternet, CA2CT(PASSPORTNEXUS_HOST), nServerPort, lpszUserName, lpszPassword, dwService, dwFlags, dwContext);
return Real_InternetConnectW(hInternet, CA2CT(MESSENGERSERVICE), nServerPort, lpszUserName, lpszPassword, dwService, dwFlags, dwContext);
}
return Real_InternetConnectW(hInternet, lpszServerName, nServerPort, lpszUserName, lpszPassword, dwService, dwFlags, dwContext);
}
hostent *WSAAPI Patched_gethostbyname(const char* name) {
if (strcmp(name, "messenger.hotmail.com") == 0) {
name = PASSPORTNEXUS_HOST;
name = MESSENGERSERVICE;
}
return Real_gethostbyname(name);
}
INT WSAAPI Patched_getaddrinfo(PCSTR pNodeName, PCSTR pServiceName, const ADDRINFOA *pHints, PADDRINFOA *ppResult) {
if (pNodeName != NULL && strcmp(pNodeName, "messenger.hotmail.com") == 0) {
pNodeName = PASSPORTNEXUS_HOST;
pNodeName = MESSENGERSERVICE;
}
return Real_getaddrinfo(pNodeName, pServiceName, pHints, ppResult);
}
VOID SetFallbackService() {
int size = strlen(MESSENGERSERVICE_DEFAULT) + 1;
MESSENGERSERVICE = (char*)calloc(size, sizeof(char));
strcpy_s(MESSENGERSERVICE, size, MESSENGERSERVICE_DEFAULT);
}
VOID LoadURL() {
HKEY key;
LSTATUS status = RegCreateKeyExA(HKEY_CURRENT_USER, "SOFTWARE\\Computernewb\\MSNRedirector", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL);
if (status != ERROR_SUCCESS) {
// Fall back
char c[128];
sprintf_s(c, "Opening MSNRedirector registry key failed with system error %d\nFalling back to default", status);
MessageBoxA(NULL, c, "Computernewb MSNRedirector", MB_OK | MB_ICONERROR);
SetFallbackService();
return;
}
DWORD type;
DWORD size;
// Get size
status = RegQueryValueExA(key, "Server", NULL, &type, NULL, &size);
if (status == ERROR_FILE_NOT_FOUND) {
SetFallbackService();
RegSetValueExA(key, "Server", 0, REG_SZ, (byte*)MESSENGERSERVICE, strlen(MESSENGERSERVICE));
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);
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);
SetFallbackService();
return;
}
// Read key
byte* data = (byte*)malloc(size);
status = RegQueryValueExA(key, "SERVER", NULL, NULL, data, &size);
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);
free(data);
RegCloseKey(key);
SetFallbackService();
return;
}
RegCloseKey(key);
MESSENGERSERVICE = (char*)data;
return;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
@ -49,6 +109,7 @@ BOOL APIENTRY DllMain( HMODULE hModule,
{
case DLL_PROCESS_ATTACH:
{
LoadURL();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());