mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-09 17:56:53 +08:00
searchFile accepts also explicit absolute or relative path
This commit is contained in:
parent
3ebc00854b
commit
440c05cdfa
1 changed files with 18 additions and 0 deletions
|
@ -667,6 +667,22 @@ char *searchFile(const char *pm3dir, const char *ext, const char *filename) {
|
||||||
if (!str_endswith(filename, ext)) {
|
if (!str_endswith(filename, ext)) {
|
||||||
suffix = 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();
|
const char *exec_path = get_my_executable_directory();
|
||||||
if (exec_path != NULL) {
|
if (exec_path != NULL) {
|
||||||
char *path = malloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1);
|
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
|
else
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
// try pm3 dirs in user .proxmark3 (user mode)
|
||||||
char *user_path = getenv("HOME");
|
char *user_path = getenv("HOME");
|
||||||
if (user_path != NULL) {
|
if (user_path != NULL) {
|
||||||
char *path = malloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1);
|
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
|
else
|
||||||
free(path);
|
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);
|
char *path = malloc(strlen(PM3_SYSTEM_DIRECTORY) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1);
|
||||||
strcpy(path, PM3_SYSTEM_DIRECTORY);
|
strcpy(path, PM3_SYSTEM_DIRECTORY);
|
||||||
|
|
Loading…
Reference in a new issue