public void BlobTemplate() { var template = StandardTemplates.Blob(100); Assert.That(template, Is.InstanceOf <BlobNodeTemplate>()); Assert.That(template.Width, Is.EqualTo(100)); }
protected override IList <IStructuralNode> CreateChildNodes() { var data = _provider.Data; var offset = _provider.MetaDataOffset; var length = data.Read <int>(offset + 12); var headerTemplate = new CompoundNodeTemplate() { { "Signature", StandardTemplates.UInt32 }, { "Major Version", StandardTemplates.UInt16 }, { "Minor Version", StandardTemplates.UInt16 }, { "Reserved", StandardTemplates.UInt32 }, { "Length", StandardTemplates.UInt32 }, { "Version", StandardTemplates.Text(length, Encoding.UTF8) }, { "Flags", StandardTemplates.UInt16 }, { "Streams", StandardTemplates.UInt16 }, }; return(new IStructuralNode[] { new TemplatedStructuralNode(_provider.Data, this, "Header", headerTemplate, _provider.MetaDataOffset), new StreamHeaderListNode(_provider, this), new StreamListNode(_provider, this), }); }
protected override IList <IStructuralNode> CreateChildNodes() { const int IsDirectoryFlag = unchecked ((int)0x80000000); var id = _provider.Data.Read <int>(_offset + 4); var rvaTarget = _resourceBase + (id & ~IsDirectoryFlag); var keyNode = new TemplatedStructuralNode(_provider.Data, this, _named ? "Name RVA" : "ID", StandardTemplates.Int32, _offset); if ((id & IsDirectoryFlag) != 0) { return(new IStructuralNode[] { keyNode, new TemplatedStructuralNode(_provider.Data, this, "Subdirectory RVA", StandardTemplates.Int32, _offset + 4), new ResourceDirectoryNode(_provider, this, _resourceBase, rvaTarget, _depth + 1), }); } else { var dataRVA = _provider.Data.Read <int>(rvaTarget); var dataSize = _provider.Data.Read <int>(rvaTarget + 4); var dataFilePos = _provider.MapRVAtoFile(dataRVA); return(new IStructuralNode[] { keyNode, new TemplatedStructuralNode(_provider.Data, this, "Data Entry RVA", StandardTemplates.Int32, _offset + 4), new TemplatedStructuralNode(_provider.Data, this, "Data Entry", PETemplates.ResourceDataEntry, rvaTarget), new TemplatedStructuralNode(_provider.Data, this, "Data", StandardTemplates.Blob(dataSize), dataFilePos), }); } }
IStructuralNode NewSectionNode(int dictionaryIndex, int fileOffset, int fileLength) { var name = Constants.GetDirectoryName(dictionaryIndex); return(dictionaryIndex switch { Constants.Directory_Index_Resources => new ResourceDirectoryNode(_provider, this, fileOffset, fileOffset, 0), Constants.Directory_Index_CLI => new TemplatedStructuralNode(_provider.Data, this, name, PETemplates.CLIHeaderTemplate, fileOffset), _ => new TemplatedStructuralNode(_provider.Data, this, name, StandardTemplates.Blob(fileLength), fileOffset), });
protected override IStructuralNode CreateChildNode(int index) { var pair = _provider.StreamHeaderOffsets[index]; var nameLen = pair.Key.Length; var stringBytes = nameLen < 32 ? nameLen + 1 : 32; var template = new CompoundNodeTemplate() { { "Offset", StandardTemplates.UInt32 }, { "Size", StandardTemplates.UInt32 }, { "Name", StandardTemplates.Text(stringBytes, Encoding.ASCII) }, }; template.RoundWidthUpToBoundary(4); return(new TemplatedStructuralNode(_provider.Data, this, pair.Key, template, _provider.MetaDataOffset + pair.Value)); }
IStructuralNode NewSectionNode(int dictionaryIndex, int fileOffset, int fileLength) { var name = Constants.GetDirectoryName(dictionaryIndex); switch (dictionaryIndex) { case Constants.Directory_Index_Resources: return(new ResourceDirectoryNode(_provider, this, fileOffset, fileOffset, 0)); case Constants.Directory_Index_CLI: return(new TemplatedStructuralNode(_provider.Data, this, name, PETemplates.CLIHeaderTemplate, fileOffset)); default: return(new TemplatedStructuralNode(_provider.Data, this, name, StandardTemplates.Blob(fileLength), fileOffset)); } }
IStructuralNode NewStreamNode(string name, int offset, int length) { var fileOffset = _provider.MetaDataOffset + offset; switch (name) { case "#GUID": var template = new RepeatingNodeTemplate(StandardTemplates.Guid, (int)(length >> 4), (i, l) => (i + 1).ToString("X08", CultureInfo.InvariantCulture)); return(new TemplatedStructuralNode(_provider.Data, this, name, template, fileOffset)); case "#~": return(new TableStreamNode(_provider, this, name, fileOffset, length)); default: return(new TemplatedStructuralNode(_provider.Data, this, name, StandardTemplates.Blob(length), fileOffset)); } }
public void TextTemplate() { var template = StandardTemplates.Text(40, Encoding.UTF8); Assert.That(template, Is.InstanceOf <TextNodeTemplate>()); }
public void EnumTemplate() { Assert.That(StandardTemplates.Enum <TypeCode>(), Is.InstanceOf <SimpleNodeTemplate <TypeCode> >()); }
Level Setup() { if (Data.ByteCount < 10) { AddNotification(0, StandardTemplates.Blob(0), "File too short to be valid"); return(Level.Invalid); } else if (Data.Read <short>(0) != Constants.MSDos_Signature) { AddNotification(0, StandardTemplates.UInt16, "Invalid signature"); return(Level.Invalid); } int tmp; if ((tmp = Data.Read <ushort>(Constants.MSDos_DosHeaderSize)) < 4) { return(Level.DosExecutable); } else if (Data.ByteCount <= (tmp << 4)) { AddNotification(Constants.MSDos_DosHeaderSize, StandardTemplates.UInt16, "Specified dos header does not fit in file."); return(Level.Invalid); } tmp = Data.Read <int>(Constants.MSDos_NewHeaderOffset); if (tmp == 0) { return(Level.DosExecutable); } else if (tmp >= Data.ByteCount - Constants.Header_Length || Data.Read <int>(tmp) != Constants.Header_Signature) { AddNotification(Constants.MSDos_NewHeaderOffset, StandardTemplates.UInt32, "Extended header not within file."); return(Level.Invalid); } PEFileHeaderOffset = tmp; PEFileOptionalHeaderOffset = PEFileHeaderOffset + Constants.Header_Length; PEFileOptionalHeaderSize = Data.Read <short>(PEFileHeaderOffset + Constants.Header_OptionalHeaderSizeOffset); if (PEFileOptionalHeaderSize > 2) { Magic = Data.Read <IMAGE_FILE_MAGIC>(PEFileOptionalHeaderOffset); } switch (Magic) { case IMAGE_FILE_MAGIC.IMAGE_FILE_MAGIC_PE: DirectoryOffset = PEFileOptionalHeaderOffset + Constants.OptHeader_DirectoryOffset; DirectoryCount = Data.Read <int>(PEFileOptionalHeaderOffset + Constants.OptHeader_DirectoryCountOffset); break; case IMAGE_FILE_MAGIC.IMAGE_FILE_MAGIC_PE_PLUS: DirectoryOffset = PEFileOptionalHeaderOffset + Constants.OptHeaderPlus_DirectoryOffset; DirectoryCount = Data.Read <int>(PEFileOptionalHeaderOffset + Constants.OptHeaderPlus_DirectoryCountOffset); break; } PESectionTableOffset = PEFileOptionalHeaderOffset + PEFileOptionalHeaderSize; PESectionCount = Data.Read <short>(PEFileHeaderOffset + Constants.Header_SectionCountOffset); tmp = Data.Read <int>(DirectoryOffset + (Constants.Directory_Index_CLI << 3)); if (tmp != 0) { CLIOffset = (int)MapRVAtoFile(tmp); MetaDataOffset = (int)MapRVAtoFile(Data.Read <int>(CLIOffset + Constants.CLIHeader_MetaDataRVA_Offset)); } return(Level.PEFile); }