public bool IsMapped(ulong va)
        {
            if (!ValidateAddress(va))
            {
                return(false);
            }

            return(_pageTable.Read <nuint>((va / PageSize) * PteSize) != 0);
        }
Exemple #2
0
        public void ReadTest()
        {
            MemoryBlock l_MemoryBlock = CreateBlock();

            Byte[] l_Buffer = new byte[10];
            l_MemoryBlock.Read(0, l_Buffer, 0, l_Buffer.Length);

            for (int i = 0; i < l_Buffer.Length; i++)
            {
                Assert.Equal(i, l_Buffer[i]);
            }
        }
Exemple #3
0
        /// <inheritdoc/>
        public T Read <T>(ulong va) where T : unmanaged
        {
            try
            {
                AssertMapped(va, (ulong)Unsafe.SizeOf <T>());

                return(_addressSpaceMirror.Read <T>(va));
            }
            catch (InvalidMemoryRegionException)
            {
                if (_invalidAccessHandler == null || !_invalidAccessHandler(va))
                {
                    throw;
                }

                return(default);
Exemple #4
0
        private unsafe static void FuzzTables(IEnumerable <MetadataTables> tables)
        {
            foreach (var moduleTables in tables)
            {
                MemoryBlock image  = moduleTables.m_import.Image;
                byte[]      memory = new byte[image.Length];
                image.Read(0, memory);
                _output = TextWriter.Null;
                Random random = new Random();

                fixed(byte *ptr = memory)
                {
                    var newImage = new MemoryBlock(memory, ptr, memory.Length);

                    TestCorruptedHeaders(memory, ptr, newImage);
                    TestShortened(memory, ptr);
                }
            }
        }
        private void lvMemory_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
        {
            do
            {
                if (null == this.Image)
                {
                    break;
                }

                UInt32 tStartAddress = (UInt32)e.StartIndex * this.LineSize;

                Int32 tLength = (e.EndIndex - e.StartIndex + 1) * (Int32)this.LineSize;


                Byte[] tBuffer = null;
                if (!this.Image.Read(tStartAddress, ref tBuffer, tLength))
                {
                    break;
                }

                MemoryBlock       tBlock     = new MemoryBlock(tStartAddress, tBuffer);
                ListViewCacheLine tCacheLine = null;
                for (UInt32 tOffset = 0; tOffset < tBlock.Size; tOffset += this.LineSize)
                {
                    Byte[] tTempLine = null;
                    UInt32 wAddress  = tStartAddress + tOffset;
                    if (!tBlock.Read(wAddress, ref tTempLine, (Int32)this.LineSize))
                    {
                        continue;
                    }

                    ListViewItem tItem = new ListViewItem(wAddress.ToString("X8"));
                    tItem.SubItems.Add(HEX.HEXBuilder.ByteArrayToHEXString(tTempLine));
                    tItem.SubItems.Add(BuildDisplayString(tTempLine));
                    tCacheLine = new ListViewCacheLine(wAddress, tItem);
                    m_ListViewCache.Add(tCacheLine);
                }

                m_ListViewCache.RemoveBefore(tStartAddress.ToString("X8"));

                m_ListViewCache.RemoveAfter(tCacheLine.ID);
            } while (false);
        }
Exemple #6
0
        public void WriteTest()
        {
            MemoryBlock l_MemoryBlock = CreateBlock();

            Byte[] l_WriteBuffer = new byte[10];
            for (int i = 0; i < l_WriteBuffer.Length; i++)
            {
                l_WriteBuffer[i] = 156;
            }

            l_MemoryBlock.Write(0, l_WriteBuffer, 0, l_WriteBuffer.Length);

            Byte[] l_Buffer = new byte[10];
            l_MemoryBlock.Read(0, l_Buffer, 0, l_Buffer.Length);

            for (int i = 0; i < l_Buffer.Length; i++)
            {
                Assert.Equal(156, l_Buffer[i]);
            }
        }
Exemple #7
0
 private static string MemoryToString(MemoryBlock block, int max = 0)
 {
     byte[] bytes = new byte[Math.Min(max, block.Length)];
     block.Read(0, bytes);
     return(BitConverter.ToString(bytes));
 }
        /// <inheritdoc/>
        public T Read <T>(ulong va) where T : unmanaged
        {
            AssertMapped(va, (ulong)Unsafe.SizeOf <T>());

            return(_addressSpaceMirror.Read <T>(va));
        }
Exemple #9
0
        public void Test_Read()
        {
            Marshal.WriteInt32(_memoryBlock.Pointer, 0x2020, 0x1234abcd);

            Assert.AreEqual(_memoryBlock.Read <int>(0x2020), 0x1234abcd);
        }