2017-02-27 21:37:47 +00:00
|
|
|
#include "magiskboot.h"
|
2016-09-08 12:59:48 +00:00
|
|
|
|
2017-02-24 19:29:12 +00:00
|
|
|
static void dump(unsigned char *buf, size_t size, const char *filename) {
|
2017-03-04 13:16:59 +00:00
|
|
|
int fd = open_new(filename);
|
2017-04-28 13:48:38 +00:00
|
|
|
xwrite(fd, buf, size);
|
2017-03-04 13:16:59 +00:00
|
|
|
close(fd);
|
2016-09-08 12:59:48 +00:00
|
|
|
}
|
|
|
|
|
2017-02-27 21:37:47 +00:00
|
|
|
void unpack(const char* image) {
|
2017-03-04 13:16:59 +00:00
|
|
|
size_t size;
|
|
|
|
unsigned char *orig;
|
|
|
|
mmap_ro(image, &orig, &size);
|
2016-09-08 12:59:48 +00:00
|
|
|
|
2017-02-27 21:37:47 +00:00
|
|
|
// Parse image
|
2017-03-09 20:08:17 +00:00
|
|
|
printf("Parsing boot image: [%s]\n\n", image);
|
2017-02-27 21:37:47 +00:00
|
|
|
parse_img(orig, size);
|
|
|
|
|
|
|
|
char name[PATH_MAX];
|
2017-02-23 23:45:48 +00:00
|
|
|
|
2017-02-24 19:29:12 +00:00
|
|
|
// Dump kernel
|
2017-02-27 21:37:47 +00:00
|
|
|
if (mtk_kernel) {
|
2017-02-24 19:29:12 +00:00
|
|
|
kernel += 512;
|
2017-02-23 23:45:48 +00:00
|
|
|
hdr.kernel_size -= 512;
|
|
|
|
}
|
2017-02-27 21:37:47 +00:00
|
|
|
dump(kernel, hdr.kernel_size, KERNEL_FILE);
|
2017-02-23 23:45:48 +00:00
|
|
|
|
|
|
|
// Dump ramdisk
|
2017-02-27 21:37:47 +00:00
|
|
|
if (mtk_ramdisk) {
|
2017-02-24 19:29:12 +00:00
|
|
|
ramdisk += 512;
|
2017-02-23 23:45:48 +00:00
|
|
|
hdr.ramdisk_size -= 512;
|
|
|
|
}
|
2017-03-02 13:59:37 +00:00
|
|
|
if (decomp(ramdisk_type, RAMDISK_FILE, ramdisk, hdr.ramdisk_size)) {
|
|
|
|
// Dump the compressed ramdisk
|
2017-03-04 17:50:36 +00:00
|
|
|
dump(ramdisk, hdr.ramdisk_size, RAMDISK_FILE ".unsupport");
|
2017-04-28 13:48:38 +00:00
|
|
|
LOGE(1, "Unsupported ramdisk format! Dumped to %s\n", RAMDISK_FILE ".unsupport");
|
2016-09-08 12:59:48 +00:00
|
|
|
}
|
2017-02-23 23:45:48 +00:00
|
|
|
|
|
|
|
if (hdr.second_size) {
|
|
|
|
// Dump second
|
2017-02-27 21:37:47 +00:00
|
|
|
dump(second, hdr.second_size, SECOND_FILE);
|
2017-02-23 23:45:48 +00:00
|
|
|
}
|
2016-09-08 12:59:48 +00:00
|
|
|
|
2017-02-23 23:45:48 +00:00
|
|
|
if (hdr.dt_size) {
|
2017-04-27 19:15:48 +00:00
|
|
|
// Dump dtb
|
|
|
|
dump(dtb, hdr.dt_size, DTB_FILE);
|
2016-09-08 12:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
munmap(orig, size);
|
|
|
|
}
|
2017-02-23 23:45:48 +00:00
|
|
|
|