-
Notifications
You must be signed in to change notification settings - Fork 9
/
BusSignalConnect.go
59 lines (53 loc) · 1.74 KB
/
BusSignalConnect.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
59
package frida_go
import (
"github.com/a97077088/frida-go/cfrida"
jsoniter "github.com/json-iterator/go"
"reflect"
"sync"
)
type BusOnMessageEventFunc func(sjson jsoniter.Any, data []byte)
type BusOnDetachEventFunc func()
type BusSignalConnect struct {
onMessageSigs sync.Map
onDetachSigs sync.Map
rawBusPtr uintptr
}
func (s *BusSignalConnect) free() {
if s.rawBusPtr!=0{
//fmt.Println("BusSignalConnect gc")
s.onMessageSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawBusPtr, key.(int64))
bus_onMessageCallbackTable.Delete(key.(int64))
return true
})
s.onDetachSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawBusPtr, key.(int64))
bus_onDetachCallbackTable.Delete(key.(int64))
return true
})
s.rawBusPtr=0
}
}
func (s *BusSignalConnect) OnDetach(on BusOnDetachEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
bus_onDetachCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawBusPtr, "detached", bus_onDetachPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onDetachSigs.Store(sigid,userdata)
return sigid
}
func (s *BusSignalConnect) OnMessage(on BusOnMessageEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
bus_onMessageCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawBusPtr, "message", bus_onMessagePtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onMessageSigs.Store(sigid,userdata)
return sigid
}
var bus_onDetachCallbackTable=sync.Map{}
var bus_onMessageCallbackTable=sync.Map{}
func NewBusSignalConnect(rawPtr uintptr) *BusSignalConnect {
sig := new(BusSignalConnect)
sig.onMessageSigs = sync.Map{}
sig.onDetachSigs = sync.Map{}
sig.rawBusPtr = rawPtr
return sig
}