Exemple #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="address">The address of the symbol</param>
 /// <param name="text">Symbol</param>
 public SymbolResult(ulong address, TextInfo text)
 {
     Address    = address;
     Text       = text;
     Flags      = SymbolFlags.None;
     SymbolSize = MemorySize.Unknown;
 }
Exemple #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="address">The address of the symbol</param>
 /// <param name="text">Symbol</param>
 /// <param name="size">Symbol size</param>
 public SymbolResult(ulong address, string text, MemorySize size)
 {
     Address    = address;
     Text       = new TextInfo(text, FormatterTextKind.Label);
     Flags      = SymbolFlags.HasSymbolSize;
     SymbolSize = size;
 }
Exemple #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="address">The address of the symbol</param>
 /// <param name="text">Symbol</param>
 /// <param name="color">Color</param>
 /// <param name="flags">Symbol flags</param>
 public SymbolResult(ulong address, string text, FormatterTextKind color, SymbolFlags flags)
 {
     Address    = address;
     Text       = new TextInfo(text, color);
     Flags      = flags & ~SymbolFlags.HasSymbolSize;
     SymbolSize = MemorySize.Unknown;
 }
Exemple #4
0
 public SymbolEntry(uint Value, SymbolFlags Flags, 
     String Section, int Size, String Name)
 {
     this.Value     = Value;
     this.Flags     = Flags;
     this.Section   = Section;
     this.Size      = Size;
     this.Name      = Name;
 }
Exemple #5
0
 /// <summary>
 /// Creates a new symbol entry.
 /// </summary>
 /// <param name="value">The symbol's integer value.</param>
 /// <param name="flags">The symbol's flags.</param>
 /// <param name="section">The section in which the symbol is declared.</param>
 /// <param name="size">The size or alignment of the symbol.</param>
 /// <param name="name">The unique name of the symbol.</param>
 public SymbolEntry(long value, SymbolFlags flags, 
     String section, int size, String name)
 {
     this.Value   = value;
     this.Flags   = flags;
     this.Section = section;
     this.Size    = size;
     this.Name    = name;
 }
Exemple #6
0
 public SymbolResultTestCase(ulong address, ulong symbolAddress, int addressSize, SymbolFlags flags, MemorySize?memorySize, string[] symbolParts)
 {
     Address       = address;
     SymbolAddress = symbolAddress;
     AddressSize   = addressSize;
     Flags         = flags;
     MemorySize    = memorySize;
     SymbolParts   = symbolParts;
 }
Exemple #7
0
        public static IEnumerable <SymbolFilterRule> FromFlags(SymbolFlags flags, bool invert = false)
        {
            if ((flags & SymbolFlags.Const) != 0)
            {
                yield return((invert) ? IsNotConst : IsConst);
            }

            if ((flags & SymbolFlags.Static) != 0)
            {
                yield return((invert) ? IsNotStatic : IsStatic);
            }

            if ((flags & SymbolFlags.Virtual) != 0)
            {
                yield return((invert) ? IsNotVirtual : IsVirtual);
            }

            if ((flags & SymbolFlags.Sealed) != 0)
            {
                yield return((invert) ? IsNotSealed : IsSealed);
            }

            if ((flags & SymbolFlags.Override) != 0)
            {
                yield return((invert) ? IsNotOverride : IsOverride);
            }

            if ((flags & SymbolFlags.Abstract) != 0)
            {
                yield return((invert) ? IsNotAbstract : IsAbstract);
            }

            if ((flags & SymbolFlags.ReadOnly) != 0)
            {
                yield return((invert) ? IsNotReadOnly : IsReadOnly);
            }

            if ((flags & SymbolFlags.Extern) != 0)
            {
                yield return((invert) ? IsNotExtern : IsExtern);
            }

            if ((flags & SymbolFlags.Async) != 0)
            {
                yield return((invert) ? IsNotAsync : IsAsync);
            }

            if ((flags & SymbolFlags.Extension) != 0)
            {
                yield return((invert) ? IsNotExtension : IsExtension);
            }
        }
        public static SymbolFlags SetFlag(this SymbolFlags flags, SymbolFlags flag, bool value)
        {
            int flagsInt = (int)flags;
            int flagInt  = (int)flag;

            if (value)
            {
                flagsInt |= flagInt;
            }
            else
            {
                flagsInt &= ~flagInt;
            }
            return((SymbolFlags)flagsInt);
        }
Exemple #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="address">The address of the symbol</param>
 /// <param name="text">Symbol</param>
 /// <param name="color">Color</param>
 /// <param name="flags">Symbol flags</param>
 public SymbolResult(ulong address, string text, FormatterOutputTextKind color, SymbolFlags flags)
 {
     Address    = address;
     Text       = new TextInfo(text, color);
     Flags      = flags & ~SymbolFlags.HasSymbolSize;
     SymbolSize = 0;
 }
        public string GetSymbolFromAddress(ulong address, out SymbolResolveLevel level, out SymbolFlags flags, out string fileName, out string symbolName, out ulong displacement)
        {
            // Assume failure (and stop the compiler from complaining).
            if (address == 0)
            {
                level = SymbolResolveLevel.Invalid;
                flags = 0;
                fileName = null;
            }

            // Allocate some memory for the symbol information.
            using (var data = new MemoryAlloc(Marshal.SizeOf(typeof(SymbolInfo)) + _maxNameLen))
            {
                var info = new SymbolInfo();

                info.SizeOfStruct = Marshal.SizeOf(info);
                info.MaxNameLen = _maxNameLen - 1;

                Marshal.StructureToPtr(info, data, false);

                // Hack for drivers, since we don't get their module sizes. 
                // Preloading modules will fix this.
                if (this.PreloadModules)
                {
                    ulong b;

                    this.GetModuleFromAddress(address, out b);

                    using (Win32.DbgHelpLock.AcquireContext())
                        Win32.SymFromAddr(_handle, b, out displacement, data);

                    Marshal.StructureToPtr(info, data, false);
                }

                // Get the symbol name.
                using (Win32.DbgHelpLock.AcquireContext())
                {
                    if (Win32.SymFromAddr(_handle, address, out displacement, data))
                    {
                        info = data.ReadStruct<SymbolInfo>();
                    }
                }

                string modFileName;
                ulong modBase;

                // Get the module name.
                if (info.ModBase == 0)
                {
                    modFileName = this.GetModuleFromAddress(address, out modBase);
                }
                else
                {
                    modBase = info.ModBase;

                    lock (_modules)
                        modFileName = _modules.Find(kvp => kvp.Key == info.ModBase).Value;
                }

                // If we don't have a module name, return an address.
                if (modFileName == null)
                {
                    level = SymbolResolveLevel.Address;
                    flags = 0;
                    fileName = null;
                    symbolName = null;

                    return Utils.FormatAddress(address);
                }

                FileInfo fi = null;

                fileName = modFileName;

                try
                {
                    fi = new FileInfo(modFileName);
                    fileName = fi.FullName;
                }
                catch
                { }

                // If we have a module name but not a symbol name, 
                // return a module plus an offset: module+offset.
                if (info.NameLen == 0)
                {
                    level = SymbolResolveLevel.Module;
                    flags = 0;
                    symbolName = null;

                    if (fi != null)
                    {
                        return fi.Name + "+0x" + (address - modBase).ToString("x");
                    }
                    else
                    {
                        var s = modFileName.Split('\\');

                        return s[s.Length - 1] + "+0x" + (address - modBase).ToString("x");
                    }
                }

                // If we have everything, return the full symbol name: module!symbol+offset.
                string name = data.ReadAnsiString(SymbolInfo.NameOffset, info.NameLen);

                level = SymbolResolveLevel.Function;
                flags = info.Flags;
                symbolName = name;

                if (displacement == 0)
                    return fi.Name + "!" + name;
                else
                    return fi.Name + "!" + name + "+0x" + displacement.ToString("x");
            }
        }
        public string GetSymbolFromAddress(ulong address, out SymbolFlags flags)
        {
            SymbolResolveLevel level;
            string fileName;

            return this.GetSymbolFromAddress(address, out level, out flags, out fileName);
        }
Exemple #12
0
        public string GetSymbolFromAddress(ulong address, out SymbolResolveLevel level, out SymbolFlags flags, out string fileName)
        {
            string symbolName;
            ulong  displacement;

            return(this.GetSymbolFromAddress(address, out level, out flags, out fileName, out symbolName, out displacement));
        }
Exemple #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="address">The address of the symbol</param>
 /// <param name="text">Symbol</param>
 public SymbolResult(ulong address, TextInfo text)
 {
     Address = address;
     Text    = text;
     Flags   = 0;
 }
 public static TCSymbol NewVariable(TypeData type, ESIR_Expression expr, SymbolFlags flags = 0)
 => new (new (type, expr), flags);
 public bool HasFlag(SymbolFlags flag)
 {
     return((flags & (int)flag) != 0);
 }
Exemple #16
0
 void ISymbolDisplayBuilder.BuildSymbolDisplay(ISymbol symbol, ISymbolWriter writer, INode enclosingDeclaration, SymbolFlags meaning, SymbolFormatFlags flags)
 {
     BuildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags, typeFlags: TypeFormatFlags.None);
 }
Exemple #17
0
            /// <summary>
            /// Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope
            /// Meaning needs to be specified if the enclosing declaration is given
            /// </summary>
            private void BuildSymbolDisplay(ISymbol inputSymbol, ISymbolWriter writer, INode enclosingDeclaration = null, SymbolFlags inputMeaning = SymbolFlags.None, SymbolFormatFlags flags = SymbolFormatFlags.None, TypeFormatFlags typeFlags = TypeFormatFlags.None)
            {
                Contract.Assert(inputSymbol != null);
                Contract.Assert(writer != null);

                // HINT: To simplify migration we're using "local" functions via delegates.
                // This code could be changed in the future, once C# would have local functions.
                Action <ISymbol, SymbolFlags> walkSymbol = null;

                ISymbol          parentSymbol = null;
                Action <ISymbol> appendParentTypeArgumentsAndSymbolName = null;

                appendParentTypeArgumentsAndSymbolName = (ISymbol symbol) =>
                {
                    if (parentSymbol != null)
                    {
                        // Write type arguments of instantiated class/interface here
                        if ((flags & SymbolFormatFlags.WriteTypeParametersOrArguments) != SymbolFormatFlags.None)
                        {
                            if ((symbol.Flags & SymbolFlags.Instantiated) != SymbolFlags.None)
                            {
                                // TODO: check types to avoid redundant ToArray call.
                                BuildDisplayForTypeArgumentsAndDelimiters(
                                    m_checker.GetTypeParametersOfClassOrInterface(parentSymbol),
                                    ((ITransientSymbol)symbol).Mapper, writer, enclosingDeclaration);
                            }
                            else
                            {
                                BuildTypeParameterDisplayFromSymbol(parentSymbol, writer, enclosingDeclaration);
                            }
                        }

                        WritePunctuation(writer, SyntaxKind.DotToken);
                    }

                    parentSymbol = symbol;
                    AppendSymbolNameOnly(symbol, writer);
                };

                // Let the writer know we just wrote out a symbol.  The declaration emitter writer uses
                // this to determine if an import it has previously seen (and not written out) needs
                // to be written to the file once the walk of the tree is complete.
                //
                // NOTE(cyrusn): This approach feels somewhat unfortunate.  A simple pass over the tree
                // up front (for example, during checking) could determine if we need to emit the imports
                // and we could then access that data during declaration emit.
                writer.TrackSymbol(inputSymbol, enclosingDeclaration, inputMeaning);

                walkSymbol = (ISymbol symbol, SymbolFlags meaning) =>
                {
                    if (symbol != null)
                    {
                        var accessibleSymbolChain = m_checker.GetAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, (flags & SymbolFormatFlags.UseOnlyExternalAliasing) != SymbolFormatFlags.None);

                        if (accessibleSymbolChain == null ||
                            m_checker.NeedsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.Count == 1 ? meaning : GetQualifiedLeftMeaning(meaning)))
                        {
                            // Go up and add our parent.
                            walkSymbol(
                                m_checker.GetParentOfSymbol(accessibleSymbolChain != null ? accessibleSymbolChain[0] : symbol),
                                GetQualifiedLeftMeaning(meaning));
                        }

                        if (accessibleSymbolChain != null)
                        {
                            foreach (var accessibleSymbol in accessibleSymbolChain)
                            {
                                appendParentTypeArgumentsAndSymbolName(accessibleSymbol);
                            }
                        }
                        else
                        {
                            // If we didn't find accessible symbol chain for this symbol, break if this is external module
                            if (parentSymbol == null && symbol.DeclarationList.Any(n => HasExternalModuleSymbol(n)))
                            {
                                return;
                            }

                            // if this is anonymous type break
                            if ((symbol.Flags & SymbolFlags.TypeLiteral) != SymbolFlags.None || (symbol.Flags & SymbolFlags.ObjectLiteral) != SymbolFlags.None)
                            {
                                return;
                            }

                            appendParentTypeArgumentsAndSymbolName(symbol);
                        }
                    }
                };

                // Get qualified name if the symbol is not a type parameter
                // and there is an enclosing declaration or we specifically
                // asked for it
                var isTypeParameter = inputSymbol.Flags & SymbolFlags.TypeParameter;
                var typeFormatFlag  = TypeFormatFlags.UseFullyQualifiedType & typeFlags;

                if (isTypeParameter == SymbolFlags.None && (enclosingDeclaration != null || typeFormatFlag != TypeFormatFlags.None))
                {
                    walkSymbol(inputSymbol, inputMeaning);
                    return;
                }

                appendParentTypeArgumentsAndSymbolName(inputSymbol);
            }
Exemple #18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="address">The address of the symbol</param>
 /// <param name="text">Symbol</param>
 /// <param name="flags">Symbol flags</param>
 public SymbolResult(ulong address, TextInfo text, SymbolFlags flags)
 {
     Address = address;
     Text    = text;
     Flags   = flags;
 }
Exemple #19
0
        public string GetSymbolFromAddress(ulong address, out SymbolResolveLevel level, out SymbolFlags flags, out string fileName, out string symbolName, out ulong displacement)
        {
            // Assume failure (and stop the compiler from complaining).
            if (address == 0)
            {
                level    = SymbolResolveLevel.Invalid;
                flags    = 0;
                fileName = null;
            }

            // Allocate some memory for the symbol information.
            using (var data = new MemoryAlloc(Marshal.SizeOf(typeof(SymbolInfo)) + _maxNameLen))
            {
                var info = new SymbolInfo();

                info.SizeOfStruct = Marshal.SizeOf(info);
                info.MaxNameLen   = _maxNameLen - 1;

                Marshal.StructureToPtr(info, data, false);

                // Hack for drivers, since we don't get their module sizes.
                // Preloading modules will fix this.
                if (this.PreloadModules)
                {
                    ulong b;

                    this.GetModuleFromAddress(address, out b);

                    using (Win32.DbgHelpLock.AcquireContext())
                        Win32.SymFromAddr(_handle, b, out displacement, data);

                    Marshal.StructureToPtr(info, data, false);
                }

                // Get the symbol name.
                using (Win32.DbgHelpLock.AcquireContext())
                {
                    if (Win32.SymFromAddr(_handle, address, out displacement, data))
                    {
                        info = data.ReadStruct <SymbolInfo>();
                    }
                }

                string modFileName;
                ulong  modBase;

                // Get the module name.
                if (info.ModBase == 0)
                {
                    modFileName = this.GetModuleFromAddress(address, out modBase);
                }
                else
                {
                    modBase = info.ModBase;

                    lock (_modules)
                        modFileName = _modules.Find(kvp => kvp.Key == info.ModBase).Value;
                }

                // If we don't have a module name, return an address.
                if (modFileName == null)
                {
                    level      = SymbolResolveLevel.Address;
                    flags      = 0;
                    fileName   = null;
                    symbolName = null;

                    return(Utils.FormatAddress(address));
                }

                FileInfo fi = null;

                fileName = modFileName;

                try
                {
                    fi       = new FileInfo(modFileName);
                    fileName = fi.FullName;
                }
                catch
                { }

                // If we have a module name but not a symbol name,
                // return a module plus an offset: module+offset.
                if (info.NameLen == 0)
                {
                    level      = SymbolResolveLevel.Module;
                    flags      = 0;
                    symbolName = null;

                    if (fi != null)
                    {
                        return(fi.Name + "+0x" + (address - modBase).ToString("x"));
                    }
                    else
                    {
                        var s = modFileName.Split('\\');

                        return(s[s.Length - 1] + "+0x" + (address - modBase).ToString("x"));
                    }
                }

                // If we have everything, return the full symbol name: module!symbol+offset.
                string name = data.ReadAnsiString(SymbolInfo.NameOffset, info.NameLen);

                level      = SymbolResolveLevel.Function;
                flags      = info.Flags;
                symbolName = name;

                if (displacement == 0)
                {
                    return(fi.Name + "!" + name);
                }
                else
                {
                    return(fi.Name + "!" + name + "+0x" + displacement.ToString("x"));
                }
            }
        }
Exemple #20
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="address">The address of the symbol</param>
 /// <param name="text">Symbol</param>
 public SymbolResult(ulong address, string text)
 {
     Address = address;
     Text    = new TextInfo(text, FormatterOutputTextKind.Label);
     Flags   = 0;
 }
        public string GetSymbolFromAddress(ulong address, out SymbolResolveLevel level, out SymbolFlags flags, out string fileName)
        {
            string symbolName;
            ulong displacement;

            return this.GetSymbolFromAddress(address, out level, out flags, out fileName, out symbolName, out displacement);
        }
Exemple #22
0
 public static T WithFlags <T>(this T symbol, SymbolFlags flags) where T : Symbol
 {
     symbol.Flags |= flags;
     return(symbol);
 }
        public static void Write(this BinaryWriter writer, SymbolFlags flags)
        {
            int i = (int)flags;

            writer.Write(i);
        }
        public string GetSymbolFromAddress(ulong address, out SymbolResolveLevel level, out SymbolFlags flags, out string fileName, out string symbolName, out ulong displacement)
        {
            if (address == 0)
            {
                level = SymbolResolveLevel.Invalid;
                flags = 0;
                fileName = null;
            }

            using (var data = new MemoryAlloc(Marshal.SizeOf(typeof(SymbolInfo)) + _maxNameLen))
            {
                var info = new SymbolInfo();

                info.SizeOfStruct = Marshal.SizeOf(info);
                info.MaxNameLen = _maxNameLen - 1;

                Marshal.StructureToPtr(info, data, false);

                if (this.PreloadModules)
                {
                    ulong b;

                    this.GetModuleFromAddress(address, out b);

                    using (Win32.DbgHelpLock.AcquireContext())
                        Win32.SymFromAddr(_handle, b, out displacement, data);

                    Marshal.StructureToPtr(info, data, false);
                }

                using (Win32.DbgHelpLock.AcquireContext())
                {
                    if (Win32.SymFromAddr(_handle, address, out displacement, data))
                    {
                        info = data.ReadStruct<SymbolInfo>();
                    }
                }

                string modFileName;
                ulong modBase;

                if (info.ModBase == 0)
                {
                    modFileName = this.GetModuleFromAddress(address, out modBase);
                }
                else
                {
                    modBase = info.ModBase;

                    lock (_modules)
                        modFileName = _modules.Find(kvp => kvp.Key == info.ModBase).Value;
                }

                if (modFileName == null)
                {
                    level = SymbolResolveLevel.Address;
                    flags = 0;
                    fileName = null;
                    symbolName = null;

                    return Utils.FormatAddress(address);
                }

                FileInfo fi = null;

                fileName = modFileName;

                try
                {
                    fi = new FileInfo(modFileName);
                    fileName = fi.FullName;
                }
                catch
                { }

                if (info.NameLen == 0)
                {
                    level = SymbolResolveLevel.Module;
                    flags = 0;
                    symbolName = null;

                    if (fi != null)
                    {
                        return fi.Name + "+0x" + (address - modBase).ToString("x");
                    }
                    else
                    {
                        var s = modFileName.Split('\\');

                        return s[s.Length - 1] + "+0x" + (address - modBase).ToString("x");
                    }
                }

                string name = Marshal.PtrToStringAnsi(data.Memory.Increment(Win32.SymbolInfoNameOffset), info.NameLen);

                level = SymbolResolveLevel.Function;
                flags = info.Flags;
                symbolName = name;

                if (displacement == 0)
                    return fi.Name + "!" + name;
                else
                    return fi.Name + "!" + name + "+0x" + displacement.ToString("x");
            }
        }