mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
commit
b643c70f0d
5 changed files with 143 additions and 125 deletions
|
@ -26,6 +26,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "proxgui.h"
|
#include "proxgui.h"
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
#include "ui.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "util_darwin.h"
|
#include "util_darwin.h"
|
||||||
|
@ -168,6 +169,10 @@ void ProxWidget::vchange_dthr_down(int v) {
|
||||||
}
|
}
|
||||||
ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
|
ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
|
||||||
this->master = master;
|
this->master = master;
|
||||||
|
// Set the initail postion and size from settings
|
||||||
|
if (session.settings_loaded)
|
||||||
|
setGeometry (session.window_plot_xpos,session.window_plot_ypos,session.window_plot_wsize,session.window_plot_hsize);
|
||||||
|
else
|
||||||
resize(800, 400);
|
resize(800, 400);
|
||||||
|
|
||||||
// Setup the controller widget
|
// Setup the controller widget
|
||||||
|
|
|
@ -29,6 +29,10 @@
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
|
// Used to enable/disable use of settings json file
|
||||||
|
// #define USE_SETTING_FILE
|
||||||
|
|
||||||
|
|
||||||
static void showBanner(void) {
|
static void showBanner(void) {
|
||||||
g_printAndLog = PRINTANDLOG_PRINT;
|
g_printAndLog = PRINTANDLOG_PRINT;
|
||||||
|
|
||||||
|
@ -489,12 +493,15 @@ finish2:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_SETTING_FILE
|
||||||
|
|
||||||
// Check if windows AnsiColor Support is enabled in the registery
|
// Check if windows AnsiColor Support is enabled in the registery
|
||||||
// [HKEY_CURRENT_USER\Console]
|
// [HKEY_CURRENT_USER\Console]
|
||||||
// "VirtualTerminalLevel"=dword:00000001
|
// "VirtualTerminalLevel"=dword:00000001
|
||||||
// 2nd Key needs to be enabled... This key takes the console out of legacy mode.
|
// 2nd Key needs to be enabled... This key takes the console out of legacy mode.
|
||||||
// [HKEY_CURRENT_USER\Console]
|
// [HKEY_CURRENT_USER\Console]
|
||||||
// "ForceV2"=dword:00000001
|
// "ForceV2"=dword:00000001
|
||||||
|
|
||||||
static bool DetectWindowsAnsiSupport(void) {
|
static bool DetectWindowsAnsiSupport(void) {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
@ -543,6 +550,8 @@ static bool DetectWindowsAnsiSupport(void) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
srand(time(0));
|
srand(time(0));
|
||||||
|
|
||||||
|
@ -582,11 +591,16 @@ int main(int argc, char *argv[]) {
|
||||||
set_my_executable_path();
|
set_my_executable_path();
|
||||||
set_my_user_directory();
|
set_my_user_directory();
|
||||||
|
|
||||||
// Settings Load and Test
|
#ifdef USE_SETTING_FILE
|
||||||
// settings_load ();
|
// Load Settings and assign
|
||||||
|
// This will allow the command line to override the settings.json values
|
||||||
|
settings_load ();
|
||||||
|
|
||||||
|
// quick patch for debug level
|
||||||
|
g_debugMode = session.client_debug_level;
|
||||||
// settings_save ();
|
// settings_save ();
|
||||||
// printf ("Ver : %s\n",mySettings.version);
|
|
||||||
// End Settings
|
// End Settings
|
||||||
|
#endif
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
|
|
||||||
|
@ -766,8 +780,11 @@ int main(int argc, char *argv[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_SETTING_FILE
|
||||||
|
// comment next 2 lines to use session values set from settings_load
|
||||||
session.supports_colors = DetectWindowsAnsiSupport();
|
session.supports_colors = DetectWindowsAnsiSupport();
|
||||||
session.emoji_mode = ALTTEXT;
|
session.emoji_mode = ALTTEXT;
|
||||||
|
#endif
|
||||||
|
|
||||||
session.stdinOnTTY = isatty(STDIN_FILENO);
|
session.stdinOnTTY = isatty(STDIN_FILENO);
|
||||||
session.stdoutOnTTY = isatty(STDOUT_FILENO);
|
session.stdoutOnTTY = isatty(STDOUT_FILENO);
|
||||||
|
@ -837,6 +854,14 @@ int main(int argc, char *argv[]) {
|
||||||
if (!script_cmds_file && !script_cmd && session.stdinOnTTY && session.stdoutOnTTY && !flash_mode)
|
if (!script_cmds_file && !script_cmd && session.stdinOnTTY && session.stdoutOnTTY && !flash_mode)
|
||||||
showBanner();
|
showBanner();
|
||||||
|
|
||||||
|
#ifdef USE_SETTING_FILE
|
||||||
|
// Save settings if not load from settings json file.
|
||||||
|
// Doing this here will ensure other checks and updates are saved to over rule default
|
||||||
|
// e.g. Linux color use check
|
||||||
|
if (!session.settings_loaded)
|
||||||
|
settings_save ();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_GUI
|
#ifdef HAVE_GUI
|
||||||
|
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
|
|
|
@ -39,46 +39,46 @@
|
||||||
// Settings Functions
|
// Settings 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 settings_load_callback to load your setting into the stucture
|
||||||
|
// Update the settings_save_callback to enusre your setting gets saved when needed.
|
||||||
|
// use the setting as needed : session.<setting name>
|
||||||
|
// Can use (session.settings_loaded) to check if json settings file was used
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
#include "emv/emvjson.h"
|
#include "emv/emvjson.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
// Load all settings into memory (struct)
|
// Load all settings into memory (struct)
|
||||||
int settings_load (void) {
|
int settings_load (void) {
|
||||||
|
|
||||||
|
// Set all defaults
|
||||||
|
session.client_debug_level = OFF;
|
||||||
|
session.window_plot_xpos = 10;
|
||||||
|
session.window_plot_ypos = 30;
|
||||||
|
session.window_plot_hsize = 400;
|
||||||
|
session.window_plot_wsize = 800;
|
||||||
|
session.emoji_mode = ALIAS;
|
||||||
|
session.show_hints = false;
|
||||||
|
session.supports_colors = false;
|
||||||
|
|
||||||
// loadFileJson wants these, so pass in place holder values, though not used
|
// loadFileJson wants these, so pass in place holder values, though not used
|
||||||
// in settings load;
|
// in settings load;
|
||||||
uint8_t dummyData = 0x00;
|
uint8_t dummyData = 0x00;
|
||||||
size_t dummyDL = 0x00;
|
size_t dummyDL = 0x00;
|
||||||
|
|
||||||
// clear all settings
|
|
||||||
memset (&mySettings,0x00,sizeof(mySettings));
|
|
||||||
|
|
||||||
if (loadFileJSON(settingsFilename, &dummyData, sizeof(dummyData), &dummyDL) == PM3_SUCCESS) {
|
if (loadFileJSON(settingsFilename, &dummyData, sizeof(dummyData), &dummyDL) == PM3_SUCCESS) {
|
||||||
printf ("==> Settings Loaded\n");
|
session.settings_loaded = true;
|
||||||
mySettings.loaded = true;
|
|
||||||
}
|
}
|
||||||
|
// Note, if session.settings_loaded == false then the settings_save
|
||||||
|
// will be called in main () to save settings as set in defaults and main() checks.
|
||||||
|
|
||||||
|
|
||||||
// Test results
|
|
||||||
/*
|
|
||||||
bool os_windows_usecolor;
|
|
||||||
bool os_windows_useansicolor;
|
|
||||||
int window_xpos;
|
|
||||||
int window_ypos;
|
|
||||||
int window_hsize;
|
|
||||||
int window_wsize;
|
|
||||||
bool use_emojis
|
|
||||||
bool use_hints
|
|
||||||
*/
|
|
||||||
printf (" Settings Version : [%s]\n", mySettings.version);
|
|
||||||
printf (" os_windows_usecolor (bool) : [%d]\n", mySettings.os_windows_usecolor);
|
|
||||||
printf (" os_windows_useAnsicolor (bool) : [%d]\n", mySettings.os_windows_useansicolor);
|
|
||||||
printf (" window_xpos (int) : [%d]\n", mySettings.window_xpos);
|
|
||||||
printf (" window_ypos (int) : [%d]\n", mySettings.window_ypos);
|
|
||||||
printf (" window_hsize (int) : [%d]\n", mySettings.window_hsize);
|
|
||||||
printf (" window_wsize (int) : [%d]\n", mySettings.window_wsize);
|
|
||||||
printf (" use emoji (bool) : [%d]\n", mySettings.use_emojis);
|
|
||||||
printf (" use hints (bool) : [%d]\n", mySettings.use_hints);
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,81 +114,78 @@ int settings_save(void) {
|
||||||
|
|
||||||
void settings_save_callback (json_t *root) {
|
void settings_save_callback (json_t *root) {
|
||||||
|
|
||||||
printf ("==> Save Settings\n");
|
|
||||||
//JsonSaveStr(root, "FileType", "settings");
|
|
||||||
//JsonSaveStr (root,"Test1.Test2","test settings");
|
|
||||||
/*
|
|
||||||
"version": "1.0 Nov 2019",
|
|
||||||
"os.windows.usecolor": true,
|
|
||||||
"os.windows.useAnsiColor": true,
|
|
||||||
"window.xpos": 10,
|
|
||||||
"window.ypos": 10,
|
|
||||||
"window.hsize": 300,
|
|
||||||
"window.wsize": 600
|
|
||||||
*/
|
|
||||||
JsonSaveStr (root,"FileType","settings");
|
JsonSaveStr (root,"FileType","settings");
|
||||||
JsonSaveStr (root,"version","1.0 Nov 2019");//mySettings.version);
|
|
||||||
JsonSaveBoolean (root,"os.windows.useColor", mySettings.os_windows_usecolor);
|
// Log level, convert to text
|
||||||
JsonSaveBoolean (root,"os.windows.useAnsiColor", mySettings.os_windows_useansicolor);
|
switch (session.client_debug_level) {
|
||||||
JsonSaveInt (root,"window.xpos", mySettings.window_xpos);
|
case OFF: JsonSaveStr (root,"client.debug.level","off"); break;
|
||||||
JsonSaveInt (root,"window.ypos", mySettings.window_ypos);
|
case SIMPLE: JsonSaveStr (root,"client.debug.level","simple"); break;
|
||||||
JsonSaveInt (root,"window.hsize", mySettings.window_hsize);
|
case FULL: JsonSaveStr (root,"client.debug.level","full"); break;
|
||||||
JsonSaveInt (root,"window.wsize", mySettings.window_wsize);
|
default:
|
||||||
JsonSaveBoolean (root,"client.useEmojis", mySettings.use_emojis);
|
JsonSaveStr (root,"logging.level","NORMAL");
|
||||||
JsonSaveBoolean (root,"client.useHints", mySettings.use_hints);
|
}
|
||||||
|
|
||||||
|
// Plot window
|
||||||
|
JsonSaveInt (root,"window.plot.xpos",session.window_plot_xpos);
|
||||||
|
JsonSaveInt (root,"window.plot.ypos",session.window_plot_ypos);
|
||||||
|
JsonSaveInt (root,"window.plot.hsize",session.window_plot_hsize);
|
||||||
|
JsonSaveInt (root,"window.plot.wsize",session.window_plot_wsize);
|
||||||
|
|
||||||
|
// Emoji
|
||||||
|
switch (session.emoji_mode) {
|
||||||
|
case ALIAS: JsonSaveStr (root,"show.emoji","alias"); break;
|
||||||
|
case EMOJI: JsonSaveStr (root,"show.emoji","emoji"); break;
|
||||||
|
case ALTTEXT: JsonSaveStr (root,"show.emoji","alttext"); break;
|
||||||
|
case ERASE: JsonSaveStr (root,"show.emoji","erase"); break;
|
||||||
|
default:
|
||||||
|
JsonSaveStr (root,"show.emoji","ALIAS");
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonSaveBoolean (root,"show.hints",session.show_hints);
|
||||||
|
|
||||||
|
JsonSaveBoolean (root,"os.supports.colors",session.supports_colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
void settings_load_callback (json_t *root) {
|
void settings_load_callback (json_t *root) {
|
||||||
|
|
||||||
json_error_t up_error = {0};
|
json_error_t up_error = {0};
|
||||||
int b1;
|
bool b1;
|
||||||
int i1;
|
int i1;
|
||||||
const char *s1;
|
const char *s1;
|
||||||
|
char tempStr [500]; // to use str_lower() since json unpack uses const char *
|
||||||
|
|
||||||
if (json_unpack_ex(root, &up_error , 0, "{s:s}","version", &s1) == 0)
|
// Logging Level
|
||||||
strncpy (mySettings.version,s1,sizeof (mySettings.version) - 1);
|
if (json_unpack_ex(root,&up_error, 0, "{s:s}","client.debug.level",&s1) == 0) {
|
||||||
else
|
strncpy (tempStr,s1,sizeof(tempStr)-1);
|
||||||
strncpy (mySettings.version,"unknown",sizeof (mySettings.version) - 1);
|
str_lower (tempStr);
|
||||||
|
if (strncmp (tempStr,"off",3) == 0) session.client_debug_level = OFF;
|
||||||
|
if (strncmp (tempStr,"simple",6) == 0) session.client_debug_level = SIMPLE;
|
||||||
|
if (strncmp (tempStr,"full",4) == 0) session.client_debug_level = FULL;
|
||||||
|
}
|
||||||
|
|
||||||
// os.windows...
|
// window plot
|
||||||
if (json_unpack_ex(root,&up_error, 0, "{s:b}","os.windows.useColor",&b1) == 0)
|
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.plot.xpos",&i1) == 0)
|
||||||
mySettings.os_windows_usecolor = b1;
|
session.window_plot_xpos = i1;
|
||||||
else // default
|
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.plot.ypos",&i1) == 0)
|
||||||
mySettings.os_windows_useansicolor = false;
|
session.window_plot_ypos = i1;
|
||||||
|
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.plot.hsize",&i1) == 0)
|
||||||
|
session.window_plot_hsize = i1;
|
||||||
|
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.plot.wsize",&i1) == 0)
|
||||||
|
session.window_plot_wsize = i1;
|
||||||
|
|
||||||
if (json_unpack_ex(root,&up_error, 0, "{s:b}","os.windows.useAnsiColor",&b1) == 0)
|
// show options
|
||||||
mySettings.os_windows_useansicolor = b1;
|
if (json_unpack_ex(root,&up_error, 0, "{s:s}","show.emoji",&s1) == 0) {
|
||||||
else // default
|
strncpy (tempStr,s1,sizeof(tempStr)-1);
|
||||||
mySettings.os_windows_useansicolor = false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
// window...
|
if (json_unpack_ex(root,&up_error, 0, "{s:b}","show.hints",&b1) == 0)
|
||||||
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.xpos",&i1) == 0)
|
session.show_hints = b1;
|
||||||
mySettings.window_xpos = i1;
|
|
||||||
else // default
|
|
||||||
mySettings.window_xpos = 0;
|
|
||||||
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.ypos",&i1) == 0)
|
|
||||||
mySettings.window_ypos = i1;
|
|
||||||
else // default
|
|
||||||
mySettings.window_ypos = 0;
|
|
||||||
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.hsize",&i1) == 0)
|
|
||||||
mySettings.window_hsize = i1;
|
|
||||||
else // default
|
|
||||||
mySettings.window_hsize = 0;
|
|
||||||
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.wsize",&i1) == 0)
|
|
||||||
mySettings.window_wsize = i1;
|
|
||||||
else // default
|
|
||||||
mySettings.window_wsize = 0;
|
|
||||||
|
|
||||||
// Use EMOJIS
|
if (json_unpack_ex(root,&up_error, 0, "{s:b}","os.supports.colors",&b1) == 0)
|
||||||
if (json_unpack_ex(root,&up_error, 0, "{s:b}","client.useEmojis",&b1) == 0)
|
session.supports_colors = b1;
|
||||||
mySettings.use_emojis = b1;
|
|
||||||
else // default
|
|
||||||
mySettings.use_emojis = false;
|
|
||||||
|
|
||||||
// Use Hints
|
|
||||||
if (json_unpack_ex(root,&up_error, 0, "{s:b}","client.useHints",&b1) == 0)
|
|
||||||
mySettings.use_hints = b1;
|
|
||||||
else // default
|
|
||||||
mySettings.use_hints = false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,29 +8,13 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Settings Functions
|
// Settings Functions
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
#ifndef settings_h
|
#ifndef SETTINGS_H_
|
||||||
#define settings_h
|
#define SETTINGS_H_
|
||||||
|
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
|
|
||||||
#define settingsFilename "settings.json"
|
#define settingsFilename "settings.json"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool loaded;
|
|
||||||
char version[20];
|
|
||||||
bool os_windows_usecolor;
|
|
||||||
bool os_windows_useansicolor;
|
|
||||||
int window_xpos;
|
|
||||||
int window_ypos;
|
|
||||||
int window_hsize;
|
|
||||||
int window_wsize;
|
|
||||||
bool use_emojis;
|
|
||||||
bool use_hints;
|
|
||||||
} settings_t;
|
|
||||||
|
|
||||||
// Settings struct so as to be available to other modules by including settings.h
|
|
||||||
settings_t mySettings;
|
|
||||||
|
|
||||||
int settings_load (void);
|
int settings_load (void);
|
||||||
int settings_save (void);
|
int settings_save (void);
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,10 @@
|
||||||
|
|
||||||
typedef enum logLevel {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG, INPLACE, HINT} logLevel_t;
|
typedef enum logLevel {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG, INPLACE, HINT} logLevel_t;
|
||||||
typedef enum emojiMode {ALIAS, EMOJI, ALTTEXT, ERASE} emojiMode_t;
|
typedef enum emojiMode {ALIAS, EMOJI, ALTTEXT, ERASE} emojiMode_t;
|
||||||
|
typedef enum clientdebugLevel {OFF,SIMPLE,FULL} clientdebugLevel_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
bool settings_loaded;
|
||||||
bool stdinOnTTY;
|
bool stdinOnTTY;
|
||||||
bool stdoutOnTTY;
|
bool stdoutOnTTY;
|
||||||
bool supports_colors;
|
bool supports_colors;
|
||||||
|
@ -28,6 +30,11 @@ typedef struct {
|
||||||
bool pm3_present;
|
bool pm3_present;
|
||||||
bool help_dump_mode;
|
bool help_dump_mode;
|
||||||
bool show_hints;
|
bool show_hints;
|
||||||
|
int window_plot_xpos;
|
||||||
|
int window_plot_ypos;
|
||||||
|
int window_plot_hsize;
|
||||||
|
int window_plot_wsize;
|
||||||
|
clientdebugLevel_t client_debug_level;
|
||||||
} session_arg_t;
|
} session_arg_t;
|
||||||
|
|
||||||
extern session_arg_t session;
|
extern session_arg_t session;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue