From 552a6bcfb02426177ec8e5fd118a4e79aeb96d5f Mon Sep 17 00:00:00 2001 From: lu4p Date: Tue, 1 Jun 2021 16:00:45 +0200 Subject: [PATCH] Obfuscate literals in string slices and arrays Fixes #354 --- internal/literals/literals.go | 2 +- testdata/scripts/literals.txt | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/literals/literals.go b/internal/literals/literals.go index 92e4c51..df41c25 100644 --- a/internal/literals/literals.go +++ b/internal/literals/literals.go @@ -140,7 +140,7 @@ func Obfuscate(file *ast.File, info *types.Info, fset *token.FileSet, ignoreObj case *ast.BasicLit: switch cursor.Name() { - case "Values", "Rhs", "Value", "Args", "X", "Y", "Results": + case "Values", "Rhs", "Value", "Args", "X", "Y", "Results", "Elts": default: return true // we don't want to obfuscate imports etc. } diff --git a/testdata/scripts/literals.txt b/testdata/scripts/literals.txt index 8054e1d..e2e8a06 100644 --- a/testdata/scripts/literals.txt +++ b/testdata/scripts/literals.txt @@ -5,7 +5,7 @@ exec ./main$exe cmp stderr main.stderr binsubstr main$exe 'Skip this block' 'also skip this' 'skip typed const' 'skip typed var' 'skip typed var assign' 'stringTypeField strType' 'stringType lambda func return' 'testMap1 key' 'testMap2 key' 'testMap3 key' 'testMap1 value' 'testMap3 value' 'testMap1 new value' 'testMap3 new value' 'stringType func param' 'stringType return' 'skip untyped const' -! binsubstr main$exe 'garbleDecrypt' 'Lorem' 'dolor' 'first assign' 'second assign' 'First Line' 'Second Line' 'map value' 'to obfuscate' 'also obfuscate' 'stringTypeField String' +! binsubstr main$exe 'garbleDecrypt' 'Lorem' 'dolor' 'first assign' 'second assign' 'First Line' 'Second Line' 'map value' '1: literal in' 'an array' '2: literal in' 'a slice' 'to obfuscate' 'also obfuscate' 'stringTypeField String' [short] stop # checking that the build is reproducible is slow @@ -131,6 +131,13 @@ func main() { typedTest() constantTest() byteTest() + + strArray := [2]string{"1: literal in", "an array"} + println(strArray[0], strArray[1]) + strSlice := []string{"2: literal in", "a slice"} + println(strSlice[0], strSlice[1]) + emptyStrSlice := []string{""} + print(emptyStrSlice[0]) } type stringType string @@ -330,3 +337,5 @@ foo 12,13, 12,13, 12,13,0,0, +1: literal in an array +2: literal in a slice