mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-24 06:55:27 -07:00
added sketch for json loading
This commit is contained in:
parent
b56bdc3c37
commit
ffee924db5
1 changed files with 65 additions and 20 deletions
|
@ -300,24 +300,69 @@ int UsageCmdHFEMVExec(void) {
|
|||
#define TLV_ADD(tag, value)( tlvdb_add(tlvRoot, tlvdb_fixed(tag, sizeof(value) - 1, (const unsigned char *)value)) )
|
||||
#define dreturn(n) {free(pdol_data_tlv);tlvdb_free(tlvSelect);tlvdb_free(tlvRoot);DropField();return n;}
|
||||
|
||||
void ParamLoadFromJson() {
|
||||
bool ParamLoadFromJson() {
|
||||
json_t *root;
|
||||
json_error_t error;
|
||||
|
||||
char *text = "{\"json\":22}";
|
||||
|
||||
root = json_loads(text, 0, &error);
|
||||
|
||||
if (root) {
|
||||
PrintAndLog("json OK");
|
||||
return; //root;
|
||||
} else {
|
||||
PrintAndLog("json error on line %d: %s", error.line, error.text);
|
||||
return; //(json_t *)0;
|
||||
// TODO: add search current path
|
||||
root = json_load_file("./emv/defparams.json", 0, &error);
|
||||
if (!root) {
|
||||
PrintAndLog("Load params: json error on line %d: %s", error.line, error.text);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
if (!json_is_array(root)) {
|
||||
PrintAndLog("Load params: Invalid json format. root must be array.");
|
||||
return false;
|
||||
}
|
||||
|
||||
PrintAndLog("Load params: json OK");
|
||||
|
||||
for(int i = 0; i < json_array_size(root); i++) {
|
||||
json_t *data, *jtype, *jlength, *jvalue;
|
||||
|
||||
data = json_array_get(root, i);
|
||||
if(!json_is_object(data))
|
||||
{
|
||||
PrintAndLog("Load params: data [%d] is not an object", i + 1);
|
||||
json_decref(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
jtype = json_object_get(data, "type");
|
||||
if(!json_is_string(jtype))
|
||||
{
|
||||
PrintAndLog("Load params: data [%d] type is not a string", i + 1);
|
||||
json_decref(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
jvalue = json_object_get(data, "value");
|
||||
if(!json_is_string(jvalue))
|
||||
{
|
||||
PrintAndLog("Load params: data [%d] value is not a string", i + 1);
|
||||
json_decref(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
jlength = json_object_get(data, "length");
|
||||
if(!json_is_number(jlength))
|
||||
{
|
||||
PrintAndLog("Load params: data [%d] length is not a number", i + 1);
|
||||
json_decref(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
json_decref(root);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int CmdHFEMVExec(const char *cmd) {
|
||||
bool activateField = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue