Пример #1
0
 public MemoryAccessor(IMemoryReader mr, long offset = 0)
 {
     // Efficient nesting of MemoryAccessors: eliminating long call chains to the base IMemoryReader
     if (mr is MemoryAccessor ma)
     {
         this.offset = offset + ma.offset;
         this.reader = ma.reader;
     }
     else
     {
         this.offset = offset;
         this.reader = mr;
     }
 }
Пример #2
0
        override public void Aktualisiire(
            IMemoryReader AusProzesLeeser,
            out bool Geändert,
            Int64 Zait,
            int?ZuLeeseListeOktetAnzaal = null)
        {
            base.Aktualisiire(
                AusProzesLeeser,
                out Geändert,
                Zait,
                ZuLeeseListeOktetAnzaal);

            WertFloat64 = ObjektBegin.BaiPlus8Double;
        }
        static public Boolean ToInt32(IMemoryReader tMemory, UInt32 tAddress, ref Int32 tData)
        {
            Boolean tResult = false;

            if (null == tMemory)
            {
                return(false);
            }

            Byte[] tBuffer = new Byte[4];
            tResult = tMemory.Read(tAddress, ref tBuffer, 4);
            tData   = BitConverter.ToInt32(tBuffer, 0);
            return(tResult);
        }
Пример #4
0
 private void init(int address, int Length, sbyte[] fromMacAddress, sbyte[] toMacAddress)
 {
     FromMacAddress = fromMacAddress;
     ToMacAddress   = toMacAddress;
     data           = new sbyte[Length];
     if (Length > 0 && address != 0)
     {
         IMemoryReader memoryReader = MemoryReader.getMemoryReader(address, Length, 1);
         for (int i = 0; i < Length; i++)
         {
             data[i] = (sbyte)memoryReader.readNext();
         }
     }
 }
Пример #5
0
        protected int     ZwiscenscpaicerListeOktetFüleAusProzes(
            IMemoryReader AusProzesLeeser,
            int ListeOktetAnzaal)
        {
            var HerkunftAdrese = this.HerkunftAdrese;

            var ListeOktetAnzaalBescrankt = Math.Max(0, ListeOktetAnzaal);

            var VorherZwiscenscpaicerListeOktet = AusScpaicerLeeseLezteListeOktetUndAnzaal.Key;

            var ZwiscenscpaicerListeOktet = VorherZwiscenscpaicerListeOktet;

            if (null != ZwiscenscpaicerListeOktet)
            {
                if (ZwiscenscpaicerListeOktet.Length < ListeOktetAnzaalBescrankt ||
                    ListeOktetAnzaalBescrankt < ZwiscenscpaicerListeOktet.Length / 2 - 10)
                {
                    //	Vorhandener Puffer ist zu klain oder zu groos und wird daher nit waiterverwendet.
                    ZwiscenscpaicerListeOktet = null;
                }
            }

            if (null == ZwiscenscpaicerListeOktet)
            {
                ZwiscenscpaicerListeOktet = new byte[ListeOktetAnzaalBescrankt + 4];
            }
            else
            {
                //	Für Debugging: für den Fal das leese feelscläägt wääre es üübersictlicer wen Array nuur 0 enthalt.
                Array.Clear(ZwiscenscpaicerListeOktet, 0, ListeOktetAnzaalBescrankt);
            }

            int GeleeseListeOktetAnzaal = 0;

            try
            {
                if (null == AusProzesLeeser)
                {
                    return(GeleeseListeOktetAnzaal);
                }

                GeleeseListeOktetAnzaal = (int)AusProzesLeeser.ListeOktetLeeseVonAdrese(HerkunftAdrese, ListeOktetAnzaalBescrankt, ZwiscenscpaicerListeOktet);
            }
            finally
            {
                this.AusScpaicerLeeseLezteListeOktetUndAnzaal = new KeyValuePair <byte[], int>(ZwiscenscpaicerListeOktet, GeleeseListeOktetAnzaal);
            }

            return(GeleeseListeOktetAnzaal);
        }
Пример #6
0
        override public void Aktualisiire(
            IMemoryReader AusProzesLeeser,
            out bool Geändert,
            Int64 Zait,
            int?ZuLeeseListeOktetAnzaal = null)
        {
            base.Aktualisiire(
                AusProzesLeeser,
                out Geändert,
                Zait,
                ZuLeeseListeOktetAnzaal);

            WertBool = 0 != WertInt32;
        }
Пример #7
0
        private static IEnumerable <NdrProcedureDefinition> ReadProcs(IMemoryReader reader, MIDL_SERVER_INFO server_info, int start_offset,
                                                                      int dispatch_count, NdrTypeCache type_cache, ISymbolResolver symbol_resolver, IList <string> names, NdrParserFlags parser_flags)
        {
            RPC_SYNTAX_IDENTIFIER transfer_syntax = server_info.GetTransferSyntax(reader);

            IntPtr proc_str    = IntPtr.Zero;
            IntPtr fmt_str_ofs = IntPtr.Zero;

            if (transfer_syntax.SyntaxGUID != NdrNativeUtils.DCE_TransferSyntax)
            {
                MIDL_SYNTAX_INFO[] syntax_info = server_info.GetSyntaxInfo(reader);
                if (!syntax_info.Any(s => s.TransferSyntax.SyntaxGUID == NdrNativeUtils.DCE_TransferSyntax))
                {
                    throw new NdrParserException("Can't parse NDR64 syntax data");
                }
                MIDL_SYNTAX_INFO dce_syntax_info = syntax_info.First(s => s.TransferSyntax.SyntaxGUID == NdrNativeUtils.DCE_TransferSyntax);
                proc_str    = dce_syntax_info.ProcString;
                fmt_str_ofs = dce_syntax_info.FmtStringOffset;
            }
            else
            {
                proc_str    = server_info.ProcString;
                fmt_str_ofs = server_info.FmtStringOffset;
            }

            IntPtr[]       dispatch_funcs       = server_info.GetDispatchTable(reader, dispatch_count);
            MIDL_STUB_DESC stub_desc            = server_info.GetStubDesc(reader);
            IntPtr         type_desc            = stub_desc.pFormatTypes;
            NDR_EXPR_DESC  expr_desc            = stub_desc.GetExprDesc(reader);
            List <NdrProcedureDefinition> procs = new List <NdrProcedureDefinition>();

            if (fmt_str_ofs != IntPtr.Zero)
            {
                for (int i = start_offset; i < dispatch_count; ++i)
                {
                    int fmt_ofs = reader.ReadInt16(fmt_str_ofs + i * 2);
                    if (fmt_ofs >= 0)
                    {
                        string name = null;
                        if (names != null)
                        {
                            name = names[i - start_offset];
                        }
                        procs.Add(new NdrProcedureDefinition(reader, type_cache, symbol_resolver,
                                                             stub_desc, proc_str + fmt_ofs, type_desc, expr_desc, dispatch_funcs[i], name, parser_flags));
                    }
                }
            }
            return(procs.AsReadOnly());
        }
Пример #8
0
 public CaptureImage(int imageaddr, int level, IMemoryReader imageReader, int width, int height, int bufferWidth, bool invert, bool overwriteFile, string fileNamePrefix)
 {
     this.imageaddr           = imageaddr;
     this.level               = level;
     this.imageReader         = imageReader;
     this.width               = width;
     this.height              = height;
     this.bufferWidth         = bufferWidth;
     this.bufferStorage       = TPSM_PIXEL_STORAGE_MODE_32BIT_ABGR8888;
     this.compressedImage     = false;
     this.compressedImageSize = 0;
     this.invert              = invert;
     this.overwriteFile       = overwriteFile;
     this.fileNamePrefix      = string.ReferenceEquals(fileNamePrefix, null) ? "Image" : fileNamePrefix;
 }
Пример #9
0
        public PyTypeObject(
            Int64 BaseAddress,
            IMemoryReader MemoryReader)
            :
            base(
                BaseAddress,
                MemoryReader)
        {
            tp_name = MemoryReader.ReadUInt32(BaseAddress + Offset_tp_name);

            if (tp_name < int.MaxValue)
            {
                tp_name_Val = MemoryReader.ReadStringAsciiNullTerminated(tp_name.Value, 0x100);
            }
        }
Пример #10
0
        public virtual void setStallAddr(int stall_addr, IMemoryReader baseMemoryReader, int startAddress, int endAddress)
        {
            lock (this)
            {
                // Both the stall address and the base memory reader need to be set at the same
                // time in a synchronized call in order to avoid any race condition
                // with the GUI thread (VideoEngine).
                StallAddr = stall_addr;

                this.baseMemoryReader             = baseMemoryReader;
                this.baseMemoryReaderStartAddress = startAddress;
                this.baseMemoryReaderEndAddress   = endAddress;
                resetMemoryReader(pc);
            }
        }
Пример #11
0
        //public static Logger log = Modules.getLogger("sceParseHttp");

        private string getHeaderString(IMemoryReader memoryReader)
        {
            StringBuilder line = new StringBuilder();

            while (true)
            {
                int c = memoryReader.readNext();
                if (c == '\n' || c == '\r')
                {
                    break;
                }
                line.Append((char)c);
            }

            return(line.ToString());
        }
Пример #12
0
        override public void Aktualisiire(
            IMemoryReader AusProzesLeeser,
            out bool Geändert,
            Int64 Zait,
            int?ZuLeeseListeOktetAnzaal = null)
        {
            Geändert = false;

            bool BaseGeändert;

            base.Aktualisiire(AusProzesLeeser, out BaseGeändert, Zait, ZuLeeseListeOktetAnzaal);

            Geändert = BaseGeändert;

            BaiPlus20Ref = ObjektBegin.BaiPlus20UInt32;
        }
Пример #13
0
        override public void Aktualisiire(
            IMemoryReader AusProzesLeeser,
            out bool Geändert,
            Int64 Zait,
            int?ZuLeeseListeOktetAnzaal = null)
        {
            Geändert = false;

            bool BaseGeändert;

            base.Aktualisiire(AusProzesLeeser, out BaseGeändert, Zait, ZuLeeseListeOktetAnzaal);

            Geändert = BaseGeändert;

            RefTexture = BaiPlus8Ref;
        }
Пример #14
0
 private void init()
 {
     stackIndex = 0;
     blockedThreadIds.Clear();
     finished                     = true;
     paused                       = false;
     reset_Renamed                = true;
     ended                        = true;
     restarted                    = false;
     memoryReader                 = null;
     baseMemoryReader             = null;
     baseMemoryReaderStartAddress = 0;
     baseMemoryReaderEndAddress   = 0;
     pc = 0;
     saveContextAddr = 0;
 }
Пример #15
0
 public static uint?ReadUInt32(this IMemoryReader memoryReader, long address)
 {
     if (memoryReader == null)
     {
         return(null);
     }
     uint[] array = memoryReader.ReadArray <uint>(address, 4);
     if (array == null)
     {
         return(null);
     }
     if (array.Length < 1)
     {
         return(null);
     }
     return(array[0]);
 }
Пример #16
0
        public static byte[] ReadBytes(this IMemoryReader memoryReader, long address, int bytesCountMax)
        {
            byte[] array = new byte[bytesCountMax];
            int    num   = memoryReader.ReadBytes(address, bytesCountMax, array);

            if (num < 1)
            {
                return(null);
            }
            if (num == array.Length)
            {
                return(array);
            }
            byte[] array2 = new byte[num];
            Buffer.BlockCopy(array, 0, array2, 0, array2.Length);
            return(array2);
        }
Пример #17
0
 public override void setCompressedTexImage(int level, int internalFormat, int width, int height, int compressedSize, Buffer buffer)
 {
     if (useTextureCache)
     {
         cachedTextureStatistics.start();
         // TODO Cache all the texture levels
         if (level == 0)
         {
             int                    bufferWidth            = context.texture_buffer_width[level];
             IMemoryReader          imageReader            = ImageReader.getImageReader(context.texture_base_pointer[level], width, height, bufferWidth, internalFormat, false, 0, 0, 0, 0, 0, 0, null, null);
             CachedTexture          cachedTexture          = CachedTexture.getCachedTexture(System.Math.Min(width, bufferWidth), height, internalFormat, imageReader);
             CachedTextureResampled cachedTextureResampled = new CachedTextureResampled(cachedTexture);
             cachedTextures[bindTexture_Renamed] = cachedTextureResampled;
         }
         cachedTextureStatistics.end();
     }
 }
Пример #18
0
        protected internal static sbyte[] getBytesUTF8(int addr)
        {
            IMemoryReader memoryReader = MemoryReader.getMemoryReader(addr, 1);

            sbyte[] bytes = new sbyte[0];
            while (true)
            {
                int utf8 = memoryReader.readNext();
                if (utf8 == 0)
                {
                    break;
                }
                bytes = addByteToArray(bytes, (sbyte)utf8);
            }

            return(bytes);
        }
Пример #19
0
        // Helper to read an IntPtr from the target
        IntPtr ReadIntPtrFromTarget(IMemoryReader reader, IntPtr ptr)
        {
            // This is not cross-platform: it assumes host and target are the same size.
            byte[] buffer = new byte[IntPtr.Size];
            reader.ReadMemory(ptr, buffer);

            System.UInt64 val = 0;
            // Note: this is dependent on endienness.
            for (int i = buffer.Length - 1; i >= 0; i--)
            {
                val <<= 8;
                val  += buffer[i];
            }
            IntPtr newptr = new IntPtr(unchecked ((long)val));

            return(newptr);
        }
Пример #20
0
        public virtual void updateValues()
        {
            values = new int[Length >> 2];

            if (RuntimeContext.hasMemoryInt(address))
            {
                Array.Copy(RuntimeContext.MemoryInt, address >> 2, values, 0, values.Length);
            }
            else
            {
                IMemoryReader memoryReader = MemoryReader.getMemoryReader(rawAddress, Length, 4);
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = memoryReader.readNext();
                }
            }
        }
        override public void Ersctele(IMemoryReader DaatenKwele)
        {
            base.Ersctele(DaatenKwele);

            LaadeListeOktetWenBisherKlainerAlsAnzaalVermuutung(DaatenKwele);

            var ListeOktet = this.ListeOktet;

            if (null == ListeOktet)
            {
                return;
            }

            WertSictListeOktet = ListeOktet.Skip(IntBeginOktetIndex).ToArray();

            this.WertSictIntModulo64Abbild = WertSictIntModulo64(WertSictListeOktet);
        }
Пример #22
0
        void RedoXts()
        {
            if (accessor == null)
            {
                return;
            }
            dataKey.Text  = dataKey.Text.PadRight(32, '0');
            tweakKey.Text = tweakKey.Text.PadRight(32, '0');
            var  data = dataKey.Text.FromHexCompact();
            var  tweak = tweakKey.Text.FromHexCompact();
            uint start, sectorSize;

            uint.TryParse(xtsStartSector.Text, out start);
            uint.TryParse(xtsSectorSize.Text, out sectorSize);
            xtsReader = new XtsDecryptReader(accessor, data, tweak, start, sectorSize);
            UpdateHexView();
        }
Пример #23
0
        public static uint?ReadPointerPath32(this IMemoryReader memoryReader, string rootModuleName, uint[] listOffset)
        {
            if (memoryReader == null)
            {
                return(null);
            }
            if (listOffset == null)
            {
                return(null);
            }
            if (listOffset.Length < 1)
            {
                return(null);
            }
            uint num = 0u;

            if (rootModuleName != null)
            {
                MemoryReaderModuleInfo[] array = memoryReader.Modules();
                if (array == null)
                {
                    return(null);
                }
                MemoryReaderModuleInfo memoryReaderModuleInfo = array.FirstOrDefault((MemoryReaderModuleInfo module) => module.ModuleName.EqualsIgnoreCase(rootModuleName));
                if (memoryReaderModuleInfo == null)
                {
                    return(null);
                }
                num = (uint)memoryReaderModuleInfo.BaseAddress;
            }
            uint num2 = num;

            for (int i = 0; i < listOffset.Length - 1; i++)
            {
                uint num3 = listOffset[i];
                num2 += num3;
                uint?num4 = memoryReader.ReadUInt32(num2);
                if (!num4.HasValue)
                {
                    return(null);
                }
                num2 = num4.Value;
            }
            return(num2 + listOffset.LastOrDefault());
        }
Пример #24
0
        public virtual void setHelloOpt(int optLen, int optData)
        {
            if (optLen <= 0 || optData == 0)
            {
                this.helloOptData = null;
                return;
            }

            // Copy the HelloOpt into an internal buffer, the user memory can be overwritten
            // after this call.
            IMemoryReader memoryReader = MemoryReader.getMemoryReader(optData, optLen, 1);

            helloOptData = new sbyte[optLen];
            for (int i = 0; i < optLen; i++)
            {
                helloOptData[i] = (sbyte)memoryReader.readNext();
            }
        }
Пример #25
0
        private void copyToCachedMemory(int address, int Length)
        {
            int offset = getBufferOffset(address) >> 2;
            int n      = Length >> 2;

            if (RuntimeContext.hasMemoryInt())
            {
                Array.Copy(RuntimeContext.MemoryInt, address >> 2, cachedMemory, offset, n);
            }
            else
            {
                IMemoryReader memoryReader = MemoryReader.getMemoryReader(address, Length, 4);
                for (int i = 0; i < n; i++)
                {
                    cachedMemory[offset + i] = memoryReader.readNext();
                }
            }
        }
Пример #26
0
        public static void ReadArray <T>(this IMemoryReader reader, long pos, T[] value, int offset, int count) where T : struct
        {
            // Fast path for bytes
            if (value is byte[] b)
            {
                reader.Read(pos, b, offset, count);
                return;
            }
            // Slow path
            int sizeOfT = Marshal.SizeOf(typeof(T));
            var buf     = new byte[sizeOfT * count];

            reader.Read(pos, buf, 0, sizeOfT * count);
            for (var i = 0; i < count; i++)
            {
                value[i] = ByteArrayToStructure <T>(buf, i * sizeOfT);
            }
        }
Пример #27
0
        public static T[] ReadArray <T>(this IMemoryReader memoryReader, long address, int numberOfBytes) where T : struct
        {
            if (memoryReader == null)
            {
                return(null);
            }
            byte[] array = memoryReader.ReadBytes(address, numberOfBytes);
            if (array == null)
            {
                return(null);
            }
            int num  = Marshal.SizeOf(typeof(T));
            int num2 = (array.Length - 1) / num + 1;

            T[] array2 = new T[num2];
            Buffer.BlockCopy(array, 0, array2, 0, array.Length);
            return(array2);
        }
        override public void Ersctele(IMemoryReader DaatenKwele)
        {
            base.Ersctele(DaatenKwele);

            var ListeOktet = this.ListeOktet;

            if (null != ListeOktet)
            {
                var ListeItemListeOktet = (ListeOktet ?? new byte[0]).Skip(0xC).ToArray();

                var ListeItemAnzaal = ListeItemListeOktet.Length / 4;

                var ListeItemRef = new UInt32[ListeItemAnzaal];

                Buffer.BlockCopy(ListeOktet, 0xC, ListeItemRef, 0, ListeItemRef.Length * 4);

                this.ListeItemRef = ListeItemRef.Select((ItemRef) => (Int64)ItemRef).ToArray();
            }
        }
        internal static T[] EnumeratePointerList <T>(this IMemoryReader reader, IntPtr p, Func <IntPtr, T> load_type)
        {
            List <T> ret = new List <T>();

            if (p == IntPtr.Zero)
            {
                return(new T[0]);
            }

            IntPtr curr  = p;
            IntPtr value = IntPtr.Zero;

            while ((value = reader.ReadIntPtr(curr)) != IntPtr.Zero)
            {
                ret.Add(load_type(value));
                curr += reader.PointerSize;
            }
            return(ret.ToArray());
        }
Пример #30
0
        /// <summary>
        /// enumerates all Addresses which are aligned to 32Bits and hold the value <paramref name="SearchedValue"/>.
        /// </summary>
        /// <param name="MemoryReader"></param>
        /// <param name="SearchedValue"></param>
        /// <param name="SearchedRegionBegin"></param>
        /// <param name="SearchedRegionEnd"></param>
        /// <returns></returns>
        static public IEnumerable <Int64> AddressesHoldingValue32Aligned32(
            this    IMemoryReader MemoryReader,
            UInt32 SearchedValue,
            Int64 SearchedRegionBegin,
            Int64 SearchedRegionEnd)
        {
            if (null == MemoryReader)
            {
                yield break;
            }

            var FirstBlockAddress =
                (SearchedRegionBegin / Static.Specialisation_RuntimeCost_BlockSize) * Static.Specialisation_RuntimeCost_BlockSize;

            var LastBlockAddress =
                (SearchedRegionEnd / Static.Specialisation_RuntimeCost_BlockSize) * Static.Specialisation_RuntimeCost_BlockSize;

            for (Int64 BlockAddress = FirstBlockAddress; BlockAddress <= LastBlockAddress; BlockAddress += Static.Specialisation_RuntimeCost_BlockSize)
            {
                var BlockValues = MemoryReader.ReadArray <UInt32>(BlockAddress, Static.Specialisation_RuntimeCost_BlockSize);

                if (null == BlockValues)
                {
                    continue;
                }

                for (int InBlockIndex = 0; InBlockIndex < BlockValues.Length; InBlockIndex++)
                {
                    var Address = BlockAddress + (InBlockIndex * 4);

                    if (Address < SearchedRegionBegin ||
                        SearchedRegionEnd < Address)
                    {
                        continue;
                    }

                    if (SearchedValue == BlockValues[InBlockIndex])
                    {
                        yield return(Address);
                    }
                }
            }
        }
        // Helper to read an IntPtr from the target
        private IntPtr ReadIntPtrFromTarget(IMemoryReader reader, IntPtr ptr)
        {
            // This is not cross-platform: it assumes host and target are the same size.
            var buffer = new byte[IntPtr.Size];
            reader.ReadMemory(ptr, buffer);

            UInt64 val = 0;
            // Note: this is dependent on endienness.
            for (int i = buffer.Length - 1; i >= 0; i--)
            {
                val <<= 8;
                val += buffer[i];
            }
            var newptr = new IntPtr(unchecked((long) val));

            return newptr;
        }
        /// <summary>
        /// Read the image name from the target.
        /// </summary>
        /// <param name="reader">access to target's memory</param>
        /// <returns>String for full path to image. Null if name not available</returns>
        /// <remarks>MSDN says this will never be provided for during Attach scenarios; nor for the first 1 or 2 dlls.</remarks>
        public string ReadImageNameFromTarget(IMemoryReader reader)
        {
            string moduleName;
            bool bUnicode = (fUnicode != 0);

            if (lpImageName == IntPtr.Zero)
            {
                return null;
            }
            else
            {
                try
                {
                    IntPtr newptr = ReadIntPtrFromTarget(reader, lpImageName);

                    if (newptr == IntPtr.Zero)
                    {
                        return null;
                    }
                    else
                    {
                        int charSize = (bUnicode) ? 2 : 1;
                        var buffer = new byte[charSize];

                        var sb = new StringBuilder();

                        while (true)
                        {
                            // Read 1 character at a time. This is extremely inefficient,
                            // but we don't know the whole length of the string and it ensures we don't
                            // read off a page.
                            reader.ReadMemory(newptr, buffer);

                            int b;
                            if (bUnicode)
                            {
                                b = buffer[0] + (buffer[1] << 8);
                            }
                            else
                            {
                                b = buffer[0];
                            }

                            if (b == 0) // string is null-terminated
                            {
                                break;
                            }
                            sb.Append((char) b);
                            newptr = new IntPtr(newptr.ToInt64() + charSize); // move to next character
                        }

                        moduleName = sb.ToString();
                    }
                }
                catch (InvalidOperationException) // ignore failures to read
                {
                    return null;
                }
            }

            return moduleName;
        }
        // 
        /// <summary>
        /// Read the log message from the target. 
        /// </summary>
        /// <param name="reader">interface to access debuggee memory</param>
        /// <returns>string containing message or null if not available</returns>
        public string ReadMessageFromTarget(IMemoryReader reader)
        {
            try
            {
                bool isUnicode = (fUnicode != 0);

                int cbCharSize = (isUnicode) ? 2 : 1;
                var buffer = new byte[nDebugStringLength*cbCharSize];
                reader.ReadMemory(lpDebugStringData, buffer);

                var sb = new StringBuilder();
                for (int i = 0; i < buffer.Length; i += cbCharSize)
                {
                    int val;
                    if (isUnicode)
                    {
                        val = buffer[i] + (buffer[i + 1] << 8);
                    }
                    else
                    {
                        val = buffer[i];
                    }
                    sb.Append((char) val);
                }
                return sb.ToString();
            }
            catch (InvalidOperationException)
            {
                return null;
            }
        }