|
|
@ -81,63 +81,63 @@ func Obfuscate(file *ast.File, info *types.Info, fset *token.FileSet, ignoreObj
|
|
|
|
case *ast.CompositeLit:
|
|
|
|
case *ast.CompositeLit:
|
|
|
|
byteType := types.Universe.Lookup("byte").Type()
|
|
|
|
byteType := types.Universe.Lookup("byte").Type()
|
|
|
|
|
|
|
|
|
|
|
|
if len(x.Elts) == 0 {
|
|
|
|
if len(x.Elts) == 0 || len(x.Elts) > maxSizeBytes {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var arrayLen int64
|
|
|
|
switch y := info.TypeOf(x.Type).(type) {
|
|
|
|
switch y := info.TypeOf(x.Type).(type) {
|
|
|
|
case *types.Array:
|
|
|
|
case *types.Array:
|
|
|
|
if y.Elem() != byteType {
|
|
|
|
if y.Elem() != byteType {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if y.Len() > maxSizeBytes {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data := make([]byte, y.Len())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i, el := range x.Elts {
|
|
|
|
|
|
|
|
lit, ok := el.(*ast.BasicLit)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
value, err := strconv.Atoi(lit.Value)
|
|
|
|
arrayLen = y.Len()
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data[i] = byte(value)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor.Replace(withPos(obfuscateByteArray(data, y.Len()), x.Pos()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case *types.Slice:
|
|
|
|
case *types.Slice:
|
|
|
|
if y.Elem() != byteType {
|
|
|
|
if y.Elem() != byteType {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(x.Elts) > maxSizeBytes {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data := make([]byte, 0, len(x.Elts))
|
|
|
|
default:
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, el := range x.Elts {
|
|
|
|
data := make([]byte, 0, len(x.Elts))
|
|
|
|
lit, ok := el.(*ast.BasicLit)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
for _, el := range x.Elts {
|
|
|
|
|
|
|
|
lit, ok := el.(*ast.BasicLit)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var value byte
|
|
|
|
|
|
|
|
if lit.Kind == token.CHAR {
|
|
|
|
|
|
|
|
val, _, _, err := strconv.UnquoteChar(lit.Value, '\'')
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
value, err := strconv.Atoi(lit.Value)
|
|
|
|
value = byte(val)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
val, err := strconv.ParseUint(lit.Value, 0, 8)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data = append(data, byte(value))
|
|
|
|
value = byte(val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cursor.Replace(withPos(obfuscateByteSlice(data), x.Pos()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = append(data, value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if arrayLen > 0 {
|
|
|
|
|
|
|
|
cursor.Replace(withPos(obfuscateByteArray(data, arrayLen), x.Pos()))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cursor.Replace(withPos(obfuscateByteSlice(data), x.Pos()))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
|
|
case *ast.BasicLit:
|
|
|
|
case *ast.BasicLit:
|
|
|
|
switch cursor.Name() {
|
|
|
|
switch cursor.Name() {
|
|
|
|
case "Values", "Rhs", "Value", "Args", "X", "Y", "Results", "Elts":
|
|
|
|
case "Values", "Rhs", "Value", "Args", "X", "Y", "Results", "Elts":
|
|
|
@ -256,7 +256,7 @@ func obfuscateByteArray(data []byte, length int64) *ast.CallExpr {
|
|
|
|
&ast.RangeStmt{
|
|
|
|
&ast.RangeStmt{
|
|
|
|
Key: ast.NewIdent("i"),
|
|
|
|
Key: ast.NewIdent("i"),
|
|
|
|
Tok: token.DEFINE,
|
|
|
|
Tok: token.DEFINE,
|
|
|
|
X: ast.NewIdent("newdata"),
|
|
|
|
X: ast.NewIdent("data"),
|
|
|
|
Body: &ast.BlockStmt{List: []ast.Stmt{
|
|
|
|
Body: &ast.BlockStmt{List: []ast.Stmt{
|
|
|
|
&ast.AssignStmt{
|
|
|
|
&ast.AssignStmt{
|
|
|
|
Lhs: []ast.Expr{ah.IndexExpr("newdata", ast.NewIdent("i"))},
|
|
|
|
Lhs: []ast.Expr{ah.IndexExpr("newdata", ast.NewIdent("i"))},
|
|
|
|