From 6f2da836a044908718ca89a3317831ea9bd7ba67 Mon Sep 17 00:00:00 2001 From: Pagran <67878280+pagran@users.noreply.github.com> Date: Fri, 14 Aug 2020 01:07:35 +0300 Subject: [PATCH] Remove file renaming Update tests Add new lines test --- main.go | 1 - testdata/scripts/basic.txt | 4 +-- testdata/scripts/debugdir.txt | 7 ++-- testdata/scripts/lines.txt | 62 +++++++++++++++++++++++++++++++++++ testdata/scripts/literals.txt | 10 +++--- testdata/scripts/syntax.txt | 2 +- 6 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 testdata/scripts/lines.txt diff --git a/main.go b/main.go index 527b0cf..90af7d3 100644 --- a/main.go +++ b/main.go @@ -513,7 +513,6 @@ func transformCompile(args []string) ([]string, error) { protectFileName = true file = transformLineInfo(i, file) file = transformGo(file, info, blacklist) - name = fmt.Sprintf("z%d.go", i) // Uncomment for some quick debugging. Do not delete. // fmt.Fprintf(os.Stderr, "\n-- %s/%s --\n", pkgPath, origName) diff --git a/testdata/scripts/basic.txt b/testdata/scripts/basic.txt index e70d43e..932cb94 100644 --- a/testdata/scripts/basic.txt +++ b/testdata/scripts/basic.txt @@ -27,7 +27,7 @@ stdout 'unknown' ! stdout $gofullversion # The binary can't contain the version string either. -! binsubstr main$exe ${WORK@R} 'globalVar' 'globalFunc' $gofullversion 'z0.go' +! binsubstr main$exe ${WORK@R} 'main.go' 'globalVar' 'globalFunc' $gofullversion [short] stop # checking that the build is reproducible is slow @@ -50,7 +50,7 @@ cmp stderr main.stderr # The default build includes full non-trimmed paths, as well as our names. # Only check $WORK on non-windows, because it's difficult to do it there. -binsubstr main$exe 'globalVar' 'globalFunc' $gofullversion +binsubstr main$exe 'main.go' 'globalVar' 'globalFunc' $gofullversion [!windows] binsubstr main$exe ${WORK@R} -- main.go -- diff --git a/testdata/scripts/debugdir.txt b/testdata/scripts/debugdir.txt index ab15769..08df254 100644 --- a/testdata/scripts/debugdir.txt +++ b/testdata/scripts/debugdir.txt @@ -1,8 +1,7 @@ garble -debugdir ./test1 build -exists 'test1/test/imported/z0.go' 'test1/main/z0.go' -! grep ImportedFunc $WORK/test1/test/imported/z0.go -! grep ImportedFunc $WORK/test1/main/z0.go - +exists 'test1/test/imported/imported.go' 'test1/main/main.go' +! grep ImportedFunc $WORK/test1/test/imported/imported.go +! grep ImportedFunc $WORK/test1/main/main.go -- go.mod -- module test diff --git a/testdata/scripts/lines.txt b/testdata/scripts/lines.txt new file mode 100644 index 0000000..0c8a70c --- /dev/null +++ b/testdata/scripts/lines.txt @@ -0,0 +1,62 @@ +garble -debugdir=.obf-src build + +env TINY_PATTERN='^\/\/line :1$' +env DEFAULT_PATTERN='^\/\/line \w\.go:[1-9][0-9]*$' +env DEFAULT_STACK_PATTERN='^\t\w\.go:[1-9][0-9]*(\s\+0x[0-9a-f]+)?' +env TINY_STACK_PATTERN='^\t\?\?:[0-9][0-9]*(\s\+0x[0-9a-f]+)?$' + +# Default mode + +# Check for file name leak protection +grep $TINY_PATTERN $WORK/.obf-src/main/main.go +grep $TINY_PATTERN $WORK/.obf-src/main/main1.go + +# Check for default line obfuscation +grep $DEFAULT_PATTERN $WORK/.obf-src/main/main.go +grep $DEFAULT_PATTERN $WORK/.obf-src/main/main1.go + +exec ./main$exe +cp stderr default.stderr +! grep 'main1?\.go' default.stderr +! grep $TINY_STACK_PATTERN default.stderr +grep $DEFAULT_STACK_PATTERN default.stderr + +# Tiny mode + +garble -tiny -debugdir=.obf-src build + +grep $TINY_PATTERN $WORK/.obf-src/main/main.go +grep $TINY_PATTERN $WORK/.obf-src/main/main1.go + +! grep $DEFAULT_PATTERN $WORK/.obf-src/main/main.go +! grep $DEFAULT_PATTERN $WORK/.obf-src/main/main1.go + +exec ./main$exe +cp stderr tiny.stderr +! grep 'main1?\.go' tiny.stderr +! grep $DEFAULT_STACK_PATTERN tiny.stderr +grep $TINY_STACK_PATTERN tiny.stderr + +-- go.mod -- +module main +-- main.go -- +package main + +import "runtime/debug" + +func dump1() { + debug.PrintStack() +} + +func main() { + dump1() + dump2() +} +-- main1.go -- +package main + +import "runtime/debug" + +func dump2() { + debug.PrintStack() +} \ No newline at end of file diff --git a/testdata/scripts/literals.txt b/testdata/scripts/literals.txt index 7ffb884..13109d5 100644 --- a/testdata/scripts/literals.txt +++ b/testdata/scripts/literals.txt @@ -37,19 +37,19 @@ cmp stderr normal.stderr # Check obfuscators # Xor obfuscator. Detect a[i] = a[i] (^|-|+) b[i] -grep '^\s+\w+\[\w+\] = \w+\[\w+\] [\^\-+] \w+$' .obf-src/main/z0.go +grep '^\s+\w+\[\w+\] = \w+\[\w+\] [\^\-+] \w+$' .obf-src/main/extraLiterals.go # Swap obfuscator. Detect [...]byte|uint16|uint32|uint64{...} -grep '^\s+\w+ := \[\.{3}\](byte|uint16|uint32|uint64)\{[0-9\s,]+\}$' .obf-src/main/z0.go +grep '^\s+\w+ := \[\.{3}\](byte|uint16|uint32|uint64)\{[0-9\s,]+\}$' .obf-src/main/extraLiterals.go # Split obfuscator. Detect decryptKey ^= i * counter -grep '^\s+\w+ \^= \w+ \* \w+$' .obf-src/main/z0.go +grep '^\s+\w+ \^= \w+ \* \w+$' .obf-src/main/extraLiterals.go # XorShuffle obfuscator. Detect data = append(data, x (^|-|+) y...) -grep '^\s+\w+ = append\(\w+,(\s+\w+\[\d+\][\^\-+]\w+\[\d+\],?)+\)$' .obf-src/main/z0.go +grep '^\s+\w+ = append\(\w+,(\s+\w+\[\d+\][\^\-+]\w+\[\d+\],?)+\)$' .obf-src/main/extraLiterals.go # XorSeed obfuscator. Detect type decFunc func(byte) decFunc -grep '^\s+type \w+ func\(byte\) \w+$' .obf-src/main/z0.go +grep '^\s+type \w+ func\(byte\) \w+$' .obf-src/main/extraLiterals.go -- go.mod -- diff --git a/testdata/scripts/syntax.txt b/testdata/scripts/syntax.txt index 7173a59..7e7da57 100644 --- a/testdata/scripts/syntax.txt +++ b/testdata/scripts/syntax.txt @@ -11,7 +11,7 @@ cmp stderr main.stderr ! binsubstr main$exe 'localName' 'globalConst' 'globalVar' 'globalType' 'valuable information' -binsubstr debug/main/z1.go 'localName' 'globalConst' +binsubstr debug/main/scopes.go 'localName' 'globalConst' -- go.mod -- module test/main