1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #define MIN(a,b) ((a) < (b) ? (a) : (b))
20 #define MAX(a,b) ((a) > (b) ? (a) : (b))
21
22
23 typedef struct bufrange {
24 uint32_t *p;
25 int off;
26 int len;
27 struct bufrange* next;
28 } BufRange;
29
30 #define OS_DRYOS 0
31 #define OS_VXWORKS 1
32
33
34 typedef struct {
35 uint32_t *buf;
36 BufRange *br, *last;
37
38 int os_type;
39
40 uint32_t base;
41 int main_offs;
42 uint32_t memisostart;
43 int size;
44 int fsize;
45 int cam_idx;
46 uint32_t pid_adr;
47 int dryos_ver;
48 int real_dryos_ver;
49 char *dryos_ver_str;
50 char *firmware_ver_str;
51 char *fw_build_date;
52 char *fw_build_time;
53 int fwver_idx;
54 int pid;
55 uint32_t maxram;
56 char *cam;
57 char *ksys;
58 int ksys_idx;
59 uint32_t dancing_bits;
60 int dancing_bits_idx;
61 uint32_t data_start;
62 uint32_t data_init_start;
63 int data_len;
64 uint32_t uncached_adr;
65 int uncached_adr_idx;
66
67
68 uint32_t *buf2;
69 uint32_t base2;
70 uint32_t base_copied;
71 int size2;
72 int lowest_idx;
73
74
75 uint32_t alt_base;
76
77
78 stub_values *sv;
79 } firmware;
80
81
82 void load_firmware(firmware *fw, const char *filename, const char *base_addr, const char *alt_base_addr, int os_type);
83
84
85
86
87 int idx_valid(firmware *fw, int i);
88
89
90 uint32_t idx2adr(firmware *fw, int idx);
91 int adr2idx(firmware *fw, uint32_t adr);
92 char* adr2ptr(firmware *fw, uint32_t adr);
93
94
95 int idxcorr(firmware *fw, int idx);
96
97 void set_ignore_errors(int n);
98 uint32_t* fwadr(firmware *fw, int i);
99
100 uint32_t fwval(firmware *fw, int i);
101
102 int fwRd(firmware *fw, int i);
103 int fwRn(firmware *fw, int i);
104 int fwRnMOV(firmware *fw, int i);
105 int fwOp2(firmware *fw, int i);
106
107
108 int idxFollowBranch(firmware *fw, int fidx, int offset);
109 uint32_t followBranch(firmware *fw, uint32_t fadr, int offset);
110 uint32_t followBranch2(firmware *fw, uint32_t fadr, int offset);
111
112
113 uint32_t LDR2adr(firmware *fw, int offset);
114 uint32_t LDR2idx(firmware *fw, int offset);
115 uint32_t LDR2val(firmware *fw, int offset);
116 uint32_t ADR2adr(firmware *fw, int offset);
117 uint32_t ALUop2(firmware *fw, int offset);
118 uint32_t ALUop2a(firmware *fw, int offset);
119
120
121 int isLDR_PC(firmware *fw, int offset);
122 int isLDR_SP(firmware *fw, int offset);
123 int isLDR_PC_cond(firmware *fw, int offset);
124 int isADR_PC(firmware *fw, int offset);
125 int isADR_PC_cond(firmware *fw, int offset);
126 int isLDMFD(firmware *fw, int offset);
127 int isLDMFD_PC(firmware *fw, int offset);
128 int isLDR(firmware *fw, int offset);
129 int isLDR_cond(firmware *fw, int offset);
130 int isADR(firmware *fw, int offset);
131 int isSTMFD(firmware *fw, int offset);
132 int isSTMFD_LR(firmware *fw, int offset);
133 int isSTR(firmware *fw, int offset);
134 int isSTR_cond(firmware *fw, int offset);
135 int isBX(firmware *fw, int offset);
136 int isBX_LR(firmware *fw, int offset);
137 int isBLX(firmware *fw, int offset);
138 int isBL(firmware *fw, int offset);
139 int isBL_cond(firmware *fw, int offset);
140 int isBLEQ(firmware *fw, int offset);
141 int isB(firmware *fw, int offset);
142 int isBorBL(firmware *fw, int offset);
143 int isCMP(firmware *fw, int offset);
144 int isMOV(firmware *fw, int offset);
145 int isMOV_immed(firmware *fw, int offset);
146 int isORR(firmware *fw, int offset);
147 int isADD(firmware *fw, int offset);
148 int isSUB(firmware *fw, int offset);
149
150 int isASCIIstring(firmware *fw, uint32_t adr);
151
152
153 int find_str(firmware *fw, char *str);
154 int find_Nth_str(firmware *fw, char *str, int N);
155
156 int find_inst(firmware *fw, int (*inst)(firmware*,int), int idx, int len);
157
158 int find_inst_rev(firmware *fw, int (*inst)(firmware*,int), int idx, int len);
159
160 int find_Nth_inst(firmware *fw, int (*inst)(firmware*,int), int idx, int len, int N);
161
162 int find_Nth_inst_rev(firmware *fw, int (*inst)(firmware*,int), int idx, int len, int N);
163
164
165 int find_strptr_ref(firmware *fw, char *str);
166 int find_str_ref(firmware *fw, char *str);
167 int find_nxt_str_ref(firmware *fw, int str_adr, int ofst);
168 int find_nxt_str_ref_alt(firmware *fw, char *str, int ofst, int limit);
169
170
171 int find_BL(firmware *fw, int k, uint32_t v1, uint32_t v2);
172 int find_B(firmware *fw, int k, uint32_t v1, uint32_t v2);
173
174
175 int search_fw(firmware *fw, int (*func)(firmware*, int, uint32_t, uint32_t), uint32_t v1, uint32_t v2, int len);
176 int search_fw_bytes(firmware *fw, int (*func)(firmware*, int));