]>
cvs.zerfleddert.de Git - rsbs2/blob - extract.c
15 void extract_files(unsigned char *fw
, int len
)
19 unsigned char unknown
[5];
23 printf("Start of filesystem: 0x%08x\n", *((unsigned int*)pos
));
25 pos
= fw
+ *((unsigned int*)pos
);
27 while (pos
< (fw
+ len
)) {
28 unknown
[0] = *pos
; pos
++;
29 unknown
[1] = *pos
; pos
++;
30 unknown
[2] = *pos
; pos
++;
31 unknown
[3] = *pos
; pos
++;
32 unknown
[4] = *pos
; pos
++;
33 length
= *((unsigned int*)pos
);
36 pos
+= strlen(name
) + 1;
38 if ((pos
+ length
) > (fw
+ len
)) {
39 printf("EOF reached\n");
42 printf("%s: unknown: %02x %02x %02x %02x %02x, length: %d",
43 name
, unknown
[0], unknown
[1], unknown
[2], unknown
[3],
47 write_file(name
, pos
, length
);
48 if (*((unsigned int*)pos
) == LZ_MAGIC
) {
51 if ((lzname
= strdup(name
)) == NULL
) {
56 if (!strcmp(lzname
+ strlen(lzname
) - 4 , ".lz")) {
57 fprintf(stderr
, "Ugh, can't derive filename...\n");
60 lzname
[strlen(lzname
) - 3] = 0x00;
62 printf("%s: packed file found", lzname
);
64 extract_lz_file(pos
, (unsigned char*)lzname
);
66 } else if (!strcmp(name
, "firmware")) {
70 bzero(lzname
, sizeof(lzname
));
71 strcpy(lzname
, "firmware.");
73 lzpos
= pos
+ *((unsigned int*)(pos
+ 0x20));
74 memcpy(lzname
+ strlen(lzname
), lzpos
- 4, 4);
76 if (*((unsigned int*)(lzpos
)) == LZ_MAGIC
) {
77 printf("%s: compressed firmware part found", lzname
);
78 extract_lz_file(lzpos
, (unsigned char*)lzname
);
88 void mkdir_p(char *dir
)
92 if ((dir
== NULL
) || (!strcmp(dir
, ".")))
95 if ((copy
= strdup(dir
)) == NULL
) {
99 parent
= dirname(copy
);
103 if (mkdir(dir
, 0755) == -1) {
104 if (errno
!= EEXIST
) {
105 fprintf(stderr
, "%s: ", dir
);
113 void write_file(char *fname
, unsigned char *buf
, int len
)
115 char filename
[PATH_MAX
];
116 char *filename_c
, *dirn
;
121 strcpy(filename
, "extracted/");
122 strcat(filename
, fname
);
124 if ((filename_c
= strdup(filename
)) == NULL
) {
128 dirn
= dirname(filename_c
);
132 if ((fd
= open(filename
, O_WRONLY
|O_CREAT
, 0644)) == -1) {
133 fprintf(stderr
, "%s: ", filename
);
141 ret
= write(fd
, buf
+ (len
- remaining
), remaining
);
149 printf(", %s written.\n", filename
);