main.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "os/exec"
  6. "strconv"
  7. "strings"
  8. )
  9. const (
  10. SYSCALL_NUMS = 500
  11. )
  12. func run(allowed_syscalls []int) error {
  13. nums := []string{}
  14. for _, syscall := range allowed_syscalls {
  15. nums = append(nums, strconv.Itoa(syscall))
  16. }
  17. os.Setenv("ALLOWED_SYSCALLS", strings.Join(nums, ","))
  18. _, err := exec.Command("python3", "cmd/test/syscall_dig/test.py").Output()
  19. if err == nil {
  20. } else {
  21. failed_msg := fmt.Sprintf("failed with %v", err)
  22. fmt.Println(failed_msg)
  23. }
  24. return err
  25. }
  26. func main() {
  27. // generate all syscall list
  28. list := make([]int, 0, SYSCALL_NUMS)
  29. for i := 0; i < SYSCALL_NUMS; i++ {
  30. list = append(list, i)
  31. }
  32. for i := 0; i < SYSCALL_NUMS; i++ {
  33. syscall := list[0]
  34. list = list[1:]
  35. err := run(list)
  36. if err != nil {
  37. if strings.Contains(err.Error(), "bad system call") {
  38. // if run into err, then this syscall is needed, add it back to the end
  39. list = append(list, syscall)
  40. } else {
  41. fmt.Println(fmt.Sprintf("Failed to run your python code, %v", err))
  42. }
  43. }
  44. }
  45. // final test
  46. err := run(list)
  47. if err != nil {
  48. fmt.Println("Failed to get the needed syscalls")
  49. } else {
  50. // use ',' to join the list and print, easy for copy the list
  51. list_str := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(list)), ","), "[]")
  52. fmt.Println("Following syscalls are required:", list_str)
  53. }
  54. }