diff --git a/cmd/gscript/main.go b/cmd/gscript/main.go index 77c8de7..3a1024d 100644 --- a/cmd/gscript/main.go +++ b/cmd/gscript/main.go @@ -17,6 +17,7 @@ import ( "strings" "time" + "github.com/fatih/color" "github.com/gen0cide/gscript" "github.com/gen0cide/gscript/compiler" "github.com/gen0cide/gscript/debugger" @@ -44,6 +45,8 @@ func main() { cli.AppHelpTemplate = fmt.Sprintf("%s\n\n%s", logging.AsciiLogo(), cli.AppHelpTemplate) cli.CommandHelpTemplate = fmt.Sprintf("%s\n\n%s", logging.AsciiLogo(), cli.CommandHelpTemplate) app := cli.NewApp() + app.Writer = color.Output + app.ErrWriter = color.Output app.Name = "gscript" app.Usage = "Command Line SDK for the Genesis Scripting Engine (GSE)" app.Version = gscript.Version @@ -135,12 +138,6 @@ func main() { Usage: "Run a Genesis script (Careful, don't infect yourself!).", Action: RunScript, }, - { - Name: "trace", - Aliases: []string{"a"}, - Usage: "Show command line options", - Action: TraceScript, - }, } sort.Sort(cli.FlagsByName(app.Flags)) @@ -209,7 +206,17 @@ func CompileScript(c *cli.Context) error { if c.NArg() == 0 { logger.Fatalf("You did not specify a genesis script!") } - scriptFiles := c.Args() + scriptFiles := []string{} + for _, a := range c.Args() { + f, err := filepath.Glob(a) + if err != nil { + logger.Fatalf("Bad file glob: %s", err.Error()) + } + for _, n := range f { + scriptFiles = append(scriptFiles, n) + } + } + if !outputSource && outputFile == "-" { outputFile = filepath.Join(os.TempDir(), fmt.Sprintf("%d_genesis.bin", time.Now().Unix())) } diff --git a/compiler/compiler.go b/compiler/compiler.go index 154790c..62926b1 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -45,6 +45,7 @@ type StringDef struct { // Compiler creates a skeleton structure to produce a compiled binary type Compiler struct { + sync.RWMutex OS string `json:"os"` Arch string `json:"arch"` OutputFile string `json:"output"` diff --git a/compiler/embedder.go b/compiler/embedder.go index c4b602d..6660416 100644 --- a/compiler/embedder.go +++ b/compiler/embedder.go @@ -3,12 +3,12 @@ package compiler import ( "bytes" "compress/gzip" + "crypto/rand" "fmt" "io/ioutil" - "math/rand" + "math/big" "path/filepath" "strings" - "time" ) type EmbeddedFile struct { @@ -74,11 +74,14 @@ func CompressedToBytes(b []byte) []byte { } func RandUpperAlphaString(strlen int) string { - var r = rand.New(rand.NewSource(time.Now().UnixNano())) const chars = "abcdefghijklmnopqrstuvwxyz" result := make([]byte, strlen) for i := range result { - result[i] = chars[r.Intn(len(chars))] + val, err := rand.Int(rand.Reader, big.NewInt(int64(len(chars)))) + if err != nil { + panic(err) + } + result[i] = chars[val.Int64()] } return strings.ToUpper(string(result)) } diff --git a/compiler/obfuscator.go b/compiler/obfuscator.go index 643a05e..cb533fa 100644 --- a/compiler/obfuscator.go +++ b/compiler/obfuscator.go @@ -258,13 +258,14 @@ func (c *Compiler) HairTangler(key rune, source string) string { varDef = append(varDef, ch^key) key ^= ch } - + c.Lock() c.StringDefs = append(c.StringDefs, &StringDef{ ID: varName, Value: source, Key: key, Data: varDef, }) + c.Unlock() return cipher } diff --git a/engine/core.go b/engine/core.go index 4deb223..5739eaa 100644 --- a/engine/core.go +++ b/engine/core.go @@ -1,18 +1,14 @@ package engine import ( - "math/rand" + "crypto/rand" + "math/big" "strings" - "time" "unicode" ) var letterRunes = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") -func init() { - rand.Seed(time.Now().UnixNano()) -} - func XorBytes(a []byte, b []byte) []byte { n := len(a) if len(b) < n { @@ -51,23 +47,31 @@ func ObfuscateString(Data string) string { } func RandString(strlen int) string { - var r = rand.New(rand.NewSource(time.Now().UnixNano())) const chars = "abcdefghijklmnopqrstuvwxyz0123456789" result := make([]byte, strlen) for i := range result { - result[i] = chars[r.Intn(len(chars))] + val, err := rand.Int(rand.Reader, big.NewInt(int64(len(chars)))) + if err != nil { + panic(err) + } + result[i] = chars[val.Int64()] } return string(result) } func RandomInt(min, max int) int { - return rand.Intn(max-min) + min + r, _ := rand.Int(rand.Reader, big.NewInt(int64(max-min))) + return int(r.Int64()) + min } func RandStringRunes(n int) string { b := make([]rune, n) for i := range b { - b[i] = letterRunes[rand.Intn(len(letterRunes))] + val, err := rand.Int(rand.Reader, big.NewInt(int64(len(letterRunes)))) + if err != nil { + panic(err) + } + b[i] = letterRunes[val.Int64()] } return string(b) } diff --git a/gscript.go b/gscript.go index 220b43a..18bd966 100644 --- a/gscript.go +++ b/gscript.go @@ -1,4 +1,4 @@ package gscript // Version defines the version of gscript -const Version = "v0.0.16" +const Version = "v0.0.17"