mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-11-10 17:49:32 +08:00
searchFile traces
This commit is contained in:
parent
40709f4536
commit
08a5de1f0e
3 changed files with 52 additions and 5 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "lfdemod.h" // for demod code
|
||||
#include "loclass/cipherutils.h" // for decimating samples in getsamples
|
||||
#include "cmdlfem4x.h" // askem410xdecode
|
||||
#include "fileutils.h" // searchFile
|
||||
|
||||
uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
|
||||
size_t DemodBufferLen = 0;
|
||||
|
@ -1646,12 +1647,19 @@ static int CmdLoad(const char *Cmd) {
|
|||
if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;
|
||||
memcpy(filename, Cmd, len);
|
||||
|
||||
FILE *f = fopen(filename, "r");
|
||||
if (!f) {
|
||||
PrintAndLogEx(WARNING, "couldn't open '%s'", filename);
|
||||
char *path;
|
||||
if (searchFile(&path, TRACES_SUBDIR, filename, "") != PM3_SUCCESS) {
|
||||
return PM3_EFILE;
|
||||
}
|
||||
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) {
|
||||
PrintAndLogEx(WARNING, "couldn't open '%s'", path);
|
||||
free(path);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
free(path);
|
||||
|
||||
GraphTraceLen = 0;
|
||||
char line[80];
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
|
|
|
@ -869,6 +869,9 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea
|
|||
char *filename = calloc(strlen(searchname) + 1, sizeof(char));
|
||||
if (filename == NULL) return PM3_EMALLOC;
|
||||
strcpy(filename, searchname);
|
||||
if (g_debugMode == 2) {
|
||||
PrintAndLogEx(INFO, "Searching %s", filename);
|
||||
}
|
||||
if (((strlen(filename) > 1) && (filename[0] == '/')) ||
|
||||
((strlen(filename) > 2) && (filename[0] == '.') && (filename[1] == '/'))) {
|
||||
if (fileExists(filename)) {
|
||||
|
@ -887,15 +890,44 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea
|
|||
return PM3_SUCCESS;
|
||||
}
|
||||
}
|
||||
// try pm3 dirs in current workdir (dev mode)
|
||||
// try pm3 dirs in current client workdir (dev mode)
|
||||
const char *exec_path = get_my_executable_directory();
|
||||
if (exec_path != NULL) {
|
||||
if ((exec_path != NULL) &&
|
||||
((strcmp(DICTIONARIES_SUBDIR, pm3dir) == 0) ||
|
||||
(strcmp(LUA_LIBRARIES_SUBDIR, pm3dir) == 0) ||
|
||||
(strcmp(LUA_SCRIPTS_SUBDIR, pm3dir) == 0) ||
|
||||
(strcmp(RESOURCES_SUBDIR, pm3dir) == 0))) {
|
||||
char *path = calloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char));
|
||||
if (path == NULL)
|
||||
goto out;
|
||||
strcpy(path, exec_path);
|
||||
strcat(path, pm3dir);
|
||||
strcat(path, filename);
|
||||
if (g_debugMode == 2) {
|
||||
PrintAndLogEx(INFO, "Searching %s", path);
|
||||
}
|
||||
if (fileExists(path)) {
|
||||
free(filename);
|
||||
*foundpath = path;
|
||||
return PM3_SUCCESS;
|
||||
} else {
|
||||
free(path);
|
||||
}
|
||||
}
|
||||
// try pm3 dirs in current repo workdir (dev mode)
|
||||
if ((exec_path != NULL) &&
|
||||
((strcmp(TRACES_SUBDIR, pm3dir) == 0))) {
|
||||
char *above = "../";
|
||||
char *path = calloc(strlen(exec_path) + strlen(above) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char));
|
||||
if (path == NULL)
|
||||
goto out;
|
||||
strcpy(path, exec_path);
|
||||
strcat(path, above);
|
||||
strcat(path, pm3dir);
|
||||
strcat(path, filename);
|
||||
if (g_debugMode == 2) {
|
||||
PrintAndLogEx(INFO, "Searching %s", path);
|
||||
}
|
||||
if (fileExists(path)) {
|
||||
free(filename);
|
||||
*foundpath = path;
|
||||
|
@ -914,6 +946,9 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea
|
|||
strcat(path, PM3_USER_DIRECTORY);
|
||||
strcat(path, pm3dir);
|
||||
strcat(path, filename);
|
||||
if (g_debugMode == 2) {
|
||||
PrintAndLogEx(INFO, "Searching %s", path);
|
||||
}
|
||||
if (fileExists(path)) {
|
||||
free(filename);
|
||||
*foundpath = path;
|
||||
|
@ -930,6 +965,9 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea
|
|||
strcpy(path, PM3_SHARE_PATH);
|
||||
strcat(path, pm3dir);
|
||||
strcat(path, filename);
|
||||
if (g_debugMode == 2) {
|
||||
PrintAndLogEx(INFO, "Searching %s", path);
|
||||
}
|
||||
if (fileExists(path)) {
|
||||
free(filename);
|
||||
*foundpath = path;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#define LUA_LIBRARIES_SUBDIR "lualibs/"
|
||||
#define LUA_SCRIPTS_SUBDIR "luascripts/"
|
||||
#define RESOURCES_SUBDIR "resources/"
|
||||
#define TRACES_SUBDIR "traces/"
|
||||
|
||||
#define PACKED __attribute__((packed))
|
||||
|
||||
|
|
Loading…
Reference in a new issue