fix: search for license file in multiple directories
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define EMU_MEM_SIZE 16384u
|
#define EMU_MEM_SIZE 16384u
|
||||||
#define EMU_PROGRAM_PATH "build/license"
|
|
||||||
#define EMU_ENTRY_SYMBOL "entry"
|
#define EMU_ENTRY_SYMBOL "entry"
|
||||||
|
#define EMU_PROGRAM_PATHS {"license", "build/license"};
|
||||||
|
|
||||||
|
|
||||||
#define STACK_SIZE 1024
|
#define STACK_SIZE 1024
|
||||||
#define RISCV_MEM_OFFSET 0x80000000
|
#define RISCV_MEM_OFFSET 0x80000000
|
||||||
|
|||||||
20
src/main.c
20
src/main.c
@@ -18,6 +18,8 @@
|
|||||||
#define MAX_STEPS 1024u
|
#define MAX_STEPS 1024u
|
||||||
|
|
||||||
|
|
||||||
|
static const char* emu_program_paths[] = EMU_PROGRAM_PATHS;
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
hw_info_t hwinfo = {0};
|
hw_info_t hwinfo = {0};
|
||||||
if(get_hw_info(&hwinfo) != 0){
|
if(get_hw_info(&hwinfo) != 0){
|
||||||
@@ -42,7 +44,19 @@ int main(){
|
|||||||
struct AES_ctx ctx;
|
struct AES_ctx ctx;
|
||||||
uint8_t nonce[16] = {0};
|
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);
|
fread(nonce, 16, 1, license);
|
||||||
long data_start = ftell(license);
|
long data_start = ftell(license);
|
||||||
fseek(license, 0, SEEK_END);
|
fseek(license, 0, SEEK_END);
|
||||||
@@ -107,8 +121,8 @@ int main(){
|
|||||||
int symbol_status = resolve_elf_symbol_memory_offset(
|
int symbol_status = resolve_elf_symbol_memory_offset(
|
||||||
decrypted_license, EMU_ENTRY_SYMBOL, cpu.mem_size, &entry_offset);
|
decrypted_license, EMU_ENTRY_SYMBOL, cpu.mem_size, &entry_offset);
|
||||||
if (symbol_status != LOAD_OK) {
|
if (symbol_status != LOAD_OK) {
|
||||||
fprintf(stderr, "Entry symbol '%s' resolve failed with code %d for '%s'\n",
|
fprintf(stderr, "Entry symbol '%s' resolve failed with code %d\n",
|
||||||
EMU_ENTRY_SYMBOL, symbol_status, EMU_PROGRAM_PATH);
|
EMU_ENTRY_SYMBOL, symbol_status);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user