#include #include #include #include #include #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 ) { }