if the seed is random and the build fails, print the seed (#213)

Fixes #212
pull/220/head
Andrew LeFevre 3 years ago committed by GitHub
parent 91deb1e224
commit e014f480f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,13 +4,11 @@
package literals package literals
import ( import (
cryptrand "crypto/rand"
"fmt" "fmt"
"go/ast" "go/ast"
"go/token" "go/token"
mathrand "math/rand" mathrand "math/rand"
"os" "os"
"strings"
) )
// obfuscator takes a byte slice and converts it to a ast.BlockStmt // obfuscator takes a byte slice and converts it to a ast.BlockStmt
@ -35,16 +33,8 @@ var (
// genRandBytes return a random []byte with the length of size. // genRandBytes return a random []byte with the length of size.
func genRandBytes(buffer []byte) { func genRandBytes(buffer []byte) {
if strings.HasPrefix(envGarbleSeed, "random;") { if _, err := mathrand.Read(buffer); err != nil {
_, err := cryptrand.Read(buffer) panic(fmt.Sprintf("couldn't generate random key: %v", err))
if err != nil {
panic(fmt.Sprintf("couldn't generate random key: %v", err))
}
} else {
_, err := mathrand.Read(buffer)
if err != nil {
panic(fmt.Sprintf("couldn't generate random key: %v", err))
}
} }
} }

@ -170,6 +170,9 @@ func main1() int {
case errJustExit: case errJustExit:
default: default:
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
if flagSeed == "random" {
fmt.Fprintf(os.Stderr, "random seed: %s\n", base64.RawStdEncoding.EncodeToString(opts.Seed))
}
} }
return 1 return 1
} }
@ -238,7 +241,7 @@ How to install Go: https://golang.org/doc/install
} }
func mainErr(args []string) error { func mainErr(args []string) error {
// If we recognise an argument, we're not running within -toolexec. // If we recognize an argument, we're not running within -toolexec.
switch cmd := args[0]; cmd { switch cmd := args[0]; cmd {
case "help": case "help":
return flag.ErrHelp return flag.ErrHelp

Loading…
Cancel
Save