remove the code to handle a nil file.Imports

I could not reproduce the supposed panic, even after I was able to reach
a nil x.Imports in that line in question with the modified test.
pull/34/head
Daniel Martí 4 years ago
parent 1bb85bbf9b
commit a09b197fe2

@ -42,15 +42,8 @@ func obfuscateLiterals(files []*ast.File) []*ast.File {
}
x.Decls = append(x.Decls, funcStmt)
x.Decls = append(x.Decls, keyStmt(key))
if x.Imports == nil {
newDecls := []ast.Decl{cryptoAesImportSpec}
newDecls = append(newDecls, x.Decls...)
x.Decls = newDecls
} else {
astutil.AddImport(fset, x, "crypto/aes")
astutil.AddImport(fset, x, "crypto/cipher")
}
astutil.AddImport(fset, x, "crypto/aes")
astutil.AddImport(fset, x, "crypto/cipher")
addedToPkg = true
case *ast.BasicLit:

@ -1,6 +1,6 @@
garble -literals build main.go
exec ./main
garble -literals build
exec ./main$exe
cmp stdout main.stdout
! binsubstr main$exe 'Lorem' 'ipsum' 'dolor' 'first assign' 'second assign' 'First Line' 'Second Line' 'map value' 'to obfuscate' 'also obfuscate'
@ -11,9 +11,11 @@ binsubstr main$exe 'Skip this block,' 'also skip this'
# Also check that the binary is reproducible.
cp main$exe main_old$exe
rm main$exe
garble -literals build main.go
garble -literals build
bincmp main$exe main_old$exe
-- go.mod --
module test/main
-- main.go --
package main
@ -48,8 +50,6 @@ var array [arrayLen]byte
type typeAlias [arrayLen]byte
var variable = "ipsum"
func main() {
empty := ""
@ -83,6 +83,14 @@ func main() {
fmt.Println(i, foo, bar)
}
-- decl_without_imports.go --
package main
// The lack of imports is an edge case, since we have to add imports like
// crypto/aes.
var variable = "ipsum"
-- main.stdout --
Lorem
First Line
@ -96,4 +104,4 @@ also obfuscate
map value
another literal
Skip this block, also skip this
1 0 1
1 0 1

Loading…
Cancel
Save