public static MetadataObject ReadVaddr(ulong vaddr, Elf64Reader.ElfHeader ehdr, bool read_references) { if (cache.ContainsKey(vaddr)) { return(cache[vaddr]); } MetadataObject ret = new MetadataObject(); ret.Address = vaddr; ret.ehdr = ehdr; ret.file_offset = ehdr.VaddrToOffset(vaddr); ret.Read(read_references); if (read_references) { cache[vaddr] = ret; } return(ret); }
public MetadataObject GetRoot() { MetadataObject ret = new MetadataObject(); ret.Address = 0; ret.ehdr = this; List <object> asms = new List <object>(); foreach (SymbolTable.Symbol s in stab.AssemblySymbols.Values) { asms.Add(MetadataObject.ReadReference(s.vaddr, this)); } ret.Fields["Assemblies"] = asms.ToArray(); ret.file_offset = 0; ret.LayoutName = "File root"; return(ret); }
public MetadataObject GetSymbols() { MetadataObject ret = new MetadataObject(); ret.Address = 0; ret.ehdr = this; List <object> syms = new List <object>(); foreach (SymbolTable.Symbol s in stab.Symbols.Values) { // Only list those symbols we can actually display try { switch (libtysila.Mangler2.DemangleName(s.Name, this.stab.ass).ObjectType) { case libtysila.Mangler2.ObjectToMangle.ObjectTypeType.Assembly: case libtysila.Mangler2.ObjectToMangle.ObjectTypeType.FieldInfo: case libtysila.Mangler2.ObjectToMangle.ObjectTypeType.MethodInfo: case libtysila.Mangler2.ObjectToMangle.ObjectTypeType.Module: case libtysila.Mangler2.ObjectToMangle.ObjectTypeType.TypeInfo: syms.Add(new MetadataObject.Reference { Address = s.vaddr, ehdr = this, file_offset = s.offset, Name = s.Name, Type = "__sym" }); break; } } catch (Exception) { } } ret.Fields["Symbols"] = syms.ToArray(); ret.file_offset = 0; ret.LayoutName = "File symbols"; return(ret); }
private static string ParseName(MetadataObject obj, string NameExp) { StringBuilder sb = new StringBuilder(); StringBuilder cur_item = new StringBuilder(); bool in_item = false; for (int i = 0; i < NameExp.Length; i++) { char c = NameExp[i]; if (c == '$') { if (in_item) { throw new ParseException("Nested items not allowed"); } cur_item = new StringBuilder(); in_item = true; } else if (c == '{') { if (!in_item) { sb.Append(c); } } else if (c == '}') { if (in_item) { string fname = cur_item.ToString(); if (!obj.Fields.ContainsKey(fname)) { StringBuilder vf_sb = new StringBuilder(); int f_id = 0; foreach (string field_name in obj.Fields.Keys) { if (f_id != 0) { vf_sb.Append(", "); } vf_sb.Append(field_name); f_id++; } string valid_fields = vf_sb.ToString(); throw new ParseException("Field name: " + fname + " not found within type " + obj.LayoutName + "." + Environment.NewLine + "Valid fields: " + valid_fields + "."); } object o = obj.Fields[fname]; if (o is string) { sb.Append((string)o); } else { throw new ParseException("Field name: " + fname + " is not of type string"); } in_item = false; } else { sb.Append(c); } } else if (in_item) { cur_item.Append(c); } else { sb.Append(c); } } return(sb.ToString()); }