-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathAceResource.h
212 lines (164 loc) · 6.73 KB
/
AceResource.h
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
/*****************************************************************************/
/* AceResource.h Copyright (c) Ladislav Zezula 2023 */
/*---------------------------------------------------------------------------*/
/* Helpers for SYSTEM_RESOURCE_ATTRIBUTE_ACE */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* 23.11.23 1.00 Lad Created */
/*****************************************************************************/
#ifndef __ACE_RESOURCE_H__
#define __ACE_RESOURCE_H__
//-----------------------------------------------------------------------------
// Not defined in older SDKs
#ifndef CLAIM_SECURITY_ATTRIBUTE_TYPE_INVALID
#define CLAIM_SECURITY_ATTRIBUTE_TYPE_INVALID 0x00
#define CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64 0x01
#define CLAIM_SECURITY_ATTRIBUTE_TYPE_UINT64 0x02
//
// Case insensitive attribute value string by default.
// Unless the flag CLAIM_SECURITY_ATTRIBUTE_VALUE_CASE_SENSITIVE
// is set indicating otherwise.
//
#define CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING 0x03 // Zero terminated UTF-16 string
#define CLAIM_SECURITY_ATTRIBUTE_TYPE_FQBN 0x04 // Refused by Windows up to 11
#define CLAIM_SECURITY_ATTRIBUTE_TYPE_SID 0x05 // 4 bytes of length, followed by the SID
#define CLAIM_SECURITY_ATTRIBUTE_TYPE_BOOLEAN 0x06 // Each item has 8 bytes, upper 4 bytes must be zero
#define CLAIM_SECURITY_ATTRIBUTE_TYPE_OCTET_STRING 0x10 // 4 bytes of length, followed by array of BYTEs
//
// Attribute Flags
//
//
// Attribute must not be inherited across process spawns.
//
#define CLAIM_SECURITY_ATTRIBUTE_NON_INHERITABLE 0x0001
//
// Attribute value is compared in a case sensitive way. It is valid with string value
// or composite type containing string value. For other types of value, this flag
// will be ignored. Currently, it is valid with the two types:
// CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING and CLAIM_SECURITY_ATTRIBUTE_TYPE_FQBN.
//
#define CLAIM_SECURITY_ATTRIBUTE_VALUE_CASE_SENSITIVE 0x0002
//
// Attribute is considered only for Deny Aces.
//
#define CLAIM_SECURITY_ATTRIBUTE_USE_FOR_DENY_ONLY 0x0004
//
// Attribute is disabled by default.
//
#define CLAIM_SECURITY_ATTRIBUTE_DISABLED_BY_DEFAULT 0x0008
//
// Attribute is disabled.
//
#define CLAIM_SECURITY_ATTRIBUTE_DISABLED 0x0010
//
// Attribute is mandatory.
//
#define CLAIM_SECURITY_ATTRIBUTE_MANDATORY 0x0020
#define CLAIM_SECURITY_ATTRIBUTE_VALID_FLAGS ( \
CLAIM_SECURITY_ATTRIBUTE_NON_INHERITABLE | \
CLAIM_SECURITY_ATTRIBUTE_VALUE_CASE_SENSITIVE | \
CLAIM_SECURITY_ATTRIBUTE_USE_FOR_DENY_ONLY | \
CLAIM_SECURITY_ATTRIBUTE_DISABLED_BY_DEFAULT | \
CLAIM_SECURITY_ATTRIBUTE_DISABLED | \
CLAIM_SECURITY_ATTRIBUTE_MANDATORY )
//
// Reserve upper 16 bits for custom flags. These should be preserved but not
// validated as they do not affect security in any way.
//
#define CLAIM_SECURITY_ATTRIBUTE_CUSTOM_FLAGS 0xFFFF0000
typedef struct _CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1
{
DWORD Name; // Name of the attribute. Offset from beginning of structure.
WORD ValueType; // Data type of attribute.
WORD Reserved; // Must be 0
DWORD Flags; // Attribute Flags
DWORD ValueCount; // Number of values.
// The actual value itself.
union
{
DWORD pInt64[ANYSIZE_ARRAY];
DWORD pUint64[ANYSIZE_ARRAY];
DWORD ppString[ANYSIZE_ARRAY];
DWORD pFqbn[ANYSIZE_ARRAY];
DWORD pOctetString[ANYSIZE_ARRAY];
} Values;
} CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1, *PCLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1;
#endif
//-----------------------------------------------------------------------------
// Octet string structure
typedef struct _ACE_OCTET_STRING
{
ULONG cbData;
BYTE pbData[1];
} ACE_OCTET_STRING, *PACE_OCTET_STRING;
inline ULONG OctetStringSize(PACE_OCTET_STRING pOctetString)
{
return sizeof(ULONG) + pOctetString->cbData;
}
//-----------------------------------------------------------------------------
// Helpers
struct ACE_CSA_OBJECT
{
ACE_CSA_OBJECT();
~ACE_CSA_OBJECT();
LPBYTE ImportData(LPBYTE pbStructure, LPBYTE pbEnd, size_t Offset, size_t Length);
LPBYTE ImportOctet(PACE_OCTET_STRING pOctetString);
void Clear();
virtual size_t ExportSize(size_t cbAlignSize = 1) const;
virtual LPBYTE Export(LPBYTE pbPtr, LPBYTE pbEnd) const;
virtual LPBYTE Default(LPBYTE pbPtr, LPBYTE pbEnd, DWORD dwIndexHint) const;
virtual LPBYTE Import(LPCVOID lpObject);
void * lpData;
size_t cbData;
};
struct ACE_CSA_DWORD64 : public ACE_CSA_OBJECT
{
LPBYTE Default(LPBYTE pbPtr, LPBYTE pbEnd, DWORD dwIndexHint) const;
LPBYTE Import(LPCVOID lpObject);
};
struct ACE_CSA_LPWSTR : public ACE_CSA_OBJECT
{
LPBYTE Default(LPBYTE pbPtr, LPBYTE pbEnd, DWORD dwIndexHint) const;
LPBYTE Import(LPCVOID lpObject);
size_t StringLength(LPCVOID lpObject) const;
};
struct ACE_CSA_SID : public ACE_CSA_OBJECT
{
LPBYTE Default(LPBYTE pbPtr, LPBYTE pbEnd, DWORD dwIndexHint) const;
LPBYTE Import(LPCVOID lpObject);
};
struct ACE_CSA_BOOLEAN : public ACE_CSA_OBJECT
{
size_t ExportSize(size_t cbAlignSize = 1) const;
LPBYTE Default(LPBYTE pbPtr, LPBYTE pbEnd, DWORD dwIndexHint) const;
LPBYTE Import(LPCVOID lpObject);
};
struct ACE_CSA_OCTET_STRING : public ACE_CSA_OBJECT
{
LPBYTE Default(LPBYTE pbPtr, LPBYTE pbEnd, DWORD dwIndexHint) const;
LPBYTE Import(LPCVOID lpObject);
};
struct ACE_CSA_HELPER
{
ACE_CSA_HELPER(LPCWSTR szName, WORD ValueType, DWORD ValueCount = 3);
ACE_CSA_HELPER();
~ACE_CSA_HELPER();
void InitialReset();
void Clear();
NTSTATUS SetValueName(LPCWSTR szName);
NTSTATUS SetValueType(WORD wValueType, DWORD dwValueCount);
NTSTATUS SetValueData(LPCVOID lpObject, ULONG nIndex);
NTSTATUS AllocateElements();
NTSTATUS Import(LPBYTE pbAttrRel, LPBYTE pbAttrEnd, PULONG pcbMoveBy = NULL);
PCLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 Export(PULONG pcbLength = NULL) const;
ULONG GetSizeAlignedToMax(LPBYTE pbPtr, LPBYTE pbEnd, ULONG cbLength);
ACE_CSA_LPWSTR Name;
WORD ValueType;
WORD Reserved;
DWORD Flags;
DWORD ValueCount;
ACE_CSA_OBJECT * ppObjects;
};
NTSTATUS CopyDataAway(LPBYTE pbPtr, LPBYTE pbEnd, LPCVOID lpData, ULONG cbData, PULONG pcbMoveBy = NULL);
#endif // __ACE_RESOURCE_H__