Exemplo n.º 1
0
        public DbgMemory(ulong address,
                         byte[] bytes,
                         bool is32bit,
                         bool isBigEndian,
                         Func <ulong, ColorString> lookupSymbol)
        {
            if (null == bytes)
            {
                throw new ArgumentNullException("bytes");
            }

            if (0 == bytes.Length)
            {
                throw new ArgumentOutOfRangeException("bytes.Length",
                                                      bytes.Length,
                                                      "You must give at least one byte.");
            }

            StartAddress   = address;
            m_bytes        = bytes;
            IsBigEndian    = isBigEndian;
            m_is32Bit      = is32bit;
            m_lookupSymbol = lookupSymbol;
            MemoryRegion   = AddressMap.GetMemoryRegionsForAddress(DbgEngDebugger._GlobalDebugger, address);

            if (isBigEndian)
            {
                throw new NotSupportedException("No support for big-endian data yet.");
            }

            DefaultDisplayFormat = DbgMemoryDisplayFormat.Bytes;
        } // end constructor
Exemplo n.º 2
0
        public static AddressMap GetAddressMap(DbgEngDebugger debugger)
        {
            if (!sm_initDone)
            {
                debugger.SymbolStateChanged   += (_, __) => DumpAddressMapAtSlightestProvocation();
                debugger.DebuggeeStateChanged += (_, __) => DumpAddressMapAtSlightestProvocation();
                sm_initDone = true;
            }

            //TODO: thread through cancellation token!
            return(sm_cachedAddressMap ?? (sm_cachedAddressMap = debugger.ExecuteOnDbgEngThread(() => BuildAddressMap(debugger))));
        }
Exemplo n.º 3
0
        private static AddressMap BuildAddressMap(DbgEngDebugger debugger)
        {
            var result   = new AddressMap();
            var addrList = result.m_addresses;

            foreach (var provider in sm_regionProviders)
            {
                foreach (var region in provider.IdentifyRegions(debugger))
                {
                    addrList.Add(region);
                }
            }

            int   addressesIdx = 0;
            ulong address      = 0;

            while (debugger.TryQueryVirtual(address, out var info) == 0)
            {
                if ((info.State & MEM.FREE) != 0)
                {
                    address += info.RegionSize;
                }
                else
                {
                    while (addressesIdx < addrList.Count && (addrList[addressesIdx].BaseAddress + addrList[addressesIdx].Size) <= info.BaseAddress)
                    {
                        addressesIdx++;
                    }

                    var region = new VirtualAllocRegion(info, debugger);
                    address += region.Size;
                    var regionEndAddress = region.BaseAddress + region.Size;

                    var contiguousRegionStart = ulong.MaxValue;
                    var contiguousRegionEnd   = ulong.MaxValue;
                    if (addressesIdx < addrList.Count)
                    {
                        contiguousRegionStart = addrList[addressesIdx].BaseAddress;
                        contiguousRegionEnd   = addrList[addressesIdx].EndAddress;
                        while (contiguousRegionEnd < regionEndAddress && addressesIdx + 1 < addrList.Count && addrList[addressesIdx + 1].BaseAddress == contiguousRegionEnd)
                        {
                            addressesIdx++;
                            contiguousRegionEnd = addrList[addressesIdx].EndAddress;
                        }
                    }


                    if (contiguousRegionStart > region.BaseAddress || contiguousRegionEnd < region.EndAddress)
                    {
                        addrList.Add(region);
                    }
                }

                //dbgeng seems to be susceptible to wigging out somewhere north of the 4GB line in 32-bit mode with Wow64 processes
                if (debugger.TargetIs32Bit && address > uint.MaxValue)
                {
                    break;
                }
            }

            return(result);
        }
Exemplo n.º 4
0
 private static void DumpAddressMapAtSlightestProvocation()
 {
     sm_cachedAddressMap = null;
 }