Exemplo n.º 1
0
        /// <summary>
        /// Gets the type with the specified name.
        /// </summary>
        /// <param name="name">The type name.</param>
        private CodeType GetTypeByName(string name)
        {
            int moduleIndex = name.IndexOf('!');

            if (moduleIndex > 0)
            {
                if (string.Compare(name.Substring(0, moduleIndex), Name, true) != 0)
                {
                    throw new ArgumentException("Type name contains wrong module name. Don't add it manually, it will be added automatically.");
                }

                name = name.Substring(moduleIndex + 1);
            }

            if (name == CodeType.NakedPointerCodeTypeName)
            {
                return(new NakedPointerCodeType(this));
            }
            else if (name.StartsWith(BuiltinCodeTypes.FakeNameStart))
            {
                return(BuiltinCodeTypes.CreateCodeType(this, name.Substring(BuiltinCodeTypes.FakeNameStart.Length)));
            }

            CodeType codeType    = null;
            bool     clrSearched = false;

            if (clrModule.Cached && ClrModule != null)
            {
                codeType    = GetClrTypeByName(name);
                clrSearched = true;
            }

            try
            {
                if (codeType == null)
                {
                    uint typeId = Context.SymbolProvider.GetTypeId(this, name);

                    if (Context.SymbolProvider.GetTypeTag(this, typeId) != CodeTypeTag.Unsupported)
                    {
                        codeType = TypesById[typeId];
                    }
                }
            }
            catch
            {
            }

            if (!clrSearched && ClrModule != null)
            {
                codeType = GetClrTypeByName(name);
            }

            if (codeType == null)
            {
                throw new Exception(string.Format("Type '{0}' wasn't found", name));
            }

            return(codeType);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Casts the specified variable to type that is usable by this class if it was naked pointer.
        /// </summary>
        /// <param name="variable">The variable.</param>
        internal static Variable CastIfNecessary(Variable variable)
        {
            if (variable.GetCodeType() is NakedPointerCodeType && !variable.IsNull())
            {
                // TODO: CodeType newCodeType = CodeType.Create<T>();
                CodeType newCodeType = BuiltinCodeTypes.GetCodeType <T>(variable.GetCodeType().Module);

                newCodeType = newCodeType.PointerToType;
                return(variable.CastAs(newCodeType));
            }

            return(variable);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads the precalculated array.
        /// </summary>
        private unsafe IReadOnlyList <T> ReadArray()
        {
            // Check if we have phisical constructor in delegates
            var delegates = GetDelegates();

            if (delegates != null && delegates.PhysicalConstructor != null)
            {
                var address     = variable.GetPointerAddress();
                var elementType = variable.GetCodeType().ElementType;

                if (elementType.Module.Process.DumpFileMemoryReader != null)
                {
                    var buffer = Debugger.ReadMemory(elementType.Module.Process, address, (uint)(Length * elementType.Size));

                    return(new BufferedElementCreatorReadOnlyList(delegates, elementType, buffer, address, address));
                }

                return(new ElementCreatorReadOnlyList(delegates, elementType, address));
            }

            // Check if type is basic type and we can read it directly with marshaler.
            Type type = typeof(T);

            if (type.IsPrimitive)
            {
                // Try to use binary conversion of memory blocks
                try
                {
                    CodeType builtinCodeType = BuiltinCodeTypes.GetCodeType <T>(variable.GetCodeType().Module);
                    CodeType elementType     = variable.GetCodeType().ElementType;

                    if ((builtinCodeType == elementType) ||
                        (builtinCodeType.Size == elementType.Size && elementType.IsSimple && builtinCodeType.IsDouble == elementType.IsDouble && builtinCodeType.IsFloat == elementType.IsFloat))
                    {
                        var  address    = variable.GetPointerAddress();
                        uint bytesCount = (uint)(Length * elementType.Size);
                        var  buffer     = Debugger.ReadMemory(elementType.Module.Process, address, bytesCount);

                        if (elementType.Module.Process.DumpFileMemoryReader == null)
                        {
                            if (type != typeof(byte))
                            {
                                T[] result = new T[Length];

                                Buffer.BlockCopy(buffer.Bytes, 0, result, 0, buffer.Bytes.Length);
                                return(result);
                            }

                            return((T[])(object)buffer.Bytes);
                        }
                        else
                        {
                            T[] result = new T[Length];

                            var handle = System.Runtime.InteropServices.GCHandle.Alloc(result, System.Runtime.InteropServices.GCHandleType.Pinned);
                            try
                            {
                                void *pointer = handle.AddrOfPinnedObject().ToPointer();

                                MemoryBuffer.MemCpy(pointer, buffer.BytePointer, bytesCount);
                            }
                            finally
                            {
                                handle.Free();
                            }
                            return(result);
                        }
                    }
                }
                catch
                {
                }
            }

            return(null);
        }