-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDeviceSignalConnect.go
155 lines (148 loc) · 6.21 KB
/
DeviceSignalConnect.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package frida_go
import (
"github.com/a97077088/frida-go/cfrida"
"reflect"
"sync"
)
type DeviceOnSpawnAddedEventFunc func(spawn *SpawnDetails)
type DeviceOnSpawnRemovedEventFunc func(spawn *SpawnDetails)
type DeviceOnChildAddedEventFunc func(child *ChildDetails)
type DeviceOnChildRemovedEventFunc func(child *ChildDetails)
type DeviceOnProcessCrashedEventFunc func(crash *CrashDetails)
type DeviceOnOutputEventFunc func(data []byte,fd int,pid int)
type DeviceOnUninjectedEventFunc func(id uint)
type DeviceOnLostEventFunc func()
var device_onSpawnAddedbackTable=sync.Map{}
var device_onSpawnRemovedCallbackTable=sync.Map{}
var device_onChildAddedCallbackTable=sync.Map{}
var device_onChildRemovedCallbackTable=sync.Map{}
var device_onProcessCrashedCallbackTable=sync.Map{}
var device_onOutputCallbackTable=sync.Map{}
var device_onUninjectedCallbackTable=sync.Map{}
var device_onLostCallbackTable=sync.Map{}
type DeviceSignalConnect struct {
onSpawnAddedSigs sync.Map
onSpawnRemovedSigs sync.Map
onChildAddedSigs sync.Map
onChildRemovedSigs sync.Map
onProcessCrashedSigs sync.Map
onOutputSigs sync.Map
onUninjectedSigs sync.Map
onLostSigs sync.Map
rawDevicePtr uintptr
}
func (s *DeviceSignalConnect) OnSpawnAdded(on DeviceOnSpawnAddedEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
device_onSpawnAddedbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawDevicePtr, "spawn-added", device_onSpawnAddedPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onSpawnAddedSigs.Store(sigid,userdata)
return sigid
}
func (s *DeviceSignalConnect) OnSpawnRemoved(on DeviceOnSpawnRemovedEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
device_onSpawnRemovedCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawDevicePtr, "spawn-removed", device_onSpawnRemovedPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onSpawnRemovedSigs.Store(sigid,userdata)
return sigid
}
func (s *DeviceSignalConnect) OnChildAdded(on DeviceOnChildAddedEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
device_onChildAddedCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawDevicePtr, "child-added", device_onChildAddedPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onChildAddedSigs.Store(sigid,userdata)
return sigid
}
func (s *DeviceSignalConnect) OnChildRemoved(on DeviceOnChildRemovedEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
device_onChildRemovedCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawDevicePtr, "child-removed", device_onChildRemovedPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onChildRemovedSigs.Store(sigid,userdata)
return sigid
}
func (s *DeviceSignalConnect) OnProcessCrashed(on DeviceOnProcessCrashedEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
device_onProcessCrashedCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawDevicePtr, "process-crashed", device_onProcessCrashedPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onProcessCrashedSigs.Store(sigid,userdata)
return sigid
}
func (s *DeviceSignalConnect) OnOutput(on DeviceOnOutputEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
device_onOutputCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawDevicePtr, "output", device_onOutputPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onOutputSigs.Store(sigid,userdata)
return sigid
}
func (s *DeviceSignalConnect) OnUninjected(on DeviceOnUninjectedEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
device_onUninjectedCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawDevicePtr, "uninjected", device_onUninjectedPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onUninjectedSigs.Store(sigid,userdata)
return sigid
}
func (s *DeviceSignalConnect) OnLost(on DeviceOnLostEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
device_onLostCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawDevicePtr, "lost", device_onLostPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onLostSigs.Store(sigid,userdata)
return sigid
}
func (s *DeviceSignalConnect) free() {
if s.rawDevicePtr!=0{
//fmt.Println("DeviceSignalConnect gc")
s.onSpawnAddedSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawDevicePtr, key.(int64))
device_onSpawnAddedbackTable.Delete(key.(int64))
return true
})
s.onSpawnRemovedSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawDevicePtr, key.(int64))
device_onSpawnRemovedCallbackTable.Delete(key.(int64))
return true
})
s.onChildAddedSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawDevicePtr, key.(int64))
device_onChildAddedCallbackTable.Delete(key.(int64))
return true
})
s.onChildRemovedSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawDevicePtr, key.(int64))
device_onChildRemovedCallbackTable.Delete(key.(int64))
return true
})
s.onProcessCrashedSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawDevicePtr, key.(int64))
device_onProcessCrashedCallbackTable.Delete(key.(int64))
return true
})
s.onOutputSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawDevicePtr, key.(int64))
device_onOutputCallbackTable.Delete(key.(int64))
return true
})
s.onUninjectedSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawDevicePtr, key.(int64))
device_onUninjectedCallbackTable.Delete(key.(int64))
return true
})
s.onLostSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawDevicePtr, key.(int64))
device_onLostCallbackTable.Delete(key.(int64))
return true
})
s.rawDevicePtr=0
}
}
func NewDeviceSignalConnect(rawPtr uintptr) *DeviceSignalConnect {
sig := new(DeviceSignalConnect)
sig.onSpawnAddedSigs = sync.Map{}
sig.onSpawnRemovedSigs = sync.Map{}
sig.onChildAddedSigs = sync.Map{}
sig.onChildRemovedSigs = sync.Map{}
sig.onProcessCrashedSigs = sync.Map{}
sig.onOutputSigs = sync.Map{}
sig.onUninjectedSigs = sync.Map{}
sig.onLostSigs = sync.Map{}
sig.rawDevicePtr = rawPtr
return sig
}