out-of-tree kernel {module, exploit} development tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2018 Mikhail Klementev. All rights reserved.
  2. // Use of this source code is governed by a AGPLv3 license
  3. // (or later) that can be found in the LICENSE file.
  4. // +build linux
  5. package main
  6. import (
  7. "io/ioutil"
  8. "log"
  9. "os/exec"
  10. "strings"
  11. "code.dumpstack.io/tools/out-of-tree/config"
  12. "github.com/zcalusic/sysinfo"
  13. )
  14. func genHostKernels(download bool) (kcfg config.KernelConfig, err error) {
  15. si := sysinfo.SysInfo{}
  16. si.GetSysInfo()
  17. distroType, err := config.NewDistroType(si.OS.Vendor)
  18. if err != nil {
  19. return
  20. }
  21. cmd := exec.Command("ls", "/lib/modules")
  22. rawOutput, err := cmd.CombinedOutput()
  23. if err != nil {
  24. log.Println(string(rawOutput), err)
  25. return
  26. }
  27. kernelsBase := "/boot/"
  28. files, err := ioutil.ReadDir(kernelsBase)
  29. if err != nil {
  30. return
  31. }
  32. // only for compatibility, docker is not really used
  33. dii := dockerImageInfo{
  34. ContainerName: config.KernelMask{
  35. DistroType: distroType,
  36. DistroRelease: si.OS.Version,
  37. }.DockerName(),
  38. }
  39. rootfs, err := genRootfsImage(dii, download)
  40. if err != nil {
  41. return
  42. }
  43. for _, k := range strings.Fields(string(rawOutput)) {
  44. ki := config.KernelInfo{
  45. DistroType: distroType,
  46. DistroRelease: si.OS.Version,
  47. KernelRelease: k,
  48. KernelSource: "/lib/modules/" + k + "/build",
  49. KernelPath: kernelsBase + genKernelPath(files, k),
  50. InitrdPath: kernelsBase + genInitrdPath(files, k),
  51. RootFS: rootfs,
  52. }
  53. vmlinux := "/usr/lib/debug/boot/vmlinux-" + k
  54. log.Println("vmlinux", vmlinux)
  55. if exists(vmlinux) {
  56. ki.VmlinuxPath = vmlinux
  57. }
  58. kcfg.Kernels = append(kcfg.Kernels, ki)
  59. }
  60. return
  61. }