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

Support for new dyld_shared_cache format in iOS 15/macOS 12 #3345

Closed
zcutlip opened this issue Aug 18, 2021 · 16 comments · Fixed by #3666
Closed

Support for new dyld_shared_cache format in iOS 15/macOS 12 #3345

zcutlip opened this issue Aug 18, 2021 · 16 comments · Fixed by #3666

Comments

@zcutlip
Copy link

zcutlip commented Aug 18, 2021

The dyld_shared_cache format in iOS 15 & macOS 12 has changed and is now been split into 2 or more slices. Ghidra is no longer able to open it.

It would be helpful if Ghidra could be updated to open these shared cache clusters.

Below are examples of the shared cache layout directory on iOS & macOS

macOS 12:

❱ ls -1 System/Library/dyld/dyld_shared_cache_arm64*
System/Library/dyld/dyld_shared_cache_arm64e
System/Library/dyld/dyld_shared_cache_arm64e.1
System/Library/dyld/dyld_shared_cache_arm64e.map

iOS 15:

❱ ls -1 System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64*
System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64
System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64.1
System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64.2
System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64.3
System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64.4
System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64.5
System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64.symbols
@ryanmkurtz
Copy link
Collaborator

Thanks for the heads up. This is definitely something we'll want to support.

@ryanmkurtz
Copy link
Collaborator

Do you have any links that describe the new format? I don't have access to these at the moment.

@zcutlip
Copy link
Author

zcutlip commented Aug 18, 2021

There's not much, unfortunately. It's anticipated that Apple will release updated dyld source in the fall, but that often lags final releases by quite a bit.

There are a couple projects that are actively working on it: DyldExtractor and blacktop's IPSW. Here's a GH issue for DyldExtractor with, with participation from blacktop:
arandomdev/DyldExtractor#15

Hopper has (very) preliminary support, but I don't think it does much yet.

If binary analysis is an option for you, I'd look at dsc_extractor.bundle in the latest Xcode betas. Each SDK in Xcode except macOS has one. But the iOS version can be loaded on arm64 macOS, and can parse arm64 macOS shared cache. Watching it do its thing in lldb would probably reveal a lot. Here's a project that loads it on macOS and is able to parse the macOS shared cache:
https://github.com/keith/dyld-shared-cache-extractor

Hope that helps. I'll see what else I can find.

Zach

@mumbel
Copy link
Contributor

mumbel commented Aug 18, 2021

So you're saying that is something that would eventually be found here https://opensource.apple.com/source/dyld/ ? does it report which version of the format is used in the current files

@zcutlip
Copy link
Author

zcutlip commented Aug 19, 2021

If the past is any indication, yes, that's where new dyld source will go, which will include header files describing the new format, as well as C++ code that parses it. I'd expect to see source for that probably in October/November. Apple isn't super consistent on this.

As far as versioning, there are header fields that report versions in various ways, but it's not a very tidy "look at the version field to see what format version we're dealing with."

Probably the best example of version detection is DyldExtractor, referenced above. They do a pretty good job of dealing with an assortment of format variants. It's a combination of looking at a few explicit version fields in different structs, and heuristics (e.g., if this field is NULL, look for some additional fields at the end).

@ryanmkurtz
Copy link
Collaborator

I got some samples and should be able to make some initial guesses about how things are laid out. The biggest issue I see up front is that our Loader framework isn't designed to bring in more than 1 file. A Loader can support the Add to Program feature, but I am seeing that these files cross references each other in terms of memory layout definitions and DYLIB locations, so we'll have to think a little bit about how to best handle this.

@astrelsky
Copy link
Contributor

There's not much, unfortunately. It's anticipated that Apple will release updated dyld source in the fall, but that often lags final releases by quite a bit...

I got some samples and should be able to make some initial guesses about how things are laid out...

Time to roll up the sleeves and do it the old fashioned way.

Not entirely accurate but still applies I guess

meme

@mstange
Copy link

mstange commented Nov 7, 2021

I've also done some research on the format and have written down my findings in gimli-rs/object#358.

@ryanmkurtz
Copy link
Collaborator

I've also done some research on the format and have written down my findings in gimli-rs/object#358.

Thanks, I'm working on this now.

@ryanmkurtz
Copy link
Collaborator

ryanmkurtz commented Nov 22, 2021

I put up a PR for this if anyone wants to try it (#3666)

@ryanmkurtz ryanmkurtz added this to the 10.1 milestone Dec 3, 2021
@Kentzo
Copy link

Kentzo commented Apr 19, 2022

I'm using 10.1.2 bug Ghidra doesn't seem to load anything from /System/Library/dyld/*. Are there extra options that need to be set for this feature to work?

@ryanmkurtz
Copy link
Collaborator

What is an example file you are trying to load? Are you selecting Single File or File System?

@Kentzo
Copy link

Kentzo commented Apr 19, 2022 via email

@ryanmkurtz
Copy link
Collaborator

I just imported that file without any issues. I opened it in the File System Browser, then right clicked on the x86-64-cpu0x31 "file" and clicked import. I'm on macOS 12.3.1.

@Kentzo
Copy link

Kentzo commented Apr 19, 2022 via email

@ryanmkurtz
Copy link
Collaborator

ryanmkurtz commented Apr 19, 2022

Ah, I'll have to try that again tonight when I'm on my mac again. Can you please open a new ticket describing your issue in detail so it doesn't get lost in this already closed one?

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

Successfully merging a pull request may close this issue.

6 participants