Skip to content

Commit

Permalink
chore: make file.go GetCStrings return a map of maps to allow for sto…
Browse files Browse the repository at this point in the history
…ring different sections cstrings together
  • Loading branch information
blacktop committed Jul 15, 2024
1 parent 8c62f51 commit 31c603e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -1645,20 +1645,24 @@ func (f *File) GetCString(addr uint64) (string, error) {
return "", fmt.Errorf("string not found at address %#x", addr)
}

func (f *File) GetCStrings() (map[uint64]string, error) {
strs := make(map[uint64]string)
func (f *File) GetCStrings() (map[string]map[string]uint64, error) {
strs := make(map[string]map[string]uint64)

for _, sec := range f.Sections {
if sec.Flags.IsCstringLiterals() && sec.Name == "__cstring" {
if sec.Flags.IsCstringLiterals() || sec.Name == "__os_log" {
off, err := f.GetOffset(sec.Addr)
if err != nil {
return nil, fmt.Errorf("failed to get offset for %s.%s: %v", sec.Seg, sec.Name, err)
}
dat := make([]byte, sec.Size)
if _, err = f.ReadAt(dat, int64(off)); err != nil {
return nil, fmt.Errorf("failed to read cstring data in %s.%s: %v", sec.Seg, sec.Name, err)

}

section := fmt.Sprintf("%s.%s", sec.Seg, sec.Name)
strs[section] = make(map[string]uint64)

csr := bytes.NewBuffer(dat)

for {
Expand All @@ -1682,7 +1686,7 @@ func (f *File) GetCStrings() (map[uint64]string, error) {
continue // skip non-ascii strings
}
}
strs[pos] = s
strs[section][s] = pos
}
}
}
Expand Down

0 comments on commit 31c603e

Please # to comment.