From ddaba93d328ad961c6538bfdf177ddeeeae72e10 Mon Sep 17 00:00:00 2001 From: Yann GASCUEL <34003959+lnv42@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:49:53 +0100 Subject: [PATCH] client: fileutils: iso15sim: add jfs15_v4 JSON format to fit eml fmt --- client/src/fileutils.c | 63 ++++++++++++++++++++++++++++++++++++++++++ client/src/fileutils.h | 1 + 2 files changed, 64 insertions(+) diff --git a/client/src/fileutils.c b/client/src/fileutils.c index 4f8ecda69..dc0ff8c3f 100644 --- a/client/src/fileutils.c +++ b/client/src/fileutils.c @@ -28,6 +28,7 @@ #include "util.h" #include "cmdhficlass.h" // pagemap #include "iclass_cmd.h" +#include "iso15.h" #ifdef _WIN32 #include "scandir.h" @@ -518,6 +519,33 @@ int saveFileJSONex(const char *preferredName, JSONFileType ftype, uint8_t *data, } break; } + // handles ISO15693 in iso15_tag_t format + case jsf15_v4: { + JsonSaveStr(root, "FileType", "15693 v4"); + iso15_tag_t *tag = (iso15_tag_t *)data; + JsonSaveBufAsHexCompact(root, "$.Card.uid", tag->uid, 8); + JsonSaveBufAsHexCompact(root, "$.Card.dsfid", &tag->dsfid, 1); + JsonSaveBufAsHexCompact(root, "$.Card.dsfidLock", (uint8_t*)&tag->dsfidLock, 1); + JsonSaveBufAsHexCompact(root, "$.Card.afi", &tag->afi, 1); + JsonSaveBufAsHexCompact(root, "$.Card.afiLock", (uint8_t*)&tag->afiLock, 1); + JsonSaveBufAsHexCompact(root, "$.Card.bytesPerPage", &tag->bytesPerPage, 1); + JsonSaveBufAsHexCompact(root, "$.Card.pagesCount", &tag->pagesCount, 1); + JsonSaveBufAsHexCompact(root, "$.Card.IC", &tag->ic, 1); + JsonSaveBufAsHexCompact(root, "$.Card.locks", tag->locks, tag->pagesCount); + JsonSaveBufAsHexCompact(root, "$.Card.random", tag->random, 2); + JsonSaveBufAsHexCompact(root, "$.Card.privacyPasswd", tag->privacyPasswd, 4); + JsonSaveBufAsHexCompact(root, "$.Card.state", (uint8_t*)&tag->state, 1); + + for (size_t i = 0 ; i < tag->pagesCount ; i++) { + if (((i+1) * tag->bytesPerPage) > ISO15693_TAG_MAX_SIZE) + break; + snprintf(path, sizeof(path), "$.blocks.%zu", i); + JsonSaveBufAsHexCompact(root, path, + &tag->data[i * tag->bytesPerPage], + tag->bytesPerPage); + } + break; + } case jsfLegic_v2: { JsonSaveStr(root, "FileType", "legic v2"); JsonSaveBufAsHexCompact(root, "$.Card.UID", data, 4); @@ -1673,6 +1701,41 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz goto out; } + if (!strcmp(ctype, "15693 v4")) { + iso15_tag_t *tag = (iso15_tag_t *)udata.bytes; + JsonLoadBufAsHex(root, "$.Card.UID", tag->uid, 8, datalen); + JsonLoadBufAsHex(root, "$.Card.dsfid", &tag->dsfid, 1, datalen); + JsonLoadBufAsHex(root, "$.Card.dsfidLock", (uint8_t*)&tag->dsfidLock, 1, datalen); + JsonLoadBufAsHex(root, "$.Card.afi", &tag->afi, 1, datalen); + JsonLoadBufAsHex(root, "$.Card.afiLock", (uint8_t*)&tag->afiLock, 1, datalen); + JsonLoadBufAsHex(root, "$.Card.bytesPerPage", &tag->bytesPerPage, 1, datalen); + JsonLoadBufAsHex(root, "$.Card.pagesCount", &tag->pagesCount, 1, datalen); + JsonLoadBufAsHex(root, "$.Card.IC", &tag->ic, 1, datalen); + JsonLoadBufAsHex(root, "$.Card.locks", tag->locks, tag->pagesCount, datalen); + JsonLoadBufAsHex(root, "$.Card.random", tag->random, 2, datalen); + JsonLoadBufAsHex(root, "$.Card.privacyPasswd", tag->privacyPasswd, 4, datalen); + JsonLoadBufAsHex(root, "$.Card.state", (uint8_t*)&tag->state, 1, datalen); + + size_t sptr = 0; + for (int i = 0; i < tag->pagesCount ; i++) { + if (((i+1) * tag->bytesPerPage) > ISO15693_TAG_MAX_SIZE) { + PrintAndLogEx(ERR, "loadFileJSONex: maxdatalen=%zu (%04zx) block (i)=%4d (%04x) sptr=%zu (%04zx) -- exceeded maxdatalen", maxdatalen, maxdatalen, i, i, sptr, sptr); + retval = PM3_EMALLOC; + goto out; + } + + snprintf(blocks, sizeof(blocks), "$.blocks.%d", i); + JsonLoadBufAsHex(root, blocks, &tag->data[sptr], tag->bytesPerPage, &len); + if (load_file_sanity(ctype, tag->bytesPerPage, i, len) == false) { + break; + } + sptr += len; + } + + *datalen = sptr; + goto out; + } + if (!strcmp(ctype, "legic v2")) { size_t sptr = 0; for (int i = 0; i < 64; i++) { diff --git a/client/src/fileutils.h b/client/src/fileutils.h index fa36fb89e..c4dcc5a0c 100644 --- a/client/src/fileutils.h +++ b/client/src/fileutils.h @@ -55,6 +55,7 @@ typedef enum { jsf15, jsf15_v2, jsf15_v3, + jsf15_v4, jsfLegic, jsfLegic_v2, jsfT55x7,