rename global session

This commit is contained in:
Philippe Teuwen 2021-08-21 20:31:05 +02:00
parent 6a2f2b3979
commit dd3b63ae32
20 changed files with 258 additions and 258 deletions

View file

@ -208,7 +208,7 @@ int CmdHFTune(const char *Cmd) {
return PM3_EINVARG; return PM3_EINVARG;
} }
barMode_t style = session.bar_mode; barMode_t style = g_session.bar_mode;
if (is_bar) if (is_bar)
style = STYLE_BAR; style = STYLE_BAR;
if (is_mix) if (is_mix)

View file

@ -189,7 +189,7 @@ static int CmdHF14AList(const char *Cmd) {
} }
int hf14a_getconfig(hf14a_config *config) { int hf14a_getconfig(hf14a_config *config) {
if (!session.pm3_present) return PM3_ENOTTY; if (!g_session.pm3_present) return PM3_ENOTTY;
if (config == NULL) if (config == NULL)
return PM3_EINVARG; return PM3_EINVARG;
@ -207,7 +207,7 @@ int hf14a_getconfig(hf14a_config *config) {
} }
int hf14a_setconfig(hf14a_config *config, bool verbose) { int hf14a_setconfig(hf14a_config *config, bool verbose) {
if (!session.pm3_present) return PM3_ENOTTY; if (!g_session.pm3_present) return PM3_ENOTTY;
clearCommandBuffer(); clearCommandBuffer();
if (config != NULL) { if (config != NULL) {
@ -247,7 +247,7 @@ static int hf_14a_config_example(void) {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int CmdHf14AConfig(const char *Cmd) { static int CmdHf14AConfig(const char *Cmd) {
if (!session.pm3_present) return PM3_ENOTTY; if (!g_session.pm3_present) return PM3_ENOTTY;
CLIParserContext *ctx; CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 14a config", CLIParserInit(&ctx, "hf 14a config",

View file

@ -843,16 +843,16 @@ static int CmdConnect(const char *Cmd) {
memcpy(port, g_conn.serial_port_name, sizeof(port)); memcpy(port, g_conn.serial_port_name, sizeof(port));
} }
if (session.pm3_present) { if (g_session.pm3_present) {
CloseProxmark(session.current_device); CloseProxmark(g_session.current_device);
} }
// 10 second timeout // 10 second timeout
OpenProxmark(&session.current_device, port, false, 10, false, baudrate); OpenProxmark(&g_session.current_device, port, false, 10, false, baudrate);
if (session.pm3_present && (TestProxmark(session.current_device) != PM3_SUCCESS)) { if (g_session.pm3_present && (TestProxmark(g_session.current_device) != PM3_SUCCESS)) {
PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark3\n"); PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark3\n");
CloseProxmark(session.current_device); CloseProxmark(g_session.current_device);
return PM3_ENOTTY; return PM3_ENOTTY;
} }
return PM3_SUCCESS; return PM3_SUCCESS;

View file

@ -138,7 +138,7 @@ static int CmdLFTune(const char *Cmd) {
return PM3_EINVARG; return PM3_EINVARG;
} }
barMode_t style = session.bar_mode; barMode_t style = g_session.bar_mode;
if (is_bar) if (is_bar)
style = STYLE_BAR; style = STYLE_BAR;
if (is_mix) if (is_mix)
@ -252,7 +252,7 @@ int CmdLFCommandRead(const char *Cmd) {
bool cm = arg_get_lit(ctx, 8); bool cm = arg_get_lit(ctx, 8);
CLIParserFree(ctx); CLIParserFree(ctx);
if (session.pm3_present == false) if (g_session.pm3_present == false)
return PM3_ENOTTY; return PM3_ENOTTY;
#define PAYLOAD_HEADER_SIZE (12 + (3 * LF_CMDREAD_MAX_EXTRA_SYMBOLS)) #define PAYLOAD_HEADER_SIZE (12 + (3 * LF_CMDREAD_MAX_EXTRA_SYMBOLS))
@ -475,7 +475,7 @@ int lf_config_savereset(sample_config *config) {
} }
int lf_getconfig(sample_config *config) { int lf_getconfig(sample_config *config) {
if (!session.pm3_present) return PM3_ENOTTY; if (!g_session.pm3_present) return PM3_ENOTTY;
if (config == NULL) if (config == NULL)
return PM3_EINVARG; return PM3_EINVARG;
@ -493,7 +493,7 @@ int lf_getconfig(sample_config *config) {
} }
int lf_config(sample_config *config) { int lf_config(sample_config *config) {
if (!session.pm3_present) return PM3_ENOTTY; if (!g_session.pm3_present) return PM3_ENOTTY;
clearCommandBuffer(); clearCommandBuffer();
if (config != NULL) if (config != NULL)
@ -548,7 +548,7 @@ int CmdLFConfig(const char *Cmd) {
int16_t trigg = arg_get_int_def(ctx, 10, -1); int16_t trigg = arg_get_int_def(ctx, 10, -1);
CLIParserFree(ctx); CLIParserFree(ctx);
if (session.pm3_present == false) if (g_session.pm3_present == false)
return PM3_ENOTTY; return PM3_ENOTTY;
// if called with no params, just print the device config // if called with no params, just print the device config
@ -629,7 +629,7 @@ int CmdLFConfig(const char *Cmd) {
} }
int lf_read(bool verbose, uint32_t samples) { int lf_read(bool verbose, uint32_t samples) {
if (!session.pm3_present) return PM3_ENOTTY; if (!g_session.pm3_present) return PM3_ENOTTY;
struct p { struct p {
uint32_t samples : 31; uint32_t samples : 31;
@ -681,7 +681,7 @@ int CmdLFRead(const char *Cmd) {
bool cm = arg_get_lit(ctx, 3); bool cm = arg_get_lit(ctx, 3);
CLIParserFree(ctx); CLIParserFree(ctx);
if (session.pm3_present == false) if (g_session.pm3_present == false)
return PM3_ENOTTY; return PM3_ENOTTY;
if (cm) { if (cm) {
@ -695,7 +695,7 @@ int CmdLFRead(const char *Cmd) {
} }
int lf_sniff(bool verbose, uint32_t samples) { int lf_sniff(bool verbose, uint32_t samples) {
if (!session.pm3_present) return PM3_ENOTTY; if (!g_session.pm3_present) return PM3_ENOTTY;
struct p { struct p {
uint32_t samples : 31; uint32_t samples : 31;
@ -750,7 +750,7 @@ int CmdLFSniff(const char *Cmd) {
bool cm = arg_get_lit(ctx, 3); bool cm = arg_get_lit(ctx, 3);
CLIParserFree(ctx); CLIParserFree(ctx);
if (session.pm3_present == false) if (g_session.pm3_present == false)
return PM3_ENOTTY; return PM3_ENOTTY;
if (cm) { if (cm) {
@ -842,7 +842,7 @@ int CmdLFSim(const char *Cmd) {
uint16_t gap = arg_get_u32_def(ctx, 1, 0); uint16_t gap = arg_get_u32_def(ctx, 1, 0);
CLIParserFree(ctx); CLIParserFree(ctx);
if (session.pm3_present == false) { if (g_session.pm3_present == false) {
PrintAndLogEx(DEBUG, "DEBUG: no proxmark present"); PrintAndLogEx(DEBUG, "DEBUG: no proxmark present");
return PM3_ENOTTY; return PM3_ENOTTY;
} }
@ -1397,7 +1397,7 @@ int CmdLFfind(const char *Cmd) {
bool search_unk = arg_get_lit(ctx, 3); bool search_unk = arg_get_lit(ctx, 3);
CLIParserFree(ctx); CLIParserFree(ctx);
int found = 0; int found = 0;
bool is_online = (session.pm3_present && (use_gb == false)); bool is_online = (g_session.pm3_present && (use_gb == false));
if (is_online) if (is_online)
lf_read(false, 30000); lf_read(false, 30000);

View file

@ -520,7 +520,7 @@ static int CmdAWIDBrute(const char *Cmd) {
// main loop // main loop
for (;;) { for (;;) {
if (!session.pm3_present) { if (!g_session.pm3_present) {
PrintAndLogEx(WARNING, "Device offline\n"); PrintAndLogEx(WARNING, "Device offline\n");
return PM3_ENODATA; return PM3_ENODATA;
} }

View file

@ -1390,7 +1390,7 @@ int CmdEM4x05Chk(const char *Cmd) {
for (uint32_t c = 0; c < keycount; ++c) { for (uint32_t c = 0; c < keycount; ++c) {
if (!session.pm3_present) { if (!g_session.pm3_present) {
PrintAndLogEx(WARNING, "device offline\n"); PrintAndLogEx(WARNING, "device offline\n");
free(keyBlock); free(keyBlock);
return PM3_ENODATA; return PM3_ENODATA;
@ -1569,7 +1569,7 @@ int CmdEM4x05Unlock(const char *Cmd) {
return PM3_EINVARG; return PM3_EINVARG;
} }
if (session.pm3_present == false) { if (g_session.pm3_present == false) {
PrintAndLogEx(WARNING, "device offline\n"); PrintAndLogEx(WARNING, "device offline\n");
return PM3_ENODATA; return PM3_ENODATA;
} }

View file

@ -556,7 +556,7 @@ static int CmdHIDBrute(const char *Cmd) {
fin_hi = fin_low = false; fin_hi = fin_low = false;
do { do {
if (!session.pm3_present) { if (!g_session.pm3_present) {
PrintAndLogEx(WARNING, "Device offline\n"); PrintAndLogEx(WARNING, "Device offline\n");
return PM3_ENODATA; return PM3_ENODATA;
} }

View file

@ -775,7 +775,7 @@ static bool DecodeT5555TraceBlock(void) {
// sanity check. Don't use proxmark if it is offline and you didn't specify useGraphbuf // sanity check. Don't use proxmark if it is offline and you didn't specify useGraphbuf
static int SanityOfflineCheck(bool useGraphBuffer) { static int SanityOfflineCheck(bool useGraphBuffer) {
if (!useGraphBuffer && !session.pm3_present) { if (!useGraphBuffer && !g_session.pm3_present) {
PrintAndLogEx(WARNING, "Your proxmark3 device is offline. Specify [1] to use graphbuffer data instead"); PrintAndLogEx(WARNING, "Your proxmark3 device is offline. Specify [1] to use graphbuffer data instead");
return PM3_ENODATA; return PM3_ENODATA;
} }
@ -3197,7 +3197,7 @@ static int CmdT55xxChkPwds(const char *Cmd) {
for (uint32_t c = 0; c < keycount && found == false; ++c) { for (uint32_t c = 0; c < keycount && found == false; ++c) {
if (!session.pm3_present) { if (!g_session.pm3_present) {
PrintAndLogEx(WARNING, "device offline\n"); PrintAndLogEx(WARNING, "device offline\n");
free(keyblock); free(keyblock);
return PM3_ENODATA; return PM3_ENODATA;

View file

@ -229,12 +229,12 @@ static int CmdHints(const char *Cmd) {
} }
if (turn_off) { if (turn_off) {
session.show_hints = false; g_session.show_hints = false;
} else if (turn_on) { } else if (turn_on) {
session.show_hints = true; g_session.show_hints = true;
} }
PrintAndLogEx(INFO, "Hints are %s", (session.show_hints) ? "ON" : "OFF"); PrintAndLogEx(INFO, "Hints are %s", (g_session.show_hints) ? "ON" : "OFF");
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -22,9 +22,9 @@ bool AlwaysAvailable(void) {
} }
bool IfPm3Present(void) { bool IfPm3Present(void) {
if (session.help_dump_mode) if (g_session.help_dump_mode)
return false; return false;
return session.pm3_present; return g_session.pm3_present;
} }
bool IfPm3Rdv4Fw(void) { bool IfPm3Rdv4Fw(void) {
@ -195,8 +195,8 @@ void CmdsHelp(const command_t Commands[]) {
int CmdsParse(const command_t Commands[], const char *Cmd) { int CmdsParse(const command_t Commands[], const char *Cmd) {
if (session.client_exe_delay != 0) { if (g_session.client_exe_delay != 0) {
msleep(session.client_exe_delay); msleep(g_session.client_exe_delay);
} }
// Help dump children // Help dump children

View file

@ -89,7 +89,7 @@ void SendCommandOLD(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, v
print_hex_break((uint8_t *)&c.d, sizeof(c.d), 32); print_hex_break((uint8_t *)&c.d, sizeof(c.d), 32);
#endif #endif
if (!session.pm3_present) { if (!g_session.pm3_present) {
PrintAndLogEx(WARNING, "Sending bytes to Proxmark3 failed." _YELLOW_("offline")); PrintAndLogEx(WARNING, "Sending bytes to Proxmark3 failed." _YELLOW_("offline"));
return; return;
} }
@ -120,7 +120,7 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool
PrintAndLogEx(INFO, "Sending %s", ng ? "NG" : "MIX"); PrintAndLogEx(INFO, "Sending %s", ng ? "NG" : "MIX");
#endif #endif
if (!session.pm3_present) { if (!g_session.pm3_present) {
PrintAndLogEx(INFO, "Sending bytes to proxmark failed - offline"); PrintAndLogEx(INFO, "Sending bytes to proxmark failed - offline");
return; return;
} }
@ -589,7 +589,7 @@ bool OpenProxmark(pm3_device **dev, char *port, bool wait_for_port, int timeout,
pthread_create(&communication_thread, NULL, &uart_communication, &g_conn); pthread_create(&communication_thread, NULL, &uart_communication, &g_conn);
__atomic_clear(&comm_thread_dead, __ATOMIC_SEQ_CST); __atomic_clear(&comm_thread_dead, __ATOMIC_SEQ_CST);
session.pm3_present = true; // TODO support for multiple devices g_session.pm3_present = true; // TODO support for multiple devices
fflush(stdout); fflush(stdout);
if (*dev == NULL) { if (*dev == NULL) {
@ -689,7 +689,7 @@ void CloseProxmark(pm3_device *dev) {
memset(&communication_thread, 0, sizeof(pthread_t)); memset(&communication_thread, 0, sizeof(pthread_t));
#endif #endif
session.pm3_present = false; g_session.pm3_present = false;
} }
// Gives a rough estimate of the communication delay based on channel & baudrate // Gives a rough estimate of the communication delay based on channel & baudrate

View file

@ -237,14 +237,14 @@ bool create_path(const char *dirname) {
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) && (g_session.defaultPaths[pathIndex] != NULL)) {
free(session.defaultPaths[pathIndex]); free(g_session.defaultPaths[pathIndex]);
session.defaultPaths[pathIndex] = NULL; g_session.defaultPaths[pathIndex] = NULL;
} }
if (Path != NULL) { if (Path != NULL) {
session.defaultPaths[pathIndex] = (char *)realloc(session.defaultPaths[pathIndex], strlen(Path) + 1); g_session.defaultPaths[pathIndex] = (char *)realloc(g_session.defaultPaths[pathIndex], strlen(Path) + 1);
strcpy(session.defaultPaths[pathIndex], Path); strcpy(g_session.defaultPaths[pathIndex], Path);
} }
return true; return true;
} }

View file

@ -79,7 +79,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 g_session.defaultPaths
char *newfilenamemcopy(const char *preferredName, const char *suffix); char *newfilenamemcopy(const char *preferredName, const char *suffix);

View file

@ -374,11 +374,11 @@ static int enter_bootloader(char *serial_port_name) {
PrintAndLogEx(SUCCESS, "Press and hold down button NOW if your bootloader requires it."); PrintAndLogEx(SUCCESS, "Press and hold down button NOW if your bootloader requires it.");
} }
msleep(100); msleep(100);
CloseProxmark(session.current_device); CloseProxmark(g_session.current_device);
// Let time to OS to make the port disappear // Let time to OS to make the port disappear
msleep(1000); msleep(1000);
if (OpenProxmark(&session.current_device, serial_port_name, true, 60, true, FLASHMODE_SPEED)) { if (OpenProxmark(&g_session.current_device, serial_port_name, true, 60, true, FLASHMODE_SPEED)) {
PrintAndLogEx(NORMAL, _GREEN_(" found")); PrintAndLogEx(NORMAL, _GREEN_(" found"));
return PM3_SUCCESS; return PM3_SUCCESS;
} else { } else {
@ -552,7 +552,7 @@ int flash_write(flash_file_t *ctx) {
PrintAndLogEx(SUCCESS, "Writing segments for file: %s", ctx->filename); PrintAndLogEx(SUCCESS, "Writing segments for file: %s", ctx->filename);
bool filter_ansi = !session.supports_colors; bool filter_ansi = !g_session.supports_colors;
for (int i = 0; i < ctx->num_segs; i++) { for (int i = 0; i < ctx->num_segs; i++) {
flash_seg_t *seg = &ctx->segments[i]; flash_seg_t *seg = &ctx->segments[i];

View file

@ -15,24 +15,24 @@
pm3_device *pm3_open(char *port) { pm3_device *pm3_open(char *port) {
pm3_init(); pm3_init();
OpenProxmark(&session.current_device, port, false, 20, false, USART_BAUD_RATE); OpenProxmark(&g_session.current_device, port, false, 20, false, USART_BAUD_RATE);
if (session.pm3_present && (TestProxmark(session.current_device) != PM3_SUCCESS)) { if (g_session.pm3_present && (TestProxmark(g_session.current_device) != PM3_SUCCESS)) {
PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark\n"); PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark\n");
CloseProxmark(session.current_device); CloseProxmark(g_session.current_device);
} }
if ((port != NULL) && (!session.pm3_present)) if ((port != NULL) && (!g_session.pm3_present))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
if (!session.pm3_present) if (!g_session.pm3_present)
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode"); PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode");
// For now, there is no real device context: // For now, there is no real device context:
return session.current_device; return g_session.current_device;
} }
void pm3_close(pm3_device *dev) { void pm3_close(pm3_device *dev) {
// Clean up the port // Clean up the port
if (session.pm3_present) { if (g_session.pm3_present) {
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_QUIT_SESSION, NULL, 0); SendCommandNG(CMD_QUIT_SESSION, NULL, 0);
msleep(100); // Make sure command is sent before killing client msleep(100); // Make sure command is sent before killing client
@ -51,5 +51,5 @@ const char *pm3_name_get(pm3_device *dev) {
} }
pm3_device *pm3_get_current_dev(void) { pm3_device *pm3_get_current_dev(void) {
return session.current_device; return g_session.current_device;
} }

View file

@ -11,8 +11,8 @@
// Add the default value for the setting in the settings_load page below // 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_load_callback to load your setting into the stucture
// Update the preferences_save_callback to ensure your setting gets saved when needed. // Update the preferences_save_callback to ensure your setting gets saved when needed.
// use the preference as needed : session.<preference name> // use the preference as needed : g_session.<preference name>
// Can use (session.preferences_loaded) to check if json settings file was used // Can use (g_session.preferences_loaded) to check if json settings file was used
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "preferences.h" #include "preferences.h"
@ -40,21 +40,21 @@ static char *prefGetFilename(void) {
int preferences_load(void) { int preferences_load(void) {
// Set all defaults // Set all defaults
session.client_debug_level = cdbOFF; g_session.client_debug_level = cdbOFF;
// session.device_debug_level = ddbOFF; // g_session.device_debug_level = ddbOFF;
session.window_changed = false; g_session.window_changed = false;
session.plot.x = 10; g_session.plot.x = 10;
session.plot.y = 30; g_session.plot.y = 30;
session.plot.h = 400; g_session.plot.h = 400;
session.plot.w = 800; g_session.plot.w = 800;
session.overlay.x = session.plot.x; g_session.overlay.x = g_session.plot.x;
session.overlay.y = 60 + session.plot.y + session.plot.h; g_session.overlay.y = 60 + g_session.plot.y + g_session.plot.h;
session.overlay.h = 200; g_session.overlay.h = 200;
session.overlay.w = session.plot.w; g_session.overlay.w = g_session.plot.w;
session.overlay_sliders = true; g_session.overlay_sliders = true;
session.show_hints = true; g_session.show_hints = true;
session.bar_mode = STYLE_VALUE; g_session.bar_mode = STYLE_VALUE;
setDefaultPath(spDefault, ""); setDefaultPath(spDefault, "");
setDefaultPath(spDump, ""); setDefaultPath(spDump, "");
setDefaultPath(spTrace, ""); setDefaultPath(spTrace, "");
@ -77,7 +77,7 @@ int preferences_load(void) {
else else
setDefaultPath(spTrace, "."); setDefaultPath(spTrace, ".");
if (session.incognito) { if (g_session.incognito) {
PrintAndLogEx(INFO, "No preferences file will be loaded"); PrintAndLogEx(INFO, "No preferences file will be loaded");
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -91,11 +91,11 @@ int preferences_load(void) {
char *fn = prefGetFilename(); char *fn = prefGetFilename();
if (fileExists(fn)) { if (fileExists(fn)) {
if (loadFileJSON(fn, &dummyData, sizeof(dummyData), &dummyDL, &preferences_load_callback) == PM3_SUCCESS) { if (loadFileJSON(fn, &dummyData, sizeof(dummyData), &dummyDL, &preferences_load_callback) == PM3_SUCCESS) {
session.preferences_loaded = true; g_session.preferences_loaded = true;
} }
} }
free(fn); free(fn);
// Note, if session.settings_loaded == false then the settings_save // Note, if g_session.settings_loaded == false then the settings_save
// will be called in main () to save settings as set in defaults and main() checks. // will be called in main () to save settings as set in defaults and main() checks.
return PM3_SUCCESS; return PM3_SUCCESS;
@ -104,7 +104,7 @@ int preferences_load(void) {
// Save all settings from memory (struct) to file // Save all settings from memory (struct) to file
int preferences_save(void) { int preferences_save(void) {
// Note sure if backup has value ? // Note sure if backup has value ?
if (session.incognito) { if (g_session.incognito) {
PrintAndLogEx(INFO, "No preferences file will be saved"); PrintAndLogEx(INFO, "No preferences file will be saved");
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -156,7 +156,7 @@ void preferences_save_callback(json_t *root) {
JsonSaveStr(root, "FileType", "settings"); JsonSaveStr(root, "FileType", "settings");
// Emoji // Emoji
switch (session.emoji_mode) { switch (g_session.emoji_mode) {
case EMO_ALIAS: case EMO_ALIAS:
JsonSaveStr(root, "show.emoji", "alias"); JsonSaveStr(root, "show.emoji", "alias");
break; break;
@ -173,29 +173,29 @@ void preferences_save_callback(json_t *root) {
JsonSaveStr(root, "show.emoji", "ALIAS"); JsonSaveStr(root, "show.emoji", "ALIAS");
} }
JsonSaveBoolean(root, "show.hints", session.show_hints); JsonSaveBoolean(root, "show.hints", g_session.show_hints);
JsonSaveBoolean(root, "os.supports.colors", session.supports_colors); JsonSaveBoolean(root, "os.supports.colors", g_session.supports_colors);
JsonSaveStr(root, "file.default.savepath", session.defaultPaths[spDefault]); JsonSaveStr(root, "file.default.savepath", g_session.defaultPaths[spDefault]);
JsonSaveStr(root, "file.default.dumppath", session.defaultPaths[spDump]); JsonSaveStr(root, "file.default.dumppath", g_session.defaultPaths[spDump]);
JsonSaveStr(root, "file.default.tracepath", session.defaultPaths[spTrace]); JsonSaveStr(root, "file.default.tracepath", g_session.defaultPaths[spTrace]);
// Plot window // Plot window
JsonSaveInt(root, "window.plot.xpos", session.plot.x); JsonSaveInt(root, "window.plot.xpos", g_session.plot.x);
JsonSaveInt(root, "window.plot.ypos", session.plot.y); JsonSaveInt(root, "window.plot.ypos", g_session.plot.y);
JsonSaveInt(root, "window.plot.hsize", session.plot.h); JsonSaveInt(root, "window.plot.hsize", g_session.plot.h);
JsonSaveInt(root, "window.plot.wsize", session.plot.w); JsonSaveInt(root, "window.plot.wsize", g_session.plot.w);
// Overlay/Slider window // Overlay/Slider window
JsonSaveInt(root, "window.overlay.xpos", session.overlay.x); JsonSaveInt(root, "window.overlay.xpos", g_session.overlay.x);
JsonSaveInt(root, "window.overlay.ypos", session.overlay.y); JsonSaveInt(root, "window.overlay.ypos", g_session.overlay.y);
JsonSaveInt(root, "window.overlay.hsize", session.overlay.h); JsonSaveInt(root, "window.overlay.hsize", g_session.overlay.h);
JsonSaveInt(root, "window.overlay.wsize", session.overlay.w); JsonSaveInt(root, "window.overlay.wsize", g_session.overlay.w);
JsonSaveBoolean(root, "window.overlay.sliders", session.overlay_sliders); JsonSaveBoolean(root, "window.overlay.sliders", g_session.overlay_sliders);
// Log level, convert to text // Log level, convert to text
switch (session.client_debug_level) { switch (g_session.client_debug_level) {
case cdbOFF: case cdbOFF:
JsonSaveStr(root, "client.debug.level", "off"); JsonSaveStr(root, "client.debug.level", "off");
break; break;
@ -209,7 +209,7 @@ void preferences_save_callback(json_t *root) {
JsonSaveStr(root, "logging.level", "NORMAL"); JsonSaveStr(root, "logging.level", "NORMAL");
} }
switch (session.bar_mode) { switch (g_session.bar_mode) {
case STYLE_BAR: case STYLE_BAR:
JsonSaveStr(root, "show.bar.mode", "bar"); JsonSaveStr(root, "show.bar.mode", "bar");
break; break;
@ -223,7 +223,7 @@ void preferences_save_callback(json_t *root) {
JsonSaveStr(root, "show.bar.mode", "value"); JsonSaveStr(root, "show.bar.mode", "value");
} }
/* /*
switch (session.device_debug_level) { switch (g_session.device_debug_level) {
case ddbOFF: case ddbOFF:
JsonSaveStr(root, "device.debug.level", "off"); JsonSaveStr(root, "device.debug.level", "off");
break; break;
@ -243,7 +243,7 @@ void preferences_save_callback(json_t *root) {
JsonSaveStr(root, "logging.level", "NORMAL"); JsonSaveStr(root, "logging.level", "NORMAL");
} }
*/ */
JsonSaveInt(root, "client.exe.delay", session.client_exe_delay); JsonSaveInt(root, "client.exe.delay", g_session.client_exe_delay);
} }
void preferences_load_callback(json_t *root) { void preferences_load_callback(json_t *root) {
@ -257,9 +257,9 @@ void preferences_load_callback(json_t *root) {
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "client.debug.level", &s1) == 0) { if (json_unpack_ex(root, &up_error, 0, "{s:s}", "client.debug.level", &s1) == 0) {
strncpy(tempStr, s1, sizeof(tempStr) - 1); strncpy(tempStr, s1, sizeof(tempStr) - 1);
str_lower(tempStr); str_lower(tempStr);
if (strncmp(tempStr, "off", 3) == 0) session.client_debug_level = cdbOFF; if (strncmp(tempStr, "off", 3) == 0) g_session.client_debug_level = cdbOFF;
if (strncmp(tempStr, "simple", 6) == 0) session.client_debug_level = cdbSIMPLE; if (strncmp(tempStr, "simple", 6) == 0) g_session.client_debug_level = cdbSIMPLE;
if (strncmp(tempStr, "full", 4) == 0) session.client_debug_level = cdbFULL; if (strncmp(tempStr, "full", 4) == 0) g_session.client_debug_level = cdbFULL;
} }
// default save path // default save path
@ -276,49 +276,49 @@ void preferences_load_callback(json_t *root) {
// 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; g_session.plot.x = i1;
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.ypos", &i1) == 0) if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.ypos", &i1) == 0)
session.plot.y = i1; g_session.plot.y = i1;
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.hsize", &i1) == 0) if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.hsize", &i1) == 0)
session.plot.h = i1; g_session.plot.h = i1;
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.wsize", &i1) == 0) if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.wsize", &i1) == 0)
session.plot.w = i1; g_session.plot.w = i1;
// overlay/slider plot // overlay/slider plot
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.xpos", &i1) == 0) if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.xpos", &i1) == 0)
session.overlay.x = i1; g_session.overlay.x = i1;
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.ypos", &i1) == 0) if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.ypos", &i1) == 0)
session.overlay.y = i1; g_session.overlay.y = i1;
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.hsize", &i1) == 0) if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.hsize", &i1) == 0)
session.overlay.h = i1; g_session.overlay.h = i1;
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.wsize", &i1) == 0) if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.overlay.wsize", &i1) == 0)
session.overlay.w = i1; g_session.overlay.w = i1;
if (json_unpack_ex(root, &up_error, 0, "{s:b}", "window.overlay.sliders", &b1) == 0) if (json_unpack_ex(root, &up_error, 0, "{s:b}", "window.overlay.sliders", &b1) == 0)
session.overlay_sliders = (bool)b1; g_session.overlay_sliders = (bool)b1;
// show options // show options
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "show.emoji", &s1) == 0) { if (json_unpack_ex(root, &up_error, 0, "{s:s}", "show.emoji", &s1) == 0) {
strncpy(tempStr, s1, sizeof(tempStr) - 1); strncpy(tempStr, s1, sizeof(tempStr) - 1);
str_lower(tempStr); str_lower(tempStr);
if (strncmp(tempStr, "alias", 5) == 0) session.emoji_mode = EMO_ALIAS; if (strncmp(tempStr, "alias", 5) == 0) g_session.emoji_mode = EMO_ALIAS;
if (strncmp(tempStr, "emoji", 5) == 0) session.emoji_mode = EMO_EMOJI; if (strncmp(tempStr, "emoji", 5) == 0) g_session.emoji_mode = EMO_EMOJI;
if (strncmp(tempStr, "alttext", 7) == 0) session.emoji_mode = EMO_ALTTEXT; if (strncmp(tempStr, "alttext", 7) == 0) g_session.emoji_mode = EMO_ALTTEXT;
if (strncmp(tempStr, "none", 4) == 0) session.emoji_mode = EMO_NONE; if (strncmp(tempStr, "none", 4) == 0) g_session.emoji_mode = EMO_NONE;
} }
if (json_unpack_ex(root, &up_error, 0, "{s:b}", "show.hints", &b1) == 0) if (json_unpack_ex(root, &up_error, 0, "{s:b}", "show.hints", &b1) == 0)
session.show_hints = (bool)b1; g_session.show_hints = (bool)b1;
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}", "os.supports.colors", &b1) == 0)
session.supports_colors = (bool)b1; g_session.supports_colors = (bool)b1;
// bar mode // bar mode
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "show.bar.mode", &s1) == 0) { if (json_unpack_ex(root, &up_error, 0, "{s:s}", "show.bar.mode", &s1) == 0) {
strncpy(tempStr, s1, sizeof(tempStr) - 1); strncpy(tempStr, s1, sizeof(tempStr) - 1);
str_lower(tempStr); str_lower(tempStr);
if (strncmp(tempStr, "bar", 5) == 0) session.bar_mode = STYLE_BAR; if (strncmp(tempStr, "bar", 5) == 0) g_session.bar_mode = STYLE_BAR;
if (strncmp(tempStr, "mixed", 5) == 0) session.bar_mode = STYLE_MIXED; if (strncmp(tempStr, "mixed", 5) == 0) g_session.bar_mode = STYLE_MIXED;
if (strncmp(tempStr, "value", 7) == 0) session.bar_mode = STYLE_VALUE; if (strncmp(tempStr, "value", 7) == 0) g_session.bar_mode = STYLE_VALUE;
} }
/* /*
@ -326,16 +326,16 @@ void preferences_load_callback(json_t *root) {
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "device.debug.level", &s1) == 0) { if (json_unpack_ex(root, &up_error, 0, "{s:s}", "device.debug.level", &s1) == 0) {
strncpy(tempStr, s1, sizeof(tempStr) - 1); strncpy(tempStr, s1, sizeof(tempStr) - 1);
str_lower(tempStr); str_lower(tempStr);
if (strncmp(tempStr, "off", 3) == 0) session.device_debug_level = ddbOFF; if (strncmp(tempStr, "off", 3) == 0) g_session.device_debug_level = ddbOFF;
if (strncmp(tempStr, "error", 5) == 0) session.device_debug_level = ddbERROR; if (strncmp(tempStr, "error", 5) == 0) g_session.device_debug_level = ddbERROR;
if (strncmp(tempStr, "info", 4) == 0) session.device_debug_level = ddbINFO; if (strncmp(tempStr, "info", 4) == 0) g_session.device_debug_level = ddbINFO;
if (strncmp(tempStr, "debug", 5) == 0) session.device_debug_level = ddbDEBUG; if (strncmp(tempStr, "debug", 5) == 0) g_session.device_debug_level = ddbDEBUG;
if (strncmp(tempStr, "extended", 8) == 0) session.device_debug_level = ddbEXTENDED; if (strncmp(tempStr, "extended", 8) == 0) g_session.device_debug_level = ddbEXTENDED;
} }
*/ */
// client command execution delay // client command execution delay
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "client.exe.delay", &i1) == 0) if (json_unpack_ex(root, &up_error, 0, "{s:i}", "client.exe.delay", &i1) == 0)
session.client_exe_delay = i1; g_session.client_exe_delay = i1;
} }
// Help Functions // Help Functions
@ -358,7 +358,7 @@ static const char *prefShowMsg(prefShowOpt_t Opt) {
static void showEmojiState(prefShowOpt_t opt) { static void showEmojiState(prefShowOpt_t opt) {
switch (session.emoji_mode) { switch (g_session.emoji_mode) {
case EMO_ALIAS: case EMO_ALIAS:
PrintAndLogEx(INFO, " %s emoji.................. "_GREEN_("alias"), prefShowMsg(opt)); PrintAndLogEx(INFO, " %s emoji.................. "_GREEN_("alias"), prefShowMsg(opt));
break; break;
@ -378,7 +378,7 @@ static void showEmojiState(prefShowOpt_t opt) {
static void showColorState(prefShowOpt_t opt) { static void showColorState(prefShowOpt_t opt) {
if (session.supports_colors) if (g_session.supports_colors)
PrintAndLogEx(INFO, " %s color.................. "_GREEN_("ansi"), prefShowMsg(opt)); PrintAndLogEx(INFO, " %s color.................. "_GREEN_("ansi"), prefShowMsg(opt));
else else
PrintAndLogEx(INFO, " %s color.................. "_WHITE_("off"), prefShowMsg(opt)); PrintAndLogEx(INFO, " %s color.................. "_WHITE_("off"), prefShowMsg(opt));
@ -386,7 +386,7 @@ static void showColorState(prefShowOpt_t opt) {
static void showClientDebugState(prefShowOpt_t opt) { static void showClientDebugState(prefShowOpt_t opt) {
switch (session.client_debug_level) { switch (g_session.client_debug_level) {
case cdbOFF: case cdbOFF:
PrintAndLogEx(INFO, " %s client debug........... "_WHITE_("off"), prefShowMsg(opt)); PrintAndLogEx(INFO, " %s client debug........... "_WHITE_("off"), prefShowMsg(opt));
break; break;
@ -402,7 +402,7 @@ static void showClientDebugState(prefShowOpt_t opt) {
} }
/* /*
static void showDeviceDebugState(prefShowOpt_t opt) { static void showDeviceDebugState(prefShowOpt_t opt) {
switch (session.device_debug_level) { switch (g_session.device_debug_level) {
case ddbOFF: case ddbOFF:
PrintAndLogEx(INFO, " %s device debug........... "_WHITE_("off"), prefShowMsg(opt)); PrintAndLogEx(INFO, " %s device debug........... "_WHITE_("off"), prefShowMsg(opt));
break; break;
@ -443,7 +443,7 @@ static void showSavePathState(savePaths_t path_index, prefShowOpt_t opt) {
} }
if (path_index < spItemCount) { if (path_index < spItemCount) {
if ((session.defaultPaths[path_index] == NULL) || (strcmp(session.defaultPaths[path_index], "") == 0)) { if ((g_session.defaultPaths[path_index] == NULL) || (strcmp(g_session.defaultPaths[path_index], "") == 0)) {
PrintAndLogEx(INFO, " %s %s "_WHITE_("not set"), PrintAndLogEx(INFO, " %s %s "_WHITE_("not set"),
prefShowMsg(opt), prefShowMsg(opt),
s s
@ -452,7 +452,7 @@ static void showSavePathState(savePaths_t path_index, prefShowOpt_t opt) {
PrintAndLogEx(INFO, " %s %s "_GREEN_("%s"), PrintAndLogEx(INFO, " %s %s "_GREEN_("%s"),
prefShowMsg(opt), prefShowMsg(opt),
s, s,
session.defaultPaths[path_index] g_session.defaultPaths[path_index]
); );
} }
} }
@ -460,31 +460,31 @@ static void showSavePathState(savePaths_t path_index, prefShowOpt_t opt) {
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, g_session.plot.x,
session.plot.y, g_session.plot.y,
session.plot.h, g_session.plot.h,
session.plot.w g_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, g_session.overlay.x,
session.overlay.y, g_session.overlay.y,
session.overlay.h, g_session.overlay.h,
session.overlay.w g_session.overlay.w
); );
} }
static void showHintsState(prefShowOpt_t opt) { static void showHintsState(prefShowOpt_t opt) {
if (session.show_hints) if (g_session.show_hints)
PrintAndLogEx(INFO, " %s hints.................. "_GREEN_("on"), prefShowMsg(opt)); PrintAndLogEx(INFO, " %s hints.................. "_GREEN_("on"), prefShowMsg(opt));
else else
PrintAndLogEx(INFO, " %s hints.................. "_WHITE_("off"), prefShowMsg(opt)); PrintAndLogEx(INFO, " %s hints.................. "_WHITE_("off"), prefShowMsg(opt));
} }
static void showPlotSliderState(prefShowOpt_t opt) { static void showPlotSliderState(prefShowOpt_t opt) {
if (session.overlay_sliders) if (g_session.overlay_sliders)
PrintAndLogEx(INFO, " %s show plot sliders...... "_GREEN_("on"), prefShowMsg(opt)); PrintAndLogEx(INFO, " %s show plot sliders...... "_GREEN_("on"), prefShowMsg(opt));
else else
PrintAndLogEx(INFO, " %s show plot sliders...... "_WHITE_("off"), prefShowMsg(opt)); PrintAndLogEx(INFO, " %s show plot sliders...... "_WHITE_("off"), prefShowMsg(opt));
@ -492,7 +492,7 @@ static void showPlotSliderState(prefShowOpt_t opt) {
static void showBarModeState(prefShowOpt_t opt) { static void showBarModeState(prefShowOpt_t opt) {
switch (session.bar_mode) { switch (g_session.bar_mode) {
case STYLE_BAR: case STYLE_BAR:
PrintAndLogEx(INFO, " %s barmode................ "_GREEN_("bar"), prefShowMsg(opt)); PrintAndLogEx(INFO, " %s barmode................ "_GREEN_("bar"), prefShowMsg(opt));
break; break;
@ -508,7 +508,7 @@ static void showBarModeState(prefShowOpt_t opt) {
} }
static void showClientExeDelayState(void) { static void showClientExeDelayState(void) {
PrintAndLogEx(INFO, " Cmd execution delay.... "_GREEN_("%u"), session.client_exe_delay); PrintAndLogEx(INFO, " Cmd execution delay.... "_GREEN_("%u"), g_session.client_exe_delay);
} }
@ -539,7 +539,7 @@ static int setCmdEmoji(const char *Cmd) {
return PM3_EINVARG; return PM3_EINVARG;
} }
emojiMode_t new_value = session.emoji_mode; emojiMode_t new_value = g_session.emoji_mode;
if (show_a) { if (show_a) {
new_value = EMO_ALIAS; new_value = EMO_ALIAS;
@ -554,9 +554,9 @@ static int setCmdEmoji(const char *Cmd) {
new_value = EMO_NONE; new_value = EMO_NONE;
} }
if (session.emoji_mode != new_value) {// changed if (g_session.emoji_mode != new_value) {// changed
showEmojiState(prefShowOLD); showEmojiState(prefShowOLD);
session.emoji_mode = new_value; g_session.emoji_mode = new_value;
showEmojiState(prefShowNEW); showEmojiState(prefShowNEW);
preferences_save(); preferences_save();
} else { } else {
@ -589,7 +589,7 @@ static int setCmdColor(const char *Cmd) {
return PM3_EINVARG; return PM3_EINVARG;
} }
bool new_value = session.supports_colors; bool new_value = g_session.supports_colors;
if (use_c) { if (use_c) {
new_value = true; new_value = true;
} }
@ -598,9 +598,9 @@ static int setCmdColor(const char *Cmd) {
new_value = false; new_value = false;
} }
if (session.supports_colors != new_value) { if (g_session.supports_colors != new_value) {
showColorState(prefShowOLD); showColorState(prefShowOLD);
session.supports_colors = new_value; g_session.supports_colors = new_value;
showColorState(prefShowNEW); showColorState(prefShowNEW);
preferences_save(); preferences_save();
} else { } else {
@ -635,7 +635,7 @@ static int setCmdDebug(const char *Cmd) {
return PM3_EINVARG; return PM3_EINVARG;
} }
clientdebugLevel_t new_value = session.client_debug_level; clientdebugLevel_t new_value = g_session.client_debug_level;
if (use_off) { if (use_off) {
new_value = cdbOFF; new_value = cdbOFF;
@ -647,9 +647,9 @@ static int setCmdDebug(const char *Cmd) {
new_value = cdbFULL; new_value = cdbFULL;
} }
if (session.client_debug_level != new_value) { if (g_session.client_debug_level != new_value) {
showClientDebugState(prefShowOLD); showClientDebugState(prefShowOLD);
session.client_debug_level = new_value; g_session.client_debug_level = new_value;
g_debugMode = new_value; g_debugMode = new_value;
showClientDebugState(prefShowNEW); showClientDebugState(prefShowNEW);
preferences_save(); preferences_save();
@ -690,7 +690,7 @@ static int setCmdDeviceDebug (const char *Cmd)
return PM3_EINVARG; return PM3_EINVARG;
} }
devicedebugLevel_t new_value = session.device_debug_level; devicedebugLevel_t new_value = g_session.device_debug_level;
if (use_off) { if (use_off) {
new_value = ddbOFF; new_value = ddbOFF;
@ -708,18 +708,18 @@ static int setCmdDeviceDebug (const char *Cmd)
new_value = ddbEXTENDED; new_value = ddbEXTENDED;
} }
if (session.device_debug_level != new_value) {// changed if (g_session.device_debug_level != new_value) {// changed
showDeviceDebugState (prefShowOLD); showDeviceDebugState (prefShowOLD);
session.device_debug_level = new_value; g_session.device_debug_level = new_value;
showDeviceDebugState (prefShowNEW); showDeviceDebugState (prefShowNEW);
preferences_save(); preferences_save();
} else { } else {
showDeviceDebugState (prefShowNone); showDeviceDebugState (prefShowNone);
} }
if (session.pm3_present) { if (g_session.pm3_present) {
PrintAndLogEx (INFO,"setting device debug loglevel"); PrintAndLogEx (INFO,"setting device debug loglevel");
SendCommandNG(CMD_SET_DBGMODE, &session.device_debug_level, 1); SendCommandNG(CMD_SET_DBGMODE, &g_session.device_debug_level, 1);
PacketResponseNG resp; PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_SET_DBGMODE, &resp, 2000) == false) if (WaitForResponseTimeout(CMD_SET_DBGMODE, &resp, 2000) == false)
PrintAndLogEx (WARNING,"failed to set device debug loglevel"); PrintAndLogEx (WARNING,"failed to set device debug loglevel");
@ -746,9 +746,9 @@ static int setCmdExeDelay(const char *Cmd) {
uint16_t new_value = (uint16_t)arg_get_int_def(ctx, 1, 0); uint16_t new_value = (uint16_t)arg_get_int_def(ctx, 1, 0);
CLIParserFree(ctx); CLIParserFree(ctx);
if (session.client_exe_delay != new_value) { if (g_session.client_exe_delay != new_value) {
showClientExeDelayState(); showClientExeDelayState();
session.client_exe_delay = new_value; g_session.client_exe_delay = new_value;
showClientExeDelayState(); showClientExeDelayState();
preferences_save(); preferences_save();
} else { } else {
@ -780,7 +780,7 @@ static int setCmdHint(const char *Cmd) {
return PM3_EINVARG; return PM3_EINVARG;
} }
bool new_value = session.show_hints; bool new_value = g_session.show_hints;
if (use_off) { if (use_off) {
new_value = false; new_value = false;
} }
@ -788,9 +788,9 @@ static int setCmdHint(const char *Cmd) {
new_value = true; new_value = true;
} }
if (session.show_hints != new_value) { if (g_session.show_hints != new_value) {
showHintsState(prefShowOLD); showHintsState(prefShowOLD);
session.show_hints = new_value; g_session.show_hints = new_value;
showHintsState(prefShowNEW); showHintsState(prefShowNEW);
preferences_save(); preferences_save();
} else { } else {
@ -823,7 +823,7 @@ static int setCmdPlotSliders(const char *Cmd) {
return PM3_EINVARG; return PM3_EINVARG;
} }
bool new_value = session.overlay_sliders; bool new_value = g_session.overlay_sliders;
if (use_off) { if (use_off) {
new_value = false; new_value = false;
} }
@ -831,9 +831,9 @@ static int setCmdPlotSliders(const char *Cmd) {
new_value = true; new_value = true;
} }
if (session.overlay_sliders != new_value) { if (g_session.overlay_sliders != new_value) {
showPlotSliderState(prefShowOLD); showPlotSliderState(prefShowOLD);
session.overlay_sliders = new_value; g_session.overlay_sliders = new_value;
showPlotSliderState(prefShowNEW); showPlotSliderState(prefShowNEW);
preferences_save(); preferences_save();
} else { } else {
@ -910,7 +910,7 @@ static int setCmdSavePaths(const char *Cmd) {
// create_path (newValue); //mkdir (newValue,0x777); // create_path (newValue); //mkdir (newValue,0x777);
if (path_item < spItemCount) { if (path_item < spItemCount) {
if (strcmp(path, session.defaultPaths[path_item]) != 0) { if (strcmp(path, g_session.defaultPaths[path_item]) != 0) {
showSavePathState(path_item, prefShowOLD); showSavePathState(path_item, prefShowOLD);
setDefaultPath(path_item, path); setDefaultPath(path_item, path);
showSavePathState(path_item, prefShowNEW); showSavePathState(path_item, prefShowNEW);
@ -948,7 +948,7 @@ static int setCmdBarMode(const char *Cmd) {
return PM3_EINVARG; return PM3_EINVARG;
} }
barMode_t new_value = session.bar_mode; barMode_t new_value = g_session.bar_mode;
if (show_bar) { if (show_bar) {
new_value = STYLE_BAR; new_value = STYLE_BAR;
} }
@ -959,9 +959,9 @@ static int setCmdBarMode(const char *Cmd) {
new_value = STYLE_VALUE; new_value = STYLE_VALUE;
} }
if (session.bar_mode != new_value) { if (g_session.bar_mode != new_value) {
showBarModeState(prefShowOLD); showBarModeState(prefShowOLD);
session.bar_mode = new_value; g_session.bar_mode = new_value;
showBarModeState(prefShowNEW); showBarModeState(prefShowNEW);
preferences_save(); preferences_save();
} else { } else {
@ -1156,7 +1156,7 @@ static int CmdPrefShow(const char *Cmd) {
CLIExecWithReturn(ctx, Cmd, argtable, true); CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx); CLIParserFree(ctx);
if (session.preferences_loaded) { if (g_session.preferences_loaded) {
char *fn = prefGetFilename(); char *fn = prefGetFilename();
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "Using "_YELLOW_("%s"), fn); PrintAndLogEx(INFO, "Using "_YELLOW_("%s"), fn);

View file

@ -192,7 +192,7 @@ void ProxGuiQT::MainLoop() {
// pictureWidget->setAttribute(Qt::WA_DeleteOnClose,true); // pictureWidget->setAttribute(Qt::WA_DeleteOnClose,true);
// Set picture widget position if no settings. // Set picture widget position if no settings.
if (session.preferences_loaded == false) { if (g_session.preferences_loaded == false) {
// Move controller widget below plot // Move controller widget below plot
//pictureController->move(x(), y() + frameSize().height()); //pictureController->move(x(), y() + frameSize().height());
//pictureController->resize(size().width(), 200); //pictureController->resize(size().width(), 200);
@ -250,8 +250,8 @@ ProxGuiQT::~ProxGuiQT(void) {
// ------------------------------------------------- // -------------------------------------------------
PictureWidget::PictureWidget() { PictureWidget::PictureWidget() {
// Set the initail postion and size from settings // Set the initail postion and size from settings
// if (session.preferences_loaded) // if (g_session.preferences_loaded)
// setGeometry(session.pw.x, session.pw.y, session.pw.w, session.pw.h); // setGeometry(g_session.pw.x, g_session.pw.y, g_session.pw.w, g_session.pw.h);
// else // else
resize(400, 400); resize(400, 400);
} }
@ -269,23 +269,23 @@ void PictureWidget::closeEvent(QCloseEvent *event) {
SliderWidget::SliderWidget() { SliderWidget::SliderWidget() {
// Set the initail postion and size from settings // Set the initail postion and size from settings
if (session.preferences_loaded) if (g_session.preferences_loaded)
setGeometry(session.overlay.x, session.overlay.y, session.overlay.w, session.overlay.h); setGeometry(g_session.overlay.x, g_session.overlay.y, g_session.overlay.w, g_session.overlay.h);
else else
resize(800, 400); resize(800, 400);
} }
void SliderWidget::resizeEvent(QResizeEvent *event) { void SliderWidget::resizeEvent(QResizeEvent *event) {
session.overlay.h = event->size().height(); g_session.overlay.h = event->size().height();
session.overlay.w = event->size().width(); g_session.overlay.w = event->size().width();
session.window_changed = true; g_session.window_changed = true;
} }
void SliderWidget::moveEvent(QMoveEvent *event) { void SliderWidget::moveEvent(QMoveEvent *event) {
session.overlay.x = event->pos().x(); g_session.overlay.x = event->pos().x();
session.overlay.y = event->pos().y(); g_session.overlay.y = event->pos().y();
session.window_changed = true; g_session.window_changed = true;
} }
//-------------------- //--------------------
@ -331,8 +331,8 @@ 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 // Set the initail postion and size from settings
if (session.preferences_loaded) if (g_session.preferences_loaded)
setGeometry(session.plot.x, session.plot.y, session.plot.w, session.plot.h); setGeometry(g_session.plot.x, g_session.plot.y, g_session.plot.w, g_session.plot.h);
else else
resize(800, 400); resize(800, 400);
@ -357,7 +357,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
QObject::connect(opsController->horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_down(int))); QObject::connect(opsController->horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_down(int)));
QObject::connect(opsController->horizontalSlider_askedge, SIGNAL(valueChanged(int)), this, SLOT(vchange_askedge(int))); QObject::connect(opsController->horizontalSlider_askedge, SIGNAL(valueChanged(int)), this, SLOT(vchange_askedge(int)));
controlWidget->setGeometry(session.overlay.x, session.overlay.y, session.overlay.w, session.overlay.h); controlWidget->setGeometry(g_session.overlay.x, g_session.overlay.y, g_session.overlay.w, g_session.overlay.h);
// Set up the plot widget, which does the actual plotting // Set up the plot widget, which does the actual plotting
plot = new Plot(this); plot = new Plot(this);
@ -373,7 +373,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
show(); show();
// Set Slider/Overlay position if no settings. // Set Slider/Overlay position if no settings.
if (session.preferences_loaded == false) { if (g_session.preferences_loaded == false) {
// Move controller widget below plot // Move controller widget below plot
controlWidget->move(x(), y() + frameSize().height()); controlWidget->move(x(), y() + frameSize().height());
controlWidget->resize(size().width(), 200); controlWidget->resize(size().width(), 200);
@ -387,7 +387,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
// controlWidget->show(); // controlWidget->show();
// now that is up, reset pos/size change flags // now that is up, reset pos/size change flags
session.window_changed = false; g_session.window_changed = false;
} }
@ -422,7 +422,7 @@ void ProxWidget::hideEvent(QHideEvent *event) {
plot->hide(); plot->hide();
} }
void ProxWidget::showEvent(QShowEvent *event) { void ProxWidget::showEvent(QShowEvent *event) {
if (session.overlay_sliders) if (g_session.overlay_sliders)
controlWidget->show(); controlWidget->show();
else else
controlWidget->hide(); controlWidget->hide();
@ -430,14 +430,14 @@ void ProxWidget::showEvent(QShowEvent *event) {
plot->show(); plot->show();
} }
void ProxWidget::moveEvent(QMoveEvent *event) { void ProxWidget::moveEvent(QMoveEvent *event) {
session.plot.x = event->pos().x(); g_session.plot.x = event->pos().x();
session.plot.y = event->pos().y(); g_session.plot.y = event->pos().y();
session.window_changed = true; g_session.window_changed = true;
} }
void ProxWidget::resizeEvent(QResizeEvent *event) { void ProxWidget::resizeEvent(QResizeEvent *event) {
session.plot.h = event->size().height(); g_session.plot.h = event->size().height();
session.plot.w = event->size().width(); g_session.plot.w = event->size().width();
session.window_changed = true; g_session.window_changed = true;
} }
//----------- Plotting //----------- Plotting

View file

@ -126,27 +126,27 @@ static void prompt_compose(char *buf, size_t buflen, const char *promptctx, cons
static int check_comm(void) { static int check_comm(void) {
// If communications thread goes down. Device disconnected then this should hook up PM3 again. // If communications thread goes down. Device disconnected then this should hook up PM3 again.
if (IsCommunicationThreadDead() && session.pm3_present) { if (IsCommunicationThreadDead() && g_session.pm3_present) {
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode. Use "_YELLOW_("\"hw connect\"") " to reconnect\n"); PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode. Use "_YELLOW_("\"hw connect\"") " to reconnect\n");
prompt_dev = PROXPROMPT_DEV_OFFLINE; prompt_dev = PROXPROMPT_DEV_OFFLINE;
#ifdef HAVE_READLINE #ifdef HAVE_READLINE
char prompt[PROXPROMPT_MAX_SIZE] = {0}; char prompt[PROXPROMPT_MAX_SIZE] = {0};
prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev); prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev);
char prompt_filtered[PROXPROMPT_MAX_SIZE] = {0}; char prompt_filtered[PROXPROMPT_MAX_SIZE] = {0};
memcpy_filter_ansi(prompt_filtered, prompt, sizeof(prompt_filtered), !session.supports_colors); memcpy_filter_ansi(prompt_filtered, prompt, sizeof(prompt_filtered), !g_session.supports_colors);
rl_set_prompt(prompt_filtered); rl_set_prompt(prompt_filtered);
rl_redisplay(); rl_redisplay();
#endif #endif
CloseProxmark(session.current_device); CloseProxmark(g_session.current_device);
} }
msleep(10); msleep(10);
return 0; return 0;
} }
#ifdef HAVE_READLINE #ifdef HAVE_READLINE
static void flush_history(void) { static void flush_history(void) {
if (session.history_path) { if (g_session.history_path) {
write_history(session.history_path); write_history(g_session.history_path);
free(session.history_path); free(g_session.history_path);
} }
} }
@ -178,7 +178,7 @@ static bool DetectWindowsAnsiSupport(void) {
#endif #endif
// disable colors if stdin or stdout are redirected // disable colors if stdin or stdout are redirected
if ((! session.stdinOnTTY) || (! session.stdoutOnTTY)) if ((! g_session.stdinOnTTY) || (! g_session.stdoutOnTTY))
return false; return false;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
@ -250,7 +250,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
bool stdinOnPipe = !isatty(STDIN_FILENO); bool stdinOnPipe = !isatty(STDIN_FILENO);
char script_cmd_buf[256] = {0x00}; // iceman, needs lua script the same file_path_buffer as the rest char script_cmd_buf[256] = {0x00}; // iceman, needs lua script the same file_path_buffer as the rest
if (session.pm3_present) { if (g_session.pm3_present) {
// cache Version information now: // cache Version information now:
if (execCommand || script_cmds_file || stdinOnPipe) if (execCommand || script_cmds_file || stdinOnPipe)
pm3_version(false, false); pm3_version(false, false);
@ -272,13 +272,13 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
} }
#ifdef HAVE_READLINE #ifdef HAVE_READLINE
session.history_path = NULL; g_session.history_path = NULL;
if (session.incognito) { if (g_session.incognito) {
PrintAndLogEx(INFO, "No history will be recorded"); PrintAndLogEx(INFO, "No history will be recorded");
} else { } else {
if (searchHomeFilePath(&session.history_path, NULL, PROXHISTORY, true) != PM3_SUCCESS) { if (searchHomeFilePath(&g_session.history_path, NULL, PROXHISTORY, true) != PM3_SUCCESS) {
PrintAndLogEx(ERR, "No history will be recorded"); PrintAndLogEx(ERR, "No history will be recorded");
session.history_path = NULL; g_session.history_path = NULL;
} else { } else {
# if defined(_WIN32) # if defined(_WIN32)
@ -291,7 +291,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
# endif # endif
rl_catch_signals = 1; rl_catch_signals = 1;
rl_set_signals(); rl_set_signals();
read_history(session.history_path); read_history(g_session.history_path);
} }
} }
#endif #endif
@ -300,7 +300,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
while (1) { while (1) {
bool printprompt = false; bool printprompt = false;
if (session.pm3_present) { if (g_session.pm3_present) {
if (g_conn.send_via_fpc_usart == false) if (g_conn.send_via_fpc_usart == false)
prompt_dev = PROXPROMPT_DEV_USB; prompt_dev = PROXPROMPT_DEV_USB;
else else
@ -380,13 +380,13 @@ check_script:
char prompt[PROXPROMPT_MAX_SIZE] = {0}; char prompt[PROXPROMPT_MAX_SIZE] = {0};
prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev); prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev);
char prompt_filtered[PROXPROMPT_MAX_SIZE] = {0}; char prompt_filtered[PROXPROMPT_MAX_SIZE] = {0};
memcpy_filter_ansi(prompt_filtered, prompt, sizeof(prompt_filtered), !session.supports_colors); memcpy_filter_ansi(prompt_filtered, prompt, sizeof(prompt_filtered), !g_session.supports_colors);
g_pendingPrompt = true; g_pendingPrompt = true;
#ifdef HAVE_READLINE #ifdef HAVE_READLINE
script_cmd = readline(prompt_filtered); script_cmd = readline(prompt_filtered);
#if defined(_WIN32) #if defined(_WIN32)
//Check if color support needs to be enabled again in case the window buffer did change //Check if color support needs to be enabled again in case the window buffer did change
session.supports_colors = DetectWindowsAnsiSupport(); g_session.supports_colors = DetectWindowsAnsiSupport();
#endif #endif
if (script_cmd != NULL) { if (script_cmd != NULL) {
execCommand = true; execCommand = true;
@ -475,7 +475,7 @@ check_script:
} }
} // end while } // end while
if (session.pm3_present) { if (g_session.pm3_present) {
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_QUIT_SESSION, NULL, 0); SendCommandNG(CMD_QUIT_SESSION, NULL, 0);
msleep(100); // Make sure command is sent before killing client msleep(100); // Make sure command is sent before killing client
@ -496,14 +496,14 @@ check_script:
#ifndef LIBPM3 #ifndef LIBPM3
static void dumpAllHelp(int markdown, bool full_help) { static void dumpAllHelp(int markdown, bool full_help) {
session.help_dump_mode = true; g_session.help_dump_mode = true;
PrintAndLogEx(NORMAL, "\n%sProxmark3 command dump%s\n\n", markdown ? "# " : "", markdown ? "" : "\n======================"); PrintAndLogEx(NORMAL, "\n%sProxmark3 command dump%s\n\n", markdown ? "# " : "", markdown ? "" : "\n======================");
PrintAndLogEx(NORMAL, "Some commands are available only if a Proxmark3 is actually connected.%s\n", markdown ? " " : ""); PrintAndLogEx(NORMAL, "Some commands are available only if a Proxmark3 is actually connected.%s\n", markdown ? " " : "");
PrintAndLogEx(NORMAL, "Check column \"offline\" for their availability.\n"); PrintAndLogEx(NORMAL, "Check column \"offline\" for their availability.\n");
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(NORMAL, "\n");
command_t *cmds = getTopLevelCommandTable(); command_t *cmds = getTopLevelCommandTable();
dumpCommandsRecursive(cmds, markdown, full_help); dumpCommandsRecursive(cmds, markdown, full_help);
session.help_dump_mode = false; g_session.help_dump_mode = false;
PrintAndLogEx(NORMAL, "Full help dump done."); PrintAndLogEx(NORMAL, "Full help dump done.");
} }
#endif //LIBPM3 #endif //LIBPM3
@ -678,7 +678,7 @@ static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[
PrintAndLogEx(SUCCESS, " "_YELLOW_("%s"), filepaths[i]); PrintAndLogEx(SUCCESS, " "_YELLOW_("%s"), filepaths[i]);
} }
if (OpenProxmark(&session.current_device, serial_port_name, true, 60, true, FLASHMODE_SPEED)) { if (OpenProxmark(&g_session.current_device, serial_port_name, true, 60, true, FLASHMODE_SPEED)) {
PrintAndLogEx(NORMAL, _GREEN_(" found")); PrintAndLogEx(NORMAL, _GREEN_(" found"));
} else { } else {
PrintAndLogEx(ERR, "Could not find Proxmark3 on " _RED_("%s") ".\n", serial_port_name); PrintAndLogEx(ERR, "Could not find Proxmark3 on " _RED_("%s") ".\n", serial_port_name);
@ -718,7 +718,7 @@ finish:
if (ret != PM3_SUCCESS) if (ret != PM3_SUCCESS)
PrintAndLogEx(INFO, "The flashing procedure failed, follow the suggested steps!"); PrintAndLogEx(INFO, "The flashing procedure failed, follow the suggested steps!");
ret = flash_stop_flashing(); ret = flash_stop_flashing();
CloseProxmark(session.current_device); CloseProxmark(g_session.current_device);
finish2: finish2:
for (int i = 0 ; i < num_files; ++i) { for (int i = 0 ; i < num_files; ++i) {
if (filepaths[i] != NULL) if (filepaths[i] != NULL)
@ -736,13 +736,13 @@ finish2:
void pm3_init(void) { void pm3_init(void) {
srand(time(0)); srand(time(0));
session.pm3_present = false; g_session.pm3_present = false;
session.help_dump_mode = false; g_session.help_dump_mode = false;
session.incognito = false; g_session.incognito = false;
session.supports_colors = false; g_session.supports_colors = false;
session.emoji_mode = EMO_ALTTEXT; g_session.emoji_mode = EMO_ALTTEXT;
session.stdinOnTTY = false; g_session.stdinOnTTY = false;
session.stdoutOnTTY = false; g_session.stdoutOnTTY = false;
// set global variables soon enough to get the log path // set global variables soon enough to get the log path
set_my_executable_path(); set_my_executable_path();
@ -788,17 +788,17 @@ int main(int argc, char *argv[]) {
// For info, grep --color=auto is doing sth like this, plus test getenv("TERM") != "dumb": // For info, grep --color=auto is doing sth like this, plus test getenv("TERM") != "dumb":
// struct stat tmp_stat; // struct stat tmp_stat;
// if ((fstat (STDOUT_FILENO, &tmp_stat) == 0) && (S_ISCHR (tmp_stat.st_mode)) && isatty(STDIN_FILENO)) // if ((fstat (STDOUT_FILENO, &tmp_stat) == 0) && (S_ISCHR (tmp_stat.st_mode)) && isatty(STDIN_FILENO))
session.stdinOnTTY = isatty(STDIN_FILENO); g_session.stdinOnTTY = isatty(STDIN_FILENO);
session.stdoutOnTTY = isatty(STDOUT_FILENO); g_session.stdoutOnTTY = isatty(STDOUT_FILENO);
session.supports_colors = false; g_session.supports_colors = false;
session.emoji_mode = EMO_ALTTEXT; g_session.emoji_mode = EMO_ALTTEXT;
if (session.stdinOnTTY && session.stdoutOnTTY) { if (g_session.stdinOnTTY && g_session.stdoutOnTTY) {
#if defined(__linux__) || defined(__APPLE__) #if defined(__linux__) || defined(__APPLE__)
session.supports_colors = true; g_session.supports_colors = true;
session.emoji_mode = EMO_EMOJI; g_session.emoji_mode = EMO_EMOJI;
#elif defined(_WIN32) #elif defined(_WIN32)
session.supports_colors = DetectWindowsAnsiSupport(); g_session.supports_colors = DetectWindowsAnsiSupport();
session.emoji_mode = EMO_ALTTEXT; g_session.emoji_mode = EMO_ALTTEXT;
#endif #endif
} }
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
@ -960,7 +960,7 @@ int main(int argc, char *argv[]) {
// do not use history nor log files // do not use history nor log files
if (strcmp(argv[i], "--incognito") == 0) { if (strcmp(argv[i], "--incognito") == 0) {
session.incognito = true; g_session.incognito = true;
continue; continue;
} }
@ -1002,14 +1002,14 @@ int main(int argc, char *argv[]) {
preferences_load(); preferences_load();
// quick patch for debug level // quick patch for debug level
if (! debug_mode_forced) if (! debug_mode_forced)
g_debugMode = session.client_debug_level; g_debugMode = g_session.client_debug_level;
// settings_save (); // settings_save ();
// End Settings // End Settings
// even if prefs, we disable colors if stdin or stdout is not a TTY // even if prefs, we disable colors if stdin or stdout is not a TTY
if ((! session.stdinOnTTY) || (! session.stdoutOnTTY)) { if ((! g_session.stdinOnTTY) || (! g_session.stdoutOnTTY)) {
session.supports_colors = false; g_session.supports_colors = false;
session.emoji_mode = EMO_ALTTEXT; g_session.emoji_mode = EMO_ALTTEXT;
} }
// Let's take a baudrate ok for real UART, USB-CDC & BT don't use that info anyway // Let's take a baudrate ok for real UART, USB-CDC & BT don't use that info anyway
@ -1048,36 +1048,36 @@ int main(int argc, char *argv[]) {
// try to open USB connection to Proxmark // try to open USB connection to Proxmark
if (port != NULL) { if (port != NULL) {
OpenProxmark(&session.current_device, port, waitCOMPort, 20, false, speed); OpenProxmark(&g_session.current_device, port, waitCOMPort, 20, false, speed);
} }
if (session.pm3_present && (TestProxmark(session.current_device) != PM3_SUCCESS)) { if (g_session.pm3_present && (TestProxmark(g_session.current_device) != PM3_SUCCESS)) {
PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark\n"); PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark\n");
CloseProxmark(session.current_device); CloseProxmark(g_session.current_device);
} }
if ((port != NULL) && (!session.pm3_present)) if ((port != NULL) && (!g_session.pm3_present))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
if (!session.pm3_present) if (!g_session.pm3_present)
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode. Check " _YELLOW_("\"%s -h\"") " if it's not what you want.\n", exec_name); PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode. Check " _YELLOW_("\"%s -h\"") " if it's not what you want.\n", exec_name);
// ascii art only in interactive client // ascii art only in interactive client
if (!script_cmds_file && !script_cmd && session.stdinOnTTY && session.stdoutOnTTY && !flash_mode) if (!script_cmds_file && !script_cmd && g_session.stdinOnTTY && g_session.stdoutOnTTY && !flash_mode)
showBanner(); showBanner();
// Save settings if not loaded from settings json file. // Save settings if not loaded from settings json file.
// Doing this here will ensure other checks and updates are saved to over rule default // Doing this here will ensure other checks and updates are saved to over rule default
// e.g. Linux color use check // e.g. Linux color use check
if ((!session.preferences_loaded) && (!session.incognito)) { if ((!g_session.preferences_loaded) && (!g_session.incognito)) {
PrintAndLogEx(INFO, "Creating initial preferences file"); // json save reports file name, so just info msg here PrintAndLogEx(INFO, "Creating initial preferences file"); // json save reports file name, so just info msg here
preferences_save(); // Save defaults preferences_save(); // Save defaults
session.preferences_loaded = true; g_session.preferences_loaded = true;
} /* else { } /* else {
// Set device debug level // Set device debug level
PrintAndLogEx(INFO,"setting device debug loglevel"); PrintAndLogEx(INFO,"setting device debug loglevel");
if (session.pm3_present) { if (g_session.pm3_present) {
SendCommandNG(CMD_SET_DBGMODE, &session.device_debug_level, 1); SendCommandNG(CMD_SET_DBGMODE, &g_session.device_debug_level, 1);
PacketResponseNG resp; PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_SET_DBGMODE, &resp, 2000) == false) if (WaitForResponseTimeout(CMD_SET_DBGMODE, &resp, 2000) == false)
PrintAndLogEx (INFO,"failed to set device debug loglevel"); PrintAndLogEx (INFO,"failed to set device debug loglevel");
@ -1108,11 +1108,11 @@ int main(int argc, char *argv[]) {
#endif #endif
// Clean up the port // Clean up the port
if (session.pm3_present) { if (g_session.pm3_present) {
CloseProxmark(session.current_device); CloseProxmark(g_session.current_device);
} }
if (session.window_changed) // Plot/Overlay moved or resized if (g_session.window_changed) // Plot/Overlay moved or resized
preferences_save(); preferences_save();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View file

@ -39,7 +39,7 @@
#include <time.h> #include <time.h>
#include "emojis.h" #include "emojis.h"
#include "emojis_alt.h" #include "emojis_alt.h"
session_arg_t session; session_arg_t g_session;
double g_CursorScaleFactor = 1; double g_CursorScaleFactor = 1;
char g_CursorScaleFactorUnit[11] = {0}; char g_CursorScaleFactorUnit[11] = {0};
@ -187,7 +187,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
return; return;
// skip HINT messages if client has hints turned off i.e. 'HINT 0' // skip HINT messages if client has hints turned off i.e. 'HINT 0'
if (session.show_hints == false && level == HINT) if (g_session.show_hints == false && level == HINT)
return; return;
char prefix[40] = {0}; char prefix[40] = {0};
@ -202,14 +202,14 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
}; };
switch (level) { switch (level) {
case ERR: case ERR:
if (session.emoji_mode == EMO_EMOJI) if (g_session.emoji_mode == EMO_EMOJI)
strncpy(prefix, "[" _RED_("!!") "] :rotating_light: ", sizeof(prefix) - 1); strncpy(prefix, "[" _RED_("!!") "] :rotating_light: ", sizeof(prefix) - 1);
else else
strncpy(prefix, "[" _RED_("!!") "] ", sizeof(prefix) - 1); strncpy(prefix, "[" _RED_("!!") "] ", sizeof(prefix) - 1);
stream = stderr; stream = stderr;
break; break;
case FAILED: case FAILED:
if (session.emoji_mode == EMO_EMOJI) if (g_session.emoji_mode == EMO_EMOJI)
strncpy(prefix, "[" _RED_("-") "] :no_entry: ", sizeof(prefix) - 1); strncpy(prefix, "[" _RED_("-") "] :no_entry: ", sizeof(prefix) - 1);
else else
strncpy(prefix, "[" _RED_("-") "] ", sizeof(prefix) - 1); strncpy(prefix, "[" _RED_("-") "] ", sizeof(prefix) - 1);
@ -224,7 +224,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
strncpy(prefix, "[" _GREEN_("+") "] ", sizeof(prefix) - 1); strncpy(prefix, "[" _GREEN_("+") "] ", sizeof(prefix) - 1);
break; break;
case WARNING: case WARNING:
if (session.emoji_mode == EMO_EMOJI) if (g_session.emoji_mode == EMO_EMOJI)
strncpy(prefix, "[" _CYAN_("!") "] :warning: ", sizeof(prefix) - 1); strncpy(prefix, "[" _CYAN_("!") "] :warning: ", sizeof(prefix) - 1);
else else
strncpy(prefix, "[" _CYAN_("!") "] ", sizeof(prefix) - 1); strncpy(prefix, "[" _CYAN_("!") "] ", sizeof(prefix) - 1);
@ -233,7 +233,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
strncpy(prefix, "[" _YELLOW_("=") "] ", sizeof(prefix) - 1); strncpy(prefix, "[" _YELLOW_("=") "] ", sizeof(prefix) - 1);
break; break;
case INPLACE: case INPLACE:
if (session.emoji_mode == EMO_EMOJI) { if (g_session.emoji_mode == EMO_EMOJI) {
strncpy(prefix, spinner_emoji[PrintAndLogEx_spinidx], sizeof(prefix) - 1); strncpy(prefix, spinner_emoji[PrintAndLogEx_spinidx], sizeof(prefix) - 1);
PrintAndLogEx_spinidx++; PrintAndLogEx_spinidx++;
if (PrintAndLogEx_spinidx >= ARRAYLEN(spinner_emoji)) if (PrintAndLogEx_spinidx >= ARRAYLEN(spinner_emoji))
@ -288,8 +288,8 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
if (level == INPLACE) { if (level == INPLACE) {
char buffer3[sizeof(buffer2)] = {0}; char buffer3[sizeof(buffer2)] = {0};
char buffer4[sizeof(buffer2)] = {0}; char buffer4[sizeof(buffer2)] = {0};
memcpy_filter_ansi(buffer3, buffer2, sizeof(buffer2), !session.supports_colors); memcpy_filter_ansi(buffer3, buffer2, sizeof(buffer2), !g_session.supports_colors);
memcpy_filter_emoji(buffer4, buffer3, sizeof(buffer3), session.emoji_mode); memcpy_filter_emoji(buffer4, buffer3, sizeof(buffer3), g_session.emoji_mode);
fprintf(stream, "\r%s", buffer4); fprintf(stream, "\r%s", buffer4);
fflush(stream); fflush(stream);
} else { } else {
@ -309,7 +309,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
pthread_mutex_lock(&g_print_lock); pthread_mutex_lock(&g_print_lock);
bool linefeed = true; bool linefeed = true;
if (logging && session.incognito) { if (logging && g_session.incognito) {
logging = 0; logging = 0;
} }
if ((g_printAndLog & PRINTANDLOG_LOG) && logging && !logfile) { if ((g_printAndLog & PRINTANDLOG_LOG) && logging && !logfile) {
@ -330,7 +330,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
logging = 0; logging = 0;
} else { } else {
if (session.supports_colors) { if (g_session.supports_colors) {
printf("["_YELLOW_("=")"] Session log " _YELLOW_("%s") "\n", my_logfile_path); printf("["_YELLOW_("=")"] Session log " _YELLOW_("%s") "\n", my_logfile_path);
} else { } else {
printf("[=] Session log %s\n", my_logfile_path); printf("[=] Session log %s\n", my_logfile_path);
@ -367,10 +367,10 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
linefeed = false; linefeed = false;
buffer[strlen(buffer) - 1] = 0; buffer[strlen(buffer) - 1] = 0;
} }
bool filter_ansi = !session.supports_colors; bool filter_ansi = !g_session.supports_colors;
memcpy_filter_ansi(buffer2, buffer, sizeof(buffer), filter_ansi); memcpy_filter_ansi(buffer2, buffer, sizeof(buffer), filter_ansi);
if (g_printAndLog & PRINTANDLOG_PRINT) { if (g_printAndLog & PRINTANDLOG_PRINT) {
memcpy_filter_emoji(buffer3, buffer2, sizeof(buffer2), session.emoji_mode); memcpy_filter_emoji(buffer3, buffer2, sizeof(buffer2), g_session.emoji_mode);
fprintf(stream, "%s", buffer3); fprintf(stream, "%s", buffer3);
if (linefeed) if (linefeed)
fprintf(stream, "\n"); fprintf(stream, "\n");
@ -661,7 +661,7 @@ void print_progress(size_t count, uint64_t max, barMode_t style) {
"\xe2\x96\x88", "\xe2\x96\x88",
}; };
int mode = (session.emoji_mode == EMO_EMOJI); int mode = (g_session.emoji_mode == EMO_EMOJI);
const char *block[] = {"#", "\xe2\x96\x88"}; const char *block[] = {"#", "\xe2\x96\x88"};
// use a 3-byte space in emoji mode to ease computations // use a 3-byte space in emoji mode to ease computations
@ -694,7 +694,7 @@ void print_progress(size_t count, uint64_t max, barMode_t style) {
char *cbar = (char *)calloc(collen, sizeof(uint8_t)); char *cbar = (char *)calloc(collen, sizeof(uint8_t));
// Add colors // Add colors
if (session.supports_colors) { if (g_session.supports_colors) {
int p60 = unit * (width * 60 / 100); int p60 = unit * (width * 60 / 100);
int p20 = unit * (width * 20 / 100); int p20 = unit * (width * 20 / 100);
snprintf(cbar, collen, _GREEN_("%.*s"), p60, bar); snprintf(cbar, collen, _GREEN_("%.*s"), p60, bar);

View file

@ -53,7 +53,7 @@ typedef struct {
pm3_device *current_device; pm3_device *current_device;
} session_arg_t; } session_arg_t;
extern session_arg_t session; extern session_arg_t g_session;
#ifndef M_PI #ifndef M_PI
#define M_PI 3.14159265358979323846264338327 #define M_PI 3.14159265358979323846264338327
#endif #endif