示例#1
0
        //return pointerOffset[offset], get a value by using a relative pointer
        private static int?getInt32ByPtr(uint pointerOffset, int offset)
        {
            IntPtr?addr = Emulator.baseAddr;

            if (Emulator.baseAddr == null)
            {
                return(null); //Fatal error
            }
            byte[] readBuf = new byte[4], readBuf2 = new byte[4];

            MemoryIO mio = new MemoryIO(Emulator.emulator);

            if (!mio.processOK())
            {
                return(null);
            }

            IntPtr pointerPointer = (IntPtr)((int)addr + pointerOffset);

            mio.MemoryRead(pointerPointer, readBuf);
            uint pointer = BitConverter.ToUInt32(readBuf, 0);

            pointer &= ~0xA0000000; //Unset virtual memory cached/uncached flags
            if (pointer == 0)
            {
                return(null);
            }

            mio.MemoryRead((IntPtr)((int)addr + pointer + offset), readBuf2);
            int value = BitConverter.ToInt32(readBuf2, 0);

            return(value);
        }
        //Detect if supported version
        private static bool versionOk(string checkVersion, MemoryIO mioRelative, IntPtr versionPtr)
        {
            byte[] expected   = System.Text.Encoding.Unicode.GetBytes(checkVersion);
            var    versionBuf = new Byte[expected.Length];

            mioRelative.MemoryRead(versionPtr, versionBuf);
            if (memcmp(expected, versionBuf, new UIntPtr((uint)expected.Length)) == 0)
            {
                return(true); //Identical
            }
            bool empty = true;

            foreach (byte b in versionBuf)
            {
                if (b != 0)
                {
                    empty = false;                                    //All bytes == 0?
                }
            }
            if (!empty)
            {
                MessageWrongVersion(checkVersion); //Read error, maybe starting up
            }
            return(false);                         //Wrong version => Fail
        }
示例#3
0
        //TODO: Use sender or e to get nud and offset
        private void ButtonSet(TextBox textBox, int offset)
        {
            IntPtr?baseAddr = ReadDEbaseAdress();

            if (baseAddr == null)
            {
                return; //Fatal error
            }

            if (textBox.Text == "")
            {
                return;
            }
            byte[] writeBuf = new byte[4];
            writeBuf = BitConverter.GetBytes(Convert.ToInt32(textBox.Text));

            MemoryIO mio = new MemoryIO(Emulator.emulator);

            if (!mio.processOK())
            {
                return;
            }

            /**
             * Write position variable
             **/
            IntPtr pointer = new IntPtr((int)baseAddr + offset);

            mio.MemoryWrite(pointer, writeBuf);
        }
        //Returns main memory start
        private static IntPtr?DetectEPSXe()
        {
            var mioRelative = new MemoryIO(EPSXE, true); //Program start = 0

            if (!mioRelative.processOK())
            {
                return(null);
            }

            return(versionOk(EPSXE_VERSION_CHECK, mioRelative, (IntPtr)Offset.ePSXeVersion)
                ? (IntPtr?)Offset.ePSXeMemstart : null); //Fixed pos, no pointer needed)
        }
        //Returns main memory start
        private static IntPtr?DetectPsxfin()
        {
            var mioRelative = new MemoryIO(PSXFIN, true); //Program start = 0

            if (!mioRelative.processOK())
            {
                return(null);
            }

            byte[] readBuf         = new byte[4];
            var    baseAddrPointer = new IntPtr(Offset.psxfinMemstart); //psxfin.exe+171A5C, memstart ptr

            mioRelative.MemoryRead(baseAddrPointer, readBuf);

            return(versionOk(PSXFIN_VERSION_CHECK, mioRelative, (IntPtr)Offset.psxfinVersion)
                ? (IntPtr?)BitConverter.ToInt32(readBuf, 0) : null);
        }
        //Returns main memory start
        private static IntPtr?DetectXEBRA()
        {
            var mioRelative = new MemoryIO(XEBRA, true); //Program start = 0

            if (!mioRelative.processOK())
            {
                return(null);
            }

            byte[] readBuf         = new byte[4];
            var    baseAddrPointer = new IntPtr(Offset.xebraMemstart); //XEBRA.EXE+54920, memstart ptr

            mioRelative.MemoryRead(baseAddrPointer, readBuf);

            return(versionOk(XEBRA_VERSION_CHECK, mioRelative, (IntPtr)Offset.xebraVersion)
                ? (IntPtr?)BitConverter.ToInt32(readBuf, 0) : null);
        }
示例#7
0
        private int?UpdateReadValue(int offset)
        {
            if (mio == null)
            {
                mio = new MemoryIO(Emulator.emulator);
            }
            IntPtr?addr = Emulator.baseAddr;

            if (addr == null)
            {
                return(null);
            }
            IntPtr pointer = new IntPtr((int)addr + offset);

            byte[] readBuf = new byte[4];
            mio.MemoryRead(pointer, readBuf);
            int value = BitConverter.ToInt32(readBuf, 0);

            return(value);
        }
示例#8
0
        private static int?getInt32(int offset)
        {
            IntPtr?addr = Emulator.baseAddr;

            if (Emulator.baseAddr == null)
            {
                return(null); //Fatal error
            }
            byte[] readBuf = new byte[4];

            MemoryIO mio = new MemoryIO(Emulator.emulator);

            if (!mio.processOK())
            {
                return(null);
            }

            IntPtr pointer = new IntPtr((int)addr + offset);

            mio.MemoryRead(pointer, readBuf);
            int value = BitConverter.ToInt32(readBuf, 0);

            return(value);
        }
示例#9
0
        private int?ReadVal(int offset)
        {
            IntPtr?baseAddr = ReadDEbaseAdress();

            byte[] readBuf = new byte[4];

            MemoryIO mio = new MemoryIO(Emulator.emulator);

            if (!mio.processOK())
            {
                return(null);
            }

            IntPtr mappointer = new IntPtr((int)baseAddr + offset);

            mio.MemoryRead(mappointer, readBuf);
            int map = BitConverter.ToInt32(readBuf, 0);

            if (Range.isInsideRange(Range.map, map))
            {
                return(map);
            }
            return(null);
        }