blacktop / ipsw

iOS/macOS Research Swiss Army Knife
https://blacktop.github.io/ipsw
MIT License
1.89k stars 147 forks source link

ipsw macho patch can only handle 1 build tool for LC_BUILD_VERSION #403

Closed saagarjha closed 7 months ago

saagarjha commented 8 months ago

What happened?

A Mach-O file can have between 0 and ~unlimited build tools. However ipsw macho patch requires exactly one: https://github.com/blacktop/ipsw/blob/1e8a8bc1a86366ee247dec921515a7bfb53f7f44/cmd/ipsw/cmd/macho/macho_patch.go#L152

How can we reproduce this?

$ ipsw macho patch mod MACHO LC_BUILD_VERSION iOS 16.3 16.3
? You are about to overwrite MACHO. Continue? Yes
   • Modifying load command LC_BUILD_VERSION in MACHO
   ⨯ failed to patch MachO file: not enough arguments for adding LC_BUILD_VERSION; must supply PLATFORM, MINOS, SDK strings and TOOL, TOOL_VERSION strings

ipsw version

Version: , BuildTime: 20240208

Search

Code of Conduct

Additional context

No response

blacktop commented 8 months ago

I believe I have fixed the ipsw code now, however, I believe there still exists a 🐛 in go-macho's export.go functionality that needs a closer look when adding/manipulating LCs etc.

The reason I hid the ipsw dsc extract cmd was reports of it creating dylibs w/ section boundaries that IDA Pro didn't like.

I don't use the functionality that much myself, but it's something I need to fix (as it also affects the ipsw macho patch cmd.

If you have any interest/time I'd ❤️ some help w/ it. Otherwise I'll keep this issue open until I can confirm it's good.

Thanks again for reporting this issue.

blacktop commented 7 months ago

Started looking at go-macho's Export and remembered that the ipsw macho patch cmd uses the Save func not the Export so this should be fine (unless you added so many NEW LCs that it had to resize the segment so closing.