From 440c05cdfa46145229cabdd479a0647c1451140e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 23 Aug 2019 00:08:19 +0200 Subject: [PATCH] searchFile accepts also explicit absolute or relative path --- client/fileutils.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/client/fileutils.c b/client/fileutils.c index 403f7fc27..7500ea8dd 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -667,6 +667,22 @@ char *searchFile(const char *pm3dir, const char *ext, const char *filename) { if (!str_endswith(filename, ext)) { suffix = ext; } + + // explicit absolute (/) or relative path (./) => try only to match it directly + if (((strlen(filename) > 1) && (filename[0] == '/')) || + ((strlen(filename) > 2) && (filename[0] == '.') && (filename[1] == '/'))) + { + char *path = malloc(strlen(filename) + strlen(suffix) + 1); + strcpy(path, filename); + strcat(path, suffix); + if (fileExists(path)) + return path; + else + free(path); + return NULL; + } + // else + // try pm3 dirs in current workdir (dev mode) const char *exec_path = get_my_executable_directory(); if (exec_path != NULL) { char *path = malloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); @@ -679,6 +695,7 @@ char *searchFile(const char *pm3dir, const char *ext, const char *filename) { else free(path); } + // try pm3 dirs in user .proxmark3 (user mode) char *user_path = getenv("HOME"); if (user_path != NULL) { char *path = malloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); @@ -692,6 +709,7 @@ char *searchFile(const char *pm3dir, const char *ext, const char *filename) { else free(path); } + // try pm3 dirs in pm3 installation dir (install mode) { char *path = malloc(strlen(PM3_SYSTEM_DIRECTORY) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); strcpy(path, PM3_SYSTEM_DIRECTORY);