add option --json to pref show

This commit is contained in:
Philippe Teuwen 2024-10-14 21:30:41 +02:00
parent 4dea606468
commit 0961b01950
5 changed files with 31 additions and 0 deletions

View file

@ -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... 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] ## [unreleased][unreleased]
- Changed `pref show` - add option to dump as JSON (@doegox)
- Changed `mf_backdoor_dump.py`- use faster ecfill/eview (@doegox) - Changed `mf_backdoor_dump.py`- use faster ecfill/eview (@doegox)
- Changed `hf mf ecfill` - wait for execution and return status (@doegox) - Changed `hf mf ecfill` - wait for execution and return status (@doegox)
- Changed `hf 14a reader` - added option to wait for a card (@doegox) - Changed `hf 14a reader` - added option to wait for a card (@doegox)

View file

@ -818,6 +818,17 @@ int saveFileJSONrootEx(const char *preferredName, const void *root, size_t flags
return PM3_EFILE; return PM3_EFILE;
} }
char *sprintJSON(JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *)) {
json_t *root = json_object();
if (prepareJSON(root, ftype, data, datalen, verbose, callback) != PM3_SUCCESS) {
return NULL;
}
char *s = json_dumps(root, JSON_INDENT(2));
json_decref(root);
return s;
}
// wave file of trace, // wave file of trace,
int saveFileWAVE(const char *preferredName, const int *data, size_t datalen) { int saveFileWAVE(const char *preferredName, const int *data, size_t datalen) {

View file

@ -142,6 +142,7 @@ int saveFileJSONex(const char *preferredName, JSONFileType ftype, uint8_t *data,
int saveFileJSONroot(const char *preferredName, void *root, size_t flags, bool verbose); int saveFileJSONroot(const char *preferredName, void *root, size_t flags, bool verbose);
int saveFileJSONrootEx(const char *preferredName, const void *root, size_t flags, bool verbose, bool overwrite, savePaths_t e_save_path); int saveFileJSONrootEx(const char *preferredName, const void *root, size_t flags, bool verbose, bool overwrite, savePaths_t e_save_path);
int prepareJSON(json_t *root, JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *)); int prepareJSON(json_t *root, JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *));
char *sprintJSON(JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *));
/** STUB /** STUB
* @brief Utility function to save WAVE data to a file. This method takes a preferred name, but if that * @brief Utility function to save WAVE data to a file. This method takes a preferred name, but if that
* file already exists, it tries with another name until it finds something suitable. * file already exists, it tries with another name until it finds something suitable.

View file

@ -168,6 +168,16 @@ int preferences_save(void) {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
// Dump all settings from memory (struct) to console in JSON
int preferences_dump(void) {
uint8_t dummyData = 0x00;
size_t dummyDL = 0x01;
char *s = sprintJSON(jsfCustom, &dummyData, dummyDL, true, &preferences_save_callback);
PrintAndLogEx(NORMAL, "%s", s);
free(s);
return PM3_SUCCESS;
}
void preferences_save_callback(json_t *root) { void preferences_save_callback(json_t *root) {
JsonSaveStr(root, "FileType", "settings"); JsonSaveStr(root, "FileType", "settings");
@ -1393,11 +1403,18 @@ static int CmdPrefShow(const char *Cmd) {
); );
void *argtable[] = { void *argtable[] = {
arg_param_begin, arg_param_begin,
arg_lit0("j", "json", "Dump prefs as JSON"),
arg_param_end arg_param_end
}; };
CLIExecWithReturn(ctx, Cmd, argtable, true); CLIExecWithReturn(ctx, Cmd, argtable, true);
bool json_dump = arg_get_lit(ctx, 1);
CLIParserFree(ctx); CLIParserFree(ctx);
if (json_dump) {
preferences_dump();
return PM3_SUCCESS;
}
if (g_session.preferences_loaded) { if (g_session.preferences_loaded) {
char *fn = prefGetFilename(); char *fn = prefGetFilename();
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");

View file

@ -27,6 +27,7 @@
int CmdPreferences(const char *Cmd); int CmdPreferences(const char *Cmd);
int preferences_load(void); int preferences_load(void);
int preferences_save(void); int preferences_save(void);
int preferences_dump(void);
void preferences_save_callback(json_t *root); void preferences_save_callback(json_t *root);
void preferences_load_callback(json_t *root); void preferences_load_callback(json_t *root);