From 003a0b0de4916b85435b3755b2e802008e1e5151 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Mon, 5 Jul 2021 12:40:07 +0300 Subject: [PATCH] splitbysize now put length of message at the first bytes of array's memory --- client/src/cmdhfmfdes.c | 8 ++++---- client/src/mifare/desfirecore.c | 26 ++++++++++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index c7a195db5..3560d5bf3 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -5298,10 +5298,10 @@ static int CmdHF14ADesGetAppNames(const char *Cmd) { PrintAndLogEx(INFO, "----------------------- " _CYAN_("File list") " -----------------------"); for (int i = 0; i < buflen; i++) PrintAndLogEx(INFO, "AID: %06x ISO file id: %02x%02x ISO DF name[%d]: %s", - DesfireAIDByteToUint(&buf[i * 24]), - buf[i * 24 + 3], buf[i * 24 + 4], - strlen((char *)&buf[i * 24 + 5]), - &buf[i * 24 + 5]); + DesfireAIDByteToUint(&buf[i * 24 + 1]), + buf[i * 24 + 1 + 3], buf[i * 24 + 1 + 4], + strlen((char *)&buf[i * 24 + 1 + 5]), + &buf[i * 24 + 1 + 5]); } DropField(); diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index a461fb254..fee49ca5a 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -404,8 +404,14 @@ static int DesfireExchangeNative(bool activate_field, DesfireContext *ctx, uint8 return res; } - if (resp) - memcpy(resp, buf, buflen); + if (resp) { + if (splitbysize) { + resp[0] = buflen; + memcpy(&resp[1], buf, buflen); + } else { + memcpy(resp, buf, buflen); + } + } if (respcode != NULL) *respcode = rcode; @@ -434,7 +440,8 @@ static int DesfireExchangeNative(bool activate_field, DesfireContext *ctx, uint8 if (resp != NULL) { if (splitbysize) { - memcpy(&resp[i * splitbysize], buf, buflen); + resp[i * splitbysize] = buflen; + memcpy(&resp[i * splitbysize + 1], buf, buflen); i += 1; } else { memcpy(&resp[pos], buf, buflen); @@ -480,8 +487,14 @@ static int DesfireExchangeISO(bool activate_field, DesfireContext *ctx, uint8_t if (respcode != NULL && ((sw & 0xff00) == 0x9100)) *respcode = sw & 0xff; - if (resp) - memcpy(resp, buf, buflen); + if (resp) { + if (splitbysize) { + resp[0] = buflen; + memcpy(&resp[1], buf, buflen); + } else { + memcpy(resp, buf, buflen); + } + } pos += buflen; if (!enable_chaining) { @@ -512,7 +525,8 @@ static int DesfireExchangeISO(bool activate_field, DesfireContext *ctx, uint8_t if (resp != NULL) { if (splitbysize) { - memcpy(&resp[i * splitbysize], buf, buflen); + resp[i * splitbysize] = buflen; + memcpy(&resp[i * splitbysize + 1], buf, buflen); i += 1; } else { memcpy(&resp[pos], buf, buflen);