Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
GenericAce.cs
Go to the documentation of this file.
2
4
5public abstract class GenericAce
6{
7 private readonly AceType _type;
8
9 private AceFlags _flags;
10
11 internal ushort _indexInAcl;
12
14
16 {
17 get
18 {
19 return _flags;
20 }
21 set
22 {
23 _flags = value;
24 }
25 }
26
27 public bool IsInherited => (AceFlags & AceFlags.Inherited) != 0;
28
30 {
31 get
32 {
33 InheritanceFlags inheritanceFlags = InheritanceFlags.None;
34 if ((AceFlags & AceFlags.ContainerInherit) != 0)
35 {
36 inheritanceFlags |= InheritanceFlags.ContainerInherit;
37 }
38 if ((AceFlags & AceFlags.ObjectInherit) != 0)
39 {
40 inheritanceFlags |= InheritanceFlags.ObjectInherit;
41 }
42 return inheritanceFlags;
43 }
44 }
45
47 {
48 get
49 {
50 PropagationFlags propagationFlags = PropagationFlags.None;
51 if ((AceFlags & AceFlags.InheritOnly) != 0)
52 {
53 propagationFlags |= PropagationFlags.InheritOnly;
54 }
55 if ((AceFlags & AceFlags.NoPropagateInherit) != 0)
56 {
57 propagationFlags |= PropagationFlags.NoPropagateInherit;
58 }
59 return propagationFlags;
60 }
61 }
62
64 {
65 get
66 {
67 AuditFlags auditFlags = AuditFlags.None;
68 if ((AceFlags & AceFlags.SuccessfulAccess) != 0)
69 {
70 auditFlags |= AuditFlags.Success;
71 }
72 if ((AceFlags & AceFlags.FailedAccess) != 0)
73 {
74 auditFlags |= AuditFlags.Failure;
75 }
76 return auditFlags;
77 }
78 }
79
80 public abstract int BinaryLength { get; }
81
82 internal void MarshalHeader(byte[] binaryForm, int offset)
83 {
84 int binaryLength = BinaryLength;
85 if (binaryForm == null)
86 {
87 throw new ArgumentNullException("binaryForm");
88 }
89 if (offset < 0)
90 {
92 }
93 if (binaryForm.Length - offset < BinaryLength)
94 {
96 }
97 if (binaryLength > 65535)
98 {
99 throw new InvalidOperationException();
100 }
101 binaryForm[offset] = (byte)AceType;
102 binaryForm[offset + 1] = (byte)AceFlags;
103 binaryForm[offset + 2] = (byte)binaryLength;
104 binaryForm[offset + 3] = (byte)(binaryLength >> 8);
105 }
106
108 {
109 _type = type;
110 _flags = flags;
111 }
112
113 internal static AceFlags AceFlagsFromAuditFlags(AuditFlags auditFlags)
114 {
115 AceFlags aceFlags = AceFlags.None;
116 if ((auditFlags & AuditFlags.Success) != 0)
117 {
118 aceFlags |= AceFlags.SuccessfulAccess;
119 }
120 if ((auditFlags & AuditFlags.Failure) != 0)
121 {
122 aceFlags |= AceFlags.FailedAccess;
123 }
124 if (aceFlags == AceFlags.None)
125 {
126 throw new ArgumentException(System.SR.Arg_EnumAtLeastOneFlag, "auditFlags");
127 }
128 return aceFlags;
129 }
130
131 internal static AceFlags AceFlagsFromInheritanceFlags(InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
132 {
133 AceFlags aceFlags = AceFlags.None;
134 if ((inheritanceFlags & InheritanceFlags.ContainerInherit) != 0)
135 {
136 aceFlags |= AceFlags.ContainerInherit;
137 }
138 if ((inheritanceFlags & InheritanceFlags.ObjectInherit) != 0)
139 {
140 aceFlags |= AceFlags.ObjectInherit;
141 }
142 if (aceFlags != 0)
143 {
144 if ((propagationFlags & PropagationFlags.NoPropagateInherit) != 0)
145 {
146 aceFlags |= AceFlags.NoPropagateInherit;
147 }
148 if ((propagationFlags & PropagationFlags.InheritOnly) != 0)
149 {
150 aceFlags |= AceFlags.InheritOnly;
151 }
152 }
153 return aceFlags;
154 }
155
156 internal static void VerifyHeader(byte[] binaryForm, int offset)
157 {
158 if (binaryForm == null)
159 {
160 throw new ArgumentNullException("binaryForm");
161 }
162 if (offset < 0)
163 {
165 }
166 if (binaryForm.Length - offset < 4)
167 {
169 }
170 if ((binaryForm[offset + 3] << 8) + binaryForm[offset + 2] > binaryForm.Length - offset)
171 {
173 }
174 }
175
176 public static GenericAce CreateFromBinaryForm(byte[] binaryForm, int offset)
177 {
178 VerifyHeader(binaryForm, offset);
179 AceType aceType = (AceType)binaryForm[offset];
180 GenericAce genericAce;
181 if (aceType == AceType.AccessAllowed || aceType == AceType.AccessDenied || aceType == AceType.SystemAudit || aceType == AceType.SystemAlarm || aceType == AceType.AccessAllowedCallback || aceType == AceType.AccessDeniedCallback || aceType == AceType.SystemAuditCallback || aceType == AceType.SystemAlarmCallback)
182 {
183 if (CommonAce.ParseBinaryForm(binaryForm, offset, out var qualifier, out var accessMask, out var sid, out var isCallback, out var opaque))
184 {
185 AceFlags flags = (AceFlags)binaryForm[offset + 1];
186 genericAce = new CommonAce(flags, qualifier, accessMask, sid, isCallback, opaque);
187 goto IL_0154;
188 }
189 }
190 else if (aceType == AceType.AccessAllowedObject || aceType == AceType.AccessDeniedObject || aceType == AceType.SystemAuditObject || aceType == AceType.SystemAlarmObject || aceType == AceType.AccessAllowedCallbackObject || aceType == AceType.AccessDeniedCallbackObject || aceType == AceType.SystemAuditCallbackObject || aceType == AceType.SystemAlarmCallbackObject)
191 {
192 if (ObjectAce.ParseBinaryForm(binaryForm, offset, out var qualifier2, out var accessMask2, out var sid2, out var objectFlags, out var objectAceType, out var inheritedObjectAceType, out var isCallback2, out var opaque2))
193 {
194 AceFlags aceFlags = (AceFlags)binaryForm[offset + 1];
195 genericAce = new ObjectAce(aceFlags, qualifier2, accessMask2, sid2, objectFlags, objectAceType, inheritedObjectAceType, isCallback2, opaque2);
196 goto IL_0154;
197 }
198 }
199 else if (aceType == AceType.AccessAllowedCompound)
200 {
201 if (CompoundAce.ParseBinaryForm(binaryForm, offset, out var accessMask3, out var compoundAceType, out var sid3))
202 {
203 AceFlags flags2 = (AceFlags)binaryForm[offset + 1];
204 genericAce = new CompoundAce(flags2, accessMask3, compoundAceType, sid3);
205 goto IL_0154;
206 }
207 }
208 else
209 {
210 AceFlags flags3 = (AceFlags)binaryForm[offset + 1];
211 byte[] array = null;
212 int num = binaryForm[offset + 2] + (binaryForm[offset + 3] << 8);
213 if (num % 4 == 0)
214 {
215 int num2 = num - 4;
216 if (num2 > 0)
217 {
218 array = new byte[num2];
219 for (int i = 0; i < num2; i++)
220 {
221 array[i] = binaryForm[offset + num - num2 + i];
222 }
223 }
224 genericAce = new CustomAce(aceType, flags3, array);
225 goto IL_0154;
226 }
227 }
228 goto IL_01a8;
229 IL_01a8:
231 IL_0154:
232 if ((genericAce is ObjectAce || binaryForm[offset + 2] + (binaryForm[offset + 3] << 8) == genericAce.BinaryLength) && (!(genericAce is ObjectAce) || binaryForm[offset + 2] + (binaryForm[offset + 3] << 8) == genericAce.BinaryLength || binaryForm[offset + 2] + (binaryForm[offset + 3] << 8) - 32 == genericAce.BinaryLength))
233 {
234 return genericAce;
235 }
236 goto IL_01a8;
237 }
238
239 public abstract void GetBinaryForm(byte[] binaryForm, int offset);
240
242 {
243 byte[] binaryForm = new byte[BinaryLength];
244 GetBinaryForm(binaryForm, 0);
245 return CreateFromBinaryForm(binaryForm, 0);
246 }
247
248 public sealed override bool Equals([NotNullWhen(true)] object? o)
249 {
250 GenericAce genericAce = o as GenericAce;
251 if (genericAce == null)
252 {
253 return false;
254 }
255 if (AceType != genericAce.AceType || AceFlags != genericAce.AceFlags)
256 {
257 return false;
258 }
259 int binaryLength = BinaryLength;
260 int binaryLength2 = genericAce.BinaryLength;
261 if (binaryLength != binaryLength2)
262 {
263 return false;
264 }
265 byte[] array = new byte[binaryLength];
266 byte[] array2 = new byte[binaryLength2];
268 genericAce.GetBinaryForm(array2, 0);
269 for (int i = 0; i < array.Length; i++)
270 {
271 if (array[i] != array2[i])
272 {
273 return false;
274 }
275 }
276 return true;
277 }
278
279 public sealed override int GetHashCode()
280 {
281 int binaryLength = BinaryLength;
282 byte[] array = new byte[binaryLength];
284 int num = 0;
285 for (int i = 0; i < binaryLength; i += 4)
286 {
287 int num2 = array[i] + (array[i + 1] << 8) + (array[i + 2] << 16) + (array[i + 3] << 24);
288 num ^= num2;
289 }
290 return num;
291 }
292
293 public static bool operator ==(GenericAce? left, GenericAce? right)
294 {
295 if ((object)left == null && (object)right == null)
296 {
297 return true;
298 }
299 if ((object)left == null || (object)right == null)
300 {
301 return false;
302 }
303 return left.Equals(right);
304 }
305
306 public static bool operator !=(GenericAce? left, GenericAce? right)
307 {
308 return !(left == right);
309 }
310}
static string ArgumentException_InvalidAceBinaryForm
Definition SR.cs:64
static string ArgumentOutOfRange_ArrayTooSmall
Definition SR.cs:74
static string Arg_EnumAtLeastOneFlag
Definition SR.cs:44
static string ArgumentOutOfRange_NeedNonNegNum
Definition SR.cs:32
Definition SR.cs:7
static bool ParseBinaryForm(byte[] binaryForm, int offset, out AceQualifier qualifier, out int accessMask, [NotNullWhen(true)] out SecurityIdentifier sid, out bool isCallback, out byte[] opaque)
Definition CommonAce.cs:29
static bool ParseBinaryForm(byte[] binaryForm, int offset, out int accessMask, out CompoundAceType compoundAceType, [NotNullWhen(true)] out SecurityIdentifier sid)
override bool Equals([NotNullWhen(true)] object? o)
static bool operator==(GenericAce? left, GenericAce? right)
static void VerifyHeader(byte[] binaryForm, int offset)
static bool operator!=(GenericAce? left, GenericAce? right)
void MarshalHeader(byte[] binaryForm, int offset)
Definition GenericAce.cs:82
GenericAce(AceType type, AceFlags flags)
void GetBinaryForm(byte[] binaryForm, int offset)
static AceFlags AceFlagsFromAuditFlags(AuditFlags auditFlags)
static AceFlags AceFlagsFromInheritanceFlags(InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
static GenericAce CreateFromBinaryForm(byte[] binaryForm, int offset)
static bool ParseBinaryForm(byte[] binaryForm, int offset, out AceQualifier qualifier, out int accessMask, [NotNullWhen(true)] out SecurityIdentifier sid, out ObjectAceFlags objectFlags, out Guid objectAceType, out Guid inheritedObjectAceType, out bool isCallback, out byte[] opaque)
Definition ObjectAce.cs:107