Пример #1
0
        private void extractSingleFST(UInt16 entry, string parent)
        {
            if (!Directory.Exists(extractPath))
            {
                Directory.CreateDirectory(extractPath);
            }

            fst_t fst = getFST(entry);

            switch (fst.mode)
            {
            case 0:
                extractDir(fst, entry, parent);
                break;

            case 1:
                extractFile(fst, entry, parent);
                break;

            default:
                msg_Error(String.Format("Ignoring unsupported mode {0}.\n\t\t(FST entry #{1})",
                                        fst.mode,
                                        entry.ToString("x4")));
                break;
            }
        }
Пример #2
0
        private void addEntry(fst_t fst, UInt16 entry, UInt16 parent)
        {
            string details;

            string[]   modes = { "d|", "f|" };
            TreeNode[] node  = fileView.Nodes.Find(parent.ToString("x4"), true);

            details  = ASCIIEncoding.ASCII.GetString(fst.filename).Replace("\0", " ");
            details += txtPadLeft(modes[fst.mode], 5);
            details += txtPadRight(fst.attr.ToString(), 3);
            details += string.Format("{0}:{1}",
                                     fst.uid.ToString("x4").ToUpper(),
                                     fst.gid.ToString("x4").ToUpper());
            if (fst.size > 0)
            {
                details += txtPadLeft(fst.size.ToString("d"), 11) + "B";
            }

            if (entry != 0)
            {
                if (node.Count() > 0)
                {
                    node[0].Nodes.Add(entry.ToString("x4"), details, fst.mode, fst.mode);
                }
                else
                {
                    fileView.Nodes.Add(entry.ToString("x4"), details, fst.mode, fst.mode);
                }
            }

            if (fst.mode == 0 && fst.sub != 0xffff)
            {
                viewFST(fst.sub, entry);
            }
        }
Пример #3
0
        private void extractFST(UInt16 entry, string parent)
        {
            fst_t fst = getFST(entry);

            if (fst.sib != 0xffff)
            {
                extractFST(fst.sib, parent);
            }

            switch (fst.mode)
            {
            case 0:
                extractDir(fst, entry, parent);
                break;

            case 1:
                extractFile(fst, entry, parent);
                break;

            default:
                msg_Error(String.Format("Ignoring unsupported mode {0}.\n\t\t(FST entry #{1})",
                                        fst.mode,
                                        entry.ToString("x4")));
                break;
            }
        }
Пример #4
0
        /*
         * Viewer functions.
         */
        private void viewFST(UInt16 entry, UInt16 parent)
        {
            fst_t fst = getFST(entry);

            if (fst.sib != 0xffff)
            {
                viewFST(fst.sib, parent);
            }

            addEntry(fst, entry, parent);

            info.Items["size"].Text  = (Convert.ToInt32(info.Items["size"].Text) + (int)fst.size).ToString();
            info.Items["files"].Text = (Convert.ToInt32(info.Items["files"].Text) + 1).ToString();
            Application.DoEvents();
        }
    private static void extractDir(fst_t fst, UInt16 entry, string parent)
    {
        string filename = ASCIIEncoding.ASCII.GetString(fst.filename).Replace("\0", string.Empty);

        if (filename != "/")
        {
            if (parent != "/" && parent != "")
            {
                filename = parent + "\\" + filename;
            }

            Directory.CreateDirectory(extractPath + "\\" + filename);
        }

        if (fst.sub != 0xffff)
        {
            extractFST(fst.sub, filename);
        }
    }
Пример #6
0
    private static void extractFile(fst_t fst, UInt16 entry, string parent)
    {
        UInt16 fat;
        int    cluster_span = (int)(fst.size / 0x4000) + 1;

        byte[] cluster = new byte[0x4000],
        data = new byte[cluster_span * 0x4000];

        string filename = "/" + parent + "/" +
                          ASCIIEncoding.ASCII.GetString(fst.filename).
                          Replace("\0", string.Empty).
                          Replace(":", "-");

        Console.WriteLine("Extracting " + filename);

        try
        {
            BinaryWriter bw = new BinaryWriter(File.Open(extractPath + filename,
                                                         FileMode.Create,
                                                         FileAccess.Write,
                                                         FileShare.Read),
                                               Encoding.ASCII);
            fat = fst.sub;
            for (int i = 0; fat < 0xFFF0; i++)
            {
                Buffer.BlockCopy(getCluster(fat), 0, data, i * 0x4000, 0x4000);
                fat = getFAT(fat);
            }

            bw.Write(data, 0, (int)fst.size);
            bw.Close();
        }
        catch
        {
            //msg_Error(string.Format("Can't open file for writing:\n{0}",
            //                            extractPath + filename));
            throw new Exception(string.Format("Can't open file: {0}", extractPath + filename));
        }
    }
    private static void extractFST(UInt16 entry, string parent)
    {
        fst_t fst = getFST(entry);

        if (fst.sib != 0xffff)
        {
            extractFST(fst.sib, parent);
        }

        switch (fst.mode)
        {
        case 0:
            extractDir(fst, entry, parent);
            break;

        case 1:
            extractFile(fst, entry, parent);
            break;

        default:
            break;
        }
    }
Пример #8
0
        private fst_t getFST(UInt16 entry)
        {
            fst_t fst = new fst_t();

            // compensate for 64 bytes of ecc data every 64 fst entries
            Int32 n_fst     = (fileType == FileType.NoECC) ? 0 : 2;
            int   loc_entry = (((entry / 0x40) * n_fst) + entry) * 0x20;

            rom.BaseStream.Seek(loc_fst + loc_entry, SeekOrigin.Begin);

            fst.filename = rom.ReadBytes(0x0C);
            fst.mode     = rom.ReadByte();
            fst.attr     = rom.ReadByte();
            fst.sub      = bswap(rom.ReadUInt16());
            fst.sib      = bswap(rom.ReadUInt16());
            fst.size     = bswap(rom.ReadUInt32());
            fst.uid      = bswap(rom.ReadUInt32());
            fst.gid      = bswap(rom.ReadUInt16());
            fst.x3       = bswap(rom.ReadUInt32());

            fst.mode &= 1;

            return(fst);
        }
Пример #9
0
    private static fst_t getFST(UInt16 entry)
    {
        fst_t fst = new fst_t();

        // compensate for 64 bytes of ecc data every 64 fst entries
        Int32[] n_fst = { 0, 2, 2 };
        int loc_entry = (((entry / 0x40) * n_fst[type]) + entry) * 0x20;

        rom.BaseStream.Seek(loc_fst + loc_entry, SeekOrigin.Begin);

        fst.filename = rom.ReadBytes(0x0C);
        fst.mode = rom.ReadByte();
        fst.attr = rom.ReadByte();
        fst.sub = bswap(rom.ReadUInt16());
        fst.sib = bswap(rom.ReadUInt16());
        fst.size = bswap(rom.ReadUInt32());
        fst.uid = bswap(rom.ReadUInt32());
        fst.gid = bswap(rom.ReadUInt16());
        fst.x3 = bswap(rom.ReadUInt32());

        fst.mode &= 1;

        return fst;
    }
Пример #10
0
    private static void extractFile(fst_t fst, UInt16 entry, string parent)
    {
        UInt16 fat;
        int cluster_span = (int)(fst.size / 0x4000) + 1;
        byte[] cluster = new byte[0x4000],
               data = new byte[cluster_span * 0x4000];

        string filename = "/" + parent + "/" +
                        ASCIIEncoding.ASCII.GetString(fst.filename).
                        Replace("\0", string.Empty).
                        Replace(":", "-");
        Console.WriteLine("Extracting " + filename);

        try
        {
            BinaryWriter bw = new BinaryWriter(File.Open(extractPath + filename,
                                                            FileMode.Create,
                                                            FileAccess.Write,
                                                            FileShare.Read),
                                                        Encoding.ASCII);
            fat = fst.sub;
            for (int i = 0; fat < 0xFFF0; i++)
            {
                Buffer.BlockCopy(getCluster(fat), 0, data, i * 0x4000, 0x4000);
                fat = getFAT(fat);
            }

            bw.Write(data, 0, (int)fst.size);
            bw.Close();
        }
        catch
        {
            //msg_Error(string.Format("Can't open file for writing:\n{0}",
            //                            extractPath + filename));
            throw new Exception(string.Format("Can't open file: {0}", extractPath + filename));
        }
    }
Пример #11
0
    private static void extractDir(fst_t fst, UInt16 entry, string parent)
    {
        string filename = ASCIIEncoding.ASCII.GetString(fst.filename).Replace("\0", string.Empty);

        if (filename != "/")
        {
            if (parent != "/" && parent != "")
                filename = parent + "/" + filename;

            Directory.CreateDirectory(extractPath + "/" + filename);
        }

        if (fst.sub != 0xffff)
            extractFST(fst.sub, filename);
    }