From d234e2a8f5a03a83017bdfad4410bb8f5bd2b278 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 1 Jun 2020 20:30:11 +0200 Subject: [PATCH] less global vars --- client/src/cmdhf14a.c | 6 ++++-- client/src/cmdhfmf.c | 13 ++++++------- client/src/cmdhfmf.h | 4 ++-- client/src/cmdparser.c | 4 ++-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index 500406439..b293e4c01 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -438,6 +438,8 @@ int CmdHF14ASim(const char *Cmd) { bool setEmulatorMem = false; bool verbose = false; bool errors = false; + sector_t *k_sector = NULL; + uint8_t k_sectorsCount = 40; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { @@ -521,7 +523,7 @@ int CmdHF14ASim(const char *Cmd) { if ((flags & FLAG_NR_AR_ATTACK) != FLAG_NR_AR_ATTACK) break; nonces_t *data = (nonces_t *)resp.data.asBytes; - readerAttack(data[0], setEmulatorMem, verbose); + readerAttack(k_sector, k_sectorsCount, data[0], setEmulatorMem, verbose); keypress = kbd_enter_pressed(); } @@ -532,7 +534,7 @@ int CmdHF14ASim(const char *Cmd) { } if (resp.status == PM3_EOPABORTED && ((flags & FLAG_NR_AR_ATTACK) == FLAG_NR_AR_ATTACK)) - showSectorTable(); + showSectorTable(k_sector, k_sectorsCount); PrintAndLogEx(INFO, "Done"); return PM3_SUCCESS; diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index 58278c9cc..e3813a5a2 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -3129,10 +3129,7 @@ out: return PM3_SUCCESS; } -sector_t *k_sector = NULL; -uint8_t k_sectorsCount = 40; - -void showSectorTable(void) { +void showSectorTable(sector_t *k_sector, uint8_t k_sectorsCount) { if (k_sector != NULL) { printKeyTable(k_sectorsCount, k_sector); free(k_sector); @@ -3140,7 +3137,7 @@ void showSectorTable(void) { } } -void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose) { +void readerAttack(sector_t *k_sector, uint8_t k_sectorsCount, nonces_t data, bool setEmulatorMem, bool verbose) { uint64_t key = 0; bool success = false; @@ -3196,6 +3193,8 @@ static int CmdHF14AMfSim(const char *Cmd) { nonces_t data[1]; char csize[13] = { 0 }; char uidsize[8] = { 0 }; + sector_t *k_sector = NULL; + uint8_t k_sectorsCount = 40; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { @@ -3343,9 +3342,9 @@ static int CmdHF14AMfSim(const char *Cmd) { if ((resp.oldarg[0] & 0xffff) != CMD_HF_MIFARE_SIMULATE) break; memcpy(data, resp.data.asBytes, sizeof(data)); - readerAttack(data[0], setEmulatorMem, verbose); + readerAttack(k_sector, k_sectorsCount, data[0], setEmulatorMem, verbose); } - showSectorTable(); + showSectorTable(k_sector, k_sectorsCount); } k_sectorsCount = MIFARE_4K_MAXSECTOR; diff --git a/client/src/cmdhfmf.h b/client/src/cmdhfmf.h index c650b90f9..5325a7956 100644 --- a/client/src/cmdhfmf.h +++ b/client/src/cmdhfmf.h @@ -19,8 +19,8 @@ int CmdHFMF(const char *Cmd); int CmdHF14AMfELoad(const char *Cmd); // used by cmd hf mfu eload int CmdHF14AMfDbg(const char *Cmd); // used by cmd hf mfu dbg -void showSectorTable(void); -void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose); +void showSectorTable(sector_t *k_sector, uint8_t k_sectorsCount); +void readerAttack(sector_t *k_sector, uint8_t k_sectorsCount, nonces_t data, bool setEmulatorMem, bool verbose); void printKeyTable(uint8_t sectorscnt, sector_t *e_sector); void printKeyTableEx(uint8_t sectorscnt, sector_t *e_sector, uint8_t start_sector); void printKeyTable_fast(uint8_t sectorscnt, icesector_t *e_sector, uint64_t bar, uint64_t foo); diff --git a/client/src/cmdparser.c b/client/src/cmdparser.c index e57d32090..529a3d553 100644 --- a/client/src/cmdparser.c +++ b/client/src/cmdparser.c @@ -234,8 +234,8 @@ int CmdsParse(const command_t Commands[], const char *Cmd) { return PM3_SUCCESS; } -char pparent[512] = {0}; -char *parent = pparent; +static char pparent[512] = {0}; +static char *parent = pparent; void dumpCommandsRecursive(const command_t cmds[], int markdown) { if (cmds[0].Name == NULL) return;