From 98f43c27f6521e7542e5ed31fcfe604d7d1eab78 Mon Sep 17 00:00:00 2001 From: blacktop Date: Mon, 3 Jun 2024 22:39:21 -0600 Subject: [PATCH] fix: LC_UNIXTHREAD cmd output --- cmds.go | 11 ++++++++++- file.go | 3 +++ macho.go | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cmds.go b/cmds.go index 7c90e74..dd6f61d 100644 --- a/cmds.go +++ b/cmds.go @@ -600,11 +600,20 @@ func (t *Thread) String() string { case types.ARM_THREAD_STATE32: var regs RegsARM binary.Read(bytes.NewReader(thread.Data), t.bo, ®s) + if regs.OnlyEntry() { + out = append(out, fmt.Sprintf("%s%s Entry: %#08x", padding, flavor, regs.PC)) + } else { + out = append(out, fmt.Sprintf("%s%s:\n%s", padding, flavor, regs.String(regPadding))) + } out = append(out, fmt.Sprintf("%s%s:\n%s", padding, flavor, regs.String(regPadding))) case types.ARM_THREAD_STATE64: var regs RegsARM64 binary.Read(bytes.NewReader(thread.Data), t.bo, ®s) - out = append(out, fmt.Sprintf("%s%s:\n%s", padding, flavor, regs.String(regPadding))) + if regs.OnlyEntry() { + out = append(out, fmt.Sprintf("%s%s Entry: %#016x", padding, flavor, regs.PC)) + } else { + out = append(out, fmt.Sprintf("%s%s:\n%s", padding, flavor, regs.String(regPadding))) + } case types.ARM_EXCEPTION_STATE: var regs ArmExceptionState binary.Read(bytes.NewReader(thread.Data), t.bo, ®s) diff --git a/file.go b/file.go index dcd1977..30379ab 100644 --- a/file.go +++ b/file.go @@ -401,6 +401,9 @@ func NewFile(r io.ReaderAt, config ...FileConfig) (*File, error) { l.LoadCmd = cmd l.Len = siz l.bo = bo + if f.isArm() || f.isArm64() || f.isArm64e() { + l.IsArm = true + } for { var thread types.ThreadState err := binary.Read(b, bo, &thread.Flavor) diff --git a/macho.go b/macho.go index 5b19cc4..0960951 100644 --- a/macho.go +++ b/macho.go @@ -115,6 +115,14 @@ type RegsARM struct { CPSR uint32 } +func (r RegsARM) OnlyEntry() bool { + return r.R0 == 0 && r.R1 == 0 && r.R2 == 0 && r.R3 == 0 && + r.R4 == 0 && r.R5 == 0 && r.R6 == 0 && r.R7 == 0 && + r.R8 == 0 && r.R9 == 0 && r.R10 == 0 && r.R11 == 0 && + r.R12 == 0 && r.SP == 0 && r.LR == 0 && r.PC != 0 && + r.CPSR == 0 +} + func (r RegsARM) String(padding int) string { return fmt.Sprintf( "%s r0 %#08x r1 %#08x r2 %#08x r3 %#08x\n"+ @@ -168,6 +176,18 @@ type RegsARM64 struct { PAD uint32 /* Same size for 32-bit or 64-bit clients */ } +func (r RegsARM64) OnlyEntry() bool { + return r.X0 == 0 && r.X1 == 0 && r.X2 == 0 && r.X3 == 0 && + r.X4 == 0 && r.X5 == 0 && r.X6 == 0 && r.X7 == 0 && + r.X8 == 0 && r.X9 == 0 && r.X10 == 0 && r.X11 == 0 && + r.X12 == 0 && r.X13 == 0 && r.X14 == 0 && r.X15 == 0 && + r.X16 == 0 && r.X17 == 0 && r.X18 == 0 && r.X19 == 0 && + r.X20 == 0 && r.X21 == 0 && r.X22 == 0 && r.X23 == 0 && + r.X24 == 0 && r.X25 == 0 && r.X26 == 0 && r.X27 == 0 && + r.X28 == 0 && r.FP == 0 && r.LR == 0 && r.SP == 0 && + r.PC != 0 && r.CPSR == 0 && r.PAD == 0 +} + func (r RegsARM64) String(padding int) string { return fmt.Sprintf( "%s x0: %#016x x1: %#016x x2: %#016x x3: %#016x\n"+