Esempio n. 1
0
        public SourceLocation FindSourceLocation(uint rva)
        {
            var dataSource = DiaLoader.GetDiaSourceObject();

            dataSource.loadDataFromPdb(this.pdbPath);
            dataSource.openSession(out var session);

            session.findLinesByRVA(rva, 0, out var sourceLocs);
            sourceLocs.Next(1, out var sourceLoc, out var fetchCount);
            if (fetchCount == 0)
            {
                return(null);
            }

            dataSource.getStreamSize("srcsrv", out var srcSrvLen);
            dataSource.getStreamSize("sourcelink", out var sourceLinkLen);

            var sourceIndexKind = SourceKind.None;

            string streamName = string.Empty;
            uint   len        = 0;

            if (sourceLinkLen > 0)
            {
                len             = sourceLinkLen;
                streamName      = "sourcelink";
                sourceIndexKind = SourceKind.SourceLink;
            }
            else if (srcSrvLen > 0)
            {
                len             = srcSrvLen;
                streamName      = "srcsrv";
                sourceIndexKind = SourceKind.SrcSrv;
            }

            string srcSrvString = null;

            if (len > 0)
            {
                var buffer = new byte[len];
                unsafe
                {
                    fixed(byte *bufferPtr = buffer)
                    {
                        dataSource.getStreamRawData(streamName, len, out *bufferPtr);
                        srcSrvString = Encoding.UTF8.GetString(buffer);
                    }
                }
            }

            var sourceFile = new SourceFile(sourceLoc.sourceFile.fileName, sourceIndexKind, srcSrvString); // we should support embedded
            var lineNum    = (int)sourceLoc.lineNumber;

            return(new SourceLocation(sourceFile, lineNum));
        }
Esempio n. 2
0
        private static bool IsValidPdb(string pdbPath, Guid incomingSignature, uint incomingAge)
        {
            try
            {
                var dataSource = DiaLoader.GetDiaSourceObject();
                var local      = incomingSignature;
                dataSource.loadAndValidateDataFromPdb(pdbPath, ref local, 0x53445352, incomingAge);
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        private void AddInstructionPointersForProcessInternal(uint pid, ulong imageBase, HashSet <ulong> instructionPointers)
        {
            lock (this.processIdsProcessed)
            {
                this.processIdsProcessed.Add(pid);
                var rvasToLookup = new List <uint>();

                foreach (var eip in instructionPointers)
                {
                    uint rva = (uint)(eip - imageBase);
                    if (!this.rvaToFunctionNameMap.ContainsKey(rva))
                    {
                        rvasToLookup.Add(rva);
                    }
                }

                if (rvasToLookup.Count == 0)
                {
                    return;
                }

                var dataSource = DiaLoader.GetDiaSourceObject();
                dataSource.loadDataFromPdb(this.pdbPath);
                dataSource.openSession(out var session);
                session.getSymbolsByAddr(out var symbolsByAddr);

                foreach (var rva in rvasToLookup)
                {
                    this.AddEntry(session, symbolsByAddr, rva + imageBase, rva);
                }

                symbolsByAddr = null;
                session       = null;
                dataSource    = null;
            }
        }
Esempio n. 4
0
        public SourceLocation FindSourceLocation(uint methodToken, int offset)
        {
            var dataSource = DiaLoader.GetDiaSourceObject();

            dataSource.loadDataFromPdb(this.pdbPath);
            dataSource.openSession(out var session);

            session.findSymbolByToken(methodToken, SymTagEnum.SymTagFunction, out var methodSym);
            if (methodSym == null)
            {
                return(null);
            }

            session.findLinesByRVA(methodSym.relativeVirtualAddress + (uint)offset, 256, out var sourceLocs);
            sourceLocs.Next(1, out var sourceLoc, out uint fetchCount);
            if (fetchCount == 0)
            {
                return(null);
            }

            dataSource.getStreamSize("srcsrv", out var srcSrvLen);
            dataSource.getStreamSize("sourcelink", out var sourceLinkLen);

            var sourceIndexKind = SourceKind.None;

            string streamName = string.Empty;
            uint   len        = 0;

            if (sourceLinkLen > 0)
            {
                len             = sourceLinkLen;
                streamName      = "sourcelink";
                sourceIndexKind = SourceKind.SourceLink;
            }
            else if (srcSrvLen > 0)
            {
                len             = srcSrvLen;
                streamName      = "srcsrv";
                sourceIndexKind = SourceKind.SrcSrv;
            }

            string srcSrvString = null;

            if (len > 0)
            {
                var buffer = new byte[len];
                unsafe
                {
                    fixed(byte *bufferPtr = buffer)
                    {
                        dataSource.getStreamRawData(streamName, len, out *bufferPtr);
                        srcSrvString = Encoding.UTF8.GetString(buffer);
                    }
                }
            }

            var sourceFile = new SourceFile(sourceLoc.sourceFile.fileName, sourceIndexKind, srcSrvString); // we should support embedded

            int lineNum;

            while (true)
            {
                lineNum = (int)sourceLoc.lineNumber;
                if (lineNum != 0xFEEFEE)
                {
                    break;
                }

                lineNum = 0;
                sourceLocs.Next(1, out sourceLoc, out fetchCount);
                if (fetchCount == 0)
                {
                    break;
                }
            }

            return(new SourceLocation(sourceFile, lineNum));
        }