Skip to content

Commit

Permalink
chore: correct some iOS18/macOS15 field names
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Oct 1, 2024
1 parent 9103370 commit 2358ce3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 48 deletions.
4 changes: 2 additions & 2 deletions pkg/dyld/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ func (f *File) parseCache(r io.ReaderAt, uuid mtypes.UUID) error {

if f.Headers[uuid].MappingOffset >= 0x208 {
// read TPRO mapping info
sr.Seek(int64(f.Headers[uuid].TPROMappingOffset), io.SeekStart)
f.TPROMappings = make([]TPROMapping, f.Headers[uuid].TPROMappingCount)
sr.Seek(int64(f.Headers[uuid].TPROMappingsOffset), io.SeekStart)
f.TPROMappings = make([]TPROMapping, f.Headers[uuid].TPROMappingsCount)
if err := binary.Read(sr, f.ByteOrder, f.TPROMappings); err != nil {
return fmt.Errorf("failed to read DSC TPRO mappings (new in iOS18.0beta1): %v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/dyld/prebuilt.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (f *File) parsePrebuiltLoaderSet(sr *io.SectionReader) (*PrebuiltLoaderSet,
}
}
// FIXME: when dyld src is out for iOS 18.0/macOS 15.0
if pset.ObjcSelectorHashTableOffset > 0 && !pset.Loaders[0].Loader.IsVersion2() {
if pset.ObjcSelectorHashTableOffset > 0 && !pset.Loaders[0].Loader.HasUUIDLoadCommand() {
sr.Seek(int64(pset.ObjcSelectorHashTableOffset), io.SeekStart)
var o ObjCSelectorOpt
if err := binary.Read(sr, f.ByteOrder, &o.objCStringTable); err != nil {
Expand All @@ -276,7 +276,7 @@ func (f *File) parsePrebuiltLoaderSet(sr *io.SectionReader) (*PrebuiltLoaderSet,
pset.SelectorTable = &o
}
// FIXME: when dyld src is out for iOS 18.0/macOS 15.0
if pset.ObjcClassHashTableOffset > 0 && !pset.Loaders[0].Loader.IsVersion2() {
if pset.ObjcClassHashTableOffset > 0 && !pset.Loaders[0].Loader.HasUUIDLoadCommand() {
sr.Seek(int64(pset.ObjcClassHashTableOffset), io.SeekStart)
var o ObjCClassOpt
if err := binary.Read(sr, f.ByteOrder, &o.objCStringTable); err != nil {
Expand Down Expand Up @@ -311,7 +311,7 @@ func (f *File) parsePrebuiltLoaderSet(sr *io.SectionReader) (*PrebuiltLoaderSet,
pset.ClassTable = &o
}
// FIXME: when dyld src is out for iOS 18.0/macOS 15.0
if pset.ObjcProtocolHashTableOffset > 0 && !pset.Loaders[0].Loader.IsVersion2() {
if pset.ObjcProtocolHashTableOffset > 0 && !pset.Loaders[0].Loader.HasUUIDLoadCommand() {
sr.Seek(int64(pset.ObjcProtocolHashTableOffset), io.SeekStart)
var o ObjCClassOpt
if err := binary.Read(sr, f.ByteOrder, &o.objCStringTable); err != nil {
Expand Down Expand Up @@ -431,7 +431,7 @@ func (f *File) parsePrebuiltLoader(sr *io.SectionReader) (*PrebuiltLoader, error
return nil, fmt.Errorf("failed to read prebuilt loader: %v", err)
}

if pbl.Loader.IsVersion2() {
if pbl.Loader.HasUUIDLoadCommand() {
if err := binary.Read(sr, binary.LittleEndian, &pbl.UUID); err != nil {
return nil, fmt.Errorf("failed to read prebuilt loader uuid: %v", err)
}
Expand Down
62 changes: 36 additions & 26 deletions pkg/dyld/prebuilt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ type Loader struct {
// hasReadOnlyObjC : 1, // Has __DATA_CONST,__objc_selrefs section
// pre2022Binary : 1,
// isPremapped : 1, // mapped by exclave core
// isVersion2 : 1, // FIXME: when dyld src is out for iOS 18.0/macOS 15.0
// unknown1 : 1, // FIXME: when dyld src is out for iOS 18.0/macOS 15.0
// unknown2 : 1, // FIXME: when dyld src is out for iOS 18.0/macOS 15.0
// unknown3 : 1, // FIXME: when dyld src is out for iOS 18.0/macOS 15.0
// padding : 6;
// hasUUIDLoadCommand : 1,
// hasWeakDefs : 1,
// hasTLVs : 1,
// belowLibSystem : 1,
// padding : 2;
Ref LoaderRef
// Unk [12]uint16
}
Expand Down Expand Up @@ -102,16 +102,16 @@ func (l Loader) Pre2022Binary() bool {
func (l Loader) IsPremapped() bool {
return types.ExtractBits(uint64(l.Info), 9, 1) != 0
}
func (l Loader) IsVersion2() bool {
func (l Loader) HasUUIDLoadCommand() bool {
return types.ExtractBits(uint64(l.Info), 10, 1) != 0
}
func (l Loader) Unknown1() bool {
func (l Loader) HasWeakDefs() bool {
return types.ExtractBits(uint64(l.Info), 11, 1) != 0
}
func (l Loader) Unknown2() bool {
func (l Loader) HasTLVs() bool {
return types.ExtractBits(uint64(l.Info), 12, 1) != 0
}
func (l Loader) Unknown3() bool {
func (l Loader) BelowLibSystem() bool {
return types.ExtractBits(uint64(l.Info), 13, 1) != 0
}
func (l Loader) Padding() uint8 {
Expand Down Expand Up @@ -152,17 +152,17 @@ func (l Loader) String() string {
if l.IsPremapped() {
out = append(out, "premapped")
}
if l.IsVersion2() {
out = append(out, "v2")
if l.HasUUIDLoadCommand() {
out = append(out, "uuid-load-cmd")
}
if l.Unknown1() {
out = append(out, "unk1")
if l.HasWeakDefs() {
out = append(out, "weak-defs")
}
if l.Unknown2() {
out = append(out, "unk2")
if l.HasTLVs() {
out = append(out, "tlvs")
}
if l.Unknown3() {
out = append(out, "unk3")
if l.BelowLibSystem() {
out = append(out, "below-libsystem")
}
return fmt.Sprintf("%s, ref: %s", strings.Join(out, "|"), l.Ref)
}
Expand Down Expand Up @@ -312,13 +312,15 @@ func (k RSKind) String() string {
}

type ResolvedSymbol struct {
TargetLoader *Loader
TargetSymbolName string
TargetRuntimeOffset uint64
Kind RSKind
IsCode bool
IsWeakDef bool
IsMissingFlatLazy bool
TargetLoader *Loader
TargetSymbolName string
TargetRuntimeOffset uint64
TargetAddressForDlsym uint64
Kind RSKind
IsCode bool
IsWeakDef bool
IsMissingFlatLazy bool
IsMaterializing bool
}

type BindTarget struct {
Expand Down Expand Up @@ -573,7 +575,8 @@ func (o ObjCBinaryInfo) String() string {
type PrebuiltLoader struct {
Loader
UUID types.UUID
Unknown [2]uint32 // FIXME: when dyld src is out for iOS 18.0/macOS 15.0
CpuSubtype uint32
Unused uint32
Header prebuiltLoaderHeader
Path string
AltPath string
Expand Down Expand Up @@ -710,6 +713,13 @@ func (pl PrebuiltLoader) String(f *File) string {
return out
}

type objCFlags uint32

const (
NoObjCFlags objCFlags = 0
HasDuplicateClasses objCFlags = 1 << 0
)

// PrebuiltLoaderSet is an mmap()ed read-only data structure which holds a set of PrebuiltLoader objects;
// The contained PrebuiltLoader objects can be found be index O(1) or path O(n).
type prebuiltLoaderSetHeader struct {
Expand All @@ -727,7 +737,7 @@ type prebuiltLoaderSetHeader struct {
ObjcSelectorHashTableOffset uint32
ObjcClassHashTableOffset uint32
ObjcProtocolHashTableOffset uint32
Reserved uint32
ObjcFlags objCFlags
ObjcProtocolClassCacheOffset uint64
// Swift prebuilt data
SwiftTypeConformanceTableOffset uint32
Expand Down
32 changes: 16 additions & 16 deletions pkg/dyld/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ type CacheHeader struct {
CacheAtlasSize uint64 // size of embedded cache atlas
DynamicDataOffset uint64 // VM offset from cache_header* to the location of dyld_cache_dynamic_data_header
DynamicDataMaxSize uint64 // maximum size of space reserved from dynamic data
TPROMappingOffset uint32 // file offset to TPRO mappings NEW in iOS 18.0 beta1 (hi mrmacete :P)
TPROMappingCount uint32 // TPRO mappings count NEW in iOS 18.0 beta1 (is 1 for now; protects OBJC_RO)
TPROMappingsOffset uint32 // file offset to first dyld_cache_tpro_mapping_info
TPROMappingsCount uint32 // number of dyld_cache_tpro_mapping_info entries
}

type CacheMappingInfo struct {
Expand All @@ -206,14 +206,14 @@ type CacheMappingInfo struct {
type CacheMappingFlag uint64

const (
DYLD_CACHE_MAPPING_NONE CacheMappingFlag = 0
DYLD_CACHE_MAPPING_AUTH_DATA CacheMappingFlag = 1 << 0
DYLD_CACHE_MAPPING_DIRTY_DATA CacheMappingFlag = 1 << 1
DYLD_CACHE_MAPPING_CONST_DATA CacheMappingFlag = 1 << 2
DYLD_CACHE_MAPPING_TEXT_STUBS CacheMappingFlag = 1 << 3
DYLD_CACHE_DYNAMIC_CONFIG_DATA CacheMappingFlag = 1 << 4
DYLD_CACHE_MAPPING_UNKNOWN CacheMappingFlag = 1 << 5
DYLD_CACHE_MAPPING_TPRO CacheMappingFlag = 1 << 6
DYLD_CACHE_MAPPING_NONE CacheMappingFlag = 0
DYLD_CACHE_MAPPING_AUTH_DATA CacheMappingFlag = 1 << 0
DYLD_CACHE_MAPPING_DIRTY_DATA CacheMappingFlag = 1 << 1
DYLD_CACHE_MAPPING_CONST_DATA CacheMappingFlag = 1 << 2
DYLD_CACHE_MAPPING_TEXT_STUBS CacheMappingFlag = 1 << 3
DYLD_CACHE_DYNAMIC_CONFIG_DATA CacheMappingFlag = 1 << 4
DYLD_CACHE_READ_ONLY_DATA CacheMappingFlag = 1 << 5
DYLD_CACHE_MAPPING_CONST_TPRO_DATA CacheMappingFlag = 1 << 6
)

func (f CacheMappingFlag) IsNone() bool {
Expand All @@ -234,11 +234,11 @@ func (f CacheMappingFlag) IsTextStubs() bool {
func (f CacheMappingFlag) IsConfigData() bool {
return (f & DYLD_CACHE_DYNAMIC_CONFIG_DATA) != 0
}
func (f CacheMappingFlag) IsUnknown() bool {
return (f & DYLD_CACHE_MAPPING_UNKNOWN) != 0
func (f CacheMappingFlag) IsReadOnlyData() bool {
return (f & DYLD_CACHE_READ_ONLY_DATA) != 0
}
func (f CacheMappingFlag) IsTPRO() bool {
return (f & DYLD_CACHE_MAPPING_TPRO) != 0
return (f & DYLD_CACHE_MAPPING_CONST_TPRO_DATA) != 0
}
func (f CacheMappingFlag) String() string {
var fStr []string
Expand All @@ -249,7 +249,7 @@ func (f CacheMappingFlag) String() string {
fStr = append(fStr, "DIRTY_DATA")
}
if f.IsTPRO() {
fStr = append(fStr, "TPRO")
fStr = append(fStr, "CONST_TPRO_DATA")
}
if f.IsConstData() {
fStr = append(fStr, "CONST_DATA")
Expand All @@ -260,8 +260,8 @@ func (f CacheMappingFlag) String() string {
if f.IsConfigData() {
fStr = append(fStr, "CONFIG_DATA")
}
if f.IsUnknown() {
fStr = append(fStr, "UNKNOWN")
if f.IsReadOnlyData() {
fStr = append(fStr, "READ_ONLY_DATA")
}
if len(fStr) > 0 {
return strings.Join(fStr, " | ")
Expand Down

0 comments on commit 2358ce3

Please sign in to comment.