{"id":13495278,"url":"https://github.com/burrowers/garble","last_synced_at":"2026-04-12T21:19:05.385Z","repository":{"id":36992469,"uuid":"226696536","full_name":"burrowers/garble","owner":"burrowers","description":"Obfuscate Go builds","archived":false,"fork":false,"pushed_at":"2025-04-13T21:10:39.000Z","size":1353,"stargazers_count":4525,"open_issues_count":40,"forks_count":289,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-04-18T00:57:17.452Z","etag":null,"topics":["binary","build","code-obfuscator","golang","obfuscation"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/burrowers.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["mvdan","lu4p","pagran"]}},"created_at":"2019-12-08T16:25:20.000Z","updated_at":"2025-04-17T17:35:57.000Z","dependencies_parsed_at":"2023-12-28T00:00:56.937Z","dependency_job_id":"51006229-a09b-4135-9c84-82ce8b544048","html_url":"https://github.com/burrowers/garble","commit_stats":{"total_commits":553,"total_committers":14,"mean_commits":39.5,"dds":"0.20433996383363473","last_synced_commit":"1f39d0af72d599b4fe50e40d8a8ee16e8467165a"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burrowers%2Fgarble","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burrowers%2Fgarble/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burrowers%2Fgarble/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burrowers%2Fgarble/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/burrowers","download_url":"https://codeload.github.com/burrowers/garble/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514759,"owners_count":21443208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary","build","code-obfuscator","golang","obfuscation"],"created_at":"2024-07-31T19:01:33.136Z","updated_at":"2026-04-12T21:19:05.379Z","avatar_url":"https://github.com/burrowers.png","language":"Go","funding_links":["https://github.com/sponsors/mvdan","https://github.com/sponsors/lu4p","https://github.com/sponsors/pagran"],"categories":["开源类库","Go","Go (531)","golang"],"sub_categories":["构建编译"],"readme":"# garble\n\n\tgo install mvdan.cc/garble@latest\n\nObfuscate Go code by wrapping the Go toolchain. Requires Go 1.26 or later.\n\n\tgarble build [build flags] [packages]\n\nThe tool also supports `garble test` to run tests with obfuscated code,\n`garble run` to obfuscate and execute simple programs,\nand `garble reverse` to de-obfuscate text such as stack traces.\nRun `garble -h` to see all available commands and flags.\n\nYou can also use `go install mvdan.cc/garble@master` to install the latest development version.\n\n### Purpose\n\nProduce a binary that works as well as a regular build, but that has as little\ninformation about the original source code as possible.\n\nThe tool is designed to be:\n\n* Coupled with `cmd/go`, to support modules and build caching\n* Deterministic and reproducible, given the same initial source code\n* Reversible given the original source, to de-obfuscate panic stack traces\n\n### Mechanism\n\nThe tool wraps calls to the Go compiler and linker to transform the Go build, in\norder to:\n\n* Replace as many useful identifiers as possible with short base64 hashes\n* Replace package paths with short base64 hashes\n* Replace filenames and position information with short base64 hashes\n* Remove all [build](https://go.dev/pkg/runtime/#Version) and [module](https://go.dev/pkg/runtime/debug/#ReadBuildInfo) information\n* Strip debugging information and symbol tables via `-ldflags=\"-w -s\"`\n* [Obfuscate literals](#literal-obfuscation), if the `-literals` flag is given\n* Remove [extra information](#tiny-mode), if the `-tiny` flag is given\n\nBy default, the tool obfuscates all the packages being built.\nYou can manually specify which packages to obfuscate via `GOGARBLE`,\na comma-separated list of glob patterns matching package path prefixes.\nThis format is borrowed from `GOPRIVATE`; see `go help private`.\n\nNote that commands like `garble build` will use the `go` version found in your\n`$PATH`. To use different versions of Go, you can\n[install them](https://go.dev/doc/manage-install#installing-multiple)\nand set up `$PATH` with them. For example, for Go 1.17.1:\n\n```sh\n$ go install golang.org/dl/go1.17.1@latest\n$ go1.17.1 download\n$ PATH=$(go1.17.1 env GOROOT)/bin:${PATH} garble build\n```\n\n### Use cases\n\nA common question is why a code obfuscator is needed for Go, a compiled language.\nGo binaries include a surprising amount of information about the original source;\neven with debug information and symbol tables stripped, many names and positions\nremain in place for the sake of traces, reflection, and debugging.\n\nSome use cases for Go require sharing a Go binary with the end user.\nIf the source code for the binary is private or requires a purchase,\nits obfuscation can help discourage reverse engineering.\n\nA similar use case is a Go library whose source is private or purchased.\nSince Go libraries cannot be imported in binary form, and Go plugins\n[have their shortcomings](https://github.com/golang/go/issues/19282),\nsharing obfuscated source code becomes an option.\nSee [#369](https://github.com/burrowers/garble/issues/369).\n\nObfuscation can also help with aspects entirely unrelated to licensing.\nFor example, the `-tiny` flag can make binaries 15% smaller,\nsimilar to the [common practice in Android](https://developer.android.com/build/shrink-code#obfuscate) to reduce app sizes.\nObfuscation has also helped some open source developers work around\nanti-virus scans incorrectly treating Go binaries as malware.\n\n### Literal obfuscation\n\nUsing the `-literals` flag causes literal expressions such as strings to be\nreplaced with more complex expressions, resolving to the same value at run-time.\nString literals injected via `-ldflags=-X` are also replaced by this flag.\nThis feature is opt-in, as it can cause slow-downs depending on the input code.\n\nLiterals used in constant expressions cannot be obfuscated, since they are\nresolved at compile time. This includes any expressions part of a `const`\ndeclaration, for example.\n\nNote that this process can be reversed given enough effort;\nsee [#984](https://github.com/burrowers/garble/issues/984).\n\n### Tiny mode\n\nWith the `-tiny` flag, even more information is stripped from the Go binary.\nPosition information is removed entirely, rather than being obfuscated.\nRuntime code which prints panics, fatal errors, and trace/debug info is removed.\nMany symbol names are also omitted from binary sections at link time.\nAll in all, this can make binaries about 15% smaller.\n\nWith this flag, no panics or fatal runtime errors will ever be printed, but they\ncan still be handled internally with `recover` as normal.\n\nNote that this flag can make debugging crashes harder, as a panic will simply\nexit the entire program without printing a stack trace, and source code\npositions and many names are removed.\nSimilarly, `garble reverse` is generally not useful in this mode.\n\n### Control flow obfuscation\n\nSee: [CONTROLFLOW.md](docs/CONTROLFLOW.md)\n\n### Speed\n\n`garble build` should take about twice as long as `go build`, as it needs to\ncomplete two builds. The original build, to be able to load and type-check the\ninput code, and then the obfuscated build.\n\nGarble obfuscates one package at a time, mirroring how Go compiles one package\nat a time. This allows Garble to fully support Go's build cache; incremental\n`garble build` calls should only re-build and re-obfuscate modified code.\n\nNote that the first call to `garble build` may be comparatively slow,\nas it has to obfuscate each package for the first time. This is akin to clearing\n`GOCACHE` with `go clean -cache` and running a `go build` from scratch.\n\nGarble also makes use of its own cache to reuse work, akin to Go's `GOCACHE`.\nIt defaults to a directory under your user's cache directory,\nsuch as `~/.cache/garble`, and can be placed elsewhere by setting `GARBLE_CACHE`.\n\n### Determinism and seeds\n\nJust like Go, garble builds are deterministic and reproducible in nature.\nThis has significant benefits, such as caching builds and being able to use\n`garble reverse` to de-obfuscate stack traces.\n\nBy default, garble will obfuscate each package in a unique way,\nwhich will change if its build input changes: the version of garble, the version\nof Go, the package's source code, or any build parameter such as GOOS or -tags.\nThis is a reasonable default since guessing those inputs is very hard.\n\nYou can use the `-seed` flag to provide your own obfuscation randomness seed.\nReusing the same seed can help produce the same code obfuscation,\nwhich can help when debugging or reproducing problems.\nRegularly rotating the seed can also help against reverse-engineering in the long run,\nas otherwise one can look at changes in how Go's standard library is obfuscated\nto guess when the Go or garble versions were changed across a series of builds.\n\nTo always use a different seed for each build, use `-seed=random`.\nNote that extra care should be taken when using custom seeds:\nif a `-seed` value used in a build is lost, `garble reverse` will not work.\n\n### Caveats\n\nMost of these can improve with time and effort. The purpose of this section is\nto document the current shortcomings of this tool.\n\n* Exported methods are never obfuscated at the moment, since they could\n  be required by interfaces. This area is a work in progress; see\n  [#3](https://github.com/burrowers/garble/issues/3).\n\n* Aside from `GOGARBLE` to select patterns of packages to obfuscate,\n  there is no supported way to exclude obfuscating a selection of files or packages.\n  More often than not, a user would want to do this to work around a bug; please file the bug instead.\n\n* Go programs [are initialized](https://go.dev/ref/spec#Program_initialization) one package at a time,\n  where imported packages are always initialized before their importers,\n  and otherwise they are initialized in the lexical order of their import paths.\n  Since garble obfuscates import paths, this lexical order may change arbitrarily.\n\n* Go plugins are not currently supported; see [#87](https://github.com/burrowers/garble/issues/87).\n\n* Garble requires `git` to patch the linker. That can be avoided once go-gitdiff\n  supports [non-strict patches](https://github.com/bluekeyes/go-gitdiff/issues/30).\n\n* APIs like [`runtime.GOROOT`](https://pkg.go.dev/runtime#GOROOT)\n  and [`runtime/debug.ReadBuildInfo`](https://pkg.go.dev/runtime/debug#ReadBuildInfo)\n  will not work in obfuscated binaries. This [can affect loading timezones](https://github.com/golang/go/issues/51473#issuecomment-2490564684), for example.\n\n### Contributing\n\nWe welcome new contributors. If you would like to contribute, see\n[CONTRIBUTING.md](CONTRIBUTING.md) as a starting point.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fburrowers%2Fgarble","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fburrowers%2Fgarble","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fburrowers%2Fgarble/lists"}