]>
cvs.zerfleddert.de Git - rsbs2/blob - rsb-lz.c
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 bitpos
; /* 8 */
21 unsigned char byte
; /* 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 char fn_59848(struct data_in_s
*data_in
)
46 if (data_in
->bitpos
== 0x80) {
47 data_in
->byte
= get_next_in_byte(data_in
);
50 r5
= data_in
->bitpos
& data_in
->byte
;
52 data_in
->bitpos
>>= 1;
53 if (data_in
->bitpos
== 0) {
54 data_in
->bitpos
= 0x80;
63 unsigned int fn_598b4(struct data_in_s
*r11_data
, unsigned int r10_arg2
)
68 r6
= 1 << (r10_arg2
- 1);
72 if (r11_data
->bitpos
== 0x80) {
73 r11_data
->byte
= get_next_in_byte(r11_data
);
75 if ((r11_data
->bitpos
& r11_data
->byte
) != 0)
80 r11_data
->bitpos
>>= 1;
82 if(r11_data
->bitpos
== 0) {
83 r11_data
->bitpos
= 0x80;
90 void write_byte(unsigned char byte
, struct data_out_s
*data_out
)
92 if (data_out
->pos
> data_out
->end
) {
96 *(data_out
->pos
) = byte
;
100 void lz_expand(struct data_in_s
*r10_data
, struct data_out_s
*data_out
)
108 unsigned char arr_59b64
[1024];
114 r2
= fn_59848(r10_data
);
118 r2
= fn_598b4(r10_data
, 8) & 0xff;
120 write_byte(r2
, data_out
);
121 arr_59b64
[r5
] = r2
& 0xff;
122 r5
= (r5
+ 1) & 0x3ff;
125 r11
= fn_598b4(r10_data
, 0x0a);
129 r2
= fn_598b4(r10_data
, 0x04);
133 r2
= (r6
+ r11
) & 0x3ff;
135 write_byte(r4
, data_out
);
137 r5
= (r5
+ 1) & 0x3ff;
143 /* Checksum is only used for the compressed firmware in 'firmware' */
145 unsigned int crc_check_59684(unsigned char *arg1
, unsigned int arg2
, unsigned int magic
)
157 r4
= *((unsigned int*)arg1
+ 0x20);
158 r5
= *((unsigned int*)arg1
+ 0x24);
160 printf("magic: 0x%08x <-> 0x%08x\n", r5
, magic
);
169 r5
= ~rsb_crc(~0x00, arg1
, r4
);
170 r3
= *((unsigned int*)(arg1
+ r4
));
171 printf("Checksums: 0x%02x <-> 0x%02x\n", r5
, r3
);
180 void extract_lz_file(unsigned char *inbuf
, unsigned char *name
)
183 unsigned char *outbuf
;
184 struct data_in_s data_in
;
185 struct data_out_s data_out
;
187 if (*((unsigned int*)inbuf
) != LZ_MAGIC
)
190 len
= *((unsigned int*)(inbuf
+ 4));
191 printf(", length: %d", len
);
193 if ((outbuf
= malloc(len
)) == NULL
) {
200 data_in
.start
= inbuf
+ 8;
201 data_in
.stop
= inbuf
+ len
;
203 data_in
.bitpos
= 0x80;
205 data_out
.pos
= outbuf
;
206 data_out
.end
= outbuf
+ len
;
208 lz_expand(&data_in
, &data_out
);
211 /* Checksum is only used for the compressed firmware in 'firmware' */
213 r5
= *((unsigned int*)r3
);
215 if ((ret
= crc_check_59684(r7
, r5
, 0x46335053)) != 0) {
216 printf("crc_check return: %d\n", ret
);
221 write_file((char*)name
, outbuf
, len
);