diff --git a/armsrc/lfops.c b/armsrc/lfops.c index c574ca339..c130d78e8 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -2242,7 +2242,7 @@ static void WriteEM4x05(uint32_t *blockdata, uint8_t startblock, uint8_t numbloc Dbprintf("--+----------------"); } - for (uint8_t i = startblock; i < startblock + numblocks; i++) { + for (uint8_t i = startblock; i < (uint8_t)(startblock + numblocks); i++) { if (i > 4) { blockdata[i - startblock] = reflect(blockdata[i - startblock], 32); } diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index a5566b6f2..47cae98ed 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -503,7 +503,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1 uint8_t mM = 0; //moebius_modifier for collection storage // Authenticate response - nonce - uint8_t rAUTH_NT[4] = {0,0,0,1}; + uint8_t rAUTH_NT[4] = {0, 0, 0, 1}; uint8_t rAUTH_NT_keystream[4]; uint32_t nonce = 0; @@ -791,12 +791,12 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1 if (g_dbglevel >= DBG_EXTENDED) { Dbprintf("[MFEMUL_WORK] Reader authenticating for block %d (0x%02x) with key %c - nonce: %08X - cuid: %08X", - receivedCmd_dec[1], - receivedCmd_dec[1], - (cardAUTHKEY == 0) ? 'A' : 'B', - nonce, - cuid - ); + receivedCmd_dec[1], + receivedCmd_dec[1], + (cardAUTHKEY == 0) ? 'A' : 'B', + nonce, + cuid + ); } } else { // nested authentication @@ -812,10 +812,10 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1 if (g_dbglevel >= DBG_EXTENDED) { Dbprintf("[MFEMUL_WORK] Reader doing nested authentication for block %d (0x%02x) with key %c", - receivedCmd_dec[1], - receivedCmd_dec[1], - (cardAUTHKEY == 0) ? 'A' : 'B' - ); + receivedCmd_dec[1], + receivedCmd_dec[1], + (cardAUTHKEY == 0) ? 'A' : 'B' + ); } } diff --git a/armsrc/mifareutil.c b/armsrc/mifareutil.c index a048aee82..fd9d86ccc 100644 --- a/armsrc/mifareutil.c +++ b/armsrc/mifareutil.c @@ -468,8 +468,8 @@ int mifare_classic_value(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE] = {0x00}; uint8_t command = MIFARE_CMD_INC; - - if (action == 0x01) + + if (action == 0x01) command = MIFARE_CMD_DEC; // Send increment or decrement command @@ -510,7 +510,7 @@ int mifare_classic_value(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo len = mifare_sendcmd_short(pcs, 1, MIFARE_CMD_TRANSFER, blockNo, receivedAnswer, receivedAnswerPar, NULL); if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]); - return 1; + return 1; } } diff --git a/client/src/cmdhf14b.c b/client/src/cmdhf14b.c index baea0126a..a096aac54 100644 --- a/client/src/cmdhf14b.c +++ b/client/src/cmdhf14b.c @@ -1445,9 +1445,7 @@ static int CmdHF14BDump(const char *Cmd) { } size_t datalen = (blocks + 1) * 4; - saveFile(filename, ".bin", data, datalen); - saveFileEML(filename, data, datalen, 4); - saveFileJSON(filename, jsf14b, data, datalen, NULL); + pm3_save_dump(filename, data, datalen, jsf14b, 4); return switch_off_field_14b(); } /* diff --git a/client/src/cmdhf15.c b/client/src/cmdhf15.c index 6688c394a..5ac00a837 100644 --- a/client/src/cmdhf15.c +++ b/client/src/cmdhf15.c @@ -39,7 +39,7 @@ #include "graph.h" #include "crc16.h" // iso15 crc #include "cmddata.h" // getsamples -#include "fileutils.h" // savefileEML +#include "fileutils.h" // pm3_save_dump #include "cliparser.h" #include "util_posix.h" // msleep @@ -1429,9 +1429,7 @@ static int CmdHF15Dump(const char *Cmd) { } size_t datalen = blocknum * 4; - saveFile(filename, ".bin", data, datalen); - saveFileEML(filename, data, datalen, 4); - saveFileJSON(filename, jsf15, data, datalen, NULL); + pm3_save_dump(filename, data, datalen, jsf15, 4); return PM3_SUCCESS; } @@ -1975,44 +1973,19 @@ static int CmdHF15Restore(const char *Cmd) { } PrintAndLogEx(INFO, "Using block size... %d", blocksize); + + // read dump file + uint8_t *dump = NULL; + size_t bytes_read = 0; // 4bytes * 256 blocks. Should be enough.. - uint8_t *data = NULL; - size_t datalen = 0; - int res = PM3_SUCCESS; - DumpFileType_t dftype = getfiletype(filename); - switch (dftype) { - case BIN: { - res = loadFile_safe(filename, ".bin", (void **)&data, &datalen); - break; - } - case EML: { - res = loadFileEML_safe(filename, (void **)&data, &datalen); - break; - } - case JSON: { - data = calloc(4 * 256, sizeof(uint8_t)); - if (data == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); - return PM3_EMALLOC; - } - res = loadFileJSON(filename, (void *)data, 256 * 4, &datalen, NULL); - break; - } - case DICTIONARY: { - PrintAndLogEx(ERR, "Error: Only BIN/JSON/EML formats allowed"); - free(data); - return PM3_EINVARG; - } - } - + int res = pm3_load_dump(filename, (void **)&dump, &bytes_read, (4 * 256)); if (res != PM3_SUCCESS) { - free(data); - return PM3_EFILE; + return res; } - if ((datalen % blocksize) != 0) { - PrintAndLogEx(WARNING, "datalen %zu isn't dividable with blocksize %d", datalen, blocksize); - free(data); + if ((bytes_read % blocksize) != 0) { + PrintAndLogEx(WARNING, "datalen %zu isn't dividable with blocksize %d", bytes_read, blocksize); + free(dump); return PM3_ESOFT; } @@ -2023,11 +1996,11 @@ static int CmdHF15Restore(const char *Cmd) { int retval = PM3_SUCCESS; size_t bytes = 0; uint16_t i = 0; - while (bytes < datalen) { + while (bytes < bytes_read) { req[reqlen] = i; // copy over the data to the request - memcpy(req + reqlen + 1, data + bytes, blocksize); + memcpy(req + reqlen + 1, dump + bytes, blocksize); AddCrc15(req, reqlen + 1 + blocksize); uint32_t tried = 0; @@ -2042,7 +2015,7 @@ static int CmdHF15Restore(const char *Cmd) { } if (tried >= retries) { - free(data); + free(dump); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(FAILED, "restore failed. Too many retries."); return retval; @@ -2050,7 +2023,7 @@ static int CmdHF15Restore(const char *Cmd) { bytes += blocksize; i++; } - free(data); + free(dump); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "done"); diff --git a/client/src/cmdhflegic.c b/client/src/cmdhflegic.c index 973f35ed5..f501dcb91 100644 --- a/client/src/cmdhflegic.c +++ b/client/src/cmdhflegic.c @@ -33,6 +33,7 @@ static int CmdHelp(const char *Cmd); #define LEGIC_PRIME_MIM22 22 #define LEGIC_PRIME_MIM256 256 #define LEGIC_PRIME_MIM1024 1024 +#define LEGIC_BLOCK_SIZE 8 static bool legic_xor(uint8_t *data, uint16_t cardsize) { @@ -873,9 +874,7 @@ static int CmdLegicDump(const char *Cmd) { FillFileNameByUID(filename, data, "-dump", 4); } - saveFile(filename, ".bin", data, readlen); - saveFileEML(filename, data, readlen, 8); - saveFileJSON(filename, jsfLegic, data, readlen, NULL); + pm3_save_dump(filename, data, readlen, jsfLegic, LEGIC_BLOCK_SIZE); free(data); return PM3_SUCCESS; } @@ -1111,9 +1110,7 @@ static int CmdLegicESave(const char *Cmd) { legic_xor(data, numofbytes); } - saveFile(filename, ".bin", data, numofbytes); - saveFileEML(filename, data, numofbytes, 8); - saveFileJSON(filename, jsfLegic, data, numofbytes, NULL); + pm3_save_dump(filename, data, numofbytes, jsfLegic, LEGIC_BLOCK_SIZE); return PM3_SUCCESS; } diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 13a95efd8..af8726298 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -2452,8 +2452,7 @@ static int CmdHF14ADesCreateApp(const char *Cmd) { int dfnamelen = 16; CLIGetStrWithReturn(ctx, 14, dfname, &dfnamelen); - if (dfnamelen == 0) // no text DF Name supplied - { + if (dfnamelen == 0) { // no text DF Name supplied dfnamelen = 16; CLIGetHexWithReturn(ctx, 15, dfname, &dfnamelen); } @@ -2547,7 +2546,7 @@ static int CmdHF14ADesCreateApp(const char *Cmd) { PrintAndLogEx(INFO, "ISO file ID %s", (data[4] & 0x20) ? "enabled" : "disabled"); if ((data[4] & 0x20)) { PrintAndLogEx(INFO, "ISO file ID 0x%04x", MemLeToUint2byte(&data[5])); - PrintAndLogEx(INFO, "DF Name[%02d] %s | %s\n", dfnamelen, sprint_ascii(dfname, dfnamelen), sprint_hex (dfname, dfnamelen)); + PrintAndLogEx(INFO, "DF Name[%02d] %s | %s\n", dfnamelen, sprint_ascii(dfname, dfnamelen), sprint_hex(dfname, dfnamelen)); } PrintKeySettings(data[3], data[4], true, true); PrintAndLogEx(INFO, "---------------------------"); diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 202aa7444..1f82db39b 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -2451,9 +2451,7 @@ static int CmdHF14AMfUDump(const char *Cmd) { FillFileNameByUID(filename, uid, "-dump", sizeof(uid)); } uint16_t datalen = pages * MFU_BLOCK_SIZE + MFU_DUMP_PREFIX_LENGTH; - saveFile(filename, ".bin", (uint8_t *)&dump_file_data, datalen); - saveFileEML(filename, (uint8_t *)&dump_file_data, datalen, MFU_BLOCK_SIZE); - saveFileJSON(filename, jsfMfuMemory, (uint8_t *)&dump_file_data, datalen, NULL); + pm3_save_dump(filename, (uint8_t *)&dump_file_data, datalen, jsfMfuMemory, MFU_BLOCK_SIZE); if (is_partial) PrintAndLogEx(WARNING, "Partial dump created. (%d of %d blocks)", pages, card_mem_size); @@ -3243,7 +3241,7 @@ static int CmdHF14AMfUPwdGen(const char *Cmd) { } PrintAndLogEx(INFO, "------------------.---------------"); - PrintAndLogEx(INFO, " Using UID : %s", sprint_hex(uid, 7)); + PrintAndLogEx(INFO, " Using UID : " _YELLOW_("%s"), sprint_hex(uid, 7)); PrintAndLogEx(INFO, "----------------------------------"); PrintAndLogEx(INFO, " algo | pwd | pack"); PrintAndLogEx(INFO, "-----------------+----------+-----"); diff --git a/client/src/cmdlfem4x05.c b/client/src/cmdlfem4x05.c index 120482ff1..1dff74de0 100644 --- a/client/src/cmdlfem4x05.c +++ b/client/src/cmdlfem4x05.c @@ -692,9 +692,9 @@ int CmdEM4x05Dump(const char *Cmd) { } else { } - if (success == PM3_SUCCESS) { // all ok save dump to file - // saveFileEML will add .eml extension to filename - // saveFile (binary) passes in the .bin extension. + // all ok save dump to file + if (success == PM3_SUCCESS) { + if (strcmp(filename, "") == 0) { if (card_type == EM_4369) { @@ -707,9 +707,10 @@ int CmdEM4x05Dump(const char *Cmd) { } PrintAndLogEx(NORMAL, ""); - saveFileJSON(filename, (card_type == EM_4369 || card_type == EM_4469) ? jsfEM4x69 : jsfEM4x05, (uint8_t *)data, 16 * sizeof(uint32_t), NULL); - saveFileEML(filename, (uint8_t *)data, 16 * sizeof(uint32_t), sizeof(uint32_t)); - saveFile(filename, ".bin", data, sizeof(data)); + if (card_type == EM_4369 || card_type == EM_4469) + pm3_save_dump(filename, (uint8_t *)data, sizeof(data), jsfEM4x69, 4); + else + pm3_save_dump(filename, (uint8_t *)data, sizeof(data), jsfEM4x05, 4); } PrintAndLogEx(NORMAL, ""); return success; diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index e35d0f141..e12627d1b 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -257,9 +257,7 @@ int CmdEM4x50ESave(const char *Cmd) { FillFileNameByUID(fptr, (uint8_t *)&data[4 * EM4X50_DEVICE_ID], "-dump", 4); } - saveFile(filename, ".bin", data, DUMP_FILESIZE); - saveFileEML(filename, data, DUMP_FILESIZE, 4); - saveFileJSON(filename, jsfEM4x50, data, DUMP_FILESIZE, NULL); + pm3_save_dump(filename, data, DUMP_FILESIZE, jsfEM4x50, 4); return PM3_SUCCESS; } @@ -798,9 +796,7 @@ int CmdEM4x50Dump(const char *Cmd) { memcpy(data + (i * 4), words[i].byte, 4); } - saveFile(filename, ".bin", data, sizeof(data)); - saveFileEML(filename, data, sizeof(data), 4); - saveFileJSON(filename, jsfEM4x50, data, sizeof(data), NULL); + pm3_save_dump(filename, data, sizeof(data), jsfEM4x50, 4); return PM3_SUCCESS; } diff --git a/client/src/cmdlfhitag.c b/client/src/cmdlfhitag.c index 62348672f..539bda10a 100644 --- a/client/src/cmdlfhitag.c +++ b/client/src/cmdlfhitag.c @@ -858,9 +858,7 @@ static int CmdLFHitag2Dump(const char *Cmd) { FillFileNameByUID(fptr, data, "-dump", 4); } - saveFile(filename, ".bin", data, 48); - saveFileEML(filename, data, 48, 4); - saveFileJSON(filename, jsfHitag, data, 48, NULL); + pm3_save_dump(filename, data, 48, jsfHitag, 4); */ return PM3_SUCCESS; }