Skip to content

Commit

Permalink
Added generic config handler to util for parsing common options. (#11)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jholowczak authored and kgwinnup committed Nov 16, 2019
1 parent fd75a0b commit 105f30d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
20 changes: 18 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
16 changes: 16 additions & 0 deletions util/config.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 105f30d

Please sign in to comment.