private void button6_Click(object sender, EventArgs e) { StartRuntime(); ulong mt = Convert.ToUInt64(textBox5.Text, 16); ClrType myType = AdHoc.GetTypeFromMT(m_runtime, mt); WriteLine("MT: {1:x16} Type: {0}", myType == null ? "*Invalid*" : myType.Name, mt); }
public void DumpClass(ulong MethodTable) { ClrType type = AdHoc.GetTypeFromMT(m_runtime, MethodTable); if (type == null) { WriteLine("No type with Method Table {0:%p}", MethodTable); WriteLine(""); return; } string fileName = type.Module == null || !type.Module.IsFile ? "(dynamic)" : type.Module.FileName; WriteLine("// Method Table: {0}", MethodTable); WriteLine("// Module Address: {0:%p}", type.Module == null ? 0 : type.Module.ImageBase); WriteLine("// Debugging Mode: {0}", type.Module == null ? "(NA in Dynamic Module)" : type.Module.DebuggingMode.ToString()); WriteLine("// Filename: {0}", fileName); WriteLine("namespace {0} {1}", type.Name.Substring(0, type.Name.LastIndexOf(".")), "{"); WriteLine(""); Write(" "); Write("{0}", type.IsInternal ? "internal " : type.IsProtected ? "protected " : type.IsPrivate ? "private " : type.IsPublic ? "public " : "undefinedvisibility "); Write("{0}", type.IsSealed ? "sealed " : ""); Write("{0}", type.IsAbstract ? "abstract " : ""); Write("{0}", type.IsInterface ? "interface " : ""); Write("{0}", type.IsValueClass ? "struct " : ""); Write("{0}", !type.IsValueClass && !type.IsInterface ? "class " : ""); Write("{0}", type.Name.Split('.')[type.Name.Split('.').Length - 1]); if ((type.BaseType != null && type.BaseType.Name != "System.Object") || type.Interfaces.Count > 0) { Write(": "); if (type.BaseType != null && type.BaseType.Name != "System.Object") { Write("<link cmd=\"!wclass {0:%p}\">{1}</link>", HeapStatItem.GetMTOfType(type.BaseType), type.BaseType.Name); if (type.Interfaces.Count > 0) { Write(", "); } } for (int i = 0; i < type.Interfaces.Count; i++) { Write("{0}", type.Interfaces[i].Name); if (i < type.Interfaces.Count - 1) { Write(", "); } } } WriteLine(""); WriteLine("{0}", " {"); WriteLine("\t//"); WriteLine("\t// Fields"); WriteLine("\t//"); WriteLine(""); foreach (var field in type.Fields) { Write("\t"); PrintFieldVisibility(field); } WriteLine(""); WriteLine("\t//"); WriteLine("\t// Static Fields"); WriteLine("\t//"); WriteLine(""); foreach (var field in type.StaticFields) { Write("\t"); PrintFieldVisibility(field, true); } foreach (var field in type.ThreadStaticFields) { Write("\t"); PrintFieldVisibility(field, true); } var properties = from m in type.Methods where m.Name.StartsWith("get_") || m.Name.StartsWith("set_") orderby m.Name.Substring(4).Split('(')[0], -(int)m.Name[0] select m; WriteLine(""); WriteLine("\t//"); WriteLine("\t// Properties"); WriteLine("\t//"); WriteLine(""); List <string> propstr = new List <string>(); int propCount = 0; foreach (ClrMethod met in properties) { string prop = met.Name.Substring(4); bool isFirst = propstr.IndexOf(prop) == -1; if (isFirst) { if (propCount > 0) { WriteLine("\t{0}", "}"); // close previous } Write("\t"); if (met.Name.StartsWith("set_")) { Write("{0} ", met.GetFullSignature().Split('(')[1].Split(')')[0]); } else { Write("/* property * / "); } WriteLine("{0}", prop.Split('(')[0]); WriteLine("\t{0}", "{"); propstr.Add(prop); } WriteLine(""); WriteLine("\t\t// JIT MODE: {0} - THIS IS ONLY VALID FOR .NET 4.5 AND BEYOND", met.CompilationType); if (met.NativeCode != ulong.MaxValue) { WriteLine("\t\t// Click for breakpoint: <cmd link=\"bp {0:%p}\">{0:%p}</link>", met.NativeCode); } else { WriteLine("\t\t// Not JITTED"); } Write("\t\t{0}", met.IsInternal ? "internal " : met.IsProtected ? "protected " : met.IsPrivate ? "private " : met.IsPublic ? "public " : ""); WriteLine("{0} {1}", met.Name.Substring(0, 3), " { } "); propCount++; } if (propCount > 0) { WriteLine("\t{0}", "}"); // close previous } WriteLine(""); WriteLine("\t//"); WriteLine("\t// Methods"); WriteLine("\t//"); WriteLine(""); foreach (var method in type.Methods) { if (!(method.Name.StartsWith("get_") || method.Name.StartsWith("set_"))) { WriteLine(""); WriteLine("\t// JIT MODE: {0} - THIS IS ONLY VALID FOR .NET 4.5 AND BEYOND", method.CompilationType); if (method.NativeCode != ulong.MaxValue) { WriteLine("\t// Click for breakpoint: <cmd link=\"bp {0:%p}\">{0:%p}</link>", method.NativeCode); } else { WriteLine("\t// Not JITTED"); } Write("\t"); Write("{0}", method.IsInternal ? "internal " : method.IsProtected ? "protected " : method.IsPrivate ? "private " : method.IsPublic ? "public " : ""); Write("{0}", method.IsVirtual ? "virtual " : ""); Write("{0}", method.IsStatic ? "static " : ""); //Write("{0} ", method.Type == null ? "object" : method.Type.Name); WriteLine("{0}({1};", method.Name, method.GetFullSignature().Split('(')[method.GetFullSignature().Split('(').Length - 1]); } } WriteLine("{0}", " }"); WriteLine("{0}", "}"); }
private void DumpFields(ulong Address, ClrType type = null) { StartRuntime(); ClrType obj; if (type == null) { obj = m_heap.GetObjectType(Address); } else { obj = type; } if (cache == null) { cache = new HeapCache(m_runtime, ShowProgress); } MDType tp = new MDType(obj); MD_TypeData data; tp.GetHeader(Address, out data); int count = 0; tp.GetAllFieldsDataRawCount(out count); int temp = 0; MD_FieldData[] fields = new MD_FieldData[count]; tp.GetAllFieldsDataRaw(data.isValueType ? 1 : 0, count, fields, out temp); for (int i = 0; i < count; i++) { string typeName; string Name; tp.GetRawFieldTypeAndName(i, out typeName, out Name); MD_TypeData fd; ClrType ftp = AdHoc.GetTypeFromMT(m_runtime, fields[i].MethodTable); MDType ft = new MDType(ftp); ulong pointer = 0; tp.GetRawFieldAddress(Address, data.isValueType ? 1 : 0, i, out pointer); if (fields[i].isValueType) { ft.GetHeader(pointer, out fd); } else { ft.GetHeader(ReadPointer(pointer), out fd); } Write("{0:x16} {1:x4} {5:x16} {6} +{2:x4} {3,30} {4,30} {7} ", fd.module, fd.token, fields[i].offset, TrimRight(typeName, 30), Name, data.MethodTable, fields[i].isThreadStatic ? " thread " : fields[i].isStatic ? " Static " : " ", fields[i].isEnum ? AdHoc.GetEnumName(ftp, ReadPointer(pointer) & (fd.size == 4 ? 0x0000FFFF : ulong.MaxValue)) : "" /*cache.GetFieldValue(Address, Name, obj)*/); ulong effAddress = pointer; if (fd.isValueType) { if (fields[i].isEnum) { WriteLine(""); continue; } try { WriteLine("{0}", ftp.GetValue(pointer)); } catch { WriteLine("{0}", ReadPointer(pointer) & (fd.size == 4 ? 0xFFFFFFFF : fd.size == 8 ? 0x00000000FFFFFFFF : ulong.MaxValue)); } continue; } else { if (pointer != 0) { effAddress = ReadPointer(pointer); } Write("({0:x16}) ", effAddress); if (effAddress == 0) { WriteLine(""); continue; } if (fd.isString) { string str; tp.GetString(effAddress, out str); Write("{0}", str); } WriteLine(""); } } /* * var fields = * from f in obj.Fields * orderby f.Offset * select f; * * foreach (var field in fields) * { * WriteLine("{0:x16} {1:x4} +{2:x4} {3,30} {4,30}", field.Type.Module.AssemblyId, * field.Type.MetadataToken, field.Offset, TrimRight(field.Type.Name, 30), field.Name); * * * } * if (obj.StaticFields.Count > 0) * { * var statFields = * from s in obj.StaticFields * orderby s.Offset * select s; * WriteLine("Static Fields:"); * foreach (var field in statFields) * { * WriteLine("{0:x16} {1:x4} +{2:x4} {3,30} {4,30}", field.Type.Module.AssemblyId, * field.Type.MetadataToken, field.Offset, TrimRight(field.Type.Name, 30), field.Name); * } * } * if (obj.ThreadStaticFields.Count > 0) * { * var threadFields = * from t in obj.ThreadStaticFields * orderby t.Offset * select t; * WriteLine("Thread Static Fields:"); * foreach (var field in threadFields) * { * WriteLine("{0:x16} {1:x4} +{2:x4} {3,30} {4,30}", field.Type.Module.AssemblyId, * field.Type.MetadataToken, field.Offset, TrimRight(field.Type.Name, 30), field.Name); * } * * } */ }