public virtual void show_index_info(IHunk info) { // references from index if (info.refs != null && info.refs.Count > 0) { this.print_extra("refs", string.Format("#{0}", info.refs.Count)); if (!this.brief) { foreach (var @ref in info.refs) { this.print_symbol(~0u, @ref.name, string.Format("({0} bits)", @ref.bits)); } } } // defines from index if (info.defs != null && info.defs.Count > 0) { this.print_extra("defs", string.Format("#{0}", info.defs.Count)); if (!this.brief) { foreach (var d in info.defs) { this.print_symbol((uint) d.value, d.name, string.Format("(type {0})", d.type)); } } } }
public virtual void ParseIndex(Action <Hunk> h) { var hunk = new IndexHunk(); h(hunk); var index_size = this.read_long(); var total_size = index_size * 4; // First read string table var strtab_size = f.ReadBeInt16(); var strtab = f.ReadBytes(strtab_size); total_size -= strtab_size + 2; // Read units var units = new List <Unit>(); hunk.units = units; var unit_no = 0; while (total_size > 2) { // Read name of unit var name_offset = f.ReadBeInt16(); total_size -= 2; if (name_offset == 0) { break; } var unit = new Unit { unit_no = unit_no }; units.Add(unit); ++unit_no; // Generate unit name unit.name = this.get_index_name(strtab, name_offset); // hunks in unit var hunk_begin = f.ReadBeInt16(); var num_hunks = f.ReadBeInt16(); total_size -= 4; unit.hunk_begin_offset = hunk_begin; // For all hunks in unit var ihunks = new List <IHunk>(); unit.hunk_infos = ihunks; for (var a = 0; a < num_hunks; ++a) { var ihunk = new IHunk(); ihunks.Add(ihunk); // get hunk info name_offset = f.ReadBeInt16(); var hunk_size = f.ReadBeInt16(); var hunk_type = f.ReadBeInt16(); total_size -= 6; ihunk.name = this.get_index_name(strtab, name_offset); ihunk.size = hunk_size; ihunk.type = hunk_type & 16383; ihunk.memf = this.SetMemoryFlags(hunk_type & 49152, 14); // get references var num_refs = f.ReadBeInt16(); total_size -= 2; if (num_refs > 0) { var refs = new List <Reference>(); ihunk.refs = refs; for (var b = 0; b < num_refs; ++b) { var @ref = new Reference(); name_offset = f.ReadBeInt16(); total_size -= 2; var name = this.get_index_name(strtab, name_offset); if (name == "") { // 16 bit refs point to the previous zero byte before the string entry... name = this.get_index_name(strtab, name_offset + 1); @ref.bits = 16; } else { @ref.bits = 32; } @ref.name = name; refs.Add(@ref); // get definitions } } var num_defs = f.ReadBeInt16(); total_size -= 2; if (num_defs > 0) { var defs = new List <Definition>(); ihunk.defs = defs; for (var b = 0; b < num_defs; ++b) { name_offset = f.ReadBeInt16(); var def_value = f.ReadBeInt16(); var def_type_flags = f.ReadBeInt16(); var def_type = def_type_flags & 16383; var def_flags = def_type_flags & 49152; total_size -= 6; var name = this.get_index_name(strtab, name_offset); var d = new Definition { name = name, value = def_value, type = def_type }; d.memf = this.SetMemoryFlags(def_flags, 14); defs.Add(d); } } } } // Align hunk to long-word. if (total_size == 2) { f.ReadBeInt16(); } else if (total_size != 0) { throw new BadImageFormatException(string.Format("{0} has invalid padding.", hunk.HunkType)); } }
public virtual void ParseIndex(Action<Hunk> h) { var hunk = new IndexHunk(); h(hunk); var index_size = this.read_long(); var total_size = index_size * 4; // First read string table var strtab_size = f.ReadBeInt16(); var strtab = f.ReadBytes(strtab_size); total_size -= strtab_size + 2; // Read units var units = new List<Unit>(); hunk.units = units; var unit_no = 0; while (total_size > 2) { // Read name of unit var name_offset = f.ReadBeInt16(); total_size -= 2; if (name_offset == 0) break; var unit = new Unit { unit_no = unit_no }; units.Add(unit); ++unit_no; // Generate unit name unit.name = this.get_index_name(strtab, name_offset); // hunks in unit var hunk_begin = f.ReadBeInt16(); var num_hunks = f.ReadBeInt16(); total_size -= 4; unit.hunk_begin_offset = hunk_begin; // For all hunks in unit var ihunks = new List<IHunk>(); unit.hunk_infos = ihunks; for (var a = 0; a < num_hunks; ++a) { var ihunk = new IHunk(); ihunks.Add(ihunk); // get hunk info name_offset = f.ReadBeInt16(); var hunk_size = f.ReadBeInt16(); var hunk_type = f.ReadBeInt16(); total_size -= 6; ihunk.name = this.get_index_name(strtab, name_offset); ihunk.size = hunk_size; ihunk.type = hunk_type & 16383; ihunk.memf = this.SetMemoryFlags(hunk_type & 49152, 14); // get references var num_refs = f.ReadBeInt16(); total_size -= 2; if (num_refs > 0) { var refs = new List<Reference>(); ihunk.refs = refs; for (var b = 0; b < num_refs; ++b) { var @ref = new Reference(); name_offset = f.ReadBeInt16(); total_size -= 2; var name = this.get_index_name(strtab, name_offset); if (name == "") { // 16 bit refs point to the previous zero byte before the string entry... name = this.get_index_name(strtab, name_offset + 1); @ref.bits = 16; } else { @ref.bits = 32; } @ref.name = name; refs.Add(@ref); // get definitions } } var num_defs = f.ReadBeInt16(); total_size -= 2; if (num_defs > 0) { var defs = new List<Definition>(); ihunk.defs = defs; for (var b = 0; b < num_defs; ++b) { name_offset = f.ReadBeInt16(); var def_value = f.ReadBeInt16(); var def_type_flags = f.ReadBeInt16(); var def_type = def_type_flags & 16383; var def_flags = def_type_flags & 49152; total_size -= 6; var name = this.get_index_name(strtab, name_offset); var d = new Definition { name = name, value = def_value, type = def_type }; d.memf = this.SetMemoryFlags(def_flags, 14); defs.Add(d); } } } } // Align hunk to long-word. if (total_size == 2) { f.ReadBeInt16(); } else if (total_size != 0) throw new BadImageFormatException(string.Format("{0} has invalid padding.", hunk.HunkType)); }