FreeCalypso > hg > fc-pcsc-tools
comparison simtool/bfsearch.c @ 145:c2889812788e
fc-simtool bfsearch implemented
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 25 Feb 2021 06:03:13 +0000 |
| parents | |
| children | 8d55571c8118 |
comparison
equal
deleted
inserted
replaced
| 144:60411fd4b803 | 145:c2889812788e |
|---|---|
| 1 /* | |
| 2 * This module implements a brute force search of file ID space at a given | |
| 3 * file system directory level. | |
| 4 */ | |
| 5 | |
| 6 #include <sys/types.h> | |
| 7 #include <ctype.h> | |
| 8 #include <stdio.h> | |
| 9 #include <stdlib.h> | |
| 10 #include "simresp.h" | |
| 11 | |
| 12 static | |
| 13 parse_skip_ids(argv, array, total) | |
| 14 char **argv; | |
| 15 unsigned *array, total; | |
| 16 { | |
| 17 unsigned n; | |
| 18 | |
| 19 for (n = 0; n < total; n++) { | |
| 20 if (!isxdigit(argv[n][0]) || !isxdigit(argv[n][1]) || | |
| 21 !isxdigit(argv[n][2]) || !isxdigit(argv[n][3]) || | |
| 22 argv[n][4]) { | |
| 23 fprintf(stderr, "error: argument is not 4-digit hex\n"); | |
| 24 return(-1); | |
| 25 } | |
| 26 array[n] = strtoul(argv[n], 0, 16); | |
| 27 } | |
| 28 return(0); | |
| 29 } | |
| 30 | |
| 31 cmd_bfsearch(argc, argv, outf) | |
| 32 char **argv; | |
| 33 FILE *outf; | |
| 34 { | |
| 35 unsigned skip_ids[8], num_skip_ids; | |
| 36 unsigned bfs, n; | |
| 37 int rc; | |
| 38 | |
| 39 num_skip_ids = argc - 1; | |
| 40 rc = parse_skip_ids(argv + 1, skip_ids, num_skip_ids); | |
| 41 if (rc < 0) | |
| 42 return(rc); | |
| 43 rc = elem_select_op(skip_ids[0]); | |
| 44 if (rc < 0) | |
| 45 return(rc); | |
| 46 if (!rc) { | |
| 47 fprintf(stderr, "error: starting file ID 0x%04X not found\n", | |
| 48 skip_ids[0]); | |
| 49 return(-1); | |
| 50 } | |
| 51 for (bfs = 0; bfs <= 0xFFFF; bfs++) { | |
| 52 for (n = 0; n < num_skip_ids; n++) { | |
| 53 if (bfs == skip_ids[n]) | |
| 54 break; | |
| 55 } | |
| 56 if (n < num_skip_ids) | |
| 57 continue; | |
| 58 rc = elem_select_op(bfs); | |
| 59 if (rc < 0) | |
| 60 return(rc); | |
| 61 if (!rc) | |
| 62 continue; | |
| 63 rc = get_response_op(); | |
| 64 if (rc < 0) | |
| 65 return(rc); | |
| 66 if (sim_resp_data_len < 14) | |
| 67 printf("%04X: too-short response struct\n", bfs); | |
| 68 else { | |
| 69 switch (sim_resp_data[6]) { | |
| 70 case 0x01: | |
| 71 printf("%04X: MF\n", bfs); | |
| 72 break; | |
| 73 case 0x02: | |
| 74 printf("%04X: DF\n", bfs); | |
| 75 break; | |
| 76 case 0x04: | |
| 77 printf("%04X: EF (struct %02X)\n", bfs, | |
| 78 sim_resp_data[13]); | |
| 79 break; | |
| 80 default: | |
| 81 printf("%04X: unknown file type %02X\n", bfs, | |
| 82 sim_resp_data[6]); | |
| 83 } | |
| 84 } | |
| 85 rc = elem_select_op(skip_ids[0]); | |
| 86 if (rc < 0) | |
| 87 return(rc); | |
| 88 if (!rc) { | |
| 89 fprintf(stderr, | |
| 90 "reselecting starting file ID 0x%04X not-found error\n", | |
| 91 skip_ids[0]); | |
| 92 return(-1); | |
| 93 } | |
| 94 } | |
| 95 return(0); | |
| 96 } |
