From cd003eade010c46d2aeb5abb918e8b1bbc8d0829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 10 Apr 2023 21:58:03 +0100 Subject: [PATCH] support `garble run` It's the third time I've wanted it to quickly test out standalone reproducers when people submit bugs. Fixes #661. --- README.md | 1 + main.go | 3 ++- testdata/script/run.txtar | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 testdata/script/run.txtar diff --git a/README.md b/README.md index ac2eacb..cd0867f 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Obfuscate Go code by wrapping the Go toolchain. Requires Go 1.20 or later. garble build [build flags] [packages] The tool also supports `garble test` to run tests with obfuscated code, +`garble run` to obfuscate and execute simple programs, and `garble reverse` to de-obfuscate text such as stack traces. See `garble -h` for up to date usage information. diff --git a/main.go b/main.go index 74b464e..24baa1a 100644 --- a/main.go +++ b/main.go @@ -121,6 +121,7 @@ The following commands are supported: build replace "go build" test replace "go test" + run replace "go run" reverse de-obfuscate output such as stack traces version print the version and build settings of the garble binary @@ -396,7 +397,7 @@ func mainErr(args []string) error { return nil case "reverse": return commandReverse(args) - case "build", "test": + case "build", "test", "run": cmd, err := toolexecCmd(command, args) defer os.RemoveAll(os.Getenv("GARBLE_SHARED")) if err != nil { diff --git a/testdata/script/run.txtar b/testdata/script/run.txtar new file mode 100644 index 0000000..c3772aa --- /dev/null +++ b/testdata/script/run.txtar @@ -0,0 +1,29 @@ +garble run garble_main.go +! stdout '^garble_main\.go 9$' +stdout '\.go \d' + +[short] stop # no need to verify this with -short + +# also with a package +garble run . +! stdout '^garble_main\.go 9$' +stdout '\.go \d' + +go run garble_main.go +stdout 'garble_main\.go 9$' +-- go.mod -- +module test/main + +go 1.20 +-- garble_main.go -- +package main + +import ( + "fmt" + "runtime" +) + +func main() { + _, file, line, _ := runtime.Caller(0) + fmt.Println(file, line) +}