From 072e83bc4977e3bba98d988cbe95257224af9b33 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 13 Mar 2019 17:50:10 +0100 Subject: [PATCH] chg: 'lf hitag reader' - now support json format --- client/cmdlfhitag.c | 19 ++++++++++--------- client/cmdlfhitag.h | 2 +- client/loclass/fileutils.c | 24 ++++++++++++++++++++---- client/loclass/fileutils.h | 5 +++++ 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/client/cmdlfhitag.c b/client/cmdlfhitag.c index 5a245a345..52952bef6 100644 --- a/client/cmdlfhitag.c +++ b/client/cmdlfhitag.c @@ -303,6 +303,7 @@ int CmdLFHitagReader(const char *Cmd) { saveFile(filename, "bin", data, 48); saveFileEML(filename, "eml", data, 48, 4); + saveFileJSON(filename, "json", jsfHitag, (uint8_t *)data, 48); } return 0; } @@ -377,7 +378,7 @@ int CmdLFHitagCheckChallenges(const char *Cmd) { return 0; } -int CmdLFHitagWP(const char *Cmd) { +int CmdLFHitagWriter(const char *Cmd) { UsbCommand c = { CMD_WR_HITAG_S }; hitag_data *htd = (hitag_data *)c.d.asBytes; hitag_function htf = param_get32ex(Cmd, 0, 0, 10); @@ -419,14 +420,14 @@ int CmdLFHitagWP(const char *Cmd) { } static command_t CommandTable[] = { - {"help", CmdHelp, 1, "This help"}, - {"list", CmdLFHitagList, 1, " List Hitag trace history"}, - {"reader", CmdLFHitagReader, 1, "Act like a Hitag Reader"}, - {"sim", CmdLFHitagSim, 1, " Simulate Hitag transponder"}, - {"simS", CmdLFHitagSimS, 1, " Simulate HitagS transponder" }, - {"sniff", CmdLFHitagSniff, 1, "Eavesdrop Hitag communication"}, - {"writer", CmdLFHitagWP, 1, "Act like a Hitag Writer" }, - {"check_challenges", CmdLFHitagCheckChallenges, 1, " test all challenges" }, + {"help", CmdHelp, 1, "This help"}, + {"list", CmdLFHitagList, 1, " List Hitag trace history"}, + {"reader", CmdLFHitagReader, 1, "Act like a Hitag Reader"}, + {"sim", CmdLFHitagSim, 1, " Simulate Hitag transponder"}, + {"simS", CmdLFHitagSimS, 1, " Simulate HitagS transponder" }, + {"sniff", CmdLFHitagSniff, 1, "Eavesdrop Hitag communication"}, + {"writer", CmdLFHitagWriter, 1, "Act like a Hitag Writer" }, + {"check_challenges", CmdLFHitagCheckChallenges, 1, " test all challenges" }, { NULL, NULL, 0, NULL } }; diff --git a/client/cmdlfhitag.h b/client/cmdlfhitag.h index 2c39ef345..4fa311f2e 100644 --- a/client/cmdlfhitag.h +++ b/client/cmdlfhitag.h @@ -18,7 +18,7 @@ extern int CmdLFHitagReader(const char *Cmd); extern int CmdLFHitagSim(const char *Cmd); extern int CmdLFHitagSimS(const char *Cmd); extern int CmdLFHitagSniff(const char *Cmd); -extern int CmdLFHitagWP(const char *Cmd); +extern int CmdLFHitagWriter(const char *Cmd); extern int CmdLFHitagCheckChallenges(const char *Cmd); #endif diff --git a/client/loclass/fileutils.c b/client/loclass/fileutils.c index 4d58c7084..45be3be04 100644 --- a/client/loclass/fileutils.c +++ b/client/loclass/fileutils.c @@ -155,11 +155,12 @@ int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType fty json_t *root = json_object(); JsonSaveStr(root, "Created", "proxmark3"); switch (ftype) { - case jsfRaw: + case jsfRaw: { JsonSaveStr(root, "FileType", "raw"); JsonSaveBufAsHexCompact(root, "raw", data, datalen); break; - case jsfCardMemory: + } + case jsfCardMemory: { JsonSaveStr(root, "FileType", "mfcard"); for (int i = 0; i < (datalen / 16); i++) { char path[PATH_MAX_LENGTH] = {0}; @@ -208,7 +209,8 @@ int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType fty } } break; - case jsfMfuMemory: + } + case jsfMfuMemory: { JsonSaveStr(root, "FileType", "mfu"); mfu_dump_t *tmp = (mfu_dump_t *)data; @@ -230,12 +232,26 @@ int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType fty size_t len = (datalen - DUMP_PREFIX_LENGTH) / 4; for (int i = 0; i < len; i++) { - char path[PATH_MAX_LENGTH] = {0}; sprintf(path, "$.blocks.%d", i); JsonSaveBufAsHexCompact(root, path, tmp->data + (i * 4), 4); } break; + } + case jsfHitag: { + JsonSaveStr(root, "FileType", "hitag"); + uint8_t uid[4] = {0}; + memcpy(uid, data, 4); + + JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid)); + + for (int i = 0; i < (datalen / 4); i++) { + char path[PATH_MAX_LENGTH] = {0}; + sprintf(path, "$.blocks.%d", i); + JsonSaveBufAsHexCompact(root, path, data + (i * 4), 4); + } + break; + } } int res = json_dump_file(root, fileName, JSON_INDENT(2)); diff --git a/client/loclass/fileutils.h b/client/loclass/fileutils.h index c2888c196..f77dfd040 100644 --- a/client/loclass/fileutils.h +++ b/client/loclass/fileutils.h @@ -55,6 +55,11 @@ typedef enum { jsfRaw, jsfCardMemory, jsfMfuMemory, + jsfHitag, +// jsf14b, +// jsf15, +// jsfLegic, +// jsfT55xx, } JSONFileType; int fileExists(const char *filename);