fix: search for license file in multiple directories

This commit is contained in:
2026-05-14 17:16:38 +02:00
parent 4554dffadb
commit f1cdacc5c2
2 changed files with 19 additions and 4 deletions

View File

@@ -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

View File

@@ -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;
}