mirror of
https://github.com/thunderbrewhq/binana.git
synced 2025-12-12 01:42:29 +00:00
feat(go): profiles are now configured by an info.json file
This commit is contained in:
parent
e591b8b17d
commit
9053d61b6b
13 changed files with 222 additions and 111 deletions
72
go/profile/info.go
Normal file
72
go/profile/info.go
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
package profile
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var (
|
||||
valid_os = []string{
|
||||
"windows",
|
||||
"darwin",
|
||||
"linux",
|
||||
}
|
||||
|
||||
valid_arch = []string{
|
||||
"386",
|
||||
"amd64",
|
||||
"ppc",
|
||||
}
|
||||
)
|
||||
|
||||
type info_schema struct {
|
||||
OS string `json:"os"`
|
||||
Arch string `json:"arch"`
|
||||
ModuleName string `json:"module_name"`
|
||||
ModuleBase string `json:"module_base"`
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
OS string
|
||||
Arch string
|
||||
ModuleName string
|
||||
ModuleBase uint64
|
||||
}
|
||||
|
||||
func read_info(filename string, info *Info) (err error) {
|
||||
var b []byte
|
||||
b, err = os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var is info_schema
|
||||
err = json.Unmarshal(b, &is)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !slices.Contains(valid_os, is.OS) {
|
||||
err = fmt.Errorf("profile: invalid os '%s'", is.OS)
|
||||
return
|
||||
}
|
||||
|
||||
if !slices.Contains(valid_arch, is.Arch) {
|
||||
err = fmt.Errorf("profile: invalid arch '%s'", is.Arch)
|
||||
return
|
||||
}
|
||||
|
||||
info.ModuleName = is.ModuleName
|
||||
|
||||
info.OS = is.OS
|
||||
info.Arch = is.Arch
|
||||
|
||||
info.ModuleBase, err = strconv.ParseUint(is.ModuleBase, 16, 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue