]>
git.zerfleddert.de Git - rsbs2/blob - rsb-lz.c
7d20942c5af1ed230af33010b15fa66f65ab889a
9 #include "filesystem.h"
11 void err_exit(const char *fname
)
13 fprintf(stderr
,"%s: error extracting...\n", fname
);
18 unsigned char *start
; /* 0 */
19 unsigned char *stop
; /* 4 */
20 unsigned char bit
; /* 8 */
21 unsigned char x
; /* 9 */
29 unsigned char get_next_in_byte(struct data_in_s
*data_in
)
33 if (data_in
->stop
< data_in
->start
)
36 byte
= *(data_in
->start
);
42 unsigned int fn_59848(struct data_in_s
*data_in
)
46 if (data_in
->bit
== 0x80) {
47 data_in
->x
= get_next_in_byte(data_in
);
50 r5
= data_in
->bit
& data_in
->x
& 0xff;
53 if (data_in
->bit
== 0) {
63 unsigned int fn_598b4(struct data_in_s
*r11_data
, unsigned int r10_arg2
)
77 r1
= get_next_in_byte(r11_data
);
101 void fn_5980c(unsigned int arg1
, struct data_out_s
*data_out
)
110 printf("r1: 0x%08x, r2: 0x%08x\n", (unsigned int)r1
, (unsigned int)r2
);
120 void lz_expand(struct data_in_s
*r10_data
, struct data_out_s
*data_out
)
128 unsigned char arr_59b64
[1024];
134 r2
= fn_59848(r10_data
);
138 r2
= fn_598b4(r10_data
, 8) & 0xff;
140 fn_5980c(r2
, data_out
);
141 arr_59b64
[r5
] = r2
& 0xff;
142 r5
= (r5
+ 1) & 0x3ff;
145 r11
= fn_598b4(r10_data
, 0x0a);
149 r2
= fn_598b4(r10_data
, 0x04);
153 r2
= (r6
+ r11
) & 0x3ff;
155 fn_5980c(r4
, data_out
);
157 r5
= (r5
+ 1) & 0x3ff;
163 /* Checksum is only used for the compressed firmware in 'firmware' */
165 unsigned int crc_check_59684(unsigned char *arg1
, unsigned int arg2
, unsigned int magic
)
177 r4
= *((unsigned int*)arg1
+ 0x20);
178 r5
= *((unsigned int*)arg1
+ 0x24);
180 printf("magic: 0x%08x <-> 0x%08x\n", r5
, magic
);
189 r5
= ~rsb_crc(~0x00, arg1
, r4
);
190 r3
= *((unsigned int*)(arg1
+ r4
));
191 printf("Checksums: 0x%02x <-> 0x%02x\n", r5
, r3
);
200 void extract_lz_file(unsigned char *inbuf
, unsigned char *name
)
203 unsigned char *outbuf
;
204 struct data_in_s data_in
;
205 struct data_out_s data_out
;
207 if (*((unsigned int*)inbuf
) != LZ_MAGIC
)
210 len
= *((unsigned int*)(inbuf
+ 4));
211 printf(", length: %d", len
);
213 if ((outbuf
= malloc(len
)) == NULL
) {
220 data_in
.start
= inbuf
+ 8;
221 data_in
.stop
= inbuf
+ len
;
225 data_out
.pos
= outbuf
;
226 data_out
.end
= outbuf
+ len
;
228 lz_expand(&data_in
, &data_out
);
231 /* Checksum is only used for the compressed firmware in 'firmware' */
233 r5
= *((unsigned int*)r3
);
235 if ((ret
= crc_check_59684(r7
, r5
, 0x46335053)) != 0) {
236 printf("crc_check return: %d\n", ret
);
241 write_file((char*)name
, outbuf
, len
);