Remove xor from the name of literal obfuscators. (#91)

pull/92/head
lu4p 5 years ago committed by GitHub
parent 28adbaa73b
commit 870cde9a0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,11 +18,11 @@ type obfuscator interface {
var ( var (
// obfuscators contains all types which implement the obfuscator Interface // obfuscators contains all types which implement the obfuscator Interface
obfuscators = []obfuscator{ obfuscators = []obfuscator{
xor{}, simple{},
swap{}, swap{},
split{}, split{},
xorShuffle{}, shuffle{},
xorSeed{}, seed{},
} }
envGarbleSeed = os.Getenv("GARBLE_SEED") envGarbleSeed = os.Getenv("GARBLE_SEED")
) )

@ -7,12 +7,12 @@ import (
ah "mvdan.cc/garble/internal/asthelper" ah "mvdan.cc/garble/internal/asthelper"
) )
type xorSeed struct{} type seed struct{}
// check that the obfuscator interface is implemented // 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() seed := genRandByte()
originalSeed := seed originalSeed := seed

@ -8,12 +8,12 @@ import (
ah "mvdan.cc/garble/internal/asthelper" ah "mvdan.cc/garble/internal/asthelper"
) )
type xorShuffle struct{} type shuffle struct{}
// check that the obfuscator interface is implemented // 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)) key := make([]byte, len(data))
genRandBytes(key) genRandBytes(key)

@ -7,12 +7,12 @@ import (
ah "mvdan.cc/garble/internal/asthelper" ah "mvdan.cc/garble/internal/asthelper"
) )
type xor struct{} type simple struct{}
// check that the obfuscator interface is implemented // 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)) key := make([]byte, len(data))
genRandBytes(key) genRandBytes(key)
@ -21,7 +21,7 @@ func (x xor) obfuscate(data []byte) *ast.BlockStmt {
data[i] = evalOperator(op, data[i], b) data[i] = evalOperator(op, data[i], b)
} }
return &ast.BlockStmt{List: []ast.Stmt{ return ah.BlockStmt(
&ast.AssignStmt{ &ast.AssignStmt{
Lhs: []ast.Expr{ah.Ident("key")}, Lhs: []ast.Expr{ah.Ident("key")},
Tok: token.DEFINE, Tok: token.DEFINE,
@ -45,5 +45,5 @@ func (x xor) obfuscate(data []byte) *ast.BlockStmt {
}, },
}}, }},
}, },
}} )
} }

@ -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 var chunks [][]byte
// Short arrays should be divided into single-byte fragments // Short arrays should be divided into single-byte fragments
if len(data)/maxChunkSize < minCaseCount { if len(data)/maxChunkSize < minCaseCount {
@ -205,5 +205,6 @@ func (x split) obfuscate(data []byte) *ast.BlockStmt {
Tag: ah.Ident("i"), Tag: ah.Ident("i"),
Body: ah.BlockStmt(shuffleStmts(switchCases...)...), Body: ah.BlockStmt(shuffleStmts(switchCases...)...),
}), }),
}) },
)
} }

@ -55,7 +55,7 @@ func generateSwapCount(dataLen int) int {
return swapCount return swapCount
} }
func (x swap) obfuscate(data []byte) *ast.BlockStmt { func (swap) obfuscate(data []byte) *ast.BlockStmt {
swapCount := generateSwapCount(len(data)) swapCount := generateSwapCount(len(data))
shiftKey := genRandByte() shiftKey := genRandByte()

Loading…
Cancel
Save