magiskboot: fix bootimg hdr v2 checksum generation

- new AOSP dtb section was missing from HASH_update
This commit is contained in:
Chris Renshaw 2019-05-20 20:57:49 -03:00 committed by topjohnwu
parent 8c40db5730
commit 290a17a764

View File

@ -345,7 +345,7 @@ int unpack(const char *image, bool hdr) {
void repack(const char* orig_image, const char* out_image) { void repack(const char* orig_image, const char* out_image) {
boot_img boot {}; boot_img boot {};
off_t header_off, kernel_off, ramdisk_off, second_off, extra_off; off_t header_off, kernel_off, ramdisk_off, second_off, extra_off, dtb_off;
// Parse original image // Parse original image
boot.parse_file(orig_image); boot.parse_file(orig_image);
@ -475,6 +475,7 @@ void repack(const char* orig_image, const char* out_image) {
} }
// dtb // dtb
dtb_off = lseek(fd, 0, SEEK_CUR);
if (access(DTB_FILE, R_OK) == 0) { if (access(DTB_FILE, R_OK) == 0) {
boot.hdr.dtb_size() = restore(DTB_FILE, fd); boot.hdr.dtb_size() = restore(DTB_FILE, fd);
file_align(); file_align();
@ -527,6 +528,11 @@ void repack(const char* orig_image, const char* out_image) {
size = boot.hdr.recovery_dtbo_size(); size = boot.hdr.recovery_dtbo_size();
HASH_update(&ctx, boot.map_addr + boot.hdr.recovery_dtbo_offset(), size); HASH_update(&ctx, boot.map_addr + boot.hdr.recovery_dtbo_offset(), size);
HASH_update(&ctx, &size, sizeof(size)); HASH_update(&ctx, &size, sizeof(size));
size = boot.hdr.dtb_size();
if (size) {
HASH_update(&ctx, boot.map_addr + dtb_off, size);
HASH_update(&ctx, &size, sizeof(size));
}
} }
memset(boot.hdr.id(), 0, 32); memset(boot.hdr.id(), 0, 32);
memcpy(boot.hdr.id(), HASH_final(&ctx), memcpy(boot.hdr.id(), HASH_final(&ctx),