Skip to content

Conversation

@Ashishworks
Copy link

  • I've read the guidelines for contributing to this repository.
  • I made sure to follow the project's coding style.
  • I've documented every RZ_API function and struct this PR changes.
  • I've added tests that prove my changes are effective.
  • I've updated the Rizin book with the relevant information (if needed).
  • I've used AI tools to generate fully or partially these code changes and I'm sure the changes are not copyrighted by somebody else.

Detailed description

This PR refactors the Android boot image (bootimg) bin plugin to avoid using a packed struct for parsing the header.

  • Remove RZ_PACKED from the boot image header definition in librz/bin/p/bin_bootimg.c.
  • Rewrite header parsing to read fields sequentially instead of reading the entire header into a packed struct using 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

  • Added minimal boot image test sample: test/db/bins/bootimg/android_boot_min.img
  • Added format tests: test/db/formats/bootimg

Tests cover:

  • opening the file (q!)
  • confirming the detected type includes Android Boot Image (iI~type)
  • confirming the header section exists (iS~header)

Closing issues

closes #5814

@notxvilka notxvilka added the Requirements not met The PR doesn't meet the minimum contribution requirements. See CONTRIBUTING.md for details. label Jan 18, 2026
@Rot127 Rot127 marked this pull request as draft January 19, 2026 19:00
@Ashishworks Ashishworks requested a review from notxvilka January 20, 2026 10:07
@Ashishworks Ashishworks marked this pull request as ready for review January 20, 2026 10:38
@Ashishworks Ashishworks requested a review from wargio January 20, 2026 11:04
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Comment on lines +63 to +115
// 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;
}
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Comment on lines +118 to +125
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);
}
Copy link
Member

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.

Copy link
Author

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);
Copy link
Member

@wargio wargio Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
snprintf(key, sizeof(key), "id.%d", i);
rz_strf(key, "id.%d", i);

@Rot127 Rot127 marked this pull request as draft January 21, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Requirements not met The PR doesn't meet the minimum contribution requirements. See CONTRIBUTING.md for details. rz-test RzBin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor bin_bootimg.c to remove RZ_PACKED

3 participants