Beispiel #1
0
        public object ReadTypedField(ulong obj, ClrFieldDescData fd)
        {
            Type typeToRead = null;

            UsefulGlobals.CorFieldTypeToType.TryGetValue(fd.FieldType, out typeToRead);
            if (typeToRead == typeof(object))
            {
                UsefulGlobals.EnsureInit(this);

                if (fd.FieldMethodTable == UsefulGlobals.TypeToMethodTable[typeof(String)])
                {
                    return(ReadFieldValueString(obj, fd));
                }
                else
                {
                    byte[] data = ReadFieldBuffer(obj, fd, (uint)IntPtr.Size);
                    return(SuperBitConverter.ToPointer(data));
                }
            }
            else if (typeToRead != null)
            {
                byte[] data = ReadFieldBuffer(obj, fd, (uint)Marshal.SizeOf(typeToRead));
                return(SuperBitConverter.Convert(data, typeToRead));
            }
            else
            {
                byte[] data = ReadFieldBuffer(obj, fd, (uint)Marshal.SizeOf(typeToRead));
                return(data);
            }
        }
Beispiel #2
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (_isArray && indexes.Length == 1)
            {
                int idx = (int)indexes[0];
                if (idx < 0 || idx >= _arrayData.NumElements)
                {
                    throw new ArgumentOutOfRangeException();
                }

                ulong  memAddr   = _arrayData.FirstElement + (ulong)(_arrayData.ElementSize * idx);
                var    dcma      = _parent.Proc.GetMemoryAccess();
                byte[] data      = new byte[_arrayData.ElementSize];
                uint   bytesRead = 0;

                GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned);
                try
                {
                    dcma.ReadVirtual(memAddr, gch.AddrOfPinnedObject(), _arrayData.ElementSize, out bytesRead);
                }
                finally
                {
                    gch.Free();
                }

                Type targetType = null;
                UsefulGlobals.EnsureInit(_parent);

                if (UsefulGlobals.MethodTableToType.TryGetValue(_arrayData.ElementMethodTable, out targetType))
                {
                    if (targetType == typeof(String))
                    {
                        var addr = SuperBitConverter.ToPointer(data);
                        result = _parent.ReadString(addr);
                    }
                    else
                    {
                        result = SuperBitConverter.Convert(data, targetType);
                    }
                }
                else
                {
                    result = data;
                }
                return(true);
            }

            return(base.TryGetIndex(binder, indexes, out result));
        }