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

machocopy example #613

Open
wolfv opened this issue Dec 20, 2023 · 3 comments
Open

machocopy example #613

wolfv opened this issue Dec 20, 2023 · 3 comments

Comments

@wolfv
Copy link

wolfv commented Dec 20, 2023

Hi, we're trying to reimplement patchelf and install_name_tool with object and at least for patchelf it seems quite straightforward with the elfcopy example :)

For install_name_tool I seem to miss a way to add load_commands to the writer. Reading the MachO file works well (we're mostly interested in patching / changing the rpath to something relative), and I can read the rpath nicely.

I was wondering if you have a quick tip on how to achieve this.

@philipc
Copy link
Contributor

philipc commented Dec 20, 2023

There isn't a way to write MachO executables yet, so there's no machocopy. We need to add the equivalent of write::elf::Writer for MachO. This isn't a small task.

@wolfv
Copy link
Author

wolfv commented Dec 21, 2023

Thanks for the hint!

Do you think there is a shortcut if all we want is to rewrite an rpath in the MachO file? We're happy to contribute.

Also if you can give me any hints on how to start this endeavor, that would be cool.

@philipc
Copy link
Contributor

philipc commented Dec 21, 2023

If I understand correctly, rewriting the rpath is conceptually simple: you just want to change the string in the load command for LC_RPATH. The catch is that doing so may change the file offsets of other data, so you still need to parse some of the other load commands and fix the file offsets if needed.

src/write/macho.rs already has code for writing some parts of a Mach-O file. Ideally some of that code would be moved into a write::macho::Writer that can be used by both write::Object and your utility. However, starting with something that only meets your needs would be fine, and write::Object can be migrated later.

I would start by implementing something that treats all of the load commands as opaque blocks, and then progressively add support for the load commands that need further parsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants