-
-
Notifications
You must be signed in to change notification settings - Fork 499
Refactor bootimg parser to avoid packed struct #5816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a dedicated repo for this (check tests/README.md). also where this file comes from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let me try a different approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
| // Read all 32-bit header fields (little-endian) | ||
| if (!rz_buf_read_le32_offset(obj->buf, &offset, &bi->kernel_size)) { | ||
| return false; | ||
| } | ||
| if (!rz_buf_read_le32_offset(obj->buf, &offset, &bi->kernel_addr)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!rz_buf_read_le32_offset(obj->buf, &offset, &bi->ramdisk_size)) { | ||
| return false; | ||
| } | ||
| if (!rz_buf_read_le32_offset(obj->buf, &offset, &bi->ramdisk_addr)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!rz_buf_read_le32_offset(obj->buf, &offset, &bi->second_size)) { | ||
| return false; | ||
| } | ||
| if (!rz_buf_read_le32_offset(obj->buf, &offset, &bi->second_addr)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!rz_buf_read_le32_offset(obj->buf, &offset, &bi->tags_addr)) { | ||
| return false; | ||
| } | ||
| if (!rz_buf_read_le32_offset(obj->buf, &offset, &bi->page_size)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!rz_buf_read_le32_offset(obj->buf, &offset, &bi->unused[0])) { | ||
| return false; | ||
| } | ||
| if (!rz_buf_read_le32_offset(obj->buf, &offset, &bi->unused[1])) { | ||
| return false; | ||
| } | ||
|
|
||
| // Read strings/arrays | ||
| if (!rz_buf_read_offset(obj->buf, &offset, bi->name, BOOT_NAME_SIZE)) { | ||
| return false; | ||
| } | ||
| if (!rz_buf_read_offset(obj->buf, &offset, bi->cmdline, BOOT_ARGS_SIZE)) { | ||
| return false; | ||
| } | ||
|
|
||
| for (i = 0; i < 8; i++) { | ||
| if (!rz_buf_read_le32_offset(obj->buf, &offset, &bi->id[i])) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| if (!rz_buf_read_offset(obj->buf, &offset, bi->extra_cmdline, BOOT_EXTRA_ARGS_SIZE)) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a function. check the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
| if ((n = rz_str_ndup((char *)bi->name, BOOT_NAME_SIZE))) { | ||
| sdb_set(db, "name", n); | ||
| free(n); | ||
| } | ||
| if ((n = rz_str_ndup((char *)bi->cmdline, BOOT_ARGS_SIZE))) { | ||
| sdb_set(db, "cmdline", n); | ||
| free(n); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a terrible idea if you don't sanitize the values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, I'll try a different approach.
|
|
||
| for (i = 0; i < 8; i++) { | ||
| char key[16]; | ||
| snprintf(key, sizeof(key), "id.%d", i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| snprintf(key, sizeof(key), "id.%d", i); | |
| rz_strf(key, "id.%d", i); |
RZ_APIfunction and struct this PR changes.Detailed description
This PR refactors the Android boot image (
bootimg) bin plugin to avoid using a packed struct for parsing the header.RZ_PACKEDfrom the boot image header definition inlibrz/bin/p/bin_bootimg.c.rz_buf_read_at().This improves portability and avoids potential alignment issues caused by packed structs.
AI disclosure: ChatGPT was used for guidance and review of the approach. All changes were implemented and verified manually.
Test plan
test/db/bins/bootimg/android_boot_min.imgtest/db/formats/bootimgTests cover:
q!)Android Boot Image(iI~type)headersection exists (iS~header)Closing issues
closes #5814