mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 02:27:26 -07:00
pref savedefaultpaths uses cliparser, enabled but is not used in the fileutils yet.
This commit is contained in:
parent
ee8309e09b
commit
8b7ef202c3
5 changed files with 209 additions and 231 deletions
|
@ -287,7 +287,7 @@ static int CmdHF14BCmdRaw(const char *Cmd) {
|
||||||
|
|
||||||
CLIParserContext *ctx;
|
CLIParserContext *ctx;
|
||||||
CLIParserInit(&ctx, "hf 14b raw",
|
CLIParserInit(&ctx, "hf 14b raw",
|
||||||
"Sends raw bytes to card ",
|
"Sends raw bytes to card",
|
||||||
"hf 14b raw -cks --data 0200a40400 -> standard select\n"
|
"hf 14b raw -cks --data 0200a40400 -> standard select\n"
|
||||||
"hf 14b raw -ck --sr --data 0200a40400 -> SRx select\n"
|
"hf 14b raw -ck --sr --data 0200a40400 -> SRx select\n"
|
||||||
"hf 14b raw -ck --cts --data 0200a40400 -> C-ticket select\n"
|
"hf 14b raw -ck --cts --data 0200a40400 -> C-ticket select\n"
|
||||||
|
|
|
@ -195,8 +195,8 @@ bool create_path(const char *dirname) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
bool setDefaultPath (savePaths_t pathIndex,const char *Path) {
|
bool setDefaultPath (savePaths_t pathIndex, const char *Path) {
|
||||||
|
|
||||||
if (pathIndex < spItemCount) {
|
if (pathIndex < spItemCount) {
|
||||||
if ((Path == NULL) && (session.defaultPaths[pathIndex] != NULL)) {
|
if ((Path == NULL) && (session.defaultPaths[pathIndex] != NULL)) {
|
||||||
|
@ -208,13 +208,11 @@ bool setDefaultPath (savePaths_t pathIndex,const char *Path) {
|
||||||
session.defaultPaths[pathIndex] = (char *)realloc(session.defaultPaths[pathIndex], strlen(Path) + 1);
|
session.defaultPaths[pathIndex] = (char *)realloc(session.defaultPaths[pathIndex], strlen(Path) + 1);
|
||||||
strcpy(session.defaultPaths[pathIndex], Path);
|
strcpy(session.defaultPaths[pathIndex], Path);
|
||||||
}
|
}
|
||||||
} else {
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
static char *filenamemcopy(const char *preferredName, const char *suffix) {
|
static char *filenamemcopy(const char *preferredName, const char *suffix) {
|
||||||
if (preferredName == NULL) return NULL;
|
if (preferredName == NULL) return NULL;
|
||||||
if (suffix == NULL) return NULL;
|
if (suffix == NULL) return NULL;
|
||||||
|
|
|
@ -78,7 +78,7 @@ typedef enum {
|
||||||
|
|
||||||
int fileExists(const char *filename);
|
int fileExists(const char *filename);
|
||||||
//bool create_path(const char *dirname);
|
//bool create_path(const char *dirname);
|
||||||
//bool setDefaultPath (savePaths_t pathIndex,const char *Path); // set a path in the path list session.defaultPaths
|
bool setDefaultPath (savePaths_t pathIndex,const char *Path); // set a path in the path list session.defaultPaths
|
||||||
|
|
||||||
char *newfilenamemcopy(const char *preferredName, const char *suffix);
|
char *newfilenamemcopy(const char *preferredName, const char *suffix);
|
||||||
|
|
||||||
|
|
|
@ -55,29 +55,27 @@ int preferences_load(void) {
|
||||||
session.show_hints = true;
|
session.show_hints = true;
|
||||||
|
|
||||||
session.bar_mode = STYLE_VALUE;
|
session.bar_mode = STYLE_VALUE;
|
||||||
// setDefaultPath (spDefault, "");
|
setDefaultPath (spDefault, "");
|
||||||
// setDefaultPath (spDump, "");
|
setDefaultPath (spDump, "");
|
||||||
// setDefaultPath (spTrace, "");
|
setDefaultPath (spTrace, "");
|
||||||
|
|
||||||
/*
|
// default save path
|
||||||
// default save path
|
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
||||||
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
setDefaultPath (spDefault, get_my_user_directory());
|
||||||
setDefaultPath (spDefault, get_my_user_directory());
|
else
|
||||||
else
|
setDefaultPath (spDefault, ".");
|
||||||
setDefaultPath (spDefault, ".");
|
|
||||||
|
|
||||||
// default dump path
|
// default dump path
|
||||||
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
||||||
setDefaultPath (spDump, get_my_user_directory());
|
setDefaultPath (spDump, get_my_user_directory());
|
||||||
else
|
else
|
||||||
setDefaultPath (spDump, ".");
|
setDefaultPath (spDump, ".");
|
||||||
|
|
||||||
// default dump path
|
// default dump path
|
||||||
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
||||||
setDefaultPath (spTrace, get_my_user_directory());
|
setDefaultPath (spTrace, get_my_user_directory());
|
||||||
else
|
else
|
||||||
setDefaultPath (spTrace, ".");
|
setDefaultPath (spTrace, ".");
|
||||||
*/
|
|
||||||
|
|
||||||
if (session.incognito) {
|
if (session.incognito) {
|
||||||
PrintAndLogEx(INFO, "No preferences file will be loaded");
|
PrintAndLogEx(INFO, "No preferences file will be loaded");
|
||||||
|
@ -179,9 +177,9 @@ void preferences_save_callback(json_t *root) {
|
||||||
|
|
||||||
JsonSaveBoolean(root, "os.supports.colors", session.supports_colors);
|
JsonSaveBoolean(root, "os.supports.colors", session.supports_colors);
|
||||||
|
|
||||||
// JsonSaveStr(root, "file.default.savepath", session.defaultPaths[spDefault]);
|
JsonSaveStr(root, "file.default.savepath", session.defaultPaths[spDefault]);
|
||||||
// JsonSaveStr(root, "file.default.dumppath", session.defaultPaths[spDump]);
|
JsonSaveStr(root, "file.default.dumppath", session.defaultPaths[spDump]);
|
||||||
// JsonSaveStr(root, "file.default.tracepath", session.defaultPaths[spTrace]);
|
JsonSaveStr(root, "file.default.tracepath", session.defaultPaths[spTrace]);
|
||||||
|
|
||||||
// Plot window
|
// Plot window
|
||||||
JsonSaveInt(root, "window.plot.xpos", session.plot.x);
|
JsonSaveInt(root, "window.plot.xpos", session.plot.x);
|
||||||
|
@ -246,7 +244,6 @@ void preferences_save_callback(json_t *root) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void preferences_load_callback(json_t *root) {
|
void preferences_load_callback(json_t *root) {
|
||||||
json_error_t up_error = {0};
|
json_error_t up_error = {0};
|
||||||
int b1;
|
int b1;
|
||||||
|
@ -262,19 +259,19 @@ void preferences_load_callback(json_t *root) {
|
||||||
if (strncmp(tempStr, "simple", 6) == 0) session.client_debug_level = cdbSIMPLE;
|
if (strncmp(tempStr, "simple", 6) == 0) session.client_debug_level = cdbSIMPLE;
|
||||||
if (strncmp(tempStr, "full", 4) == 0) session.client_debug_level = cdbFULL;
|
if (strncmp(tempStr, "full", 4) == 0) session.client_debug_level = cdbFULL;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
// default save path
|
|
||||||
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.savepath", &s1) == 0)
|
|
||||||
setDefaultPath (spDefault,s1);
|
|
||||||
|
|
||||||
// default dump path
|
// default save path
|
||||||
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.dumppath", &s1) == 0)
|
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.savepath", &s1) == 0)
|
||||||
setDefaultPath (spDump,s1);
|
setDefaultPath (spDefault, s1);
|
||||||
|
|
||||||
|
// default dump path
|
||||||
|
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.dumppath", &s1) == 0)
|
||||||
|
setDefaultPath (spDump, s1);
|
||||||
|
|
||||||
|
// default trace path
|
||||||
|
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.tracepath", &s1) == 0)
|
||||||
|
setDefaultPath (spTrace, s1);
|
||||||
|
|
||||||
// default trace path
|
|
||||||
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.tracepath", &s1) == 0)
|
|
||||||
setDefaultPath (spTrace,s1);
|
|
||||||
*/
|
|
||||||
// window plot
|
// window plot
|
||||||
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.xpos", &i1) == 0)
|
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.xpos", &i1) == 0)
|
||||||
session.plot.x = i1;
|
session.plot.x = i1;
|
||||||
|
@ -338,37 +335,6 @@ void preferences_load_callback(json_t *root) {
|
||||||
|
|
||||||
// Help Functions
|
// Help Functions
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
static int usage_set_devicedebug(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: pref set devicedebug <off | error | info | debug | extended>");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " "_GREEN_("help")" - This help");
|
|
||||||
PrintAndLogEx(NORMAL, " "_GREEN_("off")" - no debug messages");
|
|
||||||
PrintAndLogEx(NORMAL, " "_GREEN_("error")" - error messages");
|
|
||||||
PrintAndLogEx(NORMAL, " "_GREEN_("info")" - info messages");
|
|
||||||
PrintAndLogEx(NORMAL, " "_GREEN_("debug")" - debug messages");
|
|
||||||
PrintAndLogEx(NORMAL, " "_GREEN_("extended")" - extended debug messages");
|
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
static int usage_set_savePaths(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: pref set savepaths [help] [create] [default <path>] [dump <path>] [trace <path>]");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " "_GREEN_("help")" - This help");
|
|
||||||
PrintAndLogEx(NORMAL, " "_GREEN_("create")" - Create directory if it does not exist");
|
|
||||||
PrintAndLogEx(NORMAL, " "_GREEN_("default")" - Deafult path");
|
|
||||||
PrintAndLogEx(NORMAL, " "_GREEN_("dump")" - Dump path");
|
|
||||||
PrintAndLogEx(NORMAL, " "_GREEN_("trace")" - Trace help");
|
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// Preference Processing Functions
|
// Preference Processing Functions
|
||||||
// typedef enum preferenceId {prefNONE,prefHELP,prefEMOJI,prefCOLOR,prefPLOT,prefOVERLAY,prefHINTS,prefCLIENTDEBUG} preferenceId_t;
|
// typedef enum preferenceId {prefNONE,prefHELP,prefEMOJI,prefCOLOR,prefPLOT,prefOVERLAY,prefHINTS,prefCLIENTDEBUG} preferenceId_t;
|
||||||
typedef enum prefShowOpt {prefShowNone, prefShowOLD, prefShowNEW} prefShowOpt_t;
|
typedef enum prefShowOpt {prefShowNone, prefShowOLD, prefShowNEW} prefShowOpt_t;
|
||||||
|
@ -452,40 +418,56 @@ static void showDeviceDebugState(prefShowOpt_t opt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
static void showSavePathState(savePaths_t pathIndex, prefShowOpt_t opt) {
|
|
||||||
|
|
||||||
char tempStr[50];
|
static void showSavePathState(savePaths_t path_index, prefShowOpt_t opt) {
|
||||||
|
|
||||||
switch (pathIndex) {
|
char s[50];
|
||||||
|
switch (path_index) {
|
||||||
case spDefault:
|
case spDefault:
|
||||||
strcpy (tempStr,"default save path......");
|
strcpy (s, "default save path......");
|
||||||
break;
|
break;
|
||||||
case spDump:
|
case spDump:
|
||||||
strcpy (tempStr,"dump save path.........");
|
strcpy (s, "dump save path.........");
|
||||||
break;
|
break;
|
||||||
case spTrace:
|
case spTrace:
|
||||||
strcpy (tempStr,"trace save path........");
|
strcpy (s, "trace save path........");
|
||||||
break;
|
break;
|
||||||
|
case spItemCount:
|
||||||
default:
|
default:
|
||||||
strcpy (tempStr,_RED_("unknown")" save path......");
|
strcpy (s, _RED_("unknown")" save path......");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((session.defaultPaths[path_index] == NULL) || (strcmp(session.defaultPaths[path_index], "") == 0)) {
|
||||||
|
PrintAndLogEx(INFO, " %s %s "_WHITE_("not set"),
|
||||||
|
prefShowMsg(opt),
|
||||||
|
s
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(INFO, " %s %s "_GREEN_("%s"),
|
||||||
|
prefShowMsg(opt),
|
||||||
|
s,
|
||||||
|
session.defaultPaths[path_index]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if ((session.defaultPaths[pathIndex] == NULL) || (strcmp(session.defaultPaths[pathIndex],"") == 0))
|
|
||||||
PrintAndLogEx(INFO, " %s %s "_WHITE_("not set"), prefShowMsg(opt),tempStr);
|
|
||||||
else
|
|
||||||
PrintAndLogEx(INFO, " %s %s "_GREEN_("%s"), prefShowMsg(opt), tempStr, session.defaultPaths[pathIndex]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void showPlotPosState(void) {
|
static void showPlotPosState(void) {
|
||||||
PrintAndLogEx(INFO, " Plot window............ X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
|
PrintAndLogEx(INFO, " Plot window............ X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
|
||||||
session.plot.x, session.plot.y, session.plot.h, session.plot.w);
|
session.plot.x,
|
||||||
|
session.plot.y,
|
||||||
|
session.plot.h,
|
||||||
|
session.plot.w
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void showOverlayPosState(void) {
|
static void showOverlayPosState(void) {
|
||||||
PrintAndLogEx(INFO, " Slider/Overlay window.. X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
|
PrintAndLogEx(INFO, " Slider/Overlay window.. X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
|
||||||
session.overlay.x, session.overlay.y, session.overlay.h, session.overlay.w);
|
session.overlay.x,
|
||||||
|
session.overlay.y,
|
||||||
|
session.overlay.h,
|
||||||
|
session.overlay.w
|
||||||
|
);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
static void showHintsState(prefShowOpt_t opt) {
|
static void showHintsState(prefShowOpt_t opt) {
|
||||||
if (session.show_hints)
|
if (session.show_hints)
|
||||||
|
@ -668,70 +650,72 @@ static int setCmdDebug(const char *Cmd) {
|
||||||
/*
|
/*
|
||||||
static int setCmdDeviceDebug (const char *Cmd)
|
static int setCmdDeviceDebug (const char *Cmd)
|
||||||
{
|
{
|
||||||
uint8_t cmdp = 0;
|
CLIParserContext *ctx;
|
||||||
bool errors = false;
|
CLIParserInit(&ctx, "pref set devicedebug ",
|
||||||
bool validValue = false;
|
"Set presistent preference of device side debug level",
|
||||||
char strOpt[50];
|
"pref set devicedebug --on"
|
||||||
devicedebugLevel_t newValue = session.device_debug_level;
|
);
|
||||||
|
|
||||||
if (param_getchar(Cmd, cmdp) == 0x00)
|
void *argtable[] = {
|
||||||
return usage_set_devicedebug ();
|
arg_param_begin,
|
||||||
|
arg_lit0(NULL, "off", "no debug messages"),
|
||||||
|
arg_lit0(NULL, "error", "error messages"),
|
||||||
|
arg_lit0(NULL, "info", "info messages"),
|
||||||
|
arg_lit0(NULL, "dbg", "debug messages"),
|
||||||
|
arg_lit0(NULL, "ext", "extended debug messages"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
bool use_off = arg_get_lit(ctx, 1);
|
||||||
|
bool use_err = arg_get_lit(ctx, 2);
|
||||||
|
bool use_info = arg_get_lit(ctx, 3);
|
||||||
|
bool use_dbg = arg_get_lit(ctx, 4);
|
||||||
|
bool use_ext = arg_get_lit(ctx, 5);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
while ((param_getchar(Cmd, cmdp) != 0x00) && !errors) {
|
if ( (use_off + use_err + use_info + use_dbg + use_ext) > 1) {
|
||||||
|
PrintAndLogEx(FAILED, "Can only set one option");
|
||||||
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
return PM3_EINVARG;
|
||||||
str_lower(strOpt); // convert to lowercase
|
|
||||||
|
|
||||||
if (strncmp (strOpt,"help",4) == 0)
|
|
||||||
return usage_set_devicedebug();
|
|
||||||
if (strncmp (strOpt,"off",3) == 0) {
|
|
||||||
validValue = true;
|
|
||||||
newValue = ddbOFF;
|
|
||||||
}
|
|
||||||
if (strncmp (strOpt,"error",5) == 0) {
|
|
||||||
validValue = true;
|
|
||||||
newValue = ddbERROR;
|
|
||||||
}
|
|
||||||
if (strncmp (strOpt,"info",4) == 0) {
|
|
||||||
validValue = true;
|
|
||||||
newValue = ddbINFO;
|
|
||||||
}
|
|
||||||
if (strncmp (strOpt,"debug",5) == 0) {
|
|
||||||
validValue = true;
|
|
||||||
newValue = ddbDEBUG;
|
|
||||||
}
|
|
||||||
if (strncmp (strOpt,"extended",8) == 0) {
|
|
||||||
validValue = true;
|
|
||||||
newValue = ddbEXTENDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (validValue) {
|
|
||||||
if (session.device_debug_level != newValue) {// changed
|
|
||||||
showDeviceDebugState (prefShowOLD);
|
|
||||||
session.device_debug_level = newValue;
|
|
||||||
showDeviceDebugState (prefShowNEW);
|
|
||||||
preferences_save();
|
|
||||||
} else {
|
|
||||||
PrintAndLogEx(INFO,"nothing changed");
|
|
||||||
showDeviceDebugState (prefShowNone);
|
|
||||||
}
|
|
||||||
if (session.pm3_present) {
|
|
||||||
PrintAndLogEx (INFO,"setting device debug loglevel");
|
|
||||||
SendCommandNG(CMD_SET_DBGMODE, &session.device_debug_level, 1);
|
|
||||||
PacketResponseNG resp;
|
|
||||||
if (WaitForResponseTimeout(CMD_SET_DBGMODE, &resp, 2000) == false)
|
|
||||||
PrintAndLogEx (INFO,"failed to set device debug loglevel");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
PrintAndLogEx(ERR,"invalid option");
|
|
||||||
return usage_set_devicedebug();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
devicedebugLevel_t new_value = session.device_debug_level;
|
||||||
|
|
||||||
|
if (use_off) {
|
||||||
|
new_value = ddbOFF;
|
||||||
|
}
|
||||||
|
if (use_err) {
|
||||||
|
new_value = ddbERROR;
|
||||||
|
}
|
||||||
|
if (use_info) {
|
||||||
|
new_value = ddbINFO;
|
||||||
|
}
|
||||||
|
if (use_dbg) {
|
||||||
|
new_value = ddbDEBUG;
|
||||||
|
}
|
||||||
|
if (use_ext) {
|
||||||
|
new_value = ddbEXTENDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session.device_debug_level != new_value) {// changed
|
||||||
|
showDeviceDebugState (prefShowOLD);
|
||||||
|
session.device_debug_level = new_value;
|
||||||
|
showDeviceDebugState (prefShowNEW);
|
||||||
|
preferences_save();
|
||||||
|
} else {
|
||||||
|
showDeviceDebugState (prefShowNone);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session.pm3_present) {
|
||||||
|
PrintAndLogEx (INFO,"setting device debug loglevel");
|
||||||
|
SendCommandNG(CMD_SET_DBGMODE, &session.device_debug_level, 1);
|
||||||
|
PacketResponseNG resp;
|
||||||
|
if (WaitForResponseTimeout(CMD_SET_DBGMODE, &resp, 2000) == false)
|
||||||
|
PrintAndLogEx (WARNING,"failed to set device debug loglevel");
|
||||||
|
}
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int setCmdHint(const char *Cmd) {
|
static int setCmdHint(const char *Cmd) {
|
||||||
CLIParserContext *ctx;
|
CLIParserContext *ctx;
|
||||||
CLIParserInit(&ctx, "pref set hints ",
|
CLIParserInit(&ctx, "pref set hints ",
|
||||||
|
@ -774,6 +758,7 @@ static int setCmdHint(const char *Cmd) {
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setCmdPlotSliders(const char *Cmd) {
|
static int setCmdPlotSliders(const char *Cmd) {
|
||||||
CLIParserContext *ctx;
|
CLIParserContext *ctx;
|
||||||
CLIParserInit(&ctx, "pref set plotsliders ",
|
CLIParserInit(&ctx, "pref set plotsliders ",
|
||||||
|
@ -816,97 +801,87 @@ static int setCmdPlotSliders(const char *Cmd) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
static int setCmdSavePaths (const char *Cmd) {
|
static int setCmdSavePaths (const char *Cmd) {
|
||||||
uint8_t cmdp = 0;
|
CLIParserContext *ctx;
|
||||||
bool errors = false;
|
CLIParserInit(&ctx, "pref set savepath",
|
||||||
// bool validValue = false;
|
"Set presistent preference of file paths in the client",
|
||||||
char *strOpt = NULL;
|
"pref set savepaths --dump /home/mydumpfolder -> all dump files will be saved into this folder\n"
|
||||||
int optLen = 0;
|
"pref set savepaths --def /home/myfolder -c -> create if needed, all files will be saved into this folder"
|
||||||
char *newValue = NULL;
|
);
|
||||||
bool createDir = false;
|
|
||||||
savePaths_t pathItem = spItemCount;
|
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_lit0("c", "create", "create directory if it does not exist"),
|
||||||
|
arg_str0(NULL, "def", "<path>", "default path"),
|
||||||
|
arg_str0(NULL, "dump", "<path>", "dump file path"),
|
||||||
|
arg_str0(NULL, "trace", "<path>", "trace path"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
bool create_dir = arg_get_lit(ctx, 1);
|
||||||
|
|
||||||
if (param_getchar(Cmd, cmdp) == 0x00)
|
int deflen = 0;
|
||||||
return usage_set_savePaths();
|
char def_path[FILE_PATH_SIZE] = {0};
|
||||||
|
CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)def_path, FILE_PATH_SIZE, &deflen);
|
||||||
|
|
||||||
while ((param_getchar(Cmd, cmdp) != 0x00) && !errors) {
|
int dulen = 0;
|
||||||
|
char dump_path[FILE_PATH_SIZE] = {0};
|
||||||
|
CLIParamStrToBuf(arg_get_str(ctx, 3), (uint8_t *)dump_path, FILE_PATH_SIZE, &dulen);
|
||||||
|
|
||||||
optLen = param_getlength(Cmd, cmdp)+1;
|
int tlen = 0;
|
||||||
strOpt = (char *)realloc(strOpt,optLen+1);//, sizeof(uint8_t));
|
char trace_path[FILE_PATH_SIZE] = {0};
|
||||||
|
CLIParamStrToBuf(arg_get_str(ctx, 4), (uint8_t *)trace_path, FILE_PATH_SIZE, &tlen);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
if (param_getstr(Cmd, cmdp++, strOpt, optLen) != 0) {
|
if (deflen == 0 && dulen == 0 && tlen == 0) {
|
||||||
str_lower(strOpt); // convert to lowercase
|
PrintAndLogEx(FAILED, "Must give atleast one path");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
|
||||||
if (strncmp(strOpt, "help", 4) == 0)
|
savePaths_t path_item = spItemCount;
|
||||||
return usage_set_savePaths();
|
char *path = NULL;
|
||||||
|
if (deflen) {
|
||||||
|
path_item = spDefault;
|
||||||
|
path = def_path;
|
||||||
|
}
|
||||||
|
if (dulen) {
|
||||||
|
path_item = spDump;
|
||||||
|
path = dump_path;
|
||||||
|
}
|
||||||
|
if (tlen) {
|
||||||
|
path_item = spTrace;
|
||||||
|
path = trace_path;
|
||||||
|
}
|
||||||
|
|
||||||
if (strncmp(strOpt, "create", 6) == 0) {
|
// remove trailing slash.
|
||||||
// check if 2 more options.
|
size_t nplen = strlen(path);
|
||||||
if (param_getlength(Cmd, cmdp+1) == 0) // should have min 2 more options
|
if ((path[nplen - 1] == '/') || (path[nplen - 1] == '\\')) {
|
||||||
return usage_set_savePaths();
|
path[nplen - 1] = 0x00;
|
||||||
createDir = true;
|
}
|
||||||
} else {
|
|
||||||
if ((strncmp(strOpt, "default", 7) == 0) ||
|
|
||||||
(strncmp(strOpt, "dump", 4) == 0) ||
|
|
||||||
(strncmp(strOpt, "trace", 5) == 0)) {
|
|
||||||
|
|
||||||
// Get Path
|
// Check path
|
||||||
optLen = param_getlength(Cmd, cmdp) + 1;
|
if (fileExists(path) == false && create_dir == false) {
|
||||||
newValue = (char *)realloc(newValue, optLen+1);
|
PrintAndLogEx(ERR,"path does not exist... "_RED_("%s"), path);
|
||||||
if (param_getstr(Cmd, cmdp++, newValue, optLen) == 0) {
|
}
|
||||||
PrintAndLogEx(INFO, "missing %s path",strOpt);
|
|
||||||
return usage_set_savePaths();
|
|
||||||
}
|
|
||||||
// remove trailing slash.
|
|
||||||
if ((newValue[strlen(newValue)-1] == '/') || (newValue[strlen(newValue)-1] == '\\'))
|
|
||||||
newValue[strlen(newValue)-1] = 0x00;
|
|
||||||
|
|
||||||
// Check path
|
// do we need to create it
|
||||||
if (!fileExists(newValue) && !createDir) {
|
// if (!fileExists(newValue))
|
||||||
PrintAndLogEx(ERR,"path does not exist... "_RED_("%s"),newValue);
|
// create_path (newValue); //mkdir (newValue,0x777);
|
||||||
} else {
|
|
||||||
// do we need to create it
|
|
||||||
// if (!fileExists(newValue))
|
|
||||||
// create_path (newValue); //mkdir (newValue,0x777);
|
|
||||||
|
|
||||||
pathItem = spItemCount;
|
if (path_item < spItemCount) {
|
||||||
if (strncmp(strOpt, "default", 7) == 0) pathItem = spDefault;
|
if (strcmp(path, session.defaultPaths[path_item]) != 0) {
|
||||||
if (strncmp(strOpt, "dump", 4) == 0) pathItem = spDump;
|
showSavePathState(path_item, prefShowOLD);
|
||||||
if (strncmp(strOpt, "trace", 5) == 0) pathItem = spTrace;
|
setDefaultPath (path_item, path);
|
||||||
|
showSavePathState(path_item, prefShowNEW);
|
||||||
if (pathItem < spItemCount) {
|
preferences_save();
|
||||||
if (strcmp(newValue, session.defaultPaths[pathItem]) != 0) {
|
} else {
|
||||||
showSavePathState(pathItem, prefShowOLD);
|
showSavePathState(path_item, prefShowNone);
|
||||||
setDefaultPath (pathItem, newValue);
|
|
||||||
showSavePathState(pathItem, prefShowNEW);
|
|
||||||
preferences_save();
|
|
||||||
} else {
|
|
||||||
PrintAndLogEx(INFO, "nothing changed");
|
|
||||||
showSavePathState(pathItem, prefShowNone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return usage_set_savePaths();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean up
|
|
||||||
if (strOpt != NULL) free (strOpt);
|
|
||||||
if (newValue != NULL) free (newValue);
|
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getCmdHelp(const char *Cmd) {
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int setCmdBarMode(const char *Cmd) {
|
static int setCmdBarMode(const char *Cmd) {
|
||||||
CLIParserContext *ctx;
|
CLIParserContext *ctx;
|
||||||
CLIParserInit(&ctx, "pref set barmode",
|
CLIParserInit(&ctx, "pref set barmode",
|
||||||
|
@ -984,13 +959,18 @@ static int getCmdBarMode(const char *Cmd) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int getCmdSavePaths(const char *Cmd) {
|
||||||
|
showSavePathState(spDefault, prefShowNone);
|
||||||
|
showSavePathState(spDump, prefShowNone);
|
||||||
|
showSavePathState(spTrace, prefShowNone);
|
||||||
|
return PM3_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static command_t CommandTableGet[] = {
|
static command_t CommandTableGet[] = {
|
||||||
// {"help", getCmdHelp, AlwaysAvailable, "This help"},
|
|
||||||
{"barmode", getCmdBarMode, AlwaysAvailable, "Get bar mode preference"},
|
{"barmode", getCmdBarMode, AlwaysAvailable, "Get bar mode preference"},
|
||||||
{"clientdebug", getCmdDebug, AlwaysAvailable, "Get client debug level preference"},
|
{"clientdebug", getCmdDebug, AlwaysAvailable, "Get client debug level preference"},
|
||||||
{"color", getCmdColor, AlwaysAvailable, "Get color support preference"},
|
{"color", getCmdColor, AlwaysAvailable, "Get color support preference"},
|
||||||
// {"defaultsavepaths", getCmdSavePaths, AlwaysAvailable, "... to be adjusted next ... "},
|
{"savepaths", getCmdSavePaths, AlwaysAvailable, "Get file folder "},
|
||||||
// {"devicedebug", getCmdDeviceDebug, AlwaysAvailable, "Get device debug level"},
|
// {"devicedebug", getCmdDeviceDebug, AlwaysAvailable, "Get device debug level"},
|
||||||
{"emoji", getCmdEmoji, AlwaysAvailable, "Get emoji display preference"},
|
{"emoji", getCmdEmoji, AlwaysAvailable, "Get emoji display preference"},
|
||||||
{"hints", getCmdHint, AlwaysAvailable, "Get hint display preference"},
|
{"hints", getCmdHint, AlwaysAvailable, "Get hint display preference"},
|
||||||
|
@ -1005,7 +985,7 @@ static command_t CommandTableSet[] = {
|
||||||
{"color", setCmdColor, AlwaysAvailable, "Set color support"},
|
{"color", setCmdColor, AlwaysAvailable, "Set color support"},
|
||||||
{"emoji", setCmdEmoji, AlwaysAvailable, "Set emoji display"},
|
{"emoji", setCmdEmoji, AlwaysAvailable, "Set emoji display"},
|
||||||
{"hints", setCmdHint, AlwaysAvailable, "Set hint display"},
|
{"hints", setCmdHint, AlwaysAvailable, "Set hint display"},
|
||||||
// {"defaultsavepaths", setCmdSavePaths, AlwaysAvailable, "... to be adjusted next ... "},
|
{"savepaths", setCmdSavePaths, AlwaysAvailable, "... to be adjusted next ... "},
|
||||||
// {"devicedebug", setCmdDeviceDebug, AlwaysAvailable, "Set device debug level"},
|
// {"devicedebug", setCmdDeviceDebug, AlwaysAvailable, "Set device debug level"},
|
||||||
{"plotsliders", setCmdPlotSliders, AlwaysAvailable, "Set plot slider display"},
|
{"plotsliders", setCmdPlotSliders, AlwaysAvailable, "Set plot slider display"},
|
||||||
{NULL, NULL, NULL, NULL}
|
{NULL, NULL, NULL, NULL}
|
||||||
|
@ -1042,11 +1022,11 @@ static int CmdPrefShow(const char *Cmd) {
|
||||||
showEmojiState(prefShowNone);
|
showEmojiState(prefShowNone);
|
||||||
showHintsState(prefShowNone);
|
showHintsState(prefShowNone);
|
||||||
showColorState(prefShowNone);
|
showColorState(prefShowNone);
|
||||||
// showPlotPosState ();
|
showPlotPosState();
|
||||||
// showOverlayPosState ();
|
showOverlayPosState();
|
||||||
// showSavePathState(spDefault, prefShowNone);
|
showSavePathState(spDefault, prefShowNone);
|
||||||
// showSavePathState(spDump, prefShowNone);
|
showSavePathState(spDump, prefShowNone);
|
||||||
// showSavePathState(spTrace, prefShowNone);
|
showSavePathState(spTrace, prefShowNone);
|
||||||
showClientDebugState(prefShowNone);
|
showClientDebugState(prefShowNone);
|
||||||
showPlotSliderState(prefShowNone);
|
showPlotSliderState(prefShowNone);
|
||||||
// showDeviceDebugState(prefShowNone);
|
// showDeviceDebugState(prefShowNone);
|
||||||
|
|
|
@ -27,7 +27,7 @@ typedef enum logLevel {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG, INPLA
|
||||||
typedef enum emojiMode {EMO_ALIAS, EMO_EMOJI, EMO_ALTTEXT, EMO_NONE} emojiMode_t;
|
typedef enum emojiMode {EMO_ALIAS, EMO_EMOJI, EMO_ALTTEXT, EMO_NONE} emojiMode_t;
|
||||||
typedef enum clientdebugLevel {cdbOFF, cdbSIMPLE, cdbFULL} clientdebugLevel_t;
|
typedef enum clientdebugLevel {cdbOFF, cdbSIMPLE, cdbFULL} clientdebugLevel_t;
|
||||||
// typedef enum devicedebugLevel {ddbOFF, ddbERROR, ddbINFO, ddbDEBUG, ddbEXTENDED} devicedebugLevel_t;
|
// typedef enum devicedebugLevel {ddbOFF, ddbERROR, ddbINFO, ddbDEBUG, ddbEXTENDED} devicedebugLevel_t;
|
||||||
//typedef enum savePaths {spDefault, spDump, spTrace, spItemCount} savePaths_t; // last item spItemCount used to auto map to number of files
|
typedef enum savePaths {spDefault, spDump, spTrace, spItemCount} savePaths_t; // last item spItemCount used to auto map to number of files
|
||||||
typedef struct {int x; int y; int h; int w;} qtWindow_t;
|
typedef struct {int x; int y; int h; int w;} qtWindow_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -44,7 +44,7 @@ typedef struct {
|
||||||
qtWindow_t overlay;
|
qtWindow_t overlay;
|
||||||
bool overlay_sliders;
|
bool overlay_sliders;
|
||||||
bool incognito;
|
bool incognito;
|
||||||
// char *defaultPaths[spItemCount]; // Array should allow loop searching for files
|
char *defaultPaths[spItemCount]; // Array should allow loop searching for files
|
||||||
clientdebugLevel_t client_debug_level;
|
clientdebugLevel_t client_debug_level;
|
||||||
barMode_t bar_mode;
|
barMode_t bar_mode;
|
||||||
// uint8_t device_debug_level;
|
// uint8_t device_debug_level;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue