mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-07-16 10:03:04 -07:00
iso15: fix restore with new dump format
This commit is contained in:
parent
b7928eb85e
commit
169780fec0
1 changed files with 34 additions and 33 deletions
|
@ -2583,8 +2583,7 @@ static int CmdHF15Restore(const char *Cmd) {
|
||||||
uint8_t arglen = arg_add_default(argtable);
|
uint8_t arglen = arg_add_default(argtable);
|
||||||
argtable[arglen++] = arg_str0("f", "file", "<fn>", "Specify a filename for dump file"),
|
argtable[arglen++] = arg_str0("f", "file", "<fn>", "Specify a filename for dump file"),
|
||||||
argtable[arglen++] = arg_int0("r", "retry", "<dec>", "number of retries (def 3)"),
|
argtable[arglen++] = arg_int0("r", "retry", "<dec>", "number of retries (def 3)"),
|
||||||
argtable[arglen++] = arg_int0(NULL, "bs", "<dec>", "block size (def 4)"),
|
argtable[arglen++] = arg_lit0("v", "verbose", "verbose output");
|
||||||
argtable[arglen++] = arg_lit0("v", "verbose", "verbose output");
|
|
||||||
argtable[arglen++] = arg_param_end;
|
argtable[arglen++] = arg_param_end;
|
||||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
|
||||||
|
@ -2602,8 +2601,7 @@ static int CmdHF15Restore(const char *Cmd) {
|
||||||
CLIParamStrToBuf(arg_get_str(ctx, 6), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
|
CLIParamStrToBuf(arg_get_str(ctx, 6), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
|
||||||
|
|
||||||
uint32_t retries = arg_get_u32_def(ctx, 7, 3);
|
uint32_t retries = arg_get_u32_def(ctx, 7, 3);
|
||||||
int blocksize = arg_get_int_def(ctx, 8, 4);
|
bool verbose = arg_get_lit(ctx, 8);
|
||||||
bool verbose = arg_get_lit(ctx, 9);
|
|
||||||
CLIParserFree(ctx);
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
// sanity checks
|
// sanity checks
|
||||||
|
@ -2617,11 +2615,6 @@ static int CmdHF15Restore(const char *Cmd) {
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blocksize < 4) {
|
|
||||||
PrintAndLogEx(WARNING, "Blocksize too small, using default 4 bytes");
|
|
||||||
blocksize = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
// default fallback to scan for tag.
|
// default fallback to scan for tag.
|
||||||
// overriding unaddress parameter :)
|
// overriding unaddress parameter :)
|
||||||
if (uidlen != HF15_UID_LENGTH) {
|
if (uidlen != HF15_UID_LENGTH) {
|
||||||
|
@ -2641,8 +2634,6 @@ static int CmdHF15Restore(const char *Cmd) {
|
||||||
PrintAndLogEx(SUCCESS, "Using unaddressed mode");
|
PrintAndLogEx(SUCCESS, "Using unaddressed mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "Using block size... " _YELLOW_("%d"), blocksize);
|
|
||||||
|
|
||||||
// TI needs OPTION
|
// TI needs OPTION
|
||||||
if (uid[7] == 0xE0 && uid[6] == 0x07) {
|
if (uid[7] == 0xE0 && uid[6] == 0x07) {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
|
@ -2652,18 +2643,33 @@ static int CmdHF15Restore(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// read dump file
|
// read dump file
|
||||||
uint8_t *dump = NULL;
|
iso15_tag_t *tag = NULL;
|
||||||
size_t bytes_read = 0;
|
size_t bytes_read = 0;
|
||||||
// blocksize bytes * 256 blocks. Should be enough
|
// blocksize bytes * 256 blocks. Should be enough
|
||||||
int res = pm3_load_dump(filename, (void **)&dump, &bytes_read, (blocksize * 256));
|
int res = pm3_load_dump(filename, (void **)&tag, &bytes_read, sizeof(iso15_tag_t));
|
||||||
if (res != PM3_SUCCESS) {
|
if (res != PM3_SUCCESS) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((bytes_read % blocksize) != 0) {
|
if (bytes_read != sizeof(iso15_tag_t)) {
|
||||||
PrintAndLogEx(WARNING, "datalen %zu isn't dividable with blocksize %d", bytes_read, blocksize);
|
PrintAndLogEx(FAILED, "Memory image is not matching tag structure.");
|
||||||
free(dump);
|
free(tag);
|
||||||
return PM3_ESOFT;
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
if (bytes_read == 0) {
|
||||||
|
PrintAndLogEx(FAILED, "Memory image empty.");
|
||||||
|
free(tag);
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((tag->pagesCount > ISO15693_TAG_MAX_PAGES) ||
|
||||||
|
((tag->pagesCount * tag->bytesPerPage) > ISO15693_TAG_MAX_SIZE) ||
|
||||||
|
(tag->pagesCount == 0) ||
|
||||||
|
(tag->bytesPerPage == 0)) {
|
||||||
|
PrintAndLogEx(FAILED, "Tag size error: pagesCount=%d, bytesPerPage=%d",
|
||||||
|
tag->pagesCount, tag->bytesPerPage);
|
||||||
|
free(tag);
|
||||||
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "Restoring data blocks");
|
PrintAndLogEx(INFO, "Restoring data blocks");
|
||||||
|
@ -2678,19 +2684,18 @@ 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 < bytes_read) {
|
uint8_t *data = calloc(tag->bytesPerPage, sizeof(uint8_t));
|
||||||
|
uint32_t tried = 0;
|
||||||
uint8_t data[blocksize];
|
while (bytes < (tag->pagesCount * tag->bytesPerPage)) {
|
||||||
|
|
||||||
// copy over the data to the request
|
// copy over the data to the request
|
||||||
memcpy(data, dump + bytes, blocksize);
|
memcpy(data, &tag->data[bytes], tag->bytesPerPage);
|
||||||
|
|
||||||
uint32_t tried = 0;
|
|
||||||
for (tried = 0; tried < retries; tried++) {
|
for (tried = 0; tried < retries; tried++) {
|
||||||
|
|
||||||
retval = hf_15_write_blk(&pm3flags, flags, uid, fast, i, data, blocksize);
|
retval = hf_15_write_blk(&pm3flags, flags, uid, fast
|
||||||
|
, i, data, tag->bytesPerPage);
|
||||||
if (retval == PM3_SUCCESS) {
|
if (retval == PM3_SUCCESS) {
|
||||||
|
|
||||||
PrintAndLogEx(INPLACE, "blk %3d", i);
|
PrintAndLogEx(INPLACE, "blk %3d", i);
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
@ -2708,24 +2713,20 @@ static int CmdHF15Restore(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tried >= retries) {
|
if (tried >= retries) {
|
||||||
free(dump);
|
free(data);
|
||||||
|
free(tag);
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(FAILED, "Too many retries (" _RED_("fail") " )");
|
PrintAndLogEx(FAILED, "Too many retries (" _RED_("fail") " )");
|
||||||
DropField();
|
DropField();
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes += blocksize;
|
bytes += tag->bytesPerPage;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
if (retval == PM3_EOUTOFBOUND) {
|
|
||||||
// we only get this when we reached end of tag memory
|
|
||||||
// break out of while loop
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(dump);
|
free(data);
|
||||||
|
free(tag);
|
||||||
DropField();
|
DropField();
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue