-
Notifications
You must be signed in to change notification settings - Fork 10
/
rotate_function.go
50 lines (38 loc) · 1.11 KB
/
rotate_function.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
45
46
47
48
49
50
package deobfuscator
import (
"fmt"
"github.com/dop251/goja"
"runtime/debug"
"time"
)
type RotateFunction struct {
DeviceDataOrder []string
ScriptId string
vm *goja.Runtime
LastCall time.Time
}
func GetRotateFunction(script []byte) (function string, hash string, err error, errors []Error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic: %v", r)
debug.PrintStack()
}
}()
scriptReduced, vm := CleanScriptAndRun(script)
return ParseRotateFunction(scriptReduced, vm.RunString)
}
func (rf *RotateFunction) GetResult(startTimestamp int, deviceData, mouseMoveData string, totVel, deltaTimestamp int) (string, error) {
rf.LastCall = time.Now()
var information = fmt.Sprintf(
`{"startTimestamp": %d, "deviceData": "%s", "mouseMoveData": "%s", "totVel": %d, "deltaTimestamp": %d}`,
startTimestamp, deviceData, mouseMoveData, totVel, deltaTimestamp)
result, err := rf.vm.RunString(`rf()(` + information + `);`)
if err != nil {
return "", err
}
return result.String(), nil
}
func (rf *RotateFunction) GetScriptId() string {
rf.LastCall = time.Now()
return rf.ScriptId
}