diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cadedcca..ceaea4f56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Changed `prefs set client.debug` - now also toggles the client side APDU logging (@iceman1001) - Changed `hf 14b sriwrbl` - now supports --force to override block checks. Thanks @gentilkiwi for the idea! (@iceman1001) - Changed `hf 14b sriwrbl` - now tries to verify the write (@iceman1001) - Changed `hf 14b apdu` - now supports tearoff (@iceman1001) diff --git a/client/src/preferences.c b/client/src/preferences.c index 8ceab2bb5..09521cab4 100644 --- a/client/src/preferences.c +++ b/client/src/preferences.c @@ -122,7 +122,7 @@ int preferences_save(void) { PrintAndLogEx(INFO, "No preferences file will be saved"); return PM3_SUCCESS; } - PrintAndLogEx(INFO, "Saving preferences..."); + PrintAndLogEx(DEBUG, "Saving preferences..."); char *fn = prefGetFilename(); int fn_len = strlen(fn) + 5; // .bak\0 @@ -279,6 +279,12 @@ void preferences_load_callback(json_t *root) { if (strncmp(tempStr, "off", 3) == 0) g_session.client_debug_level = cdbOFF; if (strncmp(tempStr, "simple", 6) == 0) g_session.client_debug_level = cdbSIMPLE; if (strncmp(tempStr, "full", 4) == 0) g_session.client_debug_level = cdbFULL; + + if (g_session.client_debug_level == cdbOFF) { + SetAPDULogging(false); + } else { + SetAPDULogging(true); + } } // default save path @@ -368,62 +374,97 @@ void preferences_load_callback(json_t *root) { // Preference Processing Functions // 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, prefShowOff, prefShowUnknown} prefShowOpt_t; -static const char *prefShowMsg(prefShowOpt_t Opt) { - switch (Opt) { +static const char *pref_show_status_msg(prefShowOpt_t opt) { + switch (opt) { case prefShowOLD: - return "( " _YELLOW_("old") " )"; + return "( " _CYAN_("old") " )"; case prefShowNEW: return "( " _GREEN_("new") " )"; case prefShowNone: + case prefShowOff: + case prefShowUnknown: + default: + return ""; + + } +} + +static const char *pref_show_value(prefShowOpt_t opt, const char* msg) { + + static char s[128] = {0}; + switch (opt) { + case prefShowOLD: + sprintf(s, _CYAN_("%s"), msg); + return s; + + case prefShowNEW: + sprintf(s, _GREEN_("%s"), msg); + return s; + case prefShowNone: + if ((strncmp(msg, "off", 3) == 0) || (strncmp(msg, "normal", 6) ==0)) { + sprintf(s, _WHITE_("%s"), msg); + } else { + sprintf(s, _GREEN_("%s"), msg); + } + return s; + + case prefShowOff: + sprintf(s, _WHITE_("%s"), msg); + return s; + + case prefShowUnknown: + sprintf(s, _RED_("%s"), msg); + return s; + + default: return ""; } - return ""; } + static void showEmojiState(prefShowOpt_t opt) { switch (g_session.emoji_mode) { case EMO_ALIAS: - PrintAndLogEx(INFO, " %s emoji................... "_GREEN_("alias"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s emoji................... %s", pref_show_status_msg(opt), pref_show_value(opt, "alias")); break; case EMO_EMOJI: - PrintAndLogEx(INFO, " %s emoji................... "_GREEN_("emoji"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s emoji................... %s", pref_show_status_msg(opt), pref_show_value(opt, "emoji")); break; case EMO_ALTTEXT: - PrintAndLogEx(INFO, " %s emoji................... "_GREEN_("alttext"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s emoji................... %s", pref_show_status_msg(opt), pref_show_value(opt, "alttext")); break; case EMO_NONE: - PrintAndLogEx(INFO, " %s emoji................... "_GREEN_("none"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s emoji................... %s", pref_show_status_msg(opt), pref_show_value(opt, "none")); break; default: - PrintAndLogEx(INFO, " %s emoji................... "_RED_("unknown"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s emoji................... %s", pref_show_status_msg(opt), pref_show_value(prefShowUnknown, "unknown")); } } static void showColorState(prefShowOpt_t opt) { - - if (g_session.supports_colors) - PrintAndLogEx(INFO, " %s color................... "_GREEN_("ansi"), prefShowMsg(opt)); - else - PrintAndLogEx(INFO, " %s color................... "_WHITE_("off"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s color................... %s " + , pref_show_status_msg(opt) + , (g_session.supports_colors) ? pref_show_value(opt, "ansi") : pref_show_value(opt, "off") + ); } static void showClientDebugState(prefShowOpt_t opt) { switch (g_session.client_debug_level) { case cdbOFF: - PrintAndLogEx(INFO, " %s client debug............ "_WHITE_("off"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s client debug............ %s", pref_show_status_msg(opt), pref_show_value(opt, "off")); break; case cdbSIMPLE: - PrintAndLogEx(INFO, " %s client debug............ "_GREEN_("simple"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s client debug............ %s", pref_show_status_msg(opt), pref_show_value(opt, "simple")); break; case cdbFULL: - PrintAndLogEx(INFO, " %s client debug............ "_GREEN_("full"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s client debug............ %s", pref_show_status_msg(opt), pref_show_value(opt,"full")); break; default: - PrintAndLogEx(INFO, " %s client debug............ "_RED_("unknown"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s client debug............ %s", pref_show_status_msg(opt), pref_show_value(prefShowUnknown, "unknown")); } } /* @@ -471,12 +512,12 @@ static void showSavePathState(savePaths_t path_index, prefShowOpt_t opt) { if (path_index < spItemCount) { if ((g_session.defaultPaths[path_index] == NULL) || (strcmp(g_session.defaultPaths[path_index], "") == 0)) { PrintAndLogEx(INFO, " %s %s "_WHITE_("not set"), - prefShowMsg(opt), + pref_show_status_msg(opt), s ); } else { PrintAndLogEx(INFO, " %s %s "_GREEN_("%s"), - prefShowMsg(opt), + pref_show_status_msg(opt), s, g_session.defaultPaths[path_index] ); @@ -503,39 +544,41 @@ static void showOverlayPosState(void) { } static void showHintsState(prefShowOpt_t opt) { - if (g_session.show_hints) - PrintAndLogEx(INFO, " %s hints................... "_GREEN_("on"), prefShowMsg(opt)); - else - PrintAndLogEx(INFO, " %s hints................... "_WHITE_("off"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s hints................... %s" + , pref_show_status_msg(opt) + , (g_session.show_hints) ? pref_show_value(opt,"on") : pref_show_value(opt,"off") + ); } static void showPlotSliderState(prefShowOpt_t opt) { - if (g_session.overlay_sliders) - PrintAndLogEx(INFO, " %s show plot sliders....... "_GREEN_("on"), prefShowMsg(opt)); - else - PrintAndLogEx(INFO, " %s show plot sliders....... "_WHITE_("off"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s show plot sliders....... %s" + , pref_show_status_msg(opt) + , (g_session.overlay_sliders) ? pref_show_value(opt,"on") : pref_show_value(opt,"off") + ); } static void showBarModeState(prefShowOpt_t opt) { switch (g_session.bar_mode) { case STYLE_BAR: - PrintAndLogEx(INFO, " %s barmode................. "_GREEN_("bar"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s barmode................. %s", pref_show_status_msg(opt), pref_show_value(opt,"bar")); break; case STYLE_MIXED: - PrintAndLogEx(INFO, " %s barmode................. "_GREEN_("mixed"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s barmode................. %s", pref_show_status_msg(opt), pref_show_value(opt,"mixed")); break; case STYLE_VALUE: - PrintAndLogEx(INFO, " %s barmode................. "_GREEN_("value"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s barmode................. %s", pref_show_status_msg(opt), pref_show_value(opt,"value")); break; default: - PrintAndLogEx(INFO, " %s barmode................ "_RED_("unknown"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s barmode................. %s", pref_show_status_msg(opt), pref_show_value(prefShowUnknown,"unknown")); } } static void showOutputState(prefShowOpt_t opt) { - PrintAndLogEx(INFO, " %s output.................. %s", prefShowMsg(opt), - g_session.dense_output ? _GREEN_("dense") : _WHITE_("normal")); + PrintAndLogEx(INFO, " %s output.................. %s" + , pref_show_status_msg(opt) + , (g_session.dense_output) ? pref_show_value(opt,"dense") : pref_show_value(opt,"normal") + ); } static void showClientExeDelayState(void) { @@ -674,9 +717,11 @@ static int setCmdDebug(const char *Cmd) { if (use_off) { new_value = cdbOFF; } + if (use_simple) { new_value = cdbSIMPLE; } + if (use_full) { new_value = cdbFULL; } @@ -685,6 +730,13 @@ static int setCmdDebug(const char *Cmd) { showClientDebugState(prefShowOLD); g_session.client_debug_level = new_value; g_debugMode = new_value; + + if (new_value == cdbOFF) { + SetAPDULogging(false); + } else { + SetAPDULogging(true); + } + showClientDebugState(prefShowNEW); preferences_save(); } else {