magiskboot: add unpack -n to help with repack validity tests

- support unpack without decompression to allow easy testing of magiskboot's header, structure and hashing handling by comparing repack checksum versus origbootimg
- make -n first to match repack
This commit is contained in:
osm0sis 2019-10-29 15:48:58 -03:00 committed by John Wu
parent 0a89edf3b0
commit 353c3c7d81
3 changed files with 27 additions and 9 deletions

View File

@ -312,14 +312,14 @@ void boot_img::find_kernel_dtb() {
}
}
int unpack(const char *image, bool hdr) {
int unpack(const char *image, bool nodecomp, bool hdr) {
boot_img boot(image);
if (hdr)
boot.hdr->dump_hdr_file();
// Dump kernel
if (COMPRESSED(boot.k_fmt)) {
if (COMPRESSED(boot.k_fmt) && !nodecomp) {
int fd = creat(KERNEL_FILE, 0644);
decompress(boot.k_fmt, fd, boot.kernel, boot.hdr->kernel_size());
close(fd);
@ -331,7 +331,7 @@ int unpack(const char *image, bool hdr) {
dump(boot.kernel_dtb, boot.kernel_dt_size, KER_DTB_FILE);
// Dump ramdisk
if (COMPRESSED(boot.r_fmt)) {
if (COMPRESSED(boot.r_fmt) && !nodecomp) {
int fd = creat(RAMDISK_FILE, 0644);
decompress(boot.r_fmt, fd, boot.ramdisk, boot.hdr->ramdisk_size());
close(fd);

View File

@ -12,7 +12,7 @@
#define DTB_FILE "dtb"
#define NEW_BOOT "new-boot.img"
int unpack(const char *image, bool hdr = false);
int unpack(const char *image, bool nodecomp = false, bool hdr = false);
void repack(const char* src_img, const char* out_img, bool nocomp = false);
int hexpatch(const char *image, const char *from, const char *to);
int cpio_commands(int argc, char *argv[]);

View File

@ -21,9 +21,11 @@ FULL_VER(MagiskBoot) R"EOF( - Boot Image Modification Tool
Usage: %s <action> [args...]
Supported actions:
unpack [-h] <bootimg>
unpack [-n] [-h] <bootimg>
Unpack <bootimg> to, if available, kernel, kernel_dtb, ramdisk.cpio,
second, dtb, extra, and recovery_dtbo into current directory.
If '-n' is provided, it will not attempt to decompress kernel or
ramdisk.cpio from their original formats.
If '-h' is provided, it will dump header info to 'header',
which will be parsed when repacking.
Return values:
@ -146,10 +148,26 @@ int main(int argc, char *argv[]) {
printf("\n");
munmap(buf, size);
} else if (argc > 2 && action == "unpack") {
if (argv[2] == "-h"sv) {
if (argc == 3)
usage(argv[0]);
return unpack(argv[3], true);
if (argv[2] == "-n"sv) {
if (argv[3] == "-h"sv) {
if (argc == 4)
usage(argv[0]);
return unpack(argv[4], true, true);
} else {
if (argc == 3)
usage(argv[0]);
return unpack(argv[3], true);
}
} else if (argv[2] == "-h"sv) {
if (argv[3] == "-n"sv) {
if (argc == 4)
usage(argv[0]);
return unpack(argv[4], true, true);
} else {
if (argc == 3)
usage(argv[0]);
return unpack(argv[3], false, true);
}
} else {
return unpack(argv[2]);
}