Skip to content

Commit cd9aa8c

Browse files
committed
implement syscall style arch selection for now
1 parent b954027 commit cd9aa8c

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

commands/abi.go

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package commands
22

33
import (
44
"fmt"
5+
"log"
56
"os"
67
"rctf/theme"
78
)
@@ -27,7 +28,7 @@ func showLinuxAbix86() {
2728
}
2829

2930
func showLinuxAbix64() {
30-
fmt.Println(theme.ColorPurple + "\nlinux 🐧 " + theme.ColorPurple + "x64" + theme.ColorReset)
31+
fmt.Println(theme.ColorPurple + "linux 🐧 " + theme.ColorPurple + "x64" + theme.ColorReset)
3132

3233
fmt.Println(theme.ColorYellow + "\nscratch" + theme.ColorReset + "/" + theme.ColorYellow + "caller-save" + theme.ColorReset + "/" + theme.ColorYellow + "volatile" + theme.ColorReset + ":")
3334

@@ -49,7 +50,7 @@ func showLinuxAbix64() {
4950
}
5051

5152
func showWindowsAbix86() {
52-
fmt.Println(theme.ColorBlue + "\nwindows 🪟 " + theme.ColorBlue + "x86" + theme.ColorReset)
53+
fmt.Println(theme.ColorBlue + "windows 🪟 " + theme.ColorBlue + "x86" + theme.ColorReset)
5354

5455
fmt.Println(theme.ColorYellow + "\nscratch" + theme.ColorReset + "/" + theme.ColorYellow + "caller-save" + theme.ColorReset + "/" + theme.ColorYellow + "volatile" + theme.ColorReset + ":")
5556

@@ -67,7 +68,7 @@ func showWindowsAbix86() {
6768
}
6869

6970
func showWindowsAbix64() {
70-
fmt.Println(theme.ColorBlue + "\nwindows 🪟 " + theme.ColorBlue + "x64" + theme.ColorReset)
71+
fmt.Println(theme.ColorBlue + "windows 🪟 " + theme.ColorBlue + "x64" + theme.ColorReset)
7172

7273
fmt.Println(theme.ColorYellow + "\nscratch" + theme.ColorReset + "/" + theme.ColorYellow + "caller-save" + theme.ColorReset + "/" + theme.ColorYellow + "volatile" + theme.ColorReset + ":")
7374

@@ -82,23 +83,60 @@ func showWindowsAbix64() {
8283
fmt.Println(theme.ColorCyan + " RCX/ZMM0 RDX/ZMM1 R8/ZMM2 R9/ZMM3 STACK => RAX XMM0 YMM0 ZMM0" + theme.ColorReset)
8384
}
8485

86+
func abiHelp() {
87+
fmt.Fprintf(os.Stderr, theme.ColorGreen+"usage"+theme.ColorReset+": rctf "+theme.ColorBlue+"abi"+theme.ColorReset+" [(x86/32)/(x64/64)]"+theme.ColorReset+" [linux/windows]\n")
88+
fmt.Fprintf(os.Stderr, " 🤝 view abi details with rctf\n")
89+
}
90+
8591
func Abi(args []string) {
8692
if len(args) > 0 {
8793
switch args[0] {
8894
case "help":
89-
fmt.Fprintf(os.Stderr, theme.ColorGreen+"usage"+theme.ColorReset+": rctf "+theme.ColorBlue+"abi"+theme.ColorReset+"\n")
90-
fmt.Fprintf(os.Stderr, " 🤝 view abi details with rctf\n")
91-
os.Exit(0)
95+
abiHelp()
96+
os.Exit(1)
9297
}
9398
}
9499

95-
showLinuxAbix86()
96-
97-
showLinuxAbix64()
98-
99-
showWindowsAbix86()
100+
if len(args) < 2 {
101+
abiHelp()
102+
log.Fatalf("💥 "+theme.ColorRed+"error"+theme.ColorReset+": %v missing args\n", 2-len(args))
103+
os.Exit(1)
104+
}
100105

101-
showWindowsAbix64()
106+
switch args[0] {
107+
case "x86":
108+
{
109+
if args[1] == "linux" {
110+
showLinuxAbix86()
111+
} else {
112+
showWindowsAbix86()
113+
}
114+
}
115+
case "32":
116+
{
117+
if args[1] == "linux" {
118+
showLinuxAbix86()
119+
} else {
120+
showWindowsAbix86()
121+
}
122+
}
123+
case "x64":
124+
{
125+
if args[1] == "linux" {
126+
showLinuxAbix64()
127+
} else {
128+
showWindowsAbix64()
129+
}
130+
}
131+
case "64":
132+
{
133+
if args[1] == "linux" {
134+
showLinuxAbix64()
135+
} else {
136+
showWindowsAbix64()
137+
}
138+
}
139+
}
102140

103141
fmt.Println("\n🔗 " + theme.ColorCyan + "https://www.agner.org/optimize/calling_conventions.pdf" + theme.ColorReset)
104142
}

0 commit comments

Comments
 (0)