Skip to content

Commit

Permalink
fix: minor fix to ipsw dyld symaddr
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Dec 2, 2021
1 parent 229ed12 commit 450e597
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 38 deletions.
40 changes: 2 additions & 38 deletions cmd/ipsw/cmd/dyld_symaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ var symaddrCmd = &cobra.Command{
for _, bind := range binds {
if bind.Name == args[1] {
fmt.Fprintf(w, "%#09x:\t(%s.%s|from %s)\t%s\t%s\n", bind.Start+bind.Offset, bind.Segment, bind.Section, bind.Dylib, bind.Name, image.Name)

if !allMatches {
w.Flush()
return nil
Expand Down Expand Up @@ -241,35 +242,11 @@ var symaddrCmd = &cobra.Command{
fmt.Fprintf(w, "%s\n", sym)
}
w.Flush()
binds, err := m.GetBindInfo()
if err != nil {
return err
}
for _, bind := range binds {
fmt.Fprintf(w, "%#09x:\t(%s.%s|from %s)\t%s\n", bind.Start+bind.Offset, bind.Segment, bind.Section, bind.Dylib, bind.Name)
}
w.Flush()

// Dump ALL public symbols for a dylib
log.Warn("parsing exported symbols for image...")
if err := f.GetAllExportedSymbolsForImage(i, true); err != nil {
log.Error(err.Error())

log.Warn("falling back to MachO symtab")
m, err := i.GetMacho()
if err != nil {
return err
}

var sec string
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.Debug)
for _, sym := range m.Symtab.Syms {
if sym.Sect > 0 && int(sym.Sect) <= len(m.Sections) {
sec = fmt.Sprintf("%s.%s", m.Sections[sym.Sect-1].Seg, m.Sections[sym.Sect-1].Name)
}
fmt.Fprintf(w, "%#09x:\t(%s)\t%s\n", sym.Value, sym.Type.String(sec), sym.Name)
}
w.Flush()
log.Errorf("failed to get all exported symbols for image %s: %v", imageName, err)
}

return nil
Expand Down Expand Up @@ -300,19 +277,6 @@ var symaddrCmd = &cobra.Command{
sym.Sections = m.Sections
fmt.Fprintf(w, "%s\n", sym)
}
binds, err := m.GetBindInfo()
if err != nil {
return err
}
for _, bind := range binds {
if bind.Name == args[1] {
fmt.Fprintf(w, "%#09x:\t(%s.%s|from %s)\t%s\t%s\n", bind.Start+bind.Offset, bind.Segment, bind.Section, bind.Dylib, bind.Name, image.Name)
if !allMatches {
w.Flush()
return nil
}
}
}
w.Flush()
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/dyld/symbols.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,19 @@ func (f *File) GetAllExportedSymbols(dump bool) error {
}
}
w.Flush()

binds, err := m.GetBindInfo()
if err != nil {
return err
}
for _, bind := range binds {
if dump {
fmt.Fprintf(w, "%#09x:\t(%s.%s|from %s)\t%s\n", bind.Start+bind.Offset, bind.Segment, bind.Section, bind.Dylib, bind.Name)
} else {
f.AddressToSymbol[bind.Start+bind.Offset] = bind.Name
}
}
w.Flush()
} else {
return err
}
Expand Down Expand Up @@ -437,6 +450,7 @@ func (f *File) GetAllExportedSymbolsForImage(image *CacheImage, dump bool) error
f.AddressToSymbol[sym.Value] = sym.Name
}
}
w.Flush()
binds, err := m.GetBindInfo()
if err != nil {
return err
Expand Down

0 comments on commit 450e597

Please sign in to comment.