sys: Embed resources into rodata

This commit is contained in:
WerWolv
2021-07-31 17:10:19 +02:00
parent bca7f738a1
commit e8d77f8269
9 changed files with 89 additions and 24 deletions

View File

@@ -56,6 +56,8 @@ set(LIBIMHEX_SOURCES
source/providers/provider.cpp
source/views/view.cpp
source/resources.cpp
)
if (APPLE)

View File

@@ -0,0 +1,16 @@
#pragma once
#define RESOURCE_EXPORT(name) \
extern "C" unsigned char name[]; \
extern "C" int name##_size;
RESOURCE_EXPORT(splash);
RESOURCE_EXPORT(banner_light);
RESOURCE_EXPORT(banner_dark);
RESOURCE_EXPORT(cacert);
#undef RESOURCE_EXPORT

View File

@@ -4,6 +4,11 @@
#include <filesystem>
#include <mbedtls/x509.h>
#include <mbedtls/x509_crt.h>
#include <hex/resources.hpp>
namespace hex {
Net::Net() {
@@ -45,10 +50,16 @@ namespace hex {
curl_easy_setopt(ctx, CURLOPT_WRITEFUNCTION, writeToString);
curl_easy_setopt(ctx, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(ctx, CURLOPT_SSL_VERIFYHOST, 1L);
for (const auto &resourceDir : hex::getPath(hex::ImHexPath::Resources)) {
if (std::filesystem::exists(resourceDir + "/cacert.pem"))
curl_easy_setopt(ctx, CURLOPT_CAPATH, resourceDir.c_str());
}
curl_easy_setopt(ctx, CURLOPT_CAINFO, nullptr);
curl_easy_setopt(ctx, CURLOPT_CAPATH, nullptr);
curl_easy_setopt(ctx, CURLOPT_SSL_CTX_DATA, [](CURL *ctx, void *sslctx, void *userdata) -> CURLcode {
auto* mbedtlsCert = static_cast<mbedtls_x509_crt*>(sslctx);
mbedtls_x509_crt_init(mbedtlsCert);
mbedtls_x509_crt_parse(mbedtlsCert, cacert, cacert_size);
return CURLE_OK;
});
curl_easy_setopt(ctx, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(ctx, CURLOPT_TIMEOUT_MS, 2000L);
curl_easy_setopt(ctx, CURLOPT_CONNECTTIMEOUT_MS, 2000L);

View File

@@ -0,0 +1,18 @@
#define RESOURCE(name, path) __asm__ ( \
".section .rodata\n" \
".global " #name "\n" \
".global " #name "_size\n" \
#name ":\n" \
".incbin \"" path "\"\n" \
".type " #name ", @object\n" \
".size " #name "_size, 1\n" \
#name "_size:\n" \
".int " #name "_size - " #name "\n" \
".align 8\n" \
)
RESOURCE(banner_light, "../../../res/resources/banner_light.png");
RESOURCE(banner_dark, "../../../res/resources/banner_dark.png");
RESOURCE(splash, "../../../res/resources/splash.png");
RESOURCE(cacert, "../../../res/resources/cacert.pem");