/// <summary> /// Extracts data from the provided object /// </summary> /// <param name="clrObject">The object.</param> /// <param name="clrRuntime">The runtime.</param> /// <returns>Extracted dump object</returns> /// <inheritdoc /> public DumpObject Extract(IClrObject clrObject, IClrRuntime clrRuntime) { var text = clrObject.GetStringField("text"); return(new ButtonDumpObject(clrObject.Address, clrObject.Type.Name, clrObject.Size, clrRuntime.Heap.GetGeneration(clrObject.Address), text)); }
public static bool AreTypesEquivalent(IClrObject self, IClrObject other) { if (self.GetType() != other.GetType()) { return(false); } return(ClrTypeEqualityComparer.Instance.Equals(self.Type, other.Type)); }
/// <summary> /// Extracts data from the provided object /// </summary> /// <param name="clrObject">The object.</param> /// <param name="clrRuntime">The runtime.</param> /// <returns>Extracted dump object</returns> /// <inheritdoc /> public DumpObject Extract(IClrObject clrObject, IClrRuntime clrRuntime) { var value = (string)clrObject.Type.GetValue(clrObject.Address); var heapObject = new StringDumpObject(clrObject.Address, "System.String", clrObject.Size, value, clrRuntime.Heap.GetGeneration(clrObject.Address)); return(heapObject); }
public static object GetClrObject(this IClrObject self) { if (self == null) { throw new ArgumentNullException("self"); } return(self.ClrObject); }
/// <summary> /// Extracts data from the provided object /// </summary> /// <param name="clrObject">The object.</param> /// <param name="clrRuntime">The runtime.</param> /// <returns>Extracted dump object</returns> public DumpObject Extract(IClrObject clrObject, IClrRuntime clrRuntime) { var address = clrObject.Address; var gen = clrRuntime.Heap.GetGeneration(address); var size = clrObject.Size; var name = clrObject.Type.Name; var dumpObject = new DumpObject(address, name, size, gen); return(dumpObject); }
public static bool TryGetClrObject(this IClrObject self, out object obj) { if (self != null) { obj = self.ClrObject; return(true); } obj = null; return(false); }
public static T CastAs <T>(this IClrObject obj) { if (Equals(default(T), obj)) { return(default(T)); } if (TryCastAs(obj, out T result)) { return(result); } throw new InvalidCastException($"This object is a {obj.GetType().Name} and cannot be accessed as a {typeof(T).Name}"); }
/// <summary> /// Creates the object. /// </summary> /// <param name="cur">The current.</param> public void CreateObject(IClrObject cur) { var handler = DumpObjectExtractors.FirstOrDefault(h => h.CanExtract(cur, Runtime)); if (handler == null) { return; } var toAdd = handler.Extract(cur, Runtime); Objects.Add(toAdd.Address, toAdd); ObjectGraph.Add(toAdd.Address, cur.EnumerateObjectReferences().Select(x => x.Address).ToList()); ObjectToTypeMapping.Add(toAdd.Address, cur.Type.ToKeyType()); }
public bool TryReadValue <T>(IClrObject obj, out T value) { var structObj = obj as ClrStructObject; if (structObj?.Type.CanBeAssignedTo <Guid>() == true) { var bytes = new byte[16]; var count = structObj.Type.Heap.ReadMemory(structObj.Address, bytes, 0, 16); if (count != 16) { throw new Exception(); } var guid = new Guid(bytes); value = Util.ForceCast <Guid, T>(guid); return(true); } value = default(T); return(false); }
/// <summary> /// Two objects at the same address in the same heap should be of the same type. /// </summary> /// <param name="self"></param> /// <param name="other"></param> /// <returns></returns> public static bool AssertTypesEquivalent(IClrObject self, IClrObject other) { if (!ReferenceEquals(self.Type.Heap, other.Type.Heap)) { return(false); } Debug.Assert(ClrTypeEqualityComparer.Instance.Equals(self.Type, other.Type), "Mismatched ClrTypes at the same address.", "This: {0}\nOther: {1}", self.Type, other.Type); if (self.GetType() == other.GetType()) { return(true); } Debug.Fail("Mismatched IClrObject types at the same address.", $"This: {self.GetType()}\nOther: {other.GetType()}"); return(false); }
private static bool TryCastAs <T>(IClrObject obj, out T value) { if (obj is T casted) { value = casted; return(true); } if (new ValueReader().TryReadValue(obj, out value)) { return(true); } if (obj is ClrPrimitive primitive) { if (primitive.Value is T) { value = primitive.ValueAs <T>(); return(true); } } value = default(T); return(false); }
/// <summary> /// Determines whether this instance can extract from the provided object /// </summary> /// <param name="clrObject">The object to try to get values from</param> /// <param name="clrRuntime">The clr runtime being used</param> /// <returns><c>true</c> if this instance can extract from the object; otherwise, <c>false</c>.</returns> /// <inheritdoc /> public bool CanExtract(IClrObject clrObject, IClrRuntime clrRuntime) => clrObject.Type?.Name == "System.String";
/// <summary> /// Determines if this instance and another specific <see cref="!:ClrObject" /> have the same value. /// <para>Instances are considered equal when they have same <see cref="!:ClrObject.Address" />.</para> /// </summary> /// <param name="other">The <see cref="!:ClrObject" /> to compare to this instance.</param> /// <returns> /// <c>true</c> if the <see cref="!:ClrObject.Address" /> of the parameter is same as /// <see cref="!:ClrObject.Address" /> in this instance; <c>false</c> otherwise. /// </returns> /// <inheritdoc /> public bool Equals(IClrObject other) => Object.Equals((other as ClrObjectAdapter)?.Object);
/// <summary> /// Determines whether this instance can extract from the provided object /// </summary> /// <param name="clrObject">The object to try to get values from</param> /// <param name="clrRuntime">The clr runtime being used</param> /// <returns><c>true</c> if this instance can extract from the object; otherwise, <c>false</c>.</returns> public bool CanExtract(IClrObject clrObject, IClrRuntime clrRuntime) => true;
public bool Equals(IClrObject other) => Equals(other as ClrArrayObject);
public bool Equals(IClrObject other) => Equals(other as ClrClassObject);
public bool Equals(IClrObject other) => Equals(other as ClrPrimitive);
/// <summary> /// Determines whether this instance can extract from the provided object /// </summary> /// <param name="clrObject">The object to try to get values from</param> /// <param name="clrRuntime">The clr runtime being used</param> /// <returns><c>true</c> if this instance can extract from the object; otherwise, <c>false</c>.</returns> /// <inheritdoc /> public bool CanExtract(IClrObject clrObject, IClrRuntime clrRuntime) => clrObject.Type.Name == "System.Windows.Forms.Button";
public bool Equals(IClrObject other) => Equals(other as ClrStructObject);
private ClrMethod LookupClrMethod(IClrObject delegateObj, IntPtr pointer) { return(delegateObj.Type.Heap.Runtime.GetMethodByAddress((ulong)pointer.ToInt64())); }