Skip to content

Commit

Permalink
feat: out objc class ivars
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Oct 29, 2020
1 parent 5dff601 commit e2404e8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
20 changes: 16 additions & 4 deletions objc.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (f *File) GetCFStrings() ([]objc.CFString, error) {
}
}

return nil, fmt.Errorf("file does not contain a __objc_catlist section")
return nil, fmt.Errorf("file does not contain a __DATA.__cfstring section")
}

func (f *File) GetObjCProtocols() ([]objc.Protocol, error) {
Expand Down Expand Up @@ -691,6 +691,17 @@ func (f *File) GetObjCIvars(vmAddr uint64) ([]objc.Ivar, error) {
}

for _, ivar := range ivs {
off, err := f.GetOffset(f.convertToVMAddr(uint64(ivar.Offset)))
if err != nil {
return nil, fmt.Errorf("failed to convert vmaddr: %v", err)
}

f.sr.Seek(int64(off), io.SeekStart)

var o uint32
if err := binary.Read(f.sr, f.ByteOrder, &o); err != nil {
return nil, fmt.Errorf("failed to read ivar.offset: %v", err)
}
n, err := f.GetCString(f.convertToVMAddr(uint64(ivar.NameVMAddr)))
if err != nil {
return nil, fmt.Errorf("failed to read cstring: %v", err)
Expand All @@ -700,9 +711,10 @@ func (f *File) GetObjCIvars(vmAddr uint64) ([]objc.Ivar, error) {
return nil, fmt.Errorf("failed to read cstring: %v", err)
}
ivars = append(ivars, objc.Ivar{
Name: n,
Type: t,
IvarT: ivar,
Name: n,
Type: t,
Offset: o,
IvarT: ivar,
})
}

Expand Down
22 changes: 18 additions & 4 deletions types/objc/objc.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ func (c *Class) String() string {
if len(c.InstanceMethods) == 0 {
iMethods = ""
}
iVars := " // instance variables\n"
for _, ivar := range c.Ivars {
iVars += fmt.Sprintf(" %s\n", &ivar)
}
if len(c.Ivars) == 0 {
iVars = ""
}
var subClass string
if c.ReadOnlyData.Flags.IsRoot() {
subClass = "<ROOT>"
Expand All @@ -378,12 +385,13 @@ func (c *Class) String() string {
}
return fmt.Sprintf(
"0x%011x %s : %s\n"+
"%s"+
"%s",
c.ClassPtr.VMAdder,
c.Name,
subClass,
iMethods,
)
iVars,
iMethods)
}

type ObjcClassT struct {
Expand Down Expand Up @@ -497,7 +505,13 @@ type IvarT struct {
}

type Ivar struct {
Name string
Type string
Name string
Type string
Offset uint32
IvarT
}

func (i *Ivar) String() string {
return fmt.Sprintf("+%#02x %s %s (%#x)", i.Offset, i.Type, i.Name, i.Size)
// return fmt.Sprintf("+%#02x %s %s (%#x)", i.Offset, getReturnType(i.Type), i.Name, i.Size)
}

0 comments on commit e2404e8

Please sign in to comment.