intLiteral helper now accepts int (#76)

pull/77/head
pagran 4 years ago committed by GitHub
parent 4b73c37ed7
commit 14a19b3e6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,10 +9,11 @@ import (
func ident(name string) *ast.Ident {
return &ast.Ident{Name: name}
}
func intLiteral(value string) *ast.BasicLit {
func intLiteral(value int) *ast.BasicLit {
return &ast.BasicLit{
Kind: token.INT,
Value: value,
Value: strconv.Itoa(value),
}
}
@ -62,10 +63,9 @@ func returnStmt(results ...ast.Expr) *ast.ReturnStmt {
// _ = data[pos]
func boundsCheckData(pos int) *ast.AssignStmt {
posStr := strconv.Itoa(pos)
return &ast.AssignStmt{
Lhs: []ast.Expr{ident("_")},
Tok: token.ASSIGN,
Rhs: []ast.Expr{indexExpr("data", intLiteral(posStr))},
Rhs: []ast.Expr{indexExpr("data", intLiteral(pos))},
}
}

@ -200,7 +200,7 @@ func obfuscateByteArray(data []byte, length int64) *ast.CallExpr {
block := obfuscator.obfuscate(data)
arrayType := &ast.ArrayType{
Len: intLiteral(strconv.Itoa(int(length))),
Len: intLiteral(int(length)),
Elt: ident("byte"),
}
@ -245,7 +245,7 @@ func obfuscateBool(data bool) *ast.BinaryExpr {
return &ast.BinaryExpr{
X: genObfuscateInt(dataUint64, intType),
Op: token.EQL,
Y: intLiteral("1"),
Y: intLiteral(1),
}
}

@ -122,19 +122,17 @@ func bytesToUint(bits int) ast.Expr {
var expr ast.Expr
for i := 0; i < bytes; i++ {
posStr := strconv.Itoa(i)
if i == 0 {
expr = callExpr(ident("uint"+bitsStr), indexExpr("data", intLiteral(posStr)))
expr = callExpr(ident("uint"+bitsStr), indexExpr("data", intLiteral(i)))
continue
}
shiftValue := strconv.Itoa(i * 8)
shiftValue := i * 8
expr = &ast.BinaryExpr{
X: expr,
Op: token.OR,
Y: &ast.BinaryExpr{
X: callExpr(ident("uint"+bitsStr), indexExpr("data", intLiteral(posStr))),
X: callExpr(ident("uint"+bitsStr), indexExpr("data", intLiteral(i))),
Op: token.SHL,
Y: intLiteral(shiftValue),
},

@ -4,7 +4,6 @@ import (
"go/ast"
"go/token"
"math"
"strconv"
)
type swap struct{}
@ -34,7 +33,7 @@ func positionsToSlice(data []int) *ast.CompositeLit {
Elts: []ast.Expr{},
}
for _, data := range data {
arr.Elts = append(arr.Elts, intLiteral(strconv.Itoa(data)))
arr.Elts = append(arr.Elts, intLiteral(data))
}
return arr
}
@ -78,17 +77,17 @@ func (x swap) obfuscate(data []byte) *ast.BlockStmt {
Init: &ast.AssignStmt{
Lhs: []ast.Expr{ident("i")},
Tok: token.DEFINE,
Rhs: []ast.Expr{intLiteral("0")},
Rhs: []ast.Expr{intLiteral(0)},
},
Cond: &ast.BinaryExpr{
X: ident("i"),
Op: token.LSS,
Y: intLiteral(strconv.Itoa(len(positions))),
Y: intLiteral(len(positions)),
},
Post: &ast.AssignStmt{
Lhs: []ast.Expr{ident("i")},
Tok: token.ADD_ASSIGN,
Rhs: []ast.Expr{intLiteral("2")},
Rhs: []ast.Expr{intLiteral(2)},
},
Body: &ast.BlockStmt{
List: []ast.Stmt{
@ -106,12 +105,12 @@ func (x swap) obfuscate(data []byte) *ast.BlockStmt {
Y: indexExpr("positions", &ast.BinaryExpr{
X: ident("i"),
Op: token.ADD,
Y: intLiteral("1"),
Y: intLiteral(1),
}),
}),
},
Op: token.ADD,
Y: intLiteral(strconv.Itoa(int(shiftKey))),
Y: intLiteral(int(shiftKey)),
},
},
},
@ -121,7 +120,7 @@ func (x swap) obfuscate(data []byte) *ast.BlockStmt {
indexExpr("data", indexExpr("positions", &ast.BinaryExpr{
X: ident("i"),
Op: token.ADD,
Y: intLiteral("1"),
Y: intLiteral(1),
})),
},
Tok: token.ASSIGN,
@ -130,7 +129,7 @@ func (x swap) obfuscate(data []byte) *ast.BlockStmt {
X: indexExpr("data", indexExpr("positions", &ast.BinaryExpr{
X: ident("i"),
Op: token.ADD,
Y: intLiteral("1"),
Y: intLiteral(1),
})),
Op: token.XOR,
Y: ident("localKey"),

Loading…
Cancel
Save