Skip to content

Commit

Permalink
name working
Browse files Browse the repository at this point in the history
  • Loading branch information
Selyss committed Nov 19, 2023
1 parent 26f2fd3 commit b81aed2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
10 changes: 9 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -58,6 +66,6 @@ func main() {
if err != nil {
log.Fatal(err)
}
assembuddy.RenderArchTable(table)
assembuddy.RenderArchTable(opts.Arch, table)
}
}
43 changes: 40 additions & 3 deletions pkg/assembuddy/renderTable.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
package assembuddy

import (
"fmt"
"os"

"github.com/olekukonko/tablewriter"
)

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)
}
}
11 changes: 11 additions & 0 deletions pkg/assembuddy/requestTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b81aed2

Please sign in to comment.