Example #1
0
            /// <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));
            }
Example #2
0
 public static bool AreTypesEquivalent(IClrObject self, IClrObject other)
 {
     if (self.GetType() != other.GetType())
     {
         return(false);
     }
     return(ClrTypeEqualityComparer.Instance.Equals(self.Type, other.Type));
 }
Example #3
0
        /// <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);
        }
Example #4
0
        public static object GetClrObject(this IClrObject self)
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }

            return(self.ClrObject);
        }
Example #5
0
        /// <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);
        }
Example #6
0
        public static bool TryGetClrObject(this IClrObject self, out object obj)
        {
            if (self != null)
            {
                obj = self.ClrObject;
                return(true);
            }

            obj = null;
            return(false);
        }
Example #7
0
 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());
        }
Example #9
0
        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);
        }
Example #10
0
        /// <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);
        }
Example #11
0
        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);
        }
Example #12
0
 /// <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";
Example #13
0
 /// <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);
Example #14
0
 /// <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;
Example #15
0
 public bool Equals(IClrObject other) => Equals(other as ClrArrayObject);
Example #16
0
 public bool Equals(IClrObject other) => Equals(other as ClrClassObject);
Example #17
0
 public bool Equals(IClrObject other) => Equals(other as ClrPrimitive);
Example #18
0
 /// <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";
Example #19
0
 public bool Equals(IClrObject other) => Equals(other as ClrStructObject);
Example #20
0
 private ClrMethod LookupClrMethod(IClrObject delegateObj, IntPtr pointer)
 {
     return(delegateObj.Type.Heap.Runtime.GetMethodByAddress((ulong)pointer.ToInt64()));
 }