Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only obfuscate literals in packages to obfuscate #428

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,9 @@ func (tf *transformer) recordType(t types.Type) {

// transformGo obfuscates the provided Go syntax file.
func (tf *transformer) transformGo(file *ast.File) *ast.File {
if opts.ObfuscateLiterals {
// Only obfuscate the literals here if the flag is on
// and if the package in question is to be obfuscated.
if opts.ObfuscateLiterals && curPkg.ToObfuscate {
file = literals.Obfuscate(file, tf.info, fset, tf.ignoreObjects)
}

Expand Down
15 changes: 11 additions & 4 deletions testdata/scripts/gogarble.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ env GOPRIVATE=match-absolutely/nothing
! garble build -o=out ./standalone
stderr '^GOGARBLE="match-absolutely/nothing" does not match any packages to be built$'

# A build where just some packages are obfuscated.
env GOGARBLE=test/main/imported
garble build ./importer
garble -literals build -o=out ./importer

! binsubstr out 'some long string to obfuscate'
binsubstr out 'some long string to not obfuscate'

# Obfuscated packages which import non-obfuscated std packages.
# Some of the imported std packages use "import maps" due to vendoring,
Expand Down Expand Up @@ -49,15 +53,18 @@ package main

func main() {}
-- importer/importer.go --
package importer
package main

import "test/main/imported"

var _ = imported.Name
func main() {
println(imported.LongString)
println("some long string to not obfuscate")
}
-- imported/imported.go --
package imported

var Name = "value"
var LongString = "some long string to obfuscate"
-- stdimporter/main.go --
package main

Expand Down