You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
1.9 KiB
Plaintext
93 lines
1.9 KiB
Plaintext
env GOPRIVATE=test/main
|
|
|
|
garble build
|
|
exec ./main
|
|
cmp stderr main.stderr
|
|
|
|
! binsubstr main$exe 'obfuscatedFunc' 'ObfuscatedFunc'
|
|
|
|
[short] stop # no need to verify this with -short
|
|
|
|
go build
|
|
exec ./main
|
|
cmp stderr main.stderr
|
|
|
|
-- go.mod --
|
|
module test/main
|
|
|
|
go 1.16
|
|
|
|
-- a.go --
|
|
package main
|
|
|
|
// Call a function which is linknamed to another symbol.
|
|
// What's special here is that we obfuscate this call before the function declaration.
|
|
// If we decide not to obfuscate the name in the function declaration,
|
|
// we shouldn't obfuscate the name here either.
|
|
func linknameCalledInPkg() {
|
|
println(obfuscatedFunc())
|
|
}
|
|
|
|
-- main.go --
|
|
package main
|
|
|
|
import (
|
|
_ "os/exec"
|
|
_ "strings"
|
|
_ "unsafe"
|
|
|
|
"test/main/imported"
|
|
)
|
|
|
|
// A linkname to an external non-obfuscated func.
|
|
//go:linkname byteIndex strings.IndexByte
|
|
func byteIndex(s string, c byte) int
|
|
|
|
// A linkname to an external non-obfuscated non-exported func.
|
|
//go:linkname interfaceEqual os/exec.interfaceEqual
|
|
func interfaceEqual(a, b interface{}) bool
|
|
|
|
// A linkname to an external obfuscated func.
|
|
//go:linkname obfuscatedFunc test/main/imported.ObfuscatedFuncImpl
|
|
func obfuscatedFunc() string
|
|
|
|
// A linkname to an entirely made up name, implemented elsewhere.
|
|
//go:linkname renamedFunc madeup.newName
|
|
func renamedFunc() string
|
|
|
|
func main() {
|
|
println(byteIndex("01234", '3'))
|
|
println(interfaceEqual("Sephiroth", 7))
|
|
println(obfuscatedFunc())
|
|
println(renamedFunc())
|
|
println(imported.ByteIndex("01234", '3'))
|
|
linknameCalledInPkg()
|
|
}
|
|
-- imported/imported.go --
|
|
package imported
|
|
|
|
import (
|
|
_ "unsafe"
|
|
)
|
|
|
|
func ObfuscatedFuncImpl() string {
|
|
return "obfuscated func"
|
|
}
|
|
|
|
//go:linkname renamedFunc madeup.newName
|
|
func renamedFunc() string {
|
|
return "renamed func"
|
|
}
|
|
|
|
// A linkname to an external non-obfuscated func.
|
|
// Different from byteIndex, as we call this from an importer package.
|
|
//go:linkname ByteIndex strings.IndexByte
|
|
func ByteIndex(s string, c byte) int
|
|
-- main.stderr --
|
|
3
|
|
false
|
|
obfuscated func
|
|
renamed func
|
|
3
|
|
obfuscated func
|