mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 20:15:29 +00:00
Fix alignment when boot image has head offset
This commit is contained in:
parent
10bd25be52
commit
18f6ead891
@ -63,8 +63,10 @@ int parse_img(const char *image, boot_img *boot) {
|
|||||||
|
|
||||||
// Parse image
|
// Parse image
|
||||||
fprintf(stderr, "Parsing boot image: [%s]\n", image);
|
fprintf(stderr, "Parsing boot image: [%s]\n", image);
|
||||||
for (size_t pos = 0; pos < boot->map_size; pos += 256) {
|
for (void *head = boot->map_addr; head < boot->map_addr + boot->map_size; head += 256) {
|
||||||
switch (check_type(boot->map_addr + pos)) {
|
size_t pos = 0;
|
||||||
|
|
||||||
|
switch (check_type(head)) {
|
||||||
case CHROMEOS:
|
case CHROMEOS:
|
||||||
// The caller should know it's chromeos, as it needs additional signing
|
// The caller should know it's chromeos, as it needs additional signing
|
||||||
boot->flags |= CHROMEOS_FLAG;
|
boot->flags |= CHROMEOS_FLAG;
|
||||||
@ -75,33 +77,33 @@ int parse_img(const char *image, boot_img *boot) {
|
|||||||
exit(ELF64_RET);
|
exit(ELF64_RET);
|
||||||
case AOSP:
|
case AOSP:
|
||||||
// Read the header
|
// Read the header
|
||||||
memcpy(&boot->hdr, boot->map_addr + pos, sizeof(boot->hdr));
|
memcpy(&boot->hdr, head + pos, sizeof(boot->hdr));
|
||||||
pos += boot->hdr.page_size;
|
pos += boot->hdr.page_size;
|
||||||
|
|
||||||
print_hdr(&boot->hdr);
|
print_hdr(&boot->hdr);
|
||||||
|
|
||||||
boot->kernel = boot->map_addr + pos;
|
boot->kernel = head + pos;
|
||||||
pos += boot->hdr.kernel_size;
|
pos += boot->hdr.kernel_size;
|
||||||
mem_align(&pos, boot->hdr.page_size);
|
mem_align(&pos, boot->hdr.page_size);
|
||||||
|
|
||||||
boot->ramdisk = boot->map_addr + pos;
|
boot->ramdisk = head + pos;
|
||||||
pos += boot->hdr.ramdisk_size;
|
pos += boot->hdr.ramdisk_size;
|
||||||
mem_align(&pos, boot->hdr.page_size);
|
mem_align(&pos, boot->hdr.page_size);
|
||||||
|
|
||||||
if (boot->hdr.second_size) {
|
if (boot->hdr.second_size) {
|
||||||
boot->second = boot->map_addr + pos;
|
boot->second = head + pos;
|
||||||
pos += boot->hdr.second_size;
|
pos += boot->hdr.second_size;
|
||||||
mem_align(&pos, boot->hdr.page_size);
|
mem_align(&pos, boot->hdr.page_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boot->hdr.extra_size) {
|
if (boot->hdr.extra_size) {
|
||||||
boot->extra = boot->map_addr + pos;
|
boot->extra = head + pos;
|
||||||
pos += boot->hdr.extra_size;
|
pos += boot->hdr.extra_size;
|
||||||
mem_align(&pos, boot->hdr.page_size);
|
mem_align(&pos, boot->hdr.page_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos < boot->map_size) {
|
if (pos < boot->map_size) {
|
||||||
boot->tail = boot->map_addr + pos;
|
boot->tail = head + pos;
|
||||||
boot->tail_size = boot->map_size - pos;
|
boot->tail_size = boot->map_size - pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user