mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-22 06:13:51 -07:00
next attempt for tracelog. simplify
This commit is contained in:
parent
837d644b6c
commit
97c9638518
1 changed files with 22 additions and 18 deletions
|
@ -33,7 +33,8 @@ typedef struct {
|
||||||
} tracelog_hdr_t;
|
} tracelog_hdr_t;
|
||||||
|
|
||||||
// 4 + 2 + 2
|
// 4 + 2 + 2
|
||||||
#define TRACELOG_HDR_LEN sizeof(tracelog_hdr_t)
|
#define TRACELOG_HDR_LEN sizeof(tracelog_hdr_t)
|
||||||
|
#define TRACELOG_NEXT_PARITY_LEN(x) (((x)hdr->data_len - 1) / 8 + 1)
|
||||||
|
|
||||||
static int usage_trace_list(void) {
|
static int usage_trace_list(void) {
|
||||||
PrintAndLogEx(NORMAL, "List protocol data in trace buffer.");
|
PrintAndLogEx(NORMAL, "List protocol data in trace buffer.");
|
||||||
|
@ -81,13 +82,13 @@ static int usage_trace_save(void) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_last_record(uint16_t tracepos, uint8_t *trace, uint16_t traceLen) {
|
static bool is_last_record(uint16_t tracepos, uint16_t traceLen) {
|
||||||
return (tracepos + sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) >= traceLen);
|
return ((tracepos + TRACELOG_HDR_LEN) >= traceLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool next_record_is_response(uint16_t tracepos, uint8_t *trace) {
|
static bool next_record_is_response(uint16_t tracepos, uint8_t *trace) {
|
||||||
uint16_t next_records_datalen = *((uint16_t *)(trace + tracepos + sizeof(uint32_t) + sizeof(uint16_t)));
|
tracelog_hdr_t *hdr = (tracelog_hdr_t *)(trace + tracepos);
|
||||||
return ((next_records_datalen & 0x8000) == 0x8000);
|
return ((hdr->data_len & 0x8000) == 0x8000);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool merge_topaz_reader_frames(uint32_t timestamp, uint32_t *duration, uint16_t *tracepos, uint16_t traceLen,
|
static bool merge_topaz_reader_frames(uint32_t timestamp, uint32_t *duration, uint16_t *tracepos, uint16_t traceLen,
|
||||||
|
@ -101,22 +102,24 @@ static bool merge_topaz_reader_frames(uint32_t timestamp, uint32_t *duration, ui
|
||||||
|
|
||||||
memcpy(topaz_reader_command, frame, *data_len);
|
memcpy(topaz_reader_command, frame, *data_len);
|
||||||
|
|
||||||
while (!is_last_record(*tracepos, trace, traceLen) && !next_record_is_response(*tracepos, trace)) {
|
while (!is_last_record(*tracepos, traceLen) && !next_record_is_response(*tracepos, trace)) {
|
||||||
uint32_t next_timestamp = *((uint32_t *)(trace + *tracepos));
|
|
||||||
*tracepos += sizeof(uint32_t);
|
tracelog_hdr_t *hdr = (tracelog_hdr_t *)(trace + *tracepos);
|
||||||
uint16_t next_duration = *((uint16_t *)(trace + *tracepos));
|
|
||||||
*tracepos += sizeof(uint16_t);
|
uint32_t next_timestamp = hdr->timestamp;
|
||||||
uint16_t next_data_len = *((uint16_t *)(trace + *tracepos)) & 0x7FFF;
|
uint16_t next_duration = hdr->duration;
|
||||||
*tracepos += sizeof(uint16_t);
|
uint16_t next_data_len = hdr->data_len & 0x7FFF;
|
||||||
uint8_t *next_frame = (trace + *tracepos);
|
uint8_t *next_frame = hdr->frame;
|
||||||
*tracepos += next_data_len;
|
|
||||||
|
*tracepos += TRACELOG_HDR_LEN + next_data_len;
|
||||||
|
|
||||||
if ((next_data_len == 1) && (*data_len + next_data_len <= MAX_TOPAZ_READER_CMD_LEN)) {
|
if ((next_data_len == 1) && (*data_len + next_data_len <= MAX_TOPAZ_READER_CMD_LEN)) {
|
||||||
memcpy(topaz_reader_command + *data_len, next_frame, next_data_len);
|
memcpy(topaz_reader_command + *data_len, next_frame, next_data_len);
|
||||||
*data_len += next_data_len;
|
*data_len += next_data_len;
|
||||||
last_timestamp = next_timestamp + next_duration;
|
last_timestamp = next_timestamp + next_duration;
|
||||||
} else {
|
} else {
|
||||||
// rewind and exit
|
// rewind and exit
|
||||||
*tracepos = *tracepos - next_data_len - sizeof(uint16_t) - sizeof(uint16_t) - sizeof(uint32_t);
|
*tracepos = *tracepos - next_data_len - TRACELOG_HDR_LEN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uint16_t next_parity_len = (next_data_len - 1) / 8 + 1;
|
uint16_t next_parity_len = (next_data_len - 1) / 8 + 1;
|
||||||
|
@ -130,19 +133,20 @@ static bool merge_topaz_reader_frames(uint32_t timestamp, uint32_t *duration, ui
|
||||||
|
|
||||||
static uint16_t printHexLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, uint8_t protocol) {
|
static uint16_t printHexLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, uint8_t protocol) {
|
||||||
// sanity check
|
// sanity check
|
||||||
if (tracepos + TRACELOG_HDR_LEN > traceLen) return traceLen;
|
if (is_last_record(tracepos, traceLen)) return traceLen;
|
||||||
|
|
||||||
tracelog_hdr_t *hdr = (tracelog_hdr_t *)(trace + tracepos);
|
tracelog_hdr_t *hdr = (tracelog_hdr_t *)(trace + tracepos);
|
||||||
|
|
||||||
bool isResponse;
|
bool isResponse;
|
||||||
uint16_t parity_len;
|
uint16_t parity_len;
|
||||||
|
|
||||||
if (hdr->data_len & 0x8000) {
|
if ((hdr->data_len & 0x8000) == 0x8000) {
|
||||||
hdr->data_len &= 0x7fff;
|
hdr->data_len &= 0x7fff;
|
||||||
isResponse = true;
|
isResponse = true;
|
||||||
} else {
|
} else {
|
||||||
isResponse = false;
|
isResponse = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
parity_len = (hdr->data_len - 1) / 8 + 1;
|
parity_len = (hdr->data_len - 1) / 8 + 1;
|
||||||
|
|
||||||
if (sizeof(tracelog_hdr_t) + hdr->data_len + parity_len > traceLen) {
|
if (sizeof(tracelog_hdr_t) + hdr->data_len + parity_len > traceLen) {
|
||||||
|
@ -435,7 +439,7 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
||||||
explanation);
|
explanation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_last_record(tracepos, trace, traceLen)) return traceLen;
|
if (is_last_record(tracepos, traceLen)) return traceLen;
|
||||||
|
|
||||||
if (showWaitCycles && !isResponse && next_record_is_response(tracepos, trace)) {
|
if (showWaitCycles && !isResponse && next_record_is_response(tracepos, trace)) {
|
||||||
uint32_t next_timestamp = *((uint32_t *)(trace + tracepos));
|
uint32_t next_timestamp = *((uint32_t *)(trace + tracepos));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue