2020-04-12 18:24:56 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
|
|
// the license.
|
2020-04-12 11:07:25 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Preferences Functions
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Notes
|
|
|
|
// To add a new setting
|
|
|
|
// Add the new setting to the session_arg_t; in ui.h
|
|
|
|
// Add the default value for the setting in the settings_load page below
|
|
|
|
// Update the preferences_load_callback to load your setting into the stucture
|
|
|
|
// Update the preferences_save_callback to enusre your setting gets saved when needed.
|
|
|
|
// use the preference as needed : session.<preference name>
|
2020-04-16 15:01:14 +08:00
|
|
|
// Can use (session.preferences_loaded) to check if json settings file was used
|
2020-04-12 11:07:25 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "preferences.h"
|
|
|
|
#include "comms.h"
|
|
|
|
#include "emv/emvjson.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include "cmdparser.h"
|
|
|
|
#include <ctype.h>
|
2020-04-17 17:29:33 +08:00
|
|
|
#include <dirent.h>
|
2020-04-14 17:17:00 +08:00
|
|
|
#include <proxmark3.h>
|
2020-04-13 10:44:34 +08:00
|
|
|
|
2020-04-12 11:07:25 +08:00
|
|
|
static int CmdHelp(const char *Cmd);
|
2020-04-13 10:12:47 +08:00
|
|
|
static int setCmdHelp(const char *Cmd);
|
2020-04-12 11:07:25 +08:00
|
|
|
|
|
|
|
// Load all settings into memory (struct)
|
2020-04-14 17:17:00 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <direct.h>
|
|
|
|
#define GetCurrentDir _getcwd
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#define GetCurrentDir getcwd
|
|
|
|
#endif
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
static char *prefGetFilename(void) {
|
2020-04-14 17:17:00 +08:00
|
|
|
char *Path;
|
2020-04-15 14:40:28 +08:00
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (searchHomeFilePath(&Path, preferencesFilename, false) == PM3_SUCCESS)
|
2020-04-15 14:40:28 +08:00
|
|
|
return Path;
|
|
|
|
else
|
|
|
|
return preferencesFilename;
|
2020-04-13 10:12:47 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
int preferences_load(void) {
|
2020-04-12 11:07:25 +08:00
|
|
|
|
|
|
|
// Set all defaults
|
2020-04-17 17:29:33 +08:00
|
|
|
session.client_debug_level = cdbOFF;
|
2020-04-24 14:56:35 +08:00
|
|
|
// session.device_debug_level = ddbOFF;
|
2020-04-13 14:17:57 +08:00
|
|
|
session.window_changed = false;
|
2020-04-18 16:04:08 +08:00
|
|
|
session.plot.x = 10;
|
|
|
|
session.plot.y = 30;
|
|
|
|
session.plot.h = 400;
|
|
|
|
session.plot.w = 800;
|
|
|
|
session.overlay.x = session.plot.x;
|
|
|
|
session.overlay.y = 60 + session.plot.y + session.plot.h;
|
|
|
|
session.overlay.h = 200;
|
|
|
|
session.overlay.w = session.plot.w;
|
2020-04-12 11:07:25 +08:00
|
|
|
session.emoji_mode = ALIAS;
|
|
|
|
session.show_hints = false;
|
|
|
|
session.supports_colors = false;
|
2020-04-16 15:01:14 +08:00
|
|
|
|
2020-04-25 16:37:23 +08:00
|
|
|
// setDefaultPath (spDefault, "");
|
|
|
|
// setDefaultPath (spDump, "");
|
|
|
|
// setDefaultPath (spTrace, "");
|
2020-04-24 14:56:35 +08:00
|
|
|
|
|
|
|
/*
|
2020-04-17 17:29:33 +08:00
|
|
|
// default save path
|
2020-04-19 08:49:09 +08:00
|
|
|
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
|
|
|
setDefaultPath (spDefault, get_my_user_directory());
|
|
|
|
else
|
|
|
|
setDefaultPath (spDefault, ".");
|
|
|
|
|
2020-04-18 16:04:08 +08:00
|
|
|
// default dump path
|
2020-04-19 08:49:09 +08:00
|
|
|
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
|
|
|
setDefaultPath (spDump, get_my_user_directory());
|
|
|
|
else
|
|
|
|
setDefaultPath (spDump, ".");
|
|
|
|
|
|
|
|
// default dump path
|
|
|
|
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
|
|
|
setDefaultPath (spTrace, get_my_user_directory());
|
|
|
|
else
|
|
|
|
setDefaultPath (spTrace, ".");
|
2020-04-24 14:56:35 +08:00
|
|
|
*/
|
2020-04-17 17:50:12 +08:00
|
|
|
|
2020-04-12 11:07:25 +08:00
|
|
|
// loadFileJson wants these, so pass in place holder values, though not used
|
|
|
|
// in settings load;
|
|
|
|
uint8_t dummyData = 0x00;
|
|
|
|
size_t dummyDL = 0x00;
|
2020-04-16 15:01:14 +08:00
|
|
|
|
2020-04-24 14:56:35 +08:00
|
|
|
// to better control json cant find file error msg.
|
|
|
|
if (fileExists(prefGetFilename())) {
|
|
|
|
PrintAndLogEx(INFO, "Loading Preferences %s",prefGetFilename());
|
|
|
|
if (loadFileJSON(prefGetFilename(), &dummyData, sizeof(dummyData), &dummyDL) == PM3_SUCCESS) {
|
|
|
|
session.preferences_loaded = true;
|
|
|
|
}
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
2020-04-16 15:01:14 +08:00
|
|
|
// Note, if session.settings_loaded == false then the settings_save
|
2020-04-12 11:07:25 +08:00
|
|
|
// will be called in main () to save settings as set in defaults and main() checks.
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
return PM3_SUCCESS;
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save all settings from memory (struct) to file
|
2020-04-16 15:01:14 +08:00
|
|
|
int preferences_save(void) {
|
2020-04-12 11:07:25 +08:00
|
|
|
// Note sure if backup has value ?
|
2020-04-13 14:17:57 +08:00
|
|
|
|
2020-04-17 17:29:33 +08:00
|
|
|
char *backupFilename = NULL;// [FILENAME_MAX+sizeof(preferencesFilename)+10] = {0};
|
|
|
|
int fnLen = 0;
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(INFO, "Saving preferences ...");
|
2020-04-17 17:29:33 +08:00
|
|
|
|
|
|
|
fnLen = strlen(prefGetFilename()) + 5; // .bak\0
|
|
|
|
backupFilename = (char *)calloc(fnLen, sizeof(uint8_t));
|
|
|
|
snprintf(backupFilename, fnLen, "%s.bak", prefGetFilename());
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (fileExists(backupFilename)) {
|
|
|
|
if (remove(backupFilename) != 0) {
|
|
|
|
PrintAndLogEx(FAILED, "Error - could not delete old settings backup file \"%s\"", backupFilename);
|
2020-04-12 11:07:25 +08:00
|
|
|
return PM3_ESOFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (fileExists(prefGetFilename())) {
|
|
|
|
if (rename(prefGetFilename(), backupFilename) != 0) {
|
|
|
|
PrintAndLogEx(FAILED, "Error - could not backup settings file \"%s\" to \"%s\"", prefGetFilename(), backupFilename);
|
|
|
|
return PM3_ESOFT;
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t dummyData = 0x00;
|
|
|
|
size_t dummyDL = 0x00;
|
|
|
|
|
2020-04-13 10:12:47 +08:00
|
|
|
if (saveFileJSON(prefGetFilename(), jsfSettings, &dummyData, dummyDL) != PM3_SUCCESS)
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(ERR, "Error saving preferences to \"%s\"", prefGetFilename());
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-17 17:29:33 +08:00
|
|
|
if (backupFilename != NULL)
|
|
|
|
free(backupFilename);
|
|
|
|
|
2020-04-12 11:07:25 +08:00
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
void preferences_save_callback(json_t *root) {
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
JsonSaveStr(root, "FileType", "settings");
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-17 17:29:33 +08:00
|
|
|
// Emoji
|
|
|
|
switch (session.emoji_mode) {
|
|
|
|
case ALIAS:
|
|
|
|
JsonSaveStr(root, "show.emoji", "alias");
|
2020-04-16 15:01:14 +08:00
|
|
|
break;
|
2020-04-17 17:29:33 +08:00
|
|
|
case EMOJI:
|
|
|
|
JsonSaveStr(root,"show.emoji","emoji");
|
2020-04-16 15:01:14 +08:00
|
|
|
break;
|
2020-04-17 17:29:33 +08:00
|
|
|
case ALTTEXT:
|
|
|
|
JsonSaveStr(root, "show.emoji", "alttext");
|
|
|
|
break;
|
|
|
|
case ERASE:
|
|
|
|
JsonSaveStr(root, "show.emoji", "erase");
|
2020-04-16 15:01:14 +08:00
|
|
|
break;
|
2020-04-12 11:07:25 +08:00
|
|
|
default:
|
2020-04-17 17:29:33 +08:00
|
|
|
JsonSaveStr(root, "show.emoji", "ALIAS");
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
|
2020-04-17 17:29:33 +08:00
|
|
|
JsonSaveBoolean(root, "show.hints", session.show_hints);
|
|
|
|
|
|
|
|
JsonSaveBoolean(root, "os.supports.colors", session.supports_colors);
|
|
|
|
|
2020-04-25 16:37:23 +08:00
|
|
|
// JsonSaveStr(root, "file.default.savepath", session.defaultPaths[spDefault]);
|
|
|
|
// JsonSaveStr(root, "file.default.dumppath", session.defaultPaths[spDump]);
|
|
|
|
// JsonSaveStr(root, "file.default.tracepath", session.defaultPaths[spTrace]);
|
2020-04-17 17:29:33 +08:00
|
|
|
|
2020-04-12 11:07:25 +08:00
|
|
|
// Plot window
|
2020-04-18 16:04:08 +08:00
|
|
|
JsonSaveInt(root, "window.plot.xpos", session.plot.x);
|
|
|
|
JsonSaveInt(root, "window.plot.ypos", session.plot.y);
|
|
|
|
JsonSaveInt(root, "window.plot.hsize", session.plot.h);
|
|
|
|
JsonSaveInt(root, "window.plot.wsize", session.plot.w);
|
2020-04-12 11:07:25 +08:00
|
|
|
|
|
|
|
// Overlay/Slider window
|
2020-04-18 16:04:08 +08:00
|
|
|
JsonSaveInt(root, "window.overlay.xpos", session.overlay.x);
|
|
|
|
JsonSaveInt(root, "window.overlay.ypos", session.overlay.y);
|
|
|
|
JsonSaveInt(root, "window.overlay.hsize", session.overlay.h);
|
|
|
|
JsonSaveInt(root, "window.overlay.wsize", session.overlay.w);
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-17 17:29:33 +08:00
|
|
|
// Log level, convert to text
|
|
|
|
switch (session.client_debug_level) {
|
|
|
|
case cdbOFF:
|
|
|
|
JsonSaveStr(root, "client.debug.level", "off");
|
2020-04-16 15:01:14 +08:00
|
|
|
break;
|
2020-04-17 17:29:33 +08:00
|
|
|
case cdbSIMPLE:
|
|
|
|
JsonSaveStr(root, "client.debug.level", "simple");
|
2020-04-16 15:01:14 +08:00
|
|
|
break;
|
2020-04-17 17:29:33 +08:00
|
|
|
case cdbFULL:
|
|
|
|
JsonSaveStr(root, "client.debug.level", "full");
|
2020-04-16 15:01:14 +08:00
|
|
|
break;
|
2020-04-12 11:07:25 +08:00
|
|
|
default:
|
2020-04-17 17:29:33 +08:00
|
|
|
JsonSaveStr(root, "logging.level", "NORMAL");
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
2020-04-24 14:56:35 +08:00
|
|
|
/*
|
2020-04-17 17:29:33 +08:00
|
|
|
switch (session.device_debug_level) {
|
|
|
|
case ddbOFF:
|
|
|
|
JsonSaveStr(root, "device.debug.level", "off");
|
|
|
|
break;
|
|
|
|
case ddbERROR:
|
|
|
|
JsonSaveStr(root, "device.debug.level", "error");
|
|
|
|
break;
|
|
|
|
case ddbINFO:
|
|
|
|
JsonSaveStr(root, "device.debug.level", "info");
|
|
|
|
break;
|
|
|
|
case ddbDEBUG:
|
|
|
|
JsonSaveStr(root, "device.debug.level", "debug");
|
|
|
|
break;
|
|
|
|
case ddbEXTENDED:
|
|
|
|
JsonSaveStr(root, "device.debug.level", "extended");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
JsonSaveStr(root, "logging.level", "NORMAL");
|
|
|
|
}
|
2020-04-24 14:56:35 +08:00
|
|
|
*/
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
void preferences_load_callback(json_t *root) {
|
2020-04-12 11:07:25 +08:00
|
|
|
json_error_t up_error = {0};
|
|
|
|
bool b1;
|
|
|
|
int i1;
|
|
|
|
const char *s1;
|
|
|
|
char tempStr [500]; // to use str_lower() since json unpack uses const char *
|
|
|
|
|
|
|
|
// Logging Level
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "client.debug.level", &s1) == 0) {
|
|
|
|
strncpy(tempStr, s1, sizeof(tempStr) - 1);
|
|
|
|
str_lower(tempStr);
|
2020-04-17 17:29:33 +08:00
|
|
|
if (strncmp(tempStr, "off", 3) == 0) session.client_debug_level = cdbOFF;
|
|
|
|
if (strncmp(tempStr, "simple", 6) == 0) session.client_debug_level = cdbSIMPLE;
|
|
|
|
if (strncmp(tempStr, "full", 4) == 0) session.client_debug_level = cdbFULL;
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
2020-04-25 16:37:23 +08:00
|
|
|
/*
|
2020-04-17 17:29:33 +08:00
|
|
|
// default save path
|
2020-04-19 08:49:09 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.savepath", &s1) == 0)
|
|
|
|
setDefaultPath (spDefault,s1);
|
|
|
|
|
2020-04-18 16:04:08 +08:00
|
|
|
// default dump path
|
2020-04-19 08:49:09 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.dumppath", &s1) == 0)
|
|
|
|
setDefaultPath (spDump,s1);
|
|
|
|
|
2020-04-18 16:04:08 +08:00
|
|
|
// default trace path
|
2020-04-19 08:49:09 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.tracepath", &s1) == 0)
|
|
|
|
setDefaultPath (spTrace,s1);
|
2020-04-25 16:37:23 +08:00
|
|
|
*/
|
2020-04-12 11:07:25 +08:00
|
|
|
// window plot
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.xpos", &i1) == 0)
|
2020-04-18 16:04:08 +08:00
|
|
|
session.plot.x = i1;
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.ypos", &i1) == 0)
|
2020-04-18 16:04:08 +08:00
|
|
|
session.plot.y = i1;
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.hsize", &i1) == 0)
|
2020-04-18 16:04:08 +08:00
|
|
|
session.plot.h = i1;
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.wsize", &i1) == 0)
|
2020-04-18 16:04:08 +08:00
|
|
|
session.plot.w = i1;
|
2020-04-12 11:07:25 +08:00
|
|
|
|
|
|
|
// overlay/slider plot
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.xpos", &i1) == 0)
|
2020-04-18 16:04:08 +08:00
|
|
|
session.overlay.x = i1;
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.ypos", &i1) == 0)
|
2020-04-18 16:04:08 +08:00
|
|
|
session.overlay.y = i1;
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.hsize", &i1) == 0)
|
2020-04-18 16:04:08 +08:00
|
|
|
session.overlay.h = i1;
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.wsize", &i1) == 0)
|
2020-04-18 16:04:08 +08:00
|
|
|
session.overlay.w = i1;
|
2020-04-12 11:07:25 +08:00
|
|
|
|
|
|
|
// show options
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "show.emoji", &s1) == 0) {
|
|
|
|
strncpy(tempStr, s1, sizeof(tempStr) - 1);
|
|
|
|
str_lower(tempStr);
|
|
|
|
if (strncmp(tempStr, "alias", 5) == 0) session.emoji_mode = ALIAS;
|
|
|
|
if (strncmp(tempStr, "emoji", 5) == 0) session.emoji_mode = EMOJI;
|
|
|
|
if (strncmp(tempStr, "alttext", 7) == 0) session.emoji_mode = ALTTEXT;
|
|
|
|
if (strncmp(tempStr, "erase", 5) == 0) session.emoji_mode = ERASE;
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:b}", "show.hints", &b1) == 0)
|
2020-04-12 11:07:25 +08:00
|
|
|
session.show_hints = b1;
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:b}", "os.supports.colors", &b1) == 0)
|
2020-04-12 11:07:25 +08:00
|
|
|
session.supports_colors = b1;
|
2020-04-24 14:56:35 +08:00
|
|
|
/*
|
2020-04-17 17:29:33 +08:00
|
|
|
// Logging Level
|
|
|
|
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "device.debug.level", &s1) == 0) {
|
|
|
|
strncpy(tempStr, s1, sizeof(tempStr) - 1);
|
|
|
|
str_lower(tempStr);
|
|
|
|
if (strncmp(tempStr, "off", 3) == 0) session.device_debug_level = ddbOFF;
|
|
|
|
if (strncmp(tempStr, "error", 5) == 0) session.device_debug_level = ddbERROR;
|
|
|
|
if (strncmp(tempStr, "info", 4) == 0) session.device_debug_level = ddbINFO;
|
|
|
|
if (strncmp(tempStr, "debug", 5) == 0) session.device_debug_level = ddbDEBUG;
|
|
|
|
if (strncmp(tempStr, "extended", 8) == 0) session.device_debug_level = ddbEXTENDED;
|
|
|
|
}
|
2020-04-24 14:56:35 +08:00
|
|
|
*/
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Help Functions
|
2020-04-13 10:12:47 +08:00
|
|
|
|
|
|
|
static int usage_set_emoji() {
|
|
|
|
PrintAndLogEx(NORMAL, "Usage: pref set emoji <alias | emoji | alttext | erase>");
|
2020-04-12 11:07:25 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Options:");
|
2020-04-13 10:12:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("help")" - This help");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("alias")" - Show alias for emoji");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("emoji")" - Show amoji");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("alttext")" - Show alt text for emoji");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("erase")" - Dont show emoji or text");
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-13 10:12:47 +08:00
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-13 10:12:47 +08:00
|
|
|
static int usage_set_color() {
|
|
|
|
PrintAndLogEx(NORMAL, "Usage: pref set color <off | ansi>");
|
|
|
|
PrintAndLogEx(NORMAL, "Options:");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("help")" - This help");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("off")" - Dont use colors");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("ansi")" - Use ANSI colors");
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-13 10:12:47 +08:00
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-13 10:12:47 +08:00
|
|
|
static int usage_set_debug() {
|
2020-04-17 17:29:33 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Usage: pref set clientdebug <off | simple | full>");
|
2020-04-13 10:12:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Options:");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("help")" - This help");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("off")" - no debug messages");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("simple")" - simple debug messages");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("full")" - full debug messages");
|
2020-04-12 11:07:25 +08:00
|
|
|
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-04-24 14:56:35 +08:00
|
|
|
/*
|
2020-04-17 17:29:33 +08:00
|
|
|
static int usage_set_devicedebug() {
|
|
|
|
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;
|
|
|
|
}
|
2020-04-24 14:56:35 +08:00
|
|
|
*/
|
2020-04-13 10:12:47 +08:00
|
|
|
static int usage_set_hints() {
|
|
|
|
PrintAndLogEx(NORMAL, "Usage: pref set hints <off | on>");
|
2020-04-12 11:07:25 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Options:");
|
2020-04-13 10:12:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("help")" - This help");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("off")" - Dont display hints");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("on")" - Display hints");
|
2020-04-12 11:07:25 +08:00
|
|
|
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-04-25 16:37:23 +08:00
|
|
|
/*
|
2020-04-18 16:04:08 +08:00
|
|
|
static int usage_set_savePaths() {
|
|
|
|
PrintAndLogEx(NORMAL, "Usage: pref set savepaths [help] [create] [default <path>] [dump <path>] [trace <path>]");
|
2020-04-17 17:29:33 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Options:");
|
|
|
|
PrintAndLogEx(NORMAL, " "_GREEN_("help")" - This help");
|
2020-04-18 16:04:08 +08:00
|
|
|
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");
|
2020-04-17 17:29:33 +08:00
|
|
|
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-04-25 16:37:23 +08:00
|
|
|
*/
|
2020-04-12 11:07:25 +08:00
|
|
|
// Preference Processing Functions
|
2020-04-17 17:29:33 +08:00
|
|
|
// typedef enum preferenceId {prefNONE,prefHELP,prefEMOJI,prefCOLOR,prefPLOT,prefOVERLAY,prefHINTS,prefCLIENTDEBUG} preferenceId_t;
|
|
|
|
typedef enum prefShowOpt {prefShowNone, prefShowOLD, prefShowNEW} prefShowOpt_t;
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-17 17:29:33 +08:00
|
|
|
const char *prefShowMsg(prefShowOpt_t Opt)
|
|
|
|
{
|
2020-04-13 10:12:47 +08:00
|
|
|
switch (Opt) {
|
2020-04-16 15:01:14 +08:00
|
|
|
case prefShowOLD:
|
2020-04-17 17:29:33 +08:00
|
|
|
return _YELLOW_("[old]");
|
2020-04-16 15:01:14 +08:00
|
|
|
case prefShowNEW:
|
2020-04-17 17:29:33 +08:00
|
|
|
return _GREEN_("[new]");
|
2020-04-16 15:01:14 +08:00
|
|
|
case prefShowNone:
|
|
|
|
return "";
|
2020-04-13 10:12:47 +08:00
|
|
|
}
|
2020-04-16 15:01:14 +08:00
|
|
|
|
2020-04-13 10:12:47 +08:00
|
|
|
return "";
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
void showEmojiState(prefShowOpt_t Opt) {
|
2020-04-13 10:12:47 +08:00
|
|
|
|
2020-04-12 11:07:25 +08:00
|
|
|
switch (session.emoji_mode) {
|
2020-04-16 15:01:14 +08:00
|
|
|
case ALIAS:
|
|
|
|
PrintAndLogEx(NORMAL, " %s emoji.................. "_GREEN_("alias"), prefShowMsg(Opt));
|
2020-04-12 11:07:25 +08:00
|
|
|
break;
|
2020-04-16 15:01:14 +08:00
|
|
|
case EMOJI:
|
|
|
|
PrintAndLogEx(NORMAL, " %s emoji.................. "_GREEN_("emoji"), prefShowMsg(Opt));
|
2020-04-12 11:07:25 +08:00
|
|
|
break;
|
2020-04-16 15:01:14 +08:00
|
|
|
case ALTTEXT:
|
|
|
|
PrintAndLogEx(NORMAL, " %s emoji.................. "_GREEN_("alttext"), prefShowMsg(Opt));
|
2020-04-12 11:07:25 +08:00
|
|
|
break;
|
2020-04-16 15:01:14 +08:00
|
|
|
case ERASE:
|
|
|
|
PrintAndLogEx(NORMAL, " %s emoji.................. "_GREEN_("erase"), prefShowMsg(Opt));
|
2020-04-12 11:07:25 +08:00
|
|
|
break;
|
|
|
|
default:
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(NORMAL, " %s emoji.................. "_RED_("unknown"), prefShowMsg(Opt));
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
void showColorState(prefShowOpt_t Opt) {
|
2020-04-13 10:12:47 +08:00
|
|
|
|
2020-04-12 11:07:25 +08:00
|
|
|
if (session.supports_colors)
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(NORMAL, " %s color.................. "_GREEN_("ansi"), prefShowMsg(Opt));
|
2020-04-12 11:07:25 +08:00
|
|
|
else
|
2020-04-17 17:29:33 +08:00
|
|
|
PrintAndLogEx(NORMAL, " %s color.................. "_WHITE_("off"), prefShowMsg(Opt));
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
void showClientDebugState(prefShowOpt_t Opt) {
|
|
|
|
|
2020-04-12 11:07:25 +08:00
|
|
|
switch (session.client_debug_level) {
|
2020-04-17 17:29:33 +08:00
|
|
|
case cdbOFF:
|
|
|
|
PrintAndLogEx(NORMAL, " %s client debug........... "_WHITE_("off"), prefShowMsg(Opt));
|
2020-04-16 15:01:14 +08:00
|
|
|
break;
|
2020-04-17 17:29:33 +08:00
|
|
|
case cdbSIMPLE:
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(NORMAL, " %s client debug........... "_GREEN_("simple"), prefShowMsg(Opt));
|
|
|
|
break;
|
2020-04-17 17:29:33 +08:00
|
|
|
case cdbFULL:
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(NORMAL, " %s client debug........... "_GREEN_("full"), prefShowMsg(Opt));
|
|
|
|
break;
|
2020-04-12 11:07:25 +08:00
|
|
|
default:
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(NORMAL, " %s client debug........... "_RED_("unknown"), prefShowMsg(Opt));
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
}
|
2020-04-24 14:56:35 +08:00
|
|
|
/*
|
2020-04-17 17:29:33 +08:00
|
|
|
void showDeviceDebugState(prefShowOpt_t Opt) {
|
|
|
|
switch (session.device_debug_level) {
|
|
|
|
case ddbOFF:
|
|
|
|
PrintAndLogEx(NORMAL, " %s device debug........... "_WHITE_("off"), prefShowMsg(Opt));
|
|
|
|
break;
|
|
|
|
case ddbERROR:
|
|
|
|
PrintAndLogEx(NORMAL, " %s device debug........... "_GREEN_("error"), prefShowMsg(Opt));
|
|
|
|
break;
|
|
|
|
case ddbINFO:
|
|
|
|
PrintAndLogEx(NORMAL, " %s device debug........... "_GREEN_("info"), prefShowMsg(Opt));
|
|
|
|
break;
|
|
|
|
case ddbDEBUG:
|
|
|
|
PrintAndLogEx(NORMAL, " %s device debug........... "_GREEN_("debug"), prefShowMsg(Opt));
|
|
|
|
break;
|
|
|
|
case ddbEXTENDED:
|
|
|
|
PrintAndLogEx(NORMAL, " %s device debug........... "_GREEN_("extended"), prefShowMsg(Opt));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PrintAndLogEx(NORMAL, " %s device debug........... "_RED_("unknown"), prefShowMsg(Opt));
|
|
|
|
}
|
|
|
|
}
|
2020-04-24 14:56:35 +08:00
|
|
|
*/
|
2020-04-25 16:37:23 +08:00
|
|
|
/*
|
2020-04-19 08:49:09 +08:00
|
|
|
void showSavePathState(savePaths_t pathIndex, prefShowOpt_t Opt) {
|
|
|
|
|
|
|
|
char tempStr[50];
|
|
|
|
|
|
|
|
switch (pathIndex) {
|
|
|
|
case spDefault:
|
|
|
|
strcpy (tempStr,"default save path......");
|
|
|
|
break;
|
|
|
|
case spDump:
|
|
|
|
strcpy (tempStr,"dump save path.........");
|
|
|
|
break;
|
|
|
|
case spTrace:
|
|
|
|
strcpy (tempStr,"trace save path........");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy (tempStr,_RED_("unknown")" save path......");
|
|
|
|
}
|
2020-04-24 14:56:35 +08:00
|
|
|
if ((session.defaultPaths[pathIndex] == NULL) || (strcmp(session.defaultPaths[pathIndex],"") == 0))
|
|
|
|
PrintAndLogEx(NORMAL, " %s %s "_WHITE_("not set"), prefShowMsg(Opt),tempStr);
|
|
|
|
else
|
|
|
|
PrintAndLogEx(NORMAL, " %s %s "_GREEN_("%s"), prefShowMsg(Opt), tempStr, session.defaultPaths[pathIndex]);
|
2020-04-17 17:29:33 +08:00
|
|
|
}
|
2020-04-25 16:37:23 +08:00
|
|
|
*/
|
2020-04-17 17:29:33 +08:00
|
|
|
void showPlotPosState(void){
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(NORMAL, " Plot window............ X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
|
2020-04-18 16:04:08 +08:00
|
|
|
session.plot.x, session.plot.y, session.plot.h, session.plot.w);
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
void showOverlayPosState(void) {
|
|
|
|
PrintAndLogEx(NORMAL, " Slider/Overlay window.. X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
|
2020-04-18 16:04:08 +08:00
|
|
|
session.overlay.x, session.overlay.y, session.overlay.h, session.overlay.w);
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
void showHintsState(prefShowOpt_t Opt) {
|
2020-04-12 11:07:25 +08:00
|
|
|
if (session.show_hints)
|
2020-04-17 17:29:33 +08:00
|
|
|
PrintAndLogEx(NORMAL, " %s hints.................. "_GREEN_("on"), prefShowMsg(Opt));
|
2020-04-12 11:07:25 +08:00
|
|
|
else
|
2020-04-17 17:29:33 +08:00
|
|
|
PrintAndLogEx(NORMAL, " %s hints.................. "_WHITE_("off"), prefShowMsg(Opt));
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
static int setCmdEmoji(const char *Cmd) {
|
2020-04-12 11:07:25 +08:00
|
|
|
uint8_t cmdp = 0;
|
|
|
|
bool errors = false;
|
2020-04-13 12:39:16 +08:00
|
|
|
bool validValue = false;
|
2020-04-12 11:07:25 +08:00
|
|
|
char strOpt[50];
|
2020-04-13 10:12:47 +08:00
|
|
|
emojiMode_t newValue = session.emoji_mode;
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (param_getchar(Cmd, cmdp) == 0x00)
|
2020-04-13 10:12:47 +08:00
|
|
|
return usage_set_emoji();
|
|
|
|
|
|
|
|
while ((param_getchar(Cmd, cmdp) != 0x00) && !errors) {
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-13 10:12:47 +08:00
|
|
|
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
|
|
|
str_lower(strOpt); // convert to lowercase
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "help", 4) == 0)
|
2020-04-13 12:39:16 +08:00
|
|
|
return usage_set_emoji();
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "alias", 5) == 0) {
|
2020-04-13 12:39:16 +08:00
|
|
|
validValue = true;
|
|
|
|
newValue = ALIAS;
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "emoji", 5) == 0) {
|
2020-04-13 12:39:16 +08:00
|
|
|
validValue = true;
|
|
|
|
newValue = EMOJI;
|
|
|
|
}
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "alttext", 7) == 0) {
|
2020-04-13 12:39:16 +08:00
|
|
|
validValue = true;
|
|
|
|
newValue = ALTTEXT;
|
|
|
|
}
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "erase", 5) == 0) {
|
2020-04-13 12:39:16 +08:00
|
|
|
validValue = true;
|
|
|
|
newValue = ERASE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (validValue) {
|
2020-04-16 15:01:14 +08:00
|
|
|
if (session.emoji_mode != newValue) {// changed
|
|
|
|
showEmojiState(prefShowOLD);
|
2020-04-13 12:39:16 +08:00
|
|
|
session.emoji_mode = newValue;
|
2020-04-16 15:01:14 +08:00
|
|
|
showEmojiState(prefShowNEW);
|
|
|
|
preferences_save();
|
2020-04-13 12:39:16 +08:00
|
|
|
} else {
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(INFO, "nothing changed");
|
|
|
|
showEmojiState(prefShowNone);
|
2020-04-13 12:39:16 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(ERR, "invalid option");
|
2020-04-13 12:39:16 +08:00
|
|
|
return usage_set_emoji();
|
|
|
|
}
|
|
|
|
}
|
2020-04-13 10:12:47 +08:00
|
|
|
}
|
2020-04-13 12:39:16 +08:00
|
|
|
|
2020-04-13 10:12:47 +08:00
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
static int setCmdColor(const char *Cmd) {
|
2020-04-13 10:12:47 +08:00
|
|
|
uint8_t cmdp = 0;
|
|
|
|
bool errors = false;
|
2020-04-13 12:39:16 +08:00
|
|
|
bool validValue = false;
|
2020-04-13 10:12:47 +08:00
|
|
|
char strOpt[50];
|
|
|
|
bool newValue = session.supports_colors;
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (param_getchar(Cmd, cmdp) == 0x00)
|
2020-04-13 10:12:47 +08:00
|
|
|
return usage_set_color();
|
|
|
|
|
|
|
|
while ((param_getchar(Cmd, cmdp) != 0x00) && !errors) {
|
|
|
|
|
|
|
|
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
|
|
|
str_lower(strOpt); // convert to lowercase
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "help", 4) == 0)
|
2020-04-13 12:39:16 +08:00
|
|
|
return usage_set_color();
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "off", 3) == 0) {
|
2020-04-13 12:39:16 +08:00
|
|
|
validValue = true;
|
2020-04-16 15:01:14 +08:00
|
|
|
newValue = false;
|
2020-04-13 12:39:16 +08:00
|
|
|
}
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "ansi", 4) == 0) {
|
2020-04-13 12:39:16 +08:00
|
|
|
validValue = true;
|
|
|
|
newValue = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (validValue) {
|
2020-04-16 15:01:14 +08:00
|
|
|
if (session.supports_colors != newValue) {// changed
|
|
|
|
showColorState(prefShowOLD);
|
2020-04-13 12:39:16 +08:00
|
|
|
session.supports_colors = newValue;
|
2020-04-16 15:01:14 +08:00
|
|
|
showColorState(prefShowNEW);
|
|
|
|
preferences_save();
|
2020-04-13 12:39:16 +08:00
|
|
|
} else {
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(INFO, "nothing changed");
|
|
|
|
showColorState(prefShowNone);
|
2020-04-13 12:39:16 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(ERR, "invalid option");
|
2020-04-13 12:39:16 +08:00
|
|
|
return usage_set_color();
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-13 10:12:47 +08:00
|
|
|
|
2020-04-12 11:07:25 +08:00
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
static int setCmdDebug(const char *Cmd) {
|
2020-04-12 11:07:25 +08:00
|
|
|
uint8_t cmdp = 0;
|
|
|
|
bool errors = false;
|
2020-04-13 12:39:16 +08:00
|
|
|
bool validValue = false;
|
2020-04-12 11:07:25 +08:00
|
|
|
char strOpt[50];
|
2020-04-13 10:12:47 +08:00
|
|
|
clientdebugLevel_t newValue = session.client_debug_level;
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (param_getchar(Cmd, cmdp) == 0x00)
|
2020-04-13 10:12:47 +08:00
|
|
|
return usage_set_debug();
|
2020-04-12 11:07:25 +08:00
|
|
|
|
|
|
|
while ((param_getchar(Cmd, cmdp) != 0x00) && !errors) {
|
|
|
|
|
2020-04-13 10:12:47 +08:00
|
|
|
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
|
|
|
str_lower(strOpt); // convert to lowercase
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "help", 4) == 0)
|
2020-04-13 12:39:16 +08:00
|
|
|
return usage_set_debug();
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "off", 3) == 0) {
|
2020-04-13 12:39:16 +08:00
|
|
|
validValue = true;
|
2020-04-17 17:29:33 +08:00
|
|
|
newValue = cdbOFF;
|
2020-04-16 15:01:14 +08:00
|
|
|
}
|
|
|
|
if (strncmp(strOpt, "simple", 6) == 0) {
|
2020-04-13 12:39:16 +08:00
|
|
|
validValue = true;
|
2020-04-17 17:29:33 +08:00
|
|
|
newValue = cdbSIMPLE;
|
2020-04-13 12:39:16 +08:00
|
|
|
}
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "full", 4) == 0) {
|
2020-04-13 12:39:16 +08:00
|
|
|
validValue = true;
|
2020-04-17 17:29:33 +08:00
|
|
|
newValue = cdbFULL;
|
2020-04-13 12:39:16 +08:00
|
|
|
}
|
2020-04-13 10:12:47 +08:00
|
|
|
|
2020-04-13 12:39:16 +08:00
|
|
|
if (validValue) {
|
2020-04-16 15:01:14 +08:00
|
|
|
if (session.client_debug_level != newValue) {// changed
|
|
|
|
showClientDebugState(prefShowOLD);
|
2020-04-13 12:39:16 +08:00
|
|
|
session.client_debug_level = newValue;
|
|
|
|
g_debugMode = newValue;
|
2020-04-16 15:01:14 +08:00
|
|
|
showClientDebugState(prefShowNEW);
|
|
|
|
preferences_save();
|
2020-04-13 12:39:16 +08:00
|
|
|
} else {
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(INFO, "nothing changed");
|
|
|
|
showClientDebugState(prefShowNone);
|
2020-04-13 12:39:16 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(ERR, "invalid option");
|
2020-04-13 12:39:16 +08:00
|
|
|
return usage_set_debug();
|
2020-04-13 10:12:47 +08:00
|
|
|
}
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
2020-04-13 10:12:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-04-24 14:56:35 +08:00
|
|
|
/*
|
2020-04-17 17:29:33 +08:00
|
|
|
static int setCmdDeviceDebug (const char *Cmd)
|
|
|
|
{
|
|
|
|
uint8_t cmdp = 0;
|
|
|
|
bool errors = false;
|
|
|
|
bool validValue = false;
|
|
|
|
char strOpt[50];
|
|
|
|
devicedebugLevel_t newValue = session.device_debug_level;
|
|
|
|
|
|
|
|
if (param_getchar(Cmd, cmdp) == 0x00)
|
|
|
|
return usage_set_devicedebug ();
|
|
|
|
|
|
|
|
while ((param_getchar(Cmd, cmdp) != 0x00) && !errors) {
|
|
|
|
|
|
|
|
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-04-24 14:56:35 +08:00
|
|
|
*/
|
2020-04-17 17:29:33 +08:00
|
|
|
static int setCmdHint (const char *Cmd)
|
|
|
|
{
|
2020-04-13 10:12:47 +08:00
|
|
|
uint8_t cmdp = 0;
|
|
|
|
bool errors = false;
|
2020-04-13 12:39:16 +08:00
|
|
|
bool validValue = false;
|
2020-04-13 10:12:47 +08:00
|
|
|
char strOpt[50];
|
|
|
|
bool newValue = session.show_hints;
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (param_getchar(Cmd, cmdp) == 0x00)
|
2020-04-13 10:12:47 +08:00
|
|
|
return usage_set_hints();
|
|
|
|
|
|
|
|
while ((param_getchar(Cmd, cmdp) != 0x00) && !errors) {
|
|
|
|
|
|
|
|
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
|
|
|
str_lower(strOpt); // convert to lowercase
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "help", 4) == 0)
|
2020-04-13 12:39:16 +08:00
|
|
|
return usage_set_hints();
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "off", 3) == 0) {
|
2020-04-13 12:39:16 +08:00
|
|
|
validValue = true;
|
2020-04-16 15:01:14 +08:00
|
|
|
newValue = false;
|
2020-04-13 12:39:16 +08:00
|
|
|
}
|
2020-04-16 15:01:14 +08:00
|
|
|
if (strncmp(strOpt, "on", 2) == 0) {
|
2020-04-13 12:39:16 +08:00
|
|
|
validValue = true;
|
|
|
|
newValue = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (validValue) {
|
2020-04-16 15:01:14 +08:00
|
|
|
if (session.show_hints != newValue) {// changed
|
|
|
|
showHintsState(prefShowOLD);
|
2020-04-13 12:39:16 +08:00
|
|
|
session.show_hints = newValue;
|
2020-04-16 15:01:14 +08:00
|
|
|
showHintsState(prefShowNEW);
|
|
|
|
preferences_save();
|
2020-04-13 12:39:16 +08:00
|
|
|
} else {
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(INFO, "nothing changed");
|
|
|
|
showHintsState(prefShowNone);
|
2020-04-13 12:39:16 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(ERR, "invalid option");
|
2020-04-13 12:39:16 +08:00
|
|
|
return usage_set_hints();
|
2020-04-13 10:12:47 +08:00
|
|
|
}
|
2020-04-12 11:07:25 +08:00
|
|
|
}
|
|
|
|
}
|
2020-04-13 10:12:47 +08:00
|
|
|
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-04-25 16:37:23 +08:00
|
|
|
/*
|
2020-04-18 16:04:08 +08:00
|
|
|
static int setCmdSavePaths (const char *Cmd) {
|
2020-04-17 17:29:33 +08:00
|
|
|
uint8_t cmdp = 0;
|
|
|
|
bool errors = false;
|
|
|
|
// bool validValue = false;
|
|
|
|
char *strOpt = NULL;
|
|
|
|
int optLen = 0;
|
|
|
|
char *newValue = NULL;
|
2020-04-18 16:04:08 +08:00
|
|
|
bool createDir = false;
|
2020-04-19 08:49:09 +08:00
|
|
|
savePaths_t pathItem = spItemCount;
|
|
|
|
|
2020-04-17 17:29:33 +08:00
|
|
|
|
|
|
|
if (param_getchar(Cmd, cmdp) == 0x00)
|
2020-04-18 16:04:08 +08:00
|
|
|
return usage_set_savePaths();
|
2020-04-17 17:29:33 +08:00
|
|
|
|
|
|
|
while ((param_getchar(Cmd, cmdp) != 0x00) && !errors) {
|
2020-04-18 16:04:08 +08:00
|
|
|
|
2020-04-17 17:29:33 +08:00
|
|
|
optLen = param_getlength(Cmd, cmdp)+1;
|
2020-04-18 16:04:08 +08:00
|
|
|
strOpt = (char *)realloc(strOpt,optLen+1);//, sizeof(uint8_t));
|
|
|
|
|
2020-04-17 17:29:33 +08:00
|
|
|
if (param_getstr(Cmd, cmdp++, strOpt, optLen) != 0) {
|
|
|
|
str_lower(strOpt); // convert to lowercase
|
|
|
|
|
2020-04-18 16:04:08 +08:00
|
|
|
if (strncmp(strOpt, "help", 4) == 0)
|
|
|
|
return usage_set_savePaths();
|
|
|
|
|
|
|
|
if (strncmp(strOpt, "create", 6) == 0) {
|
|
|
|
// check if 2 more options.
|
|
|
|
if (param_getlength(Cmd, cmdp+1) == 0) // should have min 2 more options
|
|
|
|
return usage_set_savePaths();
|
|
|
|
createDir = true;
|
|
|
|
} else {
|
|
|
|
if ((strncmp(strOpt, "default", 7) == 0) ||
|
|
|
|
(strncmp(strOpt, "dump", 4) == 0) ||
|
2020-04-21 10:35:13 +08:00
|
|
|
(strncmp(strOpt, "trace", 5) == 0)) {
|
2020-04-18 16:04:08 +08:00
|
|
|
|
|
|
|
// Get Path
|
|
|
|
optLen = param_getlength(Cmd, cmdp) + 1;
|
|
|
|
newValue = (char *)realloc(newValue, optLen+1);
|
|
|
|
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
|
|
|
|
if (!fileExists(newValue) && !createDir) {
|
|
|
|
PrintAndLogEx(ERR,"path does not exist... "_RED_("%s"),newValue);
|
2020-04-17 17:29:33 +08:00
|
|
|
} else {
|
2020-04-18 16:04:08 +08:00
|
|
|
// do we need to create it
|
2020-04-24 14:56:35 +08:00
|
|
|
// if (!fileExists(newValue))
|
|
|
|
// create_path (newValue); //mkdir (newValue,0x777);
|
2020-04-18 16:04:08 +08:00
|
|
|
|
2020-04-19 08:49:09 +08:00
|
|
|
pathItem = spItemCount;
|
|
|
|
if (strncmp(strOpt, "default", 7) == 0) pathItem = spDefault;
|
|
|
|
if (strncmp(strOpt, "dump", 4) == 0) pathItem = spDump;
|
2020-04-21 10:35:13 +08:00
|
|
|
if (strncmp(strOpt, "trace", 5) == 0) pathItem = spTrace;
|
2020-04-19 08:49:09 +08:00
|
|
|
|
|
|
|
if (pathItem < spItemCount) {
|
|
|
|
if (strcmp(newValue, session.defaultPaths[pathItem]) != 0) {
|
|
|
|
showSavePathState(pathItem, prefShowOLD);
|
|
|
|
setDefaultPath (pathItem, newValue);
|
|
|
|
showSavePathState(pathItem, prefShowNEW);
|
|
|
|
preferences_save();
|
|
|
|
} else {
|
|
|
|
PrintAndLogEx(INFO, "nothing changed");
|
|
|
|
showSavePathState(pathItem, prefShowNone);
|
|
|
|
}
|
|
|
|
}
|
2020-04-17 17:29:33 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-18 16:04:08 +08:00
|
|
|
return usage_set_savePaths();
|
2020-04-17 17:29:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// clean up
|
|
|
|
if (strOpt != NULL) free (strOpt);
|
|
|
|
if (newValue != NULL) free (newValue);
|
|
|
|
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-04-25 16:37:23 +08:00
|
|
|
*/
|
2020-04-13 10:12:47 +08:00
|
|
|
static command_t setCommandTable[] = {
|
2020-04-18 16:04:08 +08:00
|
|
|
{"help", setCmdHelp, AlwaysAvailable, "This help"},
|
|
|
|
{"emoji", setCmdEmoji, AlwaysAvailable, "Set emoji display"},
|
|
|
|
{"hints", setCmdHint, AlwaysAvailable, "Set hint display"},
|
|
|
|
{"color", setCmdColor, AlwaysAvailable, "Set color support"},
|
2020-04-25 16:37:23 +08:00
|
|
|
// {"defaultsavepaths", setCmdSavePaths, AlwaysAvailable, "... to be adjusted next ... "},
|
2020-04-18 16:04:08 +08:00
|
|
|
{"clientdebug", setCmdDebug, AlwaysAvailable, "Set client debug level"},
|
2020-04-24 14:56:35 +08:00
|
|
|
// {"devicedebug", setCmdDeviceDebug, AlwaysAvailable, "Set device debug level"},
|
2020-04-13 10:12:47 +08:00
|
|
|
{NULL, NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int setCmdHelp(const char *Cmd) {
|
|
|
|
(void)Cmd; // Cmd is not used so far
|
|
|
|
CmdsHelp(setCommandTable);
|
|
|
|
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
int CmdPrefSet(const char *Cmd) {
|
2020-04-13 10:12:47 +08:00
|
|
|
clearCommandBuffer();
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
return CmdsParse(setCommandTable, Cmd);
|
2020-04-13 10:12:47 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
static int CmdPrefShow(const char *Cmd) {
|
|
|
|
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
2020-04-24 14:56:35 +08:00
|
|
|
PrintAndLogEx(NORMAL, _CYAN_("Preferences loaded from %s"),prefGetFilename());
|
2020-04-17 17:29:33 +08:00
|
|
|
|
|
|
|
if (!session.preferences_loaded) {
|
|
|
|
PrintAndLogEx (ERR, "Preferneces not loaded");
|
2020-04-13 10:12:47 +08:00
|
|
|
return PM3_ESOFT;
|
|
|
|
}
|
|
|
|
|
2020-04-24 14:56:35 +08:00
|
|
|
// PrintAndLogEx(NORMAL, " preference file........ "_GREEN_("%s"), prefGetFilename());
|
2020-04-16 15:01:14 +08:00
|
|
|
showEmojiState(prefShowNone);
|
2020-04-17 17:29:33 +08:00
|
|
|
showHintsState(prefShowNone);
|
2020-04-16 15:01:14 +08:00
|
|
|
showColorState(prefShowNone);
|
2020-04-17 17:29:33 +08:00
|
|
|
// showPlotPosState ();
|
|
|
|
// showOverlayPosState ();
|
2020-04-24 14:56:35 +08:00
|
|
|
// showSavePathState(spDefault, prefShowNone);
|
|
|
|
// showSavePathState(spDump, prefShowNone);
|
|
|
|
// showSavePathState(spTrace, prefShowNone);
|
|
|
|
|
2020-04-13 10:12:47 +08:00
|
|
|
showClientDebugState(prefShowNone);
|
2020-04-24 14:56:35 +08:00
|
|
|
// showDeviceDebugState(prefShowNone);
|
2020-04-16 15:01:14 +08:00
|
|
|
PrintAndLogEx(NORMAL, "");
|
2020-04-13 10:12:47 +08:00
|
|
|
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-04-13 14:17:57 +08:00
|
|
|
/*
|
2020-04-13 10:12:47 +08:00
|
|
|
static int CmdPrefSave (const char *Cmd) {
|
2020-04-12 11:07:25 +08:00
|
|
|
preferences_save();
|
2020-04-13 10:12:47 +08:00
|
|
|
|
2020-04-12 11:07:25 +08:00
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-04-13 14:17:57 +08:00
|
|
|
*/
|
2020-04-12 11:07:25 +08:00
|
|
|
static command_t CommandTable[] = {
|
|
|
|
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
|
|
|
{"set", CmdPrefSet, AlwaysAvailable, "Set a preference"},
|
2020-04-13 10:12:47 +08:00
|
|
|
{"show", CmdPrefShow, AlwaysAvailable, "Show preferences"},
|
2020-04-12 11:07:25 +08:00
|
|
|
{NULL, NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int CmdHelp(const char *Cmd) {
|
|
|
|
(void)Cmd; // Cmd is not used so far
|
|
|
|
CmdsHelp(CommandTable);
|
|
|
|
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
int CmdPreferences(const char *Cmd) {
|
2020-04-12 11:07:25 +08:00
|
|
|
clearCommandBuffer();
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
return CmdsParse(CommandTable, Cmd);
|
|
|
|
}
|