From 13bc09c273acfb980775ff72688eb951ca5ed912 Mon Sep 17 00:00:00 2001 From: dmur1 <93072266+dmur1@users.noreply.github.com> Date: Sun, 24 Nov 2024 16:16:15 +0000 Subject: [PATCH] add showLinuxAbiAAPCS64 to commands/abi.go relates: https://github.com/rerrorctf/ret/issues/194 --- README.md | 2 +- commands/abi.go | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 14287a3..f7fb2e1 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ view abi details with ret output includes calling conventions, register volatility and more -for architecture specify one of `x86`, `32`, `x64`, `64` ~ the default is `x64` +for architecture specify one of `x86`, `32`, `x64`, `64`, `arm64`, `aapcs64` ~ the default is `x64` for os specify one of `linux`, `windows` ~ the default is `linux` diff --git a/commands/abi.go b/commands/abi.go index fbd1afa..12c3393 100644 --- a/commands/abi.go +++ b/commands/abi.go @@ -32,7 +32,7 @@ func init() { func AbiHelp() string { return "view abi details with ret\n\n" + "output includes calling conventions, register volatility and more\n\n" + - "for architecture specify one of `x86`, `32`, `x64`, `64` " + theme.ColorGray + "~ the default is `x64`\n\n" + theme.ColorReset + + "for architecture specify one of `x86`, `32`, `x64`, `64`, `arm64`, `aapcs64` " + theme.ColorGray + "~ the default is `x64`\n\n" + theme.ColorReset + "for os specify one of `linux`, `windows` " + theme.ColorGray + "~ the default is `linux`\n\n" + theme.ColorReset + "for example:\n" + "```bash\n" + @@ -90,6 +90,40 @@ func showLinuxAbix64() { fmt.Println(theme.ColorGray + " 128-byte area below the stack pointer see -mno-red-zone" + theme.ColorReset) } +func showLinuxAbiAAPCS64() { + fmt.Println(theme.ColorPurple + "linux 🐧 " + theme.ColorPurple + "AAPCS64" + theme.ColorReset) + + fmt.Println(theme.ColorPurple + " X31 Stack Pointer " + theme.ColorReset + "(" + theme.ColorPurple + "SP" + theme.ColorReset + ") - " + theme.ColorPurple + + "X30 Link Register " + theme.ColorReset + "(" + theme.ColorPurple + "LR" + theme.ColorReset + ") - " + theme.ColorPurple + + "X29 Frame Pointer " + theme.ColorReset + "(" + theme.ColorPurple + "FP" + theme.ColorReset + ")") + + fmt.Println(theme.ColorYellow + "\nscratch" + theme.ColorReset + "/" + theme.ColorYellow + "caller-save" + theme.ColorReset + "/" + theme.ColorYellow + "volatile" + theme.ColorReset + ":") + + fmt.Println(theme.ColorYellow + " X9 X10 X11 X12 X13 X14 X15" + theme.ColorReset) + + fmt.Println(theme.ColorGreen + "\ncallee-save" + theme.ColorReset + "/" + theme.ColorGreen + "non-volatile" + theme.ColorReset + ":") + + fmt.Println(theme.ColorGreen + " X19 X20 X21 X22 X23 X24 X25 X26 X27 X28" + theme.ColorReset) + + fmt.Println(theme.ColorBlue + "\nintraprocedure" + theme.ColorReset + "/" + theme.ColorBlue + "platform" + theme.ColorReset + ":") + + fmt.Println(theme.ColorBlue + " X16 " + theme.ColorReset + "(" + theme.ColorBlue + "IP0" + theme.ColorReset + ") - " + theme.ColorBlue + + "X17 " + theme.ColorReset + "(" + theme.ColorBlue + "IP1" + theme.ColorReset + ") - " + theme.ColorBlue + + "X18 Platform Register " + theme.ColorReset + "(" + theme.ColorBlue + "PR" + theme.ColorReset + ")") + + fmt.Println(theme.ColorCyan + "\ncall" + theme.ColorReset + ":") + + fmt.Println(theme.ColorCyan + " X0 X1 X2 X3 X4 X5 X6 X7 STACK => X0 X1 X2 X3 X4 X5 X6 X7" + theme.ColorReset) + + fmt.Println(theme.ColorGray + " X8 can be used to pass the address location of an indirect result" + theme.ColorReset) + + fmt.Println(theme.ColorGray + " arguments on the stack should be sign or zero extended and aligned to 8 bytes" + theme.ColorReset) + + fmt.Println(theme.ColorRed + "\nsyscall" + theme.ColorReset + ":" + theme.ColorReset) + + fmt.Println(theme.ColorRed + " X8 X0 X1 X2 X3 X4 X5 => X0" + theme.ColorReset) +} + func showWindowsAbix86() { fmt.Println(theme.ColorBlue + "windows 🪟 " + theme.ColorBlue + "x86" + theme.ColorReset) @@ -154,6 +188,10 @@ func Abi(args []string) { } else { showWindowsAbix64() } + case "arm64", "aapcs64": + if opsys == "linux" { + showLinuxAbiAAPCS64() + } default: { log.Fatalf("💥 " + theme.ColorRed + "error" + theme.ColorReset + ": unsupported architecture. use 'x86/32' or 'x64/64'\n" + theme.ColorReset)