Esempio n. 1
0
            public void GetSymbolForAddress(ulong addr, ref Symbol ret)
            {
                IDiaSymbol symbol  = null;
                SymTagEnum tagEnum = SymTagEnum.SymTagFunction;

                diaSession.findSymbolByVA((ulong)addr, tagEnum, out symbol);

                if (symbol != null)
                {
                    ret.functionName    = (tagEnum == SymTagEnum.SymTagNull ? symbol.undecoratedName : symbol.name);
                    ret.address         = addr;
                    ret.functionAddress = symbol.virtualAddress;

                    IDiaEnumLineNumbers lineNumbers;
                    diaSession.findLinesByVA(addr, 1, out lineNumbers);
                    uint           celt = 0;
                    IDiaLineNumber line;
                    while (true)
                    {
                        lineNumbers.Next(1, out line, out celt);
                        if (celt == 1)
                        {
                            ret.fileName = line.sourceFile.fileName;
                            ret.line     = line.lineNumber;
                            break;
                        }
                        if (celt != 1)
                        {
                            break;
                        }
                    }
                }
            }
Esempio n. 2
0
        /// <summary>
        /// Converts <see cref="SymTagEnum"/> to <see cref="CodeTypeTag"/>.
        /// </summary>
        public static CodeTypeTag ToCodeTypeTag(this SymTagEnum tag)
        {
            switch (tag)
            {
            case SymTagEnum.ArrayType:
                return(CodeTypeTag.Array);

            case SymTagEnum.BaseType:
                return(CodeTypeTag.BuiltinType);

            case SymTagEnum.UDT:
                // TODO: What about Structure/Union? IDiaSymbol.udtKind might help...
                return(CodeTypeTag.Class);

            case SymTagEnum.Enum:
                return(CodeTypeTag.Enum);

            case SymTagEnum.FunctionType:
                return(CodeTypeTag.Function);

            case SymTagEnum.PointerType:
                return(CodeTypeTag.Pointer);

            case SymTagEnum.BaseClass:
                return(CodeTypeTag.BaseClass);

            case SymTagEnum.Exe:
                return(CodeTypeTag.ModuleGlobals);

            default:
                return(CodeTypeTag.Unsupported);
            }
        }
Esempio n. 3
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;
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <param name="tag">The tag.</param>
        public static IEnumerable<IDiaSymbol> GetChildren(this IDiaSymbol symbol, SymTagEnum tag = SymTagEnum.SymTagNull)
        {
            IDiaEnumSymbols symbols;

            symbol.findChildren(tag, null, 0, out symbols);
            return symbols.Enum();
        }
Esempio n. 5
0
    public static IDiaSymbol FindSymbol(String symName, IDiaSymbol parent, SymTagEnum symTag)
    {
        IDiaEnumSymbols e;
        parent.findChildren(symTag,
                            symName,
                            (uint)(NameSearchOptions.nsfCaseSensitive),
                            out e);

        IDiaSymbol s;
        uint celt;

        if (e == null || e.count == 0)
            return null;

        e.Next(1, out s, out celt);

        if (e.count > 1)
        {
            for (int i = 1; i < e.count; i++)
            {
                IDiaSymbol s2;
                e.Next(1, out s2, out celt);

                // Diasym reader returns multiple symbols with same RVA in some cases. Issue the warning only
                // if the returned symbols actually differ.
                if (s.virtualAddress != s2.virtualAddress)
                {
                    Shell.Error("Symbol " + symName + " has " + e.count + " matches. Taking first.");
                    break;
                }
            }
        }

        return s;
    }
Esempio n. 6
0
    public static IDiaSymbol FindClassSymbol(String name, IDiaSymbol sym, SymTagEnum tag)
    {
        IDiaSymbol res = null;
        //Console.WriteLine("Looking for " + name + " in " + sym.name);

        res = Util.FindSymbol(name, sym, tag);

        if (res == null)
        {
            IDiaEnumSymbols e;

            sym.findChildren(
                SymTagEnum.SymTagBaseClass,
                null,
                (uint)NameSearchOptions.nsNone,
                out e);

            if (e == null || e.count == 0)
                return null;

            for (int i = 0; i < e.count && res == null; i++)
            {
                UInt32 celt;
                IDiaSymbol s;
                e.Next(1, out s, out celt);
                res = FindClassSymbol(name, s.type, tag);
            }
        }

        return res;
    }
Esempio n. 7
0
        /// <summary>
        /// Gets the child symbol.
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <param name="name">The name.</param>
        /// <param name="tag">The tag.</param>
        public static IDiaSymbol GetChild(this IDiaSymbol symbol, string name, SymTagEnum tag = SymTagEnum.SymTagNull)
        {
            IDiaEnumSymbols symbols;

            symbol.findChildren(tag, name, 0, out symbols);
            return symbols.Enum().FirstOrDefault();
        }
Esempio n. 8
0
        public static IDiaSymbol FindClassSymbol(String name, IDiaSymbol sym, SymTagEnum tag)
        {
            IDiaSymbol res = null;

            //Console.WriteLine("Looking for " + name + " in " + sym.name);

            res = Util.FindSymbol(name, sym, tag);

            if (res == null)
            {
                IDiaEnumSymbols e;

                sym.findChildren(
                    SymTagEnum.SymTagBaseClass,
                    null,
                    (uint)NameSearchOptions.nsNone,
                    out e);

                if (e == null || e.count == 0)
                {
                    return(null);
                }

                for (int i = 0; i < e.count && res == null; i++)
                {
                    UInt32     celt;
                    IDiaSymbol s;
                    e.Next(1, out s, out celt);
                    res = FindClassSymbol(name, s.type, tag);
                }
            }

            return(res);
        }
Esempio n. 9
0
        private IEnumerable <Symbol> CreateChildrenImpl(SymTagEnum symbolTagType, string symbolName, NameSearchOptions searchOptions)
        {
            IDiaEnumSymbols enumSymbols = null;

            try
            {
                _sym.findChildren(symbolTagType, symbolName, (uint)searchOptions, out enumSymbols);
                if (enumSymbols == null)
                {
                    yield break;
                }

                while (true)
                {
                    uint       celt = 0;
                    IDiaSymbol symbol;
                    enumSymbols.Next(1, out symbol, out celt);
                    if (celt != 1)
                    {
                        break;            //No more symbols
                    }
                    yield return(Symbol.Create(symbol));
                }
            }
            finally
            {
                if (enumSymbols != null)
                {
                    Marshal.ReleaseComObject(enumSymbols);
                }
            }
        }
Esempio n. 10
0
        public static ComPtr<IDiaSymbol> GetSymbol(this IDiaSymbol symbol, SymTagEnum symTag, string name, Predicate<IDiaSymbol> filter = null) {
            var result = new ComPtr<IDiaSymbol>();

            IDiaEnumSymbols enumSymbols;
            symbol.findChildren(symTag, name, 1, out enumSymbols);
            using (ComPtr.Create(enumSymbols)) {
                int n = enumSymbols.count;
                if (n == 0) {
                    Debug.Fail("Symbol '" + name + "' was not found.");
                    throw new ArgumentException();
                }

                try {
                    for (int i = 0; i < n; ++i) {
                        using (var item = ComPtr.Create(enumSymbols.Item((uint)i))) {
                            if (filter == null || filter(item.Object)) {
                                if (result.Object == null) {
                                    result = item.Detach();
                                } else {
                                    Debug.Fail("Found more than one symbol named '" + name + "' and matching the filter.");
                                    throw new ArgumentException();
                                }
                            }
                        }
                    }
                } catch {
                    result.Dispose();
                    throw;
                }
            }

            return result;
        }
Esempio n. 11
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <param name="tag">The tag.</param>
        public static IEnumerable <IDiaSymbol> GetChildren(this IDiaSymbol symbol, SymTagEnum tag = SymTagEnum.SymTagNull)
        {
            IDiaEnumSymbols symbols;

            symbol.findChildren(tag, null, 0, out symbols);
            return(symbols.Enum());
        }
Esempio n. 12
0
        /// <summary>
        /// Gets the child symbol.
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <param name="name">The name.</param>
        /// <param name="tag">The tag.</param>
        public static IDiaSymbol GetChild(this IDiaSymbol symbol, string name, SymTagEnum tag = SymTagEnum.SymTagNull)
        {
            IDiaEnumSymbols symbols;

            symbol.findChildren(tag, name, 0, out symbols);
            return(symbols.Enum().FirstOrDefault());
        }
Esempio n. 13
0
        /// <summary>
        /// Converts <see cref="SymTagEnum"/> to <see cref="CodeTypeTag"/>.
        /// </summary>
        public static CodeTypeTag ConvertToCodeTypeTag(SymTagEnum tag)
        {
            switch (tag)
            {
            case SymTagEnum.ArrayType:
                return(CodeTypeTag.Array);

            case SymTagEnum.BaseType:
                return(CodeTypeTag.BuiltinType);

            case SymTagEnum.UDT:
                // TODO: What about Structure/Union?
                return(CodeTypeTag.Class);

            case SymTagEnum.Enum:
                return(CodeTypeTag.Enum);

            case SymTagEnum.FunctionType:
                return(CodeTypeTag.Function);

            case SymTagEnum.PointerType:
                return(CodeTypeTag.Pointer);

            case SymTagEnum.BaseClass:
                return(CodeTypeTag.BaseClass);

            case SymTagEnum.Exe:
                return(CodeTypeTag.ModuleGlobals);

            default:
                return(CodeTypeTag.Unsupported);
            }
        }
Esempio n. 14
0
 public static ComPtr <IDiaSymbol>[] GetSymbols(this IDiaSymbol symbol, SymTagEnum symTag, string name)
 {
     symbol.findChildren(symTag, name, 1, out IDiaEnumSymbols enumSymbols);
     using (ComPtr.Create(enumSymbols))
     {
         int n = enumSymbols.count;
         ComPtr <IDiaSymbol>[] result = new ComPtr <IDiaSymbol> [n];
         try
         {
             for (int i = 0; i < n; ++i)
             {
                 result[i] = ComPtr.Create(enumSymbols.Item((uint)i));
             }
         }
         catch
         {
             foreach (ComPtr <IDiaSymbol> item in result)
             {
                 item.Dispose();
             }
             throw;
         }
         return(result);
     }
 }
Esempio n. 15
0
 internal SymbolInformation(SymTagEnum tag, long size, int type_index, SymbolLoadedModule module, string name)
 {
     Name      = name;
     Size      = size;
     Module    = module;
     TypeIndex = type_index;
     Type      = MapType(tag);
 }
        /// <summary>
        /// Gets the code type tag of the specified type.
        /// </summary>
        /// <param name="typeId">The type identifier.</param>
        public CodeTypeTag GetTypeTag(uint typeId)
        {
            using (ProcessSwitcher switcher = new ProcessSwitcher(DbgEngDll.StateCache, Module.Process))
            {
                SymTagEnum symTag = DbgEngSymbolProvider.typedData[Tuple.Create(Module.Address, typeId, Module.Process.PebAddress)].Tag;

                return(symTag.ToCodeTypeTag());
            }
        }
Esempio n. 17
0
        private bool CheckTypeTag(long module_base, int type_index, SymTagEnum tag)
        {
            var tag_check = GetSymbolTag(module_base, type_index);

            if (!tag_check.HasValue)
            {
                return(false);
            }
            return(tag_check.Value == tag);
        }
Esempio n. 18
0
        public int GetSymTag(out SymTagEnum symTagEnum)
        {
            symTagEnum = default(SymTagEnum);
            int _symTagEnum;
            int hr = S.StdCall <int>(GetVTableMember(4), Punk, out _symTagEnum);

            GC.KeepAlive(this);
            symTagEnum = (SymTagEnum)_symTagEnum;
            return(hr);
        }
Esempio n. 19
0
 public int FindSymbolByRVA(int rva, SymTagEnum symTag, out IDiaSymbol symbol)
 {
     symbol = null;
     IntPtr _symbol;
     int hr = S.StdCall<int>(GetVTableMember(14), Punk, rva, (int)symTag, out _symbol);
     GC.KeepAlive(this);
     if (hr != S_OK)
         return hr;
     symbol = new IDiaSymbol(_symbol);
     return hr;
 }
Esempio n. 20
0
 private IDiaSymbol FindSymbol(SymTagEnum symTag, string symbolName)
 {
     foreach (var pdb in pdbEntries)
     {
         var result = pdb.session.findChildren(pdb.session.globalScope, symTag, symbolName, NameSearchOptions.CaseSensitive);
         if (result.count > 0)
         {
             return(result.Item(0));
         }
     }
     throw new KeyNotFoundException();
 }
Esempio n. 21
0
 /// <summary>
 /// Gets all children for this symbol
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="symTag"></param>
 /// <returns></returns>
 public static IEnumerable<IDiaSymbol> EnumerateChildren(this IDiaSymbol parent, SymTagEnum symTag)
 {
     IDiaEnumSymbols enumSymbols;
     parent.findChildren(symTag, null, 0, out enumSymbols);
     IDiaSymbol curSymbol;
     uint fetched;
     enumSymbols.Next(1, out curSymbol, out fetched);
     while (fetched == 1)
     {
         yield return curSymbol;
         enumSymbols.Next(1, out curSymbol, out fetched);
     }
 }
Esempio n. 22
0
        private String GetBoundString(IDiaSymbol bound)
        {
            SymTagEnum   tag  = (SymTagEnum)bound.symTag;
            LocationType kind = (LocationType)bound.locationType;

            System.Diagnostics.Debugger.Break();
            if (tag == SymTagEnum.SymTagData && kind == LocationType.LocIsConstant)
            {
                return(GetVariantString(bound.value));
            }

            return(bound.name);
        }
Esempio n. 23
0
    public static ComPtr<IDiaSymbol> FindChildSymbol(ComPtr<IDiaSymbol> parent, SymTagEnum tag, string name) {
      var result = new ComPtr<IDiaSymbol>();

      IDiaEnumSymbols enumerator;
      parent.Ptr.findChildren(tag, name, 1, out enumerator);
      using (ComPtr.Create(enumerator)) {
        if (enumerator.count == 0)
          return new ComPtr<IDiaSymbol>();

        result = ComPtr.Create(enumerator.Item((uint)0));
      }

      return result;
    }
Esempio n. 24
0
        public DiaSymbol FindSymbolByRVA(IntPtr rva, SymTagEnum symTag)
        {
            int        hr;
            IDiaSymbol symbol;

            hr = session.findSymbolByRVA((uint)rva, symTag, out symbol);

            if (hr != VSConstants.S_OK)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            return(new DiaSymbol(symbol));
        }
Esempio n. 25
0
        public int FindSymbolByRVA(int rva, SymTagEnum symTag, out IDiaSymbol symbol)
        {
            symbol = null;
            IntPtr _symbol;
            int    hr = S.StdCall <int>(GetVTableMember(14), Punk, rva, (int)symTag, out _symbol);

            GC.KeepAlive(this);
            if (hr != S_OK)
            {
                return(hr);
            }
            symbol = new IDiaSymbol(_symbol);
            return(hr);
        }
Esempio n. 26
0
        internal static IDiaSymbol TryGetDiaSymbol(IDiaSymbol symbol, SymTagEnum symTag, string name, out string error)
        {
            symbol.findChildren(symTag, name, 1, out IDiaEnumSymbols enumSymbols);

            if (enumSymbols.count != 1)
            {
                error = $"TryGetDiaSymbols() enumSymbols.count {enumSymbols.count} != 1";

                ReleaseComObject(enumSymbols);

                return(null);
            }

            error = null;
            return(enumSymbols.Item(0u));
        }
Esempio n. 27
0
        public async Task <SSymbolNameAndDisplacement> LookupSymbolName(ulong pointer)
        {
            try {
                SModule module = await this.debuggerEngine.GetModuleForAddress(pointer);

                Dia2Lib.IDiaSession session = await this.debuggerEngine.DiaLoader.LoadDiaSession(module.Name);

                if (session != null)
                {
                    // We have a DIA session; use it.
                    Dia2Lib.IDiaSymbol symbol;
                    ulong rva = pointer - module.BaseAddress;
                    session.findSymbolByRVA((uint)rva, Dia2Lib.SymTagEnum.SymTagNull, out symbol);

                    // Blocks don't have names.  Walk up to the nearest non-block parent.
                    while ((Dia2Lib.SymTagEnum)symbol.symTag == Dia2Lib.SymTagEnum.SymTagBlock)
                    {
                        symbol = symbol.lexicalParent;
                    }

                    SymTagEnum symTag = (SymTagEnum)symbol.symTag;
                    string     name;
                    if (symTag == SymTagEnum.SymTagPublicSymbol || symTag == SymTagEnum.SymTagThunk)
                    {
                        // Public symbols have decorated names that need to be undecorated (see dbghelp!diaFillSymbolInfo).
                        symbol.get_undecoratedNameEx(0x1000, out name);
                    }
                    else
                    {
                        name = symbol.name;
                    }

                    return(new SSymbolNameAndDisplacement()
                    {
                        Module = module.Name,
                        Name = name,
                        Displacement = (ulong)(rva - symbol.relativeVirtualAddress)
                    });
                }
                else
                {
                    return(await this.debuggerEngine.LookupSymbolName(pointer));
                }
            } catch {
                throw new DebuggerException(String.Format("Invalid symbol address: 0x{0:x8}", pointer));
            }
        }
Esempio n. 28
0
        void IDiaSession.findChildren(IDiaSymbol parent, SymTagEnum symTag, string name, uint compareFlags, out IDiaEnumSymbols ppResult)
        {
            dynamic typ = null;

            if (!Dia3.StructCache.ContainsKey(name))
            {
                var json      = SymAPI.TypeDef(name, CV);
                var converter = new Newtonsoft.Json.Converters.ExpandoObjectConverter();
                var obj       = JsonConvert.DeserializeObject <List <ExpandoObject> >(json.Result, converter);
                // we access just the first object back
                Dia3.StructCache.TryAdd(name, obj.First());
            }
            Dia3.StructCache.TryGetValue(name, out typ);

            ppResult = new EnumSymbols(CV, EnumSymType.Sym, typ);
            return;
        }
Esempio n. 29
0
        private static SymbolInformationType MapType(SymTagEnum tag)
        {
            switch (tag)
            {
            case SymTagEnum.SymTagUDT:
                return(SymbolInformationType.UserDefinedType);

            case SymTagEnum.SymTagEnum:
                return(SymbolInformationType.EnumeratedType);

            case SymTagEnum.SymTagBaseType:
                return(SymbolInformationType.BaseType);

            default:
                return(SymbolInformationType.UndefinedType);
            }
        }
Esempio n. 30
0
        private TypeInformation CreateType(TypeInformationCache type_cache, SymTagEnum tag,
                                           long module_base, int index, long size, SymbolLoadedModule module, string name,
                                           long address = 0)
        {
            if (type_cache.HasEntry(module_base, index))
            {
                return(type_cache.GetEntry(module_base, index));
            }

            TypeInformation ret;

            switch (tag)
            {
            case SymTagEnum.SymTagUDT:
                ret = CreateUserDefinedType(type_cache, module_base, index, module, name);
                break;

            case SymTagEnum.SymTagEnum:
                ret = CreateEnumType(type_cache, module_base, index, module, name);
                break;

            case SymTagEnum.SymTagBaseType:
                ret = CreateBaseType(type_cache, module_base, index, module);
                break;

            case SymTagEnum.SymTagPointerType:
                ret = CreatePointerType(type_cache, module_base, index, module);
                break;

            case SymTagEnum.SymTagArrayType:
                ret = CreateArrayType(type_cache, module_base, index, module);
                break;

            case SymTagEnum.SymTagFunction:
                ret = CreateFunctionType(type_cache, module_base, index, module, name, address);
                break;

            default:
                Debug.WriteLine(tag.ToString());
                ret = new TypeInformation(tag, size, index, module, name);
                break;
            }

            type_cache.AddEntry(module_base, index, ret);
            return(ret);
        }
Esempio n. 31
0
        public static ComPtr <IDiaSymbol> GetSymbol(this IDiaSymbol symbol, SymTagEnum symTag, string name, Predicate <IDiaSymbol> filter = null)
        {
            ComPtr <IDiaSymbol> result = new ComPtr <IDiaSymbol>();

            symbol.findChildren(symTag, name, 1, out IDiaEnumSymbols enumSymbols);
            using (ComPtr.Create(enumSymbols))
            {
                int n = enumSymbols.count;
                if (n == 0)
                {
                    Debug.Fail("Symbol '" + name + "' was not found.");
                    throw new ArgumentException();
                }

                try
                {
                    for (int i = 0; i < n; ++i)
                    {
                        using (ComPtr <T> item = ComPtr.Create(enumSymbols.Item((uint)i)))
                        {
                            if (filter == null || filter(item.Object))
                            {
                                if (result.Object == null)
                                {
                                    result = item.Detach();
                                }
                                else
                                {
                                    Debug.Fail("Found more than one symbol named '" + name + "' and matching the filter.");
                                    throw new ArgumentException();
                                }
                            }
                        }
                    }
                }
                catch
                {
                    result.Dispose();
                    throw;
                }
            }

            return(result);
        }
Esempio n. 32
0
        private ConstantCache LoadGlobalConstantsFromDiaSession(IDiaSession diaSession)
        {
            List <SConstantResult> constants = new List <SConstantResult>();

            diaSession.findChildren(diaSession.globalScope, SymTagEnum.SymTagData, null, 0, out IDiaEnumSymbols symbols);
            foreach (IDiaSymbol symbol in symbols)
            {
                SymTagEnum symTag = (SymTagEnum)symbol.symTag;
                if (symbol.locationType == (uint)DiaHelpers.LocationType.LocIsConstant)
                {
                    constants.Add(new SConstantResult()
                    {
                        ConstantName = symbol.name, Value = (ulong)symbol.value
                    });
                }
            }

            return(new ConstantCache(constants));
        }
Esempio n. 33
0
 public static ComPtr<IDiaSymbol>[] GetSymbols(this IDiaSymbol symbol, SymTagEnum symTag, string name) {
     IDiaEnumSymbols enumSymbols;
     symbol.findChildren(symTag, name, 1, out enumSymbols);
     using (ComPtr.Create(enumSymbols)) {
         int n = enumSymbols.count;
         var result = new ComPtr<IDiaSymbol>[n];
         try {
             for (int i = 0; i < n; ++i) {
                 result[i] = ComPtr.Create(enumSymbols.Item((uint)i));
             }
         } catch {
             foreach (var item in result) {
                 item.Dispose();
             }
             throw;
         }
         return result;
     }
 }
Esempio n. 34
0
 public int FindChildren(IDiaSymbol parent, SymTagEnum symTag, String name, NameSearchOptions compareFlags, out IDiaEnumSymbols enumSymbols)
 {
     enumSymbols = null;
     IntPtr _enumSymbols;
     int hr;
     unsafe
     {
         fixed (char* _name = name)
         {
             hr = S.StdCall<int>(GetVTableMember(8), Punk, parent.Punk, (int)symTag, _name, (int)compareFlags, out _enumSymbols);
         }
     }
     GC.KeepAlive(this);
     GC.KeepAlive(parent);
     if (hr != S_OK)
         return hr;
     enumSymbols = new IDiaEnumSymbols(_enumSymbols);
     return hr;
 }
Esempio n. 35
0
        public DiaSymbol FindClassSymbol(String name, SymTagEnum tag)
        {
            DiaSymbol  res = null;
            IDiaSymbol sym = Util.FindClassSymbol(name, m_symbol, tag);

            if (sym != null)
            {
                if ((SymTagEnum)sym.symTag == SymTagEnum.SymTagData)
                {
                    res = new DiaDataSymbol(sym);
                }
                else
                {
                    res = new DiaSymbol(sym);
                }
            }

            return(res);
        }
Esempio n. 36
0
        public unsafe int FindChildren(IDiaSymbol parent, SymTagEnum symTag, string name, NameSearchOptions compareFlags, out IDiaEnumSymbols enumSymbols)
        {
            enumSymbols = null;
            IntPtr _enumSymbols;
            int    hr;

            fixed(char *_name = name)
            {
                hr = S.StdCall <int>(GetVTableMember(8), Punk, parent.Punk, (int)symTag, _name, (int)compareFlags, out _enumSymbols);
            }

            GC.KeepAlive(this);
            GC.KeepAlive(parent);
            if (hr != S_OK)
            {
                return(hr);
            }
            enumSymbols = new IDiaEnumSymbols(_enumSymbols);
            return(hr);
        }
Esempio n. 37
0
        /// <summary>
        /// Gets the stack frame locals.
        /// </summary>
        /// <param name="block">The block.</param>
        /// <param name="relativeAddress">The relative address or uint.MaxValue if only first children are desired.</param>
        /// <param name="variables">The variables.</param>
        /// <param name="frame">The frame.</param>
        /// <param name="module">The module.</param>
        /// <param name="arguments">if set to <c>true</c> only arguments will be returned.</param>
        private static void GetFrameLocals(IDiaSymbol block, uint relativeAddress, List <Variable> variables, StackFrame frame, Module module, bool arguments)
        {
            IEnumerable <IDiaSymbol> symbols;

            if (relativeAddress != uint.MaxValue)
            {
                IDiaEnumSymbols symbolsEnum = block.findChildrenExByRVA(SymTagEnum.Null, null, 0, relativeAddress);

                symbols = symbolsEnum.Enum();
            }
            else
            {
                symbols = block.GetChildren(SymTagEnum.Data);
            }

            foreach (var symbol in symbols)
            {
                SymTagEnum tag = symbol.symTag;

                if (tag == SymTagEnum.Data)
                {
                    DataKind symbolDataKind = symbol.dataKind;

                    if ((arguments && symbolDataKind != DataKind.Param) || symbol.locationType == LocationType.Null)
                    {
                        continue;
                    }
                }
                else if (tag != SymTagEnum.FunctionArgType || !arguments)
                {
                    continue;
                }

                CodeType codeType     = module.TypesById[symbol.typeId];
                ulong    address      = ResolveAddress(module.Process, symbol, frame.FrameContext);
                var      variableName = symbol.name;

                variables.Add(Variable.CreateNoCast(codeType, address, variableName, variableName));
            }
        }
Esempio n. 38
0
        public static IDiaSymbol FindSymbol(String symName, IDiaSymbol parent, SymTagEnum symTag)
        {
            IDiaEnumSymbols e;

            parent.findChildren(symTag,
                                symName,
                                (uint)(NameSearchOptions.nsfCaseSensitive),
                                out e);

            IDiaSymbol s;
            uint       celt;

            if (e == null || e.count == 0)
            {
                return(null);
            }

            e.Next(1, out s, out celt);

            if (e.count > 1)
            {
                for (int i = 1; i < e.count; i++)
                {
                    IDiaSymbol s2;
                    e.Next(1, out s2, out celt);

                    // Diasym reader returns multiple symbols with same RVA in some cases. Issue the warning only
                    // if the returned symbols actually differ.
                    if (s.virtualAddress != s2.virtualAddress)
                    {
                        Shell.Error("Symbol " + symName + " has " + e.count + " matches. Taking first.");
                        break;
                    }
                }
            }

            return(s);
        }
Esempio n. 39
0
    public DiaSymbol FindClassSymbol(String name, SymTagEnum tag)
    {
        DiaSymbol res = null;
        IDiaSymbol sym = Util.FindClassSymbol(name, m_symbol, tag);

        if (sym != null)
        {
            if ((SymTagEnum)sym.symTag == SymTagEnum.SymTagData)
                res = new DiaDataSymbol(sym);
            else
                res = new DiaSymbol(sym);
        }

        return res;
    }
Esempio n. 40
0
        /// <summary>
        /// Gets the code type tag of the specified type.
        /// </summary>
        /// <param name="typeId">The type identifier.</param>
        public CodeTypeTag GetTypeTag(uint typeId)
        {
            SymTagEnum symTag = GetTypeFromId(typeId).symTag;

            return(symTag.ToCodeTypeTag());
        }
Esempio n. 41
0
        private String GetTypeString(IDiaSymbol s)
        {
            SymTagEnum tag = (SymTagEnum)s.symTag;

            if (tag == SymTagEnum.SymTagData || tag == SymTagEnum.SymTagTypedef)
            {
                s   = s.type;
                tag = (SymTagEnum)s.symTag;
            }

            StringBuilder str = new StringBuilder();

            if (s.name != null)
            {
                str.Append(s.name);
            }
            else if (tag == SymTagEnum.SymTagPointerType)
            {
                str.Append(GetTypeString(s.type));
                str.Append("*");
            }
            else if (tag == SymTagEnum.SymTagBaseType)
            {
                BasicType bt = (BasicType)s.baseType;
                str.AppendFormat("(base type={0}, len={1:d})", bt.ToString(), s.length);
            }
            else if (tag == SymTagEnum.SymTagArrayType)
            {
                str.Append(GetTypeString(s.type));

                bool succ = true;
                int  i;

                try
                {
                    UInt32 rank = s.rank;

                    IDiaEnumSymbols e;
                    s.findChildren(SymTagEnum.SymTagDimension, null, (UInt32)NameSearchOptions.nsNone, out e);

                    for (i = 0; i < e.count; i++)
                    {
                        IDiaSymbol ds;
                        UInt32     celt;
                        e.Next(1, out ds, out celt);

                        str.Append("[" + GetBoundString(ds.lowerBound) + ".." + GetBoundString(ds.upperBound) + "]");
                    }
                }
                catch (Exception)
                {
                    succ = false;
                }

                if (succ == false)
                {
                    try
                    {
                        succ = true;
                        IDiaEnumSymbols e;
                        s.findChildren(SymTagEnum.SymTagCustomType, null, (UInt32)NameSearchOptions.nsNone, out e);

                        for (i = 0; i < e.count; i++)
                        {
                            IDiaSymbol ds;
                            UInt32     celt;
                            e.Next(1, out ds, out celt);

                            str.Append("[" + GetTypeString(ds) + "]");
                        }
                    }
                    catch (Exception)
                    {
                        succ = false;
                    }
                }

                if (succ == false)
                {
                    try
                    {
                        succ = true;
                        str.AppendFormat("[{0:d}]", s.length / s.type.length);
                    }
                    catch (Exception)
                    {
                        succ = false;
                    }
                }
            }
            else if (tag == SymTagEnum.SymTagFunctionType)
            {
                str.Append("Function Type");
            }
            else if (tag == SymTagEnum.SymTagCustomType)
            {
                throw new Exception("NYI");

                /*
                 * str.Append("Custom Type: ");
                 * try
                 * {
                 *  str.Append(s.guid.ToString());
                 * }
                 * catch (Exception e)
                 * {
                 *  try
                 *  {
                 *      str.AppendFormat("{0:x}:{0:x}", s.oemId, s.oemSymbolId);
                 *  }
                 *  catch (Exception)
                 *  {
                 *  }
                 * }
                 * DWORD len = 0;
                 * if ( s.get_types( 0, &len, NULL ) == S_OK && len > 0 ) {
                 *  IDiaSymbol** psyms = new IDiaSymbol*[ len ];
                 *  s.get_types( len, &len, psyms );
                 *  for ( DWORD i = 0; i < len; ++i ) {
                 *      printf( " <" );
                 *      printType( psyms[i] );
                 *      printf( ">" );
                 *      psyms[i]->Release();
                 *  }
                 *  delete [] psyms;
                 * }
                 * len = 0;
                 * if ( s.get_dataBytes( 0, &len, NULL ) == S_OK && len > 0 ) {
                 *  BYTE* pdata = new BYTE[ len ];
                 *  s.get_dataBytes( len, &len, pdata );
                 *  printf( "<data" );
                 *  for ( DWORD i = 0; i < len; ++i ) {
                 *      printf( " %02x", pdata[i] );
                 *  }
                 *  printf( " data>" );
                 *  delete [] pdata;
                 * }
                 */
            }
            else
            {
                str.Append("No Type.");
            }

            return(str.ToString());
        }
Esempio n. 42
0
 /// <summary>Creates symbols which are children of this symbol of the specified type.</summary>
 /// <param name="symbolTagType">Type of the symbols to retrieve.</param>
 /// <returns>The symbols that are a child of this symbol and have tag <paramref name="symbolTagType"/>.</returns>
 public DisposableEnumerable<Symbol> CreateChildIterator(SymTagEnum symbolTagType)
 {
     return this.CreateChildren(symbolTagType, null, NameSearchOptions.nsNone);
 }
Esempio n. 43
0
 public DisposableEnumerable<Symbol> CreateChildren(SymTagEnum symbolTagType, string symbolName, NameSearchOptions searchOptions)
 {
     this.AssertNotDisposed();
     return new DisposableEnumerable<Symbol>(this.CreateChildrenImpl(symbolTagType, symbolName, searchOptions));
 }
Esempio n. 44
0
        private IEnumerable<Symbol> CreateChildrenImpl(SymTagEnum symbolTagType, string symbolName, NameSearchOptions searchOptions)
        {
            IDiaEnumSymbols enumSymbols = null;

            try
            {
                _sym.findChildren(symbolTagType, symbolName, (uint)searchOptions, out enumSymbols);
                if (enumSymbols == null)
                {
                    yield break;
                }

                while (true)
                {
                    uint celt = 0;
                    IDiaSymbol symbol;
                    enumSymbols.Next(1, out symbol, out celt);
                    if (celt != 1) break; //No more symbols
                    yield return Symbol.Create(symbol);
                }
            }
            finally
            {
                if (enumSymbols != null)
                {
                    Marshal.ReleaseComObject(enumSymbols);
                }
            }
        }
Esempio n. 45
0
        /// <summary>
        /// Gets the children using wildcard search: Applies a case-sensitive name match using asterisks (*) and question marks (?) as wildcards.
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <param name="nameWildcard">The name wildcard.</param>
        /// <param name="tag">The tag.</param>
        public static IEnumerable<IDiaSymbol> GetChildrenWildcard(this IDiaSymbol symbol, string nameWildcard, SymTagEnum tag = SymTagEnum.SymTagNull)
        {
            IDiaEnumSymbols symbols;
            const uint nsfRegularExpression = 0x8; // https://msdn.microsoft.com/en-us/library/yat28ads.aspx

            symbol.findChildren(tag, nameWildcard, nsfRegularExpression, out symbols);
            return symbols.Enum();
        }
Esempio n. 46
0
 public int GetSymTag(out SymTagEnum symTagEnum)
 {
     symTagEnum = default(SymTagEnum);
     int _symTagEnum;
     int hr = S.StdCall<int>(GetVTableMember(4), Punk, out _symTagEnum);
     GC.KeepAlive(this);
     symTagEnum = (SymTagEnum)_symTagEnum;
     return hr;
 }