Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiaSymbol"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="symbol">The DIA symbol.</param>
        public DiaSymbol(DiaModule module, IDiaSymbol symbol)
            : base(module)
        {
            SymTagEnum symTag = symbol.symTag;

            this.symbol = symbol;
            Tag         = ConvertToCodeTypeTag(symTag);
            BasicType   = symbol.baseType;
            Id          = symbol.symIndexId;
            if (symTag != SymTagEnum.Exe)
            {
                Name = TypeToString.GetTypeString(symbol);
            }
            else
            {
                Name = "";
            }

            Offset = symbol.offset;

            ulong size = symbol.length;

            if (size > int.MaxValue)
            {
                throw new ArgumentException("Symbol size is unexpected");
            }
            Size = (int)size;
            IsVirtualInheritance = symbol.virtualBaseClass;
        }
Пример #2
0
        private static void SerializeAttributes(IDictionary <string, CfgMetadata> meta, object obj, StringBuilder sb)
        {
            if (meta.Count > 0)
            {
                var pairs = meta.Where(kv => kv.Value.ListType == null).ToArray();
                for (var i = 0; i < pairs.Length; i++)
                {
                    var pair = pairs[i];
                    if (!pair.Value.Attribute.serialize)
                    {
                        continue;
                    }
                    var value = pair.Value.Getter(obj);
                    if (value == null || value.Equals(pair.Value.Attribute.value) || (!pair.Value.Attribute.ValueIsSet && pair.Value.TypeDefault != null && pair.Value.TypeDefault.Equals(value)))
                    {
                        continue;
                    }

                    var type = pair.Value.PropertyInfo.PropertyType;

                    sb.Append(" \"");
                    sb.Append(meta[pair.Key].Attribute.name);
                    sb.Append("\":");
                    sb.Append(ValueToString(type, value));
                    sb.Append(",");
                }
            }
            else
            {
                var dict = obj as IProperties;
                if (dict == null)
                {
                    return;
                }

                foreach (var pair in dict)
                {
                    sb.Append(" \"");
                    sb.Append(pair.Key);
                    sb.Append("\":");
                    sb.Append(TypeToString[pair.Value.GetType()](pair.Value));
                    sb.Append(",");
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiaModule"/> class.
        /// </summary>
        /// <param name="pdbPath">The PDB path.</param>
        /// <param name="module">The module.</param>
        public DiaModule(string pdbPath, Module module)
        {
            Module = module;
            dia    = new DiaSource();
            dia.loadDataFromPdb(pdbPath);
            dia.openSession(out session);
            globalScope   = session.globalScope;
            typeAllFields = new DictionaryCache <uint, List <Tuple <string, uint, int> > >(GetTypeAllFields);
            typeFields    = new DictionaryCache <uint, List <Tuple <string, uint, int> > >(GetTypeFields);
            basicTypes    = SimpleCache.Create(() =>
            {
                var types      = new Dictionary <string, IDiaSymbol>();
                var basicTypes = globalScope.GetChildren(SymTagEnum.SymTagBaseType);

                foreach (var type in basicTypes)
                {
                    try
                    {
                        string typeString = TypeToString.GetTypeString(type);

                        if (!types.ContainsKey(typeString))
                        {
                            types.Add(typeString, type);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                return(types);
            });
            symbolNamesByAddress = new DictionaryCache <uint, Tuple <string, ulong> >((distance) =>
            {
                IDiaSymbol symbol;
                int displacement;
                string name;

                session.findSymbolByRVAEx(distance, SymTagEnum.SymTagNull, out symbol, out displacement);
                symbol.get_undecoratedNameEx(0 | 0x8000 | 0x1000, out name);
                return(Tuple.Create(name, (ulong)displacement));
            });

            session.loadAddress = module.Address;
            enumTypeNames       = new DictionaryCache <uint, Dictionary <ulong, string> >(GetEnumName);
        }
Пример #4
0
        /// <summary>
        /// Initializes this instance of the <see cref="DiaModule"/> class.
        /// </summary>
        /// <param name="diaSession">The DIA session.</param>
        /// <param name="module">The module.</param>
        private void Initialize(IDiaSession diaSession, Module module)
        {
            Module        = module;
            session       = diaSession;
            globalScope   = session.globalScope;
            typeAllFields = new DictionaryCache <uint, List <Tuple <string, uint, int> > >(GetTypeAllFields);
            typeFields    = new DictionaryCache <uint, List <Tuple <string, uint, int> > >(GetTypeFields);
            basicTypes    = SimpleCache.Create(() =>
            {
                var types      = new Dictionary <string, IDiaSymbol>();
                var basicTypes = globalScope.GetChildren(SymTagEnum.BaseType);

                foreach (var type in basicTypes)
                {
                    try
                    {
                        string typeString = TypeToString.GetTypeString(type);

                        if (!types.ContainsKey(typeString))
                        {
                            types.Add(typeString, type);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                return(types);
            });
            symbolNamesByAddress = new DictionaryCache <uint, Tuple <string, ulong> >((distance) =>
            {
                IDiaSymbol symbol;
                int displacement;
                string name;

                session.findSymbolByRVAEx(distance, SymTagEnum.Null, out symbol, out displacement);
                name = symbol.get_undecoratedNameEx(UndecoratedNameOptions.NameOnly | UndecoratedNameOptions.NoEscu);
                return(Tuple.Create(name, (ulong)displacement));
            });

            session.loadAddress = module.Address;
            enumTypeNames       = new DictionaryCache <uint, Dictionary <ulong, string> >(GetEnumName);
        }
Пример #5
0
    public static int Main()
    {
        TypeToString tts = new TypeToString();

        TestLibrary.TestFramework.BeginTestCase("for method: Type.ToString()");

        if (tts.RunTests())
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("PASS");
            return(100);
        }
        else
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("FAIL");
            return(0);
        }
    }
Пример #6
0
 /// <summary>
 /// Gets the name of the specified type.
 /// </summary>
 /// <param name="typeId">The type identifier.</param>
 public string GetTypeName(uint typeId)
 {
     return(TypeToString.GetTypeString(GetTypeFromId(typeId)));
 }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Symbol"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="symbol">The DIA symbol.</param>
        public Symbol(Module module, IDiaSymbol symbol)
        {
            this.symbol = symbol;
            Module      = module;
            Tag         = (SymTagEnum)symbol.symTag;
            BasicType   = (BasicType)symbol.baseType;
            Id          = symbol.symIndexId;
            if (Tag != SymTagEnum.SymTagExe)
            {
                Name = TypeToString.GetTypeString(symbol);
            }
            else
            {
                Name = "";
            }

            Name   = Name.Replace("<enum ", "<").Replace(",enum ", ",");
            Offset = symbol.offset;

            var size = symbol.length;

            if (size > int.MaxValue)
            {
                throw new ArgumentException("Symbol size is unexpected");
            }
            Size = (int)size;

            // Initialize caches
            fields      = SimpleCache.Create(() => symbol.GetChildren(SymTagEnum.SymTagData).Select(s => new SymbolField(this, s)).Where(f => f.Type != null).ToArray());
            baseClasses = SimpleCache.Create(() => symbol.GetChildren(SymTagEnum.SymTagBaseClass).Select(s => Module.GetSymbol(s)).ToArray());
            elementType = SimpleCache.Create(() =>
            {
                if (Tag == SymTagEnum.SymTagPointerType || Tag == SymTagEnum.SymTagArrayType)
                {
                    IDiaSymbol type = symbol.type;

                    if (type != null)
                    {
                        var result = Module.GetSymbol(type);
                        if (Tag == SymTagEnum.SymTagPointerType)
                        {
                            result.pointerType.Value = this;
                        }
                        return(result);
                    }
                }

                return(null);
            });
            pointerType = SimpleCache.Create(() =>
            {
                var result = Module.GetSymbol(symbol.objectPointerType);
                result.elementType.Value = this;
                return(result);
            });
            userType   = SimpleCache.Create(() => (UserType)null);
            enumValues = SimpleCache.Create(() =>
            {
                List <Tuple <string, string> > result = new List <Tuple <string, string> >();

                if (Tag == SymTagEnum.SymTagEnum)
                {
                    foreach (var enumValue in symbol.GetChildren())
                    {
                        result.Add(Tuple.Create(enumValue.name, enumValue.value.ToString()));
                    }
                }

                return(result.ToArray());
            });
            namespaces = SimpleCache.Create(() => SymbolNameHelper.GetSymbolNamespaces(Name));
        }