]>
cvs.zerfleddert.de Git - rsbs2/blob - extract.c
15 void extract_files(unsigned char *fw
, int len
)
18 unsigned int type
, length
;
22 printf("Start of filesystem: 0x%08x\n", *((unsigned int*)pos
));
24 pos
= fw
+ *((unsigned int*)pos
);
26 while (pos
< (fw
+ len
)) {
27 type
= *((unsigned int*)pos
);
31 length
= *((unsigned int*)pos
);
34 pos
+= strlen(name
) + 1;
36 if ((pos
+ length
) > (fw
+ len
)) {
37 printf("EOF reached\n");
40 printf("%s: type: 0x%x, length: %d", name
, type
, length
);
43 write_file(name
, pos
, length
);
44 if (*((unsigned int*)pos
) == LZ_MAGIC
) {
47 if ((lzname
= strdup(name
)) == NULL
) {
52 if (!strcmp(lzname
+ strlen(lzname
) - 4 , ".lz")) {
53 fprintf(stderr
, "Ugh, can't derive filename...\n");
56 lzname
[strlen(lzname
) - 3] = 0x00;
58 printf("%s: packed file found", lzname
);
60 extract_lz_file(pos
, (unsigned char*)lzname
);
62 } else if (!strcmp(name
, "firmware")) {
66 bzero(lzname
, sizeof(lzname
));
67 strcpy(lzname
, "firmware.");
69 lzpos
= pos
+ *((unsigned int*)(pos
+ 0x20));
70 memcpy(lzname
+ strlen(lzname
), lzpos
- 4, 4);
72 if (*((unsigned int*)(lzpos
)) == LZ_MAGIC
) {
73 printf("%s: compressed firmware part found", lzname
);
74 extract_lz_file(lzpos
, (unsigned char*)lzname
);
84 void mkdir_p(char *dir
)
88 if ((dir
== NULL
) || (!strcmp(dir
, ".")))
91 if ((copy
= strdup(dir
)) == NULL
) {
95 parent
= dirname(copy
);
99 if (mkdir(dir
, 0755) == -1) {
100 if (errno
!= EEXIST
) {
101 fprintf(stderr
, "%s: ", dir
);
109 void write_file(char *fname
, unsigned char *buf
, int len
)
111 char filename
[PATH_MAX
];
112 char *filename_c
, *dirn
;
117 strcpy(filename
, "extracted/");
118 strcat(filename
, fname
);
120 if ((filename_c
= strdup(filename
)) == NULL
) {
124 dirn
= dirname(filename_c
);
128 if ((fd
= open(filename
, O_WRONLY
|O_CREAT
, 0644)) == -1) {
129 fprintf(stderr
, "%s: ", filename
);
137 ret
= write(fd
, buf
+ (len
- remaining
), remaining
);
145 printf(", %s written.\n", filename
);