-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSession.go
142 lines (123 loc) · 3.27 KB
/
Session.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
package frida_go
import (
"fmt"
"github.com/a97077088/frida-go/cfrida"
"unsafe"
)
const (
FRIDA_SCRIPT_RUNTIME_DEFAULT = iota
FRIDA_SCRIPT_RUNTIME_QJS
FRIDA_SCRIPT_RUNTIME_V8
)
type FridaScriptRuntime int
type Session struct {
CObj
}
func (s *Session) Pid() int {
return cfrida.Frida_session_get_pid(s.instance)
}
func (s *Session) PersistTimeout() int {
return cfrida.Frida_session_get_persist_timeout(s.instance)
}
func (s *Session) IsDetached() bool {
return cfrida.Frida_session_is_detached(s.instance)
}
func (s *Session) Detach() error {
err:=cfrida.Frida_session_detach_sync(s.instance,0,)
if err!=nil{
return err
}
return nil
}
func (s *Session) CreateScript(source string,ops ScriptOptions)(*Script,error){
if source==""{
//fix null emtry
source=`
console.log("")
`
}
rawops:=cfrida.Frida_script_options_new()
defer cfrida.G_object_unref(rawops)
if ops.Name!=""{
cfrida.Frida_script_options_set_name(rawops,ops.Name)
}
cfrida.Frida_script_options_set_runtime(rawops, int(ops.Runtime))
sc,err:=cfrida.Frida_session_create_script_sync(s.instance,source,rawops,0,)
if err!=nil{
return nil,err
}
return ScriptFromInst(sc),nil
}
func (s *Session) CreateScriptFormBytes(source []byte,ops ScriptOptions)(*Script,error){
rawops:=cfrida.Frida_script_options_new()
defer cfrida.G_object_unref(rawops)
if ops.Name!=""{
cfrida.Frida_script_options_set_name(rawops,ops.Name)
}
cfrida.Frida_script_options_set_runtime(rawops, int(ops.Runtime))
sc,err:=cfrida.Frida_session_create_script_from_bytes_sync(s.instance,source,rawops,0)
if err!=nil{
return nil,err
}
return ScriptFromInst(sc),nil
}
func (s *Session) CompileScript(source string,ops ScriptOptions)([]byte,error){
rawops:=cfrida.Frida_script_options_new()
defer cfrida.G_object_unref(rawops)
if ops.Name!=""{
cfrida.Frida_script_options_set_name(rawops,ops.Name)
}
cfrida.Frida_script_options_set_runtime(rawops, int(ops.Runtime))
bt,err:=cfrida.Frida_session_compile_script_sync(s.instance,source,rawops,0)
if err!=nil{
return nil,err
}
return bt,nil
}
func (s *Session) EnableDebugger(port int)error{
err:=cfrida.Frida_session_enable_debugger_sync(s.instance,port,0)
if err!=nil{
return err
}
return nil
}
func (s *Session) DisableDebugger()error{
err:=cfrida.Frida_session_disable_debugger_sync(s.instance,0)
if err!=nil{
return err
}
return nil
}
func (s *Session) SetupPeerConnection(ops PeerOptions)error{
rawops:=cfrida.Frida_peer_options_new()
defer cfrida.G_object_unref(rawops)
cfrida.Frida_peer_options_set_stun_server(rawops, ops.StunServer)
for _, relay := range ops.Relays {
cfrida.Frida_peer_options_add_relay(rawops, relay.instance)
}
err:=cfrida.Frida_session_setup_peer_connection_sync(s.instance,rawops,0)
if err!=nil{
return err
}
return nil
}
func (s *Session) Description() string {
if s.instance==0{
return ""
}
return fmt.Sprintf("Frida.Session(pid: %d)",s.Pid())
}
func (s *Session) Free() {
cfrida.G_object_unref(s.instance)
}
// SessionFromInst
// 新建一个对象来自已经存在的对象实例指针。
//
// Create a new object from an existing object instance pointer.
func SessionFromInst(inst uintptr) *Session {
dl:=new(Session)
dl.instance=inst
dl.ptr= unsafe.Pointer(inst)
setFinalizer(dl, (*Session).Free)
return dl
}