simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
env GOPRIVATE=test/main
|
|
|
|
|
|
|
|
garble build
|
|
|
|
exec ./main
|
|
|
|
! stdout 'someverylongmain\.go|other_file_name|is sorted'
|
|
|
|
|
|
|
|
! binsubstr main$exe 'someverylongmain.go' 'other_file_name'
|
simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
|
|
|
|
[short] stop # no need to verify this with -short
|
|
|
|
|
|
|
|
go build
|
|
|
|
exec ./main
|
|
|
|
stdout 'someverylongmain.go'
|
simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
stdout 'other_file_name'
|
|
|
|
stdout ':19: main'
|
|
|
|
stdout 'initPositions is sorted'
|
|
|
|
stdout 'varPositions is sorted'
|
simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
|
|
|
|
-- go.mod --
|
|
|
|
module test/main
|
|
|
|
|
|
|
|
go 1.16
|
|
|
|
-- someverylongmain.go --
|
simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
"sort"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _, globalFile, globalLine, _ = runtime.Caller(0)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
_, file, line, _ := runtime.Caller(0)
|
|
|
|
fmt.Printf("%s:%d: init\n", file, line)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
fmt.Printf("%s:%d: global\n", globalFile, globalLine)
|
|
|
|
|
|
|
|
_, file, line, _ := runtime.Caller(0)
|
|
|
|
fmt.Printf("%s:%d: main\n", file, line)
|
|
|
|
|
|
|
|
funcDecl()
|
|
|
|
funcVar()
|
|
|
|
|
|
|
|
// initPositions is filled by ten consecutive funcs.
|
simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
// If we are not shuffling or obfuscating line numbers,
|
|
|
|
// this list will be sorted.
|
|
|
|
// If we are, it's extremely unlikely it would remain sorted.
|
|
|
|
if sort.IsSorted(sort.StringSlice(initPositions)) {
|
|
|
|
fmt.Println("initPositions is sorted")
|
simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
}
|
|
|
|
|
|
|
|
// Same as the above, but with vars.
|
|
|
|
if sort.IsSorted(sort.StringSlice(varPositions)) {
|
|
|
|
fmt.Println("varPositions is sorted")
|
simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
}
|
|
|
|
|
|
|
|
// Adding "/*text*/" comments here is tricky,
|
|
|
|
// as we don't want to turn "a/b" into "a//*text*/b".
|
|
|
|
// We need "a/ /*text*/b" to preserve the syntax.
|
|
|
|
// The nested expression is needed to prevent spaces.
|
|
|
|
fmt.Printf("%v\n", 10*float64(3.0)/float64(4.0))
|
simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
}
|
|
|
|
-- other_file_name.go --
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
func funcDecl() {
|
|
|
|
_, file, line, _ := runtime.Caller(0)
|
|
|
|
fmt.Printf("%s:%d: func\n", file, line)
|
|
|
|
}
|
|
|
|
|
|
|
|
var funcVar = func() {
|
|
|
|
_, file, line, _ := runtime.Caller(0)
|
|
|
|
fmt.Printf("%s:%d: func var\n", file, line)
|
|
|
|
}
|
|
|
|
|
|
|
|
var initPositions []string
|
simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
|
|
|
|
func curPos() string {
|
|
|
|
_, file, line, _ := runtime.Caller(1)
|
|
|
|
return fmt.Sprintf("%s:%d", file, line)
|
simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
}
|
|
|
|
|
|
|
|
func init() { initPositions = append(initPositions, curPos()) }
|
|
|
|
func init() { initPositions = append(initPositions, curPos()) }
|
|
|
|
func init() { initPositions = append(initPositions, curPos()) }
|
|
|
|
func init() { initPositions = append(initPositions, curPos()) }
|
|
|
|
func init() { initPositions = append(initPositions, curPos()) }
|
|
|
|
func init() { initPositions = append(initPositions, curPos()) }
|
|
|
|
func init() { initPositions = append(initPositions, curPos()) }
|
|
|
|
func init() { initPositions = append(initPositions, curPos()) }
|
|
|
|
func init() { initPositions = append(initPositions, curPos()) }
|
|
|
|
func init() { initPositions = append(initPositions, curPos()) }
|
|
|
|
|
|
|
|
var varLine0 = curPos()
|
|
|
|
var varLine1 = curPos()
|
|
|
|
var varLine2 = curPos()
|
|
|
|
var varLine3 = curPos()
|
|
|
|
var varLine4 = curPos()
|
|
|
|
var varLine5 = curPos()
|
|
|
|
var varLine6 = curPos()
|
|
|
|
var varLine7 = curPos()
|
|
|
|
var varLine8 = curPos()
|
|
|
|
var varLine9 = curPos()
|
|
|
|
|
|
|
|
var varPositions = []string{
|
simplify, improve, and test line obfuscation (#239)
First, remove the shuffling of the declarations list within each file.
This is what we used at the very start to shuffle positions. Ever since
we started obfuscating positions via //line comments, that has been
entirely unnecessary.
Second, add a proper test that will fail if we don't obfuscate line
numbers well enough. Filenames were already decently covered by other
tests.
Third, simplify the line obfuscation code. It does not require
astutil.Apply, and ranging over file.Decls is easier.
Finally, also obfuscate the position of top-level vars, since we only
used to do it for top-level funcs. Without that fix, the test would fail
as varLines was unexpectedly sorted.
3 years ago
|
|
|
varLine0, varLine1, varLine2, varLine3, varLine4,
|
|
|
|
varLine5, varLine6, varLine7, varLine8, varLine9,
|
|
|
|
}
|