]>
Commit | Line | Data |
---|---|---|
90836933 | 1 | #include <stdio.h> |
14ff7444 MG |
2 | #include <stdlib.h> |
3 | #include <strings.h> | |
4 | #include <string.h> | |
e433bc03 | 5 | #include <unistd.h> |
14ff7444 | 6 | #include <errno.h> |
af1fed3a | 7 | #include "rsb-crc.h" |
90836933 | 8 | #include "rsb-lz.h" |
e8563c43 | 9 | #include "filesystem.h" |
90836933 | 10 | |
650ebf3b MG |
11 | /* TODO: IMPLEMET THIS! */ |
12 | /* Probably very broken lzw implementation by Agilent: | |
13 | * | |
5d56af72 MG |
14 | * 59508: e3a00078 mov r0, #120 ; 0x78 |
15 | * 5950c: ee010f10 mcr 15, 0, r0, cr1, cr0, {0} | |
16 | * 59510: e3a00000 mov r0, #0 ; 0x0 | |
17 | * 59514: ee070f15 mcr 15, 0, r0, cr7, cr5, {0} | |
18 | * 59518: ee070f16 mcr 15, 0, r0, cr7, cr6, {0} | |
19 | * 5951c: ee020f30 mcr 15, 0, r0, cr2, cr0, {1} | |
20 | * 59520: ee020f10 mcr 15, 0, r0, cr2, cr0, {0} | |
21 | * 59524: ee030f10 mcr 15, 0, r0, cr3, cr0, {0} | |
22 | * 59528: ee050f70 mcr 15, 0, r0, cr5, cr0, {3} | |
23 | * 5952c: ee050f50 mcr 15, 0, r0, cr5, cr0, {2} | |
24 | * 59530: ee050f30 mcr 15, 0, r0, cr5, cr0, {1} | |
25 | * 59534: ee050f10 mcr 15, 0, r0, cr5, cr0, {0} | |
26 | * 59538: e3a00016 mov r0, #22 ; 0x16 | |
27 | * 5953c: ee060f10 mcr 15, 0, r0, cr6, cr0, {0} | |
28 | * 59540: ee060f11 mcr 15, 0, r0, cr6, cr1, {0} | |
29 | * 59544: ee060f12 mcr 15, 0, r0, cr6, cr2, {0} | |
30 | * 59548: ee060f13 mcr 15, 0, r0, cr6, cr3, {0} | |
31 | * 5954c: ee060f14 mcr 15, 0, r0, cr6, cr4, {0} | |
32 | * 59550: ee060f15 mcr 15, 0, r0, cr6, cr5, {0} | |
33 | * 59554: ee060f16 mcr 15, 0, r0, cr6, cr6, {0} | |
34 | * 59558: ee060f17 mcr 15, 0, r0, cr6, cr7, {0} | |
35 | * 5955c: e1a0f00e mov r15, r14 | |
36 | * 59560: e3a01000 mov r1, #0 ; 0x0 | |
37 | * 59564: ee071f15 mcr 15, 0, r1, cr7, cr5, {0} | |
38 | * 59568: ee071f16 mcr 15, 0, r1, cr7, cr6, {0} | |
39 | * 5956c: e3800078 orr r0, r0, #120 ; 0x78 | |
40 | * 59570: ee010f10 mcr 15, 0, r0, cr1, cr0, {0} | |
41 | * 59574: e1a0f00e mov r15, r14 | |
42 | * 59578: e92d00f0 push {r4, r5, r6, r7} | |
43 | * 5957c: e3500007 cmp r0, #7 ; 0x7 | |
44 | * 59580: 8a00003c bhi 0x59678 | |
45 | * 59584: e3e04ef0 mvn r4, #3840 ; 0xf00 | |
46 | * 59588: e22440ff eor r4, r4, #255 ; 0xff | |
47 | * 5958c: e1d14004 bics r4, r1, r4 | |
48 | * 59590: 1a000038 bne 0x59678 | |
49 | * 59594: e3a0403f mov r4, #63 ; 0x3f | |
50 | * 59598: e1d24004 bics r4, r2, r4 | |
51 | * 5959c: 1a000035 bne 0x59678 | |
52 | * 595a0: e3a06001 mov r6, #1 ; 0x1 | |
53 | * 595a4: e1a04423 lsr r4, r3, #8 | |
54 | * 595a8: e2044001 and r4, r4, #1 ; 0x1 | |
55 | * 595ac: ee125f30 mrc 15, 0, r5, cr2, cr0, {1} | |
56 | * 595b0: e1c55016 bic r5, r5, r6, lsl r0 | |
57 | * 595b4: e1855014 orr r5, r5, r4, lsl r0 | |
58 | * 595b8: ee025f30 mcr 15, 0, r5, cr2, cr0, {1} | |
59 | * 595bc: e1a044a3 lsr r4, r3, #9 | |
60 | * 595c0: e2044001 and r4, r4, #1 ; 0x1 | |
61 | * 595c4: ee125f10 mrc 15, 0, r5, cr2, cr0, {0} | |
62 | * 595c8: e1c55016 bic r5, r5, r6, lsl r0 | |
63 | * 595cc: e1855014 orr r5, r5, r4, lsl r0 | |
64 | * 595d0: ee025f10 mcr 15, 0, r5, cr2, cr0, {0} | |
65 | * 595d4: e1a04523 lsr r4, r3, #10 | |
66 | * 595d8: e2044001 and r4, r4, #1 ; 0x1 | |
67 | * 595dc: ee135f10 mrc 15, 0, r5, cr3, cr0, {0} | |
68 | * 595e0: e1c55016 bic r5, r5, r6, lsl r0 | |
69 | * 595e4: e1855014 orr r5, r5, r4, lsl r0 | |
70 | * 595e8: ee035f10 mcr 15, 0, r5, cr3, cr0, {0} | |
71 | * 595ec: e3a0600f mov r6, #15 ; 0xf | |
72 | * 595f0: e3a07004 mov r7, #4 ; 0x4 | |
73 | * 595f4: e0070790 mul r7, r0, r7 | |
74 | * 595f8: e0034006 and r4, r3, r6 | |
75 | * 595fc: ee155f70 mrc 15, 0, r5, cr5, cr0, {3} | |
76 | * 59600: e1c55716 bic r5, r5, r6, lsl r7 | |
77 | * 59604: e1855714 orr r5, r5, r4, lsl r7 | |
78 | * 59608: ee055f70 mcr 15, 0, r5, cr5, cr0, {3} | |
79 | * 5960c: e1a04223 lsr r4, r3, #4 | |
80 | * 59610: e0044006 and r4, r4, r6 | |
81 | * 59614: ee155f50 mrc 15, 0, r5, cr5, cr0, {2} | |
82 | * 59618: e1c55716 bic r5, r5, r6, lsl r7 | |
83 | * 5961c: e1855714 orr r5, r5, r4, lsl r7 | |
84 | * 59620: ee055f50 mcr 15, 0, r5, cr5, cr0, {2} | |
85 | * 59624: e1814002 orr r4, r1, r2 | |
86 | * 59628: e08ff180 add r15, r15, r0, lsl #3 | |
87 | * 5962c: e1a00000 nop (mov r0,r0) | |
88 | * 59630: ee064f10 mcr 15, 0, r4, cr6, cr0, {0} | |
89 | * 59634: ea00000c b 0x5966c | |
90 | * 59638: ee064f11 mcr 15, 0, r4, cr6, cr1, {0} | |
91 | * 5963c: ea00000a b 0x5966c | |
92 | * 59640: ee064f12 mcr 15, 0, r4, cr6, cr2, {0} | |
93 | * 59644: ea000008 b 0x5966c | |
94 | * 59648: ee064f13 mcr 15, 0, r4, cr6, cr3, {0} | |
95 | * 5964c: ea000006 b 0x5966c | |
96 | * 59650: ee064f14 mcr 15, 0, r4, cr6, cr4, {0} | |
97 | * 59654: ea000004 b 0x5966c | |
98 | * 59658: ee064f15 mcr 15, 0, r4, cr6, cr5, {0} | |
99 | * 5965c: ea000002 b 0x5966c | |
100 | * 59660: ee064f16 mcr 15, 0, r4, cr6, cr6, {0} | |
101 | * 59664: ea000000 b 0x5966c | |
102 | * 59668: ee064f17 mcr 15, 0, r4, cr6, cr7, {0} | |
103 | * 5966c: e3a00000 mov r0, #0 ; 0x0 | |
104 | * 59670: e8bd00f0 pop {r4, r5, r6, r7} | |
105 | * 59674: e1a0f00e mov r15, r14 | |
106 | * 59678: e3e00000 mvn r0, #0 ; 0x0 | |
107 | * 5967c: e8bd00f0 pop {r4, r5, r6, r7} | |
108 | * 59680: e1a0f00e mov r15, r14 | |
0fcfb8f3 MG |
109 | * 59684: e92d43f8 push {r3, r4, r5, r6, r7, r8, r9, r14} |
110 | * 59688: eb000000 bl 0x59690 | |
111 | * 5968c: e8bd83f8 pop {r3, r4, r5, r6, r7, r8, r9, r15} | |
112 | * 59690: e3a08001 mov r8, #1 ; 0x1 | |
113 | * 59694: e3a034c0 mov r3, #-1073741824 ; 0xc0000000 | |
114 | * 59698: e1500003 cmp r0, r3 | |
115 | * 5969c: da000022 ble 0x5972c | |
116 | * 596a0: e3a03020 mov r3, #32 ; 0x20 | |
117 | * 596a4: e7b34000 ldr r4, [r3, r0]! | |
118 | * 596a8: e3a08002 mov r8, #2 ; 0x2 | |
119 | * 596ac: e5935004 ldr r5, [r3, #4] | |
120 | * 596b0: e1550002 cmp r5, r2 | |
121 | * 596b4: 1a00001c bne 0x5972c | |
122 | * 596b8: e3a08003 mov r8, #3 ; 0x3 | |
123 | * 596bc: e1510004 cmp r1, r4 | |
124 | * 596c0: 23b05000 movscs r5, #0 ; 0x0 | |
125 | * 596c4: 33b05001 movscc r5, #1 ; 0x1 | |
126 | * 596c8: 1a000017 bne 0x5972c | |
127 | * 596cc: e3a08004 mov r8, #4 ; 0x4 | |
128 | * 596d0: e1a03000 mov r3, r0 | |
129 | * 596d4: e0804004 add r4, r0, r4 | |
130 | * 596d8: e3e05000 mvn r5, #0 ; 0x0 | |
131 | * 596dc: e59f7050 ldr r7, [pc, #80] ; 0x59734 | |
132 | * 596e0: e1530004 cmp r3, r4 | |
133 | * 596e4: 2a00000c bcs 0x5971c | |
134 | * 596e8: e3c39003 bic r9, r3, #3 ; 0x3 | |
135 | * 596ec: e5996000 ldr r6, [r9] | |
136 | * 596f0: e2039003 and r9, r3, #3 ; 0x3 | |
137 | * 596f4: e1a09189 lsl r9, r9, #3 | |
138 | * 596f8: e1a06936 lsr r6, r6, r9 | |
139 | * 596fc: e0255c06 eor r5, r5, r6, lsl #24 | |
140 | * 59700: e3a06008 mov r6, #8 ; 0x8 | |
141 | * 59704: e1b05085 lsls r5, r5, #1 | |
142 | * 59708: 20255007 eorcs r5, r5, r7 | |
143 | * 5970c: e2566001 subs r6, r6, #1 ; 0x1 | |
144 | * 59710: 1afffffb bne 0x59704 | |
145 | * 59714: e2833001 add r3, r3, #1 ; 0x1 | |
146 | * 59718: eafffff0 b 0x596e0 | |
147 | * 5971c: e1e05005 mvn r5, r5 | |
148 | * 59720: e5943000 ldr r3, [r4] | |
149 | * 59724: e0533005 subs r3, r3, r5 | |
150 | * 59728: 03a08000 moveq r8, #0 ; 0x0 | |
151 | * 5972c: e1a00008 mov r0, r8 | |
152 | * 59730: e1a0f00e mov r15, r14 | |
153 | * 59734: 04c11db7 strbeq r1, [r1], #3511 | |
154 | * 59738: e10f1000 mrs r1, CPSR | |
155 | * 5973c: e3c12080 bic r2, r1, #128 ; 0x80 | |
156 | * 59740: e3500001 cmp r0, #1 ; 0x1 | |
157 | * 59744: 23822080 orrcs r2, r2, #128 ; 0x80 | |
158 | * 59748: e129f002 msr CPSR_fc, r2 | |
159 | * 5974c: e1b01c81 lsls r1, r1, #25 | |
160 | * 59750: e3a00000 mov r0, #0 ; 0x0 | |
161 | * 59754: 23a00001 movcs r0, #1 ; 0x1 | |
162 | * 59758: e1a0f00e mov r15, r14 | |
163 | * 5975c: e10f1000 mrs r1, CPSR | |
164 | * 59760: e3a02001 mov r2, #1 ; 0x1 | |
165 | * 59764: e00203e1 and r0, r2, r1, ror #7 | |
166 | * 59768: e1a0f00e mov r15, r14 | |
167 | * 5976c: ee151f70 mrc 15, 0, r1, cr5, cr0, {3} | |
168 | * 59770: e3a02001 mov r2, #1 ; 0x1 | |
169 | * 59774: e0020261 and r0, r2, r1, ror #4 | |
170 | * 59778: e1a0f00e mov r15, r14 | |
171 | * 5977c: e3a00000 mov r0, #0 ; 0x0 | |
172 | * 59780: ee070f16 mcr 15, 0, r0, cr7, cr6, {0} | |
173 | * 59784: e1a0f00e mov r15, r14 | |
174 | * 59788: e92d0300 push {r8, r9} | |
175 | * 5978c: e3a00001 mov r0, #1 ; 0x1 | |
176 | * 59790: e59f83bc ldr r8, [pc, #956] ; 0x59b54 | |
177 | * 59794: e5880000 str r0, [r8] | |
178 | * 59798: e3a0000a mov r0, #10 ; 0xa | |
179 | * 5979c: e59f83b4 ldr r8, [pc, #948] ; 0x59b58 | |
180 | * 597a0: e5880000 str r0, [r8] | |
181 | * 597a4: e3a00004 mov r0, #4 ; 0x4 | |
182 | * 597a8: e59f83ac ldr r8, [pc, #940] ; 0x59b5c | |
183 | * 597ac: e5880000 str r0, [r8] | |
184 | * 597b0: e59f93a8 ldr r9, [pc, #936] ; 0x59b60 | |
185 | * 597b4: e5990000 ldr r0, [r9] | |
186 | * 597b8: e3800001 orr r0, r0, #1 ; 0x1 | |
187 | * 597bc: e59f839c ldr r8, [pc, #924] ; 0x59b60 | |
188 | * 597c0: e5880000 str r0, [r8] | |
189 | * 597c4: eafffffe b 0x597c4 | |
190 | * 597c8: e92d4370 push {r4, r5, r6, r8, r9, r14} | |
191 | * 597cc: e1a06000 mov r6, r0 | |
192 | * 597d0: e3a05000 mov r5, #0 ; 0x0 | |
193 | * 597d4: e5960000 ldr r0, [r6] | |
194 | * 597d8: e5961004 ldr r1, [r6, #4] | |
195 | * 597dc: e1500001 cmp r0, r1 | |
196 | * 597e0: 2a000006 bcs 0x59800 | |
197 | * 597e4: e5960000 ldr r0, [r6] | |
198 | * 597e8: e5d05000 ldrb r5, [r0] | |
199 | * 597ec: e5960000 ldr r0, [r6] | |
200 | * 597f0: e2800001 add r0, r0, #1 ; 0x1 | |
201 | * 597f4: e5860000 str r0, [r6] | |
202 | * 597f8: e1a00005 mov r0, r5 | |
203 | * 597fc: ea000001 b 0x59808 | |
204 | * 59800: ebffffe0 bl 0x59788 | |
205 | * 59804: e1a00005 mov r0, r5 | |
206 | * 59808: e8bd8370 pop {r4, r5, r6, r8, r9, r15} | |
207 | * 5980c: e92d43f0 push {r4, r5, r6, r7, r8, r9, r14} | |
208 | * 59810: e1a07000 mov r7, r0 | |
209 | * 59814: e1a06001 mov r6, r1 | |
210 | * 59818: e5961000 ldr r1, [r6] | |
211 | * 5981c: e5962004 ldr r2, [r6, #4] | |
212 | * 59820: e1510002 cmp r1, r2 | |
213 | * 59824: 2a000005 bcs 0x59840 | |
214 | * 59828: e5961000 ldr r1, [r6] | |
215 | * 5982c: e5c17000 strb r7, [r1] | |
216 | * 59830: e5961000 ldr r1, [r6] | |
217 | * 59834: e2811001 add r1, r1, #1 ; 0x1 | |
218 | * 59838: e5861000 str r1, [r6] | |
219 | * 5983c: ea000000 b 0x59844 | |
220 | * 59840: ebffffd0 bl 0x59788 | |
221 | * 59844: e8bd83f0 pop {r4, r5, r6, r7, r8, r9, r15} | |
222 | * 59848: e92d4370 push {r4, r5, r6, r8, r9, r14} | |
223 | * 5984c: e1a06000 mov r6, r0 | |
224 | * 59850: e5d61008 ldrb r1, [r6, #8] | |
225 | * 59854: e3510080 cmp r1, #128 ; 0x80 | |
226 | * 59858: 1a000002 bne 0x59868 | |
227 | * 5985c: e1a00006 mov r0, r6 | |
228 | * 59860: ebffffd8 bl 0x597c8 | |
229 | * 59864: e5c60009 strb r0, [r6, #9] | |
230 | * 59868: e5d61008 ldrb r1, [r6, #8] | |
231 | * 5986c: e5d62009 ldrb r2, [r6, #9] | |
232 | * 59870: e0011002 and r1, r1, r2 | |
233 | * 59874: e20110ff and r1, r1, #255 ; 0xff | |
234 | * 59878: e1a05001 mov r5, r1 | |
235 | * 5987c: e5d61008 ldrb r1, [r6, #8] | |
236 | * 59880: e1a010a1 lsr r1, r1, #1 | |
237 | * 59884: e5c61008 strb r1, [r6, #8] | |
238 | * 59888: e5d61008 ldrb r1, [r6, #8] | |
239 | * 5988c: e3510000 cmp r1, #0 ; 0x0 | |
240 | * 59890: 1a000001 bne 0x5989c | |
241 | * 59894: e3a01080 mov r1, #128 ; 0x80 | |
242 | * 59898: e5c61008 strb r1, [r6, #8] | |
243 | * 5989c: e3550000 cmp r5, #0 ; 0x0 | |
244 | * 598a0: 0a000001 beq 0x598ac | |
245 | * 598a4: e3a00001 mov r0, #1 ; 0x1 | |
246 | * 598a8: ea000000 b 0x598b0 | |
247 | * 598ac: e3a00000 mov r0, #0 ; 0x0 | |
248 | * 598b0: e8bd8370 pop {r4, r5, r6, r8, r9, r15} | |
249 | * 598b4: e92d4ff0 push {r4, r5, r6, r7, r8, r9, r10, r11, r14} | |
250 | * 598b8: e1a0b000 mov r11, r0 | |
251 | * 598bc: e1a0a001 mov r10, r1 | |
252 | * 598c0: e24a1001 sub r1, r10, #1 ; 0x1 | |
253 | * 598c4: e3a02001 mov r2, #1 ; 0x1 | |
254 | * 598c8: e1a06112 lsl r6, r2, r1 | |
255 | * 598cc: e3a07000 mov r7, #0 ; 0x0 | |
256 | * 598d0: ea000015 b 0x5992c | |
257 | * 598d4: e5db1008 ldrb r1, [r11, #8] | |
258 | * 598d8: e3510080 cmp r1, #128 ; 0x80 | |
259 | * 598dc: 1a000003 bne 0x598f0 | |
260 | * 598e0: e1a0000b mov r0, r11 | |
261 | * 598e4: ebffffb7 bl 0x597c8 | |
262 | * 598e8: e1a01000 mov r1, r0 | |
263 | * 598ec: e5cb1009 strb r1, [r11, #9] | |
264 | * 598f0: e5db1008 ldrb r1, [r11, #8] | |
265 | * 598f4: e5db2009 ldrb r2, [r11, #9] | |
266 | * 598f8: e0011002 and r1, r1, r2 | |
267 | * 598fc: e3510000 cmp r1, #0 ; 0x0 | |
268 | * 59900: 0a000000 beq 0x59908 | |
269 | * 59904: e1877006 orr r7, r7, r6 | |
270 | * 59908: e1a060a6 lsr r6, r6, #1 | |
271 | * 5990c: e5db2008 ldrb r2, [r11, #8] | |
272 | * 59910: e1a020a2 lsr r2, r2, #1 | |
273 | * 59914: e5cb2008 strb r2, [r11, #8] | |
274 | * 59918: e5db1008 ldrb r1, [r11, #8] | |
275 | * 5991c: e3510000 cmp r1, #0 ; 0x0 | |
276 | * 59920: 1a000001 bne 0x5992c | |
277 | * 59924: e3a01080 mov r1, #128 ; 0x80 | |
278 | * 59928: e5cb1008 strb r1, [r11, #8] | |
279 | * 5992c: e3560000 cmp r6, #0 ; 0x0 | |
280 | * 59930: 1affffe7 bne 0x598d4 | |
281 | * 59934: e1a00007 mov r0, r7 | |
282 | * 59938: e8bd8ff0 pop {r4, r5, r6, r7, r8, r9, r10, r11, r15} | |
283 | * 5993c: e92d4ff0 push {r4, r5, r6, r7, r8, r9, r10, r11, r14} | |
284 | * 59940: e24dd004 sub r13, r13, #4 ; 0x4 | |
285 | * 59944: e1a0a000 mov r10, r0 | |
286 | * 59948: e58d1000 str r1, [r13] | |
287 | * 5994c: e3a05001 mov r5, #1 ; 0x1 | |
288 | * 59950: e1a0000a mov r0, r10 | |
289 | * 59954: ebffffbb bl 0x59848 | |
290 | * 59958: e1a02000 mov r2, r0 | |
291 | * 5995c: e3520000 cmp r2, #0 ; 0x0 | |
292 | * 59960: 0a00000f beq 0x599a4 | |
293 | * 59964: e1a0000a mov r0, r10 | |
294 | * 59968: e3a01008 mov r1, #8 ; 0x8 | |
295 | * 5996c: ebffffd0 bl 0x598b4 | |
296 | * 59970: e20020ff and r2, r0, #255 ; 0xff | |
297 | * 59974: e1a04002 mov r4, r2 | |
298 | * 59978: e59d1000 ldr r1, [r13] | |
299 | * 5997c: e1a00004 mov r0, r4 | |
300 | * 59980: ebffffa1 bl 0x5980c | |
301 | * 59984: e59f21d8 ldr r2, [pc, #472] ; 0x59b64 | |
302 | * 59988: e0852002 add r2, r5, r2 | |
303 | * 5998c: e5c24000 strb r4, [r2] | |
304 | * 59990: e2852001 add r2, r5, #1 ; 0x1 | |
305 | * 59994: e1a02b02 lsl r2, r2, #22 | |
306 | * 59998: e1a02b22 lsr r2, r2, #22 | |
307 | * 5999c: e1a05002 mov r5, r2 | |
308 | * 599a0: eaffffea b 0x59950 | |
309 | * 599a4: e1a0000a mov r0, r10 | |
310 | * 599a8: e3a0100a mov r1, #10 ; 0xa | |
311 | * 599ac: ebffffc0 bl 0x598b4 | |
312 | * 599b0: e1a02000 mov r2, r0 | |
313 | * 599b4: e1a0b002 mov r11, r2 | |
314 | * 599b8: e35b0000 cmp r11, #0 ; 0x0 | |
315 | * 599bc: 0a00001b beq 0x59a30 | |
316 | * 599c0: e1a0000a mov r0, r10 | |
317 | * 599c4: e3a01004 mov r1, #4 ; 0x4 | |
318 | * 599c8: ebffffb9 bl 0x598b4 | |
319 | * 599cc: e1a02000 mov r2, r0 | |
320 | * 599d0: e1a07002 mov r7, r2 | |
321 | * 599d4: e2877001 add r7, r7, #1 ; 0x1 | |
322 | * 599d8: e3a06000 mov r6, #0 ; 0x0 | |
323 | * 599dc: ea000010 b 0x59a24 | |
324 | * 599e0: e086200b add r2, r6, r11 | |
325 | * 599e4: e1a02b02 lsl r2, r2, #22 | |
326 | * 599e8: e1a02b22 lsr r2, r2, #22 | |
327 | * 599ec: e59f3170 ldr r3, [pc, #368] ; 0x59b64 | |
328 | * 599f0: e0822003 add r2, r2, r3 | |
329 | * 599f4: e5d24000 ldrb r4, [r2] | |
330 | * 599f8: e59d1000 ldr r1, [r13] | |
331 | * 599fc: e1a00004 mov r0, r4 | |
332 | * 59a00: ebffff81 bl 0x5980c | |
333 | * 59a04: e59f2158 ldr r2, [pc, #344] ; 0x59b64 | |
334 | * 59a08: e0852002 add r2, r5, r2 | |
335 | * 59a0c: e5c24000 strb r4, [r2] | |
336 | * 59a10: e2852001 add r2, r5, #1 ; 0x1 | |
337 | * 59a14: e1a02b02 lsl r2, r2, #22 | |
338 | * 59a18: e1a02b22 lsr r2, r2, #22 | |
339 | * 59a1c: e1a05002 mov r5, r2 | |
340 | * 59a20: e2866001 add r6, r6, #1 ; 0x1 | |
341 | * 59a24: e1560007 cmp r6, r7 | |
342 | * 59a28: daffffec ble 0x599e0 | |
343 | * 59a2c: eaffffc7 b 0x59950 | |
344 | * 59a30: e28dd004 add r13, r13, #4 ; 0x4 | |
345 | * 59a34: e8bd8ff0 pop {r4, r5, r6, r7, r8, r9, r10, r11, r15} | |
650ebf3b MG |
346 | * 59a38: e92d4ff0 push {r4, r5, r6, r7, r8, r9, r10, r11, r14} |
347 | * 59a3c: e1a07000 mov r7, r0 | |
348 | * 59a40: e1a0a001 mov r10, r1 | |
349 | * 59a44: e1a0b002 mov r11, r2 | |
350 | * 59a48: ebfffeae bl 0x59508 | |
351 | * 59a4c: e3a03033 mov r3, #51 ; 0x33 | |
352 | * 59a50: e3a0203f mov r2, #63 ; 0x3f | |
353 | * 59a54: e3a01000 mov r1, #0 ; 0x0 | |
354 | * 59a58: e3a00000 mov r0, #0 ; 0x0 | |
355 | * 59a5c: ebfffec5 bl 0x59578 | |
356 | * 59a60: e59f3100 ldr r3, [pc, #256] ; 0x59b68 | |
357 | * 59a64: e3a02033 mov r2, #51 ; 0x33 | |
358 | * 59a68: e3a01540 mov r1, #268435456 ; 0x10000000 | |
359 | * 59a6c: e3a00004 mov r0, #4 ; 0x4 | |
360 | * 59a70: ebfffec0 bl 0x59578 | |
361 | * 59a74: e59f30f0 ldr r3, [pc, #240] ; 0x59b6c | |
362 | * 59a78: e3a0201b mov r2, #27 ; 0x1b | |
363 | * 59a7c: e3a01550 mov r1, #335544320 ; 0x14000000 | |
364 | * 59a80: e3a00005 mov r0, #5 ; 0x5 | |
365 | * 59a84: ebfffebb bl 0x59578 | |
366 | * 59a88: e3a03033 mov r3, #51 ; 0x33 | |
367 | * 59a8c: e3a0203b mov r2, #59 ; 0x3b | |
368 | * 59a90: e3a014c0 mov r1, #-1073741824 ; 0xc0000000 | |
369 | * 59a94: e3a00007 mov r0, #7 ; 0x7 | |
370 | * 59a98: ebfffeb6 bl 0x59578 | |
371 | * 59a9c: e59f00cc ldr r0, [pc, #204] ; 0x59b70 | |
372 | * 59aa0: ebfffeae bl 0x59560 | |
373 | * 59aa4: e59b5000 ldr r5, [r11] | |
374 | * 59aa8: e59f20c4 ldr r2, [pc, #196] ; 0x59b74 | |
375 | * 59aac: e1550002 cmp r5, r2 | |
376 | * 59ab0: 0a000000 beq 0x59ab8 | |
377 | * 59ab4: ebffff33 bl 0x59788 | |
378 | * 59ab8: e28b3004 add r3, r11, #4 ; 0x4 | |
379 | * 59abc: e5935000 ldr r5, [r3] | |
380 | * 59ac0: e0853007 add r3, r5, r7 | |
381 | * 59ac4: e153000a cmp r3, r10 | |
382 | * 59ac8: 3a000000 bcc 0x59ad0 | |
383 | * 59acc: ebffff2d bl 0x59788 | |
384 | * 59ad0: e28b2008 add r2, r11, #8 ; 0x8 | |
385 | * 59ad4: e59f809c ldr r8, [pc, #156] ; 0x59b78 | |
386 | * 59ad8: e5882000 str r2, [r8] | |
387 | * 59adc: e085200b add r2, r5, r11 | |
388 | * 59ae0: e59f8090 ldr r8, [pc, #144] ; 0x59b78 | |
389 | * 59ae4: e5882004 str r2, [r8, #4] | |
390 | * 59ae8: e3a02000 mov r2, #0 ; 0x0 | |
391 | * 59aec: e59f8084 ldr r8, [pc, #132] ; 0x59b78 | |
392 | * 59af0: e5c82009 strb r2, [r8, #9] | |
393 | * 59af4: e3a02080 mov r2, #128 ; 0x80 | |
394 | * 59af8: e59f8078 ldr r8, [pc, #120] ; 0x59b78 | |
395 | * 59afc: e5c82008 strb r2, [r8, #8] | |
396 | * 59b00: e59f8074 ldr r8, [pc, #116] ; 0x59b7c | |
397 | * 59b04: e5887000 str r7, [r8] | |
398 | * 59b08: e0853007 add r3, r5, r7 | |
399 | * 59b0c: e59f8068 ldr r8, [pc, #104] ; 0x59b7c | |
400 | * 59b10: e5883004 str r3, [r8, #4] | |
401 | * 59b14: e59f1060 ldr r1, [pc, #96] ; 0x59b7c | |
402 | * 59b18: e59f0058 ldr r0, [pc, #88] ; 0x59b78 | |
403 | * 59b1c: ebffff86 bl 0x5993c | |
404 | * 59b20: e2873020 add r3, r7, #32 ; 0x20 | |
405 | * 59b24: e5935000 ldr r5, [r3] | |
406 | * 59b28: e59f2050 ldr r2, [pc, #80] ; 0x59b80 | |
407 | * 59b2c: e1a01005 mov r1, r5 | |
408 | * 59b30: e1a00007 mov r0, r7 | |
409 | * 59b34: ebfffed2 bl 0x59684 | |
410 | * 59b38: e1a01000 mov r1, r0 | |
411 | * 59b3c: e1a04001 mov r4, r1 | |
412 | * 59b40: e3540000 cmp r4, #0 ; 0x0 | |
413 | * 59b44: 0a000000 beq 0x59b4c | |
414 | * 59b48: ebffff0e bl 0x59788 | |
415 | * 59b4c: ebfffe6d bl 0x59508 | |
416 | * 59b50: e8bd8ff0 pop {r4, r5, r6, r7, r8, r9, r10, r11, r15} | |
417 | * 59b54: c00b003c andgt r0, r11, r12, lsr r0 | |
418 | * 59b58: c00b0038 andgt r0, r11, r8, lsr r0 | |
419 | * 59b5c: c00b0034 andgt r0, r11, r4, lsr r0 | |
420 | * 59b60: c00b0030 andgt r0, r11, r0, lsr r0 | |
421 | * 59b64: 14000418 strne r0, [r0], #-1048 | |
422 | * 59b68: 00000366 andeq r0, r0, r6, ror #6 | |
423 | * 59b6c: 00000733 andeq r0, r0, r3, lsr r7 | |
424 | * 59b70: 00001005 andeq r1, r0, r5 | |
425 | * 59b74: 6110beef tstvs r0, r15, ror #29 <- LZW Header... | |
426 | * 59b78: 14000404 strne r0, [r0], #-1028 | |
427 | * 59b7c: 14000410 strne r0, [r0], #-1040 | |
428 | * 59b80: 46335053 undefined | |
429 | */ | |
90836933 | 430 | |
2363a0d6 | 431 | void err_exit(const char *fname) |
14ff7444 | 432 | { |
e4a6d4c3 | 433 | fprintf(stderr,"%s: error extracting...\n", fname); |
14ff7444 MG |
434 | exit(1); |
435 | } | |
436 | ||
7e4dc833 | 437 | struct data_in_s { |
5e9ad31f MG |
438 | unsigned char *start; /* 0 */ |
439 | unsigned char *stop; /* 4 */ | |
7e4dc833 | 440 | unsigned char bit; /* 8 */ |
14ff7444 MG |
441 | unsigned char x; /* 9 */ |
442 | }; | |
443 | ||
7e4dc833 MG |
444 | struct data_out_s { |
445 | unsigned char *pos; | |
446 | unsigned char *end; | |
447 | }; | |
448 | ||
449 | unsigned char fn_597c8(struct data_in_s *r6_data) | |
af1fed3a | 450 | { |
5e9ad31f MG |
451 | unsigned char *r0; |
452 | unsigned char *r1; | |
453 | unsigned char r5; | |
454 | ||
455 | r5 = 0; | |
456 | ||
457 | r0 = r6_data->start; | |
458 | r1 = r6_data->stop; | |
459 | ||
460 | if (r1 < r0) | |
2363a0d6 | 461 | err_exit(__func__); |
5e9ad31f MG |
462 | |
463 | r5 = *r0; | |
464 | r0++; | |
465 | r6_data->start = r0; | |
466 | ||
467 | return r5; | |
af1fed3a MG |
468 | } |
469 | ||
7e4dc833 | 470 | unsigned int fn_59848(struct data_in_s *r6_data) |
e4a6d4c3 | 471 | { |
90c723bb MG |
472 | unsigned char r1; |
473 | unsigned char r2; | |
e4a6d4c3 MG |
474 | unsigned int r5; |
475 | ||
7e4dc833 | 476 | r1 = r6_data->bit; |
e4a6d4c3 MG |
477 | if (r1 == 0x80) { |
478 | r6_data->x = fn_597c8(r6_data); | |
479 | } | |
7e4dc833 | 480 | r1 = r6_data->bit; |
e4a6d4c3 MG |
481 | r2 = r6_data->x; |
482 | r1 = r1 & r2; | |
483 | r5 = r1 & 0xff; | |
484 | ||
7e4dc833 | 485 | r1 = r6_data->bit; |
e4a6d4c3 | 486 | r1 = r1 >> 1; |
7e4dc833 | 487 | r6_data->bit = r1; |
90c723bb | 488 | if (r1 == 0) { |
e4a6d4c3 | 489 | r1 = 0x80; |
7e4dc833 | 490 | r6_data->bit = r1; |
90c723bb MG |
491 | } |
492 | ||
e4a6d4c3 MG |
493 | if (r5 == 0) |
494 | return 0; | |
495 | ||
496 | return 1; | |
497 | } | |
498 | ||
7e4dc833 | 499 | unsigned int fn_598b4(struct data_in_s *r11_data, unsigned int r10_arg2) |
3772880c MG |
500 | { |
501 | unsigned int r1; | |
502 | unsigned int r2; | |
503 | unsigned int r6; | |
504 | unsigned int r7; | |
505 | ||
3772880c MG |
506 | r1 = r10_arg2 - 1; |
507 | r6 = 1 << r1; | |
508 | ||
509 | r7 = 0; | |
90c723bb | 510 | while (r6 != 0) { |
7e4dc833 | 511 | r1 = r11_data->bit; |
3772880c MG |
512 | if (r1 == 0x80) { |
513 | r1 = fn_597c8(r11_data); | |
90c723bb | 514 | r11_data->x = r1; |
3772880c | 515 | } |
7e4dc833 | 516 | r1 = r11_data->bit; |
3772880c MG |
517 | r2 = r11_data->x; |
518 | r1 = r1 & r2; | |
519 | if (r1 != 0) | |
520 | r7 = r7 | r6; | |
521 | ||
522 | r6 = r6 >> 1; | |
523 | ||
7e4dc833 | 524 | r2 = r11_data->bit; |
3772880c | 525 | r2 = r2 >> 1; |
7e4dc833 | 526 | r11_data->bit = r2; |
3772880c | 527 | |
7e4dc833 | 528 | r1 = r11_data->bit; |
3772880c | 529 | if(r1 == 0) { |
7e4dc833 | 530 | r11_data->bit = 0x80; |
3772880c | 531 | } |
90c723bb | 532 | } |
3772880c MG |
533 | |
534 | return r7; | |
535 | } | |
536 | ||
7e4dc833 | 537 | void fn_5980c(unsigned int arg1, struct data_out_s *data_out) |
af1fed3a | 538 | { |
9897bfc3 MG |
539 | unsigned char *r1; |
540 | unsigned char *r2; | |
541 | ||
7e4dc833 MG |
542 | r1 = data_out->pos; |
543 | r2 = data_out->end; | |
9897bfc3 | 544 | |
e4a6d4c3 MG |
545 | if (r1 > r2) { |
546 | printf("r1: 0x%08x, r2: 0x%08x\n", (unsigned int)r1, (unsigned int)r2); | |
2363a0d6 | 547 | err_exit(__func__); |
e4a6d4c3 | 548 | } |
9897bfc3 MG |
549 | |
550 | *r1 = arg1 & 0xff; | |
551 | ||
552 | r1++; | |
7e4dc833 | 553 | data_out->pos = r1; |
af1fed3a MG |
554 | } |
555 | ||
7e4dc833 | 556 | void lz_expand(struct data_in_s *r10_data, struct data_out_s *data_out) |
af1fed3a MG |
557 | { |
558 | unsigned int r5; | |
559 | unsigned int r2; | |
90c723bb | 560 | unsigned char r4; |
05c92ac4 MG |
561 | unsigned int r6; |
562 | unsigned int r7; | |
563 | unsigned int r11; | |
90c723bb | 564 | unsigned char arr_59b64[2048]; |
af1fed3a MG |
565 | |
566 | r5 = 1; | |
567 | ||
90c723bb MG |
568 | while (1) { |
569 | while (1) { | |
570 | r2 = fn_59848(r10_data); | |
05c92ac4 MG |
571 | if (r2 == 0) |
572 | break; | |
af1fed3a | 573 | |
90c723bb | 574 | r2 = fn_598b4(r10_data, 8) & 0xff; |
05c92ac4 | 575 | r4 = r2; |
af1fed3a | 576 | |
7e4dc833 | 577 | fn_5980c(r4, data_out); |
05c92ac4 MG |
578 | arr_59b64[r5] = r4 & 0xff; |
579 | r2 = r5 + 1; | |
580 | r2 = r2 << 22; | |
581 | r2 = r2 >> 22; | |
582 | r5 = r2; | |
90c723bb | 583 | } |
af1fed3a | 584 | |
90c723bb | 585 | r11 = fn_598b4(r10_data, 0x0a); |
05c92ac4 MG |
586 | if(r11 == 0) |
587 | return; | |
af1fed3a | 588 | |
90c723bb | 589 | r2 = fn_598b4(r10_data, 0x04); |
05c92ac4 MG |
590 | r7 = r2 + 1; |
591 | r6 = 0; | |
90c723bb | 592 | while (r6 <= r7) { |
05c92ac4 MG |
593 | r2 = r6 + r11; |
594 | r2 = r2 << 22; | |
595 | r2 = r2 >> 22; | |
596 | r4 = arr_59b64[r2]; | |
7e4dc833 | 597 | fn_5980c(r4, data_out); |
90c723bb | 598 | arr_59b64[r5] = r4; |
05c92ac4 MG |
599 | r2 = r5 + 1; |
600 | r2 = r2 << 22; | |
601 | r2 = r2 >> 22; | |
602 | r5 = r2; | |
603 | r6++; | |
90c723bb MG |
604 | } |
605 | } | |
af1fed3a MG |
606 | } |
607 | ||
608 | unsigned int crc_check_59684(unsigned char *arg1, unsigned int arg2, unsigned int magic) | |
609 | { | |
610 | unsigned int r3; | |
611 | unsigned int r4; | |
612 | unsigned int r5; | |
613 | ||
614 | #if 0 | |
615 | if (r0 < 0xc0000000) | |
616 | return 1; | |
617 | #endif | |
618 | ||
e433bc03 | 619 | /* ??? */ |
af1fed3a MG |
620 | r4 = *((unsigned int*)arg1 + 0x20); |
621 | r5 = *((unsigned int*)arg1 + 0x24); | |
622 | ||
e433bc03 | 623 | printf("magic: 0x%08x <-> 0x%08x\n", r5, magic); |
af1fed3a MG |
624 | if (r5 != magic) |
625 | return 2; | |
626 | ||
627 | if (arg2 >= r4) | |
628 | r5 = 0; | |
629 | else | |
630 | return 3; | |
631 | ||
632 | r5 = ~rsb_crc(~0x00, arg1, r4); | |
633 | r3 = *((unsigned int*)(arg1 + r4)); | |
634 | printf("Checksums: 0x%02x <-> 0x%02x\n", r5, r3); | |
635 | ||
636 | if (r3 == r5) | |
637 | return 0; | |
638 | ||
05c92ac4 | 639 | return 4; |
af1fed3a MG |
640 | } |
641 | ||
2363a0d6 | 642 | void extract_lz_file(unsigned char *inbuf, unsigned char *name) |
14ff7444 | 643 | { |
2363a0d6 MG |
644 | unsigned int len; |
645 | unsigned char *outbuf; | |
7e4dc833 MG |
646 | struct data_in_s data_in; |
647 | struct data_out_s data_out; | |
14ff7444 | 648 | |
2363a0d6 MG |
649 | if (*((unsigned int*)inbuf) != LZ_MAGIC) |
650 | err_exit(__func__); | |
e4a6d4c3 | 651 | |
2363a0d6 MG |
652 | len = *((unsigned int*)(inbuf + 4)); |
653 | printf(", length: %d", len); | |
14ff7444 | 654 | |
2363a0d6 | 655 | if ((outbuf = malloc(len)) == NULL) { |
e433bc03 MG |
656 | perror("malloc"); |
657 | exit(1); | |
658 | } | |
e433bc03 | 659 | |
2363a0d6 MG |
660 | bzero(outbuf, len); |
661 | ||
662 | data_in.start = inbuf + 8; | |
663 | data_in.stop = inbuf + len; | |
7e4dc833 MG |
664 | data_in.x = 0; |
665 | data_in.bit = 0x80; | |
14ff7444 | 666 | |
2363a0d6 MG |
667 | data_out.pos = outbuf; |
668 | data_out.end = outbuf + len; | |
14ff7444 | 669 | |
7e4dc833 | 670 | lz_expand(&data_in, &data_out); |
14ff7444 | 671 | |
e433bc03 MG |
672 | #if 0 |
673 | /* This seems to still be completely broken */ | |
af1fed3a MG |
674 | r3 = r7 + 0x20; |
675 | r5 = *((unsigned int*)r3); | |
676 | ||
e433bc03 MG |
677 | if ((ret = crc_check_59684(r7, r5, 0x46335053)) != 0) { |
678 | printf("crc_check return: %d\n", ret); | |
2363a0d6 | 679 | err_exit(__func__); |
e433bc03 MG |
680 | } |
681 | #endif | |
af1fed3a | 682 | |
2363a0d6 | 683 | write_file((char*)name, outbuf, len); |
e433bc03 | 684 | |
2363a0d6 | 685 | free(outbuf); |
14ff7444 | 686 | } |