Skip to content

Commit 590cbca

Browse files
committed
Added structure alignment types.
1 parent 280826a commit 590cbca

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

NtApiDotNet/Ndr/NdrSimpleTypes.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,10 @@ internal static NdrBaseTypeReference Read(NdrParseContext context, BinaryReader
620620
case NdrFormatCharacter.FC_STRUCTPAD6:
621621
case NdrFormatCharacter.FC_STRUCTPAD7:
622622
return new NdrStructurePaddingTypeReference(format);
623+
case NdrFormatCharacter.FC_ALIGNM2:
624+
case NdrFormatCharacter.FC_ALIGNM4:
625+
case NdrFormatCharacter.FC_ALIGNM8:
626+
return new NdrStructureAlignTypeReference(format);
623627
case NdrFormatCharacter.FC_IGNORE:
624628
return new NdrIgnoreTypeReference();
625629
case NdrFormatCharacter.FC_SYSTEM_HANDLE:

NtApiDotNet/Ndr/NdrStructureTypes.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,18 @@ protected virtual List<NdrStructureMember> PopulateMembers()
8181
int current_offset = 0;
8282
foreach (var type in _base_members)
8383
{
84-
if (!(type is NdrStructurePaddingTypeReference))
84+
if (type is NdrStructureAlignTypeReference align)
8585
{
86-
members.Add(new NdrStructureMember(type, current_offset, $"Member{current_offset:X}"));
86+
current_offset = align.Align(current_offset);
87+
}
88+
else
89+
{
90+
if (!(type is NdrStructurePaddingTypeReference))
91+
{
92+
members.Add(new NdrStructureMember(type, current_offset, $"Member{current_offset:X}"));
93+
}
94+
current_offset += type.GetSize();
8795
}
88-
current_offset += type.GetSize();
8996
}
9097
return members;
9198
}
@@ -311,6 +318,34 @@ public override int GetSize()
311318
}
312319
}
313320

321+
[Serializable]
322+
public sealed class NdrStructureAlignTypeReference : NdrBaseTypeReference
323+
{
324+
internal NdrStructureAlignTypeReference(NdrFormatCharacter format) : base(format)
325+
{
326+
}
327+
328+
internal int Align(int offset)
329+
{
330+
switch (Format)
331+
{
332+
case NdrFormatCharacter.FC_ALIGNM2:
333+
return (offset + 1) & ~1;
334+
case NdrFormatCharacter.FC_ALIGNM4:
335+
return (offset + 3) & ~3;
336+
case NdrFormatCharacter.FC_ALIGNM8:
337+
return (offset + 7) & ~7;
338+
default:
339+
throw new InvalidOperationException("Format must be an alignment.");
340+
}
341+
}
342+
343+
public override int GetSize()
344+
{
345+
return 0;
346+
}
347+
}
348+
314349
[Serializable]
315350
public sealed class NdrPointerInfoInstance
316351
{

0 commit comments

Comments
 (0)