-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
token_generated.go
484 lines (434 loc) · 15.8 KB
/
token_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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
// This file was autogenerated using go run mkcode.go -- token.go
// DO NOT EDIT.
package ntdll
import "unsafe"
import "reflect"
// The TokenTypeT constants have been derived from the TOKEN_TYPE enum definition.
type TokenTypeT uint32
const (
TokenPrimary TokenTypeT = 1
TokenImpersonation = 2
)
// The TokenInformationClassT constants have been derived from the TOKEN_INFORMATION_CLASS enum definition.
type TokenInformationClassT uint32
const (
TokenUser TokenInformationClassT = 1
TokenGroups = 2
TokenPrivileges = 3
TokenOwner = 4
TokenPrimaryGroup = 5
TokenDefaultDacl = 6
TokenSource = 7
TokenType = 8
TokenImpersonationLevel = 9
TokenStatistics = 10
TokenRestrictedSids = 11
TokenSessionId = 12
TokenGroupsAndPrivileges = 13
TokenSessionReference = 14
TokenSandBoxInert = 15
TokenAuditPolicy = 16
TokenOrigin = 17
TokenElevationType = 18
TokenLinkedToken = 19
TokenElevation = 20
TokenHasRestrictions = 21
TokenAccessInformation = 22
TokenVirtualizationAllowed = 23
TokenVirtualizationEnabled = 24
TokenIntegrityLevel = 25
TokenUIAccess = 26
TokenMandatoryPolicy = 27
TokenLogonSid = 28
TokenIsAppContainer = 29
TokenCapabilities = 30
TokenAppContainerSid = 31
TokenAppContainerNumber = 32
TokenUserClaimAttributes = 33
TokenDeviceClaimAttributes = 34
TokenRestrictedUserClaimAttributes = 35
TokenRestrictedDeviceClaimAttributes = 36
TokenDeviceGroups = 37
TokenRestrictedDeviceGroups = 38
TokenSecurityAttributes = 39
TokenIsRestricted = 40
TokenProcessTrustLevel = 41
TokenPrivateNameSpace = 42
TokenSingletonAttributes = 43
MaxTokenInfoClass = 44
)
// The SecurityImpersonationLevel constants have been derived from the SECURITY_IMPERSONATION_LEVEL enum definition.
type SecurityImpersonationLevel uint32
const (
SecurityAnonymous SecurityImpersonationLevel = 0
SecurityIdentification = 1
SecurityImpersonation = 2
SecurityDelegation = 3
)
var (
procNtOpenThreadToken = modntdll.NewProc("NtOpenThreadToken")
procNtOpenThreadTokenEx = modntdll.NewProc("NtOpenThreadTokenEx")
procNtOpenProcessToken = modntdll.NewProc("NtOpenProcessToken")
procNtOpenProcessTokenEx = modntdll.NewProc("NtOpenProcessTokenEx")
procNtOpenJobObjectToken = modntdll.NewProc("NtOpenJobObjectToken")
procNtDuplicateToken = modntdll.NewProc("NtDuplicateToken")
procNtFilterToken = modntdll.NewProc("NtFilterToken")
procNtImpersonateAnonymousToken = modntdll.NewProc("NtImpersonateAnonymousToken")
procNtQueryInformationToken = modntdll.NewProc("NtQueryInformationToken")
procNtSetInformationToken = modntdll.NewProc("NtSetInformationToken")
procNtAdjustPrivilegesToken = modntdll.NewProc("NtAdjustPrivilegesToken")
procNtAdjustGroupsToken = modntdll.NewProc("NtAdjustGroupsToken")
)
// TokenUserT has been derived from the TOKEN_USER struct definition.
type TokenUserT struct {
User SidAndAttributes
}
// TokenGroupsT has been derived from the TOKEN_GROUPS struct definition.
type TokenGroupsT struct {
GroupCount uint32
Groups [1]SidAndAttributes
}
// GroupsSlice returns a slice over the elements of TokenGroupsT.Groups.
//
// Beware: The data is not copied out of TokenGroupsT. The size can usually be taken from an other member of the struct (TokenGroupsT).
func (t *TokenGroupsT) GroupsSlice(size int) []SidAndAttributes {
s := []SidAndAttributes{}
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&s))
hdr.Data = uintptr(unsafe.Pointer(&t.Groups[0]))
hdr.Len = size
hdr.Cap = size
return s
}
// SetGroupsSlice copies s into the memory at TokenGroupsT.Groups.
//
// Beware: No bounds check is performed. Another member of the struct (TokenGroupsT) usually has to be set to the array size.
func (t *TokenGroupsT) SetGroupsSlice(s []SidAndAttributes) {
s1 := []SidAndAttributes{}
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&s1))
hdr.Data = uintptr(unsafe.Pointer(&t.Groups[0]))
hdr.Len = len(s)
hdr.Cap = len(s)
copy(s1, s)
}
// TokenPrivilegesT has been derived from the TOKEN_PRIVILEGES struct definition.
type TokenPrivilegesT struct {
PrivilegeCount uint32
Privileges [1]LuidAndAttributes
}
// PrivilegesSlice returns a slice over the elements of TokenPrivilegesT.Privileges.
//
// Beware: The data is not copied out of TokenPrivilegesT. The size can usually be taken from an other member of the struct (TokenPrivilegesT).
func (t *TokenPrivilegesT) PrivilegesSlice(size int) []LuidAndAttributes {
s := []LuidAndAttributes{}
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&s))
hdr.Data = uintptr(unsafe.Pointer(&t.Privileges[0]))
hdr.Len = size
hdr.Cap = size
return s
}
// SetPrivilegesSlice copies s into the memory at TokenPrivilegesT.Privileges.
//
// Beware: No bounds check is performed. Another member of the struct (TokenPrivilegesT) usually has to be set to the array size.
func (t *TokenPrivilegesT) SetPrivilegesSlice(s []LuidAndAttributes) {
s1 := []LuidAndAttributes{}
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&s1))
hdr.Data = uintptr(unsafe.Pointer(&t.Privileges[0]))
hdr.Len = len(s)
hdr.Cap = len(s)
copy(s1, s)
}
// TokenOwnerT has been derived from the TOKEN_OWNER struct definition.
type TokenOwnerT struct {
Owner *Sid
}
// TokenPrimaryGroupT has been derived from the TOKEN_PRIMARY_GROUP struct definition.
type TokenPrimaryGroupT struct {
PrimaryGroup *Sid
}
// TokenDefaultDaclT has been derived from the TOKEN_DEFAULT_DACL struct definition.
type TokenDefaultDaclT struct {
DefaultDacl *Acl
}
// TokenUserClaimsT has been derived from the TOKEN_USER_CLAIMS struct definition.
type TokenUserClaimsT struct {
UserClaims *ClaimsBlob
}
// TokenDeviceClaimsT has been derived from the TOKEN_DEVICE_CLAIMS struct definition.
type TokenDeviceClaimsT struct {
DeviceClaims *ClaimsBlob
}
// TokenGroupsAndPrivilegesT has been derived from the TOKEN_GROUPS_AND_PRIVILEGES struct definition.
type TokenGroupsAndPrivilegesT struct {
SidCount uint32
SidLength uint32
Sids *SidAndAttributes
RestrictedSidCount uint32
RestrictedSidLength uint32
RestrictedSids *SidAndAttributes
PrivilegeCount uint32
PrivilegeLength uint32
Privileges *LuidAndAttributes
AuthenticationId Luid
}
// TokenLinkedTokenT has been derived from the TOKEN_LINKED_TOKEN struct definition.
type TokenLinkedTokenT struct {
LinkedToken Handle
}
// TokenElevationT has been derived from the TOKEN_ELEVATION struct definition.
type TokenElevationT struct {
TokenIsElevated uint32
}
// TokenMandatoryLabelT has been derived from the TOKEN_MANDATORY_LABEL struct definition.
type TokenMandatoryLabelT struct {
Label SidAndAttributes
}
// TokenMandatoryPolicyT has been derived from the TOKEN_MANDATORY_POLICY struct definition.
type TokenMandatoryPolicyT struct {
Policy uint32
}
// TokenAccessInformationT has been derived from the TOKEN_ACCESS_INFORMATION struct definition.
type TokenAccessInformationT struct {
SidHash *SidAndAttributesHash
RestrictedSidHash *SidAndAttributesHash
Privileges *TokenPrivilegesT
AuthenticationId Luid
TokenType TokenTypeT
ImpersonationLevel SecurityImpersonationLevel
MandatoryPolicy TokenMandatoryPolicyT
Flags uint32
AppContainerNumber uint32
PackageSid *Sid
CapabilitiesHash *SidAndAttributesHash
TrustLevelSid *Sid
SecurityAttributes *SecurityAttributesOpaque
}
// TokenAuditPolicyT has been derived from the TOKEN_AUDIT_POLICY struct definition.
type TokenAuditPolicyT struct {
PerUserPolicy [30]byte
}
// TokenSourceT has been derived from the TOKEN_SOURCE struct definition.
type TokenSourceT struct {
SourceName [8]byte
SourceIdentifier Luid
}
// TokenStatisticsT has been derived from the TOKEN_STATISTICS struct definition.
type TokenStatisticsT struct {
TokenId Luid
AuthenticationId Luid
ExpirationTime int64
TokenType TokenTypeT
ImpersonationLevel SecurityImpersonationLevel
DynamicCharged uint32
DynamicAvailable uint32
GroupCount uint32
PrivilegeCount uint32
ModifiedId Luid
}
// TokenControlT has been derived from the TOKEN_CONTROL struct definition.
type TokenControlT struct {
TokenId Luid
AuthenticationId Luid
ModifiedId Luid
TokenSource TokenSourceT
}
// TokenOriginT has been derived from the TOKEN_ORIGIN struct definition.
type TokenOriginT struct {
OriginatingLogonSession Luid
}
// TokenAppcontainerInformationT has been derived from the TOKEN_APPCONTAINER_INFORMATION struct definition.
type TokenAppcontainerInformationT struct {
TokenAppContainer *Sid
}
// TokenSidInformationT has been derived from the TOKEN_SID_INFORMATION struct definition.
type TokenSidInformationT struct {
Sid *Sid
}
// Luid has been derived from the LUID struct definition.
type Luid struct {
LowPart uint32
HighPart int32
}
// LuidAndAttributes has been derived from the LUID_AND_ATTRIBUTES struct definition.
type LuidAndAttributes struct {
Luid Luid
Attributes uint32
}
// SidAndAttributes has been derived from the SID_AND_ATTRIBUTES struct definition.
type SidAndAttributes struct {
Sid *Sid
Attributes uint32
}
// SidAndAttributesHash has been derived from the SID_AND_ATTRIBUTES_HASH struct definition.
type SidAndAttributesHash struct {
SidCount uint32
SidAttr *SidAndAttributes
Hash [32]SidHashEntry
}
// OUT-parameter: TokenHandle.
func NtOpenThreadToken(
ThreadHandle Handle,
DesiredAccess AccessMask,
OpenAsSelf bool,
TokenHandle *Handle,
) NtStatus {
r0, _, _ := procNtOpenThreadToken.Call(uintptr(ThreadHandle),
uintptr(DesiredAccess),
fromBool(OpenAsSelf),
uintptr(unsafe.Pointer(TokenHandle)))
return NtStatus(r0)
}
// OUT-parameter: TokenHandle.
func NtOpenThreadTokenEx(
ThreadHandle Handle,
DesiredAccess AccessMask,
OpenAsSelf bool,
HandleAttributes uint32,
TokenHandle *Handle,
) NtStatus {
r0, _, _ := procNtOpenThreadTokenEx.Call(uintptr(ThreadHandle),
uintptr(DesiredAccess),
fromBool(OpenAsSelf),
uintptr(HandleAttributes),
uintptr(unsafe.Pointer(TokenHandle)))
return NtStatus(r0)
}
// OUT-parameter: TokenHandle.
func NtOpenProcessToken(
ProcessHandle Handle,
DesiredAccess AccessMask,
TokenHandle *Handle,
) NtStatus {
r0, _, _ := procNtOpenProcessToken.Call(uintptr(ProcessHandle),
uintptr(DesiredAccess),
uintptr(unsafe.Pointer(TokenHandle)))
return NtStatus(r0)
}
// OUT-parameter: TokenHandle.
func NtOpenProcessTokenEx(
ProcessHandle Handle,
DesiredAccess AccessMask,
HandleAttributes uint32,
TokenHandle *Handle,
) NtStatus {
r0, _, _ := procNtOpenProcessTokenEx.Call(uintptr(ProcessHandle),
uintptr(DesiredAccess),
uintptr(HandleAttributes),
uintptr(unsafe.Pointer(TokenHandle)))
return NtStatus(r0)
}
// OUT-parameter: TokenHandle.
func NtOpenJobObjectToken(
JobHandle Handle,
DesiredAccess AccessMask,
TokenHandle *Handle,
) NtStatus {
r0, _, _ := procNtOpenJobObjectToken.Call(uintptr(JobHandle),
uintptr(DesiredAccess),
uintptr(unsafe.Pointer(TokenHandle)))
return NtStatus(r0)
}
// OUT-parameter: NewTokenHandle.
// *OPT-parameter: ObjectAttributes.
func NtDuplicateToken(
ExistingTokenHandle Handle,
DesiredAccess AccessMask,
ObjectAttributes *ObjectAttributes,
EffectiveOnly bool,
TokenType TokenTypeT,
NewTokenHandle *Handle,
) NtStatus {
r0, _, _ := procNtDuplicateToken.Call(uintptr(ExistingTokenHandle),
uintptr(DesiredAccess),
uintptr(unsafe.Pointer(ObjectAttributes)),
fromBool(EffectiveOnly),
uintptr(TokenType),
uintptr(unsafe.Pointer(NewTokenHandle)))
return NtStatus(r0)
}
// OUT-parameter: NewTokenHandle.
// *OPT-parameter: SidsToDisable, PrivilegesToDelete, RestrictedSids.
func NtFilterToken(
ExistingTokenHandle Handle,
Flags uint32,
SidsToDisable *TokenGroupsT,
PrivilegesToDelete *TokenPrivilegesT,
RestrictedSids *TokenGroupsT,
NewTokenHandle *Handle,
) NtStatus {
r0, _, _ := procNtFilterToken.Call(uintptr(ExistingTokenHandle),
uintptr(Flags),
uintptr(unsafe.Pointer(SidsToDisable)),
uintptr(unsafe.Pointer(PrivilegesToDelete)),
uintptr(unsafe.Pointer(RestrictedSids)),
uintptr(unsafe.Pointer(NewTokenHandle)))
return NtStatus(r0)
}
func NtImpersonateAnonymousToken(
ThreadHandle Handle,
) NtStatus {
r0, _, _ := procNtImpersonateAnonymousToken.Call(uintptr(ThreadHandle))
return NtStatus(r0)
}
// OUT-parameter: TokenInformation, ReturnLength.
func NtQueryInformationToken(
TokenHandle Handle,
TokenInformationClass TokenInformationClassT,
TokenInformation *byte,
TokenInformationLength uint32,
ReturnLength *uint32,
) NtStatus {
r0, _, _ := procNtQueryInformationToken.Call(uintptr(TokenHandle),
uintptr(TokenInformationClass),
uintptr(unsafe.Pointer(TokenInformation)),
uintptr(TokenInformationLength),
uintptr(unsafe.Pointer(ReturnLength)))
return NtStatus(r0)
}
func NtSetInformationToken(
TokenHandle Handle,
TokenInformationClass TokenInformationClassT,
TokenInformation *byte,
TokenInformationLength uint32,
) NtStatus {
r0, _, _ := procNtSetInformationToken.Call(uintptr(TokenHandle),
uintptr(TokenInformationClass),
uintptr(unsafe.Pointer(TokenInformation)),
uintptr(TokenInformationLength))
return NtStatus(r0)
}
// OUT-parameter: PreviousState, ReturnLength.
// *OPT-parameter: NewState.
func NtAdjustPrivilegesToken(
TokenHandle Handle,
DisableAllPrivileges bool,
NewState *TokenPrivilegesT,
BufferLength uint32,
PreviousState *TokenPrivilegesT,
ReturnLength *uint32,
) NtStatus {
r0, _, _ := procNtAdjustPrivilegesToken.Call(uintptr(TokenHandle),
fromBool(DisableAllPrivileges),
uintptr(unsafe.Pointer(NewState)),
uintptr(BufferLength),
uintptr(unsafe.Pointer(PreviousState)),
uintptr(unsafe.Pointer(ReturnLength)))
return NtStatus(r0)
}
// OUT-parameter: PreviousState, ReturnLength.
// *OPT-parameter: NewState, BufferLength.
func NtAdjustGroupsToken(
TokenHandle Handle,
ResetToDefault bool,
NewState *TokenGroupsT,
BufferLength uint32,
PreviousState *TokenGroupsT,
ReturnLength *uint32,
) NtStatus {
r0, _, _ := procNtAdjustGroupsToken.Call(uintptr(TokenHandle),
fromBool(ResetToDefault),
uintptr(unsafe.Pointer(NewState)),
uintptr(BufferLength),
uintptr(unsafe.Pointer(PreviousState)),
uintptr(unsafe.Pointer(ReturnLength)))
return NtStatus(r0)
}