burrowers / garble

Obfuscate Go builds
BSD 3-Clause "New" or "Revised" License
3.92k stars 248 forks source link

Issue when passing -debugdir flag to Garble #879

Open SecDbg opened 21 hours ago

SecDbg commented 21 hours ago

What version of Garble and Go are you using?

$ garble version
mvdan.cc/garble v0.13.0

$ go version
go version go1.22.3 windows/amd64

What environment are you running Garble on?

go env Output
$ go env
PS C:\Users\Admin\Desktop\Test Garble> go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Admin\AppData\Local\go-build
set GOENV=C:\Users\Admin\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Admin\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Admin\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.3
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Admin\Desktop\Test Garble\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Admin\AppData\Local\Temp\go-build1244902259=/tmp/go-build -gno-record-gcc-switches

What did you do?

I was looking to test Garble and wanted to look at the obfuscated output using -debugdir=out, as outlined in garble -h When I tried running the following, I got this output

PS C:\Users\Admin\Desktop\Test Garble> garble -debugdir=out build .
unknown command: "Garble\\out"
go: error obtaining buildID for go tool compile: exit status 1
unknown command: "Garble\\out"
go: error obtaining buildID for go tool compile: exit status 1
unknown command: "Garble\\out"
exit status 1

What did you expect to see?

I expected to see an output directory, "out", with the obfuscated source so I could inspect it

What did you see instead?

I got the following errors:

PS C:\Users\Admin\Desktop\Test Garble> garble -debugdir=out build .
unknown command: "Garble\\out"
go: error obtaining buildID for go tool compile: exit status 1
unknown command: "Garble\\out"
go: error obtaining buildID for go tool compile: exit status 1
unknown command: "Garble\\out"

Additional information

When I run garble -h to see the possible flags, I get this output

PS C:\Users\Admin\Desktop\Test Garble> garble -h
Garble obfuscates Go code by wrapping the Go toolchain.

        garble [garble flags] command [go flags] [go arguments]

For example, to build an obfuscated program:

        garble build ./cmd/foo

Similarly, to combine garble flags and Go build flags:

        garble -literals build -tags=purego ./cmd/foo

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

To learn more about a command, run "garble help <command>".

garble accepts the following flags before a command:

  -debug
        Print debug logs to stderr
  -debugdir string
        Write the obfuscated source to a directory, e.g. -debugdir=out
  -literals
        Obfuscate literals such as strings
  -seed value
        Provide a base64-encoded seed, e.g. -seed=o9WDTZ4CN4w
        For a random seed, provide -seed=random
  -tiny
        Optimize for binary size, losing some ability to reverse the process

For more information, see https://github.com/burrowers/garble.

It states that -debugdir=out is a valid way of using -debugdir, but this does not work and gives the above error. Am I misunderstanding something, or is this an actual issue?

lu4p commented 18 hours ago

Can you try if -debugdir="out" helps?

SecDbg commented 2 hours ago

Tried, used both debugdir="out" and debugdir='out'. Both gave the same result as above

PS C:\Users\Admin\Desktop\Test Garble> garble -debugdir='out' build .\main.go
unknown command: "Garble\\out"
unknown command: "Garble\\out"
go: error obtaining buildID for go tool compile: exit status 1
unknown command: "Garble\\out"
unknown command: "Garble\\out"
go: error obtaining buildID for go tool compile: exit status 1
go: error obtaining buildID for go tool compile: exit status 1
go: error obtaining buildID for go tool compile: exit status 1
exit status 1
PS C:\Users\Admin\Desktop\Test Garble>
mvdan commented 2 hours ago

Which shell is this? Can you try a different shell?

Do other options work OK for you?

SecDbg commented 2 hours ago

I was using PowerShell originally, but tried doing it on cmd aswell. The result is the same I can use other flags like -tiny and -debug fine, but -debugdir just fails

SecDbg commented 2 hours ago

This is on Windows 11, not sure if relevant. I don't currently have a VM running any other Windows version, so can't check if it works differently