/// <summary> /// Sets or clears the specified flags in an enum, and returns the result. /// </summary> /// <param name="value">The value to change.</param> /// <param name="flag">The flags to set or clear.</param> /// <param name="set"><see langword="true"/> to set the flags; <see langword="false"/> to clear them.</param> public static SectionFlags SetFlag(this SectionFlags value, SectionFlags flag, bool set) { if (set) return (SectionFlags)(((uint)value) | ((uint)flag)); else return (SectionFlags)(((uint)value) & ~((uint)flag)); }
public void Load(BinaryReader rdr) { f = (SectionFlags)rdr.ReadByte(); uint s; if ((f & SectionFlags.FatFormat) == SectionFlags.FatFormat) { rdr.BaseStream.Seek(-1, SeekOrigin.Current); s = ((rdr.ReadUInt32() >> 8) - 4) / 24; for (int i = 0; i < s; i++) { ExceptionClause c = new ExceptionClause(par); c.Load(false, rdr); Items.Add(c); } } else { s = (rdr.ReadByte() - 4U) / 12; rdr.ReadByte(); rdr.ReadByte(); for (int i = 0; i < s; i++) { ExceptionClause c = new ExceptionClause(par); c.Load(true, rdr); Items.Add(c); } } }
public MachOSection(string name, Address addr, SectionFlags flags, uint reserved1, uint reserved2) { this.Name = name; this.Address = addr; this.Flags = flags; this.Reserved1 = reserved1; this.Reserved2 = reserved2; }
protected MachOSection?FindSectionByType(SectionFlags type) { foreach (var kv in ldr.imageSections) { if ((kv.Key.Flags & SECTION_TYPE) == type) { return(kv.Key); } } return(null); }
/// <summary> /// Gets the first section of a list of sections that contains the specified flag /// </summary> /// <param name="sections">The section list to search in.</param> /// <param name="characteristics">The flag to search for.</param> /// <returns></returns> public static Section GetFirstSectionByFlag(IEnumerable <Section> sections, SectionFlags characteristics) { foreach (Section s in sections) { if (s.Flags.HasFlag(characteristics)) { return(s); } } return(null); }
/// <summary> /// Creates a new section object. /// </summary> /// <param name="index">The section's order within the object file</param> /// <param name="name">The section's name.</param> /// <param name="size">The section's size in bytes.</param> /// <param name="runtimeAddress">The virtual memory address of the section. This is the address /// at which the section's contents will actually be loaded at runtime.</param> /// <param name="loadAddress">The load memory address of the section. This is the address /// at which the section's contents will loaded intially from disk.</param> /// <param name="fileOffset">The section's offset in bytes within the file.</param> /// <param name="alignment">The section's alignment in bytes.</param> /// <param name="flags">The section's flags.</param> public Section(int index, string name, uint size, uint runtimeAddress, uint loadAddress, uint fileOffset, int alignment, SectionFlags flags) { this.Index = index; this.Name = name; this.Size = size; this.FileOffset = fileOffset; this.Flags = flags; this.VirtualMemoryAddress = runtimeAddress; this.LoadMemoryAddress = loadAddress; }
/// <summary> /// Sets or clears the specified flags in an enum, and returns the result. /// </summary> /// <param name="value">The value to change.</param> /// <param name="flag">The flags to set or clear.</param> /// <param name="set"><see langword="true"/> to set the flags; <see langword="false"/> to clear them.</param> public static SectionFlags SetFlag(this SectionFlags value, SectionFlags flag, bool set) { if (set) { return((SectionFlags)(((uint)value) | ((uint)flag))); } else { return((SectionFlags)(((uint)value) & ~((uint)flag))); } }
internal Section(Bfd bfd, IntPtr section) { this.bfd = bfd; this.section = section; this.name = bfd_glue_get_section_name(section); this.vma = bfd_glue_get_section_vma(section); this.size = bfd_glue_get_section_size(section); this.flags = bfd_glue_get_section_flags(section); contents = new ObjectCache( new ObjectCacheFunc(get_section_contents), section, 5); }
private AccessMode SectionAccessMode(SectionFlags s_flags) { if (s_flags.HasFlag(SectionFlags.STYP_TEXT)) { return(AccessMode.ReadExecute); } if (s_flags.HasFlag(SectionFlags.STYP_DATA) || s_flags.HasFlag(SectionFlags.STYP_BSS)) { return(AccessMode.ReadWrite); } return(AccessMode.Read); }
public void Swap() { this.Name = this.Name.Swap(); this.Type = (SectionType)(((uint)this.Type).Swap()); this.Flags = (SectionFlags)(((ulong)this.Flags).Swap()); this.VirtualAddress = this.VirtualAddress.Swap(); this.FileOffset = this.FileOffset.Swap(); this.FileSize = this.FileSize.Swap(); this.Link = this.Link.Swap(); this.Info = this.Info.Swap(); this.Align = this.Align.Swap(); this.EntrySize = this.EntrySize.Swap(); }
/// <summary> /// Gets the last section of a list of sections that contains the specified flag /// </summary> /// <param name="sections">The section list to search in.</param> /// <param name="characteristics">The flag to search for.</param> /// <returns></returns> public static Section GetLastSectionByFlag(IEnumerable <Section> sections, SectionFlags characteristics) { Section sec = null; foreach (Section s in sections) { if (s.Flags.HasFlag(characteristics)) { sec = s; } } return(sec); }
private void SetWellKnownSection(Section section, SectionFlags flag, ImageSegment seg, ref ImageSegment?segToSet) { if (section.s_flags.HasFlag(flag)) { if (segToSet != null) { Services.RequireService <DecompilerEventListener>().Warn("Multiple XCoff {0} sections found, ignoring.", flag); Debug.WriteLine(" ?Dup?"); } else { segToSet = seg; } } }
public SectionHeader(Header parent, EndianBinaryReader reader, short sectionHeaderSize) { Parent = parent; NameIndex = reader.ReadInt32(); Type = (SectionType)reader.ReadUInt32(); Flags = (SectionFlags)reader.ReadUInt32(); SegmentInMemVirtAddress = reader.ReadUInt32(); SegmentImageOffset = reader.ReadUInt32(); SegmentImageSize = reader.ReadInt32(); LinkIndex = reader.ReadUInt32(); Info = reader.ReadUInt32(); Alignment = reader.ReadUInt32(); FixedEntrySize = reader.ReadUInt32(); var offset = reader.BaseStream.Position; switch (Type) { case SectionType.RELOC: reader.BaseStream.Seek(SegmentImageOffset, SeekOrigin.Begin); SectionData = new SimpleRelocations(parent, this, reader, SegmentImageSize / Relocation.SIZE); reader.BaseStream.Seek(offset, SeekOrigin.Begin); break; case SectionType.RELOC_ADD: reader.BaseStream.Seek(SegmentImageOffset, SeekOrigin.Begin); SectionData = new AddendRelocations(parent, this, reader, SegmentImageSize / AddendRelocation.SIZE); reader.BaseStream.Seek(offset, SeekOrigin.Begin); break; case SectionType.SYM_TABLE: reader.BaseStream.Seek(SegmentImageOffset, SeekOrigin.Begin); SectionData = new SymbolTable(parent, this, reader, SegmentImageSize / Symbol.SIZE); reader.BaseStream.Seek(offset, SeekOrigin.Begin); break; case SectionType.STR_TABLE: reader.BaseStream.Seek(SegmentImageOffset, SeekOrigin.Begin); SectionData = new StringTable(reader, SegmentImageSize); reader.BaseStream.Seek(offset, SeekOrigin.Begin); break; default: // IGNORE break; } }
internal void Read(PeReader rdr) { n = new string(rdr.ReadChars(8)).Trim('\0'); vSize = rdr.ReadUInt32(); vPtr = rdr.ReadUInt32(); uint rSize = rdr.ReadUInt32(); uint rPtr = rdr.ReadUInt32(); relocPtr = rdr.ReadUInt32(); lnPtr = rdr.ReadUInt32(); relocNo = rdr.ReadUInt16(); lnNo = rdr.ReadUInt16(); c = (SectionFlags)rdr.ReadUInt32(); rdr.SaveLocation(); rdr.SetPosition(rPtr); dat = rdr.ReadBytes((int)rSize); rdr.LoadLocation(); }
private void OnElementParsed(object sender, string name, JsonElement element) { switch (name) { case "Metadata": { var obj = element as JsonObject; if (obj != null) { if (obj.Items.ContainsKey("DateCreated")) { Console.WriteLine("Date created: {0}", ((JsonString)obj["DateCreated"]).Value); } if (obj.Items.ContainsKey("Author")) { Console.WriteLine("Author: {0}", ((JsonString)obj["Author"]).Value); } if (obj.Items.ContainsKey("NodeCount")) { Console.WriteLine("Node count: {0}", _nodeCount = (int)((JsonNumber)obj["NodeCount"]).Value); } } } _flags |= SectionFlags.Metadata; break; case "StringTable": ProcessStringTable((JsonObject)element); _flags |= SectionFlags.StringTable; break; case "Defaults": Defaults = (JsonObject)element; _flags |= SectionFlags.Defaults; break; case "NodeOffsets": ProcessNodeOffsets(((JsonString)element).Value); _flags |= SectionFlags.NodeOffsets; break; } _parser.Terminate = ((_flags & SectionFlags.RequiredSections) == SectionFlags.RequiredSections); }
public void Read(System.IO.Stream stream, ElfDocumentHeader header) { NameIndex = stream.ReadUInt32(header); Type = (SectionType)stream.ReadUInt32(header); var RawFlags = stream.ReadUIntPtr(header); Flags = unchecked ((SectionFlags)RawFlags); Flag_Writable = (Flags & SectionFlags.Writable) > 0; Flag_Allocatable = (Flags & SectionFlags.Allocatable) > 0; Flag_Executable = (Flags & SectionFlags.Executable) > 0; LoadAddress = stream.ReadUIntPtr(header); Offset = stream.ReadUIntPtr(header); Size = stream.ReadUIntPtr(header); Link = stream.ReadUInt32(header); Info = stream.ReadUInt32(header); Alignment = stream.ReadUIntPtr(header); EntrySize = stream.ReadUIntPtr(header); }
protected DemographicsLayer(string fileName) { StringTable = new Dictionary <string, string>(); _nodeOffsets = new Dictionary <int, uint>(); _flags = SectionFlags.None; _cachedNodes = new Dictionary <int, JsonObject>(); var source = CharSourceFactory.CharSourceFromFile(FileName = fileName); _parser = JsonParser.CreateJsonParser(source); _parser.ElementParsed += OnElementParsed; Console.WriteLine("Loading demographics layer '{0}'-", fileName); /*_root =*/ _parser.ParseElement() /*as JsonObject*/; _parser.ElementParsed -= OnElementParsed; _parser.Terminate = false; if ((_flags & SectionFlags.RequiredSections) != SectionFlags.RequiredSections) { Console.Error.WriteLine("Demographics layer '{0}' missing one or more required sections (Metadata, StringTable, NodeOffsets).", fileName); throw new ApplicationException(); } }
public int LoadFromStream(BinaryReader br) { long offset = br.BaseStream.Position; isASCII = br.ReadByte(); if (isASCII == 1) { throw new Exception("ascii format is unsupported"); } zero = new byte[3]; br.Read(zero, 0, 3); sectionType = (SectionType)br.ReadUInt32(); sectionCompressedLength = br.ReadUInt64(); sectionUncompressedLength = br.ReadUInt64(); sectionVersion = br.ReadUInt64(); sectionFlags = (SectionFlags)br.ReadUInt32(); name = Utils.GetStringFromStream <uint>(br); //br.ReadByte(); // SkipBytes(1), renderdoc 读取 name 少读了一个字节,然后又 skip 了一个字节,因此等于直接读name return((int)(br.BaseStream.Position - offset)); }
public void CompressData(SectionFlags flags) { }
/// <summary> /// Creates a new empty section. /// </summary> /// <param name="name">The name of the section.</param> /// <param name="characteristics">The section flags.</param> public PESection(string name, SectionFlags characteristics) { Name = name; Characteristics = characteristics; }
/// <summary> /// Creates a new empty section. /// </summary> /// <param name="name">The name of the section.</param> /// <param name="characteristics">The section flags.</param> /// <param name="contents">The contents of the section.</param> public PESection(string name, SectionFlags characteristics, ISegment contents) { Name = name; Characteristics = characteristics; Contents = contents; }
/// <summary> /// Gets the first section of a list of sections that contains the specified flag /// </summary> /// <param name="sections">The section list to search in.</param> /// <param name="characteristics">The flag to search for.</param> /// <returns></returns> public static Section GetFirstSectionByFlag(Section[] sections, SectionFlags characteristics) { foreach (Section s in sections) { if (s.Flags.HasFlag(characteristics)) return s; } return null; }
/// <summary> /// Gets the last section of an assembly that contains the specified flag /// </summary> /// <param name="assembly">The assembly to search in.</param> /// <param name="characteristics">The flag to search for.</param> /// <returns></returns> public static Section GetLastSectionByFlag(Win32Assembly assembly, SectionFlags characteristics) { return GetLastSectionByFlag(assembly.ntheader.Sections, characteristics); }
internal Section(Bfd bfd, IntPtr section) { this.bfd = bfd; this.section = section; this.name = bfd_glue_get_section_name (section); this.vma = bfd_glue_get_section_vma (section); this.size = bfd_glue_get_section_size (section); this.flags = bfd_glue_get_section_flags (section); contents = new ObjectCache ( new ObjectCacheFunc (get_section_contents), section, 5); }
/// <summary> /// Gets the last section of a list of sections that contains the specified flag /// </summary> /// <param name="sections">The section list to search in.</param> /// <param name="characteristics">The flag to search for.</param> /// <returns></returns> public static Section GetLastSectionByFlag(Section[] sections, SectionFlags characteristics) { Section sec = null; foreach (Section s in sections) { if (s.Flags.HasFlag(characteristics)) sec = s; } return sec; }
public AssemblySection(string name, long address, long size, SectionFlags flags) { this.Alias = name; this.Size = size; this.Virtual = address; this.Flags = flags; switch (name) { case ".text": this.Name = SectionType.Text; break; case ".data": this.Name = SectionType.Data; break; case ".bss": this.Name = SectionType.Bss; break; } }
/// <summary> /// Gets the last section of an assembly that contains the specified flag /// </summary> /// <param name="assembly">The assembly to search in.</param> /// <param name="characteristics">The flag to search for.</param> /// <returns></returns> public static Section GetLastSectionByFlag(Win32Assembly assembly, SectionFlags characteristics) { return(GetLastSectionByFlag(assembly._ntHeader.Sections, characteristics)); }
/// <summary> /// Gets the last section of an assembly that contains the specified flag /// </summary> /// <param name="assembly">The assembly to search in.</param> /// <param name="characteristics">The flag to search for.</param> /// <returns></returns> public static Section GetLastSectionByFlag(LWin32 assembly, SectionFlags characteristics) { return GetLastSectionByFlag(assembly._ntHeader.Sections, characteristics); }
/// <summary> /// Creates a new section header with the provided name. /// </summary> /// <param name="name">The name of the new section.</param> /// <param name="characteristics">The section flags to assign.</param> public SectionHeader(string name, SectionFlags characteristics) { Name = name; Characteristics = characteristics; }
/// <summary> /// 设置为未压缩格式 /// </summary> /// <param name="uncompressedSize"></param> public void SetToUncompressFormat() { sectionFlags &= ~(SectionFlags.LZ4Compressed | SectionFlags.ZstdCompressed); sectionCompressedLength = sectionUncompressedLength; }