├── Compatibility.cs
├── LICENSE.md
├── NativeMethods.cs
├── OxidResolver.csproj
├── OxidResolver.sln
├── Program.cs
├── Properties
└── AssemblyInfo.cs
├── README.md
├── RPC
├── dcom.cs
├── lsa.cs
├── nativemethods.cs
├── nrpc.cs
├── rpcapi.cs
├── samr.cs
└── spool.cs
└── app.config
/Compatibility.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Oxid Resolver. All rights reserved.
3 | //
4 | //
5 | // Licensed under the Non-Profit OSL. See LICENSE file in the project root for full license information.
6 | //
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Text;
10 |
11 | namespace System.Runtime.Serialization
12 | {
13 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module, Inherited = false, AllowMultiple = true)]
14 | internal sealed class ContractNamespaceAttribute : Attribute
15 | {
16 | private string clrNamespace;
17 |
18 | private string contractNamespace;
19 |
20 | public string ClrNamespace
21 | {
22 | get
23 | {
24 | return this.clrNamespace;
25 | }
26 | set
27 | {
28 | this.clrNamespace = value;
29 | }
30 | }
31 |
32 | public string ContractNamespace
33 | {
34 | get
35 | {
36 | return this.contractNamespace;
37 | }
38 | }
39 |
40 | public ContractNamespaceAttribute(string contractNamespace)
41 | {
42 | this.contractNamespace = contractNamespace;
43 | }
44 | }
45 |
46 | // available in dotnet 3 but not on dotnet 2 which is needed for Windows 2000
47 | [System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=false)]
48 | internal sealed class IgnoreDataMemberAttribute : Attribute
49 | {
50 | public IgnoreDataMemberAttribute()
51 | {
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/S3cur3Th1sSh1t/SharpOxidResolver/7f7111f3995fd0951b75991b9c7faf79ed9e4098/LICENSE.md
--------------------------------------------------------------------------------
/NativeMethods.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Oxid Resolver. All rights reserved.
3 | //
4 | //
5 | // Licensed under the Non-Profit OSL. See LICENSE file in the project root for full license information.
6 | //
7 |
8 | using System;
9 | using System.Collections.Generic;
10 | using System.ComponentModel;
11 | using System.Diagnostics;
12 | using System.Net;
13 | using System.Runtime.InteropServices;
14 | using System.Security.Permissions;
15 | using System.Security.Principal;
16 | using System.Text;
17 |
18 | namespace OxidResolver
19 | {
20 | public class NativeMethods
21 | {
22 | #region PInvoke Signatures
23 |
24 | [DllImport("advapi32.dll", SetLastError = true, CharSet=CharSet.Unicode)]
25 | private static extern bool LogonUser(string
26 | lpszUsername, string lpszDomain, string lpszPassword,
27 | int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
28 |
29 | // logon types
30 | const int LOGON32_LOGON_INTERACTIVE = 2;
31 | const int LOGON32_LOGON_NETWORK = 3;
32 | const int LOGON32_LOGON_NEW_CREDENTIALS = 9;
33 |
34 | // logon providers
35 | const int LOGON32_PROVIDER_DEFAULT = 0;
36 | const int LOGON32_PROVIDER_WINNT50 = 3;
37 | const int LOGON32_PROVIDER_WINNT40 = 2;
38 | const int LOGON32_PROVIDER_WINNT35 = 1;
39 |
40 | public static WindowsIdentity GetWindowsIdentityForUser(NetworkCredential credential, string remoteserver)
41 | {
42 | IntPtr token = IntPtr.Zero;
43 | string domain = credential.Domain;
44 | if (String.IsNullOrEmpty(domain))
45 | domain = remoteserver;
46 | Trace.WriteLine("Preparing to login with login = " + credential.UserName + " domain = " + domain);
47 | bool isSuccess = LogonUser(credential.UserName, domain, credential.Password, LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_DEFAULT, ref token);
48 | if (!isSuccess)
49 | {
50 | throw new Win32Exception();
51 | }
52 | return new WindowsIdentity(token);
53 | }
54 |
55 | [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
56 | static extern bool LookupAccountSid(
57 | string lpSystemName,
58 | [MarshalAs(UnmanagedType.LPArray)] byte[] Sid,
59 | System.Text.StringBuilder lpName,
60 | ref uint cchName,
61 | System.Text.StringBuilder ReferencedDomainName,
62 | ref uint cchReferencedDomainName,
63 | out SID_NAME_USE peUse);
64 |
65 | [DllImport("advapi32.dll", SetLastError = true)]
66 | static extern bool LookupAccountName(
67 | string lpSystemName,
68 | string lpAccountName,
69 | [MarshalAs(UnmanagedType.LPArray)] byte[] Sid,
70 | ref uint cbSid,
71 | StringBuilder ReferencedDomainName,
72 | ref uint cchReferencedDomainName,
73 | out SID_NAME_USE peUse);
74 |
75 | const int NO_ERROR = 0;
76 | const int ERROR_INSUFFICIENT_BUFFER = 122;
77 | const int ERROR_INVALID_FLAGS = 1004;
78 |
79 | public enum SID_NAME_USE
80 | {
81 | SidTypeUser = 1,
82 | SidTypeGroup,
83 | SidTypeDomain,
84 | SidTypeAlias,
85 | SidTypeWellKnownGroup,
86 | SidTypeDeletedAccount,
87 | SidTypeInvalid,
88 | SidTypeUnknown,
89 | SidTypeComputer
90 | }
91 |
92 | public static string ConvertSIDToName(string sidstring, string server)
93 | {
94 | string referencedDomain = null;
95 | return ConvertSIDToName(sidstring, server, out referencedDomain);
96 | }
97 |
98 | public static SecurityIdentifier ConvertNameToSID(string accountName, string server)
99 | {
100 | byte [] Sid = null;
101 | uint cbSid = 0;
102 | StringBuilder referencedDomainName = new StringBuilder();
103 | uint cchReferencedDomainName = (uint)referencedDomainName.Capacity;
104 | SID_NAME_USE sidUse;
105 |
106 | int err = NO_ERROR;
107 | if (LookupAccountName(server, accountName, Sid, ref cbSid, referencedDomainName, ref cchReferencedDomainName, out sidUse))
108 | {
109 | return new SecurityIdentifier(Sid, 0);
110 | }
111 | else
112 | {
113 | err = Marshal.GetLastWin32Error();
114 | if (err == ERROR_INSUFFICIENT_BUFFER || err == ERROR_INVALID_FLAGS)
115 | {
116 | Sid = new byte[cbSid];
117 | referencedDomainName.EnsureCapacity((int)cchReferencedDomainName);
118 | err = NO_ERROR;
119 | if (LookupAccountName(null, accountName, Sid, ref cbSid, referencedDomainName, ref cchReferencedDomainName, out sidUse))
120 | {
121 | return new SecurityIdentifier(Sid, 0);
122 | }
123 | }
124 | }
125 | return null;
126 | }
127 |
128 | [EnvironmentPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
129 | public static string ConvertSIDToName(string sidstring, string server, out string referencedDomain)
130 | {
131 | StringBuilder name = new StringBuilder();
132 | uint cchName = (uint)name.Capacity;
133 | StringBuilder referencedDomainName = new StringBuilder();
134 | uint cchReferencedDomainName = (uint)referencedDomainName.Capacity;
135 | SID_NAME_USE sidUse;
136 |
137 | SecurityIdentifier securityidentifier = null;
138 | referencedDomain = null;
139 | try
140 | {
141 | securityidentifier = new SecurityIdentifier(sidstring);
142 | }
143 | catch (Exception ex)
144 | {
145 | Trace.WriteLine("Got " + ex.Message + " when trying to convert " + sidstring + " as sid");
146 | Trace.WriteLine(ex.StackTrace);
147 | return sidstring;
148 | }
149 |
150 | // try to resolve the account using the server
151 | byte[] Sid = new byte[securityidentifier.BinaryLength];
152 | securityidentifier.GetBinaryForm(Sid, 0);
153 |
154 | int err = NO_ERROR;
155 | if (!LookupAccountSid(server, Sid, name, ref cchName, referencedDomainName, ref cchReferencedDomainName, out sidUse))
156 | {
157 | err = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
158 | if (err == ERROR_INSUFFICIENT_BUFFER)
159 | {
160 | name.EnsureCapacity((int)cchName);
161 | referencedDomainName.EnsureCapacity((int)cchReferencedDomainName);
162 | err = NO_ERROR;
163 | if (!LookupAccountSid(server, Sid, name, ref cchName, referencedDomainName, ref cchReferencedDomainName, out sidUse))
164 | err = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
165 | }
166 | }
167 | if (err == 0)
168 | {
169 | referencedDomain = referencedDomainName.ToString();
170 | if (String.IsNullOrEmpty(referencedDomain))
171 | return name.ToString();
172 | else
173 | return referencedDomainName + "\\" + name;
174 | }
175 | Trace.WriteLine(@"Error " + err + " when translating " + sidstring + " on " + server);
176 | return sidstring;
177 | }
178 |
179 | [StructLayout(LayoutKind.Sequential)]
180 | public struct UNICODE_STRING : IDisposable
181 | {
182 | public ushort Length;
183 | public ushort MaximumLength;
184 | private IntPtr buffer;
185 |
186 | [SecurityPermission(SecurityAction.LinkDemand)]
187 | public void Initialize(string s)
188 | {
189 | Length = (ushort)(s.Length * 2);
190 | MaximumLength = (ushort)(Length + 2);
191 | buffer = Marshal.StringToHGlobalUni(s);
192 | }
193 |
194 | [SecurityPermission(SecurityAction.LinkDemand)]
195 | public void Dispose()
196 | {
197 | Marshal.FreeHGlobal(buffer);
198 | buffer = IntPtr.Zero;
199 | }
200 | [SecurityPermission(SecurityAction.LinkDemand)]
201 | public override string ToString()
202 | {
203 | if (Length == 0)
204 | return String.Empty;
205 | return Marshal.PtrToStringUni(buffer, Length / 2);
206 | }
207 | }
208 |
209 |
210 | [DllImport("samlib.dll"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Portability", "CA1901:PInvokeDeclarationsShouldBePortable", MessageId = "3")]
211 | internal static extern int SamConnect(ref UNICODE_STRING serverName, out IntPtr hServerHandle, int desiredAccess, int trusted);
212 | [DllImport("samlib.dll")]
213 | internal static extern int SamOpenDomain(IntPtr SamHandle, int DesiredAccess, byte[] DomainId, out IntPtr DomainHandle);
214 | [DllImport("samlib.dll")]
215 | internal static extern int SamOpenAlias(IntPtr DomainHandle, int DesiredAccess, int AliasId, out IntPtr AliasHandle);
216 | [DllImport("samlib.dll")]
217 | internal static extern int SamGetMembersInAlias(IntPtr AliasHandle, out IntPtr Members, out int CountReturned);
218 | [DllImport("samlib.dll")]
219 | internal static extern int SamFreeMemory(IntPtr memory);
220 | [DllImport("samlib.dll")]
221 | internal static extern int SamCloseHandle(IntPtr SamHandle);
222 | [DllImport("advapi32.dll", SetLastError = false)]
223 | internal static extern int LsaNtStatusToWinError(int status);
224 |
225 |
226 | internal enum SHARE_TYPE : uint
227 | {
228 | STYPE_DISK = 0, // Disk Share
229 | STYPE_PRINTQ = 1, // Print Queue
230 | STYPE_DEVICE = 2, // Communication Device
231 | STYPE_IPC = 3, // IPC (Interprocess communication) Share
232 | STYPE_HIDDEN_DISK = 0x80000000, // Admin Disk Shares
233 | STYPE_HIDDEN_PRINT = 0x80000001, // Admin Print Shares
234 | STYPE_HIDDEN_DEVICE = 0x80000002, // Admin Device Shares
235 | STYPE_HIDDEN_IPC = 0x80000003, // Admin IPC Shares
236 | // Need to add flags for
237 | // STYPE_TEMPORARY
238 | }
239 |
240 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
241 | internal struct SHARE_INFO_503
242 | {
243 | public string shi503_netname;
244 | [MarshalAs(UnmanagedType.U4)]
245 | public SHARE_TYPE shi503_type;
246 | public string shi503_remark;
247 | [MarshalAs(UnmanagedType.U4)]
248 | public int shi503_permissions; // used w/ share level security only
249 | [MarshalAs(UnmanagedType.U4)]
250 | public int shi503_max_uses;
251 | [MarshalAs(UnmanagedType.U4)]
252 | public int shi503_current_uses;
253 | public string shi503_path;
254 | public string shi503_passwd; // used w/ share level security only
255 | public string shi503_servername;
256 | [MarshalAs(UnmanagedType.U4)]
257 | public int shi503_reserved;
258 | public IntPtr shi503_security_descriptor;
259 | }
260 |
261 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
262 | internal struct SHARE_INFO_1
263 | {
264 | public string shi1_netname;
265 | public uint shi1_type;
266 | public string shi1_remark;
267 | public SHARE_INFO_1(string sharename, uint sharetype, string remark)
268 | {
269 | this.shi1_netname = sharename;
270 | this.shi1_type = sharetype;
271 | this.shi1_remark = remark;
272 | }
273 | public override string ToString()
274 | {
275 | return shi1_netname;
276 | }
277 | }
278 |
279 | [DllImport("Netapi32.dll", CharSet = CharSet.Unicode)]
280 | internal static extern int NetShareEnum(
281 | string ServerName,
282 | int level,
283 | ref IntPtr bufPtr,
284 | uint prefmaxlen,
285 | ref int entriesread,
286 | ref int totalentries,
287 | ref int resume_handle
288 | );
289 |
290 | [DllImport("Netapi32", CharSet = CharSet.Auto)]
291 | internal static extern int NetApiBufferFree(IntPtr Buffer);
292 |
293 | internal struct LSA_OBJECT_ATTRIBUTES
294 | {
295 | public UInt32 Length;
296 | public IntPtr RootDirectory;
297 | public UNICODE_STRING ObjectName;
298 | public UInt32 Attributes;
299 | public IntPtr SecurityDescriptor;
300 | public IntPtr SecurityQualityOfService;
301 | }
302 |
303 | [DllImport("advapi32.dll")]
304 | internal static extern uint LsaOpenPolicy(
305 | ref UNICODE_STRING SystemName,
306 | ref LSA_OBJECT_ATTRIBUTES ObjectAttributes,
307 | uint DesiredAccess,
308 | out IntPtr PolicyHandle
309 | );
310 |
311 | [DllImport("advapi32.dll")]
312 | internal static extern uint LsaClose(IntPtr ObjectHandle);
313 |
314 | [StructLayout(LayoutKind.Sequential)]
315 | internal struct LSA_TRUST_INFORMATION
316 | {
317 | internal UNICODE_STRING Name;
318 | internal IntPtr Sid;
319 | }
320 |
321 | [DllImport("advapi32.dll")]
322 | internal static extern uint LsaEnumerateTrustedDomains(
323 | IntPtr PolicyHandle,
324 | ref IntPtr EnumerationContext,
325 | out IntPtr Buffer,
326 | UInt32 PreferedMaximumLength,
327 | out UInt32 CountReturned
328 | );
329 |
330 | #endregion
331 |
332 |
333 | [DllImport("advapi32.dll")]
334 | internal static extern int LsaFreeMemory(IntPtr pBuffer);
335 |
336 | [DllImport("advapi32.dll")]
337 | internal static extern int LsaQueryForestTrustInformation(
338 | IntPtr PolicyHandle,
339 | ref UNICODE_STRING TrustedDomainName,
340 | out IntPtr ForestTrustInfo
341 | );
342 |
343 | [StructLayout(LayoutKind.Sequential)]
344 | internal struct LSA_FOREST_TRUST_INFORMATION
345 | {
346 | public UInt32 RecordCount;
347 | public IntPtr Entries;
348 | }
349 |
350 | [StructLayout(LayoutKind.Sequential)]
351 | internal struct LSA_FOREST_TRUST_DOMAIN_INFO {
352 | public IntPtr Sid;
353 | public UNICODE_STRING DnsName;
354 | public UNICODE_STRING NetbiosName;
355 | }
356 | [StructLayout(LayoutKind.Sequential)]
357 | internal struct LSA_FOREST_TRUST_BINARY_DATA {
358 | public UInt32 Length;
359 | public IntPtr Buffer;
360 | }
361 |
362 | [StructLayout(LayoutKind.Explicit)]
363 | internal struct LSA_FOREST_TRUST_RECORD {
364 | [FieldOffset(0)]
365 | public UInt32 Flags;
366 | [FieldOffset(4)]
367 | public UInt32 ForestTrustType;
368 | [FieldOffset(8)]
369 | public Int64 Time;
370 | [FieldOffset(16)]
371 | public UNICODE_STRING TopLevelName;
372 | [FieldOffset(16)]
373 | public LSA_FOREST_TRUST_DOMAIN_INFO DomainInfo;
374 | [FieldOffset(16)]
375 | public LSA_FOREST_TRUST_BINARY_DATA Data;
376 | }
377 |
378 | [DllImport("advapi32.dll", SetLastError = true)]
379 | internal static extern uint LsaLookupSids(
380 | IntPtr PolicyHandle,
381 | int Count,
382 | IntPtr ptrEnumBuf,
383 | out IntPtr ptrDomainList,
384 | out IntPtr ptrNameList
385 | );
386 |
387 | [DllImport("advapi32")]
388 | internal static extern uint LsaLookupNames(
389 | IntPtr PolicyHandle,
390 | int Count,
391 | UNICODE_STRING[] Names,
392 | out IntPtr ReferencedDomains,
393 | out IntPtr Sids
394 | );
395 |
396 | [StructLayout(LayoutKind.Sequential)]
397 | internal struct LSA_REFERENCED_DOMAIN_LIST
398 | {
399 | public int Entries;
400 | public IntPtr Domains;
401 | }
402 |
403 | [StructLayout(LayoutKind.Sequential)]
404 | public struct LSA_TRANSLATED_NAME
405 | {
406 | public SID_NAME_USE Use;
407 | public UNICODE_STRING Name;
408 | public int DomainIndex;
409 | }
410 |
411 | [StructLayout(LayoutKind.Sequential)]
412 | public struct LSA_TRANSLATED_SID
413 | {
414 | public SID_NAME_USE Use;
415 | public uint RelativeId;
416 | public int DomainIndex;
417 | }
418 |
419 | [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
420 | public static SecurityIdentifier GetSidFromDomainName(string server, string domainToResolve)
421 | {
422 | NativeMethods.UNICODE_STRING us = new NativeMethods.UNICODE_STRING();
423 | NativeMethods.LSA_OBJECT_ATTRIBUTES loa = new NativeMethods.LSA_OBJECT_ATTRIBUTES();
424 | us.Initialize(server);
425 | IntPtr PolicyHandle = IntPtr.Zero;
426 | uint ret = NativeMethods.LsaOpenPolicy(ref us, ref loa, 0x00000800, out PolicyHandle);
427 | if (ret != 0)
428 | {
429 | Trace.WriteLine("LsaOpenPolicy 0x" + ret.ToString("x"));
430 | return null;
431 | }
432 | try
433 | {
434 | UNICODE_STRING usdomain = new UNICODE_STRING();
435 | usdomain.Initialize(domainToResolve);
436 | IntPtr ReferencedDomains, Sids;
437 | ret = LsaLookupNames(PolicyHandle, 1, new UNICODE_STRING[] { usdomain }, out ReferencedDomains, out Sids);
438 | if (ret != 0)
439 | {
440 | Trace.WriteLine("LsaLookupNames 0x" + ret.ToString("x"));
441 | return null;
442 | }
443 | try
444 | {
445 | LSA_REFERENCED_DOMAIN_LIST domainList = (LSA_REFERENCED_DOMAIN_LIST)Marshal.PtrToStructure(ReferencedDomains, typeof(LSA_REFERENCED_DOMAIN_LIST));
446 | if (domainList.Entries > 0)
447 | {
448 | LSA_TRUST_INFORMATION trustInfo = (LSA_TRUST_INFORMATION)Marshal.PtrToStructure(domainList.Domains, typeof(LSA_TRUST_INFORMATION));
449 | return new SecurityIdentifier(trustInfo.Sid);
450 | }
451 | }
452 | finally
453 | {
454 | LsaFreeMemory(ReferencedDomains);
455 | LsaFreeMemory(Sids);
456 | }
457 | }
458 | finally
459 | {
460 | NativeMethods.LsaClose(PolicyHandle);
461 | }
462 | return null;
463 | }
464 |
465 | //public static string GetNameFromSID(string server, SecurityIdentifier sidToResolve)
466 | //{
467 | // NativeMethods.UNICODE_STRING us = new NativeMethods.UNICODE_STRING();
468 | // NativeMethods.LSA_OBJECT_ATTRIBUTES loa = new NativeMethods.LSA_OBJECT_ATTRIBUTES();
469 | // us.Initialize(server);
470 | // IntPtr PolicyHandle = IntPtr.Zero;
471 | // int ret = NativeMethods.LsaOpenPolicy(ref us, ref loa, 0x00000800, out PolicyHandle);
472 | // if (ret != 0)
473 | // {
474 | // Trace.WriteLine("LsaOpenPolicy 0x" + ret.ToString("x"));
475 | // return null;
476 | // }
477 | // try
478 | // {
479 | // byte[] Sid = new byte[sidToResolve.BinaryLength];
480 | // sidToResolve.GetBinaryForm(Sid, 0);
481 | // GCHandle handle = GCHandle.Alloc(Sid, GCHandleType.Pinned);
482 | // IntPtr array = handle.AddrOfPinnedObject();
483 | // GCHandle handlearray = GCHandle.Alloc(array, GCHandleType.Pinned);
484 | // IntPtr enumBuffer = IntPtr.Zero;
485 | // IntPtr ReferencedDomains, NameList;
486 | // ret = LsaLookupSids(PolicyHandle, 1, handlearray.AddrOfPinnedObject(), out ReferencedDomains, out NameList);
487 | // handle.Free();
488 | // handlearray.Free();
489 | // if (ret != 0)
490 | // {
491 | // Trace.WriteLine("LsaLookupSids 0x" + ret.ToString("x"));
492 | // return null;
493 | // }
494 | // try
495 | // {
496 | // LSA_REFERENCED_DOMAIN_LIST domainList = (LSA_REFERENCED_DOMAIN_LIST)Marshal.PtrToStructure(ReferencedDomains, typeof(LSA_REFERENCED_DOMAIN_LIST));
497 | // if (domainList.Entries == 0)
498 | // return null;
499 | // LSA_TRUST_INFORMATION trustInfo = (LSA_TRUST_INFORMATION)Marshal.PtrToStructure(domainList.Domains, typeof(LSA_TRUST_INFORMATION));
500 | // LSA_TRANSLATED_NAME translatedName = (LSA_TRANSLATED_NAME)Marshal.PtrToStructure(NameList, typeof(LSA_TRANSLATED_NAME));
501 | // return trustInfo.Name.ToString() + "\\" + translatedName.Name;
502 | // }
503 | // finally
504 | // {
505 | // LsaFreeMemory(ReferencedDomains);
506 | // LsaFreeMemory(NameList);
507 | // }
508 | // }
509 | // finally
510 | // {
511 | // NativeMethods.LsaClose(PolicyHandle);
512 | // }
513 | //}
514 |
515 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
516 | public struct DOMAIN_CONTROLLER_INFO
517 | {
518 | [MarshalAs(UnmanagedType.LPWStr)]
519 | public string DomainControllerName;
520 | [MarshalAs(UnmanagedType.LPWStr)]
521 | public string DomainControllerAddress;
522 | public uint DomainControllerAddressType;
523 | public Guid DomainGuid;
524 | [MarshalAs(UnmanagedType.LPWStr)]
525 | public string DomainName;
526 | [MarshalAs(UnmanagedType.LPWStr)]
527 | public string DnsForestName;
528 | public uint Flags;
529 | [MarshalAs(UnmanagedType.LPWStr)]
530 | public string DcSiteName;
531 | [MarshalAs(UnmanagedType.LPWStr)]
532 | public string ClientSiteName;
533 | }
534 |
535 | [Flags]
536 | public enum DSGETDCNAME_FLAGS : uint
537 | {
538 | DS_FORCE_REDISCOVERY = 0x00000001,
539 | DS_DIRECTORY_SERVICE_REQUIRED = 0x00000010,
540 | DS_DIRECTORY_SERVICE_PREFERRED = 0x00000020,
541 | DS_GC_SERVER_REQUIRED = 0x00000040,
542 | DS_PDC_REQUIRED = 0x00000080,
543 | DS_BACKGROUND_ONLY = 0x00000100,
544 | DS_IP_REQUIRED = 0x00000200,
545 | DS_KDC_REQUIRED = 0x00000400,
546 | DS_TIMESERV_REQUIRED = 0x00000800,
547 | DS_WRITABLE_REQUIRED = 0x00001000,
548 | DS_GOOD_TIMESERV_PREFERRED = 0x00002000,
549 | DS_AVOID_SELF = 0x00004000,
550 | DS_ONLY_LDAP_NEEDED = 0x00008000,
551 | DS_IS_FLAT_NAME = 0x00010000,
552 | DS_IS_DNS_NAME = 0x00020000,
553 | DS_RETURN_DNS_NAME = 0x40000000,
554 | DS_RETURN_FLAT_NAME = 0x80000000,
555 | DS_WEB_SERVICE_REQUIRED = 0x00100000,
556 | }
557 |
558 | [DllImport("Netapi32.dll", CharSet = CharSet.Unicode)]
559 | internal static extern int DsGetDcName
560 | (
561 | [MarshalAs(UnmanagedType.LPWStr)]
562 | string ComputerName,
563 | [MarshalAs(UnmanagedType.LPWStr)]
564 | string DomainName,
565 | [In] IntPtr DomainGuid,
566 | [MarshalAs(UnmanagedType.LPWStr)]
567 | string SiteName,
568 | DSGETDCNAME_FLAGS Flags,
569 | out IntPtr pDOMAIN_CONTROLLER_INFO
570 | );
571 |
572 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
573 | public struct STAT_WORKSTATION_0
574 | {
575 | public long StatisticsStartTime;
576 | public long BytesReceived;
577 | public long SmbsReceived;
578 | public long PagingReadBytesRequested;
579 | public long NonPagingReadBytesRequested;
580 | public long CacheReadBytesRequested;
581 | public long NetworkReadBytesRequested;
582 | public long BytesTransmitted;
583 | public long SmbsTransmitted;
584 | public long PagingWriteBytesRequested;
585 | public long NonPagingWriteBytesRequested;
586 | public long CacheWriteBytesRequested;
587 | public long NetworkWriteBytesRequested;
588 | public uint InitiallyFailedOperations;
589 | public uint FailedCompletionOperations;
590 | public uint ReadOperations;
591 | public uint RandomReadOperations;
592 | public uint ReadSmbs;
593 | public uint LargeReadSmbs;
594 | public uint SmallReadSmbs;
595 | public uint WriteOperations;
596 | public uint RandomWriteOperations;
597 | public uint WriteSmbs;
598 | public uint LargeWriteSmbs;
599 | public uint SmallWriteSmbs;
600 | public uint RawReadsDenied;
601 | public uint RawWritesDenied;
602 | public uint NetworkErrors;
603 | public uint Sessions;
604 | public uint FailedSessions;
605 | public uint Reconnects;
606 | public uint CoreConnects;
607 | public uint Lanman20Connects;
608 | public uint Lanman21Connects;
609 | public uint LanmanNtConnects;
610 | public uint ServerDisconnects;
611 | public uint HungSessions;
612 | public uint UseCount;
613 | public uint FailedUseCount;
614 | public uint CurrentCommands;
615 | }
616 |
617 | [DllImport("Netapi32.dll", CharSet = CharSet.Unicode)]
618 | internal static extern uint NetStatisticsGet(
619 | [In, MarshalAs(UnmanagedType.LPWStr)] string server,
620 | [In, MarshalAs(UnmanagedType.LPWStr)] string service,
621 | int level,
622 | int options,
623 | out IntPtr bufptr);
624 |
625 | [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
626 | public static DateTime GetStartupTime(string server)
627 | {
628 | IntPtr buffer = IntPtr.Zero;
629 | uint ret = NetStatisticsGet(server, "LanmanWorkstation", 0, 0, out buffer);
630 | if (ret != 0)
631 | {
632 | Trace.WriteLine("GetStartupTime " + server + " returned " + ret);
633 | return DateTime.MinValue;
634 | }
635 | try
636 | {
637 | STAT_WORKSTATION_0 data = (STAT_WORKSTATION_0)Marshal.PtrToStructure(buffer, typeof(STAT_WORKSTATION_0));
638 | return DateTime.FromFileTime(data.StatisticsStartTime);
639 | }
640 | finally
641 | {
642 | NetApiBufferFree(buffer);
643 | }
644 | }
645 |
646 | [DllImport("winspool.drv", CharSet = CharSet.Unicode, EntryPoint = "OpenPrinterW", SetLastError = true)]
647 | internal static extern bool OpenPrinter(string pPrinterName, out IntPtr phPrinter, IntPtr pDefault);
648 |
649 | [DllImport("winspool.drv", CharSet = CharSet.Unicode, EntryPoint = "ClosePrinter", SetLastError = true)]
650 | internal static extern bool ClosePrinter(IntPtr phPrinter);
651 |
652 | [DllImport("Netapi32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Auto)]
653 | internal static extern uint DsEnumerateDomainTrusts(string ServerName,
654 | uint Flags,
655 | out IntPtr Domains,
656 | out uint DomainCount);
657 |
658 | [Flags]
659 | internal enum DS_DOMAIN_TRUST_TYPE : uint
660 | {
661 | DS_DOMAIN_IN_FOREST = 0x0001, // Domain is a member of the forest
662 | DS_DOMAIN_DIRECT_OUTBOUND = 0x0002, // Domain is directly trusted
663 | DS_DOMAIN_TREE_ROOT = 0x0004, // Domain is root of a tree in the forest
664 | DS_DOMAIN_PRIMARY = 0x0008, // Domain is the primary domain of queried server
665 | DS_DOMAIN_NATIVE_MODE = 0x0010, // Primary domain is running in native mode
666 | DS_DOMAIN_DIRECT_INBOUND = 0x0020, // Domain is directly trusting
667 | ALL = 0x003F,
668 | }
669 |
670 | [StructLayout(LayoutKind.Sequential)]
671 | internal struct DS_DOMAIN_TRUSTS
672 | {
673 | [MarshalAs(UnmanagedType.LPTStr)]
674 | public string NetbiosDomainName;
675 | [MarshalAs(UnmanagedType.LPTStr)]
676 | public string DnsDomainName;
677 | public uint Flags;
678 | public uint ParentIndex;
679 | public uint TrustType;
680 | public uint TrustAttributes;
681 | public IntPtr DomainSid;
682 | public Guid DomainGuid;
683 | }
684 |
685 | [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
686 | internal static string GetDC(string domain, bool ADWS, bool forceRediscovery)
687 | {
688 | DOMAIN_CONTROLLER_INFO domainInfo;
689 | const int ERROR_SUCCESS = 0;
690 | IntPtr pDCI = IntPtr.Zero;
691 | try
692 | {
693 | var flags = DSGETDCNAME_FLAGS.DS_DIRECTORY_SERVICE_REQUIRED |
694 | DSGETDCNAME_FLAGS.DS_RETURN_DNS_NAME |
695 | DSGETDCNAME_FLAGS.DS_IP_REQUIRED;
696 | if (ADWS)
697 | {
698 | flags |= DSGETDCNAME_FLAGS.DS_WEB_SERVICE_REQUIRED;
699 | }
700 | if (forceRediscovery)
701 | {
702 | flags |= DSGETDCNAME_FLAGS.DS_FORCE_REDISCOVERY;
703 | }
704 | int val = DsGetDcName("", domain, IntPtr.Zero, "", flags, out pDCI);
705 | //check return value for error
706 | if (ERROR_SUCCESS == val)
707 | {
708 | domainInfo = (DOMAIN_CONTROLLER_INFO)Marshal.PtrToStructure(pDCI, typeof(DOMAIN_CONTROLLER_INFO));
709 |
710 | return domainInfo.DomainControllerName.Substring(2);
711 | }
712 | else
713 | {
714 | throw new Win32Exception(val);
715 | }
716 | }
717 | finally
718 | {
719 | if (pDCI != IntPtr.Zero)
720 | NetApiBufferFree(pDCI);
721 | }
722 | }
723 |
724 | [DllImport("shell32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
725 | static extern IntPtr CommandLineToArgvW([MarshalAs(UnmanagedType.LPWStr)] string lpCmdLine, out int pNumArgs);
726 |
727 | [DllImport("kernel32.dll")]
728 | static extern IntPtr LocalFree(IntPtr hMem);
729 |
730 | internal static string[] SplitArgs(string unsplitArgumentLine)
731 | {
732 | int numberOfArgs;
733 | IntPtr ptrToSplitArgs;
734 | string[] splitArgs;
735 |
736 | ptrToSplitArgs = CommandLineToArgvW(unsplitArgumentLine, out numberOfArgs);
737 |
738 | // CommandLineToArgvW returns NULL upon failure.
739 | if (ptrToSplitArgs == IntPtr.Zero)
740 | throw new ArgumentException("Unable to split argument.", new Win32Exception());
741 |
742 | // Make sure the memory ptrToSplitArgs to is freed, even upon failure.
743 | try
744 | {
745 | splitArgs = new string[numberOfArgs];
746 |
747 | // ptrToSplitArgs is an array of pointers to null terminated Unicode strings.
748 | // Copy each of these strings into our split argument array.
749 | for (int i = 0; i < numberOfArgs; i++)
750 | splitArgs[i] = Marshal.PtrToStringUni(
751 | Marshal.ReadIntPtr(ptrToSplitArgs, i * IntPtr.Size));
752 |
753 | return splitArgs;
754 | }
755 | finally
756 | {
757 | // Free memory obtained by CommandLineToArgW.
758 | LocalFree(ptrToSplitArgs);
759 | }
760 | }
761 | }
762 | }
763 |
--------------------------------------------------------------------------------
/OxidResolver.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}
8 | Exe
9 | Properties
10 | OxidResolver
11 | OxidResolver
12 | v3.0
13 | 512
14 |
15 | false
16 | publier\
17 | true
18 | Disk
19 | false
20 | Foreground
21 | 7
22 | Days
23 | false
24 | false
25 | true
26 | 0
27 | 1.0.0.%2a
28 | false
29 | true
30 |
31 |
32 | AnyCPU
33 | true
34 | full
35 | false
36 | bin\Debug\
37 | DEBUG;TRACE
38 | prompt
39 | 4
40 | 0436
41 |
42 |
43 | AnyCPU
44 | pdbonly
45 | true
46 | bin\Release\
47 | TRACE
48 | prompt
49 | 4
50 | 0436
51 |
52 |
53 | false
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | true
65 | bin\x86\Debug\
66 | DEBUG;TRACE
67 | full
68 | x86
69 | prompt
70 | MinimumRecommendedRules.ruleset
71 |
72 |
73 | bin\x86\Release\
74 | TRACE
75 | true
76 | pdbonly
77 | x86
78 | prompt
79 | MinimumRecommendedRules.ruleset
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 | Designer
108 |
109 |
110 |
111 |
112 | False
113 | .NET Framework 3.5 SP1 Client Profile
114 | false
115 |
116 |
117 | False
118 | .NET Framework 3.5 SP1
119 | true
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
139 |
--------------------------------------------------------------------------------
/OxidResolver.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30413.136
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OxidResolver", "OxidResolver.csproj", "{52BBA3C2-A74E-4096-B65F-B88C38F92120}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|x64 = Debug|x64
12 | Debug|x86 = Debug|x86
13 | Release|Any CPU = Release|Any CPU
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Debug|x64.ActiveCfg = Debug|Any CPU
21 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Debug|x64.Build.0 = Debug|Any CPU
22 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Debug|x86.ActiveCfg = Debug|Any CPU
23 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Debug|x86.Build.0 = Debug|Any CPU
24 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Release|x64.ActiveCfg = Release|Any CPU
27 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Release|x64.Build.0 = Release|Any CPU
28 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Release|x86.ActiveCfg = Release|Any CPU
29 | {52BBA3C2-A74E-4096-B65F-B88C38F92120}.Release|x86.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {EC2B7D83-FCCE-4EF6-B7D1-7B63907C25D7}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Oxid Resolver. All rights reserved.
3 | //
4 | //
5 | // Licensed under the Non-Profit OSL. See LICENSE file in the project root for full license information.
6 | //
7 |
8 |
9 | using OxidResolver.RPC;
10 | using System;
11 | using System.Collections.Generic;
12 | using System.Diagnostics;
13 | using System.Text;
14 | using System.DirectoryServices;
15 | using System.Net.NetworkInformation;
16 |
17 | namespace OxidResolver
18 | {
19 |
20 |
21 |
22 | public class Program
23 | {
24 |
25 | public static void Main(string[] args)
26 | {
27 | string outbindings;
28 | string host;
29 |
30 | if (args == null || args.Length == 0)
31 | {
32 | List ComputerNames = new List();
33 | System.DirectoryServices.ActiveDirectory.Domain domain = System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain();
34 |
35 | string currentdom = "LDAP://" + domain.ToString();
36 | DirectoryEntry entry = new DirectoryEntry(currentdom);
37 | DirectorySearcher mySearcher = new DirectorySearcher(entry);
38 | mySearcher.Filter = ("(objectClass=computer)");
39 | mySearcher.SizeLimit = int.MaxValue;
40 | mySearcher.PageSize = int.MaxValue;
41 |
42 | foreach (SearchResult resEnt in mySearcher.FindAll())
43 | {
44 | string ComputerName = resEnt.GetDirectoryEntry().Name;
45 | if (ComputerName.StartsWith("CN="))
46 | ComputerName = ComputerName.Remove(0, "CN=".Length);
47 | ComputerNames.Add(ComputerName);
48 | }
49 |
50 | mySearcher.Dispose();
51 | entry.Dispose();
52 |
53 | foreach (string computer in ComputerNames)
54 | {
55 | Console.WriteLine("Getting bindings for " + computer + ":");
56 | Console.WriteLine("");
57 | PingReply pingReply;
58 | bool error = false;
59 | using (var ping = new Ping())
60 | {
61 | try
62 | {
63 | pingReply = ping.Send(computer);
64 | }
65 | catch
66 | {
67 | Console.WriteLine("No DNS");
68 | pingReply = ping.Send("localhost");
69 | error = true;
70 | }
71 | }
72 | if (pingReply.Status == IPStatus.Success && error != true)
73 | {
74 | outbindings = GetCsvData(computer);
75 | Console.WriteLine(outbindings);
76 | Console.WriteLine("");
77 | Console.WriteLine("");
78 | }
79 | else
80 | {
81 | Console.WriteLine("Computer not accessible");
82 | Console.WriteLine("");
83 | Console.WriteLine("");
84 | }
85 |
86 | }
87 |
88 | }
89 | else
90 | {
91 | host = args[0];
92 | outbindings = GetCsvData(host);
93 | Console.WriteLine(outbindings);
94 |
95 | }
96 | }
97 | public string Name = "oxidbindings";
98 | public string Description = "List all IP of the computer via the Oxid Resolver (part of DCOM). No authentication. Used to find other networks such as the one used for administration.";
99 |
100 | protected string GetCsvHeader()
101 | {
102 | return "Computer\tBinding";
103 | }
104 |
105 | public static string GetCsvData(string computer)
106 | {
107 | StringBuilder sb = new StringBuilder();
108 | DisplayAdvancement(computer, "Connecting to Oxid Resolver");
109 | List bindings;
110 | var oxid = new OxidBindings();
111 | int res = oxid.ServerAlive2(computer, out bindings);
112 | if (res != 0)
113 | {
114 | DisplayAdvancement(computer, "error " + res);
115 | sb.Append(computer);
116 | sb.Append("\tError " + res);
117 | }
118 | else
119 | {
120 | foreach (var binding in bindings)
121 | {
122 | if (sb.Length != 0)
123 | sb.Append("\r\n");
124 | sb.Append(computer);
125 | sb.Append("\t");
126 | sb.Append(binding);
127 | }
128 | }
129 | return sb.ToString();
130 | }
131 |
132 | public static void DisplayAdvancement(string computer, string data)
133 | {
134 | string value = "[" + DateTime.Now.ToLongTimeString() + "] " + data;
135 | Console.WriteLine(value);
136 | Trace.WriteLine(value);
137 | }
138 |
139 |
140 | }
141 | }
142 |
143 |
144 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 |
5 | [assembly: AssemblyTitle("Oxid Resolver")]
6 | [assembly: AssemblyDescription("")]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany("Oxid Resolver")]
9 | [assembly: AssemblyProduct("Oxid Resolver")]
10 | [assembly: AssemblyCopyright("Copyright © 2019 Oxid Resolver")]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 | [assembly: ComVisible(false)]
14 | [assembly: Guid("ce59f8ff-0ecf-41e9-a1fd-1776ca0b703d")]
15 | [assembly: AssemblyVersion("1.0.0.0")]
16 | [assembly: AssemblyFileVersion("1.0.0.0")]
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SharpOxidResolver
2 |
3 | ## Introduction
4 |
5 | First introduced as IOXIDResolver.py from AirBus Security.
6 |
7 | [First blog post](https://airbus-cyber-security.com/the-oxid-resolver-part-1-remote-enumeration-of-network-interfaces-without-any-authentication/)
8 |
9 | [Seccond blog post](https://airbus-cyber-security.com/the-oxid-resolver-part-2-accessing-a-remote-object-inside-dcom/)
10 |
11 | PingCastle adapted this technique as scanner module in C# [here](https://github.com/vletoux/pingcastle/blob/master/Scanners/OxidBindingScanner.cs).
12 |
13 | I basically stole this code to make it work as standalone binary.
14 |
15 | Without argument it will search the current domain for computers and get bindings for all of them:
16 | ```
17 | OxidResolver.exe
18 | ```
19 |
20 | You can also pass a hostname or IP-address to scan this specific target:
21 |
22 | ```
23 | OxidResolver.exe localhost
24 | ```
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/RPC/dcom.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Runtime.InteropServices;
4 | using System.Text;
5 |
6 | namespace OxidResolver.RPC
7 | {
8 | public class OxidBindings : rpcapi
9 | {
10 |
11 | private static byte[] MIDL_ProcFormatStringx86 = new byte[] {
12 | 0x00,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
13 | 0x48,0x00,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,
14 | 0x00,0x00,0x00,0x00,0x02,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,
15 | 0x00,0x00,0x00,0x03,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,
16 | 0x00,0x00,0x04,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x01,0x00,0x00,
17 | 0x00,0x05,0x00,0x14,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x4c,0x00,0x45,0x04,0x08,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x12,0x21,0x04,0x00,0x06,0x00,
18 | 0x13,0x20,0x08,0x00,0x0e,0x00,0x50,0x21,0x0c,0x00,0x08,0x00,0x70,0x00,0x10,0x00,0x10,0x00,0x00
19 | };
20 |
21 | private static byte[] MIDL_ProcFormatStringx64 = new byte[] {
22 | 0x00,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
23 | 0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x01,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
24 | 0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x02,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,
25 | 0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x03,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,
26 | 0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x04,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,
27 | 0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x01,0x00,0x00,0x00,0x05,0x00,0x28,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x4c,0x00,0x45,0x04,0x0a,0x03,0x01,0x00,
28 | 0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x21,0x08,0x00,0x06,0x00,0x13,0x20,0x10,0x00,0x0e,0x00,0x50,0x21,0x18,0x00,0x08,0x00,0x70,0x00,0x20,0x00,0x10,
29 | 0x00,0x00};
30 |
31 | private static byte[] MIDL_TypeFormatStringx86 = new byte[] {
32 | 0x00,0x00,0x11,0x04,0x02,0x00,0x15,0x01,0x04,0x00,0x06,0x06,0x5c,0x5b,0x11,0x14,0x02,0x00,0x12,0x00,0x0e,0x00,0x1b,0x01,0x02,0x00,0x07,0x00,0xfc,
33 | 0xff,0x01,0x00,0x06,0x5b,0x17,0x01,0x04,0x00,0xf0,0xff,0x06,0x06,0x5c,0x5b,0x11,0x0c,0x08,0x5c,0x00
34 | };
35 |
36 | private static byte[] MIDL_TypeFormatStringx64 = new byte[] {
37 | 0x00,0x00,0x11,0x04,0x02,0x00,0x15,0x01,0x04,0x00,0x06,0x06,0x5c,0x5b,0x11,0x14,0x02,0x00,0x12,0x00,0x0e,0x00,0x1b,0x01,0x02,0x00,0x07,0x00,0xfc,
38 | 0xff,0x01,0x00,0x06,0x5b,0x17,0x01,0x04,0x00,0xf0,0xff,0x06,0x06,0x5c,0x5b,0x11,0x0c,0x08,0x5c,0x00};
39 |
40 | public OxidBindings()
41 | {
42 | Guid interfaceId = new Guid("99fcfec4-5260-101b-bbcb-00aa0021347a");
43 | if (IntPtr.Size == 8)
44 | {
45 | InitializeStub(interfaceId, MIDL_ProcFormatStringx64, MIDL_TypeFormatStringx64, null, 0);
46 | }
47 | else
48 | {
49 | InitializeStub(interfaceId, MIDL_ProcFormatStringx86, MIDL_TypeFormatStringx86, null, 0);
50 | }
51 | }
52 |
53 | ~OxidBindings()
54 | {
55 | freeStub();
56 | }
57 |
58 | [StructLayout(LayoutKind.Sequential)]
59 | internal struct COMVERSION
60 | {
61 | public UInt16 MajorVersion;
62 | public UInt16 MinorVersion;
63 | }
64 |
65 | public Int32 ServerAlive2(string server, out List stringBindings)
66 | {
67 | IntPtr hBind;
68 | stringBindings = new List();
69 | Int32 status = Bind(server, out hBind);
70 | if (status != 0)
71 | return status;
72 | try
73 | {
74 | status = NativeMethods.RpcEpResolveBinding(hBind, rpcClientInterface);
75 | if (status != 0)
76 | return status;
77 |
78 | var conversion = new COMVERSION() { MajorVersion = 5, MinorVersion = 1 };
79 | UInt32 reserved = 0;
80 | IntPtr DualStringArray = IntPtr.Zero;
81 | try
82 | {
83 | if (IntPtr.Size == 8)
84 | {
85 | IntPtr result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(150), hBind, ref conversion, out DualStringArray, ref reserved);
86 | if (result != IntPtr.Zero)
87 | return result.ToInt32();
88 | }
89 | else
90 | {
91 | GCHandle h2 = GCHandle.Alloc(conversion, GCHandleType.Pinned);
92 |
93 | GCHandle h3 = GCHandle.Alloc(DualStringArray, GCHandleType.Pinned);
94 | GCHandle h4 = GCHandle.Alloc(reserved, GCHandleType.Pinned);
95 | IntPtr tempValuePointer = h3.AddrOfPinnedObject();
96 | try
97 | {
98 | IntPtr result = CallNdrClientCall2x86(140, hBind, h2.AddrOfPinnedObject(), tempValuePointer, h4.AddrOfPinnedObject());
99 | if (result != IntPtr.Zero)
100 | return result.ToInt32();
101 | // each pinvoke work on a copy of the arguments (without an out specifier)
102 | // get back the data
103 | DualStringArray = Marshal.ReadIntPtr(tempValuePointer);
104 |
105 | }
106 | finally
107 | {
108 | h2.Free();
109 | h3.Free();
110 | h4.Free();
111 | }
112 | }
113 | Int16 wSecurityOffest = Marshal.ReadInt16(new IntPtr(DualStringArray.ToInt64() + 2));
114 | int offset = 4;
115 | while (offset < wSecurityOffest * 2)
116 | {
117 | string value = Marshal.PtrToStringUni(new IntPtr(DualStringArray.ToInt64() + offset + 2));
118 | stringBindings.Add(value);
119 | offset += value.Length * 2 + 2 + 2;
120 | }
121 | FreeMemory(DualStringArray);
122 | }
123 | catch (SEHException)
124 | {
125 | return Marshal.GetExceptionCode();
126 | }
127 | }
128 | finally
129 | {
130 | Unbind(IntPtr.Zero, hBind);
131 | }
132 | return 0;
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/RPC/lsa.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Oxid Resolver. All rights reserved.
3 | //
4 | //
5 | // Licensed under the Non-Profit OSL. See LICENSE file in the project root for full license information.
6 | //
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Diagnostics;
10 | using System.Runtime.InteropServices;
11 | using System.Security.Permissions;
12 | using System.Security.Principal;
13 | using System.Text;
14 |
15 | namespace OxidResolver.RPC
16 | {
17 | [DebuggerDisplay("{DomainName}")]
18 | public class LSA_DOMAIN_INFORMATION
19 | {
20 | public string DomainName;
21 | public SecurityIdentifier DomainSid;
22 | }
23 |
24 | public enum SID_NAME_USE {
25 | SidTypeUser = 1,
26 | SidTypeGroup,
27 | SidTypeDomain,
28 | SidTypeAlias,
29 | SidTypeWellKnownGroup,
30 | SidTypeDeletedAccount,
31 | SidTypeInvalid,
32 | SidTypeUnknown,
33 | SidTypeComputer,
34 | SidTypeLabel
35 | }
36 |
37 | [DebuggerDisplay("{DomainName} {TranslatedName}")]
38 | public class LSA_LOOKUP_RESULT
39 | {
40 | public string DomainName;
41 | public SecurityIdentifier DomainSid;
42 | public string TranslatedName;
43 | public SID_NAME_USE Use;
44 | }
45 |
46 | public class lsa : rpcapi
47 | {
48 |
49 | private static byte[] MIDL_ProcFormatStringx86 = new byte[] {
50 | 0x00,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x30,0xe0,0x00,0x00,0x00,0x00,0x38,0x00,0x40,0x00,0x44,0x02,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
51 | 0x18,0x01,0x00,0x00,0x06,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
52 | 0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x02,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,
53 | 0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x03,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,
54 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x04,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,
55 | 0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x05,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,
56 | 0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x06,0x00,0x14,0x00,0x31,0x04,0x00,0x00,0x00,0x5c,0x22,0x00,0x40,0x00,0x46,0x05,0x08,0x05,0x00,0x00,0x01,0x00,
57 | 0x00,0x00,0x0a,0x00,0x00,0x00,0x0a,0x00,0x0b,0x01,0x04,0x00,0xc0,0x00,0x48,0x00,0x08,0x00,0x08,0x00,0x10,0x01,0x0c,0x00,0xfa,0x00,0x70,0x00,0x10,0x00,
58 | 0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x07,0x00,0x10,0x00,0x30,0x40,0x00,0x00,0x00,0x00,0x2a,0x00,0x08,0x00,0x45,0x04,0x08,0x03,0x01,0x00,0x00,0x00,
59 | 0x00,0x00,0x08,0x00,0x00,0x00,0xfe,0x00,0x48,0x00,0x04,0x00,0x0d,0x00,0x13,0x20,0x08,0x00,0x02,0x01,0x70,0x00,0x0c,0x00,0x08,0x00,0x00,0x48,0x00,0x00,
60 | 0x00,0x00,0x08,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,
61 | 0x09,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0a,0x00,
62 | 0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0b,0x00,0x04,0x00,
63 | 0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0c,0x00,0x04,0x00,0x32,0x00,
64 | 0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0d,0x00,0x04,0x00,0x32,0x00,0x00,0x00,
65 | 0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0e,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,
66 | 0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0f,0x00,0x1c,0x00,0x30,0x40,0x00,0x00,0x00,0x00,0x46,0x00,
67 | 0x24,0x00,0x47,0x07,0x08,0x07,0x01,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0xfe,0x00,0x0b,0x01,0x04,0x00,0xf8,0x02,0x13,0x20,0x08,0x00,0x0a,0x03,
68 | 0x1b,0x01,0x0c,0x00,0x86,0x03,0x48,0x00,0x10,0x00,0x0d,0x00,0x58,0x01,0x14,0x00,0x08,0x00,0x70,0x00,0x18,0x00,0x08,0x00,0x00
69 | };
70 |
71 | private static byte[] MIDL_ProcFormatStringx64 = new byte[] {
72 | 0x00,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x30,0xe0,0x00,0x00,0x00,0x00,0x38,0x00,0x40,0x00,0x44,0x02,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
73 | 0x00,0x00,0x18,0x01,0x00,0x00,0x06,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x01,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,
74 | 0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x02,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,
75 | 0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x03,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,
76 | 0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x04,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,
77 | 0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x05,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,
78 | 0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x06,0x00,0x28,0x00,0x31,0x08,0x00,0x00,0x00,0x5c,
79 | 0x22,0x00,0x40,0x00,0x46,0x05,0x0a,0x05,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x0a,0x00,0x0b,0x01,0x08,0x00,0xa6,0x00,0x48,0x00,
80 | 0x10,0x00,0x08,0x00,0x10,0x01,0x18,0x00,0xcc,0x00,0x70,0x00,0x20,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x07,0x00,0x20,0x00,0x30,0x40,0x00,0x00,
81 | 0x00,0x00,0x2a,0x00,0x08,0x00,0x45,0x04,0x0a,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0xd0,0x00,0x48,0x00,0x08,0x00,0x0d,0x00,
82 | 0x13,0x20,0x10,0x00,0xd4,0x00,0x70,0x00,0x18,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
83 | 0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x09,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
84 | 0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0a,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
85 | 0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0b,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
86 | 0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0c,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
87 | 0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0d,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
88 | 0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0e,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
89 | 0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0f,0x00,0x38,0x00,0x30,0x40,0x00,0x00,0x00,0x00,0x46,0x00,
90 | 0x24,0x00,0x47,0x07,0x0a,0x07,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0xd0,0x00,0x0b,0x01,0x08,0x00,0x74,0x02,0x13,0x20,0x10,0x00,
91 | 0x88,0x02,0x1b,0x01,0x18,0x00,0x00,0x03,0x48,0x00,0x20,0x00,0x0d,0x00,0x58,0x01,0x28,0x00,0x08,0x00,0x70,0x00,0x30,0x00,0x08,0x00,0x00
92 | };
93 |
94 | private static byte[] MIDL_TypeFormatStringx86 = new byte[] {
95 | 0x00,0x00,0x11,0x04,0x02,0x00,0x30,0xe1,0x00,0x00,0x12,0x08,0x05,0x5c,0x11,0x00,0xb0,0x00,0x1c,0x00,0x01,0x00,0x17,0x00,0x02,0x00,0x01,0x00,0x17,0x00,
96 | 0x00,0x00,0x01,0x00,0x02,0x5b,0x16,0x03,0x08,0x00,0x4b,0x5c,0x46,0x5c,0x04,0x00,0x04,0x00,0x12,0x00,0xe0,0xff,0x5b,0x06,0x06,0x08,0x5c,0x5b,0x1d,0x00,
97 | 0x06,0x00,0x01,0x5b,0x15,0x00,0x06,0x00,0x4c,0x00,0xf4,0xff,0x5c,0x5b,0x1b,0x03,0x04,0x00,0x04,0x00,0xf9,0xff,0x01,0x00,0x08,0x5b,0x17,0x03,0x08,0x00,
98 | 0xf0,0xff,0x02,0x02,0x4c,0x00,0xe0,0xff,0x5c,0x5b,0x1b,0x00,0x01,0x00,0x00,0x59,0x00,0x00,0x00,0x00,0x02,0x5b,0x17,0x01,0x04,0x00,0xf0,0xff,0x02,0x02,
99 | 0x06,0x5b,0x16,0x03,0x14,0x00,0x4b,0x5c,0x46,0x5c,0x04,0x00,0x04,0x00,0x12,0x00,0xce,0xff,0x46,0x5c,0x08,0x00,0x08,0x00,0x12,0x00,0xc4,0xff,0x46,0x5c,
100 | 0x0c,0x00,0x0c,0x00,0x12,0x00,0xd4,0xff,0x46,0x5c,0x10,0x00,0x10,0x00,0x12,0x00,0xca,0xff,0x5b,0x02,0x02,0x06,0x08,0x08,0x08,0x08,0x5c,0x5b,0x1a,0x03,
101 | 0x0c,0x00,0x00,0x00,0x00,0x00,0x08,0x0d,0x02,0x02,0x3e,0x5b,0x16,0x03,0x18,0x00,0x4b,0x5c,0x46,0x5c,0x04,0x00,0x04,0x00,0x12,0x08,0x02,0x5c,0x46,0x5c,
102 | 0x08,0x00,0x08,0x00,0x12,0x00,0x4c,0xff,0x46,0x5c,0x10,0x00,0x10,0x00,0x12,0x00,0x98,0xff,0x46,0x5c,0x14,0x00,0x14,0x00,0x12,0x00,0xc6,0xff,0x5b,0x08,
103 | 0x08,0x08,0x08,0x08,0x08,0x5b,0x11,0x04,0x02,0x00,0x30,0xa0,0x00,0x00,0x30,0x41,0x00,0x00,0x11,0x14,0x02,0x00,0x12,0x00,0x02,0x00,0x2b,0x0d,0x26,0x00,
104 | 0x04,0x00,0x01,0x00,0x02,0x00,0x30,0x00,0x0d,0x70,0x01,0x00,0x00,0x00,0x52,0x00,0x02,0x00,0x00,0x00,0x7a,0x00,0x03,0x00,0x00,0x00,0x9a,0x00,0x05,0x00,
105 | 0x00,0x00,0x94,0x00,0x04,0x00,0x00,0x00,0xae,0x00,0x06,0x00,0x00,0x00,0xbe,0x00,0x07,0x00,0x00,0x00,0xd4,0x00,0x09,0x00,0x00,0x00,0xf0,0x00,0x0a,0x00,
106 | 0x00,0x00,0xf8,0x00,0x0b,0x00,0x00,0x00,0xf8,0x00,0x0c,0x00,0x00,0x00,0x1e,0x01,0x0d,0x00,0x00,0x00,0x18,0x01,0x0e,0x00,0x00,0x00,0x5e,0x00,0xff,0xff,
107 | 0x15,0x07,0x08,0x00,0x0b,0x5b,0x1a,0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x4c,0x00,0xee,0xff,0x02,0x43,0x4c,0x00,0xe8,0xff,0x08,0x40,0x5c,0x5b,
108 | 0xb7,0x08,0x00,0x00,0x00,0x00,0xe8,0x03,0x00,0x00,0x1b,0x03,0x04,0x00,0x19,0x00,0x08,0x00,0x00,0x00,0x08,0x5b,0x1a,0x03,0x0c,0x00,0x00,0x00,0x0a,0x00,
109 | 0x02,0x3f,0x36,0x4c,0x00,0xdd,0xff,0x5b,0x12,0x00,0xe2,0xff,0x1c,0x01,0x02,0x00,0x17,0x55,0x02,0x00,0x01,0x00,0x17,0x55,0x00,0x00,0x01,0x00,0x05,0x5b,
110 | 0x16,0x03,0x0c,0x00,0x4b,0x5c,0x46,0x5c,0x04,0x00,0x04,0x00,0x12,0x00,0xe0,0xff,0x46,0x5c,0x08,0x00,0x08,0x00,0x12,0x00,0x7c,0xfe,0x5b,0x06,0x06,0x08,
111 | 0x08,0x5b,0x16,0x03,0x08,0x00,0x4b,0x5c,0x46,0x5c,0x04,0x00,0x04,0x00,0x12,0x00,0xc0,0xff,0x5b,0x06,0x06,0x08,0x5c,0x5b,0x1a,0x01,0x04,0x00,0x00,0x00,
112 | 0x00,0x00,0x0d,0x5b,0x1c,0x01,0x02,0x00,0x17,0x55,0x0a,0x00,0x01,0x00,0x17,0x55,0x08,0x00,0x01,0x00,0x05,0x5b,0x16,0x03,0x10,0x00,0x4b,0x5c,0x46,0x5c,
113 | 0x04,0x00,0x04,0x00,0x12,0x00,0x8e,0xff,0x46,0x5c,0x0c,0x00,0x0c,0x00,0x12,0x00,0xd6,0xff,0x5b,0x06,0x06,0x08,0x06,0x06,0x08,0x5b,0x15,0x07,0x10,0x00,
114 | 0x4c,0x00,0x2c,0xff,0x4c,0x00,0x28,0xff,0x5c,0x5b,0x15,0x00,0x01,0x00,0x02,0x5b,0x15,0x00,0x02,0x00,0x02,0x02,0x5c,0x5b,0x1d,0x00,0x08,0x00,0x01,0x5b,
115 | 0x15,0x03,0x10,0x00,0x08,0x06,0x06,0x4c,0x00,0xf1,0xff,0x5b,0x1c,0x01,0x02,0x00,0x17,0x55,0x12,0x00,0x01,0x00,0x17,0x55,0x10,0x00,0x01,0x00,0x05,0x5b,
116 | 0x16,0x03,0x2c,0x00,0x4b,0x5c,0x46,0x5c,0x04,0x00,0x04,0x00,0x12,0x00,0x2c,0xff,0x46,0x5c,0x0c,0x00,0x0c,0x00,0x12,0x00,0x74,0xff,0x46,0x5c,0x14,0x00,
117 | 0x14,0x00,0x12,0x00,0xcc,0xff,0x46,0x5c,0x28,0x00,0x28,0x00,0x12,0x00,0xb4,0xfd,0x5b,0x06,0x06,0x08,0x06,0x06,0x08,0x06,0x06,0x08,0x4c,0x00,0xa8,0xff,
118 | 0x08,0x5b,0x11,0x00,0x42,0x00,0xb7,0x08,0x00,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x16,0x03,0x04,0x00,0x4b,0x5c,0x46,0x5c,0x00,0x00,0x00,0x00,0x12,0x00,
119 | 0x86,0xfd,0x5b,0x08,0x5c,0x5b,0x1b,0x03,0x04,0x00,0x19,0x00,0x00,0x00,0x01,0x00,0x4b,0x5c,0x48,0x49,0x04,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
120 | 0x12,0x00,0x66,0xfd,0x5b,0x4c,0x00,0xcd,0xff,0x5b,0x1a,0x03,0x08,0x00,0x00,0x00,0x08,0x00,0x4c,0x00,0xb6,0xff,0x36,0x5b,0x12,0x00,0xce,0xff,0x11,0x14,
121 | 0x02,0x00,0x12,0x00,0x2c,0x00,0x1b,0x03,0x0c,0x00,0x19,0x00,0x00,0x00,0x01,0x00,0x4b,0x5c,0x48,0x49,0x0c,0x00,0x00,0x00,0x02,0x00,0x04,0x00,0x04,0x00,
122 | 0x12,0x00,0x84,0xfe,0x08,0x00,0x08,0x00,0x12,0x00,0x22,0xfd,0x5b,0x4c,0x00,0x89,0xfe,0x5b,0x16,0x03,0x0c,0x00,0x4b,0x5c,0x46,0x5c,0x04,0x00,0x04,0x00,
123 | 0x12,0x00,0xc8,0xff,0x5b,0x08,0x08,0x08,0x5c,0x5b,0x11,0x00,0x32,0x00,0xb7,0x08,0x00,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x1a,0x03,0x10,0x00,0x00,0x00,
124 | 0x00,0x00,0x0d,0x4c,0x00,0x77,0xfe,0x08,0x5c,0x5b,0x21,0x03,0x00,0x00,0x19,0x00,0x00,0x00,0x01,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x4c,0x00,0xde,0xff,
125 | 0x5c,0x5b,0x1a,0x03,0x08,0x00,0x00,0x00,0x08,0x00,0x4c,0x00,0xc6,0xff,0x36,0x5b,0x12,0x00,0xda,0xff,0x11,0x08,0x08,0x5c,0x00
126 | };
127 |
128 | private static byte[] MIDL_TypeFormatStringx64 = new byte[] {
129 | 0x00,0x00,0x11,0x04,0x02,0x00,0x30,0xe1,0x00,0x00,0x12,0x08,0x05,0x5c,0x11,0x00,0x96,0x00,0x1c,0x00,0x01,0x00,0x17,0x00,0x02,0x00,0x01,0x00,0x17,0x00,
130 | 0x00,0x00,0x01,0x00,0x02,0x5b,0x1a,0x03,0x10,0x00,0x00,0x00,0x08,0x00,0x06,0x06,0x40,0x36,0x5c,0x5b,0x12,0x00,0xde,0xff,0x1d,0x00,0x06,0x00,0x01,0x5b,
131 | 0x15,0x00,0x06,0x00,0x4c,0x00,0xf4,0xff,0x5c,0x5b,0x1b,0x03,0x04,0x00,0x04,0x00,0xf9,0xff,0x01,0x00,0x08,0x5b,0x17,0x03,0x08,0x00,0xf0,0xff,0x02,0x02,
132 | 0x4c,0x00,0xe0,0xff,0x5c,0x5b,0x1b,0x00,0x01,0x00,0x00,0x59,0x00,0x00,0x00,0x00,0x02,0x5b,0x17,0x01,0x04,0x00,0xf0,0xff,0x02,0x02,0x06,0x5b,0x1a,0x03,
133 | 0x28,0x00,0x00,0x00,0x0c,0x00,0x02,0x02,0x06,0x40,0x36,0x36,0x36,0x36,0x5c,0x5b,0x12,0x00,0xc8,0xff,0x12,0x00,0xc4,0xff,0x12,0x00,0xda,0xff,0x12,0x00,
134 | 0xd6,0xff,0x1a,0x03,0x0c,0x00,0x00,0x00,0x00,0x00,0x08,0x0d,0x02,0x02,0x3e,0x5b,0x1a,0x03,0x30,0x00,0x00,0x00,0x0c,0x00,0x08,0x40,0x36,0x36,0x08,0x40,
135 | 0x36,0x36,0x5c,0x5b,0x12,0x08,0x02,0x5c,0x12,0x00,0x66,0xff,0x12,0x00,0xb4,0xff,0x12,0x00,0xd2,0xff,0x11,0x04,0x02,0x00,0x30,0xa0,0x00,0x00,0x30,0x41,
136 | 0x00,0x00,0x11,0x14,0x02,0x00,0x12,0x00,0x02,0x00,0x2b,0x0d,0x26,0x00,0x08,0x00,0x01,0x00,0x02,0x00,0x48,0x00,0x0d,0x70,0x01,0x00,0x00,0x00,0x52,0x00,
137 | 0x02,0x00,0x00,0x00,0x7a,0x00,0x03,0x00,0x00,0x00,0xae,0x00,0x05,0x00,0x00,0x00,0xba,0x00,0x04,0x00,0x00,0x00,0xc6,0x00,0x06,0x00,0x00,0x00,0xce,0x00,
138 | 0x07,0x00,0x00,0x00,0xd2,0x00,0x09,0x00,0x00,0x00,0xde,0x00,0x0a,0x00,0x00,0x00,0xe6,0x00,0x0b,0x00,0x00,0x00,0xe6,0x00,0x0c,0x00,0x00,0x00,0xfa,0x00,
139 | 0x0d,0x00,0x00,0x00,0xf4,0x00,0x0e,0x00,0x00,0x00,0x84,0x00,0xff,0xff,0x15,0x07,0x08,0x00,0x0b,0x5b,0x1a,0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x08,0x08,
140 | 0x4c,0x00,0xee,0xff,0x02,0x43,0x4c,0x00,0xe8,0xff,0x08,0x40,0x5c,0x5b,0xb7,0x08,0x00,0x00,0x00,0x00,0xe8,0x03,0x00,0x00,0x1b,0x03,0x04,0x00,0x19,0x00,
141 | 0x10,0x00,0x00,0x00,0x08,0x5b,0x1a,0x03,0x18,0x00,0x00,0x00,0x0c,0x00,0x02,0x43,0x36,0x4c,0x00,0xdd,0xff,0x40,0x5c,0x5b,0x12,0x00,0xe0,0xff,0x1c,0x01,
142 | 0x02,0x00,0x17,0x55,0x02,0x00,0x01,0x00,0x17,0x55,0x00,0x00,0x01,0x00,0x05,0x5b,0x1a,0x03,0x10,0x00,0x00,0x00,0x08,0x00,0x06,0x06,0x40,0x36,0x5c,0x5b,
143 | 0x12,0x00,0xde,0xff,0x1a,0x03,0x18,0x00,0x00,0x00,0x08,0x00,0x4c,0x00,0xe4,0xff,0x36,0x5b,0x12,0x00,0x9a,0xfe,0x1a,0x03,0x18,0x00,0x00,0x00,0x08,0x00,
144 | 0x4c,0x00,0xd2,0xff,0x36,0x5b,0x12,0x00,0x88,0xfe,0x1a,0x03,0x10,0x00,0x00,0x00,0x00,0x00,0x4c,0x00,0xc0,0xff,0x5c,0x5b,0x1a,0x01,0x04,0x00,0x00,0x00,
145 | 0x00,0x00,0x0d,0x5b,0x1a,0x03,0x20,0x00,0x00,0x00,0x00,0x00,0x4c,0x00,0xa8,0xff,0x4c,0x00,0xa4,0xff,0x5c,0x5b,0x15,0x07,0x10,0x00,0x4c,0x00,0x3e,0xff,
146 | 0x4c,0x00,0x3a,0xff,0x5c,0x5b,0x15,0x00,0x01,0x00,0x02,0x5b,0x15,0x00,0x02,0x00,0x02,0x02,0x5c,0x5b,0x1d,0x00,0x08,0x00,0x01,0x5b,0x15,0x03,0x10,0x00,
147 | 0x08,0x06,0x06,0x4c,0x00,0xf1,0xff,0x5b,0x1a,0x03,0x48,0x00,0x00,0x00,0x14,0x00,0x4c,0x00,0x68,0xff,0x4c,0x00,0x64,0xff,0x4c,0x00,0x60,0xff,0x4c,0x00,
148 | 0xde,0xff,0x36,0x5b,0x12,0x00,0x12,0xfe,0x11,0x00,0x30,0x00,0xb7,0x08,0x00,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x1a,0x03,0x08,0x00,0x00,0x00,0x04,0x00,
149 | 0x36,0x5b,0x12,0x00,0xf6,0xfd,0x21,0x03,0x00,0x00,0x19,0x00,0x00,0x00,0x01,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x4c,0x00,0xe0,0xff,0x5c,0x5b,0x1a,0x03,
150 | 0x10,0x00,0x00,0x00,0x0a,0x00,0x4c,0x00,0xc8,0xff,0x40,0x36,0x5c,0x5b,0x12,0x00,0xd8,0xff,0x11,0x14,0x02,0x00,0x12,0x00,0x2a,0x00,0x1a,0x03,0x18,0x00,
151 | 0x00,0x00,0x08,0x00,0x4c,0x00,0xfc,0xfe,0x36,0x5b,0x12,0x00,0xb2,0xfd,0x21,0x03,0x00,0x00,0x19,0x00,0x00,0x00,0x01,0x00,0xff,0xff,0xff,0xff,0x00,0x00,
152 | 0x4c,0x00,0xdc,0xff,0x5c,0x5b,0x1a,0x03,0x18,0x00,0x00,0x00,0x08,0x00,0x08,0x40,0x36,0x08,0x40,0x5b,0x12,0x00,0xda,0xff,0x11,0x00,0x34,0x00,0xb7,0x08,
153 | 0x00,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x1a,0x03,0x20,0x00,0x00,0x00,0x00,0x00,0x0d,0x40,0x4c,0x00,0xb2,0xfe,0x08,0x40,0x5c,0x5b,0x21,0x03,0x00,0x00,
154 | 0x19,0x00,0x00,0x00,0x01,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x4c,0x00,0xdc,0xff,0x5c,0x5b,0x1a,0x03,0x10,0x00,0x00,0x00,0x0a,0x00,0x4c,0x00,0xc4,0xff,
155 | 0x40,0x36,0x5c,0x5b,0x12,0x00,0xd8,0xff,0x11,0x08,0x08,0x5c,0x00
156 | };
157 |
158 | [StructLayout(LayoutKind.Sequential)]
159 | internal struct LSAPR_OBJECT_ATTRIBUTES
160 | {
161 | public UInt32 Length;
162 | public IntPtr RootDirectory;
163 | public IntPtr ObjectName;
164 | public UInt32 Attributes;
165 | public IntPtr SecurityDescriptor;
166 | public IntPtr SecurityQualityOfService;
167 | }
168 |
169 | [StructLayout(LayoutKind.Sequential)]
170 | private struct LSAPR_POLICY_ACCOUNT_DOM_INFO
171 | {
172 | public UInt16 Length;
173 | public UInt16 MaximumLength;
174 | public IntPtr buffer;
175 | public IntPtr DomainSid;
176 | }
177 |
178 | [StructLayout(LayoutKind.Sequential)]
179 | internal struct LSAPR_SID_ENUM_BUFFER
180 | {
181 | public UInt32 Entries;
182 | public IntPtr SidInfo;
183 | }
184 |
185 |
186 | [StructLayout(LayoutKind.Sequential)]
187 | private struct LSAPR_REFERENCED_DOMAIN_LIST
188 | {
189 | public UInt32 Entries;
190 | public IntPtr Domains;
191 | public UInt32 MaxEntries;
192 | }
193 |
194 | [StructLayout(LayoutKind.Sequential)]
195 | private struct LSAPR_TRUST_INFORMATION
196 | {
197 | public UInt16 Length;
198 | public UInt16 MaximumLength;
199 | public IntPtr buffer;
200 | public IntPtr Sid;
201 | };
202 |
203 | [StructLayout(LayoutKind.Sequential)]
204 | private struct LSAPR_TRANSLATED_NAMES
205 | {
206 | public UInt32 Entries;
207 | public IntPtr Names;
208 | }
209 |
210 | [StructLayout(LayoutKind.Sequential)]
211 | private struct LSAPR_TRANSLATED_NAME
212 | {
213 | public IntPtr Use;
214 | public UInt16 Length;
215 | public UInt16 MaximumLength;
216 | public IntPtr buffer;
217 | public UInt32 DomainIndex;
218 | }
219 |
220 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
221 | public lsa()
222 | {
223 | Guid interfaceId = new Guid("12345778-1234-ABCD-EF00-0123456789AB");
224 | if (IntPtr.Size == 8)
225 | {
226 | InitializeStub(interfaceId, MIDL_ProcFormatStringx64, MIDL_TypeFormatStringx64, "\\pipe\\lsarpc", 0);
227 | }
228 | else
229 | {
230 | InitializeStub(interfaceId, MIDL_ProcFormatStringx86, MIDL_TypeFormatStringx86, "\\pipe\\lsarpc", 0);
231 | }
232 | UseNullSession = true;
233 | }
234 |
235 | [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
236 | ~lsa()
237 | {
238 | freeStub();
239 | }
240 |
241 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
242 | public Int32 LsarOpenPolicy(string SystemName, UInt32 DesiredAccess, out IntPtr PolicyHandle)
243 | {
244 | IntPtr intptrSystemName = Marshal.StringToHGlobalUni(SystemName);
245 | LSAPR_OBJECT_ATTRIBUTES objectAttributes = new LSAPR_OBJECT_ATTRIBUTES();
246 | PolicyHandle = IntPtr.Zero;
247 | IntPtr result = IntPtr.Zero;
248 | try
249 | {
250 | PolicyHandle = IntPtr.Zero;
251 | if (IntPtr.Size == 8)
252 | {
253 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(194), intptrSystemName, ref objectAttributes, DesiredAccess, out PolicyHandle);
254 | }
255 | else
256 | {
257 | IntPtr tempValue1 = new IntPtr();
258 | GCHandle handle1 = GCHandle.Alloc(tempValue1, GCHandleType.Pinned);
259 | IntPtr tempValuePointer1 = handle1.AddrOfPinnedObject();
260 | GCHandle handle2 = GCHandle.Alloc(objectAttributes, GCHandleType.Pinned);
261 | IntPtr tempValuePointer2 = handle2.AddrOfPinnedObject();
262 | try
263 | {
264 | result = CallNdrClientCall2x86(182, intptrSystemName, tempValuePointer2, new IntPtr((int)DesiredAccess), tempValuePointer1);
265 | // each pinvoke work on a copy of the arguments (without an out specifier)
266 | // get back the data
267 | PolicyHandle = Marshal.ReadIntPtr(tempValuePointer1);
268 | }
269 | finally
270 | {
271 | handle1.Free();
272 | handle2.Free();
273 | }
274 | }
275 | }
276 | catch (SEHException)
277 | {
278 | Trace.WriteLine("LsarOpenPolicy failed 0x" + Marshal.GetExceptionCode().ToString("x"));
279 | return Marshal.GetExceptionCode();
280 | }
281 | finally
282 | {
283 | if (intptrSystemName != IntPtr.Zero)
284 | Marshal.FreeHGlobal(intptrSystemName);
285 | }
286 | return (int) result.ToInt64();
287 | }
288 |
289 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
290 | public Int32 LsarClose(ref IntPtr ServerHandle)
291 | {
292 | IntPtr result = IntPtr.Zero;
293 | try
294 | {
295 | if (IntPtr.Size == 8)
296 | {
297 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(0), ref ServerHandle);
298 | }
299 | else
300 | {
301 | IntPtr tempValue = ServerHandle;
302 | GCHandle handle = GCHandle.Alloc(tempValue, GCHandleType.Pinned);
303 | IntPtr tempValuePointer = handle.AddrOfPinnedObject();
304 | try
305 | {
306 | result = CallNdrClientCall2x86(0, tempValuePointer);
307 | // each pinvoke work on a copy of the arguments (without an out specifier)
308 | // get back the data
309 | ServerHandle = Marshal.ReadIntPtr(tempValuePointer);
310 | }
311 | finally
312 | {
313 | handle.Free();
314 | }
315 | }
316 | }
317 | catch (SEHException)
318 | {
319 | Trace.WriteLine("LsarClose failed 0x" + Marshal.GetExceptionCode().ToString("x"));
320 | return Marshal.GetExceptionCode();
321 | }
322 | return (int) result.ToInt64();
323 | }
324 |
325 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
326 | public Int32 LsarQueryInformationPolicy(IntPtr PolicyHandle, UInt32 InformationClass, out LSA_DOMAIN_INFORMATION PolicyInformation)
327 | {
328 | IntPtr result = IntPtr.Zero;
329 | try
330 | {
331 | IntPtr IntPtrPolicyInformation = IntPtr.Zero;
332 | if (IntPtr.Size == 8)
333 | {
334 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(256), PolicyHandle, InformationClass, out IntPtrPolicyInformation);
335 | }
336 | else
337 | {
338 | IntPtr tempValue1 = IntPtr.Zero;
339 | GCHandle handle1 = GCHandle.Alloc(tempValue1, GCHandleType.Pinned);
340 | IntPtr tempValuePointer1 = handle1.AddrOfPinnedObject();
341 | try
342 | {
343 | result = CallNdrClientCall2x86(242, PolicyHandle, new IntPtr(InformationClass), tempValuePointer1);
344 | // each pinvoke work on a copy of the arguments (without an out specifier)
345 | // get back the data
346 | IntPtrPolicyInformation = Marshal.ReadIntPtr(tempValuePointer1);
347 | }
348 | finally
349 | {
350 | handle1.Free();
351 | }
352 | }
353 | PolicyInformation = Unmarshal_LSAPR_POLICY_ACCOUNT_DOM_INFO(IntPtrPolicyInformation);
354 | }
355 | catch (SEHException)
356 | {
357 | PolicyInformation = null;
358 | Trace.WriteLine("LsarQueryInformationPolicy failed 0x" + Marshal.GetExceptionCode().ToString("x"));
359 | return Marshal.GetExceptionCode();
360 | }
361 | return (int) result.ToInt64();
362 | }
363 |
364 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
365 | private LSA_DOMAIN_INFORMATION Unmarshal_LSAPR_POLICY_ACCOUNT_DOM_INFO(IntPtr IntPtrPolicyInformation)
366 | {
367 | if (IntPtrPolicyInformation == IntPtr.Zero)
368 | return null;
369 | LSAPR_POLICY_ACCOUNT_DOM_INFO Buffer = (LSAPR_POLICY_ACCOUNT_DOM_INFO)Marshal.PtrToStructure(IntPtrPolicyInformation, typeof(LSAPR_POLICY_ACCOUNT_DOM_INFO));
370 | LSA_DOMAIN_INFORMATION output = new LSA_DOMAIN_INFORMATION();
371 | output.DomainName = Marshal.PtrToStringUni(Buffer.buffer, Buffer.Length / 2);
372 | output.DomainSid = new SecurityIdentifier(Buffer.DomainSid);
373 |
374 | if (Buffer.buffer != IntPtr.Zero && Buffer.MaximumLength > 0)
375 | FreeMemory(Buffer.buffer);
376 | if (Buffer.DomainSid != IntPtr.Zero)
377 | FreeMemory(Buffer.DomainSid);
378 | FreeMemory(IntPtrPolicyInformation);
379 | return output;
380 | }
381 |
382 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
383 | public Int32 LsarLookupSids(IntPtr PolicyHandle, SecurityIdentifier[] SidEnumBuffer, out LSA_LOOKUP_RESULT[] LookupResult, UInt32 LookupLevel,out UInt32 MappedCount)
384 | {
385 | List HandleToFree = new List();
386 | IntPtr result = IntPtr.Zero;
387 | LookupResult = null;
388 | MappedCount = 0;
389 | try
390 | {
391 | IntPtr IntPtrReferencedDomains = IntPtr.Zero;
392 | LSAPR_TRANSLATED_NAMES TranslatedNames = new LSAPR_TRANSLATED_NAMES();
393 | GCHandle handleTranslatedNames = GCHandle.Alloc(TranslatedNames, GCHandleType.Pinned);
394 | // translatedNamesValuePointer points to a copy of TranslatedNames
395 | IntPtr IntPtrTranslatedNames = handleTranslatedNames.AddrOfPinnedObject();
396 | HandleToFree.Add(handleTranslatedNames);
397 |
398 | LSAPR_SID_ENUM_BUFFER enumBuffer = Marshal_LSAPR_SID_ENUM_BUFFER(SidEnumBuffer, HandleToFree);
399 | if (IntPtr.Size == 8)
400 | {
401 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(522), PolicyHandle, enumBuffer, out IntPtrReferencedDomains, IntPtrTranslatedNames, LookupLevel, out MappedCount);
402 | }
403 | else
404 | {
405 | GCHandle handle1 = GCHandle.Alloc(enumBuffer, GCHandleType.Pinned);
406 | IntPtr tempValuePointer1 = handle1.AddrOfPinnedObject();
407 | IntPtr tempValue2 = IntPtr.Zero;
408 | GCHandle handle2 = GCHandle.Alloc(tempValue2, GCHandleType.Pinned);
409 | IntPtr tempValuePointer2 = handle2.AddrOfPinnedObject();
410 |
411 | IntPtr tempValue4 = IntPtr.Zero;
412 | GCHandle handle4 = GCHandle.Alloc(tempValue4, GCHandleType.Pinned);
413 | IntPtr tempValuePointer4 = handle4.AddrOfPinnedObject();
414 | try
415 | {
416 | result = CallNdrClientCall2x86(492, PolicyHandle, tempValuePointer1, tempValuePointer2, IntPtrTranslatedNames, new IntPtr(LookupLevel), tempValuePointer4);
417 | // each pinvoke work on a copy of the arguments (without an out specifier)
418 | // get back the data
419 | IntPtrReferencedDomains = Marshal.ReadIntPtr(tempValuePointer2);
420 | MappedCount = (UInt32)Marshal.ReadInt32(tempValuePointer4);
421 | }
422 | finally
423 | {
424 | handle1.Free();
425 | handle2.Free();
426 | handle4.Free();
427 | }
428 | }
429 | if (result == IntPtr.Zero || result == new IntPtr(0x00000107))
430 | {
431 | LookupResult = Marshal_LsarLookupSids_Output(IntPtrReferencedDomains, IntPtrTranslatedNames);
432 | }
433 | }
434 | catch (SEHException)
435 | {
436 | Trace.WriteLine("LsarLookupSids failed 0x" + Marshal.GetExceptionCode().ToString("x"));
437 | return Marshal.GetExceptionCode();
438 | }
439 | finally
440 | {
441 | foreach (GCHandle handle in HandleToFree)
442 | {
443 | handle.Free();
444 | }
445 | }
446 | return (int) result.ToInt64();
447 | }
448 |
449 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
450 | private LSAPR_SID_ENUM_BUFFER Marshal_LSAPR_SID_ENUM_BUFFER(SecurityIdentifier[] SidEnumBuffer, List HandleToFree)
451 | {
452 | LSAPR_SID_ENUM_BUFFER output = new LSAPR_SID_ENUM_BUFFER();
453 | output.Entries = (UInt32) SidEnumBuffer.Length;
454 | IntPtr[] sidPtr = new IntPtr[SidEnumBuffer.Length];
455 | for (int i = 0; i < SidEnumBuffer.Length; i++)
456 | {
457 | byte[] sid = new byte[SidEnumBuffer[i].BinaryLength];
458 | SidEnumBuffer[i].GetBinaryForm(sid, 0);
459 | GCHandle handlesid = GCHandle.Alloc(sid, GCHandleType.Pinned);
460 | HandleToFree.Add(handlesid);
461 | sidPtr[i] = handlesid.AddrOfPinnedObject();
462 | }
463 | GCHandle handle = GCHandle.Alloc(sidPtr, GCHandleType.Pinned);
464 | HandleToFree.Add(handle);
465 | output.SidInfo = handle.AddrOfPinnedObject();
466 | return output;
467 | }
468 |
469 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
470 | private LSA_LOOKUP_RESULT[] Marshal_LsarLookupSids_Output(IntPtr IntPtrReferencedDomains, IntPtr IntPtrTranslatedNames)
471 | {
472 | if (IntPtrReferencedDomains == IntPtr.Zero || IntPtrTranslatedNames == IntPtr.Zero)
473 | return null;
474 | LSAPR_REFERENCED_DOMAIN_LIST ReferencedDomains = (LSAPR_REFERENCED_DOMAIN_LIST)Marshal.PtrToStructure(IntPtrReferencedDomains, typeof(LSAPR_REFERENCED_DOMAIN_LIST));
475 | LSAPR_TRANSLATED_NAMES TranslatedNames = (LSAPR_TRANSLATED_NAMES)Marshal.PtrToStructure(IntPtrTranslatedNames, typeof(LSAPR_TRANSLATED_NAMES));
476 |
477 |
478 | int SizeTranslatedName = Marshal.SizeOf(typeof(LSAPR_TRANSLATED_NAME));
479 | int SizeTrustInformation = Marshal.SizeOf(typeof(LSAPR_TRUST_INFORMATION));
480 |
481 | string[] referencedDomainsString = new string[ReferencedDomains.Entries];
482 | SecurityIdentifier[] referencedDomainsSid = new SecurityIdentifier[ReferencedDomains.Entries];
483 | for (UInt32 i = 0; i < ReferencedDomains.Entries; i++)
484 | {
485 | LSAPR_TRUST_INFORMATION trustInformation = (LSAPR_TRUST_INFORMATION)Marshal.PtrToStructure(new IntPtr(ReferencedDomains.Domains.ToInt64() + SizeTrustInformation * i), typeof(LSAPR_TRUST_INFORMATION));
486 |
487 | if (trustInformation.buffer != IntPtr.Zero)
488 | referencedDomainsString[i] = Marshal.PtrToStringUni(trustInformation.buffer, trustInformation.Length / 2);
489 | if (trustInformation.Sid != null)
490 | referencedDomainsSid[i] = new SecurityIdentifier(trustInformation.Sid);
491 |
492 | if (trustInformation.buffer != IntPtr.Zero && trustInformation.MaximumLength > 0)
493 | FreeMemory(trustInformation.buffer);
494 | if (trustInformation.Sid != IntPtr.Zero)
495 | FreeMemory(trustInformation.Sid);
496 | }
497 |
498 | LSA_LOOKUP_RESULT[] output = new LSA_LOOKUP_RESULT[TranslatedNames.Entries];
499 | for (UInt32 i = 0; i < TranslatedNames.Entries; i++)
500 | {
501 | LSAPR_TRANSLATED_NAME translatedName = (LSAPR_TRANSLATED_NAME)Marshal.PtrToStructure(new IntPtr(TranslatedNames.Names.ToInt64() + SizeTranslatedName * i), typeof(LSAPR_TRANSLATED_NAME));
502 | output[i] = new LSA_LOOKUP_RESULT();
503 |
504 | if (translatedName.buffer != IntPtr.Zero)
505 | output[i].TranslatedName = Marshal.PtrToStringUni(translatedName.buffer, translatedName.Length / 2);
506 | output[i].Use = (SID_NAME_USE) translatedName.Use;
507 | output[i].DomainName = referencedDomainsString[translatedName.DomainIndex];
508 | output[i].DomainSid = referencedDomainsSid[translatedName.DomainIndex];
509 |
510 | if (translatedName.buffer != IntPtr.Zero && translatedName.MaximumLength > 0)
511 | FreeMemory(translatedName.buffer);
512 | }
513 |
514 | FreeMemory(ReferencedDomains.Domains);
515 | FreeMemory(TranslatedNames.Names);
516 | FreeMemory(IntPtrReferencedDomains);
517 | return output;
518 | }
519 | }
520 | }
521 |
--------------------------------------------------------------------------------
/RPC/nativemethods.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Oxid Resolver. All rights reserved.
3 | //
4 | //
5 | // Licensed under the Non-Profit OSL. See LICENSE file in the project root for full license information.
6 | //
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Runtime.InteropServices;
10 | using System.Text;
11 |
12 | namespace OxidResolver.RPC
13 | {
14 | internal class NativeMethods
15 | {
16 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingFromStringBindingW",
17 | CallingConvention = CallingConvention.StdCall,
18 | CharSet = CharSet.Unicode, SetLastError = false)]
19 | internal static extern Int32 RpcBindingFromStringBinding(String bindingString, out IntPtr lpBinding);
20 |
21 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
22 | CharSet = CharSet.Unicode, SetLastError = false)]
23 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, ref IntPtr Handle);
24 |
25 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
26 | CharSet = CharSet.Unicode, SetLastError = false)]
27 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr intptrServer, int flag, ref OxidResolver.RPC.nrpc.NETLOGON_TRUSTED_DOMAIN_ARRAY output);
28 |
29 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
30 | CharSet = CharSet.Unicode, SetLastError = false)]
31 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr intptrSystemName, ref OxidResolver.RPC.lsa.LSAPR_OBJECT_ATTRIBUTES objectAttributes, UInt32 DesiredAccess, out IntPtr PolicyHandle);
32 |
33 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
34 | CharSet = CharSet.Unicode, SetLastError = false)]
35 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr PolicyHandle, UInt32 InformationClass, out IntPtr IntPtrPolicyInformation);
36 |
37 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
38 | CharSet = CharSet.Unicode, SetLastError = false)]
39 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr PolicyHandle, OxidResolver.RPC.lsa.LSAPR_SID_ENUM_BUFFER enumBuffer, out IntPtr IntPtrReferencedDomains, IntPtr IntPtrTranslatedNames, UInt32 LookupLevel, out UInt32 MappedCount);
40 |
41 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
42 | CharSet = CharSet.Unicode, SetLastError = false)]
43 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr intptrServer, out IntPtr ServerHandle, UInt32 DesiredAccess);
44 |
45 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
46 | CharSet = CharSet.Unicode, SetLastError = false)]
47 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr ServerHandle, ref IntPtr EnumerationContext, out IntPtr IntptrBuffer, UInt32 PreferedMaximumLength, out UInt32 CountReturned);
48 |
49 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
50 | CharSet = CharSet.Unicode, SetLastError = false)]
51 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr ServerHandle, OxidResolver.NativeMethods.UNICODE_STRING NameString, out IntPtr sid);
52 |
53 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
54 | CharSet = CharSet.Unicode, SetLastError = false)]
55 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr ServerHandle, Int32 DesiredAccess, byte[] sid, out IntPtr DomainHandle);
56 |
57 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
58 | CharSet = CharSet.Unicode, SetLastError = false)]
59 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr DomainHandle, ref IntPtr EnumerationContext, Int32 UserAccountControl, out IntPtr IntptrBuffer, Int32 PreferedMaximumLength, ref UInt32 CountReturned);
60 |
61 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
62 | CharSet = CharSet.Unicode, SetLastError = false)]
63 | internal static extern IntPtr NdrClientCall2x86(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr args);
64 |
65 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
66 | CharSet = CharSet.Unicode, SetLastError = false)]
67 | internal static extern IntPtr NdrClientCall2x64(IntPtr intPtr1, IntPtr intPtr2, string pPrinterName, out IntPtr pHandle, string pDatatype, ref rprn.DEVMODE_CONTAINER pDevModeContainer, int AccessRequired);
68 |
69 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
70 | CharSet = CharSet.Unicode, SetLastError = false)]
71 | internal static extern IntPtr NdrClientCall2x64(IntPtr intPtr1, IntPtr intPtr2, IntPtr hPrinter, uint fdwFlags, uint fdwOptions, string pszLocalMachine, uint dwPrinterLocal, IntPtr intPtr3);
72 |
73 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl,
74 | CharSet = CharSet.Unicode, SetLastError = false)]
75 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr Handle, ref OxidResolver.RPC.OxidBindings.COMVERSION i1, out System.IntPtr i2, ref uint i3);
76 |
77 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingFree", CallingConvention = CallingConvention.StdCall,
78 | CharSet = CharSet.Unicode, SetLastError = false)]
79 | internal static extern Int32 RpcBindingFree(ref IntPtr lpString);
80 |
81 | //#region RpcStringBindingCompose
82 |
83 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcStringBindingComposeW", CallingConvention = CallingConvention.StdCall,
84 | CharSet = CharSet.Unicode, SetLastError = false)]
85 | internal static extern Int32 RpcStringBindingCompose(
86 | String ObjUuid, String ProtSeq, String NetworkAddr, String Endpoint, String Options,
87 | out IntPtr lpBindingString
88 | );
89 |
90 | [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
91 | internal struct SEC_WINNT_AUTH_IDENTITY
92 | {
93 | [MarshalAs(UnmanagedType.LPWStr)]
94 | public string User;
95 | public int UserLength;
96 | [MarshalAs(UnmanagedType.LPWStr)]
97 | public string Domain;
98 | public int DomainLength;
99 | [MarshalAs(UnmanagedType.LPWStr)]
100 | public string Password;
101 | public int PasswordLength;
102 | public int Flags;
103 | };
104 |
105 | [StructLayout(LayoutKind.Sequential)]
106 | public struct RPC_SECURITY_QOS
107 | {
108 | public Int32 Version;
109 | public Int32 Capabilities;
110 | public Int32 IdentityTracking;
111 | public Int32 ImpersonationType;
112 | };
113 |
114 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetAuthInfoW", CallingConvention = CallingConvention.StdCall,
115 | CharSet = CharSet.Unicode, SetLastError = false)]
116 | internal static extern Int32 RpcBindingSetAuthInfo(IntPtr Binding, String ServerPrincName,
117 | UInt32 AuthnLevel, UInt32 AuthnSvc,
118 | IntPtr identity,
119 | uint AuthzSvc);
120 |
121 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetAuthInfoExW", CallingConvention = CallingConvention.StdCall,
122 | CharSet = CharSet.Unicode, SetLastError = false)]
123 | internal static extern Int32 RpcBindingSetAuthInfoEx(IntPtr lpBinding, string ServerPrincName,
124 | UInt32 AuthnLevel, UInt32 AuthnSvc, ref SEC_WINNT_AUTH_IDENTITY AuthIdentity, UInt32 AuthzSvc, ref RPC_SECURITY_QOS SecurityQOS);
125 |
126 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetAuthInfoW", CallingConvention = CallingConvention.StdCall,
127 | CharSet = CharSet.Unicode, SetLastError = false)]
128 | internal static extern Int32 RpcBindingSetAuthInfo(IntPtr lpBinding, string ServerPrincName,
129 | UInt32 AuthnLevel, UInt32 AuthnSvc, ref SEC_WINNT_AUTH_IDENTITY AuthIdentity, UInt32 AuthzSvc);
130 |
131 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetAuthInfoW", CallingConvention = CallingConvention.StdCall,
132 | CharSet = CharSet.Unicode, SetLastError = false)]
133 | internal static extern Int32 RpcBindingSetAuthInfo(IntPtr lpBinding, string ServerPrincName,
134 | UInt32 AuthnLevel, UInt32 AuthnSvc, UIntPtr pointer, UInt32 AuthzSvc);
135 |
136 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetOption", CallingConvention = CallingConvention.StdCall,SetLastError= false)]
137 | internal static extern Int32 RpcBindingSetOption(IntPtr Binding,UInt32 Option, UInt32 OptionValue);
138 |
139 | [DllImport("Rpcrt4.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)]
140 | internal static extern Int32 RpcEpResolveBinding(IntPtr Binding, IntPtr RpcClientInterface);
141 |
142 | [DllImport("advapi32.dll", SetLastError = true)]
143 | internal static extern IntPtr GetSidSubAuthority(IntPtr sid, UInt32 subAuthorityIndex);
144 |
145 | [DllImport("advapi32.dll", SetLastError = true)]
146 | internal static extern IntPtr GetSidSubAuthorityCount(IntPtr psid);
147 |
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/RPC/nrpc.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Oxid Resolver. All rights reserved.
3 | //
4 | //
5 | // Licensed under the Non-Profit OSL. See LICENSE file in the project root for full license information.
6 | //
7 | using Microsoft.Win32.SafeHandles;
8 | using System;
9 | using System.Collections.Generic;
10 | using System.Diagnostics;
11 | using System.Runtime.ConstrainedExecution;
12 | using System.Runtime.InteropServices;
13 | using System.Security.Permissions;
14 | using System.Security.Principal;
15 | using System.Text;
16 |
17 | namespace OxidResolver.RPC
18 | {
19 |
20 | [DebuggerDisplay("{DnsDomainName} {NetbiosDomainName}")]
21 | public class TrustedDomain
22 | {
23 | public string NetbiosDomainName;
24 | public string DnsDomainName;
25 | public TrustedDomainFlag Flags;
26 | public int ParentIndex;
27 | public int TrustType;
28 | public int TrustAttributes;
29 | public SecurityIdentifier DomainSid;
30 | public Guid DomainGuid;
31 | }
32 |
33 | [Flags]
34 | public enum TrustedDomainFlag
35 | {
36 | DS_DOMAIN_IN_FOREST = 1,
37 | DS_DOMAIN_DIRECT_OUTBOUND = 2,
38 | DS_DOMAIN_TREE_ROOT = 4,
39 | DS_DOMAIN_PRIMARY = 8,
40 | DS_DOMAIN_NATIVE_MODE = 16,
41 | DS_DOMAIN_DIRECT_INBOUND =32,
42 | }
43 |
44 | public class nrpc : rpcapi
45 | {
46 |
47 | private static byte[] MIDL_ProcFormatStringx86 = new byte[] {
48 | 0x00,0x48,0x00,0x00,0x00,0x00,0x28,0x00,0x10,0x00,0x31,0x04,0x00,0x00,0x00,0x5c,0x08,0x00,0x08,0x00,0x47,0x04,0x08,0x03,0x01,0x00,0x00,0x00,0x00,
49 | 0x00,0x0b,0x00,0x00,0x00,0x02,0x00,0x48,0x00,0x04,0x00,0x08,0x00,0x13,0x21,0x08,0x00,0xaa,0x00,0x70,0x00,0x0c,0x00,0x08,0x00,0x00
50 | };
51 |
52 | private static byte[] MIDL_ProcFormatStringx64 = new byte[] {
53 | 0x00,0x48,0x00,0x00,0x00,0x00,0x28,0x00,0x20,0x00,0x31,0x08,0x00,0x00,0x00,0x5c,0x08,0x00,0x08,0x00,0x47,0x04,0x0a,0x03,0x01,0x00,0x00,0x00,0x00,
54 | 0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x02,0x00,0x48,0x00,0x08,0x00,0x08,0x00,0x13,0x41,0x10,0x00,0x7c,0x00,0x70,0x00,0x18,0x00,0x08,0x00,0x00
55 | };
56 |
57 | private static byte[] MIDL_TypeFormatStringx86 = new byte[] {
58 | 0x00,0x00,0x12,0x08,0x25,0x5c,0x11,0x04,0xa2,0x00,0x1d,0x00,0x08,0x00,0x01,0x5b,0x15,0x03,0x10,0x00,0x08,0x06,0x06,0x4c,0x00,0xf1,0xff,0x5b,0x1d,
59 | 0x00,0x06,0x00,0x01,0x5b,0x15,0x00,0x06,0x00,0x4c,0x00,0xf4,0xff,0x5c,0x5b,0x1b,0x03,0x04,0x00,0x04,0x00,0xf9,0xff,0x01,0x00,0x08,0x5b,0x17,0x03,
60 | 0x08,0x00,0xf0,0xff,0x02,0x02,0x4c,0x00,0xe0,0xff,0x5c,0x5b,0x16,0x03,0x2c,0x00,0x4b,0x5c,0x46,0x5c,0x00,0x00,0x00,0x00,0x12,0x08,0x25,0x5c,0x46,
61 | 0x5c,0x04,0x00,0x04,0x00,0x12,0x08,0x25,0x5c,0x46,0x5c,0x18,0x00,0x18,0x00,0x12,0x00,0xd0,0xff,0x5b,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x4c,0x00,
62 | 0x9c,0xff,0x5c,0x5b,0x1b,0x03,0x2c,0x00,0x19,0x00,0x00,0x00,0x01,0x00,0x4b,0x5c,0x48,0x49,0x2c,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x12,
63 | 0x08,0x25,0x5c,0x04,0x00,0x04,0x00,0x12,0x08,0x25,0x5c,0x18,0x00,0x18,0x00,0x12,0x00,0x96,0xff,0x5b,0x4c,0x00,0x9f,0xff,0x5b,0x16,0x03,0x08,0x00,
64 | 0x4b,0x5c,0x46,0x5c,0x04,0x00,0x04,0x00,0x12,0x00,0xc0,0xff,0x5b,0x08,0x08,0x5b,0x00
65 | };
66 |
67 | private static byte[] MIDL_TypeFormatStringx64 = new byte[] {
68 | 0x00,0x00,0x12,0x08,0x25,0x5c,0x11,0x04,0x74,0x00,0x1d,0x00,0x08,0x00,0x01,0x5b,0x15,0x03,0x10,0x00,0x08,0x06,0x06,0x4c,0x00,0xf1,0xff,0x5b,0x1d,
69 | 0x00,0x06,0x00,0x01,0x5b,0x15,0x00,0x06,0x00,0x4c,0x00,0xf4,0xff,0x5c,0x5b,0x1b,0x03,0x04,0x00,0x04,0x00,0xf9,0xff,0x01,0x00,0x08,0x5b,0x17,0x03,
70 | 0x08,0x00,0xf0,0xff,0x02,0x02,0x4c,0x00,0xe0,0xff,0x5c,0x5b,0x1a,0x03,0x38,0x00,0x00,0x00,0x0e,0x00,0x36,0x36,0x08,0x08,0x08,0x08,0x36,0x4c,0x00,
71 | 0xb9,0xff,0x5b,0x12,0x08,0x25,0x5c,0x12,0x08,0x25,0x5c,0x12,0x00,0xd4,0xff,0x21,0x03,0x00,0x00,0x19,0x00,0x00,0x00,0x01,0x00,0xff,0xff,0xff,0xff,
72 | 0x00,0x00,0x4c,0x00,0xce,0xff,0x5c,0x5b,0x1a,0x03,0x10,0x00,0x00,0x00,0x06,0x00,0x08,0x40,0x36,0x5b,0x12,0x00,0xdc,0xff,0x00
73 | };
74 |
75 | [StructLayout(LayoutKind.Sequential)]
76 | internal struct NETLOGON_TRUSTED_DOMAIN_ARRAY
77 | {
78 | public int DomainCount;
79 | public IntPtr Domains;
80 | }
81 |
82 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
83 | private struct DS_DOMAIN_TRUSTSW
84 | {
85 | public IntPtr NetbiosDomainName;
86 | public IntPtr DnsDomainName;
87 | public int Flags;
88 | public int ParentIndex;
89 | public int TrustType;
90 | public int TrustAttributes;
91 | public IntPtr DomainSid;
92 | public Guid DomainGuid;
93 | }
94 |
95 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
96 | public nrpc(bool WillUseNullSession = true)
97 | {
98 | Guid interfaceId = new Guid("12345678-1234-ABCD-EF00-01234567CFFB");
99 | if (IntPtr.Size == 8)
100 | {
101 | InitializeStub(interfaceId, MIDL_ProcFormatStringx64, MIDL_TypeFormatStringx64, "\\pipe\\netlogon");
102 | }
103 | else
104 | {
105 | InitializeStub(interfaceId, MIDL_ProcFormatStringx86, MIDL_TypeFormatStringx86, "\\pipe\\netlogon");
106 | }
107 | UseNullSession = WillUseNullSession;
108 | }
109 |
110 | [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
111 | ~nrpc()
112 | {
113 | freeStub();
114 | }
115 |
116 | [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
117 | public Int32 DsrEnumerateDomainTrusts(string server, int flag, out List domains)
118 | {
119 | IntPtr result = IntPtr.Zero;
120 | domains = null;
121 | IntPtr intptrServer = Marshal.StringToHGlobalUni(server);
122 | NETLOGON_TRUSTED_DOMAIN_ARRAY output = new NETLOGON_TRUSTED_DOMAIN_ARRAY();
123 | try
124 | {
125 | if (IntPtr.Size == 8)
126 | {
127 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(0), intptrServer, flag, ref output);
128 | }
129 | else
130 | {
131 | GCHandle handle = GCHandle.Alloc(output, GCHandleType.Pinned);
132 | IntPtr tempValuePointer = handle.AddrOfPinnedObject();
133 | try
134 | {
135 | result = CallNdrClientCall2x86(0, intptrServer, new IntPtr((int)flag), tempValuePointer);
136 | // each pinvoke work on a copy of the arguments (without an out specifier)
137 | // get back the data
138 | output = (NETLOGON_TRUSTED_DOMAIN_ARRAY)Marshal.PtrToStructure(tempValuePointer, typeof(NETLOGON_TRUSTED_DOMAIN_ARRAY));
139 | }
140 | finally
141 | {
142 | handle.Free();
143 | }
144 | }
145 | }
146 | catch (SEHException)
147 | {
148 | return Marshal.GetExceptionCode();
149 | }
150 | finally
151 | {
152 | if (intptrServer != IntPtr.Zero)
153 | Marshal.FreeHGlobal(intptrServer);
154 | }
155 | domains = DomainArrayToTrustedDomainList(output);
156 | return (int) result.ToInt64();
157 | }
158 |
159 | [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
160 | private List DomainArrayToTrustedDomainList(NETLOGON_TRUSTED_DOMAIN_ARRAY trustedDomainArray)
161 | {
162 | List output = new List();
163 | int size = Marshal.SizeOf(typeof(DS_DOMAIN_TRUSTSW));
164 | for (int i = 0; i < trustedDomainArray.DomainCount; i++)
165 | {
166 | DS_DOMAIN_TRUSTSW trust = (DS_DOMAIN_TRUSTSW) Marshal.PtrToStructure(new IntPtr(trustedDomainArray.Domains.ToInt64() + size * i), typeof(DS_DOMAIN_TRUSTSW));
167 | TrustedDomain domain = new TrustedDomain();
168 | if (trust.DnsDomainName != IntPtr.Zero)
169 | {
170 | domain.DnsDomainName = Marshal.PtrToStringUni(trust.DnsDomainName);
171 | FreeMemory(trust.DnsDomainName);
172 | }
173 | if (trust.NetbiosDomainName != IntPtr.Zero)
174 | {
175 | domain.NetbiosDomainName = Marshal.PtrToStringUni(trust.NetbiosDomainName);
176 | FreeMemory(trust.NetbiosDomainName);
177 | }
178 | domain.Flags = (TrustedDomainFlag) trust.Flags;
179 | domain.ParentIndex = trust.ParentIndex;
180 | domain.TrustAttributes = trust.TrustAttributes;
181 | domain.TrustType = trust.TrustType;
182 | domain.DomainGuid = trust.DomainGuid;
183 | if (trust.DomainSid != IntPtr.Zero)
184 | {
185 | domain.DomainSid = new SecurityIdentifier(trust.DomainSid);
186 | FreeMemory(trust.DomainSid);
187 | }
188 | output.Add(domain);
189 | }
190 | FreeMemory(trustedDomainArray.Domains);
191 | return output;
192 | }
193 |
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/RPC/rpcapi.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Oxid Resolver. All rights reserved.
3 | //
4 | //
5 | // Licensed under the Non-Profit OSL. See LICENSE file in the project root for full license information.
6 | //
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Diagnostics;
10 | using System.Runtime.CompilerServices;
11 | using System.Runtime.InteropServices;
12 | using System.Security.Permissions;
13 | using System.Text;
14 |
15 | namespace OxidResolver.RPC
16 | {
17 | public abstract class rpcapi
18 | {
19 |
20 | private byte[] MIDL_ProcFormatString;
21 | private byte[] MIDL_TypeFormatString;
22 | private GCHandle procString;
23 | private GCHandle formatString;
24 | private GCHandle stub;
25 | protected IntPtr rpcClientInterface;
26 | private GCHandle faultoffsets;
27 | private GCHandle clientinterface;
28 | private GCHandle bindinghandle;
29 | private string PipeName;
30 |
31 | // important: keep a reference on delegate to avoid CallbackOnCollectedDelegate exception
32 | bind BindDelegate;
33 | unbind UnbindDelegate;
34 | allocmemory AllocateMemoryDelegate = AllocateMemory;
35 | freememory FreeMemoryDelegate = FreeMemory;
36 |
37 | public bool UseNullSession { get; set; }
38 | // 5 seconds
39 | public UInt32 RPCTimeOut = 5000;
40 |
41 | [StructLayout(LayoutKind.Sequential)]
42 | private struct COMM_FAULT_OFFSETS
43 | {
44 | public short CommOffset;
45 | public short FaultOffset;
46 | }
47 |
48 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1049:TypesThatOwnNativeResourcesShouldBeDisposable"), StructLayout(LayoutKind.Sequential)]
49 | private struct GENERIC_BINDING_ROUTINE_PAIR
50 | {
51 | public IntPtr Bind;
52 | public IntPtr Unbind;
53 | }
54 |
55 |
56 | [StructLayout(LayoutKind.Sequential)]
57 | private struct RPC_VERSION
58 | {
59 | public ushort MajorVersion;
60 | public ushort MinorVersion;
61 |
62 |
63 | public static readonly RPC_VERSION INTERFACE_VERSION = new RPC_VERSION() { MajorVersion = 1, MinorVersion = 0 };
64 | public static readonly RPC_VERSION SYNTAX_VERSION = new RPC_VERSION() { MajorVersion = 2, MinorVersion = 0 };
65 |
66 | public RPC_VERSION(ushort InterfaceVersionMajor, ushort InterfaceVersionMinor)
67 | {
68 | MajorVersion = InterfaceVersionMajor;
69 | MinorVersion = InterfaceVersionMinor;
70 | }
71 | }
72 |
73 | [StructLayout(LayoutKind.Sequential)]
74 | private struct RPC_SYNTAX_IDENTIFIER
75 | {
76 | public Guid SyntaxGUID;
77 | public RPC_VERSION SyntaxVersion;
78 | }
79 |
80 |
81 |
82 | [StructLayout(LayoutKind.Sequential)]
83 | private struct RPC_CLIENT_INTERFACE
84 | {
85 | public uint Length;
86 | public RPC_SYNTAX_IDENTIFIER InterfaceId;
87 | public RPC_SYNTAX_IDENTIFIER TransferSyntax;
88 | public IntPtr /*PRPC_DISPATCH_TABLE*/ DispatchTable;
89 | public uint RpcProtseqEndpointCount;
90 | public IntPtr /*PRPC_PROTSEQ_ENDPOINT*/ RpcProtseqEndpoint;
91 | public IntPtr Reserved;
92 | public IntPtr InterpreterInfo;
93 | public uint Flags;
94 |
95 | public static readonly Guid IID_SYNTAX = new Guid(0x8A885D04u, 0x1CEB, 0x11C9, 0x9F, 0xE8, 0x08, 0x00, 0x2B,
96 | 0x10,
97 | 0x48, 0x60);
98 |
99 | public RPC_CLIENT_INTERFACE(Guid iid, ushort InterfaceVersionMajor = 1, ushort InterfaceVersionMinor = 0)
100 | {
101 | Length = (uint)Marshal.SizeOf(typeof(RPC_CLIENT_INTERFACE));
102 | InterfaceId = new RPC_SYNTAX_IDENTIFIER() { SyntaxGUID = iid, SyntaxVersion = new RPC_VERSION(InterfaceVersionMajor, InterfaceVersionMinor) };
103 | TransferSyntax = new RPC_SYNTAX_IDENTIFIER() { SyntaxGUID = IID_SYNTAX, SyntaxVersion = RPC_VERSION.SYNTAX_VERSION };
104 | DispatchTable = IntPtr.Zero;
105 | RpcProtseqEndpointCount = 0u;
106 | RpcProtseqEndpoint = IntPtr.Zero;
107 | Reserved = IntPtr.Zero;
108 | InterpreterInfo = IntPtr.Zero;
109 | Flags = 0u;
110 | }
111 | }
112 |
113 | [StructLayout(LayoutKind.Sequential)]
114 | private struct MIDL_STUB_DESC
115 | {
116 | public IntPtr /*RPC_CLIENT_INTERFACE*/ RpcInterfaceInformation;
117 | public IntPtr pfnAllocate;
118 | public IntPtr pfnFree;
119 | public IntPtr pAutoBindHandle;
120 | public IntPtr /*NDR_RUNDOWN*/ apfnNdrRundownRoutines;
121 | public IntPtr /*GENERIC_BINDING_ROUTINE_PAIR*/ aGenericBindingRoutinePairs;
122 | public IntPtr /*EXPR_EVAL*/ apfnExprEval;
123 | public IntPtr /*XMIT_ROUTINE_QUINTUPLE*/ aXmitQuintuple;
124 | public IntPtr pFormatTypes;
125 | public int fCheckBounds;
126 | /* Ndr library version. */
127 | public uint Version;
128 | public IntPtr /*MALLOC_FREE_STRUCT*/ pMallocFreeStruct;
129 | public int MIDLVersion;
130 | public IntPtr CommFaultOffsets;
131 | // New fields for version 3.0+
132 | public IntPtr /*USER_MARSHAL_ROUTINE_QUADRUPLE*/ aUserMarshalQuadruple;
133 | // Notify routines - added for NT5, MIDL 5.0
134 | public IntPtr /*NDR_NOTIFY_ROUTINE*/ NotifyRoutineTable;
135 | public IntPtr mFlags;
136 | // International support routines - added for 64bit post NT5
137 | public IntPtr /*NDR_CS_ROUTINES*/ CsRoutineTables;
138 | public IntPtr ProxyServerInfo;
139 | public IntPtr /*NDR_EXPR_DESC*/ pExprInfo;
140 | // Fields up to now present in win2000 release.
141 |
142 | public MIDL_STUB_DESC(IntPtr pFormatTypesPtr, IntPtr RpcInterfaceInformationPtr,
143 | IntPtr pfnAllocatePtr, IntPtr pfnFreePtr, IntPtr aGenericBindingRoutinePairsPtr)
144 | {
145 | pFormatTypes = pFormatTypesPtr;
146 | RpcInterfaceInformation = RpcInterfaceInformationPtr;
147 | CommFaultOffsets = IntPtr.Zero;
148 | pfnAllocate = pfnAllocatePtr;
149 | pfnFree = pfnFreePtr;
150 | pAutoBindHandle = IntPtr.Zero;
151 | apfnNdrRundownRoutines = IntPtr.Zero;
152 | aGenericBindingRoutinePairs = aGenericBindingRoutinePairsPtr;
153 | apfnExprEval = IntPtr.Zero;
154 | aXmitQuintuple = IntPtr.Zero;
155 | fCheckBounds = 1;
156 | Version = 0x50002u;
157 | pMallocFreeStruct = IntPtr.Zero;
158 | MIDLVersion = 0x8000253;
159 | aUserMarshalQuadruple = IntPtr.Zero;
160 | NotifyRoutineTable = IntPtr.Zero;
161 | mFlags = new IntPtr(0x00000001);
162 | CsRoutineTables = IntPtr.Zero;
163 | ProxyServerInfo = IntPtr.Zero;
164 | pExprInfo = IntPtr.Zero;
165 | }
166 | }
167 |
168 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
169 | protected void InitializeStub(Guid interfaceID, byte[] MIDL_ProcFormatString, byte[] MIDL_TypeFormatString, string pipe, ushort MajorVerson = 1, ushort MinorVersion = 0)
170 | {
171 | this.MIDL_ProcFormatString = MIDL_ProcFormatString;
172 | this.MIDL_TypeFormatString = MIDL_TypeFormatString;
173 | PipeName = pipe;
174 | procString = GCHandle.Alloc(this.MIDL_ProcFormatString, GCHandleType.Pinned);
175 |
176 | RPC_CLIENT_INTERFACE clientinterfaceObject = new RPC_CLIENT_INTERFACE(interfaceID, MajorVerson, MinorVersion);
177 | GENERIC_BINDING_ROUTINE_PAIR bindingObject = new GENERIC_BINDING_ROUTINE_PAIR();
178 | // important: keep a reference to avoid CallbakcOnCollectedDelegate Exception
179 | BindDelegate = Bind;
180 | UnbindDelegate = Unbind;
181 | bindingObject.Bind = Marshal.GetFunctionPointerForDelegate((bind)BindDelegate);
182 | bindingObject.Unbind = Marshal.GetFunctionPointerForDelegate((unbind)UnbindDelegate);
183 |
184 | faultoffsets = GCHandle.Alloc(new COMM_FAULT_OFFSETS() { CommOffset = -1, FaultOffset = -1 }, GCHandleType.Pinned);
185 | clientinterface = GCHandle.Alloc(clientinterfaceObject, GCHandleType.Pinned);
186 | formatString = GCHandle.Alloc(MIDL_TypeFormatString, GCHandleType.Pinned);
187 | bindinghandle = GCHandle.Alloc(bindingObject, GCHandleType.Pinned);
188 |
189 | MIDL_STUB_DESC stubObject = new MIDL_STUB_DESC(formatString.AddrOfPinnedObject(),
190 | clientinterface.AddrOfPinnedObject(),
191 | Marshal.GetFunctionPointerForDelegate(AllocateMemoryDelegate),
192 | Marshal.GetFunctionPointerForDelegate(FreeMemoryDelegate),
193 | bindinghandle.AddrOfPinnedObject());
194 | rpcClientInterface = stubObject.RpcInterfaceInformation;
195 |
196 | stub = GCHandle.Alloc(stubObject, GCHandleType.Pinned);
197 | }
198 |
199 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
200 | protected void freeStub()
201 | {
202 | procString.Free();
203 | faultoffsets.Free();
204 | clientinterface.Free();
205 | formatString.Free();
206 | bindinghandle.Free();
207 | stub.Free();
208 | }
209 |
210 | delegate IntPtr allocmemory(int size);
211 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
212 | protected static IntPtr AllocateMemory(int size)
213 | {
214 | IntPtr memory = Marshal.AllocHGlobal(size);
215 | //Trace.WriteLine("allocating " + memory.ToString());
216 | return memory;
217 | }
218 |
219 | delegate void freememory(IntPtr memory);
220 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
221 | protected static void FreeMemory(IntPtr memory)
222 | {
223 | //Trace.WriteLine("freeing " + memory.ToString());
224 | Marshal.FreeHGlobal(memory);
225 | }
226 |
227 | delegate IntPtr bind(IntPtr IntPtrserver);
228 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
229 | protected IntPtr Bind (IntPtr IntPtrserver)
230 | {
231 | string server = Marshal.PtrToStringUni(IntPtrserver);
232 | IntPtr bindingstring = IntPtr.Zero;
233 | IntPtr binding = IntPtr.Zero;
234 | Int32 status;
235 |
236 | Trace.WriteLine("Binding to " + server + " " + PipeName);
237 | status = NativeMethods.RpcStringBindingCompose(null, "ncacn_np", server, PipeName, null, out bindingstring);
238 | if (status != 0)
239 | {
240 | Trace.WriteLine("RpcStringBindingCompose failed with status 0x" + status.ToString("x"));
241 | return IntPtr.Zero;
242 | }
243 | status = NativeMethods.RpcBindingFromStringBinding(Marshal.PtrToStringUni(bindingstring), out binding);
244 | NativeMethods.RpcBindingFree(ref bindingstring);
245 | if (status != 0)
246 | {
247 | Trace.WriteLine("RpcBindingFromStringBinding failed with status 0x" + status.ToString("x"));
248 | return IntPtr.Zero;
249 | }
250 | if (UseNullSession)
251 | {
252 | // note: windows xp doesn't support user or domain = "" => return 0xE
253 | NativeMethods.SEC_WINNT_AUTH_IDENTITY identity = new NativeMethods.SEC_WINNT_AUTH_IDENTITY();
254 | identity.User = "";
255 | identity.UserLength = identity.User.Length * 2;
256 | identity.Domain = "";
257 | identity.DomainLength = identity.Domain.Length * 2;
258 | identity.Password = "";
259 | identity.Flags = 2;
260 |
261 | NativeMethods.RPC_SECURITY_QOS qos = new NativeMethods.RPC_SECURITY_QOS();
262 | qos.Version = 1;
263 | qos.ImpersonationType = 3;
264 | GCHandle qoshandle = GCHandle.Alloc(qos, GCHandleType.Pinned);
265 |
266 | // 9 = negotiate , 10 = ntlm ssp
267 | status = NativeMethods.RpcBindingSetAuthInfoEx(binding, server, 0, 9, ref identity, 0, ref qos);
268 | qoshandle.Free();
269 | if (status != 0)
270 | {
271 | Trace.WriteLine("RpcBindingSetAuthInfoEx failed with status 0x" + status.ToString("x"));
272 | Unbind(IntPtrserver, binding);
273 | return IntPtr.Zero;
274 | }
275 | }
276 |
277 | status = NativeMethods.RpcBindingSetOption(binding, 12, RPCTimeOut);
278 | if (status != 0)
279 | {
280 | Trace.WriteLine("RpcBindingSetOption failed with status 0x" + status.ToString("x"));
281 | }
282 | Trace.WriteLine("binding ok (handle=" + binding + ")");
283 | return binding;
284 | }
285 |
286 | protected Int32 Bind(string server, out IntPtr binding)
287 | {
288 | IntPtr bindingstring = IntPtr.Zero;
289 | binding = IntPtr.Zero;
290 | Int32 status;
291 |
292 | status = NativeMethods.RpcStringBindingCompose(null, "ncacn_ip_tcp", server, "135", null, out bindingstring);
293 | if (status != 0)
294 | return status;
295 | status = NativeMethods.RpcBindingFromStringBinding(Marshal.PtrToStringUni(bindingstring), out binding);
296 | NativeMethods.RpcBindingFree(ref bindingstring);
297 | if (status != 0)
298 | return status;
299 |
300 | status = NativeMethods.RpcBindingSetAuthInfo(binding, null, 1, 0, IntPtr.Zero, 0);
301 | if (status != 0)
302 | {
303 | Unbind(IntPtr.Zero, binding);
304 | return status;
305 | }
306 |
307 | status = NativeMethods.RpcBindingSetOption(binding, 12, RPCTimeOut);
308 | return status;
309 | }
310 |
311 | delegate void unbind(IntPtr IntPtrserver, IntPtr hBinding);
312 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
313 | protected static void Unbind(IntPtr IntPtrserver, IntPtr hBinding)
314 | {
315 | string server = Marshal.PtrToStringUni(IntPtrserver);
316 | Trace.WriteLine("unbinding " + server);
317 | NativeMethods.RpcBindingFree(ref hBinding);
318 | }
319 |
320 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
321 | protected IntPtr GetProcStringHandle(int offset)
322 | {
323 | return Marshal.UnsafeAddrOfPinnedArrayElement(MIDL_ProcFormatString, offset);
324 | }
325 |
326 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
327 | protected IntPtr GetStubHandle()
328 | {
329 | return stub.AddrOfPinnedObject();
330 | }
331 |
332 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
333 | protected IntPtr CallNdrClientCall2x86(int offset, params IntPtr[] args)
334 | {
335 |
336 | GCHandle stackhandle = GCHandle.Alloc(args, GCHandleType.Pinned);
337 | IntPtr result;
338 | try
339 | {
340 | result = NativeMethods.NdrClientCall2x86(GetStubHandle(), GetProcStringHandle(offset), stackhandle.AddrOfPinnedObject());
341 | }
342 | finally
343 | {
344 | stackhandle.Free();
345 | }
346 | return result;
347 | }
348 |
349 | }
350 | }
351 |
--------------------------------------------------------------------------------
/RPC/samr.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Oxid Resolver. All rights reserved.
3 | //
4 | //
5 | // Licensed under the Non-Profit OSL. See LICENSE file in the project root for full license information.
6 | //
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Diagnostics;
10 | using System.Runtime.ConstrainedExecution;
11 | using System.Runtime.InteropServices;
12 | using System.Security.Permissions;
13 | using System.Security.Principal;
14 | using System.Text;
15 |
16 | namespace OxidResolver.RPC
17 | {
18 |
19 | [DebuggerDisplay("{Name}")]
20 | public class SAMR_ENUMERATION_ENTRY
21 | {
22 | public long RelativeId;
23 | public string Name;
24 | }
25 |
26 | public class samr : rpcapi
27 | {
28 |
29 | private static byte[] MIDL_ProcFormatStringx86 = new byte[] {
30 | 0x00,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x31,0x04,0x00,0x00,0x00,0x5c,0x22,0x00,0x40,0x00,0x44,0x04,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
31 | 0x0a,0x00,0x00,0x00,0x02,0x00,0x10,0x01,0x04,0x00,0x0a,0x00,0x48,0x00,0x08,0x00,0x08,0x00,0x70,0x00,0x0c,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,
32 | 0x01,0x00,0x08,0x00,0x30,0xe0,0x00,0x00,0x00,0x00,0x38,0x00,0x40,0x00,0x44,0x02,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x01,0x00,0x00,0x12,0x00,
33 | 0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x02,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,
34 | 0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x03,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,
35 | 0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x04,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
36 | 0x00,0x48,0x00,0x00,0x00,0x00,0x05,0x00,0x10,0x00,0x30,0x40,0x00,0x00,0x00,0x00,0x24,0x00,0x08,0x00,0x47,0x04,0x08,0x07,0x01,0x00,0x01,0x00,0x00,0x00,
37 | 0x08,0x00,0x00,0x00,0x16,0x00,0x0b,0x01,0x04,0x00,0x30,0x00,0x13,0x20,0x08,0x00,0x46,0x00,0x70,0x00,0x0c,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,
38 | 0x06,0x00,0x18,0x00,0x30,0x40,0x00,0x00,0x00,0x00,0x48,0x00,0x40,0x00,0x45,0x06,0x08,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x16,0x00,
39 | 0x58,0x01,0x04,0x00,0x08,0x00,0x13,0x20,0x08,0x00,0x7c,0x00,0x48,0x00,0x0c,0x00,0x08,0x00,0x50,0x21,0x10,0x00,0x08,0x00,0x70,0x00,0x14,0x00,0x08,0x00,
40 | 0x00,0x48,0x00,0x00,0x00,0x00,0x07,0x00,0x14,0x00,0x30,0x40,0x00,0x00,0x00,0x00,0x2c,0x00,0x40,0x00,0x46,0x05,0x08,0x05,0x00,0x00,0x01,0x00,0x00,0x00,
41 | 0x08,0x00,0x00,0x00,0x16,0x00,0x48,0x00,0x04,0x00,0x08,0x00,0x0b,0x01,0x08,0x00,0x6a,0x00,0x10,0x01,0x0c,0x00,0xee,0x00,0x70,0x00,0x10,0x00,0x08,0x00,
42 | 0x00,0x48,0x00,0x00,0x00,0x00,0x08,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,
43 | 0x00,0x00,0x00,0x00,0x09,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,
44 | 0x00,0x00,0x0a,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,
45 | 0x0b,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0c,0x00,
46 | 0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0d,0x00,0x1c,0x00,
47 | 0x30,0x40,0x00,0x00,0x00,0x00,0x50,0x00,0x40,0x00,0x45,0x07,0x08,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x16,0x00,0x58,0x01,0x04,0x00,
48 | 0x08,0x00,0x48,0x00,0x08,0x00,0x08,0x00,0x13,0x20,0x0c,0x00,0x7c,0x00,0x48,0x00,0x10,0x00,0x08,0x00,0x50,0x21,0x14,0x00,0x08,0x00,0x70,0x00,0x18,0x00,
49 | 0x08,0x00,0x00
50 | };
51 |
52 | private static byte[] MIDL_ProcFormatStringx64 = new byte[] {
53 | 0x00,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x31,0x08,0x00,0x00,0x00,0x5c,0x22,0x00,0x40,0x00,0x44,0x04,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
54 | 0x00,0x00,0x0a,0x00,0x00,0x00,0x02,0x00,0x10,0x01,0x08,0x00,0x0a,0x00,0x48,0x00,0x10,0x00,0x08,0x00,0x70,0x00,0x18,0x00,0x08,0x00,0x00,0x48,0x00,0x00,
55 | 0x00,0x00,0x01,0x00,0x10,0x00,0x30,0xe0,0x00,0x00,0x00,0x00,0x38,0x00,0x40,0x00,0x44,0x02,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x01,
56 | 0x00,0x00,0x12,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x02,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,
57 | 0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x03,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,
58 | 0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x04,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,
59 | 0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x05,0x00,0x20,0x00,0x30,0x40,0x00,0x00,0x00,0x00,0x24,0x00,0x08,0x00,
60 | 0x47,0x04,0x0a,0x07,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x16,0x00,0x0b,0x01,0x08,0x00,0x30,0x00,0x13,0x20,0x10,0x00,0x42,0x00,
61 | 0x70,0x00,0x18,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x06,0x00,0x30,0x00,0x30,0x40,0x00,0x00,0x00,0x00,0x48,0x00,0x40,0x00,0x45,0x06,0x0a,0x03,
62 | 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x16,0x00,0x58,0x01,0x08,0x00,0x08,0x00,0x13,0x20,0x10,0x00,0x78,0x00,0x48,0x00,0x18,0x00,
63 | 0x08,0x00,0x50,0x21,0x20,0x00,0x08,0x00,0x70,0x00,0x28,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x07,0x00,0x28,0x00,0x30,0x40,0x00,0x00,0x00,0x00,
64 | 0x2c,0x00,0x40,0x00,0x46,0x05,0x0a,0x05,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x16,0x00,0x48,0x00,0x08,0x00,0x08,0x00,0x0b,0x01,
65 | 0x10,0x00,0x66,0x00,0x10,0x01,0x18,0x00,0xc2,0x00,0x70,0x00,0x20,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x32,0x00,0x00,0x00,
66 | 0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x09,0x00,0x08,0x00,0x32,0x00,0x00,0x00,
67 | 0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0a,0x00,0x08,0x00,0x32,0x00,0x00,0x00,
68 | 0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0b,0x00,0x08,0x00,0x32,0x00,0x00,0x00,
69 | 0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0c,0x00,0x08,0x00,0x32,0x00,0x00,0x00,
70 | 0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0d,0x00,0x38,0x00,0x30,0x40,0x00,0x00,
71 | 0x00,0x00,0x50,0x00,0x40,0x00,0x45,0x07,0x0a,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x16,0x00,0x58,0x01,0x08,0x00,0x08,0x00,
72 | 0x48,0x00,0x10,0x00,0x08,0x00,0x13,0x20,0x18,0x00,0x78,0x00,0x48,0x00,0x20,0x00,0x08,0x00,0x50,0x21,0x28,0x00,0x08,0x00,0x70,0x00,0x30,0x00,0x08,0x00,
73 | 0x00
74 | };
75 |
76 | private static byte[] MIDL_TypeFormatStringx86 = new byte[] {
77 | 0x00,0x00,0x12,0x08,0x05,0x5c,0x11,0x04,0x02,0x00,0x30,0xa0,0x00,0x00,0x11,0x04,0x02,0x00,0x30,0xe1,0x00,0x00,0x30,0x41,0x00,0x00,0x11,0x00,0x14,0x00,
78 | 0x1c,0x01,0x02,0x00,0x17,0x55,0x02,0x00,0x01,0x00,0x17,0x55,0x00,0x00,0x01,0x00,0x05,0x5b,0x16,0x03,0x08,0x00,0x4b,0x5c,0x46,0x5c,0x04,0x00,0x04,0x00,
79 | 0x12,0x00,0xe0,0xff,0x5b,0x06,0x06,0x08,0x5c,0x5b,0x11,0x14,0x02,0x00,0x12,0x00,0x1e,0x00,0x1d,0x00,0x06,0x00,0x01,0x5b,0x15,0x00,0x06,0x00,0x4c,0x00,
80 | 0xf4,0xff,0x5c,0x5b,0x1b,0x03,0x04,0x00,0x04,0x00,0xf9,0xff,0x01,0x00,0x08,0x5b,0x17,0x03,0x08,0x00,0xf0,0xff,0x02,0x02,0x4c,0x00,0xe0,0xff,0x5c,0x5b,
81 | 0x11,0x08,0x08,0x5c,0x11,0x14,0x02,0x00,0x12,0x00,0x4c,0x00,0x1c,0x01,0x02,0x00,0x17,0x55,0x06,0x00,0x01,0x00,0x17,0x55,0x04,0x00,0x01,0x00,0x05,0x5b,
82 | 0x16,0x03,0x0c,0x00,0x4b,0x5c,0x46,0x5c,0x08,0x00,0x08,0x00,0x12,0x00,0xe0,0xff,0x5b,0x08,0x06,0x06,0x08,0x5b,0x1b,0x03,0x0c,0x00,0x19,0x00,0x00,0x00,
83 | 0x01,0x00,0x4b,0x5c,0x48,0x49,0x0c,0x00,0x00,0x00,0x01,0x00,0x08,0x00,0x08,0x00,0x12,0x00,0xbe,0xff,0x5b,0x4c,0x00,0xcb,0xff,0x5b,0x16,0x03,0x08,0x00,
84 | 0x4b,0x5c,0x46,0x5c,0x04,0x00,0x04,0x00,0x12,0x00,0xd0,0xff,0x5b,0x08,0x08,0x5b,0x11,0x0c,0x08,0x5c,0x11,0x00,0x82,0xff,0x11,0x04,0x02,0x00,0x30,0xa0,
85 | 0x00,0x01,0x00
86 | };
87 |
88 | private static byte[] MIDL_TypeFormatStringx64 = new byte[] {
89 | 0x00,0x00,0x12,0x08,0x05,0x5c,0x11,0x04,0x02,0x00,0x30,0xa0,0x00,0x00,0x11,0x04,0x02,0x00,0x30,0xe1,0x00,0x00,0x30,0x41,0x00,0x00,0x11,0x00,0x14,0x00,
90 | 0x1c,0x01,0x02,0x00,0x17,0x55,0x02,0x00,0x01,0x00,0x17,0x55,0x00,0x00,0x01,0x00,0x05,0x5b,0x1a,0x03,0x10,0x00,0x00,0x00,0x08,0x00,0x06,0x06,0x40,0x36,
91 | 0x5c,0x5b,0x12,0x00,0xde,0xff,0x11,0x14,0x02,0x00,0x12,0x00,0x1e,0x00,0x1d,0x00,0x06,0x00,0x01,0x5b,0x15,0x00,0x06,0x00,0x4c,0x00,0xf4,0xff,0x5c,0x5b,
92 | 0x1b,0x03,0x04,0x00,0x04,0x00,0xf9,0xff,0x01,0x00,0x08,0x5b,0x17,0x03,0x08,0x00,0xf0,0xff,0x02,0x02,0x4c,0x00,0xe0,0xff,0x5c,0x5b,0x11,0x08,0x08,0x5c,
93 | 0x11,0x14,0x02,0x00,0x12,0x00,0x28,0x00,0x1a,0x03,0x18,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x4c,0x00,0xa4,0xff,0x5c,0x5b,0x21,0x03,0x00,0x00,0x19,0x00,
94 | 0x00,0x00,0x01,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x4c,0x00,0xde,0xff,0x5c,0x5b,0x1a,0x03,0x10,0x00,0x00,0x00,0x06,0x00,0x08,0x40,0x36,0x5b,0x12,0x00,
95 | 0xdc,0xff,0x11,0x0c,0x08,0x5c,0x11,0x00,0xaa,0xff,0x11,0x04,0x02,0x00,0x30,0xa0,0x00,0x01,0x00
96 | };
97 |
98 | [StructLayout(LayoutKind.Sequential)]
99 | private struct SAMPR_ENUMERATION_BUFFER
100 | {
101 | public UInt32 EntriesRead;
102 | public IntPtr Buffer;
103 | };
104 |
105 | [StructLayout(LayoutKind.Sequential)]
106 | private struct SAMPR_RID_ENUMERATION
107 | {
108 | public IntPtr RelativeId;
109 | public UInt16 Length;
110 | public UInt16 MaximumLength;
111 | public IntPtr buffer;
112 | };
113 |
114 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
115 | public samr()
116 | {
117 | Guid interfaceId = new Guid("12345778-1234-ABCD-EF00-0123456789AC");
118 | if (IntPtr.Size == 8)
119 | {
120 | InitializeStub(interfaceId, MIDL_ProcFormatStringx64, MIDL_TypeFormatStringx64, "\\pipe\\samr");
121 | }
122 | else
123 | {
124 | InitializeStub(interfaceId, MIDL_ProcFormatStringx86, MIDL_TypeFormatStringx86, "\\pipe\\samr");
125 | }
126 | UseNullSession = true;
127 | }
128 |
129 | [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
130 | ~samr()
131 | {
132 | freeStub();
133 | }
134 |
135 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
136 | public Int32 SamrConnect(string server, out IntPtr ServerHandle, UInt32 DesiredAccess)
137 | {
138 | IntPtr intptrServer = Marshal.StringToHGlobalUni(server);
139 |
140 | ServerHandle = IntPtr.Zero;
141 | IntPtr result = IntPtr.Zero;
142 | try
143 | {
144 | ServerHandle = IntPtr.Zero;
145 | if (IntPtr.Size == 8)
146 | {
147 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(0), intptrServer, out ServerHandle, DesiredAccess);
148 | }
149 | else
150 | {
151 | IntPtr tempValue = new IntPtr();
152 | GCHandle handle = GCHandle.Alloc(tempValue, GCHandleType.Pinned);
153 | IntPtr tempValuePointer = handle.AddrOfPinnedObject();
154 | try
155 | {
156 | result = CallNdrClientCall2x86(0, intptrServer, tempValuePointer, new IntPtr((int)DesiredAccess));
157 | // each pinvoke work on a copy of the arguments (without an out specifier)
158 | // get back the data
159 | ServerHandle = Marshal.ReadIntPtr(tempValuePointer);
160 | }
161 | finally
162 | {
163 | handle.Free();
164 | }
165 | }
166 | }
167 | catch (SEHException)
168 | {
169 | Trace.WriteLine("SamrConnect failed 0x" + Marshal.GetExceptionCode().ToString("x"));
170 | return Marshal.GetExceptionCode();
171 | }
172 | finally
173 | {
174 | if (intptrServer != IntPtr.Zero)
175 | Marshal.FreeHGlobal(intptrServer);
176 | }
177 | return (int) result.ToInt64();
178 | }
179 |
180 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
181 | public Int32 SamrCloseHandle(ref IntPtr ServerHandle)
182 | {
183 | IntPtr result = IntPtr.Zero;
184 | try
185 | {
186 | if (IntPtr.Size == 8)
187 | {
188 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(56), ref ServerHandle);
189 | }
190 | else
191 | {
192 | IntPtr tempValue = ServerHandle;
193 | GCHandle handle = GCHandle.Alloc(tempValue, GCHandleType.Pinned);
194 | IntPtr tempValuePointer = handle.AddrOfPinnedObject();
195 | try
196 | {
197 | result = CallNdrClientCall2x86(54, tempValuePointer);
198 | // each pinvoke work on a copy of the arguments (without an out specifier)
199 | // get back the data
200 | ServerHandle = Marshal.ReadIntPtr(tempValuePointer);
201 | }
202 | finally
203 | {
204 | handle.Free();
205 | }
206 | }
207 | }
208 | catch (SEHException)
209 | {
210 | Trace.WriteLine("SamrCloseHandle failed 0x" + Marshal.GetExceptionCode().ToString("x"));
211 | return Marshal.GetExceptionCode();
212 | }
213 | return (int) result.ToInt64();
214 | }
215 |
216 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
217 | public Int32 SamrEnumerateDomainsInSamServer(IntPtr ServerHandle, ref IntPtr EnumerationContext,
218 | out SAMR_ENUMERATION_ENTRY[] Buffer, UInt32 PreferedMaximumLength, out UInt32 CountReturned)
219 | {
220 | IntPtr result = IntPtr.Zero;
221 | CountReturned = 0;
222 | try
223 | {
224 | IntPtr IntptrBuffer = IntPtr.Zero;
225 | if (IntPtr.Size == 8)
226 | {
227 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(246), ServerHandle, ref EnumerationContext, out IntptrBuffer, PreferedMaximumLength, out CountReturned);
228 | }
229 | else
230 | {
231 | IntPtr tempValue1 = EnumerationContext;
232 | GCHandle handle1 = GCHandle.Alloc(tempValue1, GCHandleType.Pinned);
233 | IntPtr tempValuePointer1 = handle1.AddrOfPinnedObject();
234 | IntPtr tempValue2 = IntPtr.Zero;
235 | GCHandle handle2 = GCHandle.Alloc(tempValue2, GCHandleType.Pinned);
236 | IntPtr tempValuePointer2 = handle2.AddrOfPinnedObject();
237 | IntPtr tempValue3 = IntPtr.Zero;
238 | GCHandle handle3 = GCHandle.Alloc(tempValue3, GCHandleType.Pinned);
239 | IntPtr tempValuePointer3 = handle3.AddrOfPinnedObject();
240 | try
241 | {
242 | result = CallNdrClientCall2x86(234, ServerHandle, tempValuePointer1, tempValuePointer2, new IntPtr(PreferedMaximumLength), tempValuePointer3);
243 | // each pinvoke work on a copy of the arguments (without an out specifier)
244 | // get back the data
245 | EnumerationContext = Marshal.ReadIntPtr(tempValuePointer1);
246 | IntptrBuffer = Marshal.ReadIntPtr(tempValuePointer2);
247 | CountReturned = (UInt32)Marshal.ReadInt32(tempValuePointer3);
248 | }
249 | finally
250 | {
251 | handle1.Free();
252 | handle2.Free();
253 | handle3.Free();
254 | }
255 | }
256 | Buffer = Unmarshal_SAMR_ENUMRATION(IntptrBuffer);
257 | }
258 | catch (SEHException)
259 | {
260 | Buffer = null;
261 | Trace.WriteLine("SamrEnumerateDomainsInSamServer failed 0x" + Marshal.GetExceptionCode().ToString("x"));
262 | return Marshal.GetExceptionCode();
263 | }
264 | return (int) result.ToInt64();
265 | }
266 |
267 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
268 | private SAMR_ENUMERATION_ENTRY[] Unmarshal_SAMR_ENUMRATION(IntPtr IntptrBuffer)
269 | {
270 | if (IntptrBuffer == IntPtr.Zero)
271 | return null;
272 | SAMPR_ENUMERATION_BUFFER Buffer = (SAMPR_ENUMERATION_BUFFER) Marshal.PtrToStructure(IntptrBuffer, typeof(SAMPR_ENUMERATION_BUFFER));
273 |
274 | SAMR_ENUMERATION_ENTRY[] output = new SAMR_ENUMERATION_ENTRY[Buffer.EntriesRead];
275 | int size = Marshal.SizeOf(typeof(SAMPR_RID_ENUMERATION));
276 | for (int i = 0; i < (int)Buffer.EntriesRead; i++)
277 | {
278 | output[i] = new SAMR_ENUMERATION_ENTRY();
279 | SAMPR_RID_ENUMERATION ridenumaration = (SAMPR_RID_ENUMERATION)Marshal.PtrToStructure(new IntPtr(Buffer.Buffer.ToInt64() + size * i), typeof(SAMPR_RID_ENUMERATION));
280 | output[i].RelativeId = ridenumaration.RelativeId.ToInt64();
281 | output[i].Name = Marshal.PtrToStringUni(ridenumaration.buffer, ridenumaration.Length/2);
282 | if (ridenumaration.buffer != IntPtr.Zero && ridenumaration.MaximumLength > 0)
283 | FreeMemory(ridenumaration.buffer);
284 | }
285 | if (Buffer.Buffer != IntPtr.Zero)
286 | FreeMemory(Buffer.Buffer);
287 | FreeMemory(IntptrBuffer);
288 | return output;
289 | }
290 |
291 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
292 | public Int32 SamrLookupDomainInSamServer(IntPtr ServerHandle, string Name, out SecurityIdentifier DomainId)
293 | {
294 | IntPtr result = IntPtr.Zero;
295 | DomainId = null;
296 | IntPtr sid = IntPtr.Zero;
297 | using (var NameString = new OxidResolver.NativeMethods.UNICODE_STRING())
298 | {
299 | try
300 | {
301 | NameString.Initialize(Name);
302 | if (IntPtr.Size == 8)
303 | {
304 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(190), ServerHandle, NameString, out sid);
305 | }
306 | else
307 | {
308 | GCHandle handle1 = GCHandle.Alloc(NameString, GCHandleType.Pinned);
309 | IntPtr tempValuePointer1 = handle1.AddrOfPinnedObject();
310 | IntPtr tempValue2 = sid;
311 | GCHandle handle2 = GCHandle.Alloc(tempValue2, GCHandleType.Pinned);
312 | IntPtr tempValuePointer2 = handle2.AddrOfPinnedObject();
313 | try
314 | {
315 | result = CallNdrClientCall2x86(180, ServerHandle, tempValuePointer1, tempValuePointer2);
316 | // each pinvoke work on a copy of the arguments (without an out specifier)
317 | // get back the data
318 | sid = Marshal.ReadIntPtr(tempValuePointer2);
319 | }
320 | finally
321 | {
322 | handle1.Free();
323 | handle2.Free();
324 | }
325 | }
326 | DomainId = new SecurityIdentifier(sid);
327 | FreeMemory(sid);
328 | }
329 | catch (SEHException)
330 | {
331 | Trace.WriteLine("SamrLookupDomainInSamServer failed 0x" + Marshal.GetExceptionCode().ToString("x"));
332 | return Marshal.GetExceptionCode();
333 | }
334 | }
335 | return (int) result.ToInt64();
336 | }
337 |
338 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
339 | public Int32 SamrOpenDomain(IntPtr ServerHandle, Int32 DesiredAccess, SecurityIdentifier DomainId, out IntPtr DomainHandle)
340 | {
341 | IntPtr result = IntPtr.Zero;
342 | DomainHandle = IntPtr.Zero;
343 | try
344 | {
345 | byte[] sid = new byte[DomainId.BinaryLength];
346 | DomainId.GetBinaryForm(sid, 0);
347 | if (IntPtr.Size == 8)
348 | {
349 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(314), ServerHandle, DesiredAccess, sid, out DomainHandle);
350 | }
351 | else
352 | {
353 | GCHandle handle1 = GCHandle.Alloc(sid, GCHandleType.Pinned);
354 | IntPtr tempValuePointer1 = handle1.AddrOfPinnedObject();
355 | IntPtr tempValue2 = IntPtr.Zero;
356 | GCHandle handle2 = GCHandle.Alloc(tempValue2, GCHandleType.Pinned);
357 | IntPtr tempValuePointer2 = handle2.AddrOfPinnedObject();
358 | try
359 | {
360 | result = CallNdrClientCall2x86(300, ServerHandle, new IntPtr(DesiredAccess), tempValuePointer1, tempValuePointer2);
361 | // each pinvoke work on a copy of the arguments (without an out specifier)
362 | // get back the data
363 | DomainHandle = Marshal.ReadIntPtr(tempValuePointer2);
364 | }
365 | finally
366 | {
367 | handle1.Free();
368 | handle2.Free();
369 | }
370 | }
371 | }
372 | catch (SEHException)
373 | {
374 | Trace.WriteLine("SamrOpenDomain failed 0x" + Marshal.GetExceptionCode().ToString("x"));
375 | return Marshal.GetExceptionCode();
376 | }
377 | return (int) result.ToInt64();
378 | }
379 |
380 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
381 | public Int32 SamrEnumerateUsersInDomain(IntPtr DomainHandle, ref IntPtr EnumerationContext, Int32 UserAccountControl,
382 | out SAMR_ENUMERATION_ENTRY[] Buffer, Int32 PreferedMaximumLength, out UInt32 CountReturned)
383 | {
384 | IntPtr result = IntPtr.Zero;
385 | CountReturned = 0;
386 | try
387 | {
388 | IntPtr IntptrBuffer = IntPtr.Zero;
389 | if (IntPtr.Size == 8)
390 | {
391 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(526), DomainHandle, ref EnumerationContext, UserAccountControl, out IntptrBuffer, PreferedMaximumLength, ref CountReturned);
392 | }
393 | else
394 | {
395 | IntPtr tempValue1 = EnumerationContext;
396 | GCHandle handle1 = GCHandle.Alloc(tempValue1, GCHandleType.Pinned);
397 | IntPtr tempValuePointer1 = handle1.AddrOfPinnedObject();
398 | IntPtr tempValue2 = IntPtr.Zero;
399 | GCHandle handle2 = GCHandle.Alloc(tempValue2, GCHandleType.Pinned);
400 | IntPtr tempValuePointer2 = handle2.AddrOfPinnedObject();
401 | IntPtr tempValue3 = IntPtr.Zero;
402 | GCHandle handle3 = GCHandle.Alloc(tempValue3, GCHandleType.Pinned);
403 | IntPtr tempValuePointer3 = handle3.AddrOfPinnedObject();
404 | try
405 | {
406 | result = CallNdrClientCall2x86(500, DomainHandle, tempValuePointer1, new IntPtr(UserAccountControl), tempValuePointer2, new IntPtr(PreferedMaximumLength), tempValuePointer3);
407 | // each pinvoke work on a copy of the arguments (without an out specifier)
408 | // get back the data
409 | EnumerationContext = Marshal.ReadIntPtr(tempValuePointer1);
410 | IntptrBuffer = Marshal.ReadIntPtr(tempValuePointer2);
411 | CountReturned = (UInt32)Marshal.ReadInt32(tempValuePointer3);
412 | }
413 | finally
414 | {
415 | handle1.Free();
416 | handle2.Free();
417 | handle3.Free();
418 | }
419 | }
420 | Buffer = Unmarshal_SAMR_ENUMRATION(IntptrBuffer);
421 | }
422 | catch (SEHException)
423 | {
424 | Buffer = null;
425 | Trace.WriteLine("SamrEnumerateUsersInDomain failed 0x" + Marshal.GetExceptionCode().ToString("x"));
426 | return Marshal.GetExceptionCode();
427 | }
428 | return (int) result.ToInt64();
429 | }
430 | }
431 | }
432 |
--------------------------------------------------------------------------------
/RPC/spool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Runtime.InteropServices;
5 | using System.Security.Permissions;
6 | using System.Text;
7 |
8 | namespace OxidResolver.RPC
9 | {
10 | public class rprn : rpcapi
11 | {
12 | private static byte[] MIDL_ProcFormatStringx86 = new byte[] {
13 | 0x00,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,
14 | 0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x31,0x04,0x00,0x00,0x00,0x5c,0x08,0x00,0x40,0x00,0x46,0x06,0x08,0x05,
15 | 0x00,0x00,0x01,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x02,0x00,0x10,0x01,0x04,0x00,0x0a,0x00,0x0b,0x00,0x08,0x00,0x02,0x00,0x0b,0x01,0x0c,0x00,0x1e,
16 | 0x00,0x48,0x00,0x10,0x00,0x08,0x00,0x70,0x00,0x14,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x02,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,
17 | 0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x03,0x00,0x08,0x00,0x32,
18 | 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,
19 | 0x04,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,
20 | 0x48,0x00,0x00,0x00,0x00,0x05,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,
21 | 0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x06,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,
22 | 0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x07,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,
23 | 0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,
24 | 0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x09,0x00,0x08,0x00,
25 | 0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,
26 | 0x00,0x0a,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,
27 | 0x00,0x48,0x00,0x00,0x00,0x00,0x0b,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,
28 | 0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0c,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,
29 | 0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0d,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,
30 | 0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0e,0x00,0x08,0x00,0x32,0x00,0x00,0x00,
31 | 0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0f,0x00,0x08,
32 | 0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,
33 | 0x00,0x00,0x10,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,
34 | 0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x11,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
35 | 0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x12,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,
36 | 0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x13,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,
37 | 0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x14,0x00,0x08,0x00,0x32,0x00,0x00,
38 | 0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x15,0x00,
39 | 0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,
40 | 0x00,0x00,0x00,0x16,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,
41 | 0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x17,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,
42 | 0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x18,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,
43 | 0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x19,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,
44 | 0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x1a,0x00,0x08,0x00,0x32,0x00,
45 | 0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x1b,
46 | 0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,
47 | 0x00,0x00,0x00,0x00,0x1c,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,
48 | 0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x1d,0x00,0x08,0x00,0x30,0xe0,0x00,0x00,0x00,0x00,0x38,0x00,0x40,0x00,0x44,0x02,0x08,0x01,0x00,0x00,
49 | 0x00,0x00,0x00,0x00,0x18,0x01,0x00,0x00,0x36,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x1e,0x00,0x08,0x00,0x32,0x00,0x00,
50 | 0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x1f,0x00,
51 | 0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,
52 | 0x00,0x00,0x00,0x20,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,
53 | 0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x21,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,
54 | 0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x22,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,
55 | 0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x23,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,
56 | 0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x24,0x00,0x08,0x00,0x32,0x00,
57 | 0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x25,
58 | 0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x26,0x00,
59 | 0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x27,0x00,0x08,
60 | 0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,
61 | 0x00,0x00,0x28,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,
62 | 0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x29,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
63 | 0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2a,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,
64 | 0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
65 | 0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2c,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,
66 | 0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2d,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,
67 | 0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2e,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,
68 | 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2f,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,
69 | 0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x30,0x00,0x08,0x00,0x32,
70 | 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,
71 | 0x31,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x32,
72 | 0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x33,0x00,
73 | 0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,
74 | 0x00,0x00,0x00,0x34,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,
75 | 0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x35,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,
76 | 0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x36,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,
77 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x37,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,
78 | 0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x38,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,
79 | 0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x39,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,
80 | 0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x3a,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,
81 | 0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x3b,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,
82 | 0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x3c,0x00,0x08,0x00,
83 | 0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,
84 | 0x00,0x3d,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x08,0x00,
85 | 0x00,0x48,0x00,0x00,0x00,0x00,0x3e,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x70,
86 | 0x00,0x04,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x3f,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,
87 | 0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x40,0x00,0x04,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x01,0x00,0x00,0x00,
88 | 0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x41,0x00,0x1c,0x00,0x30,0x40,0x00,0x00,0x00,0x00,0x3c,0x00,0x08,0x00,0x46,0x07,0x08,0x05,0x00,0x00,
89 | 0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x3a,0x00,0x48,0x00,0x04,0x00,0x08,0x00,0x48,0x00,0x08,0x00,0x08,0x00,0x0b,0x00,0x0c,0x00,0x02,0x00,0x48,
90 | 0x00,0x10,0x00,0x08,0x00,0x0b,0x00,0x14,0x00,0x3e,0x00,0x70,0x00,0x18,0x00,0x08,0x00,0x00
91 | };
92 |
93 | private static byte[] MIDL_ProcFormatStringx64 = new byte[] {
94 | 0x00,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
95 | 0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x01,0x00,0x30,0x00,0x31,0x08,0x00,0x00,0x00,0x5c,0x08,0x00,0x40,0x00,0x46,0x06,
96 | 0x0a,0x05,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x02,0x00,0x10,0x01,0x08,0x00,0x0a,0x00,0x0b,0x00,0x10,0x00,0x02,0x00,0x0b,
97 | 0x01,0x18,0x00,0x1e,0x00,0x48,0x00,0x20,0x00,0x08,0x00,0x70,0x00,0x28,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x02,0x00,0x10,0x00,0x32,0x00,
98 | 0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,
99 | 0x00,0x03,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,
100 | 0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x04,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,
101 | 0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x05,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,
102 | 0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x06,0x00,0x10,0x00,0x32,0x00,0x00,
103 | 0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,
104 | 0x07,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,
105 | 0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x08,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
106 | 0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x09,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,
107 | 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0a,0x00,0x10,0x00,0x32,0x00,0x00,0x00,
108 | 0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0b,
109 | 0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,
110 | 0x00,0x48,0x00,0x00,0x00,0x00,0x0c,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
111 | 0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0d,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,
112 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0e,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,
113 | 0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x0f,0x00,
114 | 0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,
115 | 0x48,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
116 | 0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x11,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,
117 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x12,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,
118 | 0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x13,0x00,0x10,
119 | 0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,
120 | 0x00,0x00,0x00,0x00,0x14,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,
121 | 0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x15,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,
122 | 0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x16,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,
123 | 0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x17,0x00,0x10,0x00,
124 | 0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,
125 | 0x00,0x00,0x00,0x18,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,
126 | 0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x19,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,
127 | 0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x1a,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,
128 | 0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x1b,0x00,0x10,0x00,0x32,
129 | 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,
130 | 0x00,0x00,0x1c,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,
131 | 0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x1d,0x00,0x10,0x00,0x30,0xe0,0x00,0x00,0x00,0x00,0x38,0x00,0x40,0x00,0x44,0x02,0x0a,0x01,0x00,0x00,
132 | 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x01,0x00,0x00,0x32,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x1e,0x00,0x10,0x00,0x32,
133 | 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,
134 | 0x00,0x00,0x1f,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,
135 | 0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x20,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,
136 | 0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x21,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,
137 | 0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x22,0x00,0x10,0x00,0x32,0x00,
138 | 0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,
139 | 0x00,0x23,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,
140 | 0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x24,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,
141 | 0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x25,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,
142 | 0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x26,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,
143 | 0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x27,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,
144 | 0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x28,0x00,0x10,0x00,0x32,
145 | 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,
146 | 0x00,0x00,0x29,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,
147 | 0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2a,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,
148 | 0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2b,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,
149 | 0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2c,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
150 | 0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2d,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,
151 | 0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2e,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,
152 | 0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x2f,0x00,0x10,
153 | 0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,
154 | 0x00,0x00,0x00,0x00,0x30,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,
155 | 0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x31,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,
156 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x32,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,
157 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x33,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,
158 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x34,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,
159 | 0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x35,0x00,
160 | 0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,
161 | 0x48,0x00,0x00,0x00,0x00,0x36,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
162 | 0x00,0x48,0x00,0x00,0x00,0x00,0x37,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
163 | 0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x38,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
164 | 0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x39,0x00,0x08,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x0a,
165 | 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x3a,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,
166 | 0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x3b,0x00,0x10,0x00,0x32,0x00,0x00,
167 | 0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,
168 | 0x3c,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,
169 | 0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x3d,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
170 | 0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x3e,0x00,0x10,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x44,0x01,0x0a,
171 | 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x08,0x00,0x08,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x3f,0x00,0x08,0x00,0x32,0x00,0x00,0x00,
172 | 0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x40,0x00,0x08,0x00,0x32,0x00,0x00,
173 | 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x0a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x41,0x00,0x38,0x00,0x30,0x40,
174 | 0x00,0x00,0x00,0x00,0x3c,0x00,0x08,0x00,0x46,0x07,0x0a,0x05,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x36,0x00,0x48,0x00,0x08,
175 | 0x00,0x08,0x00,0x48,0x00,0x10,0x00,0x08,0x00,0x0b,0x00,0x18,0x00,0x02,0x00,0x48,0x00,0x20,0x00,0x08,0x00,0x0b,0x00,0x28,0x00,0x3a,0x00,0x70,0x00,
176 | 0x30,0x00,0x08,0x00,0x00
177 |
178 | };
179 |
180 | private static byte[] MIDL_TypeFormatStringx86 = new byte[] {
181 | 0x00,0x00,0x12,0x08,0x25,0x5c,0x11,0x04,0x02,0x00,0x30,0xa0,0x00,0x00,0x11,0x00,0x0e,0x00,0x1b,0x00,0x01,0x00,0x19,0x00,0x00,0x00,0x01,0x00,0x01,
182 | 0x5b,0x16,0x03,0x08,0x00,0x4b,0x5c,0x46,0x5c,0x04,0x00,0x04,0x00,0x12,0x00,0xe6,0xff,0x5b,0x08,0x08,0x5b,0x11,0x04,0x02,0x00,0x30,0xe1,0x00,0x00,
183 | 0x30,0x41,0x00,0x00,0x12,0x00,0x48,0x00,0x1b,0x01,0x02,0x00,0x19,0x00,0x0c,0x00,0x01,0x00,0x06,0x5b,0x16,0x03,0x14,0x00,0x4b,0x5c,0x46,0x5c,0x10,
184 | 0x00,0x10,0x00,0x12,0x00,0xe6,0xff,0x5b,0x06,0x06,0x08,0x08,0x08,0x08,0x5b,0x1b,0x03,0x14,0x00,0x19,0x00,0x08,0x00,0x01,0x00,0x4b,0x5c,0x48,0x49,
185 | 0x14,0x00,0x00,0x00,0x01,0x00,0x10,0x00,0x10,0x00,0x12,0x00,0xc2,0xff,0x5b,0x4c,0x00,0xc9,0xff,0x5b,0x16,0x03,0x10,0x00,0x4b,0x5c,0x46,0x5c,0x0c,
186 | 0x00,0x0c,0x00,0x12,0x00,0xd0,0xff,0x5b,0x08,0x08,0x08,0x08,0x5b,0x00
187 | };
188 |
189 | private static byte[] MIDL_TypeFormatStringx64 = new byte[] {
190 | 0x00,0x00,0x12,0x08,0x25,0x5c,0x11,0x04,0x02,0x00,0x30,0xa0,0x00,0x00,0x11,0x00,0x0e,0x00,0x1b,0x00,0x01,0x00,0x19,0x00,0x00,0x00,0x01,0x00,0x01,
191 | 0x5b,0x1a,0x03,0x10,0x00,0x00,0x00,0x06,0x00,0x08,0x40,0x36,0x5b,0x12,0x00,0xe6,0xff,0x11,0x04,0x02,0x00,0x30,0xe1,0x00,0x00,0x30,0x41,0x00,0x00,
192 | 0x12,0x00,0x38,0x00,0x1b,0x01,0x02,0x00,0x19,0x00,0x0c,0x00,0x01,0x00,0x06,0x5b,0x1a,0x03,0x18,0x00,0x00,0x00,0x0a,0x00,0x06,0x06,0x08,0x08,0x08,
193 | 0x36,0x5c,0x5b,0x12,0x00,0xe2,0xff,0x21,0x03,0x00,0x00,0x19,0x00,0x08,0x00,0x01,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x4c,0x00,0xda,0xff,0x5c,0x5b,
194 | 0x1a,0x03,0x18,0x00,0x00,0x00,0x08,0x00,0x08,0x08,0x08,0x40,0x36,0x5b,0x12,0x00,0xda,0xff,0x00
195 | };
196 |
197 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
198 | public rprn()
199 | {
200 | Guid interfaceId = new Guid("12345678-1234-ABCD-EF00-0123456789AB");
201 | if (IntPtr.Size == 8)
202 | {
203 | InitializeStub(interfaceId, MIDL_ProcFormatStringx64, MIDL_TypeFormatStringx64, "\\pipe\\spoolss");
204 | }
205 | else
206 | {
207 | InitializeStub(interfaceId, MIDL_ProcFormatStringx86, MIDL_TypeFormatStringx86, "\\pipe\\spoolss");
208 | }
209 | }
210 |
211 | [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
212 | ~rprn()
213 | {
214 | freeStub();
215 | }
216 |
217 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
218 | public struct DEVMODE_CONTAINER
219 | {
220 | Int32 cbBuf;
221 | IntPtr pDevMode;
222 | }
223 |
224 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
225 | public struct RPC_V2_NOTIFY_OPTIONS_TYPE
226 | {
227 | UInt16 Type;
228 | UInt16 Reserved0;
229 | UInt32 Reserved1;
230 | UInt32 Reserved2;
231 | UInt32 Count;
232 | IntPtr pFields;
233 | };
234 |
235 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
236 | public struct RPC_V2_NOTIFY_OPTIONS
237 | {
238 | UInt32 Version;
239 | UInt32 Reserved;
240 | UInt32 Count;
241 | /* [unique][size_is] */
242 | RPC_V2_NOTIFY_OPTIONS_TYPE pTypes;
243 | };
244 |
245 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
246 | public Int32 RpcOpenPrinter(string pPrinterName, out IntPtr pHandle, string pDatatype, ref DEVMODE_CONTAINER pDevModeContainer, Int32 AccessRequired)
247 | {
248 | IntPtr result = IntPtr.Zero;
249 | IntPtr intptrPrinterName = Marshal.StringToHGlobalUni(pPrinterName);
250 | IntPtr intptrDatatype = Marshal.StringToHGlobalUni(pDatatype);
251 | pHandle = IntPtr.Zero;
252 | try
253 | {
254 | if (IntPtr.Size == 8)
255 | {
256 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(36), pPrinterName, out pHandle, pDatatype, ref pDevModeContainer, AccessRequired);
257 | }
258 | else
259 | {
260 | IntPtr tempValue = IntPtr.Zero;
261 | GCHandle handle = GCHandle.Alloc(tempValue, GCHandleType.Pinned);
262 | IntPtr tempValuePointer = handle.AddrOfPinnedObject();
263 | GCHandle handleDevModeContainer = GCHandle.Alloc(pDevModeContainer, GCHandleType.Pinned);
264 | IntPtr tempValueDevModeContainer = handleDevModeContainer.AddrOfPinnedObject();
265 | try
266 | {
267 | result = CallNdrClientCall2x86(34, intptrPrinterName, tempValuePointer, intptrDatatype, tempValueDevModeContainer, new IntPtr(AccessRequired));
268 | // each pinvoke work on a copy of the arguments (without an out specifier)
269 | // get back the data
270 | pHandle = Marshal.ReadIntPtr(tempValuePointer);
271 | }
272 | finally
273 | {
274 | handle.Free();
275 | handleDevModeContainer.Free();
276 | }
277 | }
278 | }
279 | catch (SEHException)
280 | {
281 | Trace.WriteLine("RpcOpenPrinter failed 0x" + Marshal.GetExceptionCode().ToString("x"));
282 | return Marshal.GetExceptionCode();
283 | }
284 | finally
285 | {
286 | if (intptrPrinterName != IntPtr.Zero)
287 | Marshal.FreeHGlobal(intptrPrinterName);
288 | if (intptrDatatype != IntPtr.Zero)
289 | Marshal.FreeHGlobal(intptrDatatype);
290 | }
291 | return (int)result.ToInt64();
292 | }
293 |
294 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
295 | public Int32 RpcClosePrinter(ref IntPtr ServerHandle)
296 | {
297 | IntPtr result = IntPtr.Zero;
298 | try
299 | {
300 | if (IntPtr.Size == 8)
301 | {
302 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(1076), ref ServerHandle);
303 | }
304 | else
305 | {
306 | IntPtr tempValue = ServerHandle;
307 | GCHandle handle = GCHandle.Alloc(tempValue, GCHandleType.Pinned);
308 | IntPtr tempValuePointer = handle.AddrOfPinnedObject();
309 | try
310 | {
311 | result = CallNdrClientCall2x86(1018, tempValuePointer);
312 | // each pinvoke work on a copy of the arguments (without an out specifier)
313 | // get back the data
314 | ServerHandle = Marshal.ReadIntPtr(tempValuePointer);
315 | }
316 | finally
317 | {
318 | handle.Free();
319 | }
320 | }
321 | }
322 | catch (SEHException)
323 | {
324 | Trace.WriteLine("RpcClosePrinter failed 0x" + Marshal.GetExceptionCode().ToString("x"));
325 | return Marshal.GetExceptionCode();
326 | }
327 | return (int)result.ToInt64();
328 | }
329 |
330 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
331 | public Int32 RpcRemoteFindFirstPrinterChangeNotificationEx(
332 | /* [in] */ IntPtr hPrinter,
333 | /* [in] */ UInt32 fdwFlags,
334 | /* [in] */ UInt32 fdwOptions,
335 | /* [unique][string][in] */ string pszLocalMachine,
336 | /* [in] */ UInt32 dwPrinterLocal)
337 | {
338 | IntPtr result = IntPtr.Zero;
339 | IntPtr intptrLocalMachine = Marshal.StringToHGlobalUni(pszLocalMachine);
340 | try
341 | {
342 | if (IntPtr.Size == 8)
343 | {
344 | result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(2308), hPrinter, fdwFlags, fdwOptions, pszLocalMachine, dwPrinterLocal, IntPtr.Zero);
345 | }
346 | else
347 | {
348 | try
349 | {
350 | result = CallNdrClientCall2x86(2178, hPrinter, new IntPtr(fdwFlags), new IntPtr(fdwOptions), intptrLocalMachine, new IntPtr(dwPrinterLocal), IntPtr.Zero);
351 | // each pinvoke work on a copy of the arguments (without an out specifier)
352 | // get back the data
353 | }
354 | finally
355 | {
356 | }
357 | }
358 | }
359 | catch (SEHException)
360 | {
361 | Trace.WriteLine("RpcRemoteFindFirstPrinterChangeNotificationEx failed 0x" + Marshal.GetExceptionCode().ToString("x"));
362 | return Marshal.GetExceptionCode();
363 | }
364 | finally
365 | {
366 | if (intptrLocalMachine != IntPtr.Zero)
367 | Marshal.FreeHGlobal(intptrLocalMachine);
368 | }
369 | return (int)result.ToInt64();
370 | }
371 | }
372 | }
373 |
--------------------------------------------------------------------------------
/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 |
23 |
24 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------