From 105f30d5f505d8f8e5fe66090631492a9b20dec2 Mon Sep 17 00:00:00 2001 From: John Holowczak Date: Sat, 16 Nov 2019 17:42:48 -0500 Subject: [PATCH] Added generic config handler to util for parsing common options. (#11) For use with apiset parsing functionality, instead of hard-coded values. One thing to note: configs are tied very heavily to the emulator itself, might want to consider refactoring configs in the future. --- main.go | 20 ++++++++++++++++++-- util/config.go | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 util/config.go diff --git a/main.go b/main.go index 19b3422..167a723 100644 --- a/main.go +++ b/main.go @@ -112,7 +112,15 @@ func main() { // if apiset dump option, load apisetschema.dll and dump all apisets if options.ApisetDump { - path, err := util.SearchFile([]string{"C:\\Windows\\System32", "os/win10_32/windows/system32"}, "apisetschema.dll") + rootFolder := "os/win10_32/" + if options.Config != "" { + conf, err := util.ReadGenericConfig(options.Config) + if err != nil { + log.Fatal(err) + } + rootFolder = conf.Root + } + path, err := util.SearchFile([]string{"C:\\Windows\\System32", rootFolder + "windows/system32"}, "apisetschema.dll") if err != nil { log.Fatal(err) } @@ -128,7 +136,15 @@ func main() { // if apiset lookup, load apisetschema.dll and look up the apiset name if options.ApisetLookup != "" { - path, err := util.SearchFile([]string{"C:\\Windows\\System32", "os/win10_32/windows/system32"}, "apisetschema.dll") + rootFolder := "os/win10_32/" + if options.Config != "" { + conf, err := util.ReadGenericConfig(options.Config) + if err != nil { + log.Fatal(err) + } + rootFolder = conf.Root + } + path, err := util.SearchFile([]string{"C:\\Windows\\System32", rootFolder + "windows/system32"}, "apisetschema.dll") if err != nil { log.Fatal(err) } diff --git a/util/config.go b/util/config.go new file mode 100644 index 0000000..b2e6b7a --- /dev/null +++ b/util/config.go @@ -0,0 +1,16 @@ +package util + +import "gopkg.in/yaml.v2" +import "io/ioutil" + +type GenericConfig struct { + Root string `yaml:"root"` +} + +func ReadGenericConfig(config string) (conf GenericConfig, err error) { + var buf []byte + if buf, err = ioutil.ReadFile(config); err == nil { + err = yaml.Unmarshal(buf, &conf) + } + return +}