From f1cdacc5c2aaa861b954316d9241edf1aa53cf67 Mon Sep 17 00:00:00 2001 From: Michael <20937441+KMikeeU@users.noreply.github.com> Date: Thu, 14 May 2026 17:16:38 +0200 Subject: [PATCH] fix: search for license file in multiple directories --- src/config.h | 3 ++- src/main.c | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/config.h b/src/config.h index a4e4a6a..7459b78 100644 --- a/src/config.h +++ b/src/config.h @@ -1,8 +1,9 @@ #pragma once #define EMU_MEM_SIZE 16384u -#define EMU_PROGRAM_PATH "build/license" #define EMU_ENTRY_SYMBOL "entry" +#define EMU_PROGRAM_PATHS {"license", "build/license"}; + #define STACK_SIZE 1024 #define RISCV_MEM_OFFSET 0x80000000 diff --git a/src/main.c b/src/main.c index 8dc00da..7f3004f 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,8 @@ #define MAX_STEPS 1024u +static const char* emu_program_paths[] = EMU_PROGRAM_PATHS; + int main(){ hw_info_t hwinfo = {0}; if(get_hw_info(&hwinfo) != 0){ @@ -42,7 +44,19 @@ int main(){ struct AES_ctx ctx; uint8_t nonce[16] = {0}; - FILE* license = fopen(EMU_PROGRAM_PATH, "rb"); + FILE* license; + for(size_t i = 0; i < sizeof(emu_program_paths); i++) { + license = fopen(emu_program_paths[i], "rb"); + if (license != NULL) { + break; + } + } + + if (license == NULL) { + fprintf(stderr, "Could not find license file\n"); + return 1; + } + fread(nonce, 16, 1, license); long data_start = ftell(license); fseek(license, 0, SEEK_END); @@ -107,8 +121,8 @@ int main(){ int symbol_status = resolve_elf_symbol_memory_offset( decrypted_license, EMU_ENTRY_SYMBOL, cpu.mem_size, &entry_offset); if (symbol_status != LOAD_OK) { - fprintf(stderr, "Entry symbol '%s' resolve failed with code %d for '%s'\n", - EMU_ENTRY_SYMBOL, symbol_status, EMU_PROGRAM_PATH); + fprintf(stderr, "Entry symbol '%s' resolve failed with code %d\n", + EMU_ENTRY_SYMBOL, symbol_status); return 2; }