# garble
GO111MODULE=on go get mvdan.cc/garble
Obfuscate Go code by wrapping the Go toolchain. Requires Go 1.16 or later.
garble build [build flags] [packages]
The tool also supports `garble test` to run tests with obfuscated code,
and `garble reverse` to de-obfuscate text such as stack traces.
See `garble -h` for up to date usage information.
### Purpose
Produce a binary that works as well as a regular build, but that has as little
information about the original source code as possible.
The tool is designed to be:
* Coupled with `cmd/go`, to support modules and build caching
* Deterministic and reproducible, given the same initial source code
* Reversible given the original source, to de-obfuscate panic stack traces
### Mechanism
The tool wraps calls to the Go compiler and linker to transform the Go build, in
order to:
* Replace as many useful identifiers as possible with short base64 hashes
* Replace package paths with short base64 hashes
* Remove all [build](https://golang.org/pkg/runtime/#Version) and [module](https://golang.org/pkg/runtime/debug/#ReadBuildInfo) information
* Strip filenames and shuffle position information
* Strip debugging information and symbol tables via `-ldflags="-w -s"`
* [Obfuscate literals](#literal-obfuscation), if the `-literals` flag is given
* Remove [extra information](#tiny-mode), if the `-tiny` flag is given
By default, the tool obfuscates the packages under the current module. If not
running in module mode, then only the main package is obfuscated. To specify
what packages to obfuscate, set `GOPRIVATE`, documented at `go help private`.
Note that commands like `garble build` will use the `go` version found in your
`$PATH`. To use different versions of Go, you can
[install them](https://golang.org/doc/manage-install#installing-multiple)
and set up `$PATH` with them. For example, for Go 1.16.1:
```sh
$ go get golang.org/dl/go1.16.1
$ go1.16.1 download
$ PATH=$(go1.16.1 env GOROOT)/bin:${PATH} garble build
```
### Literal obfuscation
Using the `-literals` flag causes literal expressions such as strings to be
replaced with more complex variants, resolving to the same value at run-time.
This feature is opt-in, as it can cause slow-downs depending on the input code.
Literal expressions used as constants cannot be obfuscated, since they are
resolved at compile time. This includes any expressions part of a `const`
declaration.
### Tiny mode
When the `-tiny` flag is passed, extra information is stripped from the resulting
Go binary. This includes line numbers, filenames, and code in the runtime that
prints panics, fatal errors, and trace/debug info. All in all this can make binaries
2-5% smaller in our testing, as well as prevent extracting some more information.
With this flag, no panics or fatal runtime errors will ever be printed, but they
can still be handled internally with `recover` as normal. In addition, the
`GODEBUG` environmental variable will be ignored.
Note that this flag can make debugging crashes harder, as a panic will simply
exit the entire program without printing a stack trace, and all source code
positions are set to line 1. Similarly, `garble reverse` is generally not useful
in this mode.
### Speed
`garble build` should take about twice as long as `go build`, as it needs to
complete two builds. The original build, to be able to load and type-check the
input code, and finally the obfuscated build.
Go's build cache is fully supported; if a first `garble build` run is slow, a
second run should be significantly faster. This should offset the cost of the
double builds, as incremental builds in Go are fast.
### Determinism and seeds
Just like Go, garble builds are deterministic and reproducible if the inputs
remain the same: the version of Go, the version of Garble, and the input code.
This has significant benefits, such as caching builds or being able to use
`garble reverse` to de-obfuscate stack traces.
However, it also means that an input package will be obfuscated in exactly the
same way if none of those inputs change. If you want two builds of your program
to be entirely different, you can use `-seed` to provide a new seed for the
entire build, which will cause a full rebuild.
If any open source packages are being obfuscated, providing a custom seed can
also provide extra protection. It could be possible to guess the versions of Go
and garble given how a public package was obfuscated without a seed.
### Caveats
Most of these can improve with time and effort. The purpose of this section is
to document the current shortcomings of this tool.
* Exported methods are never obfuscated at the moment, since they could
be required by interfaces and reflection. This area is a work in progress.
* It can be hard for garble to know what types will be used with
[reflection](https://golang.org/pkg/reflect), including JSON encoding or
decoding. If your program breaks because a type's names are obfuscated when
they should not be, you can add an explicit hint:
```go
type Message struct {
Command string
Args string
}
// Never obfuscate the Message type.
var _ = reflect.TypeOf(Message{})
```
* Go plugins are not currently supported; see [#87](https://github.com/burrowers/garble/issues/87).
### Contributing
We welcome new contributors. If you would like to contribute, see
[CONTRIBUTING.md](CONTRIBUTING.md) as a starting point.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
通过包装Go工具链来混淆Go代码乱码GO111MODULE = on go获取mvdan.cc/garble通过包装Go工具链来混淆Go代码。 需要Go 1.16或更高版本。 garble build [build flags] [packages]该工具还支持garble test,以使用混淆后的代码运行测试,而garble反向则可对诸如堆栈跟踪之类的文本进行反混淆处理。 有关最新用法信息,请参见garble -h。 目的生成一个与常规版本一样工作的二进制文件,但是其有关原始源代码的信息越少越好。 该工具是
资源推荐
资源详情
资源评论























收起资源包目录











































































共 62 条
- 1
资源评论


西西里上尉
- 粉丝: 37
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 计算机应用基础习题及答案.docx
- 软件质量保证与测试.doc
- 第5章网络营销渠道.ppt
- 旋转编码器与PLC的连接.doc
- XX年中国达人秀网络营销分析报告.ppt
- 华南农业大学农科Java上机实验.doc
- TSQL命令创建新数据库.ppt
- 2.淘宝子游-移动电子商务的用户需求演示教学.pptx
- CAD中“党是不会亏待你的”等恶意程序删除办法.doc
- 2023年全国计算机等级考试四级数据库工程师笔试真题.doc
- 基于MATLAB的数字带通滤波器课程设计报告(1).doc
- 大学C语言期末考试题库试题及答案汇总.docx
- 单片机原理及应用(C语言版).ppt
- 《奇妙的国际互联网》教学反思.docx
- 2023年计算机图形学实验报告.doc
- 基于互联网下的高中信息技术教学研究.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
