From cef3406691891a0065f970d436e038ab9f9a380e Mon Sep 17 00:00:00 2001 From: Kagamine Haku Date: Fri, 18 Oct 2024 13:34:25 +0700 Subject: [PATCH] Add switch for openssl patch in segatools.ini --- platform/config.c | 17 +++++++++++++++++ platform/config.h | 1 + platform/opensslpatch.c | 15 ++++++++++++--- platform/opensslpatch.h | 6 +++++- platform/platform.c | 6 +++++- platform/platform.h | 1 + 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/platform/config.c b/platform/config.c index ad97905..98b67b6 100644 --- a/platform/config.c +++ b/platform/config.c @@ -23,6 +23,7 @@ #include "platform/platform.h" #include "platform/vfs.h" #include "platform/system.h" +#include "platform/opensslpatch.h" void platform_config_load(struct platform_config *cfg, const wchar_t *filename) { @@ -41,6 +42,7 @@ void platform_config_load(struct platform_config *cfg, const wchar_t *filename) nusec_config_load(&cfg->nusec, filename); vfs_config_load(&cfg->vfs, filename); system_config_load(&cfg->system, filename); + openssl_patch_config_load(&cfg->openssl, filename); } void amvideo_config_load(struct amvideo_config *cfg, const wchar_t *filename) @@ -355,3 +357,18 @@ void epay_config_load(struct epay_config *cfg, const wchar_t *filename) cfg->enable = GetPrivateProfileIntW(L"epay", L"enable", 1, filename); } + +void openssl_patch_config_load(struct openssl_patch_config *cfg, const wchar_t *filename) +{ + // Ensure the config structure and filename are valid + assert(cfg != NULL); + assert(filename != NULL); + + // Read the "enable" key from the "[openssl]" section of the configuration file + cfg->enable = GetPrivateProfileIntW( + L"openssl", // Section name + L"enable", // Key name + 1, // Default value if the key is not found (disabled by default) + filename // INI file name + ); +} diff --git a/platform/config.h b/platform/config.h index e945378..9f1f7f4 100644 --- a/platform/config.h +++ b/platform/config.h @@ -36,3 +36,4 @@ void nusec_config_load(struct nusec_config *cfg, const wchar_t *filename); void pcbid_config_load(struct pcbid_config *cfg, const wchar_t *filename); void vfs_config_load(struct vfs_config *cfg, const wchar_t *filename); void system_config_load(struct system_config *cfg, const wchar_t *filename); +void openssl_patch_config_load(struct openssl_patch_config *cfg, const wchar_t *filename); \ No newline at end of file diff --git a/platform/opensslpatch.c b/platform/opensslpatch.c index 4537195..bebbaf9 100644 --- a/platform/opensslpatch.c +++ b/platform/opensslpatch.c @@ -79,16 +79,25 @@ static void openssl_patch(void) { } } -int openssl_patch_apply(void) { +HRESULT openssl_patch_apply(const struct openssl_patch_config *cfg) { + HRESULT hr; + + assert(cfg != NULL); + + if (!cfg->enable) { + return S_FALSE; + } + char* cpuname = get_cpu_name(); if (cpuname == NULL) { dprintf("OpenSSL Patch: Error: Unable to detect CPU.\n"); - return 1; + return S_FALSE; } if (check_cpu(cpuname)) { openssl_patch(); } + free(cpuname); - return 0; + return S_OK; } \ No newline at end of file diff --git a/platform/opensslpatch.h b/platform/opensslpatch.h index fe665a5..f97d9b7 100644 --- a/platform/opensslpatch.h +++ b/platform/opensslpatch.h @@ -1,3 +1,7 @@ #pragma once -int openssl_patch_apply(void); +struct openssl_patch_config { + int enable; +}; + +HRESULT openssl_patch_apply(const struct openssl_patch_config *cfg); diff --git a/platform/platform.c b/platform/platform.c index 4f663bc..c61c031 100644 --- a/platform/platform.c +++ b/platform/platform.c @@ -29,7 +29,11 @@ HRESULT platform_hook_init( assert(platform_id != NULL); assert(redir_mod != NULL); - openssl_patch_apply(); + hr = openssl_patch_apply(&cfg->openssl); + + if (FAILED(hr)) { + return hr; + } hr = amvideo_hook_init(&cfg->amvideo, redir_mod); diff --git a/platform/platform.h b/platform/platform.h index b9bf7fd..4972bfe 100644 --- a/platform/platform.h +++ b/platform/platform.h @@ -29,6 +29,7 @@ struct platform_config { struct nusec_config nusec; struct vfs_config vfs; struct system_config system; + struct openssl_patch_config openssl; }; HRESULT platform_hook_init(