Exemplo n.º 1
0
        /// <summary>
        /// Signal that a virtual memory event happened at the given location.
        /// </summary>
        /// <param name="address">Virtual address accessed</param>
        /// <param name="size">Size of the region affected in bytes</param>
        /// <param name="write">Whether the region was written to or read</param>
        /// <returns>True if the event triggered any tracking regions, false otherwise</returns>
        public bool VirtualMemoryEvent(ulong address, ulong size, bool write)
        {
            // Look up the virtual region using the region list.
            // Signal up the chain to relevant handles.

            lock (TrackingLock)
            {
                var results = _virtualResults;
                int count   = _virtualRegions.FindOverlapsNonOverlapping(address, size, ref results);

                if (count == 0)
                {
                    if (!_memoryManager.IsMapped(address))
                    {
                        throw new InvalidMemoryRegionException();
                    }

                    _memoryManager.TrackingReprotect(address & ~(ulong)(_pageSize - 1), (ulong)_pageSize, MemoryPermission.ReadAndWrite);
                    return(false); // We can't handle this - it's probably a real invalid access.
                }

                for (int i = 0; i < count; i++)
                {
                    VirtualRegion region = results[i];
                    region.Signal(address, size, write);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private void LoadMod0Symbols(IVirtualMemoryManager memory, ulong textOffset)
        {
            ulong mod0Offset = textOffset + memory.Read <uint>(textOffset + 4);

            if (mod0Offset < textOffset || !memory.IsMapped(mod0Offset) || (mod0Offset & 3) != 0)
            {
                return;
            }

            Dictionary <ElfDynamicTag, ulong> dynamic = new Dictionary <ElfDynamicTag, ulong>();

            int mod0Magic = memory.Read <int>(mod0Offset + 0x0);

            if (mod0Magic != Mod0)
            {
                return;
            }

            ulong dynamicOffset    = memory.Read <uint>(mod0Offset + 0x4) + mod0Offset;
            ulong bssStartOffset   = memory.Read <uint>(mod0Offset + 0x8) + mod0Offset;
            ulong bssEndOffset     = memory.Read <uint>(mod0Offset + 0xc) + mod0Offset;
            ulong ehHdrStartOffset = memory.Read <uint>(mod0Offset + 0x10) + mod0Offset;
            ulong ehHdrEndOffset   = memory.Read <uint>(mod0Offset + 0x14) + mod0Offset;
            ulong modObjOffset     = memory.Read <uint>(mod0Offset + 0x18) + mod0Offset;

            bool isAArch32 = memory.Read <ulong>(dynamicOffset) > 0xFFFFFFFF || memory.Read <ulong>(dynamicOffset + 0x10) > 0xFFFFFFFF;

            while (true)
            {
                ulong tagVal;
                ulong value;

                if (isAArch32)
                {
                    tagVal = memory.Read <uint>(dynamicOffset + 0);
                    value  = memory.Read <uint>(dynamicOffset + 4);

                    dynamicOffset += 0x8;
                }
                else
                {
                    tagVal = memory.Read <ulong>(dynamicOffset + 0);
                    value  = memory.Read <ulong>(dynamicOffset + 8);

                    dynamicOffset += 0x10;
                }

                ElfDynamicTag tag = (ElfDynamicTag)tagVal;

                if (tag == ElfDynamicTag.DT_NULL)
                {
                    break;
                }

                dynamic[tag] = value;
            }

            if (!dynamic.TryGetValue(ElfDynamicTag.DT_STRTAB, out ulong strTab) ||
                !dynamic.TryGetValue(ElfDynamicTag.DT_SYMTAB, out ulong symTab) ||
                !dynamic.TryGetValue(ElfDynamicTag.DT_SYMENT, out ulong symEntSize))
            {
                return;
            }

            ulong strTblAddr = textOffset + strTab;
            ulong symTblAddr = textOffset + symTab;

            List <ElfSymbol> symbols = new List <ElfSymbol>();

            while (symTblAddr < strTblAddr)
            {
                ElfSymbol sym = isAArch32 ? GetSymbol32(memory, symTblAddr, strTblAddr) : GetSymbol64(memory, symTblAddr, strTblAddr);

                symbols.Add(sym);

                symTblAddr += symEntSize;
            }

            lock (_images)
            {
                _images.Add(new Image(textOffset, symbols.OrderBy(x => x.Value).ToArray()));
            }
        }