예제 #1
0
        private ulong GetFieldAddress(string fieldName, ClrElementType element, string typeName)
        {
            if (IsNull)
            {
                throw new NullReferenceException();
            }

            ClrInstanceField field = Type.GetFieldByName(fieldName);

            if (field == null)
            {
                throw new ArgumentException($"Type '{Type.Name}' does not contain a field named '{fieldName}'");
            }

            if (field.ElementType != element)
            {
                throw new InvalidOperationException($"Field '{Type.Name}.{fieldName}' is not of type '{typeName}'.");
            }

            ulong address = field.GetAddress(Address);

            return(address);
        }
예제 #2
0
        /// <summary>
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public ClrValueClass GetValueClassField(string fieldName)
        {
            ClrInstanceField field = Type.GetFieldByName(fieldName);

            if (field == null)
            {
                throw new ArgumentException($"Type '{Type.Name}' does not contain a field named '{fieldName}'");
            }

            if (!field.IsValueClass)
            {
                throw new ArgumentException($"Field '{Type.Name}.{fieldName}' is not a ValueClass.");
            }

            if (field.Type == null)
            {
                throw new Exception("Field does not have an associated class.");
            }

            ulong addr = field.GetAddress(Address, _interior);

            return(new ClrValueClass(addr, field.Type, true));
        }
예제 #3
0
        /// <summary>
        /// Gets the given field in this object
        /// </summary>
        /// <param name="fieldName">The name of the field.</param>
        /// <returns>The value of the field.</returns>
        public ClrValue GetFieldOrNull(string fieldName)
        {
            if (IsNull)
            {
                return(new ClrValueImpl(Type.Heap));
            }

            ClrInstanceField field = _type.GetFieldByName(fieldName);

            if (field == null)
            {
                throw new ArgumentException($"Type '{_type.Name}' does not contain a field named '{fieldName}'");
            }

            ulong addr      = Address;
            ulong fieldAddr = field.GetAddress(addr);

            if (fieldAddr == 0)
            {
                throw new MemoryReadException(addr);
            }

            return(new ClrValueImpl(_type.Heap.Runtime, fieldAddr, field));
        }
예제 #4
0
 public ClrObject this[ClrInstanceField field] => GetInnerObject(field.GetAddress(Address, IsInterior), field.Type);