Commit Graph

655 Commits (d2beda1f0016a11b0b0a364eff06a153eb4a448a)
 

Author SHA1 Message Date
pagran 4b73c37ed7
Add new obfuscators for literals - swap (#74)
Implement swap obfuscator
4 years ago
lu4p 50d24cdf51 Add float, int, and boolean literal obfuscation.
Add ast helper functions to reduce ast footprint.

Add binsubfloat and binsubint functions for testing.

Fixes #55.
4 years ago
Daniel Martí 3ea6fda837 CI: test on gotip
Since the new linker was failing on our crypto/aes shenanigans until the
recent commit to remove it for literal obfuscation.

Building Go does take about two minutes on the CI machine, but that's
fast enough. One can see the exact version that was used via the 'go
version' line.
4 years ago
lu4p 705f9d3a28 Fix byte array and untyped constant obfuscation.
Byte arrays were previously,
obfuscated as byte slices.

Untyped constants are now skipped,
because they cannot be replaced with typed variables.
4 years ago
lu4p d48bdbadae Use XOR instead of AES for literal obfuscation.
Implement a literal obfuscator interface,
to allow the easy addition of new encodings.

Add literal obfuscation for byte literals.

Choose a random obfuscator on literal obfuscation,
useful when multiple obfuscators are implemented.

Fixes #62
4 years ago
Daniel Martí 9c4b7d5a44 add the first benchmark and CONTRIBUTING doc 4 years ago
Pagran 0c5e0a8944 Fix 'A required privilege is not held by the client' on Windows 4 years ago
Daniel Martí bad4e52ac4 don't use CombinedOutput for 'go list -json'
Since sometimes it will output warnings to stderr even when succeeding,
such as when having to deal with cgo.

Fixes #27.
4 years ago
Daniel Martí 47b1bc8e6a minor code cleanup for position shuffling
Make the comments a bit more self-explanatory, and reduce unnecessary
verbosity.
4 years ago
lu4p b4ed621eed
Shuffle the order of top-level definitions. (#60) 4 years ago
lu4p b3616f19c4
fix implementedOutsideGo, fixes #56 (#59)
Injected functions were mistaken for functions implemented outside go.

Asm functions:
obj.Scope().Pos() == 0
obj.Scope().End() == 0

Injected functions:
obj.Scope().Pos() == 0
obj.Scope().End() == 1

We now check for the End instead of the Pos.
4 years ago
Andrew LeFevre 796f2b833e fix README mentioning old HidePanics function 4 years ago
Daniel Martí b171463a47 slightly less verbose runtime AST code
And rewrite a loop to be a bit simpler.
4 years ago
Andrew LeFevre 7ede37cc0b
add runtime API to suppress printing fatal errors
Fixes #50.
4 years ago
lu4p baae7a46fd
simplify detection of reflection 4 years ago
lu4p f1bf6f91ee
skip literals used in constant expressions
Fixes #39.
4 years ago
Daniel Martí c9bc7bac3b add a bit of code to aid debugging tests 4 years ago
Andrew LeFevre ee18db7ef1 only add crypto dependencies if -literals is passed 4 years ago
Daniel Martí 3e4f3821ea don't leak build version information via a const either
This requires a bit of extra magic to replace one constant in
runtime/internal/sys, but that was simple enough given that we can reuse
a lot of the code to parse the files and write them to a temporary dir.

We can also drop the -X flags, as runtime.buildVersion is based on the
constant that we replace here.

Fixes #44, again.
4 years ago
Daniel Martí 442eb4e139 speed up builds with the compiler's -dwarf=false flag
Generating DWARF in the compiler object files could take as much as 10%
extra CPU time, while we ignore it entirely at the link stage.

Speeds up 'go test -short' from ~19.5s to ~18.5s on my laptop.
4 years ago
Daniel Martí ccd46404c0 improve binsubstr error messages a bit
By printing all the strings that failed at once, not just the first.
4 years ago
lu4p 44f638e84d
upgrade dependencies 4 years ago
Daniel Martí 51550e98e8 README: simplify and update with the latest changes 4 years ago
Daniel Martí 649cc2f6ba strip Go version information from the binary too
Fixes #44.
4 years ago
Daniel Martí c7d1fc7c60 strip buildid information from linked binaries
Otherwise, one can use 'go tool buildid' to obtain the main package's
build ID, which can make de-obfuscating the main package much simpler.

Fixes #43.
4 years ago
lu4p 199d24d24f
use fmt's %q to encode []byte literals
I now implemented and tested hex encoded strings, binary literals, and fmt.Sprintf("%q", data).
In the case of garble all produce the exact same binary size.

I decided to use %q because it is the simplest, leads to the smallest garbled code file size size
of the three, and is faster at compile time than binary literals.

It looks like:

    var ztN0xdMLL = garbleDecrypt([]byte("\xaf\xbd\x01\\&\x14\xab\xeb\x94\x10Q\xf2H#\xde\x17\a\x8f\x89MmZs\u0088\xcfw\xba?\x9e\xe1\x81\x1eպD\xe1@\xf2\x8d\xe3Ije\xca\bB\xbey\x8b"))

From the fmt docs:

    String and slice of bytes (treated equivalently with these verbs):
    [...]
    %q    a double-quoted string safely escaped with Go syntax

Fixes #40.
4 years ago
lu4p fdc7f97db8
use binary literals instead of hex strings
Fixes #40
4 years ago
lu4p 234174b418
don't obfuscate some literals which might break typechecking 4 years ago
lu4p 4c64b13506
make -seed=random use the same random seed for all packages
Otherwise, a different random seed per package will break imported names.
4 years ago
lu4p 0cf8d4e7a6
add seed flag to control how builds are reproducible
Fixes #26.
4 years ago
Daniel Martí 5604a2aa9e avoid importing fmt in strings test
Reduces its 'go test -short' time from ~3s to ~2.4s on my laptop, since
we have to compile fewer dependencies.
4 years ago
Daniel Martí a09b197fe2 remove the code to handle a nil file.Imports
I could not reproduce the supposed panic, even after I was able to reach
a nil x.Imports in that line in question with the modified test.
4 years ago
Daniel Martí 1bb85bbf9b simplify the code to obfuscate literals a bit 4 years ago
lu4p dd1fc4ed87
don't replace all consts with vars
In some cases, such as iotas or when constants are later required to be constants,
we could break compilation. Be more conservative.

Fixes #32.
4 years ago
Nicholas Jones ecbcc61a62
handle embedded struct fields with universe scope
Whilst it may not be particularly common, it is legal to embed fields
where the type has universe scope (e.g. int, error, etc). This can
cause a panic in 2 difference places:

- When embedding `error`, a named type is resolved but the package is
nil. The call to `pkg.Name()` results in a panic
- When embedding a basic type such as `int`, no named type is resolved
at all. The call to `namedType(obj.Type()).Obj()` results in a panic

I'm assuming it is OK to return early when a named type cannot be
resolved.. we could let it continue but I think `pkg` should be set to
nil to be correct, so it'd end up returning straight away anyway.
4 years ago
Daniel Martí 04e8beed32 testdata: add sections to scripts/test.txt 4 years ago
Daniel Martí c6643d37f9 simplify and tidy up the string obfuscation code
Mainly removing unnecessary indentation and newlines, but also other
minor things like making error handling a bit more consistent.
4 years ago
lu4p 65ceb9b7ca
allow easy inpection of garbled code
Fixes #17.
4 years ago
lu4p 077d02d43a
add basic literal obfuscation, starting with strings
Fixes #16.
4 years ago
Daniel Martí 462f60a307 sto pusing -toolexec directly in the tests
Since we introduced $GARBLE_DIR, we stopped recommending the use of
toolexec directly. It's still possible to set up the right flags and env
vars, but that will be a moving target.

In particular, string obfuscation in #16 will require using $GARBLE_DIR
in more scenarios. A work-in-progress patch for string obfuscation
triggered this test script to start failing for the reason above.

While at it, we don't care about what the second build contains, since
we already compare it with the previous build.
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í e4b58b1452 reduce unnecessary std imports in tests
Since we have to recompile all dependencies, this reduces a substantial
amount of work, reducing 'go test -short' time from ~16s to ~12s on my
laptop.
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í 3c97725ccc skip plugin test case on Windows
Spotted by CI.
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