public virtual void show_ext_hunk(ExtHunk hunk) { // definition foreach (var ext in hunk.ext_def) { var tname = ext.type.ToString().Replace("EXT_", "").ToLower(); this.print_symbol(ext.def, ext.name, tname); } // references foreach (var ext in hunk.ext_ref) { var refs = ext.refs; var tname = ext.type.ToString().Replace("EXT_", "").ToLower(); foreach (var @ref in refs) { this.print_symbol(@ref, ext.name, tname); } } // common_base foreach (var ext in hunk.ext_common) { var tname = ext.type.ToString().Replace("EXT_", "").ToLower(); this.print_symbol(ext.common_size, ext.name, tname); } }
public void ParseExt(Action<Hunk> h) { var hunk = new ExtHunk(); h(hunk); var ext_def = new List<ExtObject>(); var ext_ref = new List<ExtObject>(); var ext_common = new List<ExtObject>(); hunk.ext_def = ext_def; hunk.ext_ref = ext_ref; hunk.ext_common = ext_common; var ext_type_size = 1; while (ext_type_size > 0) { // ext type | size ext_type_size = this.read_long(); if (ext_type_size < 0) throw new BadImageFormatException(string.Format("{0} has invalid size.", hunk.HunkType)); var ext_type = (ExtType) (ext_type_size >> (int) ExtType.EXT_TYPE_SHIFT); var ext_size = ext_type_size & (int) ExtType.EXT_TYPE_SIZE_MASK; // ext name string ext_name = this.ReadSizedString(ext_size); if (ext_name == null) throw new BadImageFormatException(string.Format("{0} has invalid name.", hunk.HunkType)); else if (ext_name.Length == 0) break; // create local ext object var ext = new ExtObject { type = ext_type, name = ext_name }; // check and setup type name if (!ext_names.ContainsKey(ext_type)) throw new BadImageFormatException(string.Format("{0} has unspported ext entry {1}.", hunk.HunkType, ext_type)); // ext common if (ext_type == ExtType.EXT_ABSCOMMON || ext_type == ExtType.EXT_RELCOMMON) { ext.common_size = (uint) this.read_long(); ext_common.Add(ext); // ext def } else if (ext_type == ExtType.EXT_DEF || ext_type == ExtType.EXT_ABS || ext_type == ExtType.EXT_RES) { ext.def = f.ReadBeUInt32(); ext_def.Add(ext); } else { // ext ref var num_refs = this.read_long(); if (num_refs == 0) { num_refs = 1; } var refs = new List<uint>(); for (int a = 0; a < num_refs; ++a) { var @ref = f.ReadBeUInt32(); refs.Add(@ref); } ext.refs = refs; ext_ref.Add(ext); } } }