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
+1 -1
View File
@@ -208,7 +208,7 @@ int CmdHFTune(const char *Cmd) {
return PM3_EINVARG;
}
barMode_t style = session.bar_mode;
barMode_t style = g_session.bar_mode;
if (is_bar)
style = STYLE_BAR;
if (is_mix)
+3 -3
View File
@@ -189,7 +189,7 @@ static int CmdHF14AList(const char *Cmd) {
}
int hf14a_getconfig(hf14a_config *config) {
if (!session.pm3_present) return PM3_ENOTTY;
if (!g_session.pm3_present) return PM3_ENOTTY;
if (config == NULL)
return PM3_EINVARG;
@@ -207,7 +207,7 @@ int hf14a_getconfig(hf14a_config *config) {
}
int hf14a_setconfig(hf14a_config *config, bool verbose) {
if (!session.pm3_present) return PM3_ENOTTY;
if (!g_session.pm3_present) return PM3_ENOTTY;
clearCommandBuffer();
if (config != NULL) {
@@ -247,7 +247,7 @@ static int hf_14a_config_example(void) {
return PM3_SUCCESS;
}
static int CmdHf14AConfig(const char *Cmd) {
if (!session.pm3_present) return PM3_ENOTTY;
if (!g_session.pm3_present) return PM3_ENOTTY;
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 14a config",
+5 -5
View File
@@ -843,16 +843,16 @@ static int CmdConnect(const char *Cmd) {
memcpy(port, g_conn.serial_port_name, sizeof(port));
}
if (session.pm3_present) {
CloseProxmark(session.current_device);
if (g_session.pm3_present) {
CloseProxmark(g_session.current_device);
}
// 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");
CloseProxmark(session.current_device);
CloseProxmark(g_session.current_device);
return PM3_ENOTTY;
}
return PM3_SUCCESS;
+11 -11
View File
@@ -138,7 +138,7 @@ static int CmdLFTune(const char *Cmd) {
return PM3_EINVARG;
}
barMode_t style = session.bar_mode;
barMode_t style = g_session.bar_mode;
if (is_bar)
style = STYLE_BAR;
if (is_mix)
@@ -252,7 +252,7 @@ int CmdLFCommandRead(const char *Cmd) {
bool cm = arg_get_lit(ctx, 8);
CLIParserFree(ctx);
if (session.pm3_present == false)
if (g_session.pm3_present == false)
return PM3_ENOTTY;
#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) {
if (!session.pm3_present) return PM3_ENOTTY;
if (!g_session.pm3_present) return PM3_ENOTTY;
if (config == NULL)
return PM3_EINVARG;
@@ -493,7 +493,7 @@ int lf_getconfig(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();
if (config != NULL)
@@ -548,7 +548,7 @@ int CmdLFConfig(const char *Cmd) {
int16_t trigg = arg_get_int_def(ctx, 10, -1);
CLIParserFree(ctx);
if (session.pm3_present == false)
if (g_session.pm3_present == false)
return PM3_ENOTTY;
// 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) {
if (!session.pm3_present) return PM3_ENOTTY;
if (!g_session.pm3_present) return PM3_ENOTTY;
struct p {
uint32_t samples : 31;
@@ -681,7 +681,7 @@ int CmdLFRead(const char *Cmd) {
bool cm = arg_get_lit(ctx, 3);
CLIParserFree(ctx);
if (session.pm3_present == false)
if (g_session.pm3_present == false)
return PM3_ENOTTY;
if (cm) {
@@ -695,7 +695,7 @@ int CmdLFRead(const char *Cmd) {
}
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 {
uint32_t samples : 31;
@@ -750,7 +750,7 @@ int CmdLFSniff(const char *Cmd) {
bool cm = arg_get_lit(ctx, 3);
CLIParserFree(ctx);
if (session.pm3_present == false)
if (g_session.pm3_present == false)
return PM3_ENOTTY;
if (cm) {
@@ -842,7 +842,7 @@ int CmdLFSim(const char *Cmd) {
uint16_t gap = arg_get_u32_def(ctx, 1, 0);
CLIParserFree(ctx);
if (session.pm3_present == false) {
if (g_session.pm3_present == false) {
PrintAndLogEx(DEBUG, "DEBUG: no proxmark present");
return PM3_ENOTTY;
}
@@ -1397,7 +1397,7 @@ int CmdLFfind(const char *Cmd) {
bool search_unk = arg_get_lit(ctx, 3);
CLIParserFree(ctx);
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)
lf_read(false, 30000);
+1 -1
View File
@@ -520,7 +520,7 @@ static int CmdAWIDBrute(const char *Cmd) {
// main loop
for (;;) {
if (!session.pm3_present) {
if (!g_session.pm3_present) {
PrintAndLogEx(WARNING, "Device offline\n");
return PM3_ENODATA;
}
+2 -2
View File
@@ -1390,7 +1390,7 @@ int CmdEM4x05Chk(const char *Cmd) {
for (uint32_t c = 0; c < keycount; ++c) {
if (!session.pm3_present) {
if (!g_session.pm3_present) {
PrintAndLogEx(WARNING, "device offline\n");
free(keyBlock);
return PM3_ENODATA;
@@ -1569,7 +1569,7 @@ int CmdEM4x05Unlock(const char *Cmd) {
return PM3_EINVARG;
}
if (session.pm3_present == false) {
if (g_session.pm3_present == false) {
PrintAndLogEx(WARNING, "device offline\n");
return PM3_ENODATA;
}
+1 -1
View File
@@ -556,7 +556,7 @@ static int CmdHIDBrute(const char *Cmd) {
fin_hi = fin_low = false;
do {
if (!session.pm3_present) {
if (!g_session.pm3_present) {
PrintAndLogEx(WARNING, "Device offline\n");
return PM3_ENODATA;
}
+2 -2
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
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");
return PM3_ENODATA;
}
@@ -3197,7 +3197,7 @@ static int CmdT55xxChkPwds(const char *Cmd) {
for (uint32_t c = 0; c < keycount && found == false; ++c) {
if (!session.pm3_present) {
if (!g_session.pm3_present) {
PrintAndLogEx(WARNING, "device offline\n");
free(keyblock);
return PM3_ENODATA;
+3 -3
View File
@@ -229,12 +229,12 @@ static int CmdHints(const char *Cmd) {
}
if (turn_off) {
session.show_hints = false;
g_session.show_hints = false;
} 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;
}
+4 -4
View File
@@ -22,9 +22,9 @@ bool AlwaysAvailable(void) {
}
bool IfPm3Present(void) {
if (session.help_dump_mode)
if (g_session.help_dump_mode)
return false;
return session.pm3_present;
return g_session.pm3_present;
}
bool IfPm3Rdv4Fw(void) {
@@ -195,8 +195,8 @@ void CmdsHelp(const command_t Commands[]) {
int CmdsParse(const command_t Commands[], const char *Cmd) {
if (session.client_exe_delay != 0) {
msleep(session.client_exe_delay);
if (g_session.client_exe_delay != 0) {
msleep(g_session.client_exe_delay);
}
// Help dump children
+4 -4
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);
#endif
if (!session.pm3_present) {
if (!g_session.pm3_present) {
PrintAndLogEx(WARNING, "Sending bytes to Proxmark3 failed." _YELLOW_("offline"));
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");
#endif
if (!session.pm3_present) {
if (!g_session.pm3_present) {
PrintAndLogEx(INFO, "Sending bytes to proxmark failed - offline");
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);
__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);
if (*dev == NULL) {
@@ -689,7 +689,7 @@ void CloseProxmark(pm3_device *dev) {
memset(&communication_thread, 0, sizeof(pthread_t));
#endif
session.pm3_present = false;
g_session.pm3_present = false;
}
// Gives a rough estimate of the communication delay based on channel & baudrate
+5 -5
View File
@@ -237,14 +237,14 @@ bool create_path(const char *dirname) {
bool setDefaultPath(savePaths_t pathIndex, const char *Path) {
if (pathIndex < spItemCount) {
if ((Path == NULL) && (session.defaultPaths[pathIndex] != NULL)) {
free(session.defaultPaths[pathIndex]);
session.defaultPaths[pathIndex] = NULL;
if ((Path == NULL) && (g_session.defaultPaths[pathIndex] != NULL)) {
free(g_session.defaultPaths[pathIndex]);
g_session.defaultPaths[pathIndex] = NULL;
}
if (Path != NULL) {
session.defaultPaths[pathIndex] = (char *)realloc(session.defaultPaths[pathIndex], strlen(Path) + 1);
strcpy(session.defaultPaths[pathIndex], Path);
g_session.defaultPaths[pathIndex] = (char *)realloc(g_session.defaultPaths[pathIndex], strlen(Path) + 1);
strcpy(g_session.defaultPaths[pathIndex], Path);
}
return true;
}
+1 -1
View File
@@ -79,7 +79,7 @@ typedef enum {
int fileExists(const char *filename);
//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);
+3 -3
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.");
}
msleep(100);
CloseProxmark(session.current_device);
CloseProxmark(g_session.current_device);
// Let time to OS to make the port disappear
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"));
return PM3_SUCCESS;
} else {
@@ -552,7 +552,7 @@ int flash_write(flash_file_t *ctx) {
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++) {
flash_seg_t *seg = &ctx->segments[i];
+8 -8
View File
@@ -15,24 +15,24 @@
pm3_device *pm3_open(char *port) {
pm3_init();
OpenProxmark(&session.current_device, port, false, 20, false, USART_BAUD_RATE);
if (session.pm3_present && (TestProxmark(session.current_device) != PM3_SUCCESS)) {
OpenProxmark(&g_session.current_device, port, false, 20, false, USART_BAUD_RATE);
if (g_session.pm3_present && (TestProxmark(g_session.current_device) != PM3_SUCCESS)) {
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);
if (!session.pm3_present)
if (!g_session.pm3_present)
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode");
// For now, there is no real device context:
return session.current_device;
return g_session.current_device;
}
void pm3_close(pm3_device *dev) {
// Clean up the port
if (session.pm3_present) {
if (g_session.pm3_present) {
clearCommandBuffer();
SendCommandNG(CMD_QUIT_SESSION, NULL, 0);
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) {
return session.current_device;
return g_session.current_device;
}
+111 -111
View File
File diff suppressed because it is too large Load Diff
+23 -23
View File
@@ -192,7 +192,7 @@ void ProxGuiQT::MainLoop() {
// pictureWidget->setAttribute(Qt::WA_DeleteOnClose,true);
// Set picture widget position if no settings.
if (session.preferences_loaded == false) {
if (g_session.preferences_loaded == false) {
// Move controller widget below plot
//pictureController->move(x(), y() + frameSize().height());
//pictureController->resize(size().width(), 200);
@@ -250,8 +250,8 @@ ProxGuiQT::~ProxGuiQT(void) {
// -------------------------------------------------
PictureWidget::PictureWidget() {
// Set the initail postion and size from settings
// if (session.preferences_loaded)
// setGeometry(session.pw.x, session.pw.y, session.pw.w, session.pw.h);
// if (g_session.preferences_loaded)
// setGeometry(g_session.pw.x, g_session.pw.y, g_session.pw.w, g_session.pw.h);
// else
resize(400, 400);
}
@@ -269,23 +269,23 @@ void PictureWidget::closeEvent(QCloseEvent *event) {
SliderWidget::SliderWidget() {
// Set the initail postion and size from settings
if (session.preferences_loaded)
setGeometry(session.overlay.x, session.overlay.y, session.overlay.w, session.overlay.h);
if (g_session.preferences_loaded)
setGeometry(g_session.overlay.x, g_session.overlay.y, g_session.overlay.w, g_session.overlay.h);
else
resize(800, 400);
}
void SliderWidget::resizeEvent(QResizeEvent *event) {
session.overlay.h = event->size().height();
session.overlay.w = event->size().width();
session.window_changed = true;
g_session.overlay.h = event->size().height();
g_session.overlay.w = event->size().width();
g_session.window_changed = true;
}
void SliderWidget::moveEvent(QMoveEvent *event) {
session.overlay.x = event->pos().x();
session.overlay.y = event->pos().y();
session.window_changed = true;
g_session.overlay.x = event->pos().x();
g_session.overlay.y = event->pos().y();
g_session.window_changed = true;
}
//--------------------
@@ -331,8 +331,8 @@ void ProxWidget::vchange_dthr_down(int v) {
ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
this->master = master;
// Set the initail postion and size from settings
if (session.preferences_loaded)
setGeometry(session.plot.x, session.plot.y, session.plot.w, session.plot.h);
if (g_session.preferences_loaded)
setGeometry(g_session.plot.x, g_session.plot.y, g_session.plot.w, g_session.plot.h);
else
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_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
plot = new Plot(this);
@@ -373,7 +373,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
show();
// Set Slider/Overlay position if no settings.
if (session.preferences_loaded == false) {
if (g_session.preferences_loaded == false) {
// Move controller widget below plot
controlWidget->move(x(), y() + frameSize().height());
controlWidget->resize(size().width(), 200);
@@ -387,7 +387,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
// controlWidget->show();
// 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();
}
void ProxWidget::showEvent(QShowEvent *event) {
if (session.overlay_sliders)
if (g_session.overlay_sliders)
controlWidget->show();
else
controlWidget->hide();
@@ -430,14 +430,14 @@ void ProxWidget::showEvent(QShowEvent *event) {
plot->show();
}
void ProxWidget::moveEvent(QMoveEvent *event) {
session.plot.x = event->pos().x();
session.plot.y = event->pos().y();
session.window_changed = true;
g_session.plot.x = event->pos().x();
g_session.plot.y = event->pos().y();
g_session.window_changed = true;
}
void ProxWidget::resizeEvent(QResizeEvent *event) {
session.plot.h = event->size().height();
session.plot.w = event->size().width();
session.window_changed = true;
g_session.plot.h = event->size().height();
g_session.plot.w = event->size().width();
g_session.window_changed = true;
}
//----------- Plotting
+55 -55
View File
@@ -126,27 +126,27 @@ static void prompt_compose(char *buf, size_t buflen, const char *promptctx, cons
static int check_comm(void) {
// 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");
prompt_dev = PROXPROMPT_DEV_OFFLINE;
#ifdef HAVE_READLINE
char prompt[PROXPROMPT_MAX_SIZE] = {0};
prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev);
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_redisplay();
#endif
CloseProxmark(session.current_device);
CloseProxmark(g_session.current_device);
}
msleep(10);
return 0;
}
#ifdef HAVE_READLINE
static void flush_history(void) {
if (session.history_path) {
write_history(session.history_path);
free(session.history_path);
if (g_session.history_path) {
write_history(g_session.history_path);
free(g_session.history_path);
}
}
@@ -178,7 +178,7 @@ static bool DetectWindowsAnsiSupport(void) {
#endif
// disable colors if stdin or stdout are redirected
if ((! session.stdinOnTTY) || (! session.stdoutOnTTY))
if ((! g_session.stdinOnTTY) || (! g_session.stdoutOnTTY))
return false;
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);
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:
if (execCommand || script_cmds_file || stdinOnPipe)
pm3_version(false, false);
@@ -272,13 +272,13 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
}
#ifdef HAVE_READLINE
session.history_path = NULL;
if (session.incognito) {
g_session.history_path = NULL;
if (g_session.incognito) {
PrintAndLogEx(INFO, "No history will be recorded");
} 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");
session.history_path = NULL;
g_session.history_path = NULL;
} else {
# if defined(_WIN32)
@@ -291,7 +291,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
# endif
rl_catch_signals = 1;
rl_set_signals();
read_history(session.history_path);
read_history(g_session.history_path);
}
}
#endif
@@ -300,7 +300,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
while (1) {
bool printprompt = false;
if (session.pm3_present) {
if (g_session.pm3_present) {
if (g_conn.send_via_fpc_usart == false)
prompt_dev = PROXPROMPT_DEV_USB;
else
@@ -380,13 +380,13 @@ check_script:
char prompt[PROXPROMPT_MAX_SIZE] = {0};
prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev);
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;
#ifdef HAVE_READLINE
script_cmd = readline(prompt_filtered);
#if defined(_WIN32)
//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
if (script_cmd != NULL) {
execCommand = true;
@@ -475,7 +475,7 @@ check_script:
}
} // end while
if (session.pm3_present) {
if (g_session.pm3_present) {
clearCommandBuffer();
SendCommandNG(CMD_QUIT_SESSION, NULL, 0);
msleep(100); // Make sure command is sent before killing client
@@ -496,14 +496,14 @@ check_script:
#ifndef LIBPM3
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, "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, "\n");
command_t *cmds = getTopLevelCommandTable();
dumpCommandsRecursive(cmds, markdown, full_help);
session.help_dump_mode = false;
g_session.help_dump_mode = false;
PrintAndLogEx(NORMAL, "Full help dump done.");
}
#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]);
}
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"));
} else {
PrintAndLogEx(ERR, "Could not find Proxmark3 on " _RED_("%s") ".\n", serial_port_name);
@@ -718,7 +718,7 @@ finish:
if (ret != PM3_SUCCESS)
PrintAndLogEx(INFO, "The flashing procedure failed, follow the suggested steps!");
ret = flash_stop_flashing();
CloseProxmark(session.current_device);
CloseProxmark(g_session.current_device);
finish2:
for (int i = 0 ; i < num_files; ++i) {
if (filepaths[i] != NULL)
@@ -736,13 +736,13 @@ finish2:
void pm3_init(void) {
srand(time(0));
session.pm3_present = false;
session.help_dump_mode = false;
session.incognito = false;
session.supports_colors = false;
session.emoji_mode = EMO_ALTTEXT;
session.stdinOnTTY = false;
session.stdoutOnTTY = false;
g_session.pm3_present = false;
g_session.help_dump_mode = false;
g_session.incognito = false;
g_session.supports_colors = false;
g_session.emoji_mode = EMO_ALTTEXT;
g_session.stdinOnTTY = false;
g_session.stdoutOnTTY = false;
// set global variables soon enough to get the log 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":
// struct stat tmp_stat;
// if ((fstat (STDOUT_FILENO, &tmp_stat) == 0) && (S_ISCHR (tmp_stat.st_mode)) && isatty(STDIN_FILENO))
session.stdinOnTTY = isatty(STDIN_FILENO);
session.stdoutOnTTY = isatty(STDOUT_FILENO);
session.supports_colors = false;
session.emoji_mode = EMO_ALTTEXT;
if (session.stdinOnTTY && session.stdoutOnTTY) {
g_session.stdinOnTTY = isatty(STDIN_FILENO);
g_session.stdoutOnTTY = isatty(STDOUT_FILENO);
g_session.supports_colors = false;
g_session.emoji_mode = EMO_ALTTEXT;
if (g_session.stdinOnTTY && g_session.stdoutOnTTY) {
#if defined(__linux__) || defined(__APPLE__)
session.supports_colors = true;
session.emoji_mode = EMO_EMOJI;
g_session.supports_colors = true;
g_session.emoji_mode = EMO_EMOJI;
#elif defined(_WIN32)
session.supports_colors = DetectWindowsAnsiSupport();
session.emoji_mode = EMO_ALTTEXT;
g_session.supports_colors = DetectWindowsAnsiSupport();
g_session.emoji_mode = EMO_ALTTEXT;
#endif
}
for (int i = 1; i < argc; i++) {
@@ -960,7 +960,7 @@ int main(int argc, char *argv[]) {
// do not use history nor log files
if (strcmp(argv[i], "--incognito") == 0) {
session.incognito = true;
g_session.incognito = true;
continue;
}
@@ -1002,14 +1002,14 @@ int main(int argc, char *argv[]) {
preferences_load();
// quick patch for debug level
if (! debug_mode_forced)
g_debugMode = session.client_debug_level;
g_debugMode = g_session.client_debug_level;
// settings_save ();
// End Settings
// even if prefs, we disable colors if stdin or stdout is not a TTY
if ((! session.stdinOnTTY) || (! session.stdoutOnTTY)) {
session.supports_colors = false;
session.emoji_mode = EMO_ALTTEXT;
if ((! g_session.stdinOnTTY) || (! g_session.stdoutOnTTY)) {
g_session.supports_colors = false;
g_session.emoji_mode = EMO_ALTTEXT;
}
// 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
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");
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);
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);
// 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();
// Save settings if not loaded 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.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
preferences_save(); // Save defaults
session.preferences_loaded = true;
g_session.preferences_loaded = true;
} /* else {
// Set device debug level
PrintAndLogEx(INFO,"setting device debug loglevel");
if (session.pm3_present) {
SendCommandNG(CMD_SET_DBGMODE, &session.device_debug_level, 1);
if (g_session.pm3_present) {
SendCommandNG(CMD_SET_DBGMODE, &g_session.device_debug_level, 1);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_SET_DBGMODE, &resp, 2000) == false)
PrintAndLogEx (INFO,"failed to set device debug loglevel");
@@ -1108,11 +1108,11 @@ int main(int argc, char *argv[]) {
#endif
// Clean up the port
if (session.pm3_present) {
CloseProxmark(session.current_device);
if (g_session.pm3_present) {
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();
exit(EXIT_SUCCESS);
}
+14 -14
View File
@@ -39,7 +39,7 @@
#include <time.h>
#include "emojis.h"
#include "emojis_alt.h"
session_arg_t session;
session_arg_t g_session;
double g_CursorScaleFactor = 1;
char g_CursorScaleFactorUnit[11] = {0};
@@ -187,7 +187,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
return;
// 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;
char prefix[40] = {0};
@@ -202,14 +202,14 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
};
switch (level) {
case ERR:
if (session.emoji_mode == EMO_EMOJI)
if (g_session.emoji_mode == EMO_EMOJI)
strncpy(prefix, "[" _RED_("!!") "] :rotating_light: ", sizeof(prefix) - 1);
else
strncpy(prefix, "[" _RED_("!!") "] ", sizeof(prefix) - 1);
stream = stderr;
break;
case FAILED:
if (session.emoji_mode == EMO_EMOJI)
if (g_session.emoji_mode == EMO_EMOJI)
strncpy(prefix, "[" _RED_("-") "] :no_entry: ", sizeof(prefix) - 1);
else
strncpy(prefix, "[" _RED_("-") "] ", sizeof(prefix) - 1);
@@ -224,7 +224,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
strncpy(prefix, "[" _GREEN_("+") "] ", sizeof(prefix) - 1);
break;
case WARNING:
if (session.emoji_mode == EMO_EMOJI)
if (g_session.emoji_mode == EMO_EMOJI)
strncpy(prefix, "[" _CYAN_("!") "] :warning: ", sizeof(prefix) - 1);
else
strncpy(prefix, "[" _CYAN_("!") "] ", sizeof(prefix) - 1);
@@ -233,7 +233,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
strncpy(prefix, "[" _YELLOW_("=") "] ", sizeof(prefix) - 1);
break;
case INPLACE:
if (session.emoji_mode == EMO_EMOJI) {
if (g_session.emoji_mode == EMO_EMOJI) {
strncpy(prefix, spinner_emoji[PrintAndLogEx_spinidx], sizeof(prefix) - 1);
PrintAndLogEx_spinidx++;
if (PrintAndLogEx_spinidx >= ARRAYLEN(spinner_emoji))
@@ -288,8 +288,8 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
if (level == INPLACE) {
char buffer3[sizeof(buffer2)] = {0};
char buffer4[sizeof(buffer2)] = {0};
memcpy_filter_ansi(buffer3, buffer2, sizeof(buffer2), !session.supports_colors);
memcpy_filter_emoji(buffer4, buffer3, sizeof(buffer3), session.emoji_mode);
memcpy_filter_ansi(buffer3, buffer2, sizeof(buffer2), !g_session.supports_colors);
memcpy_filter_emoji(buffer4, buffer3, sizeof(buffer3), g_session.emoji_mode);
fprintf(stream, "\r%s", buffer4);
fflush(stream);
} else {
@@ -309,7 +309,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
pthread_mutex_lock(&g_print_lock);
bool linefeed = true;
if (logging && session.incognito) {
if (logging && g_session.incognito) {
logging = 0;
}
if ((g_printAndLog & PRINTANDLOG_LOG) && logging && !logfile) {
@@ -330,7 +330,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
logging = 0;
} else {
if (session.supports_colors) {
if (g_session.supports_colors) {
printf("["_YELLOW_("=")"] Session log " _YELLOW_("%s") "\n", my_logfile_path);
} else {
printf("[=] Session log %s\n", my_logfile_path);
@@ -367,10 +367,10 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
linefeed = false;
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);
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);
if (linefeed)
fprintf(stream, "\n");
@@ -661,7 +661,7 @@ void print_progress(size_t count, uint64_t max, barMode_t style) {
"\xe2\x96\x88",
};
int mode = (session.emoji_mode == EMO_EMOJI);
int mode = (g_session.emoji_mode == EMO_EMOJI);
const char *block[] = {"#", "\xe2\x96\x88"};
// 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));
// Add colors
if (session.supports_colors) {
if (g_session.supports_colors) {
int p60 = unit * (width * 60 / 100);
int p20 = unit * (width * 20 / 100);
snprintf(cbar, collen, _GREEN_("%.*s"), p60, bar);
+1 -1
View File
@@ -53,7 +53,7 @@ typedef struct {
pm3_device *current_device;
} session_arg_t;
extern session_arg_t session;
extern session_arg_t g_session;
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327
#endif