Add automatically apply OpenSSL patch for Intel Gen 10+ CPUs #43

Open
kagaminehaku wants to merge 5 commits from kagaminehaku/segatools:develop into develop
6 changed files with 41 additions and 5 deletions
Showing only changes of commit cef3406691 - Show all commits

View File

@ -23,6 +23,7 @@
#include "platform/platform.h" #include "platform/platform.h"
#include "platform/vfs.h" #include "platform/vfs.h"
#include "platform/system.h" #include "platform/system.h"
#include "platform/opensslpatch.h"
void platform_config_load(struct platform_config *cfg, const wchar_t *filename) 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); nusec_config_load(&cfg->nusec, filename);
vfs_config_load(&cfg->vfs, filename); vfs_config_load(&cfg->vfs, filename);
system_config_load(&cfg->system, 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) 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); 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
);
}

View File

@ -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 pcbid_config_load(struct pcbid_config *cfg, const wchar_t *filename);
void vfs_config_load(struct vfs_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 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);

View File

@ -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;
}
kagaminehaku marked this conversation as resolved Outdated

I would only keep this print, change it to add that the patch applied successfully and remove the

dprintf("OpenSSL Patch applied successfully.\n");
I would only keep this print, change it to add that the patch applied successfully and remove the ```c dprintf("OpenSSL Patch applied successfully.\n"); ```
char* cpuname = get_cpu_name(); char* cpuname = get_cpu_name();
if (cpuname == NULL) { if (cpuname == NULL) {
dprintf("OpenSSL Patch: Error: Unable to detect CPU.\n"); dprintf("OpenSSL Patch: Error: Unable to detect CPU.\n");
return 1; return S_FALSE;
} }
if (check_cpu(cpuname)) { if (check_cpu(cpuname)) {
openssl_patch(); openssl_patch();
} }
free(cpuname); free(cpuname);
return 0; return S_OK;
} }

View File

@ -1,3 +1,7 @@
#pragma once #pragma once
int openssl_patch_apply(void); struct openssl_patch_config {
int enable;
};
kagaminehaku marked this conversation as resolved Outdated

Only add the function you need to access from outside so in your case only ChecknPatch(). All other functions can be static.

Only add the function you need to access from outside so in your case only `ChecknPatch()`. All other functions can be static.
HRESULT openssl_patch_apply(const struct openssl_patch_config *cfg);

View File

@ -29,7 +29,11 @@ HRESULT platform_hook_init(
assert(platform_id != NULL); assert(platform_id != NULL);
assert(redir_mod != NULL); assert(redir_mod != NULL);
openssl_patch_apply(); hr = openssl_patch_apply(&cfg->openssl);
kagaminehaku marked this conversation as resolved Outdated

I would rename it to something more descriptive, like openssl_patch_apply().

I would rename it to something more descriptive, like `openssl_patch_apply()`.
if (FAILED(hr)) {
return hr;
}
hr = amvideo_hook_init(&cfg->amvideo, redir_mod); hr = amvideo_hook_init(&cfg->amvideo, redir_mod);

View File

@ -29,6 +29,7 @@ struct platform_config {
struct nusec_config nusec; struct nusec_config nusec;
struct vfs_config vfs; struct vfs_config vfs;
struct system_config system; struct system_config system;
struct openssl_patch_config openssl;
}; };
HRESULT platform_hook_init( HRESULT platform_hook_init(