Esempio n. 1
0
        public static uint[] DumpSaveSlots(TCPGecko gecko, uint diff, uint start, uint size)
        {
            using (var memoryStream = new MemoryStream())
            {
                // dump all save slots
                gecko.Dump(start + diff, start + diff + size, memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);

                // convert to a uint array
                var saveSlots = new uint[size / 4];
                for (var i = 0; i < saveSlots.Length; i++)
                {
                    var buffer = new byte[4];
                    memoryStream.Read(buffer, 0, 4);
                    saveSlots[i] = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0));
                }

                return(saveSlots);
            }
        }
Esempio n. 2
0
        public void Update(bool fast)
        {
            MemoryStream miniDump = new MemoryStream();
            int          oldColumnIndex, oldRowIndex;

            if (gView.SelectedCells.Count > 0)
            {
                oldColumnIndex = gView.SelectedCells[0].ColumnIndex;
                oldRowIndex    = gView.SelectedCells[0].RowIndex;
            }
            else
            {
                oldColumnIndex = 1;
                oldRowIndex    = 1;
            }

            UInt32 sAddress = cAddress & 0xFFFFFFF0;
            UInt32 offset   = cAddress - sAddress;

            try
            {
                gecko.Dump(sAddress, sAddress + 0x100, miniDump);

                //gView.Rows.Add(16);
                // Only clear and re-load gView.Rows when it's != 16
                // This was one thing slowing us down...
                if (gView.Rows.Count != 16)
                {
                    gView.Rows.Clear();
                    gView.Rows.Add(16);
                }

                miniDump.Seek(0, SeekOrigin.Begin);
                UInt32 value, bValue;
                Byte[] buffer = new Byte[4];
                UInt16 hwInput;
                UInt32 pValue = 0;
                for (int i = 0; i < 16; i++)
                {
                    gView.Rows[i].Cells[0].Value = GlobalFunctions.toHex(sAddress + i * 16);
                    for (int j = 1; j < 5; j++)
                    {
                        miniDump.Read(buffer, 0, 4);
                        bValue = BitConverter.ToUInt32(buffer, 0);
                        value  = ByteSwap.Swap(bValue);
                        if (sAddress + i * 0x10 + (j - 1) * 4 == selAddress)
                        {
                            pValue = value;
                        }
                        DataGridViewCell cell = gView.Rows[i].Cells[j];
                        if (PViewMode == MemoryViewMode.Hex)
                        {
                            cell.Value = GlobalFunctions.toHex(value);
                        }
                        else if (PViewMode == MemoryViewMode.ASCII)
                        {
                            cell.Value = DecodeASCII(buffer);
                        }
                        else if (PViewMode == MemoryViewMode.ANSI)
                        {
                            cell.Value = DecodeANSI(buffer);
                        }
                        else if (PViewMode == MemoryViewMode.Unicode)
                        {
                            cell.Value = DecodeUnicode(buffer);
                        }
                        else if (PViewMode == MemoryViewMode.Single)
                        {
                            cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value));
                        }
                        else if (PViewMode == MemoryViewMode.AutoZero || PViewMode == MemoryViewMode.AutoDot)
                        {
                            // if it might be a pointer, cast it as hex
                            if (ValidMemory.validAddress(value))
                            {
                                cell.Value = GlobalFunctions.toHex(value);
                            }
                            else
                            {
                                // If it's a float, and it's not too big or small, cast it as a Single
                                Single singleCast = GlobalFunctions.UIntToSingle(value);
                                if (!Single.IsNaN(singleCast) && Math.Abs(singleCast) > 1e-7 && Math.Abs(singleCast) < 1e10)
                                {
                                    cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value));
                                }
                                else
                                {
                                    if (IsASCII(buffer))
                                    {
                                        if (PViewMode == MemoryViewMode.AutoZero && value == 0)
                                        {
                                            // Cast 0 as hex in auto zero mode
                                            cell.Value = GlobalFunctions.toHex(value);
                                        }
                                        else
                                        {
                                            // If all characters are valid printable ASCII, cast it as char
                                            cell.Value = DecodeASCII(buffer);
                                        }
                                    }
                                    else
                                    {
                                        // When all else fails, cast as hex
                                        cell.Value = GlobalFunctions.toHex(value);
                                    }
                                }
                            }
                        }
                    }
                }
                oldRow = (int)offset / 0x10;
                oldCol = (int)(offset & 0xC) / 4 + 1;
                if (!fast)
                {
                    gView.Rows[oldRowIndex].Cells[oldColumnIndex].Selected = true;
                    // Don't update the poke value during auto-updates
                    // This way the user can still poke things

                    // TODO: Ignore this if the poke operation isn't write?
                    //pokeValue.Text = GlobalFunctions.toHex(pValue);
                }

                pokeAddress.Text = GlobalFunctions.toHex(selAddress);
                fpValue.Text     = GlobalFunctions.UIntToSingle(pValue).ToString("G6");
            }
            catch (ETCPGeckoException e)
            {
                exceptionHandling.HandleException(e);
            }
        }
Esempio n. 3
0
        public void Update(bool fast)
        {
            MemoryStream miniDump = new MemoryStream();
            int          oldColumnIndex, oldRowIndex;

            if (gView.SelectedCells.Count > 0)
            {
                oldColumnIndex = gView.SelectedCells[0].ColumnIndex;
                oldRowIndex    = gView.SelectedCells[0].RowIndex;
            }
            else
            {
                oldColumnIndex = 1;
                oldRowIndex    = 1;
            }

            uint sAddress = cAddress & 0xFFFFFFF0;
            uint offset   = cAddress - sAddress;

            try
            {
                gecko.Dump(sAddress, sAddress + 0x100, miniDump);

                if (gView.Rows.Count != 16)
                {
                    gView.Rows.Clear();
                    gView.Rows.Add(16);
                }

                miniDump.Seek(0, SeekOrigin.Begin);
                uint   value, bValue;
                byte[] buffer = new byte[4];
                uint   pValue = 0;
                for (int i = 0; i < 16; i++)
                {
                    gView.Rows[i].Cells[0].Value = GlobalFunctions.toHex(sAddress + i * 16);
                    for (int j = 1; j < 5; j++)
                    {
                        miniDump.Read(buffer, 0, 4);
                        bValue = BitConverter.ToUInt32(buffer, 0);
                        value  = ByteSwap.Swap(bValue);
                        if (sAddress + i * 0x10 + (j - 1) * 4 == selectedAddress)
                        {
                            pValue = value;
                        }
                        DataGridViewCell cell = gView.Rows[i].Cells[j];
                        if (viewMode == MemoryViewMode.Hex)
                        {
                            cell.Value = GlobalFunctions.toHex(value);
                        }
                        else if (viewMode == MemoryViewMode.ASCII)
                        {
                            cell.Value = DecodeASCII(buffer);
                        }
                        else if (viewMode == MemoryViewMode.ANSI)
                        {
                            cell.Value = DecodeANSI(buffer);
                        }
                        else if (viewMode == MemoryViewMode.Unicode)
                        {
                            cell.Value = DecodeUnicode(buffer);
                        }
                        else if (viewMode == MemoryViewMode.Single)
                        {
                            cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value));
                        }
                        else if (viewMode == MemoryViewMode.AutoZero || viewMode == MemoryViewMode.AutoDot)
                        {
                            if (ValidMemory.validAddress(value))
                            {
                                cell.Value = GlobalFunctions.toHex(value);
                            }
                            else
                            {
                                float singleCast = GlobalFunctions.UIntToSingle(value);
                                if (!float.IsNaN(singleCast) && Math.Abs(singleCast) > 1e-7 && Math.Abs(singleCast) < 1e10)
                                {
                                    cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value));
                                }
                                else
                                {
                                    if (IsASCII(buffer))
                                    {
                                        if (viewMode == MemoryViewMode.AutoZero && value == 0)
                                        {
                                            cell.Value = GlobalFunctions.toHex(value);
                                        }
                                        else
                                        {
                                            cell.Value = DecodeASCII(buffer);
                                        }
                                    }
                                    else
                                    {
                                        cell.Value = GlobalFunctions.toHex(value);
                                    }
                                }
                            }
                        }
                    }
                }
                oldRow = (int)offset / 0x10;
                oldCol = (int)(offset & 0xC) / 4 + 1;
                if (!fast)
                {
                    gView.Rows[oldRowIndex].Cells[oldColumnIndex].Selected = true;
                }

                pokeAddress.Text = GlobalFunctions.toHex(selectedAddress);
                fpValue.Text     = GlobalFunctions.UIntToSingle(pValue).ToString("G6");
            }
            catch (ETCPGeckoException e)
            {
                exceptionHandling.HandleException(e);
            }
        }
Esempio n. 4
0
        //DUMP
        public void nameDump(uint address, uint length, uint nameOffset)
        {
            //dumps all the player names
            for (uint i = 0; i < 8; i++)
            {
                try
                {
                    using (MemoryStream Player = new MemoryStream())
                    {
                        //dumps data from memory
                        Gecko.Dump(address + (i * nameOffset), address + (i * nameOffset) + 0x1A, Player);

                        //define dump to byte array
                        Player.Seek(0, SeekOrigin.Begin);
                        byte[] b = Player.GetBuffer();

                        //checks name before reading
                        if (!(canName = validNamesChecker(b)))
                        {
                            delayRead = 0;
                            break; // cancel and exit the for loop
                        }

                        byte[] playersArray = new byte[0x16];
                        Array.Copy(b, 8, playersArray, 0, 0x16);

                        //detects name length before a 16-bit null at every name
                        uint nameLength = 0;
                        for (uint c = 0; c < 0x16; c += 2)
                        {
                            if (playersArray[c] == 0 && playersArray[c + 1] == 0)
                            {
                                nameLength = c;
                                break;
                            }
                        }

                        //clone the displayable name array before the first null byte
                        name[i] = new byte[nameLength];
                        Array.Copy(playersArray, name[i], nameLength);
                    }
                }
                catch (ETCPGeckoException)
                {
                    Disconnect();
                    MessageBox.Show(Properties.Strings.ERROR, "Session Has Been Disconnected", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            //displays all names on the GUI
            if (canName)
            {
                changeNames();
            }

            //set no loop delay with every successful read (except the 0x12 range)
            if (modeComboBox.Text == "Classic (slow)")
            {
                delayRead = 0;
            }
            else if (canName)
            {
                delayRead = 1337;
            }
        }
Esempio n. 5
0
        public void DumpTree(params String[] folders)
        {
            UInt32 FSInit;
            UInt32 FSAddClient;
            UInt32 FSDelClient;
            UInt32 FSInitCmdBlock;
            UInt32 FSOpenDir;
            UInt32 FSCloseDir;
            UInt32 FSReadDir;
            UInt32 memalign;
            UInt32 free;

            switch (gecko.OsVersionRequest())
            {
            case 400:
            case 410:
                FSInit         = 0x01060d70;
                FSAddClient    = 0x01061290;
                FSDelClient    = 0x0106129c;
                FSInitCmdBlock = 0x01061498;
                FSOpenDir      = 0x01066f3c;
                FSCloseDir     = 0x01066fac;
                FSReadDir      = 0x0106702c;
                memalign       = gecko.peek(0x10049edc);
                free           = gecko.peek(0x100adc2c);
                break;

            case 500:
            case 510:
                FSInit         = 0x010666fc;
                FSAddClient    = 0x01066d80;
                FSDelClient    = 0x01066d8c;
                FSInitCmdBlock = 0x01066fec;
                FSOpenDir      = 0x0106db58;
                FSCloseDir     = 0x0106dbc8;
                FSReadDir      = 0x0106dc48;
                memalign       = gecko.peek(0x1004e2d0);
                free           = gecko.peek(0x100b41fc);
                break;

            case 532:
            case 540:
                FSInit         = 0x010683C8;
                FSAddClient    = 0x010689FC;
                FSDelClient    = 0x01068A08;
                FSInitCmdBlock = 0x01068C54;
                FSOpenDir      = 0x0106F690;
                FSCloseDir     = 0x0106F700;
                FSReadDir      = 0x0106F780;
                memalign       = gecko.peek(0x100b4878);
                free           = gecko.peek(0x100b487c);
                break;

            default:
                MessageBox.Show("Unsupported Wii U OS version.", "Version mismatch", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                UInt32 ret;
                ret = gecko.rpc(FSInit);

                UInt32 pClient = gecko.rpc(memalign, 0x1700, 0x20);
                if (pClient == 0)
                {
                    goto noClient;
                }
                UInt32 pCmd = gecko.rpc(memalign, 0xA80, 0x20);
                if (pCmd == 0)
                {
                    goto noCmd;
                }

                ret = gecko.rpc(FSAddClient, pClient, 0);
                ret = gecko.rpc(FSInitCmdBlock, pCmd);

                UInt32 pDh = gecko.rpc(memalign, 4, 4);
                if (pDh == 0)
                {
                    goto noDh;
                }
                UInt32 pPath = gecko.rpc(memalign, 0x200, 0x20);
                if (pPath == 0)
                {
                    goto noPath;
                }
                UInt32 pBuf = gecko.rpc(memalign, 0x200, 0x20);
                if (pBuf == 0)
                {
                    goto noBuf;
                }

                root = new fileStructure("vol", -1);
                Queue <fileStructure> scanQueue = new Queue <fileStructure>();
                foreach (String item in folders)
                {
                    scanQueue.Enqueue(root.addSubFolder(item, -1));
                }
                while (scanQueue.Count > 0)
                {
                    fileStructure current = scanQueue.Dequeue();
                    using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(current.Path + "\0")))
                    {
                        gecko.Upload(pPath, pPath + (uint)ms.Length, ms);
                    }


                    ret = gecko.rpc(FSOpenDir, pClient, pCmd, pPath, pDh, 0xffffffff);
                    if (ret != 0)
                    {
                        goto noDir;
                    }

                    UInt32 dh = gecko.peek(pDh);

                    do
                    {
                        ret = gecko.rpc(FSReadDir, pClient, pCmd, dh, pBuf, 0xffffffff);
                        if (ret != 0)
                        {
                            break;
                        }

                        using (MemoryStream ms = new MemoryStream())
                        {
                            gecko.Dump(pBuf, pBuf + 0x200, ms);

                            Byte[] data = ms.ToArray();
                            UInt32 attr = ByteSwap.Swap(BitConverter.ToUInt32(data, 0));
                            UInt32 size = ByteSwap.Swap(BitConverter.ToUInt32(data, 8));

                            String name = new String(Encoding.ASCII.GetChars(data, 0x64, 0x100));
                            name = name.Remove(name.IndexOf('\0'));

                            if ((attr & 0x80000000) != 0)
                            {
                                scanQueue.Enqueue(current.addSubFolder(name, -1));
                            }
                            else
                            {
                                current.addFile(name, -1, size);
                            }
                        }
                    } while (true);

                    gecko.rpc(FSCloseDir, pClient, pCmd, dh, 0);
noDir:
                    continue;
                }

                gecko.rpc(free, pBuf);
noBuf:
                gecko.rpc(free, pPath);
noPath:
                gecko.rpc(free, pDh);
noDh:

                ret = gecko.rpc(FSDelClient, pClient);

                gecko.rpc(free, pCmd);
noCmd:
                gecko.rpc(free, pClient);
noClient:

                if (root != null)
                {
                    root.Sort();
                    root.ToTreeView(treeView);
                }
            }
            catch (ETCPGeckoException e)
            {
                exceptionHandling.HandleException(e);
            }
            catch
            {
            }
        }
Esempio n. 6
0
        public String[] Disassemble(UInt32 address, int commands)
        {
            List <String> result = new List <String>();

            address = address & 0xFFFFFFFC;
            UInt32 eAddress = address + (UInt32)commands * 4;

            if (!File.Exists(vdappPath))
            {
#if MONO
                return(new String[] { "vdappc not found!" });
#else
                return(new String[] { "vdappc.exe not found!" });
#endif
            }

            // TODO: who is leaving this file open?
            FileStream values;
            string     filename = System.IO.Path.GetTempFileName();
            try
            {
                values = new FileStream(filename, FileMode.Create);
            }
            catch (Exception e)
            {
                return(new String[] { "Couldn't open diss.bin!" });
            }

            try
            {
                gecko.Dump(address, eAddress, values);
            }
            catch (ETCPGeckoException e)
            {
                exceptionHandling.HandleException(e);
                return(result.ToArray());
            }
            finally
            {
                // This will always close the FileStream, even if the exception is handled
                values.Close();
            }

            Process proc = new Process();
            proc.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            proc.StartInfo.UseShellExecute        = false;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.FileName       = vdappPath;
            proc.StartInfo.Arguments      = "\"" + filename + "\" 0x" + GlobalFunctions.toHex(address);
            proc.StartInfo.CreateNoWindow = true;
            //proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            //proc.StartInfo.CreateNoWindow = false;
            proc.Start();

            // Must read from the standard output before waiting on the process to close!
            // Otherwise, the standard output buffer will be full and vdappc will lock up
            // and we would never read from the buffer
            while (!proc.StandardOutput.EndOfStream)
            {
                result.Add(proc.StandardOutput.ReadLine());
            }
            proc.WaitForExit(/*2000*/);

            //int exitCode = proc.ExitCode;
            //if (exitCode == 0)
            //{
            //    while (!proc.StandardOutput.EndOfStream)
            //        result.Add(proc.StandardOutput.ReadLine());
            //}
            proc.Close();

            File.Delete(filename);

            return(result.ToArray());
        }
Esempio n. 7
0
        public string[] Disassemble(uint address, int commands)
        {
            List <string> result = new List <string>();

            address = address & 0xFFFFFFFC;
            uint eAddress = address + (uint)commands * 4;

            if (!File.Exists(vdappPath))
            {
#if MONO
                return(new String[] { "vdappc not found!" });
#else
                return(new string[] { "vdappc.exe not found!" });
#endif
            }

            FileStream values;
            string     filename = System.IO.Path.GetTempFileName();
            try
            {
                values = new FileStream(filename, FileMode.Create);
            }
            catch (Exception)
            {
                return(new string[] { "Couldn't open diss.bin!" });
            }

            try
            {
                gecko.Dump(address, eAddress, values);
            }
            catch (ETCPGeckoException e)
            {
                exceptionHandling.HandleException(e);
                return(result.ToArray());
            }
            finally
            {
                values.Close();
            }

            Process proc = new Process();
            proc.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            proc.StartInfo.UseShellExecute        = false;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.FileName       = vdappPath;
            proc.StartInfo.Arguments      = "\"" + filename + "\" 0x" + GlobalFunctions.toHex(address);
            proc.StartInfo.CreateNoWindow = true;
            proc.Start();

            while (!proc.StandardOutput.EndOfStream)
            {
                result.Add(proc.StandardOutput.ReadLine());
            }
            proc.WaitForExit();

            proc.Close();

            File.Delete(filename);

            return(result.ToArray());
        }