add iclass json dump format

This commit is contained in:
iceman1001 2019-08-24 13:16:28 +02:00
parent ec174a7232
commit f9d8d56317
2 changed files with 35 additions and 0 deletions

View file

@ -281,6 +281,19 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s
}
break;
}
case jsfIclass: {
JsonSaveStr(root, "FileType", "iclass");
uint8_t uid[8] = {0};
memcpy(uid, data, 8);
JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid));
for (size_t i = 0; i < (datalen / 8 ); i++) {
char path[PATH_MAX_LENGTH] = {0};
sprintf(path, "$blocks.%zu", i);
JsonSaveBufAsHexCompact(root, path, data + (i * 8), 8);
}
break;
}
}
int res = json_dump_file(root, fileName, JSON_INDENT(2));
@ -512,6 +525,27 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_
*datalen = sptr;
}
if (!strcmp(ctype, "iclass")) {
size_t sptr = 0;
for (size_t i = 0; i < (maxdatalen / 8); i++) {
if (sptr + 8 > maxdatalen) {
retval = 5;
goto out;
}
char path[30] = {0};
sprintf(path, "$.blocks.%zu", i);
size_t len = 0;
JsonLoadBufAsHex(root, path, &udata[sptr], 8, &len);
if (!len)
break;
sptr += len;
}
*datalen = sptr;
}
PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName);
out:
json_decref(root);

View file

@ -54,6 +54,7 @@ typedef enum {
jsfCardMemory,
jsfMfuMemory,
jsfHitag,
jsfIclass,
// jsf14b,
// jsf15,
// jsfLegic,