# HG changeset patch # User Mychaela Falconia # Date 1614238114 0 # Node ID 26d7a88155159b07f13399b9e83f1ee4eacaf794 # Parent db43bc57ecf71c6f189a270b00418b083b6cf679 fc-simtool bfsearch-full implemented diff -r db43bc57ecf7 -r 26d7a8815515 simtool/bfsearch.c --- a/simtool/bfsearch.c Thu Feb 25 07:00:51 2021 +0000 +++ b/simtool/bfsearch.c Thu Feb 25 07:28:34 2021 +0000 @@ -8,6 +8,7 @@ #include #include #include "simresp.h" +#include "file_id.h" static parse_skip_ids(argv, array, total) @@ -127,3 +128,103 @@ } return(0); } + +static +bfsearch_dir(path, pathlen, siblings, nsiblings, outf) + unsigned *path, pathlen, *siblings, nsiblings; + FILE *outf; +{ + unsigned bfs, n; + unsigned df_children[255], ndfc; + unsigned childpath[8]; + int rc; + + for (n = 0; n < pathlen; n++) { + rc = elem_select_op(path[n]); + if (rc < 0) + return(rc); + if (!rc) { + fprintf(stderr, + "error selecting 0x%04X: file not found\n", + path[n]); + return(-1); + } + } + ndfc = 0; + for (bfs = 0; bfs <= 0xFFFF; bfs++) { + for (n = 0; n < pathlen; n++) { + if (bfs == path[n]) + break; + } + if (n < pathlen) + continue; + for (n = 0; n < nsiblings; n++) { + if (bfs == siblings[n]) + break; + } + if (n < nsiblings) + continue; + rc = elem_select_op(bfs); + if (rc < 0) + return(rc); + if (!rc) + continue; + rc = get_response_op(); + if (rc < 0) + return(rc); + for (n = 0; n < pathlen; n++) + fprintf(outf, "%04X/", path[n]); + fprintf(outf, "%04X: ", bfs); + if (sim_resp_data_len < 14) + fprintf(outf, "too-short response struct\n"); + else { + switch (sim_resp_data[6]) { + case 0x01: + fprintf(outf, "MF\n"); + break; + case 0x02: + fprintf(outf, "DF\n"); + if (ndfc < 255) + df_children[ndfc++] = bfs; + break; + case 0x04: + report_ef_struct(outf); + break; + default: + fprintf(outf, "unknown file type %02X\n", + sim_resp_data[6]); + } + } + rc = elem_select_op(path[pathlen-1]); + if (rc < 0) + return(rc); + if (!rc) { + fprintf(stderr, + "reselecting starting file ID 0x%04X not-found error\n", + path[pathlen-1]); + return(-1); + } + } + if (pathlen >= 8) + return(0); + for (n = 0; n < pathlen; n++) + childpath[n] = path[n]; + for (n = 0; n < ndfc; n++) { + childpath[pathlen] = df_children[n]; + rc = bfsearch_dir(childpath, pathlen + 1, df_children, ndfc, + outf); + if (rc < 0) + return(rc); + } + return(0); +} + +cmd_bfsearch_full(argc, argv, outf) + char **argv; + FILE *outf; +{ + unsigned initpath; + + initpath = FILEID_MF; + return bfsearch_dir(&initpath, 1, &initpath, 1, outf); +} diff -r db43bc57ecf7 -r 26d7a8815515 simtool/dispatch.c --- a/simtool/dispatch.c Thu Feb 25 07:00:51 2021 +0000 +++ b/simtool/dispatch.c Thu Feb 25 07:28:34 2021 +0000 @@ -11,6 +11,7 @@ extern int cmd_a38(); extern int cmd_apdu(); extern int cmd_bfsearch(); +extern int cmd_bfsearch_full(); extern int cmd_cd(); extern int cmd_change_chv(); extern int cmd_disable_chv(); @@ -110,6 +111,7 @@ {"apdu", 1, 1, 0, cmd_apdu}, {"atr", 0, 0, 0, retrieve_atr}, {"bfsearch", 1, 18, 1, cmd_bfsearch}, + {"bfsearch-full", 0, 0, 1, cmd_bfsearch_full}, {"cd", 1, 1, 0, cmd_cd}, {"change-chv1", 2, 2, 0, cmd_change_chv}, {"change-chv2", 2, 2, 0, cmd_change_chv},