This commit is contained in:
iceman1001 committed 2025-11-10 16:20:50 +01:00
1 parent ed516550ca
commit abb0427960
1 file changed
+36 -37
+36 -37
View File
@@ -334,27 +334,27 @@ int hf14a_setconfig(hf14a_config_t *config, bool verbose) {
static json_t *load_ecplist(void) { static json_t *load_ecplist(void) {
json_error_t error; json_error_t error;
char *path; char *path;
int res = searchFile(&path, RESOURCES_SUBDIR, "ecplist", ".json", false); int res = searchFile(&path, RESOURCES_SUBDIR, "ecplist", ".json", false);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Cannot find ecplist.json"); PrintAndLogEx(ERR, "Cannot find ecplist.json");
return NULL; return NULL;
} }
json_t *root = json_load_file(path, 0, &error); json_t *root = json_load_file(path, 0, &error);
free(path); free(path);
if (!root) { if (!root) {
PrintAndLogEx(ERR, "json error on line %d: %s", error.line, error.text); PrintAndLogEx(ERR, "json error on line %d: %s", error.line, error.text);
return NULL; return NULL;
} }
if (!json_is_array(root)) { if (!json_is_array(root)) {
PrintAndLogEx(ERR, "Invalid ecplist.json format. Root must be an array."); PrintAndLogEx(ERR, "Invalid ecplist.json format. Root must be an array.");
json_decref(root); json_decref(root);
return NULL; return NULL;
} }
return root; return root;
} }
@@ -365,7 +365,7 @@ static json_t *load_ecplist(void) {
static json_t *search_ecplist_by_key(json_t *root, const char *type, const char *subtype, const char *key) { static json_t *search_ecplist_by_key(json_t *root, const char *type, const char *subtype, const char *key) {
size_t index; size_t index;
json_t *entry; json_t *entry;
json_array_foreach(root, index, entry) { json_array_foreach(root, index, entry) {
// If type filter is specified, check if entry has matching type // If type filter is specified, check if entry has matching type
if (type != NULL) { if (type != NULL) {
@@ -373,7 +373,7 @@ static json_t *search_ecplist_by_key(json_t *root, const char *type, const char
if (!type_obj) { if (!type_obj) {
continue; // Skip entries without type field continue; // Skip entries without type field
} }
bool type_matched = false; bool type_matched = false;
if (json_is_string(type_obj)) { if (json_is_string(type_obj)) {
const char *type_str = json_string_value(type_obj); const char *type_str = json_string_value(type_obj);
@@ -391,7 +391,7 @@ static json_t *search_ecplist_by_key(json_t *root, const char *type, const char
} }
} }
} }
if (!type_matched) { if (!type_matched) {
continue; // Type doesn't match continue; // Type doesn't match
} }
@@ -401,10 +401,10 @@ static json_t *search_ecplist_by_key(json_t *root, const char *type, const char
continue; continue;
} }
} }
bool key_matched = (key == NULL); // If no key specified, consider it matched bool key_matched = (key == NULL); // If no key specified, consider it matched
bool subtype_matched = (subtype == NULL); // If no subtype specified, consider it matched bool subtype_matched = (subtype == NULL); // If no subtype specified, consider it matched
// Check if the subtype matches the "subtype" field (string or array) // Check if the subtype matches the "subtype" field (string or array)
if (subtype != NULL) { if (subtype != NULL) {
json_t *subtype_obj = json_object_get(entry, "subtype"); json_t *subtype_obj = json_object_get(entry, "subtype");
@@ -427,7 +427,7 @@ static json_t *search_ecplist_by_key(json_t *root, const char *type, const char
} }
} }
} }
// Check if the key matches the "key" field (string or array) // Check if the key matches the "key" field (string or array)
if (key != NULL) { if (key != NULL) {
json_t *key_obj = json_object_get(entry, "key"); json_t *key_obj = json_object_get(entry, "key");
@@ -450,13 +450,13 @@ static json_t *search_ecplist_by_key(json_t *root, const char *type, const char
} }
} }
} }
// Entry must match both key and subtype criteria (if specified) // Entry must match both key and subtype criteria (if specified)
if (key_matched && subtype_matched) { if (key_matched && subtype_matched) {
return entry; return entry;
} }
} }
return NULL; // Not found return NULL; // Not found
} }
@@ -472,7 +472,7 @@ static int parse_ecp_subcommand(const char *cmd, uint8_t *frame, size_t frame_si
if (!cmd_copy) { if (!cmd_copy) {
return -1; return -1;
} }
for (char *p_char = cmd_copy; *p_char != '\0'; p_char++) { for (char *p_char = cmd_copy; *p_char != '\0'; p_char++) {
if (*p_char == '.' || *p_char == ':') { if (*p_char == '.' || *p_char == ':') {
*p_char = ' '; *p_char = ' ';
@@ -499,7 +499,7 @@ static int parse_ecp_subcommand(const char *cmd, uint8_t *frame, size_t frame_si
int result = -1; int result = -1;
const char *type = NULL; const char *type = NULL;
const char *search_term = p; const char *search_term = p;
// Check if first term is a type ("transit" or "access") // Check if first term is a type ("transit" or "access")
if (strncmp(p, "transit", 7) == 0) { if (strncmp(p, "transit", 7) == 0) {
type = "transit"; type = "transit";
@@ -508,7 +508,7 @@ static int parse_ecp_subcommand(const char *cmd, uint8_t *frame, size_t frame_si
p++; p++;
} }
search_term = p; search_term = p;
// If second term provided, search by key in transit entries // If second term provided, search by key in transit entries
if (*p != '\0') { if (*p != '\0') {
json_t *entry = search_ecplist_by_key(ecplist, type, NULL, search_term); json_t *entry = search_ecplist_by_key(ecplist, type, NULL, search_term);
@@ -528,7 +528,7 @@ static int parse_ecp_subcommand(const char *cmd, uint8_t *frame, size_t frame_si
} }
} }
} }
// If not found, try interpreting as hex TCI // If not found, try interpreting as hex TCI
if (result == -1) { if (result == -1) {
char *endptr; char *endptr;
@@ -556,34 +556,34 @@ static int parse_ecp_subcommand(const char *cmd, uint8_t *frame, size_t frame_si
} else { } else {
PrintAndLogEx(ERR, "Transit type requires a key or TCI value"); PrintAndLogEx(ERR, "Transit type requires a key or TCI value");
} }
} else if (strncmp(p, "access", 6) == 0) { } else if (strncmp(p, "access", 6) == 0) {
type = "access"; type = "access";
p += 6; p += 6;
while (*p == ' ' || *p == '\t') { while (*p == ' ' || *p == '\t') {
p++; p++;
} }
// Parse second term // Parse second term
const char *second_term = p; const char *second_term = p;
// Skip to end of second term // Skip to end of second term
while (*p != '\0' && *p != ' ' && *p != '\t') { while (*p != '\0' && *p != ' ' && *p != '\t') {
p++; p++;
} }
// Extract second term // Extract second term
size_t second_term_len = p - second_term; size_t second_term_len = p - second_term;
char *second = NULL; char *second = NULL;
if (second_term_len > 0) { if (second_term_len > 0) {
second = str_ndup(second_term, second_term_len); second = str_ndup(second_term, second_term_len);
} }
// Skip whitespace // Skip whitespace
while (*p == ' ' || *p == '\t') { while (*p == ' ' || *p == '\t') {
p++; p++;
} }
// Parse third term if present // Parse third term if present
const char *third_term = p; const char *third_term = p;
char *third = NULL; char *third = NULL;
@@ -597,26 +597,26 @@ static int parse_ecp_subcommand(const char *cmd, uint8_t *frame, size_t frame_si
third = str_ndup(third_term, third_term_len); third = str_ndup(third_term, third_term_len);
} }
} }
// Default TCI is 02ffff if not provided // Default TCI is 02ffff if not provided
uint32_t tci = 0x02ffff; uint32_t tci = 0x02ffff;
// If terms provided, try to parse them // If terms provided, try to parse them
if (second != NULL && *second != '\0') { if (second != NULL && *second != '\0') {
json_t *entry = NULL; json_t *entry = NULL;
if (third != NULL && *third != '\0') { if (third != NULL && *third != '\0') {
// Two terms: second is subtype, third is key // Two terms: second is subtype, third is key
entry = search_ecplist_by_key(ecplist, type, second, third); entry = search_ecplist_by_key(ecplist, type, second, third);
} else { } else {
// One term: try as subtype first, then as key // One term: try as subtype first, then as key
entry = search_ecplist_by_key(ecplist, type, second, NULL); entry = search_ecplist_by_key(ecplist, type, second, NULL);
if (!entry) { if (!entry) {
entry = search_ecplist_by_key(ecplist, type, NULL, second); entry = search_ecplist_by_key(ecplist, type, NULL, second);
} }
} }
if (entry) { if (entry) {
// Found matching entry, use its value // Found matching entry, use its value
json_t *value_obj = json_object_get(entry, "value"); json_t *value_obj = json_object_get(entry, "value");
@@ -633,7 +633,7 @@ static int parse_ecp_subcommand(const char *cmd, uint8_t *frame, size_t frame_si
} }
} }
} }
// If not found and no third term, try interpreting second term as hex TCI // If not found and no third term, try interpreting second term as hex TCI
if (result == -1 && third == NULL) { if (result == -1 && third == NULL) {
char *endptr; char *endptr;
@@ -655,14 +655,14 @@ static int parse_ecp_subcommand(const char *cmd, uint8_t *frame, size_t frame_si
return -1; return -1;
} }
} }
if (second) { if (second) {
free(second); free(second);
} }
if (third) { if (third) {
free(third); free(third);
} }
// Build frame with TCI if we didn't find a matching entry // Build frame with TCI if we didn't find a matching entry
if (result == -1) { if (result == -1) {
// Build frame: 6a02c30200{tci as 3 bytes} // Build frame: 6a02c30200{tci as 3 bytes}
@@ -676,7 +676,7 @@ static int parse_ecp_subcommand(const char *cmd, uint8_t *frame, size_t frame_si
frame[7] = tci & 0xff; frame[7] = tci & 0xff;
result = 8; result = 8;
} }
} else { } else {
// No type specified, search for entries without type field by key // No type specified, search for entries without type field by key
json_t *entry = search_ecplist_by_key(ecplist, search_term, NULL, NULL); json_t *entry = search_ecplist_by_key(ecplist, search_term, NULL, NULL);
@@ -699,7 +699,7 @@ static int parse_ecp_subcommand(const char *cmd, uint8_t *frame, size_t frame_si
PrintAndLogEx(HINT, "Available types: access, transit, vasorpay, vasandpay, vasonly, payonly, gymkit, identity, aidrop"); PrintAndLogEx(HINT, "Available types: access, transit, vasorpay, vasandpay, vasonly, payonly, gymkit, identity, aidrop");
} }
} }
json_decref(ecplist); json_decref(ecplist);
free(cmd_copy); free(cmd_copy);
return result; return result;
@@ -879,11 +879,11 @@ static int CmdHf14AConfig(const char *Cmd) {
.last_byte_bits = 8, .last_byte_bits = 8,
.extra_delay = 5 .extra_delay = 5
}; };
// Get main --pla value // Get main --pla value
CLIParamStrToBuf(arg_get_str(ctx, 7), (uint8_t *)value, sizeof(value), &vlen); CLIParamStrToBuf(arg_get_str(ctx, 7), (uint8_t *)value, sizeof(value), &vlen);
str_lower((char *)value); str_lower((char *)value);
if (vlen > 0) { if (vlen > 0) {
if (strncmp((char *)value, "std", 3) == 0) pla.frame_length = 0; if (strncmp((char *)value, "std", 3) == 0) pla.frame_length = 0;
else if (strncmp((char *)value, "skip", 4) == 0) pla.frame_length = 0; else if (strncmp((char *)value, "skip", 4) == 0) pla.frame_length = 0;
@@ -904,8 +904,7 @@ static int CmdHf14AConfig(const char *Cmd) {
pla.frame[pla.frame_length++] = first; pla.frame[pla.frame_length++] = first;
pla.frame[pla.frame_length++] = second; pla.frame[pla.frame_length++] = second;
PrintAndLogEx(INFO, "Set polling loop annotation to ECP: %s", sprint_hex(pla.frame, pla.frame_length)); PrintAndLogEx(INFO, "Set polling loop annotation to ECP: %s", sprint_hex(pla.frame, pla.frame_length));
} } else {
else {
// Convert hex string to bytes // Convert hex string to bytes
int length = 0; int length = 0;
if (param_gethex_to_eol((char *)value, 0, pla.frame, sizeof(pla.frame), &length) != 0) { if (param_gethex_to_eol((char *)value, 0, pla.frame, sizeof(pla.frame), &length) != 0) {