p-x9 / MachOKit

🔬 A Swift library for parsing mach-o files to obtain various information.
https://p-x9.github.io/MachOKit/documentation/machokit/
MIT License
74 stars 5 forks source link

[dyld cache] Consider the actual size of header #125

Open p-x9 opened 2 hours ago

p-x9 commented 2 hours ago

The contents of the dyld_cache_header changes with each dyld version and its size. Therefore, when analysing different versions of the dyld cache, there may be cases where incorrect values are obtained by using properties of the header that should not exist.

The actual size of the header can be obtained from dyld_cache_header.mappingOffset. (dyld_cache_mapping_info exists after the header.)

Example: https://github.com/apple-oss-distributions/dyld/blob/65bbeed63cec73f313b1d636e63f243964725a9d/common/DyldSharedCache.cpp#L562

We would like to improve the use of header properties that seem to have been added relatively recently, using the above method to check whether they actually exist or not before using them.

p-x9 commented 2 hours ago

The following properties also require improvement

https://github.com/p-x9/MachOKit/blob/351aaae2e77d8ca148a2086d56c698403ce3a9e3/Sources/MachOKit/DyldCache.swift#L16-L18