diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index a347e799a..b1b76d3e5 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -181,7 +181,7 @@ static const hintAIDList_t hintAIDList[] = { }; // iso14a apdu input frame length -static uint16_t g_frame_len = 0; +static uint16_t gs_frame_len = 0; static uint16_t atsFSC[] = {16, 24, 32, 40, 48, 64, 96, 128, 256}; static int CmdHF14AList(const char *Cmd) { @@ -776,7 +776,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav *dataoutlen = 0; if (activateField) { - // select with no disconnect and set g_frame_len + // select with no disconnect and set gs_frame_len int selres = SelectCard14443A_4(false, !silentMode, NULL); if (selres != PM3_SUCCESS) return selres; @@ -835,7 +835,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav int SelectCard14443A_4(bool disconnect, bool verbose, iso14a_card_select_t *card) { // global vars should be prefixed with g_ - g_frame_len = 0; + gs_frame_len = 0; if (card) { memset(card, 0, sizeof(iso14a_card_select_t)); @@ -884,7 +884,7 @@ int SelectCard14443A_4(bool disconnect, bool verbose, iso14a_card_select_t *card if (resp.oldarg[0] > 1) { uint8_t fsci = resp.data.asBytes[1] & 0x0f; if (fsci < ARRAYLEN(atsFSC)) { - g_frame_len = atsFSC[fsci]; + gs_frame_len = atsFSC[fsci]; } } } else { @@ -893,7 +893,7 @@ int SelectCard14443A_4(bool disconnect, bool verbose, iso14a_card_select_t *card if (vcard->ats_len > 1) { uint8_t fsci = vcard->ats[1] & 0x0f; if (fsci < ARRAYLEN(atsFSC)) { - g_frame_len = atsFSC[fsci]; + gs_frame_len = atsFSC[fsci]; } } @@ -915,7 +915,7 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool *chainingout = false; if (activateField) { - // select with no disconnect and set g_frame_len + // select with no disconnect and set gs_frame_len int selres = SelectCard14443A_4(false, true, NULL); if (selres != PM3_SUCCESS) return selres; @@ -1002,14 +1002,14 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea // 3 byte here - 1b framing header, 2b crc16 if (APDUInFramingEnable && - ((g_frame_len && (datainlen > g_frame_len - 3)) || (datainlen > PM3_CMD_DATA_SIZE - 3))) { + ((gs_frame_len && (datainlen > gs_frame_len - 3)) || (datainlen > PM3_CMD_DATA_SIZE - 3))) { int clen = 0; bool vActivateField = activateField; do { - int vlen = MIN(g_frame_len - 3, datainlen - clen); + int vlen = MIN(gs_frame_len - 3, datainlen - clen); bool chainBlockNotLast = ((clen + vlen) < datainlen); *dataoutlen = 0; diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 6f89059a0..1eeb4f29d 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -60,7 +60,7 @@ #include "cmdlfvisa2000.h" // for VISA2000 menu #include "pm3_cmd.h" // for LF_CMDREAD_MAX_EXTRA_SYMBOLS -static bool g_lf_threshold_set = false; +static bool gs_lf_threshold_set = false; static int CmdHelp(const char *Cmd); @@ -578,7 +578,7 @@ int CmdLFConfig(const char *Cmd) { config.divisor = LF_DIVISOR_125; config.samples_to_skip = 0; config.trigger_threshold = 0; - g_lf_threshold_set = false; + gs_lf_threshold_set = false; } if (use_125) @@ -621,7 +621,7 @@ int CmdLFConfig(const char *Cmd) { if (trigg > -1) { config.trigger_threshold = trigg; - g_lf_threshold_set = (config.trigger_threshold > 0); + gs_lf_threshold_set = (config.trigger_threshold > 0); } config.samples_to_skip = skip; @@ -643,7 +643,7 @@ int lf_read(bool verbose, uint32_t samples) { clearCommandBuffer(); SendCommandNG(CMD_LF_ACQ_RAW_ADC, (uint8_t *)&payload, sizeof(payload)); PacketResponseNG resp; - if (g_lf_threshold_set) { + if (gs_lf_threshold_set) { WaitForResponse(CMD_LF_ACQ_RAW_ADC, &resp); } else { if (!WaitForResponseTimeout(CMD_LF_ACQ_RAW_ADC, &resp, 2500)) { @@ -709,7 +709,7 @@ int lf_sniff(bool verbose, uint32_t samples) { clearCommandBuffer(); SendCommandNG(CMD_LF_SNIFF_RAW_ADC, (uint8_t *)&payload, sizeof(payload)); PacketResponseNG resp; - if (g_lf_threshold_set) { + if (gs_lf_threshold_set) { WaitForResponse(CMD_LF_SNIFF_RAW_ADC, &resp); } else { if (!WaitForResponseTimeout(CMD_LF_SNIFF_RAW_ADC, &resp, 2500)) { diff --git a/client/src/cmdlfem410x.c b/client/src/cmdlfem410x.c index 97244fb06..e03b41a6e 100644 --- a/client/src/cmdlfem410x.c +++ b/client/src/cmdlfem410x.c @@ -35,7 +35,7 @@ #include "cliparser.h" #include "cmdhw.h" -static uint64_t g_em410xid = 0; +static uint64_t gs_em410xid = 0; static int CmdHelp(const char *Cmd); /* Read the ID of an EM410x tag. @@ -273,7 +273,7 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo) { } printEM410x(*hi, *lo, verbose, ans); - g_em410xid = *lo; + gs_em410xid = *lo; return PM3_SUCCESS; } @@ -407,7 +407,7 @@ static int CmdEM410xReader(const char *Cmd) { lf_read(false, 12288); AskEm410xDemod(clk, invert, max_err, max_len, amplify, &hi, &lo, verbose); - if (break_first && g_em410xid != 0) { + if (break_first && gs_em410xid != 0) { break; } } while (cm && !kbd_enter_pressed()); @@ -615,9 +615,9 @@ static int CmdEM410xSpoof(const char *Cmd) { CLIParserFree(ctx); // loops if the captured ID was in XL-format. - g_em410xid = 0; + gs_em410xid = 0; CmdEM410xReader("-b@"); - PrintAndLogEx(SUCCESS, "Replaying captured EM Tag ID "_YELLOW_("%010" PRIx64), g_em410xid); + PrintAndLogEx(SUCCESS, "Replaying captured EM Tag ID "_YELLOW_("%010" PRIx64), gs_em410xid); CmdLFSim(""); return PM3_SUCCESS; } diff --git a/client/src/cmdtrace.c b/client/src/cmdtrace.c index 38df3d9df..68f254e9c 100644 --- a/client/src/cmdtrace.c +++ b/client/src/cmdtrace.c @@ -26,8 +26,8 @@ static int CmdHelp(const char *Cmd); // trace pointer -static uint8_t *g_trace; -static long g_traceLen = 0; +static uint8_t *gs_trace; +static long gs_traceLen = 0; static bool is_last_record(uint16_t tracepos, uint16_t traceLen) { return ((tracepos + TRACELOG_HDR_LEN) >= traceLen); @@ -503,13 +503,13 @@ static int download_trace(void) { } // reserve some space. - if (g_trace) - free(g_trace); + if (gs_trace) + free(gs_trace); - g_traceLen = 0; + gs_traceLen = 0; - g_trace = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); - if (g_trace == NULL) { + gs_trace = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); + if (gs_trace == NULL) { PrintAndLogEx(FAILED, "Cannot allocate memory for trace"); return PM3_EMALLOC; } @@ -518,29 +518,29 @@ static int download_trace(void) { // Query for the size of the trace, downloading PM3_CMD_DATA_SIZE PacketResponseNG response; - if (!GetFromDevice(BIG_BUF, g_trace, PM3_CMD_DATA_SIZE, 0, NULL, 0, &response, 4000, true)) { + if (!GetFromDevice(BIG_BUF, gs_trace, PM3_CMD_DATA_SIZE, 0, NULL, 0, &response, 4000, true)) { PrintAndLogEx(WARNING, "timeout while waiting for reply."); - free(g_trace); - g_trace = NULL; + free(gs_trace); + gs_trace = NULL; return PM3_ETIMEOUT; } - g_traceLen = response.oldarg[2]; + gs_traceLen = response.oldarg[2]; // if tracelog buffer was larger and we need to download more. - if (g_traceLen > PM3_CMD_DATA_SIZE) { + if (gs_traceLen > PM3_CMD_DATA_SIZE) { - free(g_trace); - g_trace = calloc(g_traceLen, sizeof(uint8_t)); - if (g_trace == NULL) { + free(gs_trace); + gs_trace = calloc(gs_traceLen, sizeof(uint8_t)); + if (gs_trace == NULL) { PrintAndLogEx(FAILED, "Cannot allocate memory for trace"); return PM3_EMALLOC; } - if (!GetFromDevice(BIG_BUF, g_trace, g_traceLen, 0, NULL, 0, NULL, 2500, false)) { + if (!GetFromDevice(BIG_BUF, gs_trace, gs_traceLen, 0, NULL, 0, NULL, 2500, false)) { PrintAndLogEx(WARNING, "command execution time out"); - free(g_trace); - g_trace = NULL; + free(gs_trace); + gs_trace = NULL; return PM3_ETIMEOUT; } } @@ -579,20 +579,20 @@ static int CmdTraceLoad(const char *Cmd) { CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); CLIParserFree(ctx); - if (g_trace) { - free(g_trace); - g_trace = NULL; + if (gs_trace) { + free(gs_trace); + gs_trace = NULL; } size_t len = 0; - if (loadFile_safe(filename, ".trace", (void **)&g_trace, &len) != PM3_SUCCESS) { + if (loadFile_safe(filename, ".trace", (void **)&gs_trace, &len) != PM3_SUCCESS) { PrintAndLogEx(FAILED, "Could not open file " _YELLOW_("%s"), filename); return PM3_EIO; } - g_traceLen = (long)len; + gs_traceLen = (long)len; - PrintAndLogEx(SUCCESS, "Recorded Activity (TraceLen = " _YELLOW_("%lu") " bytes)", g_traceLen); + PrintAndLogEx(SUCCESS, "Recorded Activity (TraceLen = " _YELLOW_("%lu") " bytes)", gs_traceLen); return PM3_SUCCESS; } @@ -617,15 +617,15 @@ static int CmdTraceSave(const char *Cmd) { CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); CLIParserFree(ctx); - if (g_traceLen == 0) { + if (gs_traceLen == 0) { download_trace(); - if (g_traceLen == 0) { + if (gs_traceLen == 0) { PrintAndLogEx(WARNING, "trace is empty, nothing to save"); return PM3_SUCCESS; } } - saveFile(filename, ".trace", g_trace, g_traceLen); + saveFile(filename, ".trace", gs_trace, gs_traceLen); return PM3_SUCCESS; } @@ -756,13 +756,13 @@ int CmdTraceList(const char *Cmd) { if (use_buffer == false) { download_trace(); - } else if (g_traceLen == 0) { + } else if (gs_traceLen == 0) { PrintAndLogEx(FAILED, "You requested a trace list in offline mode but there is no trace, consider using 'trace load' or removing parameter '-1'"); return PM3_EINVARG; } - PrintAndLogEx(SUCCESS, "Recorded activity (trace len = " _YELLOW_("%lu") " bytes)", g_traceLen); - if (g_traceLen == 0) { + PrintAndLogEx(SUCCESS, "Recorded activity (trace len = " _YELLOW_("%lu") " bytes)", gs_traceLen); + if (gs_traceLen == 0) { return PM3_SUCCESS; } @@ -770,12 +770,12 @@ int CmdTraceList(const char *Cmd) { /* if (protocol == FELICA) { - printFelica(g_traceLen, g_trace); + printFelica(gs_traceLen, gs_trace); } */ if (show_hex) { - while (tracepos < g_traceLen) { - tracepos = printHexLine(tracepos, g_traceLen, g_trace, protocol); + while (tracepos < gs_traceLen) { + tracepos = printHexLine(tracepos, gs_traceLen, gs_trace, protocol); } } else { @@ -877,8 +877,8 @@ int CmdTraceList(const char *Cmd) { prev_EOT = &previous_EOT; } - while (tracepos < g_traceLen) { - tracepos = printTraceLine(tracepos, g_traceLen, g_trace, protocol, show_wait_cycles, mark_crc, prev_EOT, use_us, dicKeys, dicKeysCount); + while (tracepos < gs_traceLen) { + tracepos = printTraceLine(tracepos, gs_traceLen, gs_trace, protocol, show_wait_cycles, mark_crc, prev_EOT, use_us, dicKeys, dicKeysCount); if (kbd_enter_pressed()) break; diff --git a/client/src/flash.c b/client/src/flash.c index 6c3f9a689..869cd1630 100644 --- a/client/src/flash.c +++ b/client/src/flash.c @@ -404,9 +404,9 @@ static int wait_for_ack(PacketResponseNG *ack) { return PM3_SUCCESS; } -static bool g_printed_msg = false; +static bool gs_printed_msg = false; static void flash_suggest_update_bootloader(void) { - if (g_printed_msg) + if (gs_printed_msg) return; PrintAndLogEx(ERR, _RED_("It is recommended that you first" _YELLOW_(" update your bootloader") _RED_(" alone,"))); @@ -416,7 +416,7 @@ static void flash_suggest_update_bootloader(void) { PrintAndLogEx(ERR, " 2) ./pm3-flash-all"); PrintAndLogEx(ERR, " 3) ./pm3"); PrintAndLogEx(INFO, "--------------------------------------------------------"); - g_printed_msg = true; + gs_printed_msg = true; } static void flash_suggest_update_flasher(void) { diff --git a/client/src/proxguiqt.cpp b/client/src/proxguiqt.cpp index 44d90a0bb..e25603ed9 100644 --- a/client/src/proxguiqt.cpp +++ b/client/src/proxguiqt.cpp @@ -38,8 +38,8 @@ extern "C" int preferences_save(void); static int s_Buff[MAX_GRAPH_TRACE_LEN]; -static bool g_useOverlays = false; -static int g_absVMax = 0; +static bool gs_useOverlays = false; +static int gs_absVMax = 0; static uint32_t startMax; // Maximum offset in the graph (right side of graph) static uint32_t PageWidth; // How many samples are currently visible on this 'page' / graph static int unlockStart = 0; @@ -302,28 +302,28 @@ void ProxWidget::stickOperation() { void ProxWidget::vchange_autocorr(int v) { int ans = AutoCorrelate(g_GraphBuffer, s_Buff, g_GraphTraceLen, v, true, false); if (g_debugMode) printf("vchange_autocorr(w:%d): %d\n", v, ans); - g_useOverlays = true; + gs_useOverlays = true; RepaintGraphWindow(); } void ProxWidget::vchange_askedge(int v) { //extern int AskEdgeDetect(const int *in, int *out, int len, int threshold); int ans = AskEdgeDetect(g_GraphBuffer, s_Buff, g_GraphTraceLen, v); if (g_debugMode) printf("vchange_askedge(w:%d)%d\n", v, ans); - g_useOverlays = true; + gs_useOverlays = true; RepaintGraphWindow(); } void ProxWidget::vchange_dthr_up(int v) { int down = opsController->horizontalSlider_dirthr_down->value(); directionalThreshold(g_GraphBuffer, s_Buff, g_GraphTraceLen, v, down); //printf("vchange_dthr_up(%d)", v); - g_useOverlays = true; + gs_useOverlays = true; RepaintGraphWindow(); } void ProxWidget::vchange_dthr_down(int v) { //printf("vchange_dthr_down(%d)", v); int up = opsController->horizontalSlider_dirthr_up->value(); directionalThreshold(g_GraphBuffer, s_Buff, g_GraphTraceLen, v, up); - g_useOverlays = true; + gs_useOverlays = true; RepaintGraphWindow(); } @@ -415,7 +415,7 @@ ProxWidget::~ProxWidget(void) { void ProxWidget::closeEvent(QCloseEvent *event) { event->ignore(); this->hide(); - g_useOverlays = false; + gs_useOverlays = false; } void ProxWidget::hideEvent(QHideEvent *event) { controlWidget->hide(); @@ -504,10 +504,10 @@ void Plot::setMaxAndStart(int *buffer, size_t len, QRect plotRect) { if (v > vMax) vMax = v; } - g_absVMax = 0; - if (fabs((double) vMin) > g_absVMax) g_absVMax = (int)fabs((double) vMin); - if (fabs((double) vMax) > g_absVMax) g_absVMax = (int)fabs((double) vMax); - g_absVMax = (int)(g_absVMax * 1.25 + 1); + gs_absVMax = 0; + if (fabs((double) vMin) > gs_absVMax) gs_absVMax = (int)fabs((double) vMin); + if (fabs((double) vMax) > gs_absVMax) gs_absVMax = (int)fabs((double) vMax); + gs_absVMax = (int)(gs_absVMax * 1.25 + 1); } void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, uint32_t plotOffset) { @@ -572,14 +572,14 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe int64_t vMean = 0; uint32_t i = 0; int x = xCoordOf(g_GraphStart, plotRect); - int y = yCoordOf(buffer[g_GraphStart], plotRect, g_absVMax); + int y = yCoordOf(buffer[g_GraphStart], plotRect, gs_absVMax); penPath.moveTo(x, y); for (i = g_GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) { x = xCoordOf(i, plotRect); v = buffer[i]; - y = yCoordOf(v, plotRect, g_absVMax); + y = yCoordOf(v, plotRect, gs_absVMax); penPath.lineTo(x, y); @@ -601,7 +601,7 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe int xo = 5 + (graphNum * 40); painter->drawLine(xo, plotRect.top(), xo, plotRect.bottom()); - int vMarkers = (g_absVMax - (g_absVMax % 10)) / 5; + int vMarkers = (gs_absVMax - (gs_absVMax % 10)) / 5; int minYDist = 40; // Minimum pixel-distance between markers char yLbl[20]; @@ -609,9 +609,9 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe int n = 0; int lasty0 = 65535; - for (v = vMarkers; yCoordOf(v, plotRect, g_absVMax) > plotRect.top() && n < 20; v += vMarkers, n++) { - int y0 = yCoordOf(v, plotRect, g_absVMax); - int y1 = yCoordOf(-v, plotRect, g_absVMax); + for (v = vMarkers; yCoordOf(v, plotRect, gs_absVMax) > plotRect.top() && n < 20; v += vMarkers, n++) { + int y0 = yCoordOf(v, plotRect, gs_absVMax); + int y1 = yCoordOf(-v, plotRect, gs_absVMax); if (lasty0 - y0 < minYDist) continue; @@ -662,11 +662,11 @@ void Plot::plotGridLines(QPainter *painter, QRect r) { } if (g_PlotGridY > 0) { - for (i = 0; yCoordOf(i, r, g_absVMax) > r.top(); i += grid_delta_y) { + for (i = 0; yCoordOf(i, r, gs_absVMax) > r.top(); i += grid_delta_y) { // line above mid - painter->drawLine(r.left(), yCoordOf(i, r, g_absVMax), r.right(), yCoordOf(i, r, g_absVMax)); + painter->drawLine(r.left(), yCoordOf(i, r, gs_absVMax), r.right(), yCoordOf(i, r, gs_absVMax)); // line below mid - painter->drawLine(r.left(), yCoordOf(-i, r, g_absVMax), r.right(), yCoordOf(-i, r, g_absVMax)); + painter->drawLine(r.left(), yCoordOf(-i, r, gs_absVMax), r.right(), yCoordOf(-i, r, gs_absVMax)); } } } @@ -714,7 +714,7 @@ void Plot::paintEvent(QPaintEvent *event) { if (g_DemodBufferLen > 8) { PlotDemod(g_DemodBuffer, g_DemodBufferLen, plotRect, infoRect, &painter, 2, g_DemodStartIdx); } - if (g_useOverlays) { + if (gs_useOverlays) { //init graph variables setMaxAndStart(s_Buff, g_GraphTraceLen, plotRect); PlotGraph(s_Buff, g_GraphTraceLen, plotRect, infoRect, &painter, 1); @@ -790,7 +790,7 @@ Plot::Plot(QWidget *parent) : QWidget(parent), g_GraphPixelsPerPoint(1) { void Plot::closeEvent(QCloseEvent *event) { event->ignore(); this->hide(); - g_useOverlays = false; + gs_useOverlays = false; } void Plot::Zoom(double factor, uint32_t refX) {