diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e39702d7..6a0a18f0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac ## [unreleased][unreleased] +- Fixed `lf em 4x05 dump` writing byte-swapped (corrupted) block data to the saved dump file (@munzzyy) - Added `hf 14b dump` support for Standard ISO14443-B tags (@thisiscamk) - Added `hf 14b ctrdbl` and `hf 14b ctdump` commands for interacting with ASK CTS tags (@kormax) - Fixed `hf legic migrate` failing to parse the optional DCF argument as hex (@IdanHo) diff --git a/client/src/cmdlfem4x05.c b/client/src/cmdlfem4x05.c index 17e1b73be..80940c5f2 100644 --- a/client/src/cmdlfem4x05.c +++ b/client/src/cmdlfem4x05.c @@ -934,14 +934,20 @@ static void em4x05_print_footer(void) { PrintAndLogEx(NORMAL, ""); } -static void em4x05_print_blocks(em_tech_type_t cardtype, uint8_t *data, uint8_t dlen) { +static void em4x05_print_blocks(em_tech_type_t cardtype, const uint8_t *src, uint8_t dlen) { // must have 4 byte alignment - if ((data == NULL) || (dlen % EM4X05_BLOCK_SIZE) != 0) { + if ((src == NULL) || (dlen % EM4X05_BLOCK_SIZE) != 0) { return; } - uint32_t *d = (void *)data; + // Work on a private copy. This routine byte-swaps the buffer for display, + // and callers such as CmdEM4x05Dump() still need the original bytes + // afterwards to save an uncorrupted dump to file (issue #3403). + // dlen is a uint8_t, so 64 words is enough to hold any valid input. + uint32_t d[64] = {0}; + memcpy(d, src, dlen); + uint8_t *data = (uint8_t *)d; uint8_t i; for (i = 0; i < (dlen >> 2); i++) {