testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
env GOPRIVATE='test/main,private.source/*'
|
|
|
|
|
|
|
|
garble build -tags directives
|
|
|
|
exec ./main$exe
|
|
|
|
cmp stderr main.stderr
|
|
|
|
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
! binsubstr main$exe 'localName' 'globalConst' 'globalVar' 'globalType' 'valuable information' 'private.source' 'remoteIntReturn' 'intReturn'
|
|
|
|
binsubstr main$exe 'magicFunc'
|
|
|
|
|
|
|
|
[short] stop # no need to verify this with -short
|
|
|
|
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
# Check that the program works as expected without garble.
|
|
|
|
go build -tags directives
|
|
|
|
exec ./main$exe
|
|
|
|
cmp stderr main.stderr
|
|
|
|
|
|
|
|
binsubstr main$exe 'globalVar' # 'globalType' only matches on go < 1.15
|
|
|
|
! binsubstr main$exe 'localName' 'globalConst' 'remoteIntReturn' 'intReturn'
|
|
|
|
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
-- extra/go.mod --
|
|
|
|
module "private.source/extra"
|
|
|
|
-- extra/extra.go --
|
|
|
|
package extra
|
|
|
|
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
func Func() string {
|
|
|
|
return "This is a separate module to obfuscate."
|
|
|
|
}
|
|
|
|
-- go.mod --
|
|
|
|
module test/main
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
|
|
|
|
// We include an extra module to obfuscate, included in the same original source
|
|
|
|
// code via a replace directive.
|
|
|
|
replace private.source/extra => ./extra
|
|
|
|
-- main.go --
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"go/ast"
|
|
|
|
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
"private.source/extra"
|
|
|
|
"test/main/sub"
|
|
|
|
)
|
|
|
|
|
|
|
|
// This comment contains valuable information. Ensure it's not in the final binary.
|
|
|
|
var V interface{}
|
|
|
|
|
|
|
|
type T struct {
|
|
|
|
ast.Node
|
|
|
|
*ast.Ident
|
|
|
|
}
|
|
|
|
|
|
|
|
type EncodingT struct {
|
|
|
|
Foo int
|
|
|
|
}
|
|
|
|
|
|
|
|
type Embedded int
|
|
|
|
|
|
|
|
type Embedding struct {
|
|
|
|
Embedded
|
|
|
|
}
|
|
|
|
|
|
|
|
type embedded int
|
|
|
|
|
|
|
|
type embedding struct {
|
|
|
|
embedded
|
|
|
|
}
|
|
|
|
|
|
|
|
// embedded fields whose type is in the universe scope used to crash garble
|
|
|
|
type EmbeddingUniverseScope struct {
|
|
|
|
error
|
|
|
|
int
|
|
|
|
string
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
switch V := V.(type) {
|
|
|
|
case int:
|
|
|
|
var _ int = V
|
|
|
|
case nil:
|
|
|
|
println("nil case")
|
|
|
|
}
|
|
|
|
|
|
|
|
enc, _ := json.Marshal(EncodingT{Foo: 3})
|
|
|
|
println(string(enc))
|
|
|
|
scopesTest()
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
println(extra.Func())
|
|
|
|
sub.Test()
|
|
|
|
sub.TestDirectives()
|
|
|
|
}
|
|
|
|
|
|
|
|
-- scopes.go --
|
|
|
|
package main
|
|
|
|
|
|
|
|
const globalConst = 1
|
|
|
|
|
|
|
|
type globalType int
|
|
|
|
|
|
|
|
var (
|
|
|
|
globalVar = 1
|
|
|
|
globalVarTyped globalType = 1
|
|
|
|
)
|
|
|
|
|
|
|
|
func scopesTest() {
|
|
|
|
println(globalVar, globalConst, globalVarTyped)
|
|
|
|
const localNameConst = 1
|
|
|
|
|
|
|
|
localNameShort := 4
|
|
|
|
|
|
|
|
type localNameType int
|
|
|
|
|
|
|
|
var (
|
|
|
|
localNameVar = 5
|
|
|
|
localNameTypeVar localNameType = 1
|
|
|
|
)
|
|
|
|
|
|
|
|
println(localNameConst, localNameShort, localNameVar, localNameTypeVar, input("input"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func input(localNameParam string) (localNameReturn string) { return localNameParam }
|
|
|
|
|
|
|
|
-- sub/names.go --
|
|
|
|
package sub
|
|
|
|
|
|
|
|
var someGlobalVar0 = "0"
|
|
|
|
var someGlobalVar1 = "1"
|
|
|
|
var someGlobalVar2 = "2"
|
|
|
|
|
|
|
|
func Test() {
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
var A, B, C, D, E string
|
|
|
|
noop(A, B, C, D, E)
|
|
|
|
if someGlobalVar0 != "0" || someGlobalVar1 != "1" || someGlobalVar2 != "2"{
|
|
|
|
panic("name collision detected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func noop(...interface{}) {}
|
|
|
|
|
|
|
|
-- sub/directives.go --
|
|
|
|
// +build directives
|
|
|
|
|
|
|
|
package sub
|
|
|
|
|
|
|
|
import (
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
_ "unsafe"
|
|
|
|
_ "test/main/sub/a"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:linkname remoteIntReturn a.magicFunc
|
|
|
|
|
|
|
|
func remoteIntReturn() int
|
|
|
|
|
|
|
|
//go:noinline
|
|
|
|
func TestDirectives() {
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
if remoteIntReturn() != 42 {
|
|
|
|
panic("invalid result")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-- sub/a/directives.go --
|
|
|
|
// +build directives
|
|
|
|
|
|
|
|
package a
|
|
|
|
|
|
|
|
import _ "unsafe"
|
|
|
|
|
|
|
|
//go:linkname intReturn a.magicFunc
|
|
|
|
|
|
|
|
//go:noinline
|
|
|
|
func intReturn() int {
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
return 42
|
|
|
|
}
|
|
|
|
-- main.stderr --
|
|
|
|
nil case
|
|
|
|
{"Foo":3}
|
|
|
|
1 1 1
|
|
|
|
1 4 5 1 input
|
testdata: make syntax.txt pass when offline
The test intended to use an extra module to be obfuscated, rsc.io/quote,
which we were bundling in the local proxy as well. Unfortunately, the
use of GOPRIVATE also meant that we did not actually fetch the module
from the proxy, and we would instead do a full roundtrip to the internet
to "git clone" the actual upstream repository.
To prevent that roundtrip, instead use a locally replaced module. This
fits the syntax.txt test too, since it's one more edge case that we want
to make sure works well with garble. Since rsc.io/quote is used in
another test, simply make up our own tiny module.
Reduces a 'go test -run Syntax/syntax' run with warm cache from ~5s to
~0.5s, thanks to removing the multiple roundtrips. A warm 'go test' run
still sits at ~6s, since we still need that much CPU time in total.
While at it, fix a staticcheck warning and fix inconsistent indentation
in a couple of tests.
4 years ago
|
|
|
This is a separate module to obfuscate.
|