|
|
|
@ -55,14 +55,13 @@ func shuffleStmts(stmts ...ast.Stmt) []ast.Stmt {
|
|
|
|
|
return stmts
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Xor encrypt chunks based on key and position
|
|
|
|
|
func encryptChunks(chunks [][]byte, key int) {
|
|
|
|
|
idx := 0
|
|
|
|
|
for chunkIdx := range chunks {
|
|
|
|
|
chunk := chunks[chunkIdx]
|
|
|
|
|
for i := range chunk {
|
|
|
|
|
chunk[i] ^= byte(key ^ idx)
|
|
|
|
|
idx++
|
|
|
|
|
// Encrypt chunks based on key and position
|
|
|
|
|
func encryptChunks(chunks [][]byte, op token.Token, key byte) {
|
|
|
|
|
byteOffset := 0
|
|
|
|
|
for _, chunk := range chunks {
|
|
|
|
|
for i, b := range chunk {
|
|
|
|
|
chunk[i] = evalOperator(op, b, key^byte(byteOffset))
|
|
|
|
|
byteOffset++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -79,13 +78,15 @@ func (x split) obfuscate(data []byte) *ast.BlockStmt {
|
|
|
|
|
// Generate indexes for cases chunk count + 1 decrypt case + 1 exit case
|
|
|
|
|
indexes := mathrand.Perm(len(chunks) + 2)
|
|
|
|
|
|
|
|
|
|
decryptKeyInitial := mathrand.Int()
|
|
|
|
|
decryptKeyInitial := genRandByte()
|
|
|
|
|
decryptKey := decryptKeyInitial
|
|
|
|
|
// Calculate decrypt key based on indexes and position. Ignore exit index
|
|
|
|
|
for i, index := range indexes[:len(indexes)-1] {
|
|
|
|
|
decryptKey ^= index * i
|
|
|
|
|
decryptKey ^= byte(index * i)
|
|
|
|
|
}
|
|
|
|
|
encryptChunks(chunks, decryptKey)
|
|
|
|
|
|
|
|
|
|
op := randOperator()
|
|
|
|
|
encryptChunks(chunks, op, decryptKey)
|
|
|
|
|
|
|
|
|
|
decryptIndex := indexes[len(indexes)-2]
|
|
|
|
|
exitIndex := indexes[len(indexes)-1]
|
|
|
|
@ -103,12 +104,18 @@ func (x split) obfuscate(data []byte) *ast.BlockStmt {
|
|
|
|
|
X: ah.Ident("data"),
|
|
|
|
|
Body: ah.BlockStmt(&ast.AssignStmt{
|
|
|
|
|
Lhs: []ast.Expr{ah.IndexExpr("data", ah.Ident("y"))},
|
|
|
|
|
Tok: token.XOR_ASSIGN,
|
|
|
|
|
Rhs: []ast.Expr{ah.CallExpr(ah.Ident("byte"), &ast.BinaryExpr{
|
|
|
|
|
X: ah.Ident("decryptKey"),
|
|
|
|
|
Op: token.XOR,
|
|
|
|
|
Y: ah.Ident("y"),
|
|
|
|
|
})},
|
|
|
|
|
Tok: token.ASSIGN,
|
|
|
|
|
Rhs: []ast.Expr{
|
|
|
|
|
operatorToReversedBinaryExpr(
|
|
|
|
|
op,
|
|
|
|
|
ah.IndexExpr("data", ah.Ident("y")),
|
|
|
|
|
ah.CallExpr(ah.Ident("byte"), &ast.BinaryExpr{
|
|
|
|
|
X: ah.Ident("decryptKey"),
|
|
|
|
|
Op: token.XOR,
|
|
|
|
|
Y: ah.Ident("y"),
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
@ -165,7 +172,7 @@ func (x split) obfuscate(data []byte) *ast.BlockStmt {
|
|
|
|
|
&ast.AssignStmt{
|
|
|
|
|
Lhs: []ast.Expr{ah.Ident("decryptKey")},
|
|
|
|
|
Tok: token.DEFINE,
|
|
|
|
|
Rhs: []ast.Expr{ah.IntLit(decryptKeyInitial)},
|
|
|
|
|
Rhs: []ast.Expr{ah.IntLit(int(decryptKeyInitial))},
|
|
|
|
|
},
|
|
|
|
|
&ast.ForStmt{
|
|
|
|
|
Init: &ast.AssignStmt{
|
|
|
|
|