Commit Graph

343 Commits (d2beda1f0016a11b0b0a364eff06a153eb4a448a)

Author SHA1 Message Date
lu4p 077d02d43a
add basic literal obfuscation, starting with strings
Fixes #16.
4 years ago
Daniel Martí 80538f19c7 blacklist struct fields with reflection too
In the added test, the unexported field used to be garbled.

Reflection can only reach exported methods, exported fields, and
unexported fields. Exported methods and fields are currently never
garbled, so unexported fields was the only missing piece.
4 years ago
Daniel Martí 809b7a8dda remove forgotten debug print 4 years ago
Daniel Martí 4bc64ef8fb make detection of reflect more robust
It now works with variables and composite type expressions too.
4 years ago
lu4p 8b898ad0d2
exclude identifiers used via reflection
If reflect.TypeOf or reflect.ValueOf are used on a type declared in the same package,
don't garble that type name or any of its fields.

Fixes #15.
4 years ago
Daniel Martí e8074d4665 support building ad-hoc plugin packages
That is, plugin packages by source file names, not by package path.

Fixes #19.
4 years ago
Daniel Martí 56a1fd0257 support -ldflags=-X=pkg.name=str with garbled names
Because the linker has access to all the build IDs, just like the
compiler, we can support this transparently. Add a test too.

Fixes #21.
4 years ago
Daniel Martí 7321b29efe first version of plugins working
Add a caveat about -trimpath too.

Fixes #18.
4 years ago
Daniel Martí 012d5d6b34 document objOf 4 years ago
Daniel Martí 3617013cd1 clean up the function that walks the syntax tree
Avoiding a type switch for the entire node prevents an indentation
level.

We can obtain obj and pkg early, and return early as well if either is
uninteresting. That means less nil checks later on, which means even
less indentation and complexity.
4 years ago
Daniel Martí f0a609c7fc fix out of bounds panic with "garble build"
Forgot to run all the tests with the last commit.
4 years ago
Daniel Martí 1ef3daf251 clarify usage text, add help flags
Also remove the -toolexec equivalent, as it's becoming longer now that
we have GARBLE_DIR, and it might become out of date in the future again.
We don't want users to assume it will work forever.
4 years ago
Daniel Martí 19e4c098cd make selection of packages configurable via GOPRIVATE
Carefully select a default that will do the right thing when inside a
module, as well as when building ad-hoc packages.

This means we no longer need to look at the compiler's -std flag, which
is nice.

Also replace foo.com/ with test/, as per golang/go#37641.

Fixes #7.
4 years ago
Daniel Martí 04dea79b2d initial support for cgo
I'm sure that the added test case doesn't cover many edge cases, but
it's a start.

Fixes #12.
4 years ago
Daniel Martí 5aaa086e5d don't remove "//go:" compile directives
For example, this broke cgo, since it uses go:linkname.

Updates #12.
4 years ago
Daniel Martí a7da406207 start supporting asm functions better
Spotted while trying to link a program using unix.Syscall, since its
implementation is assembly.

Telling if a function couldn't be garbled isn't trivial. If that
function belongs to an imported package, we only load its export data
instead of type-checking from source, so we don't have all the
information needed.

Instead, use the gc export data importer to import two versions of each
dependency: its original version, for the initial type-checking, and its
garbled version, to check if any of its exported names weren't garbled.

Updates #9.
4 years ago
Daniel Martí d72c00eafd support building modules which require other modules
We use 'go list -json -export' to locate required modules. This works
fine to locate direct module dependencies; since we're building in the
current module, we run 'go list' in the correct directory.

However, if we're building one of those module dependencies, and it has
other module dependencies of its own, we would fail with cryptic errors
like:

	typecheck error: [...] go list error: updates to go.sum needed, disabled by -mod=readonly

This is because we would try to run 'go list' outside of the main
module, probably inside the module cache. Instead, use a $GARBLE_DIR env
var from the top-level 'garble build' call to always run 'go list' in
the original directory.

We add a few small modules to properly test this.

Updates #9.
4 years ago
Daniel Martí b8aec97e86 don't garble any embedded fields
In the added test case, we'd see a failure, since we garbled the name of
the "Embedded" type but not its use as an anonymous field. Garble both.

This might possibly break some reflect code, but it doesn't seem like we
have an option. When we garble a type, it's impossible to tell if it's
going to be used as an anonymous field later.

Updates #9.
4 years ago
Daniel Martí 4d5ad43f10 allow garble to test itself
With this patch, 'go install && garble test' works.
4 years ago
Daniel Martí 1ce5310440 don't garble exported struct fields
They might reasonably affect the behavior of the code, such as when
encoding/json is used without tags.
4 years ago
Daniel Martí b10cce34f8 parse boolean flags differently from string flags
This is important, because "-std -foo" and "-buildid -foo" are entirely
different cases. The first is equivalent to "-std=true -foo" since the
flag is boolean, but the second is equivalent to "-buildid=-foo" since
the flag isn't boolean.

We can keep track of which of the flags we're interested in are boolean,
which isn't much extra work. Also add unit tests; the build ID is a
hash, so it's very hard to write an end-to-end test that reliably has an
ID starting with a dash.
4 years ago
Daniel Martí ce0137fa6a don't break TestMain funcs
Important for 'garble test', if a package uses one.
4 years ago
Daniel Martí 5ccf56662a don't panic with struct pointer anonymous fields
While at it, make the "object of type" code shared and more robust.
5 years ago
Daniel Martí bee30aff41 add initial support for running tests
For now, it mainly consists of not garbling Test* funcs, and not
garbling the _testmain.go file that will run them.

Updates #6.
5 years ago
Daniel Martí c23f529830 use real package paths when typechecking
'go tool compile' receives the package path via the -p flag. This is
better than making up one.

We have to be careful with "-p main" though, as that's not part of the
standard library.
5 years ago
Daniel Martí b6d889cdcf start rejecting unknown non-tool commands 5 years ago
Daniel Martí 0cc6e36414 split main1 with a func returning an error 5 years ago
Daniel Martí 5556be7402 make the tool work on Windows, enable tests
The tests required a few last tweaks to work on Windows.
5 years ago
Daniel Martí 0058dfc12a make output binaries deterministic
We were leaking temporary file paths, which is no longer the case.
5 years ago
Daniel Martí ab560ff007 start testing on GitHub Actions
No windows yet, because a few portability issues remain.
5 years ago
Daniel Martí 63cbc01628 support anonymous fields better 5 years ago
Daniel Martí a87002e662 don't break types implementing interfaces 5 years ago
Daniel Martí 3f35fb07f2 remove module info from the resulting binary 5 years ago
Daniel Martí 33f2a4bc2e remove all unnecessary empty lines from garbled Go 5 years ago
Daniel Martí aba66758ca support type switches with symbolic vars 5 years ago
Daniel Martí 766bb47b82 support std imports 5 years ago
Daniel Martí 1fe0351517 garbling imported packages starts being supported 5 years ago
Daniel Martí 764af03e89 introduce 'garble build' shortcut
This way, the user doesn't need to remember to use flags like -a and
-trimpath. Also because we might need more 'go build' flags in the
future.
5 years ago
Daniel Martí f4e356ab13 start hashing identifiers 5 years ago
Daniel Martí f47c12caba add a bit more docs 5 years ago
Daniel Martí a670f80fe9 error if the user forgot -trimpath 5 years ago
Daniel Martí f81b92a0fa start enforcing the link flags -w -s 5 years ago
Daniel Martí f5f72ef626 initial commit 5 years ago