Skip to content

Commit

Permalink
searchFile accepts also explicit absolute or relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
doegox committed Aug 22, 2019
1 parent 3ebc008 commit 440c05c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions client/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 440c05c

Please sign in to comment.