From 9ddfc16de5c8a5c9a4a8434c6bae52ba2dfabd3b Mon Sep 17 00:00:00 2001 From: Selyss <99344963+Selyss@users.noreply.github.com> Date: Thu, 16 Nov 2023 18:44:16 -0500 Subject: [PATCH] even more --- cmd/main.go | 3 ++- pkg/assembuddy/asm.go | 4 ---- pkg/assembuddy/listOptions.go | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 pkg/assembuddy/listOptions.go diff --git a/cmd/main.go b/cmd/main.go index dcdf7a9..641cbbc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -34,5 +34,6 @@ func parseArgs() *assembuddy.CLIOptions { func main() { opts := parseArgs() - assembuddy.QueryASM(opts) + // assembuddy.QueryASM(opts) + fmt.Println(assembuddy.ListQueryMatches(opts.Syscall)) } diff --git a/pkg/assembuddy/asm.go b/pkg/assembuddy/asm.go index 4ef4c99..e33b62c 100644 --- a/pkg/assembuddy/asm.go +++ b/pkg/assembuddy/asm.go @@ -39,10 +39,6 @@ func QueryASM(opts *CLIOptions) { selectedName = syscall } - if selectedName == "" { - log.Fatalf("No syscall selected.") - } - selectedSyscall, err := getSyscallDetails(arch, selectedName) if err != nil { log.Fatalf("Error fetching syscall details: %s", err) diff --git a/pkg/assembuddy/listOptions.go b/pkg/assembuddy/listOptions.go new file mode 100644 index 0000000..76c7d28 --- /dev/null +++ b/pkg/assembuddy/listOptions.go @@ -0,0 +1,39 @@ +package assembuddy + +import ( + "encoding/json" + "fmt" + "io" + "net/http" +) + +// ListOptions provides options for listing assemblies. +func ListArchSyscalls() { +} + +func ListQueryMatches(query string) ([]string, error) { + url := fmt.Sprintf("https://api.syscall.sh/v1/syscalls/%s", query) + resp, err := http.Get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + var syscalls []Syscall + + if err := json.Unmarshal(body, &syscalls); err != nil { + return nil, err + } + + var syscallNames []string + for _, syscall := range syscalls { + syscallNames = append(syscallNames, syscall.Name) + } + + return syscallNames, nil +}