Skip to content
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

SegmentCommand.create does not properly create a segment command with a non-zero number of sections #7428

Open
nmggithub opened this issue Jan 30, 2025 · 2 comments
Assignees
Labels
Feature: Loader/Mach-O Status: Triage Information is being gathered

Comments

@nmggithub
Copy link

Describe the bug
A clear and concise description of the bug.

To Reproduce
Use the SegmentCommand.create method and pass a non-zero value to the numSections argument. The resulting bytes have a cmdsize parameter that does not account for the section definitions.

Expected behavior
The resulting bytes have a cmdsize parameter that does account for the section definitions.

Additional context
As far as I know, each section definition is of a guaranteed size, so it should be trivial to multiply that size by the number of sections and add it to the total size. The sections may not be included in the returned bytes, but at least the cmdsize parameter will be more accurate. The function could include null bytes of the correct size, if need be. At worst, it can throw if a non-zero value is passed to the numSections argument.

I understand this is a new-ish method, but is quite helpful for some work that I am doing. I am, however, having to manually re-do the cmdsize parameter afterwards and would prefer to not have to do that.

@ryanmkurtz
Copy link
Collaborator

Yea, i guess i only needed to create segments with no sections, so the numSections introduces the potential for wrongness. I am inclined to fix this by just removing the parameter and updating the javadoc.

Do you actually need meaningful sections to be created?

@ryanmkurtz ryanmkurtz added Feature: Loader/Mach-O Status: Triage Information is being gathered labels Feb 3, 2025
@ryanmkurtz ryanmkurtz self-assigned this Feb 3, 2025
@nmggithub
Copy link
Author

I'm using it with some code that fixes up commands (adjusts the values of specific fields) and it's cleaner code to use this method and pass in all the old values (plus whatever values I want to change) instead of relying on manually calculated offsets for where to write the bytes.

Honestly, if there was an easier way for any of these data types to target specific fields and get the bytes to write back, it would be nice. But I understand that's probably more complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Loader/Mach-O Status: Triage Information is being gathered
Projects
None yet
Development

No branches or pull requests

2 participants