main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main import ( "fmt" "log" "net/http" "os" "os/exec" "path/filepath" "sync" ) var mu sync.Mutex func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "Welcome to Gore: Submit a Go module for execution!") fmt.Fprintln(w, "Use /submit?module=<module-url> to submit a Go module.") }) http.HandleFunc("/submit", handleModuleSubmission) log.Println("Starting Gore server on :8080...") log.Fatal(http.ListenAndServe(":8080", nil)) } func handleModuleSubmission(w http.ResponseWriter, r *http.Request) { module := r.URL.Query().Get("module") if module == "" { http.Error(w, "Module URL is required", http.StatusBadRequest) return } go func() { if err := processModule(module); err != nil { log.Printf("Error processing module %s: %v", module, err) } }() fmt.Fprintf(w, "Module %s submitted for processing.\n", module) } func processModule(module string) error { mu.Lock() defer mu.Unlock() log.Printf("Processing module: %s", module) // Create a temporary directory for the module tempDir, err := os.MkdirTemp("", "gore-*") if err != nil { return fmt.Errorf("failed to create temp dir: %v", err) } defer os.RemoveAll(tempDir) // `go get` the module cmd := exec.Command("go", "mod", "init", "gore-temp") cmd.Dir = tempDir if err := cmd.Run(); err != nil { return fmt.Errorf("failed to initialize module: %v", err) } cmd = exec.Command("go", "get", module) cmd.Dir = tempDir if err := cmd.Run(); err != nil { return fmt.Errorf("failed to get module: %v", err) } // Build the module outputBinary := filepath.Join(tempDir, "module-binary") cmd = exec.Command("go", "build", "-o", outputBinary) cmd.Dir = tempDir if err := cmd.Run(); err != nil { return fmt.Errorf("failed to build module: %v", err) } log.Printf("Module built: %s", outputBinary) // Launch QEMU VM with u-root and the built binary if err := launchQEMU(outputBinary); err != nil { return fmt.Errorf("failed to launch QEMU: %v", err) } return nil } func launchQEMU(binary string) error { // Simulate QEMU launching log.Printf("Launching QEMU VM with binary: %s", binary) // Replace this with actual QEMU invocation cmd := exec.Command("qemu-system-x86_64", "-kernel", binary, "-append", "console=ttyS0", "-nographic") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { return fmt.Errorf("failed to start QEMU: %v", err) } return nil }