Exemple #1
0
        public void DumpTree()
        {
            //address will be alligned to 4
            UInt32 paddress = 0x80000038;

            //Create a memory stream for the actual dump
            MemoryStream stream = new MemoryStream();

            try
            {
                //dump data
                gecko.Dump(paddress, paddress + 8, stream);

                //go to beginning
                stream.Seek(0, SeekOrigin.Begin);
                Byte[] buffer = new Byte[8];
                stream.Read(buffer, 0, 8);

                //Stream can be cleared now
                stream.Close();

                //Read buffer
                UInt32 fstadd  = BitConverter.ToUInt32(buffer, 0);
                UInt32 fstsize = BitConverter.ToUInt32(buffer, 4);

                //Swap to machine endianness and return
                fstadd  = ByteSwap.Swap(fstadd);
                fstsize = ByteSwap.Swap(fstsize);

                stream = new MemoryStream();
                gecko.Dump(fstadd, fstadd + fstsize + 1, stream);
                stream.Seek(-1, SeekOrigin.End);
                buffer = new Byte[] { 0xFF };
                stream.Write(buffer, 0, 1);

                stream.Seek(0, SeekOrigin.Begin);
                buffer = new Byte[0xC];
                stream.Read(buffer, 0, 12);

                Byte   flag = buffer[0];
                UInt32 truenameoff;
                buffer[0] = 0;
                UInt32 nameoff = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0));
                UInt32 offset  = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 4));
                UInt32 entries = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 8));
                long   fstpos  = stream.Position;
                UInt32 strpos  = entries * 0x0C;
                UInt32 endpos  = strpos;

                //List<TreeNode> rootArr = new List<TreeNode>();
                List <fileStructure> rootArr = new List <fileStructure>();
                List <UInt32>        dirSize = new List <UInt32>();
                dirSize.Add(0);

                fstTextPositions.Clear();
                sourceFile                = null;
                targetFile                = null;
                generatedSwapCode.Text    = "";
                targetFileName.Text       = "";
                sourceFileName.Text       = "";
                setAsSourceButton.Enabled = false;
                setAsTargetButton.Enabled = false;
                generateFileSwap.Enabled  = false;
                swapFilesNow.Enabled      = false;
                selectedFile              = -1;

                //TreeNode current = treeView.Nodes.Add("Root");
                fileStructure current = new fileStructure("Root", -1);
                root = current;

                int tag;
                int curDir = 0;
                rootArr.Add(current);
                String nname;
                do
                {
                    stream.Seek(fstpos, SeekOrigin.Begin);
                    stream.Read(buffer, 0, 12);

                    flag        = buffer[0];
                    truenameoff = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0));
                    buffer[0]   = 0;
                    nameoff     = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0));
                    offset      = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 4));
                    entries     = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 8));

                    fstTextPositions.Add(new fstEntry((UInt32)fstpos + fstadd,
                                                      truenameoff, offset, entries, (UInt32)fstpos + strpos + nameoff));
                    tag = fstTextPositions.Count - 1;

                    fstpos = stream.Position;

                    stream.Seek(strpos + nameoff, SeekOrigin.Begin);
                    //fstTextPositions.Add((UInt32)stream.Position + fstadd);
                    nname = ReadString(stream);

                    do
                    {
                        if (fstpos == dirSize[curDir] * 0x0C + 0x0C && curDir > 0)
                        {
                            dirSize[curDir] = 0;
                            curDir--;
                        }
                    } while (curDir != 0 && fstpos >= dirSize[curDir] * 0x0C + 0x0C);

                    if (flag == 0)
                    {
                        //current = rootArr[curDir].Nodes.Add(nname);
                        rootArr[curDir].addFile(nname, tag);
                        //image crap
                    }
                    else
                    {
                        curDir++;
                        current = rootArr[curDir - 1].addSubFolder(nname, tag);
                        //current = rootArr[curDir-1].Nodes.Add(nname);
                        //image crap
                        if (rootArr.Count > curDir)
                        {
                            rootArr[curDir] = current;
                            dirSize[curDir] = entries;
                        }
                        else
                        {
                            rootArr.Add(current);
                            dirSize.Add(entries);
                        }
                    }
                } while (fstpos < endpos);
                stream.Close();

                root.Sort();
                root.ToTreeView(treeView);
            }
            catch (EUSBGeckoException e)
            {
                exceptionHandling.HandleException(e);
            }
            catch
            {
            }
        }
Exemple #2
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
            {
            }
        }