diff --git a/cmd/main.go b/cmd/main.go index 318eb5e..2b6264f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -46,6 +46,14 @@ func parseArgs() *CLIOptions { func main() { opts := parseArgs() + if opts.Syscall == "" && opts.Arch == "" { + table, err := assembuddy.GetArchData(opts.Arch, opts.PrettyPrint) + if err != nil { + log.Fatal(err) + } + assembuddy.RenderArchTable(opts.Arch, table) + } + if opts.Syscall != "" { table, err := assembuddy.GetNameData(opts.Syscall, opts.PrettyPrint) if err != nil { @@ -58,6 +66,6 @@ func main() { if err != nil { log.Fatal(err) } - assembuddy.RenderArchTable(table) + assembuddy.RenderArchTable(opts.Arch, table) } } diff --git a/pkg/assembuddy/renderTable.go b/pkg/assembuddy/renderTable.go index a82ba13..9dcc3c1 100644 --- a/pkg/assembuddy/renderTable.go +++ b/pkg/assembuddy/renderTable.go @@ -1,6 +1,7 @@ package assembuddy import ( + "fmt" "os" "github.com/olekukonko/tablewriter" @@ -8,10 +9,46 @@ import ( func RenderNameTable(tableData []Syscall) { table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"ARCH", "NR", "SYSCALL", "RAX", "rdi", "rsi", "rdx", "r10", "r8", "r9"}) + table.SetHeader([]string{"ARCH", "NR", "NAME", "RETURN", "ARG0", "ARG1", "ARG2", "ARG3", "ARG4", "ARG5"}) + col := tablewriter.Colors{tablewriter.Bold, tablewriter.FgHiGreenColor} + table.SetHeaderColor(col, col, col, col, col, col, col, col, col, col) + for _, syscall := range tableData { + table.Append([]string{syscall.Arch, fmt.Sprint(syscall.Nr), syscall.Name, syscall.ReturnValue, syscall.Arg0, syscall.Arg1, syscall.Arg2, syscall.Arg3, syscall.Arg4, syscall.Arg5}) + } + table.Render() } -func RenderArchTable(tableData []Syscall) { +func RenderArchTable(arch string, tableData []Syscall) { table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"NR", "SYSCALL", "RAX", "rdi", "rsi", "rdx", "r10", "r8", "r9"}) + getArchTable(arch, *table) + for _, syscall := range tableData { + table.Append([]string{syscall.Name, syscall.ReturnValue, syscall.Arg0, syscall.Arg1, syscall.Arg2, syscall.Arg3, syscall.Arg4, syscall.Arg5}) + } + table.Render() +} + +func getArchTable(arch string, table tablewriter.Table) { + // TODO: add the ARG0 (x0) stuff to headers + // + // HACK: hard coding the header len as 9 for now + // + // INFO: I actually need the col stuff because the library needs it + switch arch { + case "x64": + table.SetHeader([]string{"NR", "SYSCALL", "RAX", "rdi", "rsi", "rdx", "r10", "r8", "r9"}) + col := tablewriter.Colors{tablewriter.Bold, tablewriter.FgHiYellowColor} + table.SetHeaderColor(col, col, col, col, col, col, col, col, col) + case "x86": + table.SetHeader([]string{"NR", "SYSCALL", "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp"}) + col := tablewriter.Colors{tablewriter.Bold, tablewriter.FgHiCyanColor} + table.SetHeaderColor(col, col, col, col, col, col, col, col, col) + case "arm64": + table.SetHeader([]string{"NR", "SYSCALL", "x8", "x0", "x1", "x2", "x3", "x4", "x5"}) + col := tablewriter.Colors{tablewriter.Bold, tablewriter.FgHiRedColor} + table.SetHeaderColor(col, col, col, col, col, col, col, col, col) + case "arm": + table.SetHeader([]string{"NR", "SYSCALL", "r7", "r0", "r1", "r2", "r3", "r4", "r5"}) + col := tablewriter.Colors{tablewriter.Bold, tablewriter.FgHiMagentaColor} + table.SetHeaderColor(col, col, col, col, col, col, col, col, col) + } } diff --git a/pkg/assembuddy/requestTable.go b/pkg/assembuddy/requestTable.go index 3aa8bb9..5c7261b 100644 --- a/pkg/assembuddy/requestTable.go +++ b/pkg/assembuddy/requestTable.go @@ -47,6 +47,17 @@ func fetchData(endpointURL string, prettyp bool) ([]Syscall, error) { return systemCalls, nil } +func GetSpecificData(arch string, name string, prettyp bool) ([]Syscall, error) { + url := "https://api.syscall.sh/v1/syscalls/" + // if arch is x64, x86, arm, or arm64, concat to endpointURL + if arch == "x64" || arch == "x86" || arch == "arm" || arch == "arm64" { + url += arch + } else { + return nil, errors.New("invalid architecture") + } + return fetchData(url, prettyp) +} + func GetArchData(arch string, prettyp bool) ([]Syscall, error) { url := "https://api.syscall.sh/v1/syscalls/" // if arch is x64, x86, arm, or arm64, concat to endpointURL