-
Notifications
You must be signed in to change notification settings - Fork 10
/
string_bis.go
44 lines (34 loc) · 1.03 KB
/
string_bis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package deobfuscator
import (
"encoding/json"
"regexp"
"strings"
)
func (v *Virtual) deobString(fast bool) {
if v.listName == "" {
v.listName = pushValueRegex.FindStringSubmatch(v.script)[1]
v.runInVm("var " + v.listName + "=[];")
}
var evilRegex = regexp.MustCompile(`(\w+\.\w+(\.call|\.apply|)\((([!\s]*)(null|\w+|,|\((\w+(\((\w+|{}|\[])\))?|\{}|\[])\)|[\[\]]|[{}]|\s))+\))|(` + v.listName + `\.(push|pop\(\w+\)))`)
var lastWasPop bool
v.deobedScript = string(evilRegex.ReplaceAllFunc([]byte(v.deobedScript), func(match []byte) []byte {
if lastWasPop && strings.HasPrefix(string(match), v.listName+".pop") {
return match
}
if strings.HasPrefix(string(match), v.listName+".pop") {
lastWasPop = true
} else {
lastWasPop = false
}
r, _ := v.runInVm(string(match))
if !strings.HasPrefix(string(match), v.listName+".push") && !strings.HasPrefix(string(match), v.listName+".pop") {
var r2, _ = json.Marshal(r)
return r2
}
return match
}))
if !fast {
v.evalInt()
replaceOperations(&v.deobedScript)
}
}