Skip to content

Commit

Permalink
feat: add mig to ipsw kernel symbolication
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Jul 25, 2024
1 parent c21208d commit 8b558b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/kernelcache/mig.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type MigKernSubsystem struct {
Routines []KernRoutineDescriptor /* Kernel routine descriptor array */
}

func (m MigKernSubsystem) LookupRoutineName(SubsystemStart, idx int) string {
func (m MigKernSubsystem) LookupRoutineName(idx int) string {
switch m.Start {
case mach_vm_subsystem:
if idx >= len(machVmSubsystemFuncs) {
Expand Down Expand Up @@ -216,7 +216,7 @@ func (m MigKernSubsystem) String() string {
continue // skip empty routines
}
out += fmt.Sprintf(" %s: ", colorAddr("%#x", r.KStubRoutine))
out += colorBold(m.LookupRoutineName(int(m.Start), idx))
out += colorBold(m.LookupRoutineName(idx))
out += fmt.Sprintf("\t%s=%#x %s=%02d %s=%d %s=%d %s=%d\n",
colorName("impl"), r.ImplRoutine,
colorName("argc"), r.ArgC,
Expand Down
23 changes: 23 additions & 0 deletions pkg/signature/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,26 @@ func (sm SymbolMap) getMachTraps(m *macho.File) error {
return nil
}

func (sm SymbolMap) getMig(m *macho.File) error {
migs, err := kernelcache.GetMigSubsystems(m)
if err != nil {
return fmt.Errorf("failed to get mach trap table: %v", err)
}

for _, mig := range migs {
if err := sm.Add(mig.KServer, strings.TrimSuffix(mig.Start.String(), "_subsystem")+"_server_routine"); err != nil {
utils.Indent(log.WithError(err).Debug, 2)("Adding mig server_routine")
}
for idx, routine := range mig.Routines {
if err := sm.Add(routine.KStubRoutine, mig.LookupRoutineName(idx)); err != nil {
utils.Indent(log.WithError(err).Debug, 2)("Adding mig routine")
}
}
}

return nil
}

func (sm SymbolMap) Symbolicate(infile string, sigs []Symbolicator, quiet bool) error {
kc, err := macho.Open(infile)
if err != nil {
Expand All @@ -261,6 +281,9 @@ func (sm SymbolMap) Symbolicate(infile string, sigs []Symbolicator, quiet bool)
if err := sm.getMachTraps(kc); err != nil {
return err
}
if err := sm.getMig(kc); err != nil {
return err
}

goodsig := false

Expand Down

0 comments on commit 8b558b5

Please sign in to comment.