advanced record reading

This commit is contained in:
merlokk 2021-07-27 20:00:18 +03:00
parent 882e96a3ce
commit 5a7e507de2
3 changed files with 28 additions and 8 deletions

View file

@ -6345,7 +6345,7 @@ static int CmdHF14ADesReadData(const char *Cmd) {
if (resplen > 0) {
PrintAndLogEx(SUCCESS, "Read %u bytes from file 0x%02x offset %u", resplen, fnum, offset);
print_buffer_with_offset(resp, resplen, offset);
print_buffer_with_offset(resp, resplen, offset, true);
} else {
PrintAndLogEx(SUCCESS, "Read operation returned no data from file %d", fnum);
}
@ -6363,6 +6363,17 @@ static int CmdHF14ADesReadData(const char *Cmd) {
}
if (op == RFTRecord) {
res = DesfireReadRecords(&dctx, fnum, offset, 1, resp, &resplen);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Desfire ReadRecords (len=1) command " _RED_("error") ". Result: %d", res);
DropField();
return PM3_ESOFT;
}
size_t reclen = resplen;
if (verbose)
PrintAndLogEx(INFO, "Record length %zu", reclen);
res = DesfireReadRecords(&dctx, fnum, offset, length, resp, &resplen);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Desfire ReadRecords command " _RED_("error") ". Result: %d", res);
@ -6371,8 +6382,15 @@ static int CmdHF14ADesReadData(const char *Cmd) {
}
if (resplen > 0) {
PrintAndLogEx(SUCCESS, "Read %u bytes from file 0x%02x offset %u", resplen, fnum, offset);
print_buffer_with_offset(resp, resplen, offset);
size_t reccount = resplen / reclen;
PrintAndLogEx(SUCCESS, "Read %u bytes from file 0x%02x from record %u record count %zu record length %zu", resplen, fnum, offset, reccount, reclen);
if (reccount > 0)
PrintAndLogEx(SUCCESS, "Lastest record at the bottom.");
for (int i = 0; i < reccount; i++) {
if (i != 0)
PrintAndLogEx(SUCCESS, "Record %d", i + offset);
print_buffer_with_offset(&resp[i * reclen], reclen, offset, (i == 0));
}
} else {
PrintAndLogEx(SUCCESS, "Read operation returned no data from file %d", fnum);
}
@ -6389,7 +6407,7 @@ static int CmdHF14ADesReadData(const char *Cmd) {
if (resplen > 0) {
if (resplen != 12) {
PrintAndLogEx(WARNING, "Read wrong %u bytes from file 0x%02x offset %u", resplen, fnum, offset);
print_buffer_with_offset(resp, resplen, offset);
print_buffer_with_offset(resp, resplen, offset, true);
} else {
uint32_t cnt = MemLeToUint4byte(&resp[0]);
PrintAndLogEx(SUCCESS, "Transaction counter: %d (0x%08x)", cnt, cnt);

View file

@ -249,9 +249,11 @@ void print_buffer(const uint8_t *data, const size_t len, int level) {
print_buffer_ex(data, len, level, 16);
}
void print_buffer_with_offset(const uint8_t *data, const size_t len, int offset) {
PrintAndLogEx(INFO, " Offset | Data | Ascii");
PrintAndLogEx(INFO, "----------------------------------------------------------------------------");
void print_buffer_with_offset(const uint8_t *data, const size_t len, int offset, bool print_header) {
if (print_header) {
PrintAndLogEx(INFO, " Offset | Data | Ascii");
PrintAndLogEx(INFO, "----------------------------------------------------------------------------");
}
for (uint32_t i = 0; i < len; i += 16) {
uint32_t l = len - i;

View file

@ -52,7 +52,7 @@ char *sprint_hex_ascii(const uint8_t *data, const size_t len);
char *sprint_ascii(const uint8_t *data, const size_t len);
char *sprint_ascii_ex(const uint8_t *data, const size_t len, const size_t min_str_len);
void print_buffer_with_offset(const uint8_t *data, const size_t len, int offset);
void print_buffer_with_offset(const uint8_t *data, const size_t len, int offset, bool print_header);
void print_buffer(const uint8_t *data, const size_t len, int level);
void print_blocks(uint32_t *data, size_t len);