-
Notifications
You must be signed in to change notification settings - Fork 15
Fix to read correctly even when linkedit does not exist in the same cache #231
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modifies the MachOKit library to properly handle linkedit data when reading from dyld cache files on iOS, where linkedit data is stored in a separate cache file (.0x.linkeditdata) rather than in the same cache as the main Mach-O data.
- Introduces new methods
_fileSliceForLinkEditData
and_readLinkEditData
to handle linkedit data reading from appropriate cache locations - Updates multiple properties to use the new linkedit data reading methods instead of direct file handle operations
- Adds cached properties for
DyldCache
andFullDyldCache
instances to improve performance
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
File | Description |
---|---|
Sources/MachOKit/MachOFile.swift | Core implementation with new linkedit data handling methods and updated properties |
Sources/MachOKit/MachOFile+Symbols.swift | Updated symbol loading to use new linkedit data methods |
Sources/MachOKit/MachOFile+Strings.swift | Added new initializer for Strings class |
Sources/MachOKit/MachOFile+FunctionStarts.swift | Updated function starts loading to use new linkedit data method |
Sources/MachOKit/MachOFile+ExportTrie.swift | Updated export trie loading to use new linkedit data method |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
.deletingPathExtension() | ||
.deletingPathExtension() | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These computed properties will create new cache instances on every access. Consider implementing lazy stored properties or caching mechanisms to avoid repeated initialization overhead, especially since these caches are accessed multiple times throughout the codebase.
} | |
internal lazy var cache: DyldCache? = { | |
try? DyldCache(url: url) | |
}() | |
internal lazy var fullCache: FullDyldCache? = { | |
try? FullDyldCache( | |
url: url | |
.deletingPathExtension() | |
.deletingPathExtension() | |
) | |
}() |
Copilot uses AI. Check for mistakes.
length: numericCast(symtab.strsize) | ||
) | ||
)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force unwrapping with !
can cause crashes if _fileSliceForLinkEditData
returns nil. Consider using guard statements or proper error handling instead of force unwrapping.
Copilot uses AI. Check for mistakes.
length: numericCast(symtab.nsyms) * MemoryLayout<nlist_64>.size | ||
) | ||
)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force unwrapping with !
can cause crashes if _fileSliceForLinkEditData
returns nil. Consider using guard statements or proper error handling instead of force unwrapping.
Copilot uses AI. Check for mistakes.
let stringsSlice = machO._fileSliceForLinkEditData( | ||
offset: numericCast(symtab.stroff), | ||
length: numericCast(symtab.strsize) | ||
)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force unwrapping with !
can cause crashes if _fileSliceForLinkEditData
returns nil. Consider using guard statements or proper error handling instead of force unwrapping.
Copilot uses AI. Check for mistakes.
let symbolsSlice = machO._fileSliceForLinkEditData( | ||
offset: numericCast(symtab.symoff), | ||
length: numericCast(symtab.nsyms) * MemoryLayout<nlist>.size | ||
)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force unwrapping with !
can cause crashes if _fileSliceForLinkEditData
returns nil. Consider using guard statements or proper error handling instead of force unwrapping.
Copilot uses AI. Check for mistakes.
length: functionStartsSize | ||
) | ||
)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force unwrapping with !
can cause crashes if _readLinkEditData
returns nil. Consider using guard statements or proper error handling instead of force unwrapping.
Copilot uses AI. Check for mistakes.
length: exportSize | ||
) | ||
)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force unwrapping with !
can cause crashes if _readLinkEditData
returns nil. Consider using guard statements or proper error handling instead of force unwrapping.
Copilot uses AI. Check for mistakes.
The linkedit data in iOS is stored together in a separate, independent cache.
(dyld_shared_cache_arm64e.65.dyldreadonly)