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