mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-21 22:03:19 -07:00
add tlv tag save to json
This commit is contained in:
parent
0635c570d5
commit
c3bf91edaf
4 changed files with 48 additions and 1 deletions
|
@ -1170,6 +1170,37 @@ int JsonSaveHex(json_t *elm, char *path, uint64_t data, int datalen) {
|
|||
return JsonSaveBufAsHex(elm, path, bdata, len);
|
||||
}
|
||||
|
||||
int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveValue) {
|
||||
json_error_t error;
|
||||
|
||||
if (strlen(path) < 1)
|
||||
return 1;
|
||||
|
||||
if (path[0] == '$') {
|
||||
json_t *obj = json_object();
|
||||
|
||||
if (json_path_set(elm, path, obj, 0, &error)) {
|
||||
PrintAndLog("ERROR: can't set json path: ", error.text);
|
||||
return 2;
|
||||
} else {
|
||||
char * name = emv_get_tag_name(tlvelm);
|
||||
if (name && strlen(name) > 0 && strncmp(name, "Unknown", 7))
|
||||
JsonSaveStr(obj, "name", emv_get_tag_name(tlvelm));
|
||||
JsonSaveHex(obj, "tag", tlvelm->tag, 0);
|
||||
JsonSaveHex(obj, "length", tlvelm->len, 0);
|
||||
if (saveValue)
|
||||
JsonSaveBufAsHex(obj, "value", (uint8_t *)tlvelm->value, tlvelm->len);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JsonSaveTLVTreeElm(json_t *elm, char *path, struct tlvdb *tlvdbelm, bool saveValue) {
|
||||
JsonSaveTLVElm(elm, path, (struct tlv *)tlvdb_get_tlv(tlvdbelm), saveValue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHFEMVScan(const char *cmd) {
|
||||
uint8_t AID[APDU_AID_LEN] = {0};
|
||||
size_t AIDlen = 0;
|
||||
|
@ -1269,8 +1300,8 @@ int CmdHFEMVScan(const char *cmd) {
|
|||
if (!res) {
|
||||
TLVPrintAIDlistFromSelectTLV(tlvSelect);
|
||||
|
||||
JsonSaveStr(root, "$.PPSE.ver", "1.0");
|
||||
JsonSaveBufAsHex(root, "$.PPSE.AID", (uint8_t *)"2PAY.SYS.DDF01", 14);
|
||||
JsonSaveTLVTreeElm(root, "$.PPSE.FCITemplate", tlvdb_find(tlvSelect, 0x6f), true);
|
||||
// here save PSE result to JSON
|
||||
|
||||
} else {
|
||||
|
|
|
@ -686,3 +686,17 @@ bool emv_tag_dump(const struct tlv *tlv, FILE *f, int level)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
char *emv_get_tag_name(const struct tlv *tlv)
|
||||
{
|
||||
static char *defstr = "";
|
||||
|
||||
if (!tlv)
|
||||
return defstr;
|
||||
|
||||
const struct emv_tag *tag = emv_get_tag(tlv);
|
||||
if (tag)
|
||||
return tag->name;
|
||||
|
||||
return defstr;
|
||||
}
|
||||
|
|
|
@ -31,5 +31,6 @@
|
|||
# define EMVCID_REASON_MASK 0x07
|
||||
|
||||
bool emv_tag_dump(const struct tlv *tlv, FILE *f, int level);
|
||||
char *emv_get_tag_name(const struct tlv *tlv);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -50,6 +50,7 @@ void tlvdb_change_or_add_node(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len, co
|
|||
void tlvdb_visit(const struct tlvdb *tlvdb, tlv_cb cb, void *data, int level);
|
||||
const struct tlv *tlvdb_get(const struct tlvdb *tlvdb, tlv_tag_t tag, const struct tlv *prev);
|
||||
const struct tlv *tlvdb_get_inchild(const struct tlvdb *tlvdb, tlv_tag_t tag, const struct tlv *prev);
|
||||
const struct tlv *tlvdb_get_tlv(const struct tlvdb *tlvdb);
|
||||
|
||||
bool tlv_parse_tl(const unsigned char **buf, size_t *len, struct tlv *tlv);
|
||||
unsigned char *tlv_encode(const struct tlv *tlv, size_t *len);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue