示例#1
0
        public UInt32 ReadAddress(UInt32 addressToRead, int numBytes)
        {
            if (addressToRead < startAddress)
            {
                return(0);
            }
            if (addressToRead > endAddress - numBytes)
            {
                return(0);
            }

            Byte[] buffer = new Byte[4];
            Buffer.BlockCopy(mem, index(addressToRead), buffer, 0, numBytes);

            //Read buffer
            switch (numBytes)
            {
            case 4:
                UInt32 result = BitConverter.ToUInt32(buffer, 0);

                //Swap to machine endianness and return
                return(ByteSwap.Swap(result));

            case 2:
                UInt16 result16 = BitConverter.ToUInt16(buffer, 0);

                //Swap to machine endianness and return
                return(ByteSwap.Swap(result16));

            default:
                return(buffer[0]);
            }
        }
示例#2
0
        /// <summary>
        /// Reads memory (bytes) from the Wii U
        /// </summary>
        /// <param name="address">Address to read</param>
        /// <param name="length">Length of the bytes</param>
        private void RequestBytes(uint address, uint length)
        {
            try
            {
                SendCommand(GeckoUCommands.Command.COMMAND_READ_MEMORY);

                uint bytesRead = 0;
                var  bytes     = BitConverter.GetBytes(ByteSwap.Swap(address));
                var  bytes2    = BitConverter.GetBytes(ByteSwap.Swap(address + length));
                GUC.Write(bytes, 4, ref bytesRead);
                GUC.Write(bytes2, 4, ref bytesRead);
            }
            catch (Exception)
            {
            }
        }
示例#3
0
        /// <summary>
        /// Write Paritioned Bytes to the Wii U
        /// </summary>
        /// <param name="address">Address to write to</param>
        /// <param name="byteChunks">Partitioned Bytes to write</param>
        private void WritePartitionedBytes(uint address, IEnumerable <byte[]> byteChunks)
        {
            IEnumerable <byte[]> enumerable = byteChunks as IList <byte[]> ?? byteChunks.ToList();
            var length = (uint)enumerable.Sum(chunk => chunk.Length);

            try
            {
                SendCommand(GeckoUCommands.Command.COMMAND_UPLOAD_MEMORY);

                uint bytesRead = 0;
                var  start     = BitConverter.GetBytes(ByteSwap.Swap(address));
                var  end       = BitConverter.GetBytes(ByteSwap.Swap(address + length));

                GUC.Write(start, 4, ref bytesRead);
                GUC.Write(end, 4, ref bytesRead);

                enumerable.Aggregate(address, UploadBytes);
            }
            catch (Exception Error)
            {
                Console.Write(Error.Message);
            }
        }
示例#4
0
        /// <summary>
        /// Call a function from an RPL/RPX
        /// </summary>
        /// <param name="address">The function address to call</param>
        /// <param name="args">The arguements to pass through</param>
        /// <returns>UInt64</returns>
        public UInt64 CallFunction64(uint address, params uint[] args)
        {
            byte[] buffer = new Byte[4 + 8 * 4];

            address = ByteSwap.Swap(address);

            BitConverter.GetBytes(address).CopyTo(buffer, 0);

            for (int i = 0; i < 8; i++)
            {
                if (i < args.Length)
                {
                    BitConverter.GetBytes(ByteSwap.Swap(args[i])).CopyTo(buffer, 4 + i * 4);
                }
                else
                {
                    BitConverter.GetBytes(0xfecad0ba).CopyTo(buffer, 4 + i * 4);
                }
            }

            if (RawCommand(GeckoUCommands.cmd_rpc) != FTDICommand.CMD_OK)
            {
                throw new GeckoUException(GeckoUException.ETCPErrorCode.FTDICommandSendError);
            }

            if (GeckoUWrite(buffer, buffer.Length) != FTDICommand.CMD_OK)
            {
                throw new GeckoUException(GeckoUException.ETCPErrorCode.FTDICommandSendError);
            }

            if (GeckoURead(buffer, 8) != FTDICommand.CMD_OK)
            {
                throw new GeckoUException(GeckoUException.ETCPErrorCode.FTDICommandSendError);
            }

            return(ByteSwap.Swap(BitConverter.ToUInt64(buffer, 0)));
        }
示例#5
0
        public UInt32 ReadAddress32(UInt32 addressToRead)
        {
            //dumpStream.Seek(addressToRead - startAddress, SeekOrigin.Begin);
            //byte [] buffer = new byte[4];

            //dumpStream.Read(buffer, 0, 4);
            if (addressToRead < startAddress)
            {
                return(0);
            }
            if (addressToRead > endAddress - 4)
            {
                return(0);
            }
            Byte[] buffer = new Byte[4];
            Buffer.BlockCopy(mem, index(addressToRead), buffer, 0, 4);
            //GeckoApp.SubArray<byte> buffer = new GeckoApp.SubArray<byte>(mem, (int)(addressToRead - startAddress), 4);

            //Read buffer
            UInt32 result = BitConverter.ToUInt32(buffer, 0);

            //Swap to machine endianness and return
            return(ByteSwap.Swap(result));
        }