mirror of
https://github.com/burrowers/garble.git
synced 2026-04-22 23:57:14 +08:00
Make -debugdir also output the unobfuscated source tree
This makes the unobfuscated state easily accessible, for debugging. Obfuscated code is output to: `./<debugdir>/garbled` The original source code is output to: `./<debugdir>/source` Also enable caching for debugdir to allow for faster iteration.
This commit is contained in:
committed by
Daniel Martí
parent
e693cd0632
commit
53c5f022b4
Vendored
+7
-7
@@ -7,25 +7,25 @@ exec ./main
|
||||
cmp stderr main.stderr
|
||||
|
||||
# simple check to ensure that control flow will work. Must be a minimum of 10 goto's
|
||||
grep 'goto _s2a_l10' $WORK/debug/test/main/GARBLE_controlflow.go
|
||||
grep 'goto _s2a_l10' $WORK/debug/garbled/test/main/GARBLE_controlflow.go
|
||||
|
||||
# obfuscated function must be removed from original file
|
||||
! grep 'main\(\)' $WORK/debug/test/main/garble_main.go
|
||||
! grep 'main\(\)' $WORK/debug/garbled/test/main/garble_main.go
|
||||
# original file must contains empty function
|
||||
grep '\_\(\)' $WORK/debug/test/main/garble_main.go
|
||||
grep '\_\(\)' $WORK/debug/garbled/test/main/garble_main.go
|
||||
|
||||
# obfuscated file must contains interface for unexported interface emulation
|
||||
grep 'GoString\(\) string' $WORK/debug/test/main/GARBLE_controlflow.go
|
||||
grep 'String\(\) string' $WORK/debug/test/main/GARBLE_controlflow.go
|
||||
grep 'GoString\(\) string' $WORK/debug/garbled/test/main/GARBLE_controlflow.go
|
||||
grep 'String\(\) string' $WORK/debug/garbled/test/main/GARBLE_controlflow.go
|
||||
|
||||
# control flow obfuscation should work correctly with literals obfuscation
|
||||
! binsubstr main$exe 'correct name'
|
||||
|
||||
|
||||
# check xor hardening
|
||||
grep '\(\w+ \^ \d+\)' $WORK/debug/test/main/GARBLE_controlflow.go
|
||||
grep '\(\w+ \^ \d+\)' $WORK/debug/garbled/test/main/GARBLE_controlflow.go
|
||||
# check delegate table hardening
|
||||
grep 'func\(int\) int' $WORK/debug/test/main/GARBLE_controlflow.go
|
||||
grep 'func\(int\) int' $WORK/debug/garbled/test/main/GARBLE_controlflow.go
|
||||
|
||||
-- go.mod --
|
||||
module test/main
|
||||
|
||||
Vendored
+17
-10
@@ -1,11 +1,18 @@
|
||||
exec garble -debugdir=debug1 build
|
||||
exists 'debug1/test/main/imported/imported.go' 'debug1/test/main/main.go' 'debug1/reflect/type.go'
|
||||
exists 'debug1/runtime/error.go' 'debug1/runtime/funcdata.h' 'debug1/runtime/asm.s'
|
||||
[amd64] exists 'debug1/runtime/cpuflags_amd64.go' 'debug1/runtime/asm_amd64.s'
|
||||
[!amd64] ! exists 'debug1/runtime/cpuflags_amd64.go' 'debug1/runtime/asm_amd64.s'
|
||||
! grep ImportedFunc $WORK/debug1/test/main/imported/imported.go
|
||||
! grep ImportedFunc $WORK/debug1/test/main/main.go
|
||||
! grep 'some comment' $WORK/debug1/test/main/main.go
|
||||
exists 'debug1/source/test/main/imported/imported.go' 'debug1/source/test/main/main.go' 'debug1/source/reflect/type.go'
|
||||
exists 'debug1/source/runtime/error.go' 'debug1/source/runtime/funcdata.h' 'debug1/source/runtime/asm.s'
|
||||
[amd64] exists 'debug1/source/runtime/cpuflags_amd64.go' 'debug1/source/runtime/asm_amd64.s'
|
||||
[!amd64] ! exists 'debug1/source/runtime/cpuflags_amd64.go' 'debug1/source/runtime/asm_amd64.s'
|
||||
exists 'debug1/garbled/test/main/imported/imported.go' 'debug1/garbled/test/main/main.go' 'debug1/garbled/reflect/type.go'
|
||||
exists 'debug1/garbled/runtime/error.go' 'debug1/garbled/runtime/funcdata.h' 'debug1/garbled/runtime/asm.s'
|
||||
[amd64] exists 'debug1/garbled/runtime/cpuflags_amd64.go' 'debug1/garbled/runtime/asm_amd64.s'
|
||||
[!amd64] ! exists 'debug1/garbled/runtime/cpuflags_amd64.go' 'debug1/garbled/runtime/asm_amd64.s'
|
||||
grep ImportedFunc $WORK/debug1/source/test/main/imported/imported.go
|
||||
grep ImportedFunc $WORK/debug1/source/test/main/main.go
|
||||
grep 'some comment' $WORK/debug1/source/test/main/main.go
|
||||
! grep ImportedFunc $WORK/debug1/garbled/test/main/imported/imported.go
|
||||
! grep ImportedFunc $WORK/debug1/garbled/test/main/main.go
|
||||
! grep 'some comment' $WORK/debug1/garbled/test/main/main.go
|
||||
|
||||
# We should refuse to delete non-empty directories which weren't created
|
||||
# by an earlier invocation of garble -debugdir, as that could lead to data loss.
|
||||
@@ -17,11 +24,11 @@ exists notdebug/subdir/important_data.txt
|
||||
[short] stop
|
||||
|
||||
# Sources from previous builds should be deleted
|
||||
cp $WORK/debug1/test/main/main.go $WORK/debug1/some_file_from_prev_build.go
|
||||
cp $WORK/debug1/garbled/test/main/main.go $WORK/debug1/some_file_from_prev_build.go
|
||||
|
||||
exec garble -debugdir=debug1 build -v
|
||||
stderr 'test/main' # we force rebuilds with -debugdir
|
||||
exec garble -debugdir=debug1 build
|
||||
! exists $WORK/debug1/some_file_from_prev_build.go
|
||||
exists 'debug1/source/test/main/main.go' 'debug1/garbled/test/main/main.go'
|
||||
|
||||
-- notdebug/important_data.txt --
|
||||
This file should not be deleted by -debugdir.
|
||||
|
||||
Vendored
+6
-6
@@ -38,23 +38,23 @@ cmp stderr main.stderr
|
||||
# Check obfuscators.
|
||||
|
||||
# Xor obfuscator. Detect a[i] = a[i] (^|-|+) b[i]
|
||||
grep '^\s+\w+\[\w+\] = \w+\[\w+\] [\^\-+] \w+$' debug1/test/main/extra_literals.go
|
||||
grep '^\s+\w+\[\w+\] = \w+\[\w+\] [\^\-+] \w+$' debug1/garbled/test/main/extra_literals.go
|
||||
|
||||
# Swap obfuscator. Detect [...]byte|uint16|uint32|uint64{...}
|
||||
grep '^\s+\w+ := \[\.{3}\](byte|uint16|uint32|uint64)\{[0-9\s,]+\}$' debug1/test/main/extra_literals.go
|
||||
grep '^\s+\w+ := \[\.{3}\](byte|uint16|uint32|uint64)\{[0-9\s,]+\}$' debug1/garbled/test/main/extra_literals.go
|
||||
|
||||
# Split obfuscator. Detect decryptKey ^= i * counter
|
||||
grep '^\s+\w+ \^= \w+ \* \w+$' debug1/test/main/extra_literals.go
|
||||
grep '^\s+\w+ \^= \w+ \* \w+$' debug1/garbled/test/main/extra_literals.go
|
||||
|
||||
# XorShuffle obfuscator. Detect data = append(data, x[? ^ idxKey[?]] (^|-|+) y[? ^ idxKey[?]]...).
|
||||
# Note that the line obfuscator adds an inline comment before the call.
|
||||
grep '^(\s+)?\w+ = .*\bappend\(\w+,(\s+\w+\[\d+\^\s.+\][\^\-+]\w+\[\d+\^\s.+\],?)+\)$' debug1/test/main/extra_literals.go
|
||||
grep '^(\s+)?\w+ = .*\bappend\(\w+,(\s+\w+\[\d+\^\s.+\][\^\-+]\w+\[\d+\^\s.+\],?)+\)$' debug1/garbled/test/main/extra_literals.go
|
||||
|
||||
# XorSeed obfuscator. Detect type decFunc func(byte) decFunc
|
||||
grep '^\s+type \w+ func\(byte\) \w+$' debug1/test/main/extra_literals.go
|
||||
grep '^\s+type \w+ func\(byte\) \w+$' debug1/garbled/test/main/extra_literals.go
|
||||
|
||||
# Check external keys
|
||||
grep 'garbleExternalKey' debug1/test/main/extra_literals.go
|
||||
grep 'garbleExternalKey' debug1/garbled/test/main/extra_literals.go
|
||||
|
||||
# Finally, sanity check that we can build all of std with -literals.
|
||||
# Analogous to gogarble.txt.
|
||||
|
||||
Reference in New Issue
Block a user