-
Notifications
You must be signed in to change notification settings - Fork 77
/
Page09Security.cpp
3590 lines (3054 loc) · 125 KB
/
Page09Security.cpp
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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************/
/* Page09Security.cpp Copyright (c) Ladislav Zezula 2005 */
/*---------------------------------------------------------------------------*/
/* Description : */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* 15.08.05 1.00 Lad The first version of Page09Security.cpp */
/*****************************************************************************/
#include "FileTest.h"
#include "resource.h"
//-----------------------------------------------------------------------------
// Local variables
#define ALL_SACL_SECURITY_INFORMATION 0xFFFFFFF8 // Mask for all system-type security infos
#define ITEM_DATA_MAGIC 0xDEADBABE
#define MAX_ITEM_TEXT 1024
#define MAX_NEST_LEVEL 8
#define ItemDataNULL (PVOID)(INT_PTR)(NULL)
#define ItemDataValid (PVOID)(INT_PTR)(1)
typedef enum _ITEM_TYPE
{
ItemTypeUnknown,
ItemTypeOwner, // The item contains "OWNER_SECURITY_INFORMATION"
ItemTypeGroup, // The item contains "GROUP_SECURITY_INFORMATION"
ItemTypeDacl, // The item contains "DACL_SECURITY_INFORMATION"
ItemTypeSacl, // The item contains "SACL_SECURITY_INFORMATION"
ItemTypeNoAcl, // The item says that an ACL is not present
ItemTypeNullAcl, // NULL ACL
ItemTypeSid, // Security Identifier (SID)
ItemTypeAce, // Access Control Entry (ACE) from DACL
ItemTypeAceType, // ACE_HEADER::AceType
ItemTypeBool, // A boolean value
ItemTypeUint08, // 8-bit integer
ItemTypeUint16, // 16-bit integer
ItemTypeUint32, // 32-bit integer
ItemTypeUint64, // 64-bit integer
ItemTypeLPWSTR, // Pointer to a zero-terminate unicode string (LPWSTR)
ItemTypeBinN, // An octet string with length at the beginning
ItemTypeGuid, // An object GUID
ItemTypeGuid2, // An inherited object GUID
ItemTypeSid11, // mandatory label SID
ItemTypeSid17, // Policy label SID
ItemTypeSid19, // Trust level SID
ItemTypeCSA_V1, // The CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 structure
ItemTypeCSA_VType, // CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1::ValueType
ItemTypeCSA_VCnt, // CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1::ValueCount
ItemTypeSidN, // "Counted" SID (with preceding ULONG, containing length)
ItemTypeCondition, // ACE condition
} ITEM_TYPE, *PITEM_TYPE;
typedef struct _NON_EDITABLE_DATA
{
ULONG Magic; // ITEM_DATA_MAGIC
ULONG Length; // Length of the subsequent data
BYTE Data[1]; // The data itself
} NON_EDITABLE_DATA, *PNON_EDITABLE_DATA;
typedef struct _TREE_ITEM_INFO
{
ITEM_TYPE ItemType;
UINT nIDFormat1; // Format string when no data
UINT nIDFormat2; // Format string when there are data
// Array of flag values and flag names
TFlagInfo * pFlagInfos;
// Converts the binary item to string representation that will be shown in the tree view item
NTSTATUS (*ToString) (_TREE_ITEM_INFO * pItemInfo, LPTSTR szBuffer, size_t ccBuffer, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy);
// Converts the string representation to binary item
NTSTATUS(*StringTo) (_TREE_ITEM_INFO * pItemInfo, LPCTSTR szString, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy);
// Creates a new item of that type
NTSTATUS(*CreateNew)(_TREE_ITEM_INFO * pItemInfo, LPBYTE pbDataBuffer, size_t * pcbDataBuffer);
// Type of the item data
PVOID ItemData;
} TREE_ITEM_INFO, *PTREE_ITEM_INFO;
typedef const TREE_ITEM_INFO *PCTREE_ITEM_INFO;
typedef struct _ACE_FIELD_INFO
{
ULONG AceLayoutFlag;
TREE_ITEM_INFO TreeItem;
} ACE_FIELD_INFO, *PACE_FIELD_INFO;
typedef struct _TV_SELECTION
{
size_t ItemIndex[MAX_NEST_LEVEL]; // Item index in each level
size_t nNestLevel; // Nest level of the item that was selected
} TV_SELECTION, *PTV_SELECTION;
static LPCTSTR szAceTypeSuffix = _T("_TYPE");
static LPCSTR szUnknownAceType = "UNKNOWN_ACE_TYPE: %02x";
static size_t GLOBAL_ItemIndex = INVALID_ITEM_INDEX;
static PACL pAclInWork = NULL; // Current ACL-in-construction
static PACE pAceInWork = NULL; // Current ACE-in-construction
static SID_IDENTIFIER_AUTHORITY SiaNull = SECURITY_NULL_SID_AUTHORITY;
static SID_IDENTIFIER_AUTHORITY SiaWorld = SECURITY_WORLD_SID_AUTHORITY;
static SID_IDENTIFIER_AUTHORITY SiaLabel = SECURITY_MANDATORY_LABEL_AUTHORITY;
static SID_IDENTIFIER_AUTHORITY SiaPolicy = SECURITY_SCOPED_POLICY_ID_AUTHORITY;
static SID_IDENTIFIER_AUTHORITY SiaTrust = SECURITY_PROCESS_TRUST_AUTHORITY;
static const BYTE EmptyAcl[] =
{
ACL_REVISION, 0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const BYTE FullControlAcl[] =
{
0x04, 0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10,
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
};
static const LPCTSTR szNoGuidString = _T("(none)");
static TFlagInfo SecurityInformations[] =
{
FLAGINFO_BITV(OWNER_SECURITY_INFORMATION),
FLAGINFO_BITV(GROUP_SECURITY_INFORMATION),
FLAGINFO_BITV(DACL_SECURITY_INFORMATION),
FLAGINFO_BITV(SACL_SECURITY_INFORMATION),
FLAGINFO_BITV(LABEL_SECURITY_INFORMATION),
FLAGINFO_BITV(ATTRIBUTE_SECURITY_INFORMATION),
FLAGINFO_BITV(SCOPE_SECURITY_INFORMATION),
FLAGINFO_BITV(PROCESS_TRUST_LABEL_SECURITY_INFORMATION),
FLAGINFO_BITV(ACCESS_FILTER_SECURITY_INFORMATION),
FLAGINFO_BITV(BACKUP_SECURITY_INFORMATION),
FLAGINFO_BITV(PROTECTED_DACL_SECURITY_INFORMATION),
FLAGINFO_BITV(PROTECTED_SACL_SECURITY_INFORMATION),
FLAGINFO_BITV(UNPROTECTED_DACL_SECURITY_INFORMATION),
FLAGINFO_BITV(UNPROTECTED_SACL_SECURITY_INFORMATION),
FLAGINFO_END()
};
static TFlagInfo AclRevFlags[] =
{
FLAGINFO_NUMV(ACL_REVISION1),
FLAGINFO_NUMV(ACL_REVISION2),
FLAGINFO_NUMV(ACL_REVISION3),
FLAGINFO_NUMV(ACL_REVISION_DS),
FLAGINFO_END()
};
static TFlagInfo AceHdrTypes[] =
{
FLAGINFO_NUMV(ACCESS_ALLOWED_ACE_TYPE),
FLAGINFO_NUMV(ACCESS_DENIED_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_AUDIT_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_ALARM_ACE_TYPE),
FLAGINFO_NUMV(ACCESS_ALLOWED_COMPOUND_ACE_TYPE),
FLAGINFO_NUMV(ACCESS_ALLOWED_OBJECT_ACE_TYPE),
FLAGINFO_NUMV(ACCESS_DENIED_OBJECT_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_AUDIT_OBJECT_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_ALARM_OBJECT_ACE_TYPE),
FLAGINFO_NUMV(ACCESS_ALLOWED_CALLBACK_ACE_TYPE),
FLAGINFO_NUMV(ACCESS_DENIED_CALLBACK_ACE_TYPE),
FLAGINFO_NUMV(ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE),
FLAGINFO_NUMV(ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_AUDIT_CALLBACK_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_ALARM_CALLBACK_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_MANDATORY_LABEL_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_SCOPED_POLICY_ID_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_PROCESS_TRUST_LABEL_ACE_TYPE),
FLAGINFO_NUMV(SYSTEM_ACCESS_FILTER_ACE_TYPE),
FLAGINFO_END()
};
static TFlagInfo AceHdrFlags[] =
{
FLAGINFO_BITV(OBJECT_INHERIT_ACE),
FLAGINFO_BITV(CONTAINER_INHERIT_ACE),
FLAGINFO_BITV(NO_PROPAGATE_INHERIT_ACE),
FLAGINFO_BITV(INHERIT_ONLY_ACE),
FLAGINFO_BITV(INHERITED_ACE),
FLAGINFO_BITV(SUCCESSFUL_ACCESS_ACE_FLAG),
FLAGINFO_BITV(FAILED_ACCESS_ACE_FLAG),
FLAGINFO_END()
};
static TFlagInfo AceHdrFlags2[] =
{
FLAGINFO_BITV(OBJECT_INHERIT_ACE),
FLAGINFO_BITV(CONTAINER_INHERIT_ACE),
FLAGINFO_BITV(NO_PROPAGATE_INHERIT_ACE),
FLAGINFO_BITV(INHERIT_ONLY_ACE),
FLAGINFO_BITV(INHERITED_ACE),
FLAGINFO_BITV(TRUST_PROTECTED_FILTER_ACE_FLAG),
FLAGINFO_END()
};
static TFlagInfo AceMasks[] =
{
FLAGINFO_BITV(FILE_READ_DATA),
FLAGINFO_BITV(FILE_WRITE_DATA),
FLAGINFO_BITV(FILE_APPEND_DATA),
FLAGINFO_BITV(FILE_READ_EA),
FLAGINFO_BITV(FILE_WRITE_EA),
FLAGINFO_BITV(FILE_EXECUTE),
FLAGINFO_BITV(FILE_DELETE_CHILD),
FLAGINFO_BITV(FILE_READ_ATTRIBUTES),
FLAGINFO_BITV(FILE_WRITE_ATTRIBUTES),
FLAGINFO_BITV(DELETE),
FLAGINFO_BITV(READ_CONTROL),
FLAGINFO_BITV(WRITE_DAC),
FLAGINFO_BITV(WRITE_OWNER),
FLAGINFO_BITV(SYNCHRONIZE),
FLAGINFO_BITV(GENERIC_WRITE),
FLAGINFO_BITV(GENERIC_READ),
FLAGINFO_BITV(GENERIC_WRITE),
FLAGINFO_BITV(GENERIC_EXECUTE),
FLAGINFO_BITV(GENERIC_ALL),
FLAGINFO_END()
};
static TFlagInfo AdsAceMasks[] =
{
FLAGINFO_BITV(ADS_RIGHT_DS_CREATE_CHILD),
FLAGINFO_BITV(ADS_RIGHT_DS_DELETE_CHILD),
FLAGINFO_BITV(ADS_RIGHT_ACTRL_DS_LIST),
FLAGINFO_BITV(ADS_RIGHT_DS_SELF),
FLAGINFO_BITV(ADS_RIGHT_DS_READ_PROP),
FLAGINFO_BITV(ADS_RIGHT_DS_WRITE_PROP),
FLAGINFO_BITV(ADS_RIGHT_DS_DELETE_TREE),
FLAGINFO_BITV(ADS_RIGHT_DS_LIST_OBJECT),
FLAGINFO_BITV(ADS_RIGHT_DS_CONTROL_ACCESS),
FLAGINFO_BITV(ADS_RIGHT_DELETE),
FLAGINFO_BITV(ADS_RIGHT_READ_CONTROL),
FLAGINFO_BITV(ADS_RIGHT_WRITE_DAC),
FLAGINFO_BITV(ADS_RIGHT_WRITE_OWNER),
FLAGINFO_BITV(ADS_RIGHT_SYNCHRONIZE),
FLAGINFO_BITV(ADS_RIGHT_ACCESS_SYSTEM_SECURITY),
FLAGINFO_BITV(ADS_RIGHT_GENERIC_READ),
FLAGINFO_BITV(ADS_RIGHT_GENERIC_WRITE),
FLAGINFO_BITV(ADS_RIGHT_GENERIC_EXECUTE),
FLAGINFO_BITV(ADS_RIGHT_GENERIC_ALL),
FLAGINFO_END()
};
static TFlagInfo LabelMasks[] =
{
FLAGINFO_BITV(SYSTEM_MANDATORY_LABEL_NO_WRITE_UP),
FLAGINFO_BITV(SYSTEM_MANDATORY_LABEL_NO_READ_UP),
FLAGINFO_BITV(SYSTEM_MANDATORY_LABEL_NO_EXECUTE_UP),
FLAGINFO_END()
};
static TFlagInfo CAceTypes[] =
{
FLAGINFO_BITV(COMPOUND_ACE_IMPERSONATION),
FLAGINFO_END()
};
static TFlagInfo ObjAceFlags[] =
{
FLAGINFO_BITV(ACE_OBJECT_TYPE_PRESENT),
FLAGINFO_BITV(ACE_INHERITED_OBJECT_TYPE_PRESENT),
FLAGINFO_END()
};
static TFlagInfo CompoundAceTypes[] =
{
FLAGINFO_BITV(COMPOUND_ACE_IMPERSONATION),
FLAGINFO_END()
};
static TFlagInfo IntgrLevels[] =
{
FLAGINFO_NUMV(SECURITY_MANDATORY_UNTRUSTED_RID),
FLAGINFO_NUMV(SECURITY_MANDATORY_LOW_RID),
FLAGINFO_NUMV(SECURITY_MANDATORY_MEDIUM_RID),
FLAGINFO_NUMV(SECURITY_MANDATORY_MEDIUM_PLUS_RID),
FLAGINFO_NUMV(SECURITY_MANDATORY_HIGH_RID),
FLAGINFO_NUMV(SECURITY_MANDATORY_SYSTEM_RID),
FLAGINFO_NUMV(SECURITY_MANDATORY_PROTECTED_PROCESS_RID),
FLAGINFO_END()
};
// Process trust types
// Source: https://github.com/googleprojectzero/sandbox-attacksurface-analysis-tools/NtApiDotNet/NtSemaphore.cs
#define TT_None 0
#define TT_ProtectedLight 512
#define TT_Protected 1024
static TFlagInfo PsTrustTypes[] =
{
FLAGINFO_NUMV(TT_None),
FLAGINFO_NUMV(TT_ProtectedLight),
FLAGINFO_NUMV(TT_Protected),
FLAGINFO_END()
};
// Process trust levels
#define TL_None 0
#define TL_Authenticode 1024
#define TL_AntiMalware 1536
#define TL_App 2048
#define TL_Windows 4096
#define TL_WinTcb 8192
static TFlagInfo PsTrustLevels[] =
{
FLAGINFO_NUMV(TL_None),
FLAGINFO_NUMV(TL_Authenticode),
FLAGINFO_NUMV(TL_AntiMalware),
FLAGINFO_NUMV(TL_App),
FLAGINFO_NUMV(TL_Windows),
FLAGINFO_NUMV(TL_WinTcb),
FLAGINFO_END()
};
static TFlagInfo CSA_ValTypes[] =
{
FLAGINFO_NUMV(CLAIM_SECURITY_ATTRIBUTE_TYPE_INVALID),
FLAGINFO_NUMV(CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64),
FLAGINFO_NUMV(CLAIM_SECURITY_ATTRIBUTE_TYPE_UINT64),
FLAGINFO_NUMV(CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING),
FLAGINFO_NUMV(CLAIM_SECURITY_ATTRIBUTE_TYPE_FQBN),
FLAGINFO_NUMV(CLAIM_SECURITY_ATTRIBUTE_TYPE_SID),
FLAGINFO_NUMV(CLAIM_SECURITY_ATTRIBUTE_TYPE_BOOLEAN),
FLAGINFO_NUMV(CLAIM_SECURITY_ATTRIBUTE_TYPE_OCTET_STRING),
FLAGINFO_END()
};
static TFlagInfo CSA_Flags[] =
{
FLAGINFO_BITV(CLAIM_SECURITY_ATTRIBUTE_NON_INHERITABLE),
FLAGINFO_BITV(CLAIM_SECURITY_ATTRIBUTE_VALUE_CASE_SENSITIVE),
FLAGINFO_BITV(CLAIM_SECURITY_ATTRIBUTE_USE_FOR_DENY_ONLY),
FLAGINFO_BITV(CLAIM_SECURITY_ATTRIBUTE_DISABLED_BY_DEFAULT),
FLAGINFO_BITV(CLAIM_SECURITY_ATTRIBUTE_DISABLED),
FLAGINFO_BITV(CLAIM_SECURITY_ATTRIBUTE_MANDATORY),
FLAGINFO_END()
};
//-----------------------------------------------------------------------------
// Debug
//#define _COMPARE_ACLS
#ifdef _COMPARE_ACLS
BYTE SaveAclBuffer[MAX_ACL_LENGTH] = {0};
#endif
//-----------------------------------------------------------------------------
// Local functions
static void ReverseArrayItems(HTREEITEM array[], size_t length)
{
size_t start = 0;
size_t end = length - 1;
while(start < end)
{
// Swap elements at start and end indices
HTREEITEM temp = array[start];
array[start] = array[end];
array[end] = temp;
// Move indices towards the center
start++;
end--;
}
}
static PNON_EDITABLE_DATA IsItemDataPointer(PVOID ptr)
{
if((UINT_PTR)(ptr) > 0x100)
{
if(((PNON_EDITABLE_DATA)(ptr))->Magic == ITEM_DATA_MAGIC)
{
return (PNON_EDITABLE_DATA)(ptr);
}
}
return NULL;
}
static bool IsValidAceAttributeType(LPBYTE pbBuffer)
{
WORD wValueType = *(PWORD)(pbBuffer);
// Check valid values
if(CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64 <= wValueType && wValueType <= CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING)
return true;
if(CLAIM_SECURITY_ATTRIBUTE_TYPE_SID <= wValueType && wValueType <= CLAIM_SECURITY_ATTRIBUTE_TYPE_OCTET_STRING)
return true;
return false;
}
static bool IsValidAceAttributeCount(LPBYTE pbBuffer)
{
DWORD dwValueCount = *(PDWORD)(pbBuffer);
// Artificially limited value count
return (0 < dwValueCount && dwValueCount <= 100);
}
static bool IsItemTypeEditable(PTREE_ITEM_INFO pItemInfo)
{
switch(pItemInfo->ItemType)
{
case ItemTypeAce:
case ItemTypeCondition:
return false;
default:
return true;
}
}
static bool IsIntegerTypeWithFlags(PTREE_ITEM_INFO pItemInfo)
{
int nItemType;
if(pItemInfo->pFlagInfos != NULL)
{
nItemType = (int)pItemInfo->ItemType;
return ((int)ItemTypeUint08 <= nItemType && nItemType <= (int)ItemTypeUint64);
}
return false;
}
static LPCSTR GetAceTypeString(DWORD AceType)
{
static CHAR szBuffer[64];
BYTE MaxAceType = (BYTE)(_countof(AceHdrTypes) - 1);
// Insert the "root" item with ACE type
if(AceType < MaxAceType)
return AceHdrTypes[AceType].szFlagText;
// Prepare string for an unknown ACE type
StringCchPrintfA(szBuffer, _countof(szBuffer), szUnknownAceType, AceType);
return szBuffer;
}
static bool GetAceTypeString(LPTSTR szBuffer, size_t ccBuffer, PACE_HEADER pAceHeader)
{
LPCSTR szAceType = GetAceTypeString(pAceHeader->AceType);
LPTSTR szSuffix;
// Format the ACE type name
StringCchPrintf(szBuffer, ccBuffer, _T("%hs"), szAceType);
// Cut off the "_TYPE" suffix
if((szSuffix = _tcsrchr(szBuffer, _T('_'))) != NULL)
{
if(!_tcscmp(szSuffix, szAceTypeSuffix))
{
szSuffix[0] = 0;
}
}
return true;
}
static ULONG AceObjectGuidFlag(ITEM_TYPE ItemType)
{
if(ItemType == ItemTypeGuid)
return ACE_OBJECT_TYPE_PRESENT;
if(ItemType == ItemTypeGuid2)
return ACE_INHERITED_OBJECT_TYPE_PRESENT;
return 0;
}
static ULONG AceObjectGuidPresent(PACE pAce, ITEM_TYPE ItemType)
{
if(pAce != NULL)
{
ACE_HELPER AceHelper(pAce->Header.AceType);
if(AceHelper.AceLayout & ACE_FIELD_GUID_FLAGS)
{
return (pAce->Flags & AceObjectGuidFlag(ItemType));
}
}
return 0;
}
void SidToString(PSID pvSid, LPTSTR szString, size_t cchString, bool bAddUserName)
{
PSID_IDENTIFIER_AUTHORITY pSia;
SID * pSid = (SID *)pvSid;
LPTSTR szStringEnd = szString + cchString;
UCHAR SubAuthCount;
// Add the "S-%u-" begin with revision
pSia = GetSidIdentifierAuthority(pSid);
StringCchPrintfEx(szString, (szStringEnd - szString), &szString, NULL, 0, _T("S-%u-%u"),
pSid->Revision,
pSia->Value[5]);
// Add the subauthorities
SubAuthCount = *GetSidSubAuthorityCount(pSid);
for(DWORD i = 0; i < SubAuthCount; i++)
{
DWORD dwSubAuth = *GetSidSubAuthority(pSid, i);
StringCchPrintfEx(szString, (szStringEnd - szString), &szString, NULL, 0, L"-%u", dwSubAuth);
}
// If we are required to add user name, do it.
if(bAddUserName)
{
SID_NAME_USE SidNameUse;
TCHAR szDomainName[128] = _T("");
TCHAR szUserName[128] = _T("");
DWORD cchDomainName = _countof(szDomainName);
DWORD cchUserName = _countof(szUserName);
if(LookupAccountSid(NULL, pSid, szUserName, &cchUserName, szDomainName, &cchDomainName, &SidNameUse))
{
if(szDomainName[0] != 0)
StringCchPrintf(szString, (szStringEnd - szString), _T(" (%s\\%s)"), szDomainName, szUserName);
else
StringCchPrintf(szString, (szStringEnd - szString), _T(" (%s)"), szUserName);
}
else
{
StringCchPrintf(szString, (szStringEnd - szString), _T(" (Unknown SID)"));
}
}
}
//
// The SID in the SYSTEM_MANDATORY_LABEL_ACE has the following format:
//
// - IdentifierAuthority is set to SECURITY_MANDATORY_LABEL_AUTHORITY
// - The last subauthority is set to one of the SECURITY_MANDATORY_XXXX values
//
static LPBYTE GetSystemSidIntegerValue(PSID pSid, PSID_IDENTIFIER_AUTHORITY pSiaExpected, UCHAR SubAuthCountNeeded = 1)
{
UCHAR SubAuthCount;
if(pSid != NULL && RtlLengthSid(pSid) > FIELD_OFFSET(SYSTEM_MANDATORY_LABEL_ACE, SidStart))
{
PSID_IDENTIFIER_AUTHORITY pSia = GetSidIdentifierAuthority(pSid);
// Compare the required identifier authority
if(!memcmp(pSia, pSiaExpected, sizeof(SID_IDENTIFIER_AUTHORITY)))
{
// Get the number of sub-authorities
if((SubAuthCount = *GetSidSubAuthorityCount(pSid)) == SubAuthCountNeeded)
{
// Get the last authority
return (LPBYTE)GetSidSubAuthority(pSid, 0);
}
}
}
// Return NULL
assert(false);
return NULL;
}
static LPBYTE GetSidIntegrityLevel(PSID pSid)
{
return GetSystemSidIntegerValue(pSid, &SiaLabel);
}
static LPBYTE GetSidScopedPolicyId(PSID pSid)
{
return GetSystemSidIntegerValue(pSid, &SiaPolicy);
}
static LPBYTE GetSidProcessTrustLevel(PSID pSid)
{
return GetSystemSidIntegerValue(pSid, &SiaTrust, 2);
}
//-----------------------------------------------------------------------------
// Local functions - tree items
static DWORD GetDefaultAceTypeForAcl(PCTREE_ITEM_INFO pItemInfo)
{
return (pItemInfo->ItemType == ItemTypeSacl) ? SYSTEM_MANDATORY_LABEL_ACE_TYPE : ACCESS_ALLOWED_ACE_TYPE;
}
static int GetDefaultCharLimit(PCTREE_ITEM_INFO pItemInfo)
{
if(pItemInfo->ItemType == ItemTypeUint08 || pItemInfo->ItemType == ItemTypeAceType)
return 8;
if(pItemInfo->ItemType == ItemTypeUint16)
return 16;
if(pItemInfo->ItemType == ItemTypeUint32)
return 32;
if(pItemInfo->ItemType == ItemTypeUint64)
return 64;
return 256;
}
static void UpdateAceVariables(PACE pAce, LPBYTE pbPtr)
{
if(pAce != NULL)
{
LPBYTE pbAce = (LPBYTE)(pAce);
// Update the length of the ACE
pAce->Header.AceSize = (WORD)(pbPtr - pbAce);
// Update the ACL-in-work variables
if(pAclInWork != NULL)
{
// If the ACE is of ACCESS_ALLOWED_COMPOUND_ACE_TYPE, the ACL revision must be 3 or higher
if(pAce->Header.AceType == ACCESS_ALLOWED_COMPOUND_ACE_TYPE)
pAclInWork->AclRevision = max(pAclInWork->AclRevision, ACL_REVISION3);
// If the ACE is one of the object ACEs or later, raise the ACL revision
if(pAce->Header.AceType >= ACCESS_ALLOWED_OBJECT_ACE_TYPE)
pAclInWork->AclRevision = max(pAclInWork->AclRevision, ACL_REVISION_DS);
// Update the ACE count
pAclInWork->AceCount++;
}
}
}
// The item text is expected to be in format "Name: 0x12345678"
static LPTSTR GetItemTextValue(LPTSTR szItemText, bool bKeepQuotedPart = false)
{
LPTSTR szStringEnd;
LPTSTR szTextPtr;
// Retrieve the first occurence of ":"
if((szTextPtr = _tcschr(szItemText, _T(':'))) != NULL)
{
// Skip the colon
szItemText = szTextPtr + 1;
// Skip spaces
while(szItemText[0] == ' ')
szItemText++;
// Did we come across a quotation mark?
if(szItemText[0] == _T('\"'))
{
if((szStringEnd = _tcschr(szItemText + 1, _T('\"'))) > szItemText)
{
szStringEnd[0] = 0;
szItemText += 1;
}
}
// If the number is followed by a space, cut it
if(bKeepQuotedPart == false)
{
if((szTextPtr = _tcschr(szItemText, _T(' '))) != NULL)
{
szTextPtr[0] = 0;
}
}
}
// Return the text
return szItemText;
}
static bool TV_TextToEditText(const _TREE_ITEM_INFO * pItemInfo, LPTSTR szBuffer, size_t ccBuffer, LPCTSTR szItemText)
{
LPCTSTR szTextValue;
// Copy the entire text from the source to the target
StringCchCopy(szBuffer, ccBuffer, szItemText);
// Extract the text value from the item
szTextValue = GetItemTextValue(szBuffer, (pItemInfo->ItemType == ItemTypeCondition));
// Move the text value
if(szTextValue > szBuffer)
memmove(szBuffer, szTextValue, (_tcslen(szTextValue) + 1) * sizeof(TCHAR));
return true;
}
static void TV_MakeItemText(
PTREE_ITEM_INFO pItemInfo,
LPTSTR szBuffer,
size_t ccBuffer,
LPBYTE pbPtr,
LPBYTE pbEnd,
PULONG pcbMoveBy = NULL)
{
ULONG cbMoveBy = 0;
TCHAR szDataText[0x400] = {0};
UINT nIDFormat = pItemInfo->nIDFormat1;
bool bApplyIndex = false;
// Do we have data and format for it?
if(pItemInfo->nIDFormat2)
{
if(pItemInfo->ToString != NULL)
{
// Format the numeric or whatever value
if(NT_SUCCESS(pItemInfo->ToString(pItemInfo, szDataText, _countof(szDataText), pbPtr, pbEnd, &cbMoveBy)))
{
nIDFormat = pItemInfo->nIDFormat2;
bApplyIndex = true;
}
}
}
// Finally, format the data to the item
if(pcbMoveBy != NULL)
pcbMoveBy[0] = cbMoveBy;
// Format the final value
if(GLOBAL_ItemIndex != INVALID_ITEM_INDEX && bApplyIndex)
rsprintf(szBuffer, ccBuffer, nIDFormat, GLOBAL_ItemIndex, szDataText);
else
rsprintf(szBuffer, ccBuffer, nIDFormat, szDataText);
}
//-----------------------------------------------------------------------------
// Conversion of String <-> Integer Value (Hex)
template <typename INTEGER>
NTSTATUS ToString_Hex(PTREE_ITEM_INFO pItemInfo, LPTSTR szBuffer, size_t ccBuffer, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
ULONG64 dwIntValue = 0;
// Capture the integer value
if((pbPtr + sizeof(INTEGER)) > pbEnd)
return STATUS_BUFFER_OVERFLOW;
if(ccBuffer < (sizeof(INTEGER) * 2) + 1)
return STATUS_BUFFER_OVERFLOW;
dwIntValue = *(INTEGER *)(pbPtr);
// Write the "0x" prefix
StringCchCopyEx(szBuffer, ccBuffer, _T("0x"), &szBuffer, &ccBuffer, 0);
// Convert to string
Hex2TextXX(dwIntValue, szBuffer, sizeof(INTEGER));
// If the value has flags, we add the flags suffix
if(pItemInfo->pFlagInfos != NULL)
{
// Convert the flags to their text representations
TFlagString fs(pItemInfo->pFlagInfos, dwIntValue);
if(fs.GetConvertedFlagsCount())
{
StringCchCat(szBuffer, ccBuffer, _T(" "));
StringCchCat(szBuffer, ccBuffer, fs);
}
}
// Give the move by
if(pcbMoveBy != NULL)
pcbMoveBy[0] = sizeof(INTEGER);
return STATUS_SUCCESS;
}
template <typename INTEGER>
NTSTATUS StringTo_Hex(PTREE_ITEM_INFO /* pItemInfo */, LPCTSTR szString, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
LONGLONG dwIntValue;
if((pbPtr + sizeof(INTEGER)) <= pbEnd)
{
if(Text2Hex64(szString, &dwIntValue) == ERROR_SUCCESS)
{
// Copy the integer
*(INTEGER *)(pbPtr) = (INTEGER)(dwIntValue);
// Give the pcbMoveBy
if(pcbMoveBy != NULL)
pcbMoveBy[0] = sizeof(INTEGER);
return STATUS_SUCCESS;
}
}
return STATUS_BUFFER_OVERFLOW;
}
static NTSTATUS ToString_Hex1(PTREE_ITEM_INFO pItemInfo, LPTSTR szBuffer, size_t ccBuffer, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
return ToString_Hex<BYTE>(pItemInfo, szBuffer, ccBuffer, pbPtr, pbEnd, pcbMoveBy);
}
static NTSTATUS StringTo_Hex1(PTREE_ITEM_INFO pItemInfo, LPCTSTR szString, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
return StringTo_Hex<BYTE>(pItemInfo, szString, pbPtr, pbEnd, pcbMoveBy);
}
static NTSTATUS ToString_Hex2(PTREE_ITEM_INFO pItemInfo, LPTSTR szBuffer, size_t ccBuffer, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
return ToString_Hex<WORD>(pItemInfo, szBuffer, ccBuffer, pbPtr, pbEnd, pcbMoveBy);
}
static NTSTATUS StringTo_Hex2(PTREE_ITEM_INFO pItemInfo, LPCTSTR szString, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
return StringTo_Hex<WORD>(pItemInfo, szString, pbPtr, pbEnd, pcbMoveBy);
}
static NTSTATUS ToString_Hex4(PTREE_ITEM_INFO pItemInfo, LPTSTR szBuffer, size_t ccBuffer, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
return ToString_Hex<DWORD>(pItemInfo, szBuffer, ccBuffer, pbPtr, pbEnd, pcbMoveBy);
}
static NTSTATUS StringTo_Hex4(PTREE_ITEM_INFO pItemInfo, LPCTSTR szString, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
return StringTo_Hex<DWORD>(pItemInfo, szString, pbPtr, pbEnd, pcbMoveBy);
}
static NTSTATUS ToString_Hex8(PTREE_ITEM_INFO pItemInfo, LPTSTR szBuffer, size_t ccBuffer, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
return ToString_Hex<DWORD64>(pItemInfo, szBuffer, ccBuffer, pbPtr, pbEnd, pcbMoveBy);
}
static NTSTATUS StringTo_Hex8(PTREE_ITEM_INFO pItemInfo, LPCTSTR szString, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
return StringTo_Hex<DWORD64>(pItemInfo, szString, pbPtr, pbEnd, pcbMoveBy);
}
// For fields that are auto-calculated, such as ACE_HEADER::AceSize
static NTSTATUS StringTo_Auto(PTREE_ITEM_INFO pItemInfo, LPCTSTR /* szString */, LPBYTE /* pbPtr */, LPBYTE /* pbEnd */, PULONG pcbMoveBy = NULL)
{
if(pcbMoveBy != NULL)
pcbMoveBy[0] = (pItemInfo->ItemType == ItemTypeUint16) ? sizeof(USHORT) : sizeof(DWORD);
return (pAclInWork || pAceInWork) ? STATUS_SUCCESS : STATUS_AUTO_CALCULATED;
}
//-----------------------------------------------------------------------------
// Conversion of String <-> Trust Level
static bool ToString_TrustLevel(PTREE_ITEM_INFO /* pItemInfo */, LPTSTR szBuffer, size_t ccBuffer, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
LPDWORD PtrTrustLevels = (LPDWORD)(pbPtr);
LPTSTR szBuffEnd = szBuffer + ccBuffer - 1;
ULONG cbMoveBy = 0;
if((pbPtr + sizeof(DWORD64)) <= pbEnd)
{
// Write the 64-bit value
StringCchPrintfEx(szBuffer, (szBuffEnd - szBuffer), &szBuffer, NULL, 0, _T("%x-%x "), PtrTrustLevels[0], PtrTrustLevels[1]);
// Write the trust levels
szBuffer = FlagsToString(PsTrustTypes, szBuffer, (szBuffEnd - szBuffer), *(LPDWORD)(pbPtr + 0));
StringCchCatEx(szBuffer, (szBuffEnd - szBuffer), _T("/"), &szBuffer, NULL, 0);
szBuffer = FlagsToString(PsTrustLevels, szBuffer, (szBuffEnd - szBuffer), *(LPDWORD)(pbPtr + 4));
cbMoveBy = sizeof(DWORD64);
}
// Give the pcbMoveBy
if(pcbMoveBy != NULL)
pcbMoveBy[0] = cbMoveBy;
return (cbMoveBy != 0);
}
static NTSTATUS StringTo_TrustLevel(PTREE_ITEM_INFO /* pItemInfo */, LPCTSTR szString, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
LPTSTR szHiPart;
LPTSTR szLoPart;
NTSTATUS Status = STATUS_UNSUCCESSFUL;
DWORD TrustLevel[2];
TCHAR szBuffer[0x40];
if((pbPtr + sizeof(DWORD64)) <= pbEnd)
{
StringCchCopy(szBuffer, _countof(szBuffer), szString);
szHiPart = szBuffer;
if((szLoPart = _tcschr(szHiPart, _T('-'))) != NULL)
{
*szLoPart++ = 0;
if(Text2Hex32(szHiPart, &TrustLevel[0]) == ERROR_SUCCESS &&
Text2Hex32(szLoPart, &TrustLevel[1]) == ERROR_SUCCESS)
{
if(pcbMoveBy != NULL)
pcbMoveBy[0] = sizeof(DWORD64);
memcpy(pbPtr, TrustLevel, sizeof(TrustLevel));
Status = STATUS_SUCCESS;
}
}
}
return Status;
}
//-----------------------------------------------------------------------------
// Conversion of String <-> Binary Data: BOOL
static NTSTATUS ToString_Bool(PTREE_ITEM_INFO /* pItemInfo */, LPTSTR szBuffer, size_t ccBuffer, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
if((pbPtr + sizeof(BYTE)) > pbEnd)
return STATUS_BUFFER_OVERFLOW;
if(pcbMoveBy != NULL)
pcbMoveBy[0] = sizeof(BYTE);
StringCchCopy(szBuffer, ccBuffer, pbPtr[0] ? _T("TRUE") : _T("FALSE"));
return STATUS_SUCCESS;
}
static NTSTATUS StringTo_Bool(PTREE_ITEM_INFO pItemInfo, LPCTSTR szString, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
NTSTATUS Status;
BYTE FalseValue = 0;
BYTE TrueValue = 1;
BYTE ItemValue[1];
// Check for TRUE / FALSE
if(!_tcsicmp(szString, _T("FALSE")) || !_tcsicmp(szString, _T("OFF")))
return CopyDataAway(pbPtr, pbEnd, &FalseValue, sizeof(FalseValue), pcbMoveBy);
if(!_tcsicmp(szString, _T("TRUE")) || !_tcsicmp(szString, _T("ON")))
return CopyDataAway(pbPtr, pbEnd, &TrueValue, sizeof(TrueValue), pcbMoveBy);
// Try numeric value. If nonzero, it's TRUE, if not, it's FALSE
if((Status = StringTo_Hex1(pItemInfo, szString, &ItemValue[0], &ItemValue[1])) == STATUS_SUCCESS)
{
if(ItemValue[0] == 0)
return CopyDataAway(pbPtr, pbEnd, &FalseValue, sizeof(FalseValue), pcbMoveBy);
else
return CopyDataAway(pbPtr, pbEnd, &TrueValue, sizeof(TrueValue), pcbMoveBy);
}
return Status;
}
//-----------------------------------------------------------------------------
// Conversion of LPWSTR to string
static NTSTATUS ToString_STR(PTREE_ITEM_INFO /* pItemInfo */, LPTSTR szBuffer, size_t ccBuffer, LPBYTE pbPtr, LPBYTE /* pbEnd */, PULONG pcbMoveBy = NULL)
{
LPWSTR szString = (LPWSTR)(pbPtr);
if(pcbMoveBy != NULL)
pcbMoveBy[0] = (ULONG)((wcslen(szString) + 1) * sizeof(WCHAR));
StringCchPrintf(szBuffer, ccBuffer, _T("\"%s\""), szString);
return STATUS_SUCCESS;
}
static NTSTATUS StringTo_STR(PTREE_ITEM_INFO /* pItemInfo */, LPCTSTR szString, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
ULONG cbString = (ULONG)((wcslen(szString) + 1) * sizeof(WCHAR));
return CopyDataAway(pbPtr, pbEnd, szString, cbString, pcbMoveBy);
}
//-----------------------------------------------------------------------------
// Conversion of String <-> Binary Data: SID
static TREE_ITEM_INFO ItemType_IntLevel = {ItemTypeUint32, 0, IDS_FORMAT_INT_LEVEL, IntgrLevels};
static TREE_ITEM_INFO ItemType_PolicyId = {ItemTypeUint32, 0, IDS_FORMAT_POLICY_ID};
static TREE_ITEM_INFO ItemType_TrustLev = {ItemTypeUint64, 0, IDS_FORMAT_TRUST_LEVEL};
static NTSTATUS ToString_Sid(PTREE_ITEM_INFO /* pItemInfo */, LPTSTR szBuffer, size_t ccBuffer, LPBYTE pbPtr, LPBYTE pbEnd, PULONG pcbMoveBy = NULL)
{
NTSTATUS Status = STATUS_SUCCESS;
ULONG cbMoveBy = 0;
// If there is a SID, format it to the buffer
if(pbPtr != NULL)
{
if((pbPtr + 8) <= pbEnd)
{
PSID_IDENTIFIER_AUTHORITY pSia;
LPBYTE pbIntValue;
PSID pSid = (PSID)(pbPtr);
// Determine the SID type by the authority
pSia = GetSidIdentifierAuthority(pSid);
// Is it a mandatory label?
if(!memcmp(pSia, &SiaLabel, sizeof(SID_IDENTIFIER_AUTHORITY)))
{
if((pbIntValue = GetSidIntegrityLevel(pSid)) != NULL)
ToString_Hex4(&ItemType_IntLevel, szBuffer, ccBuffer, pbIntValue, pbIntValue + sizeof(DWORD));
cbMoveBy = RtlLengthSid(pSid);
}
else if(!memcmp(pSia, &SiaPolicy, sizeof(SID_IDENTIFIER_AUTHORITY)))
{
if((pbIntValue = GetSidScopedPolicyId(pSid)) != NULL)
ToString_Hex4(&ItemType_PolicyId, szBuffer, ccBuffer, pbIntValue, pbIntValue + sizeof(DWORD));
cbMoveBy = RtlLengthSid(pSid);
}
else if(!memcmp(pSia, &SiaTrust, sizeof(SID_IDENTIFIER_AUTHORITY)))
{
if((pbIntValue = GetSidProcessTrustLevel(pSid)) != NULL)
ToString_TrustLevel(&ItemType_TrustLev, szBuffer, ccBuffer, pbIntValue, pbIntValue + sizeof(ULONG64));
cbMoveBy = RtlLengthSid(pSid);
}
else
{
SidToString(pSid, szBuffer, ccBuffer, true);
cbMoveBy = RtlLengthSid(pSid);
}
}
else
{
Status = STATUS_INVALID_PARAMETER;
}