Skip to content

Commit

Permalink
fix: LC_UNIXTHREAD cmd output
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Jun 4, 2024
1 parent 8599097 commit 98f43c2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &regs)
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, &regs)
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, &regs)
Expand Down
3 changes: 3 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions macho.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"+
Expand Down Expand Up @@ -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"+
Expand Down

0 comments on commit 98f43c2

Please sign in to comment.