-
Notifications
You must be signed in to change notification settings - Fork 9
/
ScriptSignalConnect.go
58 lines (53 loc) · 1.86 KB
/
ScriptSignalConnect.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
51
52
53
54
55
56
57
58
package frida_go
import (
"github.com/a97077088/frida-go/cfrida"
jsoniter "github.com/json-iterator/go"
"reflect"
"sync"
)
type ScriptOnMessageEventFunc func(sjson jsoniter.Any, data []byte)
type ScriptOnDestroyedEventFunc func()
type ScriptSignalConnect struct {
onMessageSigs sync.Map
onDestroyedSigs sync.Map
rawScriptPtr uintptr
}
func (s *ScriptSignalConnect) free() {
if s.rawScriptPtr!=0{
//fmt.Println("ScriptSignalConnect gc")
s.onMessageSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawScriptPtr, key.(int64))
script_onMessageCallbackTable.Delete(key.(int64))
return true
})
s.onDestroyedSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawScriptPtr, key.(int64))
script_onDestroyedCallbackTable.Delete(key.(int64))
return true
})
s.rawScriptPtr=0
}
}
func (s *ScriptSignalConnect) OnDestroyed(on ScriptOnDestroyedEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
script_onDestroyedCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawScriptPtr, "destroyed", script_onDestroyedPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onDestroyedSigs.Store(sigid,userdata)
return sigid
}
func (s *ScriptSignalConnect) OnMessage(on ScriptOnMessageEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
script_onMessageCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawScriptPtr, "message", script_onMessagePtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onMessageSigs.Store(sigid,userdata)
return sigid
}
var script_onDestroyedCallbackTable=sync.Map{}
var script_onMessageCallbackTable=sync.Map{}
func NewScriptSignalConnect(rawPtr uintptr) *ScriptSignalConnect {
sig := new(ScriptSignalConnect)
sig.onMessageSigs = sync.Map{}
sig.onDestroyedSigs = sync.Map{}
sig.rawScriptPtr = rawPtr
return sig
}