-
Notifications
You must be signed in to change notification settings - Fork 9
/
DeviceManager.go
111 lines (105 loc) · 3.01 KB
/
DeviceManager.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
package frida_go
import (
"github.com/a97077088/frida-go/cfrida"
"unsafe"
)
const (
G_CONNECT_AFTER = 1 << 0
G_CONNECT_SWAPPED = 1 << 1
)
type DeviceManager struct {
CObj
*DeviceManagerSignalConnect
}
func (d *DeviceManager) Close()error{
err:=cfrida.Frida_device_manager_close_sync(d.instance,0)
if err!=nil{
return err
}
return nil
}
func (d *DeviceManager) Free() {
d.free()
//fmt.Println("DeviceManager gc")
cfrida.G_object_unref(d.instance)
}
func (d *DeviceManager) EnumerateDevices()([]*Device,error){
rawDevices,err:=cfrida.Frida_device_manager_enumerate_devices_sync(d.instance,0)
if err!=nil{
return nil,err
}
defer cfrida.G_object_unref(rawDevices)
devices:=make([]*Device,0)
n:=cfrida.Frida_device_list_size(rawDevices)
for i := 0; i <n; i++ {
devices=append(devices,DeviceFromInst(cfrida.Frida_device_list_get(rawDevices,i)))
}
return devices,nil
}
func (d *DeviceManager) AddRemoteDevice(address string,ops RemoteDeviceOptions)(*Device,error){
rawops:=cfrida.Frida_remote_device_options_new()
defer cfrida.G_object_unref(rawops)
if ops.Certificate!=""{
panic("no imp")
}
if ops.Origin!=""{
cfrida.Frida_remote_device_options_set_origin(rawops,ops.Origin)
}
if ops.Token!=""{
cfrida.Frida_remote_device_options_set_token(rawops,ops.Token)
}
if ops.KeepaliveInterval!=0{
cfrida.Frida_remote_device_options_set_keepalive_interval(rawops,ops.KeepaliveInterval)
}
r,err:=cfrida.Frida_device_manager_add_remote_device_sync(d.instance,address,rawops,0)
if err!=nil{
return nil,err
}
return DeviceFromInst(r),nil
}
func (d *DeviceManager) RemoveRemoteDevice(address string)error{
err:=cfrida.Frida_device_manager_remove_remote_device_sync(d.instance,address,0)
if err!=nil{
return err
}
return nil
}
func (d *DeviceManager) GetDeviceById(id string,timeout_ms int) (*Device,error) {
dev,err:=cfrida.Frida_device_manager_get_device_by_id_sync(d.instance,id,timeout_ms,0)
if err!=nil{
return nil,err
}
return DeviceFromInst(dev),nil
}
func (d *DeviceManager) GetDeviceByType(tp DeviceType,timeout_ms int) (*Device,error) {
dev,err:=cfrida.Frida_device_manager_get_device_by_type_sync(d.instance, int(tp),timeout_ms,0)
if err!=nil{
return nil,err
}
return DeviceFromInst(dev),nil
}
func (d *DeviceManager) FindDeviceById(id string,timeout_ms int) (*Device,error) {
dev,err:=cfrida.Frida_device_manager_find_device_by_id_sync(d.instance,id,timeout_ms,0)
if err!=nil{
return nil,err
}
return DeviceFromInst(dev),nil
}
func (d *DeviceManager) FindDeviceByType(tp DeviceType,timeout_ms int) (*Device,error) {
dev,err:=cfrida.Frida_device_manager_find_device_by_type_sync(d.instance, int(tp),timeout_ms,0)
if err!=nil{
return nil,err
}
if dev==0{
return nil,nil
}
return DeviceFromInst(dev),nil
}
func DeviceManager_Create() *DeviceManager {
i := new(DeviceManager)
i.instance = cfrida.Frida_device_manager_new()
i.ptr = unsafe.Pointer(i.instance)
i.DeviceManagerSignalConnect=NewDeviceManagerSignalConnect(i.instance)
setFinalizer(i, (*DeviceManager).Free)
return i
}