Skip to content

Commit

Permalink
fix: objc class superclass and isa bind lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Apr 19, 2024
1 parent d2793fe commit 9391308
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
48 changes: 48 additions & 0 deletions objc.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,18 @@ func (f *File) GetObjCClass(vmaddr uint64) (*objc.Class, error) {
f.PutObjC(classPtr.SuperclassVMAddr, superClass)
}
}
} else {
bind, err := f.GetBindName(vmaddr + uint64(unsafe.Offsetof(classPtr.SuperclassVMAddr)))
if err != nil {
return nil, fmt.Errorf("failed to read super class objc_class_t at vmaddr: %#x; %v", vmaddr, err)
}
if info.Flags.IsRoot() {
superClass = &objc.Class{Name: bind}
} else if info.Flags.IsMeta() {
superClass = &objc.Class{Name: strings.TrimPrefix(bind, "_OBJC_METACLASS_$_")}
} else {
superClass = &objc.Class{Name: strings.TrimPrefix(bind, "_OBJC_CLASS_$_")}
}
}

isaClass := &objc.Class{}
Expand Down Expand Up @@ -494,6 +506,18 @@ func (f *File) GetObjCClass(vmaddr uint64) (*objc.Class, error) {
f.PutObjC(classPtr.IsaVMAddr, isaClass)
}
}
} else {
bind, err := f.GetBindName(vmaddr + uint64(unsafe.Offsetof(classPtr.IsaVMAddr)))
if err != nil {
return nil, fmt.Errorf("failed to read super class objc_class_t at vmaddr: %#x; %v", vmaddr, err)
}
if info.Flags.IsRoot() {
isaClass = &objc.Class{Name: bind}
} else if info.Flags.IsMeta() {
isaClass = &objc.Class{Name: strings.TrimPrefix(bind, "_OBJC_METACLASS_$_")}
} else {
isaClass = &objc.Class{Name: strings.TrimPrefix(bind, "_OBJC_CLASS_$_")}
}
}

return &objc.Class{
Expand Down Expand Up @@ -623,6 +647,18 @@ func (f *File) GetObjCClass2(vmaddr uint64) (*objc.Class, error) {
f.PutObjC(classPtr.SuperclassVMAddr, superClass)
}
}
} else {
bind, err := f.GetBindName(vmaddr + uint64(unsafe.Offsetof(classPtr.SuperclassVMAddr)))
if err != nil {
return nil, fmt.Errorf("failed to read super class objc_class_t at vmaddr: %#x; %v", vmaddr, err)
}
if info.Flags.IsRoot() {
superClass = &objc.Class{Name: bind}
} else if info.Flags.IsMeta() {
superClass = &objc.Class{Name: strings.TrimPrefix(bind, "_OBJC_METACLASS_$_")}
} else {
superClass = &objc.Class{Name: strings.TrimPrefix(bind, "_OBJC_CLASS_$_")}
}
}

isaClass := &objc.Class{}
Expand Down Expand Up @@ -653,6 +689,18 @@ func (f *File) GetObjCClass2(vmaddr uint64) (*objc.Class, error) {
f.PutObjC(classPtr.IsaVMAddr, isaClass)
}
}
} else {
bind, err := f.GetBindName(vmaddr + uint64(unsafe.Offsetof(classPtr.IsaVMAddr)))
if err != nil {
return nil, fmt.Errorf("failed to read super class objc_class_t at vmaddr: %#x; %v", vmaddr, err)
}
if info.Flags.IsRoot() {
isaClass = &objc.Class{Name: bind}
} else if info.Flags.IsMeta() {
isaClass = &objc.Class{Name: strings.TrimPrefix(bind, "_OBJC_METACLASS_$_")}
} else {
isaClass = &objc.Class{Name: strings.TrimPrefix(bind, "_OBJC_CLASS_$_")}
}
}

return &objc.Class{
Expand Down
16 changes: 16 additions & 0 deletions types/objc/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ func (f ClassRoFlags) HasCxxStructors() bool {
func (f ClassRoFlags) HasFuture() bool {
return (f & RO_FUTURE) != 0
}
func (f ClassRoFlags) String() string {
var out []string
if f.IsMeta() {
out = append(out, "META")
}
if f.IsRoot() {
out = append(out, "ROOT")
}
if f.HasCxxStructors() {
out = append(out, "HAS_CXX_STRUCTORS")
}
if f.HasFuture() {
out = append(out, "FUTURE")
}
return strings.Join(out, " | ")
}

type ClassRO struct {
Flags ClassRoFlags
Expand Down

0 comments on commit 9391308

Please sign in to comment.