void ReadStrongNameSignature(PeHeaders peHeaders, HexSpan?span) { if (span == null) { return; } strongNameSignature = ArrayData.CreateVirtualByteArray(new HexBufferSpan(file.Buffer, span.Value), name: "STRONGNAMESIGNATURE"); }
public DotNetEmbeddedResourceImpl(DotNetResourceProvider resourceProvider, HexBufferSpan span, uint token) : base(resourceProvider, span, token) { if (span.Length < 4) { throw new ArgumentOutOfRangeException(nameof(span)); } Size = new StructField <UInt32Data>("Size", new UInt32Data(span.Buffer, span.Start.Position)); Content = new StructField <VirtualArrayData <ByteData> >("Content", ArrayData.CreateVirtualByteArray(HexBufferSpan.FromBounds(span.Start + 4, span.End))); Fields = new BufferField[] { Size, Content, }; }
ComplexData?GetStructure(BlobDataInfo info, HexPosition position) { var pos = info.Span.Start; var lengthStart = pos; var len = ReadCompressedUInt32(ref pos) ?? -1; if (len < 0) { return(null); } if (pos + len > Span.Span.End) { return(null); } var lengthSpan = HexSpan.FromBounds(lengthStart, pos); var dataSpan = new HexSpan(lengthSpan.End, (ulong)len); var fullSpan = HexSpan.FromBounds(lengthSpan.Start, dataSpan.End); if (!fullSpan.Contains(position)) { return(null); } switch (info.Kind) { case BlobDataKind.None: case BlobDataKind.TypeSignature: case BlobDataKind.Signature: case BlobDataKind.Constant: case BlobDataKind.CustomAttribute: case BlobDataKind.NativeType: case BlobDataKind.PermissionSet: case BlobDataKind.PublicKey: case BlobDataKind.PublicKeyOrToken: case BlobDataKind.HashValue: case BlobDataKind.Utf8Name: case BlobDataKind.Name: case BlobDataKind.SequencePoints: case BlobDataKind.LocalConstantSig: case BlobDataKind.Imports: case BlobDataKind.CustomDebugInformationValue: var varray = ArrayData.CreateVirtualByteArray(new HexBufferSpan(Span.Buffer, dataSpan)); return(new BlobHeapRecordData(Span.Buffer, fullSpan, lengthSpan, varray, info.Tokens, this)); default: throw new InvalidOperationException(); } }
/// <summary> /// Constructor /// </summary> /// <param name="resourceProvider">Owner</param> /// <param name="resourceInfo">Resource info</param> /// <param name="span">Span</param> /// <param name="lengthPosition">Position of 32-bit content length which immediately follows the 7-bit encoded type code</param> public MultiResourceArrayDataHeaderData(DotNetMultiFileResources resourceProvider, MultiResourceInfo resourceInfo, HexBufferSpan span, HexPosition lengthPosition) : base(resourceProvider, resourceInfo, span) { var typeCodeSpan = new HexBufferSpan(span.Buffer, HexSpan.FromBounds(span.Start, lengthPosition)); TypeCode = new StructField <ResourceTypeCodeData>("TypeCode", ResourceTypeCodeData.Create(typeCodeSpan)); ContentLength = new StructField <UInt32Data>("ContentLength", new UInt32Data(span.Buffer, lengthPosition)); var arraySpan = new HexBufferSpan(span.Buffer, HexSpan.FromBounds(lengthPosition + 4, span.End)); Content = new StructField <VirtualArrayData <ByteData> >("Content", ArrayData.CreateVirtualByteArray(arraySpan)); Fields = new BufferField[] { TypeCode, ContentLength, Content, }; }
public FatMethodBodyImpl(DotNetMethodProvider methodProvider, HexBufferSpan span, ReadOnlyCollection <uint> tokens, HexSpan instructionsSpan, HexSpan ehSpan, bool fatEH) : base(methodProvider, span, tokens) { var buffer = span.Buffer; var pos = span.Start.Position; Flags_Size = new StructField <UInt16FlagsData>("Flags", new UInt16FlagsData(buffer, pos, fatHeaderFlagsFlagInfos)); MaxStack = new StructField <UInt16Data>("MaxStack", new UInt16Data(buffer, pos + 2)); CodeSize = new StructField <UInt32Data>("CodeSize", new UInt32Data(buffer, pos + 4)); LocalVarSigTok = new StructField <TokenData>("LocalVarSigTok", new TokenData(buffer, pos + 8)); Instructions = new StructField <VirtualArrayData <ByteData> >(TinyMethodBodyImpl.InstructionsFieldName, ArrayData.CreateVirtualByteArray(new HexBufferSpan(span.Buffer, instructionsSpan), TinyMethodBodyImpl.InstructionsFieldName)); if (!ehSpan.IsEmpty) { ExceptionHandlerTable ehTable; if (fatEH) { ehTable = new FatExceptionHandlerTableImpl(new HexBufferSpan(buffer, ehSpan)); } else { ehTable = new SmallExceptionHandlerTableImpl(new HexBufferSpan(buffer, ehSpan)); } EHTable = new StructField <ExceptionHandlerTable>("EHTable", ehTable); var paddingSpan = HexBufferSpan.FromBounds(Instructions.Data.Span.End, EHTable.Data.Span.Start); Padding = new StructField <VirtualArrayData <ByteData> >("Padding", ArrayData.CreateVirtualByteArray(paddingSpan)); } var fields = new List <BufferField>(7) { Flags_Size, MaxStack, CodeSize, LocalVarSigTok, Instructions, }; if (Padding is not null) { fields.Add(Padding); } if (EHTable is not null) { fields.Add(EHTable); } Fields = fields.ToArray(); }
public InvalidMethodBodyImpl(DotNetMethodProvider methodProvider, HexBufferSpan span, ReadOnlyCollection <uint> tokens) : base(methodProvider, span, tokens) { var buffer = span.Buffer; var pos = span.Start.Position; Instructions = new StructField <VirtualArrayData <ByteData> >(TinyMethodBodyImpl.InstructionsFieldName, ArrayData.CreateVirtualByteArray(HexBufferSpan.FromBounds(span.Start, span.End), TinyMethodBodyImpl.InstructionsFieldName)); Fields = new BufferField[] { Instructions, }; }
public TinyMethodBodyImpl(DotNetMethodProvider methodProvider, HexBufferSpan span, ReadOnlyCollection <uint> tokens) : base(methodProvider, span, tokens) { var buffer = span.Buffer; var pos = span.Start.Position; Flags_CodeSize = new StructField <ByteFlagsData>("Flags_CodeSize", new ByteFlagsData(buffer, pos, flagsCodeSizeFlagInfos)); Instructions = new StructField <VirtualArrayData <ByteData> >(InstructionsFieldName, ArrayData.CreateVirtualByteArray(HexBufferSpan.FromBounds(span.Start + 1, span.End), InstructionsFieldName)); Fields = new BufferField[] { Flags_CodeSize, Instructions, }; }
/// <summary> /// Constructor /// </summary> /// <param name="resourceProvider">Owner</param> /// <param name="resourceInfo">Resource info</param> /// <param name="span">Span</param> /// <param name="dataPosition">Position of data which immediately follows the 7-bit encoded type code</param> public MultiResourceSimplDataHeaderData(DotNetMultiFileResources resourceProvider, MultiResourceInfo resourceInfo, HexBufferSpan span, HexPosition dataPosition) : base(resourceProvider, resourceInfo, span) { // Don't use Contains() since data length could be 0 if (dataPosition < span.Start || dataPosition > span.End) { throw new ArgumentOutOfRangeException(nameof(dataPosition)); } var typeCodeSpan = new HexBufferSpan(span.Buffer, HexSpan.FromBounds(span.Start, dataPosition)); TypeCode = new StructField <ResourceTypeCodeData>("TypeCode", ResourceTypeCodeData.Create(typeCodeSpan)); var pos = typeCodeSpan.Span.Start; var typeCode = (ResourceTypeCode)(Utils.Read7BitEncodedInt32(span.Buffer, ref pos) ?? -1); var dataSpan = new HexBufferSpan(span.Buffer, HexSpan.FromBounds(dataPosition, span.End)); switch (typeCode) { case ResourceTypeCode.String: Debug.Fail($"Use {nameof(MultiResourceStringDataHeaderData)}"); goto default; case ResourceTypeCode.ByteArray: case ResourceTypeCode.Stream: Debug.Fail($"Use {nameof(MultiResourceArrayDataHeaderData)}"); goto default; case ResourceTypeCode.Boolean: Content = new StructField <BooleanData>("Content", new BooleanData(dataSpan)); break; case ResourceTypeCode.Char: Content = new StructField <CharData>("Content", new CharData(dataSpan)); break; case ResourceTypeCode.Byte: Content = new StructField <ByteData>("Content", new ByteData(dataSpan)); break; case ResourceTypeCode.SByte: Content = new StructField <SByteData>("Content", new SByteData(dataSpan)); break; case ResourceTypeCode.Int16: Content = new StructField <Int16Data>("Content", new Int16Data(dataSpan)); break; case ResourceTypeCode.UInt16: Content = new StructField <UInt16Data>("Content", new UInt16Data(dataSpan)); break; case ResourceTypeCode.Int32: Content = new StructField <Int32Data>("Content", new Int32Data(dataSpan)); break; case ResourceTypeCode.UInt32: Content = new StructField <UInt32Data>("Content", new UInt32Data(dataSpan)); break; case ResourceTypeCode.Int64: Content = new StructField <Int64Data>("Content", new Int64Data(dataSpan)); break; case ResourceTypeCode.UInt64: Content = new StructField <UInt64Data>("Content", new UInt64Data(dataSpan)); break; case ResourceTypeCode.Single: Content = new StructField <SingleData>("Content", new SingleData(dataSpan)); break; case ResourceTypeCode.Double: Content = new StructField <DoubleData>("Content", new DoubleData(dataSpan)); break; case ResourceTypeCode.Decimal: Content = new StructField <DecimalData>("Content", new DecimalData(dataSpan)); break; case ResourceTypeCode.DateTime: Content = new StructField <DateTimeData>("Content", new DateTimeData(dataSpan)); break; case ResourceTypeCode.TimeSpan: Content = new StructField <TimeSpanData>("Content", new TimeSpanData(dataSpan)); break; case ResourceTypeCode.Null: default: Content = new StructField <VirtualArrayData <ByteData> >("Content", ArrayData.CreateVirtualByteArray(dataSpan)); break; } Fields = new BufferField[] { TypeCode, Content, }; }
public DotNetMultiFileResourceHeaderDataImpl(HexBufferSpan span, Bit7String?resourceTypeSpan, Bit7String?resourceSetTypeSpan, HexPosition versionPosition, HexSpan paddingSpan, Bit7String[] typeNames, int numResources) : base(span) { var buffer = span.Buffer; var pos = span.Start.Position; MagicNum = new StructField <UInt32Data>("MagicNum", new UInt32Data(buffer, pos)); ResMgrHeaderVersion = new StructField <UInt32Data>("ResMgrHeaderVersion", new UInt32Data(buffer, pos + 4)); HeaderSize = new StructField <UInt32Data>("HeaderSize", new UInt32Data(buffer, pos + 8)); if (resourceTypeSpan == null) { if (resourceSetTypeSpan != null) { throw new ArgumentException(); } UnknownHeader = new StructField <VirtualArrayData <ByteData> >("Header", ArrayData.CreateVirtualByteArray(new HexBufferSpan(buffer, HexSpan.FromBounds(pos + 0x0C, versionPosition)))); } else { if (resourceSetTypeSpan == null) { throw new ArgumentNullException(nameof(resourceSetTypeSpan)); } ReaderType = new StructField <Bit7EncodedStringData>("ReaderType", new Bit7EncodedStringData(buffer, resourceTypeSpan.Value.LengthSpan, resourceTypeSpan.Value.StringSpan, Encoding.UTF8)); ResourceSetType = new StructField <Bit7EncodedStringData>("ResourceSetType", new Bit7EncodedStringData(buffer, resourceSetTypeSpan.Value.LengthSpan, resourceSetTypeSpan.Value.StringSpan, Encoding.UTF8)); } pos = versionPosition; Version = new StructField <UInt32Data>("Version", new UInt32Data(buffer, pos)); NumResources = new StructField <UInt32Data>("NumResources", new UInt32Data(buffer, pos + 4)); NumTypes = new StructField <UInt32Data>("NumTypes", new UInt32Data(buffer, pos + 8)); pos += 0x0C; var fields = new ArrayField <Bit7EncodedStringData> [typeNames.Length]; var currPos = pos; for (int i = 0; i < fields.Length; i++) { var info = typeNames[i]; var field = new ArrayField <Bit7EncodedStringData>(new Bit7EncodedStringData(buffer, info.LengthSpan, info.StringSpan, Encoding.UTF8), (uint)i); fields[i] = field; currPos = field.Data.Span.End; } TypeNames = new StructField <VariableLengthArrayData <Bit7EncodedStringData> >("TypeNames", new VariableLengthArrayData <Bit7EncodedStringData>(string.Empty, new HexBufferSpan(buffer, HexSpan.FromBounds(pos, currPos)), fields)); Alignment8 = new StructField <ArrayData <ByteData> >("Padding", ArrayData.CreateByteArray(buffer, paddingSpan.Start, (int)paddingSpan.Length.ToUInt64())); pos = paddingSpan.End; NameHashes = new StructField <VirtualArrayData <UInt32Data> >("NameHashes", ArrayData.CreateVirtualUInt32Array(new HexBufferSpan(buffer, new HexSpan(pos, (ulong)numResources * 4)))); pos += (ulong)numResources * 4; NamePositions = new StructField <VirtualArrayData <UInt32Data> >("NamePositions", ArrayData.CreateVirtualUInt32Array(new HexBufferSpan(buffer, new HexSpan(pos, (ulong)numResources * 4)))); pos += (ulong)numResources * 4; DataSectionOffset = new StructField <FileOffsetData>("DataSectionOffset", new FileOffsetData(buffer, pos)); pos += 4; if (pos != span.Span.End) { throw new ArgumentOutOfRangeException(nameof(span)); } var list = new List <BufferField>(13); list.Add(MagicNum); list.Add(ResMgrHeaderVersion); list.Add(HeaderSize); if (UnknownHeader != null) { list.Add(UnknownHeader); } if (ReaderType != null) { list.Add(ReaderType); } if (ResourceSetType != null) { list.Add(ResourceSetType); } list.Add(Version); list.Add(NumResources); list.Add(NumTypes); list.Add(TypeNames); list.Add(Alignment8); list.Add(NameHashes); list.Add(NamePositions); list.Add(DataSectionOffset); Fields = list.ToArray(); }