diff --git a/internal/literals/obfuscators.go b/internal/literals/obfuscators.go index ad73809..7e11100 100644 --- a/internal/literals/obfuscators.go +++ b/internal/literals/obfuscators.go @@ -18,11 +18,11 @@ type obfuscator interface { var ( // obfuscators contains all types which implement the obfuscator Interface obfuscators = []obfuscator{ - xor{}, + simple{}, swap{}, split{}, - xorShuffle{}, - xorSeed{}, + shuffle{}, + seed{}, } envGarbleSeed = os.Getenv("GARBLE_SEED") ) diff --git a/internal/literals/xor_seed.go b/internal/literals/seed.go similarity index 95% rename from internal/literals/xor_seed.go rename to internal/literals/seed.go index 1c97a49..18bd2b9 100644 --- a/internal/literals/xor_seed.go +++ b/internal/literals/seed.go @@ -7,12 +7,12 @@ import ( ah "mvdan.cc/garble/internal/asthelper" ) -type xorSeed struct{} +type seed struct{} // check that the obfuscator interface is implemented -var _ obfuscator = xorSeed{} +var _ obfuscator = seed{} -func (x xorSeed) obfuscate(data []byte) *ast.BlockStmt { +func (seed) obfuscate(data []byte) *ast.BlockStmt { seed := genRandByte() originalSeed := seed diff --git a/internal/literals/xor_shuffle.go b/internal/literals/shuffle.go similarity index 92% rename from internal/literals/xor_shuffle.go rename to internal/literals/shuffle.go index 28f7a60..075839b 100644 --- a/internal/literals/xor_shuffle.go +++ b/internal/literals/shuffle.go @@ -8,12 +8,12 @@ import ( ah "mvdan.cc/garble/internal/asthelper" ) -type xorShuffle struct{} +type shuffle struct{} // check that the obfuscator interface is implemented -var _ obfuscator = xorShuffle{} +var _ obfuscator = shuffle{} -func (x xorShuffle) obfuscate(data []byte) *ast.BlockStmt { +func (shuffle) obfuscate(data []byte) *ast.BlockStmt { key := make([]byte, len(data)) genRandBytes(key) diff --git a/internal/literals/xor.go b/internal/literals/simple.go similarity index 87% rename from internal/literals/xor.go rename to internal/literals/simple.go index 092728f..e7e9d88 100644 --- a/internal/literals/xor.go +++ b/internal/literals/simple.go @@ -7,12 +7,12 @@ import ( ah "mvdan.cc/garble/internal/asthelper" ) -type xor struct{} +type simple struct{} // check that the obfuscator interface is implemented -var _ obfuscator = xor{} +var _ obfuscator = simple{} -func (x xor) obfuscate(data []byte) *ast.BlockStmt { +func (simple) obfuscate(data []byte) *ast.BlockStmt { key := make([]byte, len(data)) genRandBytes(key) @@ -21,7 +21,7 @@ func (x xor) obfuscate(data []byte) *ast.BlockStmt { data[i] = evalOperator(op, data[i], b) } - return &ast.BlockStmt{List: []ast.Stmt{ + return ah.BlockStmt( &ast.AssignStmt{ Lhs: []ast.Expr{ah.Ident("key")}, Tok: token.DEFINE, @@ -45,5 +45,5 @@ func (x xor) obfuscate(data []byte) *ast.BlockStmt { }, }}, }, - }} + ) } diff --git a/internal/literals/split.go b/internal/literals/split.go index 1ff99d2..39816b6 100644 --- a/internal/literals/split.go +++ b/internal/literals/split.go @@ -66,7 +66,7 @@ func encryptChunks(chunks [][]byte, op token.Token, key byte) { } } -func (x split) obfuscate(data []byte) *ast.BlockStmt { +func (split) obfuscate(data []byte) *ast.BlockStmt { var chunks [][]byte // Short arrays should be divided into single-byte fragments if len(data)/maxChunkSize < minCaseCount { @@ -205,5 +205,6 @@ func (x split) obfuscate(data []byte) *ast.BlockStmt { Tag: ah.Ident("i"), Body: ah.BlockStmt(shuffleStmts(switchCases...)...), }), - }) + }, + ) } diff --git a/internal/literals/swap.go b/internal/literals/swap.go index 91b585c..fec000e 100644 --- a/internal/literals/swap.go +++ b/internal/literals/swap.go @@ -55,7 +55,7 @@ func generateSwapCount(dataLen int) int { return swapCount } -func (x swap) obfuscate(data []byte) *ast.BlockStmt { +func (swap) obfuscate(data []byte) *ast.BlockStmt { swapCount := generateSwapCount(len(data)) shiftKey := genRandByte()