Skip to content

Commit

Permalink
fix: objc selector parsing for image #60
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Dec 18, 2021
1 parent 3e53f9b commit a467b30
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 124 deletions.
24 changes: 3 additions & 21 deletions cmd/ipsw/cmd/dyld_a2s.go
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/apex/log"
"github.com/blacktop/ipsw/internal/utils"
"github.com/blacktop/ipsw/pkg/dyld"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -81,7 +80,7 @@ var a2sCmd = &cobra.Command{
if fileInfo.Mode()&os.ModeSymlink != 0 {
symlinkPath, err := os.Readlink(dscPath)
if err != nil {
return errors.Wrapf(err, "failed to read symlink %s", dscPath)
return fmt.Errorf("failed to read symlink %s", dscPath)
}
// TODO: this seems like it would break
linkParent := filepath.Dir(dscPath)
Expand Down Expand Up @@ -208,27 +207,10 @@ var a2sCmd = &cobra.Command{
return err
}

// TODO: add objc methods in the -[Class sel:] form
if m.HasObjC() {
log.Debug("Parsing ObjC runtime structures...")
if err := f.CFStringsForImage(image.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc cfstrings")
}
if err := f.MethodsForImage(image.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc methods")
}
// if strings.Contains(image.Name, "libobjc.A.dylib") { // TODO: should I put this back in?
// _, err = f.GetAllSelectors(false)
// } else {
if err := f.SelectorsForImage(image.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc selectors")
}
// }
if err := f.ClassesForImage(image.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc classes")
}
if err := f.ProtocolsForImage(image.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc protocols")
if err := f.ParseObjcForImage(image.Name); err != nil {
return fmt.Errorf("failed to parse objc data for image %s: %v", image.Name, err)
}
}

Expand Down
21 changes: 2 additions & 19 deletions cmd/ipsw/cmd/dyld_disass.go
Expand Up @@ -278,25 +278,8 @@ var dyldDisassCmd = &cobra.Command{

if m.HasObjC() {
log.Info("Parsing ObjC runtime structures...")
if err := f.CFStringsForImage(image.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc cfstrings")
}
if err := f.MethodsForImage(image.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc methods")
}
if strings.Contains(image.Name, "libobjc.A.dylib") {
_, err = f.GetAllSelectors(false)
} else {
err = f.SelectorsForImage(image.Name)
}
if err != nil {
return errors.Wrapf(err, "failed to parse objc selectors")
}
if err := f.ClassesForImage(image.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc classes")
}
if err := f.ProtocolsForImage(image.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc protocols")
if err := f.ParseObjcForImage(image.Name); err != nil {
return fmt.Errorf("failed to parse objc data for image %s: %v", image.Name, err)
}
}

Expand Down
8 changes: 3 additions & 5 deletions cmd/ipsw/cmd/dyld_objc_sel.go
Expand Up @@ -87,9 +87,8 @@ var objcSelCmd = &cobra.Command{
fmt.Printf("0x%x: %s\n", ptr, args[1])
} else {
if len(imageName) > 0 {
err = f.SelectorsForImage(imageName)
if err != nil {
return err
if err := f.SelectorsForImage(imageName); err != nil {
return fmt.Errorf("failed to parse objc selectors for image %s: %v", imageName, err)
}

// sort by address
Expand All @@ -104,8 +103,7 @@ var objcSelCmd = &cobra.Command{
}

} else {
_, err := f.GetAllSelectors(true)
if err != nil {
if _, err := f.GetAllSelectors(true); err != nil {
return err
}
}
Expand Down
16 changes: 2 additions & 14 deletions cmd/ipsw/cmd/dyld_xref.go
Expand Up @@ -148,20 +148,8 @@ var xrefCmd = &cobra.Command{

if m.HasObjC() {
log.Debug("Parsing ObjC runtime structures...")
if err := f.CFStringsForImage(img.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc cfstrings")
}
if err := f.MethodsForImage(img.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc methods")
}
if err := f.SelectorsForImage(img.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc selectors")
}
if err := f.ClassesForImage(img.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc classes")
}
if err := f.ProtocolsForImage(img.Name); err != nil {
return errors.Wrapf(err, "failed to parse objc protocols")
if err := f.ParseObjcForImage(img.Name); err != nil {
return fmt.Errorf("failed to parse objc data for image %s: %v", img.Name, err)
}
}

Expand Down
24 changes: 3 additions & 21 deletions cmd/ipsw/cmd/symbolicate.go
Expand Up @@ -25,7 +25,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"text/tabwriter"

"github.com/apex/log"
Expand Down Expand Up @@ -78,7 +77,7 @@ var symbolicateCmd = &cobra.Command{
if fileInfo.Mode()&os.ModeSymlink != 0 {
symlinkPath, err := os.Readlink(dscPath)
if err != nil {
return errors.Wrapf(err, "failed to read symlink %s", dscPath)
return fmt.Errorf("failed to read symlink %s: %v", dscPath, err)
}
// TODO: this seems like it would break
linkParent := filepath.Dir(dscPath)
Expand Down Expand Up @@ -180,25 +179,8 @@ var symbolicateCmd = &cobra.Command{
}

if m.HasObjC() {
err = f.CFStringsForImage(image.Name)
if err != nil {
return errors.Wrapf(err, "failed to parse objc cfstrings")
}
err = f.MethodsForImage(image.Name)
if err != nil {
return errors.Wrapf(err, "failed to parse objc methods")
}
if strings.Contains(image.Name, "libobjc.A.dylib") {
_, err = f.GetAllSelectors(false)
} else {
err = f.SelectorsForImage(image.Name)
}
if err != nil {
return errors.Wrapf(err, "failed to parse objc selectors")
}
err = f.ClassesForImage(image.Name)
if err != nil {
return errors.Wrapf(err, "failed to parse objc classes")
if err := f.ParseObjcForImage(image.Name); err != nil {
return fmt.Errorf("failed to parse objc data for image %s: %v", image.Name, err)
}
}

Expand Down

0 comments on commit a467b30

Please sign in to comment.