Пример #1
0
        private void TargetButtonClick(object sender, EventArgs e)
        {
            if (selectedFile == -1)
            {
                return;
            }
            fstEntry oldTarget     = targetFile;
            String   oldTargetFile = targetFileName.Text;

            targetFile = fstTextPositions[selectedFile];
            if (targetFile == sourceFile)
            {
                if (oldTarget != null)
                {
                    sourceFile          = oldTarget;
                    sourceFileName.Text = oldTargetFile;
                }
                else
                {
                    sourceFile          = null;
                    sourceFileName.Text = "";
                }
            }
            targetFileName.Text = selFile;

            if (sourceFile != null)
            {
                generateFileSwap.Enabled = true;
                swapFilesNow.Enabled     = true;
            }
        }
Пример #2
0
        public FST(USBGecko UGecko, TreeView UTreeView, TextBox UFileSwapCode,
                   Button USetAsSourceButton, Button USetAsTargetButton, Button UGenerateFileSwap,
                   Label USourceFileName, Label UTargetFileName, TextBox UGeneratedSwapCode,
                   Button USwapNowButton, ExceptionHandler UExceptionHandling)
        {
            exceptionHandling = UExceptionHandling;
            imgList           = new ImageList();
#if !MONO
            System.Drawing.Icon ni = IconReader.GetFolderIcon(IconReader.IconSize.Small,
                                                              IconReader.FolderType.Closed);
            imgList.Images.Add(ni);
            ni = IconReader.GetFolderIcon(IconReader.IconSize.Small,
                                          IconReader.FolderType.Open);
            imgList.Images.Add(ni);
            ni = IconReader.GetFileIcon("?.?", IconReader.IconSize.Small, false);
            imgList.Images.Add(ni);
#endif
            treeView                 = UTreeView;
            treeView.ImageList       = imgList;
            treeView.NodeMouseClick += TreeView_NodeMouseClick;
            gecko            = UGecko;
            fstTextPositions = new List <fstEntry>();

            fileSwapCode = UFileSwapCode;

            sourceFile        = null;
            targetFile        = null;
            setAsSourceButton = USetAsSourceButton;
            setAsTargetButton = USetAsTargetButton;
            generateFileSwap  = UGenerateFileSwap;
            sourceFileName    = USourceFileName;
            targetFileName    = UTargetFileName;
            generatedSwapCode = UGeneratedSwapCode;
            swapFilesNow      = USwapNowButton;

            setAsSourceButton.Click += SourceButtonClick;
            setAsTargetButton.Click += TargetButtonClick;
            generateFileSwap.Click  += GenSwapButtonClick;
            swapFilesNow.Click      += ImmediateSwap;

            generatedSwapCode.Text    = "";
            targetFileName.Text       = "";
            sourceFileName.Text       = "";
            setAsSourceButton.Enabled = false;
            setAsTargetButton.Enabled = false;
            generateFileSwap.Enabled  = false;
            swapFilesNow.Enabled      = false;
            selectedFile = -1;
        }
Пример #3
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
            {
            }
        }