mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 02:27:26 -07:00
simplify save files
This commit is contained in:
parent
2c61530cba
commit
b4255eea77
11 changed files with 48 additions and 88 deletions
|
@ -2242,7 +2242,7 @@ static void WriteEM4x05(uint32_t *blockdata, uint8_t startblock, uint8_t numbloc
|
||||||
Dbprintf("--+----------------");
|
Dbprintf("--+----------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = startblock; i < startblock + numblocks; i++) {
|
for (uint8_t i = startblock; i < (uint8_t)(startblock + numblocks); i++) {
|
||||||
if (i > 4) {
|
if (i > 4) {
|
||||||
blockdata[i - startblock] = reflect(blockdata[i - startblock], 32);
|
blockdata[i - startblock] = reflect(blockdata[i - startblock], 32);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
uint8_t mM = 0; //moebius_modifier for collection storage
|
||||||
|
|
||||||
// Authenticate response - nonce
|
// 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];
|
uint8_t rAUTH_NT_keystream[4];
|
||||||
uint32_t nonce = 0;
|
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) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("[MFEMUL_WORK] Reader authenticating for block %d (0x%02x) with key %c - nonce: %08X - cuid: %08X",
|
Dbprintf("[MFEMUL_WORK] Reader authenticating for block %d (0x%02x) with key %c - nonce: %08X - cuid: %08X",
|
||||||
receivedCmd_dec[1],
|
receivedCmd_dec[1],
|
||||||
receivedCmd_dec[1],
|
receivedCmd_dec[1],
|
||||||
(cardAUTHKEY == 0) ? 'A' : 'B',
|
(cardAUTHKEY == 0) ? 'A' : 'B',
|
||||||
nonce,
|
nonce,
|
||||||
cuid
|
cuid
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// nested authentication
|
// nested authentication
|
||||||
|
@ -812,10 +812,10 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
|
|
||||||
if (g_dbglevel >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("[MFEMUL_WORK] Reader doing nested authentication for block %d (0x%02x) with key %c",
|
Dbprintf("[MFEMUL_WORK] Reader doing nested authentication for block %d (0x%02x) with key %c",
|
||||||
receivedCmd_dec[1],
|
receivedCmd_dec[1],
|
||||||
receivedCmd_dec[1],
|
receivedCmd_dec[1],
|
||||||
(cardAUTHKEY == 0) ? 'A' : 'B'
|
(cardAUTHKEY == 0) ? 'A' : 'B'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 receivedAnswerPar[MAX_MIFARE_PARITY_SIZE] = {0x00};
|
||||||
|
|
||||||
uint8_t command = MIFARE_CMD_INC;
|
uint8_t command = MIFARE_CMD_INC;
|
||||||
|
|
||||||
if (action == 0x01)
|
if (action == 0x01)
|
||||||
command = MIFARE_CMD_DEC;
|
command = MIFARE_CMD_DEC;
|
||||||
|
|
||||||
// Send increment or decrement command
|
// 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);
|
len = mifare_sendcmd_short(pcs, 1, MIFARE_CMD_TRANSFER, blockNo, receivedAnswer, receivedAnswerPar, NULL);
|
||||||
if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK
|
if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK
|
||||||
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1445,9 +1445,7 @@ static int CmdHF14BDump(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t datalen = (blocks + 1) * 4;
|
size_t datalen = (blocks + 1) * 4;
|
||||||
saveFile(filename, ".bin", data, datalen);
|
pm3_save_dump(filename, data, datalen, jsf14b, 4);
|
||||||
saveFileEML(filename, data, datalen, 4);
|
|
||||||
saveFileJSON(filename, jsf14b, data, datalen, NULL);
|
|
||||||
return switch_off_field_14b();
|
return switch_off_field_14b();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
#include "crc16.h" // iso15 crc
|
#include "crc16.h" // iso15 crc
|
||||||
#include "cmddata.h" // getsamples
|
#include "cmddata.h" // getsamples
|
||||||
#include "fileutils.h" // savefileEML
|
#include "fileutils.h" // pm3_save_dump
|
||||||
#include "cliparser.h"
|
#include "cliparser.h"
|
||||||
#include "util_posix.h" // msleep
|
#include "util_posix.h" // msleep
|
||||||
|
|
||||||
|
@ -1429,9 +1429,7 @@ static int CmdHF15Dump(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t datalen = blocknum * 4;
|
size_t datalen = blocknum * 4;
|
||||||
saveFile(filename, ".bin", data, datalen);
|
pm3_save_dump(filename, data, datalen, jsf15, 4);
|
||||||
saveFileEML(filename, data, datalen, 4);
|
|
||||||
saveFileJSON(filename, jsf15, data, datalen, NULL);
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1975,44 +1973,19 @@ static int CmdHF15Restore(const char *Cmd) {
|
||||||
}
|
}
|
||||||
PrintAndLogEx(INFO, "Using block size... %d", blocksize);
|
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..
|
// 4bytes * 256 blocks. Should be enough..
|
||||||
uint8_t *data = NULL;
|
int res = pm3_load_dump(filename, (void **)&dump, &bytes_read, (4 * 256));
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res != PM3_SUCCESS) {
|
if (res != PM3_SUCCESS) {
|
||||||
free(data);
|
return res;
|
||||||
return PM3_EFILE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((datalen % blocksize) != 0) {
|
if ((bytes_read % blocksize) != 0) {
|
||||||
PrintAndLogEx(WARNING, "datalen %zu isn't dividable with blocksize %d", datalen, blocksize);
|
PrintAndLogEx(WARNING, "datalen %zu isn't dividable with blocksize %d", bytes_read, blocksize);
|
||||||
free(data);
|
free(dump);
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2023,11 +1996,11 @@ static int CmdHF15Restore(const char *Cmd) {
|
||||||
int retval = PM3_SUCCESS;
|
int retval = PM3_SUCCESS;
|
||||||
size_t bytes = 0;
|
size_t bytes = 0;
|
||||||
uint16_t i = 0;
|
uint16_t i = 0;
|
||||||
while (bytes < datalen) {
|
while (bytes < bytes_read) {
|
||||||
|
|
||||||
req[reqlen] = i;
|
req[reqlen] = i;
|
||||||
// copy over the data to the request
|
// 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);
|
AddCrc15(req, reqlen + 1 + blocksize);
|
||||||
|
|
||||||
uint32_t tried = 0;
|
uint32_t tried = 0;
|
||||||
|
@ -2042,7 +2015,7 @@ static int CmdHF15Restore(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tried >= retries) {
|
if (tried >= retries) {
|
||||||
free(data);
|
free(dump);
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(FAILED, "restore failed. Too many retries.");
|
PrintAndLogEx(FAILED, "restore failed. Too many retries.");
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -2050,7 +2023,7 @@ static int CmdHF15Restore(const char *Cmd) {
|
||||||
bytes += blocksize;
|
bytes += blocksize;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
free(data);
|
free(dump);
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(INFO, "done");
|
PrintAndLogEx(INFO, "done");
|
||||||
|
|
|
@ -33,6 +33,7 @@ static int CmdHelp(const char *Cmd);
|
||||||
#define LEGIC_PRIME_MIM22 22
|
#define LEGIC_PRIME_MIM22 22
|
||||||
#define LEGIC_PRIME_MIM256 256
|
#define LEGIC_PRIME_MIM256 256
|
||||||
#define LEGIC_PRIME_MIM1024 1024
|
#define LEGIC_PRIME_MIM1024 1024
|
||||||
|
#define LEGIC_BLOCK_SIZE 8
|
||||||
|
|
||||||
static bool legic_xor(uint8_t *data, uint16_t cardsize) {
|
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);
|
FillFileNameByUID(filename, data, "-dump", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveFile(filename, ".bin", data, readlen);
|
pm3_save_dump(filename, data, readlen, jsfLegic, LEGIC_BLOCK_SIZE);
|
||||||
saveFileEML(filename, data, readlen, 8);
|
|
||||||
saveFileJSON(filename, jsfLegic, data, readlen, NULL);
|
|
||||||
free(data);
|
free(data);
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -1111,9 +1110,7 @@ static int CmdLegicESave(const char *Cmd) {
|
||||||
legic_xor(data, numofbytes);
|
legic_xor(data, numofbytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveFile(filename, ".bin", data, numofbytes);
|
pm3_save_dump(filename, data, numofbytes, jsfLegic, LEGIC_BLOCK_SIZE);
|
||||||
saveFileEML(filename, data, numofbytes, 8);
|
|
||||||
saveFileJSON(filename, jsfLegic, data, numofbytes, NULL);
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2452,8 +2452,7 @@ static int CmdHF14ADesCreateApp(const char *Cmd) {
|
||||||
int dfnamelen = 16;
|
int dfnamelen = 16;
|
||||||
CLIGetStrWithReturn(ctx, 14, dfname, &dfnamelen);
|
CLIGetStrWithReturn(ctx, 14, dfname, &dfnamelen);
|
||||||
|
|
||||||
if (dfnamelen == 0) // no text DF Name supplied
|
if (dfnamelen == 0) { // no text DF Name supplied
|
||||||
{
|
|
||||||
dfnamelen = 16;
|
dfnamelen = 16;
|
||||||
CLIGetHexWithReturn(ctx, 15, dfname, &dfnamelen);
|
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");
|
PrintAndLogEx(INFO, "ISO file ID %s", (data[4] & 0x20) ? "enabled" : "disabled");
|
||||||
if ((data[4] & 0x20)) {
|
if ((data[4] & 0x20)) {
|
||||||
PrintAndLogEx(INFO, "ISO file ID 0x%04x", MemLeToUint2byte(&data[5]));
|
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);
|
PrintKeySettings(data[3], data[4], true, true);
|
||||||
PrintAndLogEx(INFO, "---------------------------");
|
PrintAndLogEx(INFO, "---------------------------");
|
||||||
|
|
|
@ -2451,9 +2451,7 @@ static int CmdHF14AMfUDump(const char *Cmd) {
|
||||||
FillFileNameByUID(filename, uid, "-dump", sizeof(uid));
|
FillFileNameByUID(filename, uid, "-dump", sizeof(uid));
|
||||||
}
|
}
|
||||||
uint16_t datalen = pages * MFU_BLOCK_SIZE + MFU_DUMP_PREFIX_LENGTH;
|
uint16_t datalen = pages * MFU_BLOCK_SIZE + MFU_DUMP_PREFIX_LENGTH;
|
||||||
saveFile(filename, ".bin", (uint8_t *)&dump_file_data, datalen);
|
pm3_save_dump(filename, (uint8_t *)&dump_file_data, datalen, jsfMfuMemory, MFU_BLOCK_SIZE);
|
||||||
saveFileEML(filename, (uint8_t *)&dump_file_data, datalen, MFU_BLOCK_SIZE);
|
|
||||||
saveFileJSON(filename, jsfMfuMemory, (uint8_t *)&dump_file_data, datalen, NULL);
|
|
||||||
|
|
||||||
if (is_partial)
|
if (is_partial)
|
||||||
PrintAndLogEx(WARNING, "Partial dump created. (%d of %d blocks)", pages, card_mem_size);
|
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, "------------------.---------------");
|
||||||
PrintAndLogEx(INFO, " Using UID : %s", sprint_hex(uid, 7));
|
PrintAndLogEx(INFO, " Using UID : " _YELLOW_("%s"), sprint_hex(uid, 7));
|
||||||
PrintAndLogEx(INFO, "----------------------------------");
|
PrintAndLogEx(INFO, "----------------------------------");
|
||||||
PrintAndLogEx(INFO, " algo | pwd | pack");
|
PrintAndLogEx(INFO, " algo | pwd | pack");
|
||||||
PrintAndLogEx(INFO, "-----------------+----------+-----");
|
PrintAndLogEx(INFO, "-----------------+----------+-----");
|
||||||
|
|
|
@ -692,9 +692,9 @@ int CmdEM4x05Dump(const char *Cmd) {
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success == PM3_SUCCESS) { // all ok save dump to file
|
// all ok save dump to file
|
||||||
// saveFileEML will add .eml extension to filename
|
if (success == PM3_SUCCESS) {
|
||||||
// saveFile (binary) passes in the .bin extension.
|
|
||||||
if (strcmp(filename, "") == 0) {
|
if (strcmp(filename, "") == 0) {
|
||||||
|
|
||||||
if (card_type == EM_4369) {
|
if (card_type == EM_4369) {
|
||||||
|
@ -707,9 +707,10 @@ int CmdEM4x05Dump(const char *Cmd) {
|
||||||
|
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
saveFileJSON(filename, (card_type == EM_4369 || card_type == EM_4469) ? jsfEM4x69 : jsfEM4x05, (uint8_t *)data, 16 * sizeof(uint32_t), NULL);
|
if (card_type == EM_4369 || card_type == EM_4469)
|
||||||
saveFileEML(filename, (uint8_t *)data, 16 * sizeof(uint32_t), sizeof(uint32_t));
|
pm3_save_dump(filename, (uint8_t *)data, sizeof(data), jsfEM4x69, 4);
|
||||||
saveFile(filename, ".bin", data, sizeof(data));
|
else
|
||||||
|
pm3_save_dump(filename, (uint8_t *)data, sizeof(data), jsfEM4x05, 4);
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
return success;
|
return success;
|
||||||
|
|
|
@ -257,9 +257,7 @@ int CmdEM4x50ESave(const char *Cmd) {
|
||||||
FillFileNameByUID(fptr, (uint8_t *)&data[4 * EM4X50_DEVICE_ID], "-dump", 4);
|
FillFileNameByUID(fptr, (uint8_t *)&data[4 * EM4X50_DEVICE_ID], "-dump", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveFile(filename, ".bin", data, DUMP_FILESIZE);
|
pm3_save_dump(filename, data, DUMP_FILESIZE, jsfEM4x50, 4);
|
||||||
saveFileEML(filename, data, DUMP_FILESIZE, 4);
|
|
||||||
saveFileJSON(filename, jsfEM4x50, data, DUMP_FILESIZE, NULL);
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -798,9 +796,7 @@ int CmdEM4x50Dump(const char *Cmd) {
|
||||||
memcpy(data + (i * 4), words[i].byte, 4);
|
memcpy(data + (i * 4), words[i].byte, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveFile(filename, ".bin", data, sizeof(data));
|
pm3_save_dump(filename, data, sizeof(data), jsfEM4x50, 4);
|
||||||
saveFileEML(filename, data, sizeof(data), 4);
|
|
||||||
saveFileJSON(filename, jsfEM4x50, data, sizeof(data), NULL);
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -858,9 +858,7 @@ static int CmdLFHitag2Dump(const char *Cmd) {
|
||||||
FillFileNameByUID(fptr, data, "-dump", 4);
|
FillFileNameByUID(fptr, data, "-dump", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveFile(filename, ".bin", data, 48);
|
pm3_save_dump(filename, data, 48, jsfHitag, 4);
|
||||||
saveFileEML(filename, data, 48, 4);
|
|
||||||
saveFileJSON(filename, jsfHitag, data, 48, NULL);
|
|
||||||
*/
|
*/
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue