Compare commits

..

No commits in common. "develop" and "develop" have entirely different histories.

9 changed files with 3 additions and 132 deletions

View File

@ -14,7 +14,6 @@
#include "hook/table.h" #include "hook/table.h"
#include "util/dprintf.h" #include "util/dprintf.h"
#include "util/get_function_ordinal.h"
#include "hooklib/dns.h" #include "hooklib/dns.h"
@ -82,12 +81,6 @@ static bool WINAPI hook_WinHttpCrackUrl(
DWORD dwFlags, DWORD dwFlags,
LPURL_COMPONENTS lpUrlComponents); LPURL_COMPONENTS lpUrlComponents);
static DWORD WINAPI hook_send(
SOCKET s,
const char* buf,
int len,
int flags);
/* Link pointers */ /* Link pointers */
static DNS_STATUS (WINAPI *next_DnsQuery_A)( static DNS_STATUS (WINAPI *next_DnsQuery_A)(
@ -129,12 +122,6 @@ static bool (WINAPI *next_WinHttpCrackUrl)(
DWORD dwFlags, DWORD dwFlags,
LPURL_COMPONENTS lpUrlComponents); LPURL_COMPONENTS lpUrlComponents);
static DWORD (WINAPI *next_send)(
SOCKET s,
const char* buf,
int len,
int flags);
static const struct hook_symbol dns_hook_syms_dnsapi[] = { static const struct hook_symbol dns_hook_syms_dnsapi[] = {
{ {
.name = "DnsQuery_A", .name = "DnsQuery_A",
@ -157,7 +144,7 @@ static const struct hook_symbol dns_hook_syms_ws2[] = {
.ordinal = 176, .ordinal = 176,
.patch = hook_getaddrinfo, .patch = hook_getaddrinfo,
.link = (void **) &next_getaddrinfo, .link = (void **) &next_getaddrinfo,
}, }
}; };
static const struct hook_symbol dns_hook_syms_winhttp[] = { static const struct hook_symbol dns_hook_syms_winhttp[] = {
@ -170,14 +157,7 @@ static const struct hook_symbol dns_hook_syms_winhttp[] = {
.patch = hook_WinHttpCrackUrl, .patch = hook_WinHttpCrackUrl,
.link = (void **) &next_WinHttpCrackUrl, .link = (void **) &next_WinHttpCrackUrl,
} }
};
static struct hook_symbol http_hook_syms_ws2[] = {
{
.name = "send",
.patch = hook_send,
.link = (void **) &next_send
},
}; };
static bool dns_hook_initted; static bool dns_hook_initted;
@ -206,7 +186,7 @@ static void dns_hook_init(void)
"ws2_32.dll", "ws2_32.dll",
dns_hook_syms_ws2, dns_hook_syms_ws2,
_countof(dns_hook_syms_ws2)); _countof(dns_hook_syms_ws2));
hook_table_apply( hook_table_apply(
NULL, NULL,
"winhttp.dll", "winhttp.dll",
@ -214,18 +194,6 @@ static void dns_hook_init(void)
_countof(dns_hook_syms_winhttp)); _countof(dns_hook_syms_winhttp));
} }
void http_hook_init(){
for (size_t i = 0; i < _countof(http_hook_syms_ws2); ++i) {
http_hook_syms_ws2[i].ordinal = get_function_ordinal("ws2_32.dll", http_hook_syms_ws2[i].name);
}
hook_table_apply(
NULL,
"ws2_32.dll",
http_hook_syms_ws2,
_countof(http_hook_syms_ws2));
}
// This function match domain and subdomains like *.naominet.jp. // This function match domain and subdomains like *.naominet.jp.
bool match_domain(const wchar_t* target, const wchar_t* pattern) { bool match_domain(const wchar_t* target, const wchar_t* pattern) {
if (_wcsicmp(pattern, target) == 0) { if (_wcsicmp(pattern, target) == 0) {
@ -650,49 +618,3 @@ static bool WINAPI hook_WinHttpCrackUrl(
lpUrlComponents lpUrlComponents
); );
} }
DWORD WINAPI hook_send(SOCKET s, const char* buf, int len, int flags) {
if (strstr(buf, "HTTP/") != NULL) {
char *new_buf = malloc(len + 1);
if (new_buf == NULL) return SOCKET_ERROR;
memcpy(new_buf, buf, len);
new_buf[len] = '\0';
char *host_start = strstr(new_buf, "Host: ");
if (host_start != NULL) {
char *host_end = strstr(host_start, "\r\n");
if (host_end != NULL) {
host_end += 2;
int host_len = host_end - host_start;
char *host_value_start = host_start + 6;
char *host_value_end = strstr(host_value_start, "\r\n");
if (host_value_end != NULL) {
int value_len = host_value_end - host_value_start;
char host_value[value_len + 1];
strncpy(host_value, host_value_start, value_len);
host_value[value_len] = '\0';
for (struct dns_hook_entry *entry = dns_hook_entries; entry && entry->from; entry++) {
char from_value[256];
wcstombs(from_value, entry->from, sizeof(from_value));
if (strcmp(host_value, from_value) == 0) {
char to_value[256];
wcstombs(to_value, entry->to, sizeof(to_value));
snprintf(host_start, len - (host_start - new_buf), "Host: %s\r\n", to_value);
break;
}
}
}
len = (int)strlen(new_buf);
}
}
DWORD result = next_send(s, new_buf, len, flags);
free(new_buf);
return result;
}
return next_send(s, buf, len, flags);
}

View File

@ -3,7 +3,7 @@
#include <windows.h> #include <windows.h>
#include <stddef.h> #include <stddef.h>
void http_hook_init();
// if to_src is NULL, all lookups for from_src will fail // if to_src is NULL, all lookups for from_src will fail
HRESULT dns_hook_push(const wchar_t *from_src, const wchar_t *to_src); HRESULT dns_hook_push(const wchar_t *from_src, const wchar_t *to_src);

View File

@ -81,7 +81,6 @@ dinput8_lib = cc.find_library('dinput8')
dxguid_lib = cc.find_library('dxguid') dxguid_lib = cc.find_library('dxguid')
xinput_lib = cc.find_library('xinput') xinput_lib = cc.find_library('xinput')
pathcch_lib = cc.find_library('pathcch') pathcch_lib = cc.find_library('pathcch')
imagehlp_lib = cc.find_library('imagehlp')
inc = include_directories('.') inc = include_directories('.')
capnhook = subproject('capnhook') capnhook = subproject('capnhook')

View File

@ -121,8 +121,6 @@ void dns_config_load(struct dns_config *cfg, const wchar_t *filename)
cfg->title, cfg->title,
_countof(cfg->title), _countof(cfg->title),
filename); filename);
cfg->replaceHost = GetPrivateProfileIntW(L"dns", L"replaceHost", 0, filename);
} }
void hwmon_config_load(struct hwmon_config *cfg, const wchar_t *filename) void hwmon_config_load(struct hwmon_config *cfg, const wchar_t *filename)

View File

@ -16,10 +16,6 @@ HRESULT dns_platform_hook_init(const struct dns_config *cfg)
return S_FALSE; return S_FALSE;
} }
if(cfg->replaceHost){
http_hook_init();
}
hr = dns_hook_push(L"tenporouter.loc", cfg->router); hr = dns_hook_push(L"tenporouter.loc", cfg->router);
if (FAILED(hr)) { if (FAILED(hr)) {

View File

@ -12,7 +12,6 @@ struct dns_config {
wchar_t billing[128]; wchar_t billing[128];
wchar_t aimedb[128]; wchar_t aimedb[128];
wchar_t title[128]; wchar_t title[128];
bool replaceHost;
}; };
HRESULT dns_platform_hook_init(const struct dns_config *cfg); HRESULT dns_platform_hook_init(const struct dns_config *cfg);

View File

@ -1,34 +0,0 @@
#include "get_function_ordinal.h"
DWORD get_function_ordinal(const char* dllName, const char* functionName) {
HMODULE hModule = LoadLibraryA(dllName);
if (!hModule) {
dprintf("Failed to load DLL: %s\n", dllName);
return 0;
}
ULONG size;
PIMAGE_EXPORT_DIRECTORY exportDir = (PIMAGE_EXPORT_DIRECTORY)ImageDirectoryEntryToData(
hModule, TRUE, IMAGE_DIRECTORY_ENTRY_EXPORT, &size);
if (!exportDir) {
dprintf("Failed to get export table\n");
FreeLibrary(hModule);
return 0;
}
DWORD* functionNames = (DWORD*)((BYTE*)hModule + exportDir->AddressOfNames);
WORD* ordinals = (WORD*)((BYTE*)hModule + exportDir->AddressOfNameOrdinals);
for (DWORD i = 0; i < exportDir->NumberOfNames; ++i) {
char* name = (char*)((BYTE*)hModule + functionNames[i]);
if (strcmp(name, functionName) == 0) {
DWORD ordinal = ordinals[i] + exportDir->Base;
FreeLibrary(hModule);
return ordinal;
}
}
dprintf("Function not found: %s\n", functionName);
FreeLibrary(hModule);
return 0;
}

View File

@ -1,6 +0,0 @@
#pragma once
#include <dbghelp.h>
#include "dprintf.h"
DWORD get_function_ordinal(const char* dllName, const char* functionName);

View File

@ -5,7 +5,6 @@ util_lib = static_library(
c_pch : '../precompiled.h', c_pch : '../precompiled.h',
dependencies : [ dependencies : [
capnhook.get_variable('hook_dep'), capnhook.get_variable('hook_dep'),
imagehlp_lib,
], ],
sources : [ sources : [
'async.c', 'async.c',
@ -18,8 +17,6 @@ util_lib = static_library(
'dprintf.h', 'dprintf.h',
'dump.c', 'dump.c',
'dump.h', 'dump.h',
'get_function_ordinal.c',
'get_function_ordinal.h',
'lib.c', 'lib.c',
'lib.h', 'lib.h',
'str.c', 'str.c',