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

Mach-O : cannot set bind_opcodes #857

Open
nsurbay opened this issue Jan 23, 2023 · 2 comments
Open

Mach-O : cannot set bind_opcodes #857

nsurbay opened this issue Jan 23, 2023 · 2 comments

Comments

@nsurbay
Copy link
Contributor

nsurbay commented Jan 23, 2023

Describe the bug
I try to set target.dyld_info.bind_opcodes on a MachO binary. The property seems to be set to the expected value before the write method, but is back to the previous value when write the modified binary.

To Reproduce

binary = lief.MachO.parse("/bin/ls")
target = binary.at(1) # with target.header.cpu_type == lief.MachO.CPU_TYPES.ARM64
opcodes = target.dyld_info.bind_opcodes.tobytes()
print("origin =", opcodes[:20].hex())
# change opcode 
target.dyld_info.bind_opcodes = [0] * len(opcodes)
print("change =", target.dyld_info.bind_opcodes.tobytes()[:20].hex())
# write library in outputfile
target.write(outputfile)
print("write =", target.dyld_info.bind_opcodes.tobytes()[:20].hex())
# get opcode of outputfile
binary2 = lief.MachO.parse(outputfile)
print("outputfile =", binary2.at(0).dyld_info.bind_opcodes.tobytes()[:20].hex())

returns

origin = d05a11405f68756d616e697a655f6e756d626572
change = 0000000000000000000000000000000000000000
write = d05a11405f68756d616e697a655f6e756d626572
outputfile = d05a11405f68756d616e697a655f6e756d626572

Expected behavior

The opcode is replaced in the output binary.

origin = d05a11405f68756d616e697a655f6e756d626572
change = 0000000000000000000000000000000000000000
write = 0000000000000000000000000000000000000000
outputfile = 0000000000000000000000000000000000000000

Environment (please complete the following information):

  • System and Version : macOS 13.1 / Python3.9
  • Target format : Mach-O
  • LIEF commit version: 0.12.3-e34a2fb7 (Installed with pip install lief)

Additional context
n/a

@romainthomas
Copy link
Member

Hi Nicolas,

Yes actually you can't modify the raw Dyld opcodes as they are recomputed in the build process. Nevertheless I could add an option in the build process to avoid this re-computation.

@nsurbay
Copy link
Contributor Author

nsurbay commented Feb 14, 2023

I finally didn't manage to do what I wanted by modifying bind_opcodes outside of lief.

Another solution could be to mark the property as readonly.

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

No branches or pull requests

2 participants