-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
memory_generated.go
247 lines (225 loc) · 7.93 KB
/
memory_generated.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// This file was autogenerated using go run mkcode.go -- memory.go
// DO NOT EDIT.
package ntdll
import "unsafe"
import "reflect"
// The MemoryInformationClass constants have been derived from the MEMORY_INFORMATION_CLASS enum definition.
type MemoryInformationClass uint32
const (
MemoryBasicInformation MemoryInformationClass = 0
MemoryWorkingSetInformation = 1
MemoryMappedFilenameInformation = 2
MemoryRegionInformation = 3
MemoryWorkingSetExInformation = 4
MemorySharedCommitInformation = 5
MemoryImageInformation = 6
MemoryRegionInformationEx = 7
MemoryPrivilegedBasicInformation = 8
MemoryEnclaveImageInformation = 9
MemoryBasicInformationCapped = 10
MemoryPhysicalContiguityInformation = 11
)
var (
procNtAllocateVirtualMemory = modntdll.NewProc("NtAllocateVirtualMemory")
procNtFreeVirtualMemory = modntdll.NewProc("NtFreeVirtualMemory")
procNtReadVirtualMemory = modntdll.NewProc("NtReadVirtualMemory")
procNtWriteVirtualMemory = modntdll.NewProc("NtWriteVirtualMemory")
procNtProtectVirtualMemory = modntdll.NewProc("NtProtectVirtualMemory")
procNtQueryVirtualMemory = modntdll.NewProc("NtQueryVirtualMemory")
procNtFlushVirtualMemory = modntdll.NewProc("NtFlushVirtualMemory")
)
// MemoryBasicInformationT has been derived from the MEMORY_BASIC_INFORMATION struct definition.
type MemoryBasicInformationT struct {
BaseAddress *byte
AllocationBase *byte
AllocationProtect uint32
PartitionId uint16
RegionSize uintptr
State uint32
Protect uint32
Type uint32
}
// MemoryBasicInformation32 has been derived from the MEMORY_BASIC_INFORMATION32 struct definition.
type MemoryBasicInformation32 struct {
BaseAddress uint32
AllocationBase uint32
AllocationProtect uint32
RegionSize uint32
State uint32
Protect uint32
Type uint32
}
// MemoryBasicInformation64 has been derived from the MEMORY_BASIC_INFORMATION64 struct definition.
type MemoryBasicInformation64 struct {
BaseAddress uint64
AllocationBase uint64
AllocationProtect uint32
__alignment1 uint32
RegionSize uint64
State uint32
Protect uint32
Type uint32
__alignment2 uint32
}
// MemoryWorkingSetInformationT has been derived from the MEMORY_WORKING_SET_INFORMATION struct definition.
type MemoryWorkingSetInformationT struct {
NumberOfEntries *uint32
WorkingSetInfo [1]MemoryWorkingSetBlock
}
// WorkingSetInfoSlice returns a slice over the elements of MemoryWorkingSetInformationT.WorkingSetInfo.
//
// Beware: The data is not copied out of MemoryWorkingSetInformationT. The size can usually be taken from an other member of the struct (MemoryWorkingSetInformationT).
func (t *MemoryWorkingSetInformationT) WorkingSetInfoSlice(size int) []MemoryWorkingSetBlock {
s := []MemoryWorkingSetBlock{}
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&s))
hdr.Data = uintptr(unsafe.Pointer(&t.WorkingSetInfo[0]))
hdr.Len = size
hdr.Cap = size
return s
}
// SetWorkingSetInfoSlice copies s into the memory at MemoryWorkingSetInformationT.WorkingSetInfo.
//
// Beware: No bounds check is performed. Another member of the struct (MemoryWorkingSetInformationT) usually has to be set to the array size.
func (t *MemoryWorkingSetInformationT) SetWorkingSetInfoSlice(s []MemoryWorkingSetBlock) {
s1 := []MemoryWorkingSetBlock{}
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&s1))
hdr.Data = uintptr(unsafe.Pointer(&t.WorkingSetInfo[0]))
hdr.Len = len(s)
hdr.Cap = len(s)
copy(s1, s)
}
// MemoryRegionInformationT has been derived from the MEMORY_REGION_INFORMATION struct definition.
type MemoryRegionInformationT struct {
AllocationBase *byte
AllocationProtect uint32
RegionType uint32
RegionSize uintptr
CommitSize uintptr
PartitionId *uint32
NodePreference *uint32
}
// MemoryWorkingSetExInformationT has been derived from the MEMORY_WORKING_SET_EX_INFORMATION struct definition.
type MemoryWorkingSetExInformationT struct {
VirtualAddress *byte
VirtualAttributes MemoryWorkingSetExBlock
}
// MemorySharedCommitInformationT has been derived from the MEMORY_SHARED_COMMIT_INFORMATION struct definition.
type MemorySharedCommitInformationT struct {
CommitSize uintptr
}
// MemoryImageInformationT has been derived from the MEMORY_IMAGE_INFORMATION struct definition.
type MemoryImageInformationT struct {
ImageBase *byte
SizeOfImage uintptr
ImageFlags uint32
}
// INOUT-parameter: BaseAddress, RegionSize.
func NtAllocateVirtualMemory(
ProcessHandle Handle,
BaseAddress *byte,
ZeroBits *uint32,
RegionSize *uintptr,
AllocationType uint32,
Protect uint32,
) NtStatus {
r0, _, _ := procNtAllocateVirtualMemory.Call(uintptr(ProcessHandle),
uintptr(unsafe.Pointer(BaseAddress)),
uintptr(unsafe.Pointer(ZeroBits)),
uintptr(unsafe.Pointer(RegionSize)),
uintptr(AllocationType),
uintptr(Protect))
return NtStatus(r0)
}
// INOUT-parameter: BaseAddress, RegionSize.
func NtFreeVirtualMemory(
ProcessHandle Handle,
BaseAddress *byte,
RegionSize *uintptr,
FreeType uint32,
) NtStatus {
r0, _, _ := procNtFreeVirtualMemory.Call(uintptr(ProcessHandle),
uintptr(unsafe.Pointer(BaseAddress)),
uintptr(unsafe.Pointer(RegionSize)),
uintptr(FreeType))
return NtStatus(r0)
}
// OUT-parameter: Buffer, NumberOfBytesRead.
// *OPT-parameter: BaseAddress, NumberOfBytesRead.
func NtReadVirtualMemory(
ProcessHandle Handle,
BaseAddress *byte,
Buffer *byte,
BufferSize uintptr,
NumberOfBytesRead *uintptr,
) NtStatus {
r0, _, _ := procNtReadVirtualMemory.Call(uintptr(ProcessHandle),
uintptr(unsafe.Pointer(BaseAddress)),
uintptr(unsafe.Pointer(Buffer)),
uintptr(BufferSize),
uintptr(unsafe.Pointer(NumberOfBytesRead)))
return NtStatus(r0)
}
// OUT-parameter: NumberOfBytesWritten.
// *OPT-parameter: BaseAddress, NumberOfBytesWritten.
func NtWriteVirtualMemory(
ProcessHandle Handle,
BaseAddress *byte,
Buffer *byte,
BufferSize uintptr,
NumberOfBytesWritten *uintptr,
) NtStatus {
r0, _, _ := procNtWriteVirtualMemory.Call(uintptr(ProcessHandle),
uintptr(unsafe.Pointer(BaseAddress)),
uintptr(unsafe.Pointer(Buffer)),
uintptr(BufferSize),
uintptr(unsafe.Pointer(NumberOfBytesWritten)))
return NtStatus(r0)
}
// OUT-parameter: OldProtect.
// INOUT-parameter: BaseAddress, RegionSize.
func NtProtectVirtualMemory(
ProcessHandle Handle,
BaseAddress *byte,
RegionSize *uintptr,
NewProtect uint32,
OldProtect *uint32,
) NtStatus {
r0, _, _ := procNtProtectVirtualMemory.Call(uintptr(ProcessHandle),
uintptr(unsafe.Pointer(BaseAddress)),
uintptr(unsafe.Pointer(RegionSize)),
uintptr(NewProtect),
uintptr(unsafe.Pointer(OldProtect)))
return NtStatus(r0)
}
// OUT-parameter: MemoryInformation, ReturnLength.
// *OPT-parameter: BaseAddress, ReturnLength.
func NtQueryVirtualMemory(
ProcessHandle Handle,
BaseAddress *byte,
MemoryInformationClass MemoryInformationClass,
MemoryInformation *byte,
MemoryInformationLength uintptr,
ReturnLength *uintptr,
) NtStatus {
r0, _, _ := procNtQueryVirtualMemory.Call(uintptr(ProcessHandle),
uintptr(unsafe.Pointer(BaseAddress)),
uintptr(MemoryInformationClass),
uintptr(unsafe.Pointer(MemoryInformation)),
uintptr(MemoryInformationLength),
uintptr(unsafe.Pointer(ReturnLength)))
return NtStatus(r0)
}
// OUT-parameter: IoStatus.
// INOUT-parameter: BaseAddress, RegionSize.
func NtFlushVirtualMemory(
ProcessHandle Handle,
BaseAddress *byte,
RegionSize *uintptr,
IoStatus *IoStatusBlock,
) NtStatus {
r0, _, _ := procNtFlushVirtualMemory.Call(uintptr(ProcessHandle),
uintptr(unsafe.Pointer(BaseAddress)),
uintptr(unsafe.Pointer(RegionSize)),
uintptr(unsafe.Pointer(IoStatus)))
return NtStatus(r0)
}