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