| | 1 | | using System; |
| | 2 | | using System.Security.Principal; |
| | 3 | |
|
| | 4 | | namespace SharpHoundRPC |
| | 5 | | { |
| | 6 | | public static class Extensions |
| | 7 | | { |
| | 8 | | public static bool IsError(this NtStatus status) |
| 0 | 9 | | { |
| 0 | 10 | | if (status != NtStatus.StatusSuccess && status != NtStatus.StatusMoreEntries && |
| 0 | 11 | | status != NtStatus.StatusSomeMapped && status != NtStatus.StatusNoMoreEntries) |
| 0 | 12 | | return true; |
| | 13 | |
|
| 0 | 14 | | return false; |
| 0 | 15 | | } |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// Gets the relative identifier for a SID |
| | 19 | | /// </summary> |
| | 20 | | /// <param name="securityIdentifier"></param> |
| | 21 | | /// <returns></returns> |
| | 22 | | public static int Rid(this SecurityIdentifier securityIdentifier) |
| 0 | 23 | | { |
| 0 | 24 | | var value = securityIdentifier.Value; |
| 0 | 25 | | var rid = int.Parse(value.Substring(value.LastIndexOf("-", StringComparison.Ordinal) + 1)); |
| 0 | 26 | | return rid; |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | public static byte[] GetBytes(this SecurityIdentifier identifier) |
| 0 | 30 | | { |
| 0 | 31 | | var bytes = new byte[identifier.BinaryLength]; |
| 0 | 32 | | identifier.GetBinaryForm(bytes, 0); |
| 0 | 33 | | return bytes; |
| 0 | 34 | | } |
| | 35 | | } |
| | 36 | | } |