-
Notifications
You must be signed in to change notification settings - Fork 9
/
IOStream.go
91 lines (82 loc) · 1.89 KB
/
IOStream.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
package frida_go
import (
"fmt"
"github.com/a97077088/frida-go/cfrida"
"unsafe"
)
type IOStream struct {
CObj
Input uintptr
OutPut uintptr
}
func (i *IOStream) IsClosed() bool {
return cfrida.G_io_stream_is_closed(i.instance)
}
func (i *IOStream) Close() (bool,error) {
err:=cfrida.G_input_stream_close(i.Input,0)
if err!=nil{
return false,err
}
err=cfrida.G_output_stream_close(i.OutPut,0)
if err!=nil{
return false,err
}
b,err:=cfrida.G_io_stream_close(i.instance,0)
if err!=nil{
return false,err
}
return b,nil
}
func (i *IOStream) Read(count int) ([]byte,error) {
bt,err:=cfrida.G_input_stream_read_bytes(i.instance,count,0)
if err!=nil{
return nil,err
}
return bt,nil
}
func (i *IOStream) ReadAll(count int) ([]byte,int,error) {
buf:=make([]byte,count)
bytes_read:=0
_,err:=cfrida.G_input_stream_read_all(i.instance,buf,count,&bytes_read,0)
if err!=nil{
return nil,0,err
}
return buf,bytes_read,nil
}
func (i *IOStream) Write(data []byte) (int,error) {
n,err:=cfrida.G_output_stream_write_bytes(i.OutPut,data,0)
if err!=nil{
return 0,err
}
return n,nil
}
func (i *IOStream) WriteAll(data []byte) (int,error) {
outsize:=0
_,err:=cfrida.G_output_stream_write_all(i.OutPut,data,&outsize,0,)
if err!=nil{
return 0,err
}
return outsize,nil
}
func (p *IOStream) Description() string {
if p.instance==0{
return ""
}
return fmt.Sprintf("Frida.IOStream()")
}
func (p *IOStream) Free() {
cfrida.G_object_unref(p.instance)
}
// IOStreamFromInst
// 新建一个对象来自已经存在的对象实例指针。
//
// Create a new object from an existing object instance pointer.
func IOStreamFromInst(inst uintptr) *IOStream {
dl:=new(IOStream)
dl.instance=inst
dl.ptr= unsafe.Pointer(inst)
dl.Input=cfrida.G_io_stream_get_input_stream(dl.instance)
dl.OutPut=cfrida.G_io_stream_get_output_stream(dl.instance)
setFinalizer(dl, (*IOStream).Free)
return dl
}