Skip to content

Commit 73178e2

Browse files
committed
Simplistic back port of IDL NDR formatter.
1 parent 21e0bbe commit 73178e2

File tree

8 files changed

+927
-0
lines changed

8 files changed

+927
-0
lines changed

NtApiDotNet/Ndr/IdlNdrFormatterInternal.cs

Lines changed: 857 additions & 0 deletions
Large diffs are not rendered by default.

NtApiDotNet/Ndr/NdrArrayTypes.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ internal NdrConformantArrayTypeReference(NdrFormatCharacter format, NdrParseCont
129129
ReadElementType(context, reader);
130130
}
131131

132+
internal override NdrCorrelationDescriptor GetConformanceDescriptor()
133+
{
134+
return ConformanceDescriptor;
135+
}
136+
137+
internal override NdrCorrelationDescriptor GetVarianceDescriptor()
138+
{
139+
return VarianceDescriptor;
140+
}
141+
132142
protected override int GetElementSize()
133143
{
134144
return _element_size;
@@ -185,6 +195,16 @@ internal NdrBogusArrayTypeReference(NdrParseContext context, BinaryReader reader
185195
ReadElementType(context, reader);
186196
}
187197

198+
internal override NdrCorrelationDescriptor GetConformanceDescriptor()
199+
{
200+
return ConformanceDescriptor;
201+
}
202+
203+
internal override NdrCorrelationDescriptor GetVarianceDescriptor()
204+
{
205+
return VarianceDescriptor;
206+
}
207+
188208
protected override int GetElementCount()
189209
{
190210
if (NumberofElements > 0)

NtApiDotNet/Ndr/NdrFormatter.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ public enum DefaultNdrFormatterFlags
345345
/// Don't emit comments.
346346
/// </summary>
347347
RemoveComments = 0x1,
348+
/// <summary>
349+
/// Enable type defs.
350+
/// </summary>
351+
EnableTypeDefs = 0x2,
348352
}
349353

350354
/// <summary>
@@ -485,4 +489,23 @@ public static INdrFormatter Create()
485489
return Create(new Dictionary<Guid, string>());
486490
}
487491
}
492+
493+
/// <summary>
494+
/// NDR formatter constructor for IDL style output.
495+
/// </summary>
496+
public static class IdlNdrFormatter
497+
{
498+
/// <summary>
499+
/// Create the CPP formatter.
500+
/// </summary>
501+
/// <param name="iids_to_names">Specify a dictionary of IIDs to names.</param>
502+
/// <param name="demangle_com_name">Function to demangle COM interface names during formatting.</param>
503+
/// <param name="flags">Formatter flags.</param>
504+
/// <returns>The CPP formatter.</returns>
505+
public static INdrFormatter Create(IDictionary<Guid, string> iids_to_names = null,
506+
Func<string, string> demangle_com_name = null, DefaultNdrFormatterFlags flags = 0)
507+
{
508+
return new IdlNdrFormatterInternal(iids_to_names, demangle_com_name, flags);
509+
}
510+
}
488511
}

NtApiDotNet/Ndr/NdrNativeUtils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ internal static U[] Cast<T, U>(this T[] array)
131131

132132
internal static readonly Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046");
133133
internal static readonly Guid IID_IDispatch = new Guid("00020400-0000-0000-C000-000000000046");
134+
internal static readonly Guid IID_IInspectable = new Guid("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90");
134135
internal static readonly Guid IID_IPSFactoryBuffer = new Guid("D5F569D0-593B-101A-B569-08002B2DBF7A");
135136
internal static readonly Guid DCE_TransferSyntax = new Guid("8A885D04-1CEB-11C9-9FE8-08002B104860");
136137
internal static readonly Guid NDR64_TransferSyntax = new Guid("71710533-BEBA-4937-8319-B5DBEF9CCC36");

NtApiDotNet/Ndr/NdrPointerTypes.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ internal override string FormatType(INdrFormatterInternal formatter)
122122
}
123123
}
124124

125+
internal override NdrCorrelationDescriptor GetConformanceDescriptor()
126+
{
127+
return Type.GetConformanceDescriptor();
128+
}
129+
130+
internal override NdrCorrelationDescriptor GetVarianceDescriptor()
131+
{
132+
return Type.GetVarianceDescriptor();
133+
}
134+
125135
public override int GetSize()
126136
{
127137
return IntPtr.Size;

NtApiDotNet/Ndr/NdrSimpleTypes.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ internal static NdrFormatCharacter ReadFormat(BinaryReader reader)
196196
return (NdrFormatCharacter)reader.ReadByte();
197197
}
198198

199+
internal virtual NdrCorrelationDescriptor GetConformanceDescriptor()
200+
{
201+
return null;
202+
}
203+
204+
internal virtual NdrCorrelationDescriptor GetVarianceDescriptor()
205+
{
206+
return null;
207+
}
208+
199209
protected virtual void OnFixupLateBoundTypes()
200210
{
201211
// Do nothing in the base.

NtApiDotNet/Ndr/NdrStringTypes.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ internal override string FormatType(INdrFormatterInternal context)
104104
return $"{conformance_desc}{base.FormatType(context)}[{GetCharCount()}]";
105105
}
106106

107+
internal override NdrCorrelationDescriptor GetConformanceDescriptor()
108+
{
109+
return ConformanceDescriptor;
110+
}
111+
107112
private int GetCharSize()
108113
{
109114
if (Format == NdrFormatCharacter.FC_C_WSTRING)

NtApiDotNet/NtApiDotNet.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<Compile Include="IO\UsnJournal\UsnJournalReasonFlags.cs" />
7474
<Compile Include="IO\UsnJournal\UsnJournalUtils.cs" />
7575
<Compile Include="KnownSids.cs" />
76+
<Compile Include="Ndr\IdlNdrFormatterInternal.cs" />
7677
<Compile Include="Ndr\Marshal\FLAGGED_WORD_BLOB.cs" />
7778
<Compile Include="Ndr\Marshal\NdrUserMarshal.cs" />
7879
<Compile Include="Ndr\NdrUtils.cs" />

0 commit comments

Comments
 (0)