commit so I can work somewhere else lol

This commit is contained in:
Kevin Trocolli
2024-02-14 13:17:04 -05:00
parent 0263157f1a
commit ffcf6dafc2
9 changed files with 188 additions and 0 deletions
+139
View File
@@ -0,0 +1,139 @@
#include <windows.h>
#include <wincrypt.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include "hook/table.h"
#include "platform/cert.h"
#include "hook/procaddr.h"
#include "util/dprintf.h"
#include "util/str.h"
static CRITICAL_SECTION cert_lock;
static wchar_t path[MAX_PATH];
HCERTSTORE WINAPI hook_CertOpenStore(
LPCSTR lpszStoreProvider,
DWORD dwEncodingType,
HCRYPTPROV_LEGACY hCryptProv,
DWORD dwFlags,
const void *pvPara
);
PCCERT_CONTEXT WINAPI hook_CertFindCertificateInStore(
HCERTSTORE hCertStore,
DWORD dwCertEncodingType,
DWORD dwFindFlags,
DWORD dwFindType,
const void *pvFindPara,
PCCERT_CONTEXT pPrevCertContext
);
BOOL WINAPI hook_CertCloseStore(
HCERTSTORE hCertStore,
DWORD dwFlags
);
HCERTSTORE (WINAPI *next_CertOpenStore)(
LPCSTR lpszStoreProvider,
DWORD dwEncodingType,
HCRYPTPROV_LEGACY hCryptProv,
DWORD dwFlags,
const void *pvPara
);
PCCERT_CONTEXT (WINAPI *next_CertFindCertificateInStore)(
HCERTSTORE hCertStore,
DWORD dwCertEncodingType,
DWORD dwFindFlags,
DWORD dwFindType,
const void *pvFindPara,
PCCERT_CONTEXT pPrevCertContext
);
BOOL (WINAPI *next_CertCloseStore)(
HCERTSTORE hCertStore,
DWORD dwFlags
);
static const struct hook_symbol cert_syms[] = {
{
.name = "CertOpenStore",
.patch = hook_CertOpenStore,
.link = (void **) &next_CertOpenStore,
}, {
.name = "CertFindCertificateInStore",
.patch = hook_CertFindCertificateInStore,
.link = (void **) &next_CertFindCertificateInStore,
}, {
.name = "CertCloseStore",
.patch = hook_CertCloseStore,
.link = (void **) &next_CertCloseStore,
},
};
HRESULT cert_hook_init(const struct cert_config *cfg)
{
assert(cfg != NULL);
if (!cfg->enable) {
return S_FALSE;
}
dprintf("Cert hook init\n");
wcscpy_s(path, MAX_PATH, cfg->path);
InitializeCriticalSection(&cert_lock);
cert_hook_insert_hooks(NULL);
proc_addr_table_push(
NULL,
"crypt32.dll",
(struct hook_symbol *) cert_syms,
_countof(cert_syms));
return S_OK;
}
void cert_hook_insert_hooks(HMODULE target)
{
hook_table_apply(
target,
"crypt32.dll",
cert_syms,
_countof(cert_syms));
}
HCERTSTORE WINAPI hook_CertOpenStore(
LPCSTR lpszStoreProvider,
DWORD dwEncodingType,
HCRYPTPROV_LEGACY hCryptProv,
DWORD dwFlags,
const void *pvPara
)
{
}
PCCERT_CONTEXT WINAPI hook_CertFindCertificateInStore(
HCERTSTORE hCertStore,
DWORD dwCertEncodingType,
DWORD dwFindFlags,
DWORD dwFindType,
const void *pvFindPara,
PCCERT_CONTEXT pPrevCertContext
)
{
}
BOOL WINAPI hook_CertCloseStore(
HCERTSTORE hCertStore,
DWORD dwFlags
)
{
}
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <windows.h>
#include <stddef.h>
#include <stdint.h>
struct cert_config {
bool enable;
wchar_t path[MAX_PATH];
};
HRESULT cert_hook_init(const struct cert_config *cfg);
void cert_hook_insert_hooks(HMODULE target);
+17
View File
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include "platform/cert.h"
#include "platform/clock.h"
#include "platform/config.h"
#include "platform/dns.h"
@@ -24,6 +25,7 @@ void platform_config_load(struct platform_config *cfg, const wchar_t *filename)
assert(cfg != NULL);
assert(filename != NULL);
cert_config_load(&cfg->cert, filename);
clock_config_load(&cfg->clock, filename);
dns_config_load(&cfg->dns, filename);
misc_config_load(&cfg->misc, filename);
@@ -33,6 +35,21 @@ void platform_config_load(struct platform_config *cfg, const wchar_t *filename)
syscfg_config_load(&cfg->syscfg, filename);
}
void cert_config_load(struct cert_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
assert(filename != NULL);
cfg->enable = GetPrivateProfileIntW(L"cert", L"enable", 1, filename);
GetPrivateProfileStringW(
L"cert",
L"path",
L"cert",
cfg->path,
_countof(cfg->path),
filename);
}
void clock_config_load(struct clock_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
+2
View File
@@ -6,6 +6,7 @@
#include <stddef.h>
#include <stdint.h>
#include "platform/cert.h"
#include "platform/clock.h"
#include "platform/dns.h"
#include "platform/misc.h"
@@ -19,6 +20,7 @@ void platform_config_load(
struct platform_config *cfg,
const wchar_t *filename);
void cert_config_load(struct cert_config *cfg, const wchar_t *filename);
void clock_config_load(struct clock_config *cfg, const wchar_t *filename);
void dns_config_load(struct dns_config *cfg, const wchar_t *filename);
void misc_config_load(struct misc_config *cfg, const wchar_t *filename);
+2
View File
@@ -8,6 +8,8 @@ platform_lib = static_library(
shlwapi_lib,
],
sources : [
'cert.c',
'cert.h',
'clock.c',
'clock.h',
'config.c',
+7
View File
@@ -2,6 +2,7 @@
#include <assert.h>
#include "platform/cert.h"
#include "platform/clock.h"
#include "platform/dns.h"
#include "platform/misc.h"
@@ -22,6 +23,12 @@ HRESULT platform_hook_init(
assert(game_id != 0);
assert(redir_mod != NULL);
hr = cert_hook_init(&cfg->cert);
if (FAILED(hr)) {
return hr;
}
hr = clock_hook_init(&cfg->clock);
if (FAILED(hr)) {
+2
View File
@@ -2,6 +2,7 @@
#include <windows.h>
#include "platform/cert.h"
#include "platform/clock.h"
#include "platform/dns.h"
#include "platform/misc.h"
@@ -11,6 +12,7 @@
#include "platform/syscfg.h"
struct platform_config {
struct cert_config cert;
struct clock_config clock;
struct dns_config dns;
struct misc_config misc;