mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-22 06:13:27 -07:00
added tlvdb_change_or_add_node, change of element dont work...
This commit is contained in:
parent
7211c375a8
commit
86b44ab789
3 changed files with 32 additions and 3 deletions
|
@ -297,7 +297,7 @@ int UsageCmdHFEMVExec(void) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#define TLV_ADD(tag, value)( tlvdb_add(tlvRoot, tlvdb_fixed(tag, sizeof(value) - 1, (const unsigned char *)value)) )
|
||||
#define TLV_ADD(tag, value)( tlvdb_change_or_add_node(tlvRoot, tag, sizeof(value) - 1, (const unsigned char *)value) )
|
||||
#define dreturn(n) {free(pdol_data_tlv);tlvdb_free(tlvSelect);tlvdb_free(tlvRoot);DropField();return n;}
|
||||
|
||||
bool HexToBuffer(const char *errormsg, const char *hexvalue, uint8_t * buffer, size_t maxbufferlen, size_t *bufferlen) {
|
||||
|
@ -417,8 +417,7 @@ bool ParamLoadFromJson(struct tlvdb *tlv) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// TODO: here needs to be change_or_add!!!!
|
||||
tlvdb_add(tlv, tlvdb_fixed(tag, tlvLength, (const unsigned char *)buf));
|
||||
tlvdb_change_or_add_node(tlv, tag, tlvLength, (const unsigned char *)buf);
|
||||
}
|
||||
|
||||
json_decref(root);
|
||||
|
|
|
@ -342,6 +342,35 @@ void tlvdb_add(struct tlvdb *tlvdb, struct tlvdb *other)
|
|||
tlvdb->next = other;
|
||||
}
|
||||
|
||||
void tlvdb_change_or_add_node(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len, const unsigned char *value)
|
||||
{
|
||||
struct tlvdb *telm = tlvdb_find(tlvdb, tag);
|
||||
if (telm == NULL) {
|
||||
// new tlv element
|
||||
tlvdb_add(tlvdb, tlvdb_fixed(tag, len, value));
|
||||
} else {
|
||||
// the same tlv structure
|
||||
if (telm->tag.tag == tag && telm->tag.len == len && !memcmp(telm->tag.value, value, len))
|
||||
return;
|
||||
|
||||
PrintAndLog("-replace %x", tag);
|
||||
// replace tlv element
|
||||
struct tlvdb *tnewelm = tlvdb_fixed(tag, len, value);
|
||||
tnewelm->next = telm->next;
|
||||
tnewelm->parent = telm->parent;
|
||||
|
||||
if (telm->parent && telm->parent->children == telm) {
|
||||
telm->parent->children = tnewelm;
|
||||
}
|
||||
|
||||
|
||||
// telm->next = NULL;
|
||||
// tlvdb_free(telm);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void tlvdb_visit(const struct tlvdb *tlvdb, tlv_cb cb, void *data, int level)
|
||||
{
|
||||
struct tlvdb *next = NULL;
|
||||
|
|
|
@ -44,6 +44,7 @@ struct tlvdb *tlvdb_find_next(struct tlvdb *tlvdb, tlv_tag_t tag);
|
|||
struct tlvdb *tlvdb_find_path(struct tlvdb *tlvdb, tlv_tag_t tag[]);
|
||||
|
||||
void tlvdb_add(struct tlvdb *tlvdb, struct tlvdb *other);
|
||||
void tlvdb_change_or_add_node(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len, const unsigned char *value);
|
||||
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue