Skip to content

Commit

Permalink
feat: add fileset getters
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Dec 4, 2020
1 parent 62d7d61 commit bef7db6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
23 changes: 23 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,29 @@ func (f *File) BuildVersion() *BuildVersion {
return nil
}

// FileSets returns an array of Fileset entries.
func (f *File) FileSets() []*FilesetEntry {
var fsets []*FilesetEntry
for _, l := range f.Loads {
if fs, ok := l.(*FilesetEntry); ok {
fsets = append(fsets, fs)
}
}
return fsets
}

// GetFileSetFileByName returns the Fileset MachO for a given name.
func (f *File) GetFileSetFileByName(name string) (*File, error) {
for _, l := range f.Loads {
if fs, ok := l.(*FilesetEntry); ok {
if strings.Contains(strings.ToLower(fs.EntryID), strings.ToLower(name)) {
return NewFile(io.NewSectionReader(f.sr, int64(fs.Offset), 1<<63-1))
}
}
}
return nil, fmt.Errorf("fileset does NOT contain %s", name)
}

// FunctionStarts returns the function starts array, or nil if none exists.
func (f *File) FunctionStarts() *FunctionStarts {
for _, l := range f.Loads {
Expand Down
60 changes: 29 additions & 31 deletions objc.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,41 +393,39 @@ func (f *File) GetCFStrings() ([]objc.CFString, error) {
var cfstrings []objc.CFString

for _, s := range f.Segments() {
if strings.HasPrefix(s.Name, "__DATA") {
if sec := f.Section(s.Name, "__cfstring"); sec != nil {
dat, err := sec.Data()
if err != nil {
return nil, fmt.Errorf("failed to read __cfstring: %v", err)
}
if sec := f.Section(s.Name, "__cfstring"); sec != nil {
dat, err := sec.Data()
if err != nil {
return nil, fmt.Errorf("failed to read __cfstring: %v", err)
}

cfstrings = make([]objc.CFString, int(sec.Size)/binary.Size(objc.CFString64T{}))
cfStrTypes := make([]objc.CFString64T, int(sec.Size)/binary.Size(objc.CFString64T{}))
if err := binary.Read(bytes.NewReader(dat), f.ByteOrder, &cfStrTypes); err != nil {
return nil, fmt.Errorf("failed to read cfstring64_t structs: %v", err)
}
cfstrings = make([]objc.CFString, int(sec.Size)/binary.Size(objc.CFString64T{}))
cfStrTypes := make([]objc.CFString64T, int(sec.Size)/binary.Size(objc.CFString64T{}))
if err := binary.Read(bytes.NewReader(dat), f.ByteOrder, &cfStrTypes); err != nil {
return nil, fmt.Errorf("failed to read cfstring64_t structs: %v", err)
}

for idx, cfstr := range cfStrTypes {
cfstrings[idx].CFString64T = &cfstr
if cfstr.Data == 0 {
return nil, fmt.Errorf("unhandled cstring parse case where data is 0")
// uint64_t n_value;
// const char *symbol_name = get_symbol_64(offset + offsetof(struct cfstring64_t, characters), S, info, n_value);
// if (symbol_name == nullptr)
// return nullptr;
// cfs_characters = n_value;
}
cfstrings[idx].Name, err = f.GetCString(f.convertToVMAddr(cfstr.Data))
if err != nil {
return nil, fmt.Errorf("failed to read cstring: %v", err)
}
cfstrings[idx].Address = sec.Addr + uint64(idx*binary.Size(objc.CFString64T{}))
if err != nil {
return nil, fmt.Errorf("failed to calulate cfstring vmaddr: %v", err)
}
for idx, cfstr := range cfStrTypes {
cfstrings[idx].CFString64T = &cfstr
if cfstr.Data == 0 {
return nil, fmt.Errorf("unhandled cstring parse case where data is 0")
// uint64_t n_value;
// const char *symbol_name = get_symbol_64(offset + offsetof(struct cfstring64_t, characters), S, info, n_value);
// if (symbol_name == nullptr)
// return nullptr;
// cfs_characters = n_value;
}
cfstrings[idx].Name, err = f.GetCString(f.convertToVMAddr(cfstr.Data))
if err != nil {
return nil, fmt.Errorf("failed to read cstring: %v", err)
}
cfstrings[idx].Address = sec.Addr + uint64(idx*binary.Size(objc.CFString64T{}))
if err != nil {
return nil, fmt.Errorf("failed to calulate cfstring vmaddr: %v", err)
}

return cfstrings, nil
}

return cfstrings, nil
}
}

Expand Down

0 comments on commit bef7db6

Please sign in to comment.