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:
parent
0a89edf3b0
commit
353c3c7d81
@ -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);
|
boot_img boot(image);
|
||||||
|
|
||||||
if (hdr)
|
if (hdr)
|
||||||
boot.hdr->dump_hdr_file();
|
boot.hdr->dump_hdr_file();
|
||||||
|
|
||||||
// Dump kernel
|
// Dump kernel
|
||||||
if (COMPRESSED(boot.k_fmt)) {
|
if (COMPRESSED(boot.k_fmt) && !nodecomp) {
|
||||||
int fd = creat(KERNEL_FILE, 0644);
|
int fd = creat(KERNEL_FILE, 0644);
|
||||||
decompress(boot.k_fmt, fd, boot.kernel, boot.hdr->kernel_size());
|
decompress(boot.k_fmt, fd, boot.kernel, boot.hdr->kernel_size());
|
||||||
close(fd);
|
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(boot.kernel_dtb, boot.kernel_dt_size, KER_DTB_FILE);
|
||||||
|
|
||||||
// Dump ramdisk
|
// Dump ramdisk
|
||||||
if (COMPRESSED(boot.r_fmt)) {
|
if (COMPRESSED(boot.r_fmt) && !nodecomp) {
|
||||||
int fd = creat(RAMDISK_FILE, 0644);
|
int fd = creat(RAMDISK_FILE, 0644);
|
||||||
decompress(boot.r_fmt, fd, boot.ramdisk, boot.hdr->ramdisk_size());
|
decompress(boot.r_fmt, fd, boot.ramdisk, boot.hdr->ramdisk_size());
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#define DTB_FILE "dtb"
|
#define DTB_FILE "dtb"
|
||||||
#define NEW_BOOT "new-boot.img"
|
#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);
|
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 hexpatch(const char *image, const char *from, const char *to);
|
||||||
int cpio_commands(int argc, char *argv[]);
|
int cpio_commands(int argc, char *argv[]);
|
||||||
|
@ -21,9 +21,11 @@ FULL_VER(MagiskBoot) R"EOF( - Boot Image Modification Tool
|
|||||||
Usage: %s <action> [args...]
|
Usage: %s <action> [args...]
|
||||||
|
|
||||||
Supported actions:
|
Supported actions:
|
||||||
unpack [-h] <bootimg>
|
unpack [-n] [-h] <bootimg>
|
||||||
Unpack <bootimg> to, if available, kernel, kernel_dtb, ramdisk.cpio,
|
Unpack <bootimg> to, if available, kernel, kernel_dtb, ramdisk.cpio,
|
||||||
second, dtb, extra, and recovery_dtbo into current directory.
|
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',
|
If '-h' is provided, it will dump header info to 'header',
|
||||||
which will be parsed when repacking.
|
which will be parsed when repacking.
|
||||||
Return values:
|
Return values:
|
||||||
@ -146,10 +148,26 @@ int main(int argc, char *argv[]) {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
munmap(buf, size);
|
munmap(buf, size);
|
||||||
} else if (argc > 2 && action == "unpack") {
|
} else if (argc > 2 && action == "unpack") {
|
||||||
if (argv[2] == "-h"sv) {
|
if (argv[2] == "-n"sv) {
|
||||||
if (argc == 3)
|
if (argv[3] == "-h"sv) {
|
||||||
usage(argv[0]);
|
if (argc == 4)
|
||||||
return unpack(argv[3], true);
|
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 {
|
} else {
|
||||||
return unpack(argv[2]);
|
return unpack(argv[2]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user