Skip to content

Commit

Permalink
fix: ipsw symbolicate command and only support bug_type 109, 210 an…
Browse files Browse the repository at this point in the history
…d 309 for now
  • Loading branch information
blacktop committed Mar 22, 2024
1 parent e86c8fe commit 034f4f8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 19 deletions.
20 changes: 17 additions & 3 deletions cmd/ipsw/cmd/symbolicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func init() {

// symbolicateCmd represents the symbolicate command
var symbolicateCmd = &cobra.Command{
Use: "symbolicate <CRASHLOG> <DSC>",
Use: "symbolicate <CRASHLOG> [IPSW|DSC]",
Aliases: []string{"sym"},
Short: "Symbolicate ARM 64-bit crash logs (similar to Apple's symbolicatecrash)",
Args: cobra.MinimumNArgs(1),
Expand All @@ -61,16 +61,28 @@ var symbolicateCmd = &cobra.Command{
// cacheFile, _ := cmd.Flags().GetString("cache")
demangleFlag, _ := cmd.Flags().GetBool("demangle")

if ips, err := crashlog.OpenIPS(args[0]); err == nil { // NEW JSON STYLE CRASHLOG
hdr, err := crashlog.ParseHeader(args[0])
if err != nil {
return err
}

switch hdr.BugType {
case "210", "309": // NEW JSON STYLE CRASHLOG
ips, err := crashlog.OpenIPS(args[0])
if err != nil {
return fmt.Errorf("failed to parse IPS file: %v", err)
}

if len(args) < 2 {
log.Warnf("please supply %s %s IPSW for symbolication", ips.Payload.Product, ips.Header.OsVersion)
} else {
if err := ips.Symbolicate(filepath.Clean(args[1])); err != nil {
return err
}
}

fmt.Println(ips)
} else { // OLD STYLE CRASHLOG
case "109": // OLD STYLE CRASHLOG
crashLog, err := crashlog.Open(args[0])
if err != nil {
return err
Expand Down Expand Up @@ -229,6 +241,8 @@ var symbolicateCmd = &cobra.Command{
} else {
log.Errorf("please supply a dyld_shared_cache for %s running %s (%s)", crashLog.HardwareModel, crashLog.OSVersion, crashLog.OSBuild)
}
default:
log.Errorf("unsupported crashlog type: %s - %s (notify author to add support)", hdr.BugType, hdr.BugTypeDesc)
}

return nil
Expand Down
59 changes: 43 additions & 16 deletions pkg/crashlog/ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ type IpsMetadata struct {
AppName string `json:"app_name,omitempty"`
AppVersion string `json:"app_version,omitempty"`
BugType string `json:"bug_type,omitempty"`
BugTypeDesc string `json:"bug_type_desc,omitempty"`
OsVersion string `json:"os_version,omitempty"`
BundleID string `json:"bundleID,omitempty"`
BuildVersion string `json:"build_version,omitempty"`
Expand Down Expand Up @@ -194,7 +195,7 @@ type Process struct {
CopyOnWriteFaults int `json:"copyOnWriteFaults"`
PageFaults int `json:"pageFaults"`
UserTimeTask float64 `json:"userTimeTask"`
SystemTimeTask int `json:"systemTimeTask"`
SystemTimeTask float64 `json:"systemTimeTask"`
Flags []string `json:"flags"`
ResidentMemoryBytes int `json:"residentMemoryBytes"`
ThreadByID map[int]Thread `json:"threadById,omitempty"`
Expand Down Expand Up @@ -324,7 +325,7 @@ func fmtAddrSmol(val uint64) string {
if val == 0 {
return colorAddr("%#08x", val)
}
return fmt.Sprintf("%#016x", val)
return fmt.Sprintf("%#08x", val)
}

func (s ThreadState) String() string {
Expand All @@ -337,8 +338,8 @@ func (s ThreadState) String() string {
" x20: %s x21: %s x22: %s x23: %s\n"+
" x24: %s x25: %s x26: %s x27: %s\n"+
" x28: %s fp: %s lr: %s\n"+
" sp: %s pc: %s cpsr: %#08x\n"+
" esr: %#08x\n",
" sp: %s pc: %s cpsr: %s\n"+
" esr: %s\n",
fmtAddr(s.X[0].Value), fmtAddr(s.X[1].Value), fmtAddr(s.X[2].Value), fmtAddr(s.X[3].Value),
fmtAddr(s.X[4].Value), fmtAddr(s.X[5].Value), fmtAddr(s.X[6].Value), fmtAddr(s.X[7].Value),
fmtAddr(s.X[8].Value), fmtAddr(s.X[9].Value), fmtAddr(s.X[10].Value), fmtAddr(s.X[11].Value),
Expand Down Expand Up @@ -492,6 +493,32 @@ type IPSPayload struct {
Termination Termination `json:"termination,omitempty"`
}

func ParseHeader(in string) (hdr *IpsMetadata, err error) {
f, err := os.Open(in)
if err != nil {
return nil, err
}
defer f.Close()

if err := json.NewDecoder(f).Decode(&hdr); err != nil {
return nil, err
}

db, err := GetLogTypes()
if err != nil {
return nil, fmt.Errorf("failed to get log types database: %w", err)
}

if bt, ok := (*db)[hdr.BugType]; ok {
hdr.BugTypeDesc = bt.Name
if len(bt.Comment) > 0 {
hdr.BugTypeDesc = hdr.BugType + " (" + bt.Comment + ")"
}
}

return hdr, nil
}

func OpenIPS(in string) (*Ips, error) {
var ips Ips

Expand All @@ -514,22 +541,22 @@ func OpenIPS(in string) (*Ips, error) {
ips.Payload.Product = ips.Payload.ModelCode
}

return &ips, nil
}

func (i *Ips) Symbolicate(ipswPath string) error {
db, err := GetLogTypes()
if err != nil {
return fmt.Errorf("failed to get log types: %w", err)
return nil, fmt.Errorf("failed to get log types database: %w", err)
}

if bt, ok := (*db)[i.Header.BugType]; ok {
i.Header.BugType = bt.Name
if bt, ok := (*db)[ips.Header.BugType]; ok {
ips.Header.BugTypeDesc = bt.Name
if len(bt.Comment) > 0 {
i.Header.BugType += " (" + bt.Comment + ")"
ips.Header.BugTypeDesc = ips.Header.BugType + " (" + bt.Comment + ")"
}
}

return &ips, nil
}

func (i *Ips) Symbolicate(ipswPath string) error {
total := len(i.Payload.BinaryImages)

// add default binary image names
Expand Down Expand Up @@ -674,8 +701,8 @@ func (i *Ips) String() string {
var out string

switch i.Header.BugType {
case "151", "Panic", "210":
out = fmt.Sprintf("[%s] - %s - %s %s\n\n", colorTime(i.Header.Timestamp.Format("02Jan2006 15:04:05")), colorError(i.Header.BugType), i.Payload.Product, i.Payload.Build)
case "Panic", "210":
out = fmt.Sprintf("[%s] - %s - %s %s\n\n", colorTime(i.Header.Timestamp.Format("02Jan2006 15:04:05")), colorError(i.Header.BugTypeDesc), i.Payload.Product, i.Payload.Build)
out += i.Payload.PanicString
out += i.Payload.OtherString + "\n"
var pids []int
Expand Down Expand Up @@ -730,8 +757,8 @@ func (i *Ips) String() string {
}
out += "\n"
}
case "109", "Crash", "309", "327", "385":
out = fmt.Sprintf("[%s] - %s\n\n", colorTime(i.Header.Timestamp.Format("02Jan2006 15:04:05")), colorError(i.Header.BugType))
case "Crash", "309":
out = fmt.Sprintf("[%s] - %s\n\n", colorTime(i.Header.Timestamp.Format("02Jan2006 15:04:05")), colorError(i.Header.BugTypeDesc))
out += fmt.Sprintf(
colorField("Process:")+" %s [%d]\n"+
colorField("Hardware Model:")+" %s\n"+
Expand Down

0 comments on commit 034f4f8

Please sign in to comment.