Пример #1
0
 public Device(GTFS fs)
 {
     bool   flip                = false;
     string DevicePath          = GT.ReadASCII(fs, 256, flip);
     string DeviceBusID         = GT.ReadASCII(fs, 32, flip);
     int    busnum              = GT.ReadInt32(fs, 4, flip);
     int    devnum              = GT.ReadInt32(fs, 4, flip);
     int    speed               = GT.ReadInt32(fs, 4, flip);
     int    idVendor            = GT.ReadInt16(fs, 2, flip);
     int    idProduct           = GT.ReadInt16(fs, 2, flip);
     int    bcdDevice           = GT.ReadInt16(fs, 2, flip);
     int    bDeviceClass        = GT.ReadByte(fs);
     int    bDeviceSubClass     = GT.ReadByte(fs);
     int    bDeviceProtocol     = GT.ReadByte(fs);
     int    bConfigurationValue = GT.ReadByte(fs);
     int    bNumConfigurations  = GT.ReadByte(fs);
     int    bNumInterfaces      = GT.ReadByte(fs);
 }
Пример #2
0
        public static void OpenPack(OpenFileDialog openFileDialog)
        {
            bool flip = true;
            GTFS fs   = new GTFS(openFileDialog.FileName);

            uint nothing  = GT.ReadUInt32(fs, 4, flip);
            uint numFiles = GT.ReadUInt32(fs, 4, flip);
            uint offset   = GT.ReadUInt32(fs, 4, flip); // + 4 I guess?

            uint unknown = GT.ReadUInt32(fs, 4, flip);

            List <Pack> listPack = new List <Pack>();

            for (int i = 0; i < numFiles; i++)
            {
                byte   nameLen = GT.ReadByte(fs);
                string name    = GT.ReadASCII(fs, nameLen, false);
                int    fileLen = GT.ReadInt32(fs, 4, flip);

                listPack.Add(new Pack(name, -1, fileLen));
            }

            string toFolder = openFileDialog.SafeFileName.Replace('.', '_');

            if (!Directory.Exists(extract_path))
            {
                Directory.CreateDirectory(extract_path);
            }

            if (!Directory.Exists(extract_path + "\\" + toFolder))
            {
                Directory.CreateDirectory(extract_path + "\\" + toFolder);
            }

            foreach (Pack pack in listPack)
            {
                string newfile = extract_path + "\\" + toFolder + "\\" + pack.Filename;
                GT.WriteSubFile(fs, newfile, (int)pack.Size);
            }
        }
Пример #3
0
        public static object Get(GTFS fs)
        {
            bool flip   = true;
            int  first  = GT.ReadUInt16(fs, 2, flip);
            int  second = GT.ReadUInt16(fs, 2, flip);

            if (second == 32773)
            {
                OP_REQ_DEVLIST op     = new OP_REQ_DEVLIST();
                int            status = GT.ReadInt32(fs, 4, flip);

                return(op);
            }
            else if (second == 5)
            {
                OP_REP_DEVLIST op        = new OP_REP_DEVLIST();
                int            status    = GT.ReadInt32(fs, 4, flip);
                int            NumExport = GT.ReadInt32(fs, 4, flip);

                Device dev = new Device(fs);
                for (int i = 0; i < 1; i++)   //dev.bNumInterfaces
                {
                    byte bInterfaceClass    = GT.ReadByte(fs);
                    byte bInterfaceSubClass = GT.ReadByte(fs);
                    byte bInterfaceProtocol = GT.ReadByte(fs);
                    byte padding            = GT.ReadByte(fs);
                }

                return(op);
            }
            else if (second == 32771)
            {
                OP_REQ_IMPORT op     = new OP_REQ_IMPORT();
                int           status = GT.ReadInt32(fs, 4, flip);
                string        busid  = GT.ReadASCII(fs, 32, flip);
                return(op);
            }
            else if (second == 3)
            {
                OP_REP_IMPORT op     = new OP_REP_IMPORT();
                int           status = GT.ReadInt32(fs, 4, flip);
                Device        dev    = new Device(fs);
                return(op);
            }
            else if (second == 1)
            {
                USBIP_CMD_SUBMIT op           = new USBIP_CMD_SUBMIT();
                int    seqnum                 = GT.ReadInt32(fs, 4, flip);
                int    devid                  = GT.ReadInt32(fs, 4, flip);
                int    direction              = GT.ReadInt32(fs, 4, flip);
                int    ep                     = GT.ReadInt32(fs, 4, flip);
                byte[] transfer_flags         = GT.ReadBytes(fs, 4, flip);
                byte[] transfer_buffer_length = GT.ReadBytes(fs, 4, flip);
                byte[] start_frame            = GT.ReadBytes(fs, 4, flip);
                int    number_of_packets      = GT.ReadInt32(fs, 4, flip);
                int    interval               = GT.ReadInt32(fs, 4, flip);

                //URB Setup
                byte bmRequestType = GT.ReadByte(fs);
                byte bRequest      = GT.ReadByte(fs);
                int  wValue        = GT.ReadUInt16(fs, 2, false);
                int  wIndex        = GT.ReadUInt16(fs, 2, false);
                int  wLength       = GT.ReadUInt16(fs, 2, false);

                byte[] _remainingURB;
                if (fs.Position < fs.Length)
                {
                    _remainingURB = GT.ReadBytes(fs, (int)(fs.Length - fs.Position), flip);
                }

                return(op);
            }
            else if (second == 3)
            {
                USBIP_RET_SUBMIT op      = new USBIP_RET_SUBMIT();
                int    seqnum            = GT.ReadInt32(fs, 4, flip);
                int    devid             = GT.ReadInt32(fs, 4, flip);
                int    direction         = GT.ReadInt32(fs, 4, flip);
                int    ep                = GT.ReadInt32(fs, 4, flip);
                int    status            = GT.ReadInt32(fs, 4, flip);
                int    actual_length     = GT.ReadInt32(fs, 4, flip);
                byte[] start_frame       = GT.ReadBytes(fs, 4, flip);
                int    number_of_packets = GT.ReadInt32(fs, 4, flip);
                int    error_count       = GT.ReadInt32(fs, 4, flip);
                byte[] setup             = GT.ReadBytes(fs, 8, flip);
                byte[] _data             = GT.ReadBytes(fs, actual_length, flip);

                return(op);
            }

            return(null);
        }
Пример #4
0
        public override void Open(OpenFileDialog openFileDialog, bool export = false, bool useGTFSView = false)
        {
            openFileDialog.FileName = "";
            openFileDialog.Filter   = "All Hotel Dusk|*.anm;*.frm;*.wpf;*.bin;*.txt;*.dtx|"
                                      + "All Files (*.*)|*.*";

            DialogResult res = openFileDialog.ShowDialog();

            if (res == DialogResult.OK)
            {
                string[] filenameParts = openFileDialog.SafeFileName.Split('.');
                Array.Reverse(filenameParts);

                if (filenameParts[0].ToUpper() == "FRM")
                {
                    GTFS fs  = new GTFS(openFileDialog.FileName);
                    FRM  frm = new FRM(fs);

                    new FormImage(frm.bitmap).Show();
                }
                else if (filenameParts[0].ToUpper() == "ANM")
                {
                    GTFS fs  = new GTFS(openFileDialog.FileName);
                    ANM  anm = new ANM(fs);

                    new FormImageAnimated(anm.BitmapsBlended()).Show();
                }
                else if (filenameParts[0].ToUpper() == "WPF")
                {
                    WPF.Open(openFileDialog);
                }
                else if (filenameParts[0].ToUpper() == "WPFBIN" || filenameParts[0].ToUpper() == "BIN")
                {
                    GTFS fs = new GTFS(openFileDialog.FileName);

                    byte[] magic = GT.ReadBytes(fs, 4, false);
                    fs.Position = 0;
                    if (magic.SequenceEqual(LRIM.Magic))
                    {
                        LRIM lrim = new LRIM(fs);
                    }
                    else
                    {
                        WPFBIN wpfbin = new WPFBIN(fs);
                        new FormImage(wpfbin.bitmap).Show();
                    }
                }
                else if (filenameParts[0].ToUpper() == "DTX")
                {
                    GTFS   fs     = new GTFS(openFileDialog.FileName);
                    WPFBIN wpfbin = new WPFBIN(fs);
                    new FormImage(wpfbin.bitmap).Show();
                    //GTFS compressed = new GTFS(openFileDialog.FileName);
                    //GTFS decompressed = Decompress.ToGTFS(compressed);
                    //decompressed.WriteBytesToFile("GT-KH-DecompDTX.gtbin");
                }
                else if (filenameParts[0].ToUpper() == "TXT")
                {
                    GTFS compressed   = new GTFS(openFileDialog.FileName);
                    GTFS decompressed = Decompress.ToGTFS(compressed);
                    //decompressed.WriteBytesToFile("GT-KH-DecompTXT.gtbin");

                    byte[] test = GT.ReadBytes(decompressed, 4, false);
                    decompressed.Position = 0;

                    if (test[0] == 0 || test[1] == 0 || test[2] == 0 || test[3] == 3)
                    {
                        int total = GT.ReadInt32(decompressed, 4, false);
                        for (int i = 0; i < total; i++)
                        {
                            int offset = GT.ReadInt32(decompressed, 4, false);
                        }

                        long baseOffset = decompressed.Position;

                        string input = GT.ReadASCII(decompressed, (int)(decompressed.Length - 1 - baseOffset), false);
                        input = input.Replace((char)0x00, (char)0x20);

                        new FormText(input).Show();
                    }
                    else
                    {
                        string input = GT.ReadASCII(decompressed, decompressed.Length - 1, false);
                        input = input.Replace("\n", "\r\n");

                        new FormText(input).Show();
                    }
                }
                else
                {
                    MessageBox.Show("Unexpected file extension: " + filenameParts[0]);
                }
            }
        }
Пример #5
0
        public static List <string> Open(string file, string outdir)
        {
            GTFS fs = new GTFS(file);

            byte[] bHeader = GT.ReadBytes(fs, 4, false);
            bool   flip    = false;

            List <Pack> pack = new List <Pack>();

            if (bHeader[1] == 0x38)
            {
                long lOffsetTail        = GT.ReadUInt32(fs, 4, flip);
                long lNumResources      = GT.ReadUInt32(fs, 4, flip);
                long lOffsetStringTable = GT.ReadUInt32(fs, 4, flip);
                long lOffsetStringSize  = GT.ReadUInt32(fs, 4, flip);

                string hoho = GT.ReadASCII(fs, 12, flip);

                fs.Position = lOffsetTail;
                for (int i = 0; i < lNumResources; i++)
                {
                    long lOffsetFileName = GT.ReadUInt32(fs, 4, flip);
                    long lFileSize       = GT.ReadUInt32(fs, 4, flip);
                    long lOffsetFile     = GT.ReadUInt32(fs, 4, flip);

                    long   lStart  = lOffsetStringTable + lOffsetFileName;
                    string sString = GT.ReadASCIItoNull(fs, lStart, flip);

                    pack.Add(new Pack(sString, lOffsetFile, lFileSize));
                }
            }
            else if (bHeader[1] == 0x34)
            {
                long lOffsetTail = GT.ReadUInt32(fs, 4, flip);
                long lTailSize   = GT.ReadUInt32(fs, 4, flip);
                long lReserved   = GT.ReadUInt32(fs, 4, flip);

                fs.Position = lOffsetTail;
                long lNumResources = lTailSize / 60;
                for (int i = 0; i < lNumResources; i++)
                {
                    long last = fs.Position;

                    string sString = GT.ReadASCIItoNull(fs, fs.Position, flip);

                    fs.Position = last + 48;

                    long   lOffsetFile = GT.ReadUInt32(fs, 4, flip);
                    long   lFileSize   = GT.ReadUInt32(fs, 4, flip);
                    byte[] bFReserved  = GT.ReadBytes(fs, 4, false);

                    pack.Add(new Pack(sString, lOffsetFile, lFileSize));
                }
            }
            else
            {
                MessageBox.Show("Is " + file + " a TS2 Pak file?");
            }

            List <string> listFiles = new List <string>();

            foreach (Pack pf in pack)
            {
                pf.WriteOut(fs, outdir);
                listFiles.Add(pf.Filename);
            }
            return(listFiles);
        }
Пример #6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            GTFS brres = new GTFS(file);
            bool flip  = false;

            //Header
            string fileID = GT.ReadASCII(brres, 4, flip);

            byte[] bBOM = GT.ReadBytes(brres, 2, flip);
            if (bBOM[0] == 0xFE)
            {
                flip = true;
            }
            byte[] bPV         = GT.ReadBytes(brres, 2, flip); //Pad/Version
            uint   fileLen     = GT.ReadUInt32(brres, 4, flip);
            ushort rootOffset  = GT.ReadUInt16(brres, 2, flip);
            ushort numSections = GT.ReadUInt16(brres, 2, flip);

            //Root
            brres.Position = rootOffset;
            string rootID            = GT.ReadASCII(brres, 4, false);
            uint   rootLen           = GT.ReadUInt32(brres, 4, flip); ///  <<<<<<<<-------- This might be key, the group is as long as this?
            long   positionAfterRoot = brres.Position;

            //First index group
            //long lastPosition = brres.Position;

            //http://wiki.tockdom.com/wiki/BRRES_Index_Group_(File_Format)
            uint groupLen = GT.ReadUInt32(brres, 4, flip);
            uint groupNum = GT.ReadUInt32(brres, 4, flip);

            Console.WriteLine();

            for (uint i = 0; i < groupNum + 1; i++)  //First group is special, doesn't count
            {
                ushort entryID    = GT.ReadUInt16(brres, 2, flip);
                ushort unknown    = GT.ReadUInt16(brres, 2, flip); //Zero?
                ushort indexLeft  = GT.ReadUInt16(brres, 2, flip);
                ushort indexRight = GT.ReadUInt16(brres, 2, flip);
                uint   nameOffset = GT.ReadUInt32(brres, 4, flip);
                uint   dataOffset = GT.ReadUInt32(brres, 4, flip);

                if (i == 0)
                {
                    continue;
                }

                long posLast = brres.Position;
                //--
                //long lNameOffset = rootOffset + 4 + nameOffset;
                brres.Position = rootOffset + 4 + nameOffset;
                uint nameLen = GT.ReadUInt32(brres, 4, flip);
                if (nameLen > 30)
                {
                    throw new Exception();
                }

                string name        = GT.ReadASCII(brres, (int)nameLen, false);
                ushort nameGapZero = GT.ReadUInt16(brres, 2, flip); //Zero?
                uint   name2Len    = GT.ReadUInt32(brres, 4, flip);
                string name2       = GT.ReadASCII(brres, (int)name2Len, false);
                //Console.WriteLine();
                //I have no idea, skipping
                //--
                brres.Position = posLast;
            }

            /*
             * brres.Position = 160;
             *
             *
             * //MDL0
             * long subfileoffstart = brres.Position;
             * string subfileID = GT.ReadASCII(brres, 4, false);
             * uint subfileLen = GT.ReadUInt32(brres, 4, flip);
             * uint subfileVer = GT.ReadUInt32(brres, 4, flip);
             *
             * if (subfileVer != 8)
             *  throw new Exception(); //Different version, different number of sections
             *
             * int outerOffset = GT.ReadInt32(brres, 4, flip); //Negative
             *
             * if (subfileVer == 8) { // N * 4
             *  for(int n = 0; n < subfileVer; n++) {
             *      uint n0 = GT.ReadUInt32(brres, 4, flip);
             *      uint n1 = GT.ReadUInt32(brres, 4, flip);
             *      uint n2 = GT.ReadUInt32(brres, 4, flip);
             *      uint n3 = GT.ReadUInt32(brres, 4, flip);
             *  }
             * }
             *
             * uint nameOffset2 = GT.ReadUInt32(brres, 4, flip) + (uint)subfileoffstart;
             *
             * //brres.Position = lastPosition + groupLen;
             *
             * //string nextID = ReadASCII(brres, 4, false);
             *
             * long position = brres.Position;
             * Console.WriteLine();
             */

            new GTFSView(brres).Show();
        }
Пример #7
0
        public static List <string> Open(string file, string outdir)
        {
            GTFS fs = new GTFS(file);

            byte[] bHeader = GT.ReadBytes(fs, 4, false);
            bool   flip    = false;

            List <Pack> pack = new List <Pack>();

            if (bHeader[1] == 0x35)   //P5CK (TS:FP GC)

            {
                bool isGamecube = false;
                Dictionary <string, string> c2n = new Dictionary <string, string>();
                string filec2n = file.ToLower().Replace(".pak", ".c2n");
                if (File.Exists(filec2n))
                {
                    isGamecube = true;

                    GTFS cs = new GTFS(filec2n);

                    while (true)
                    {
                        byte[] ox = GT.ReadBytes(cs, 2, flip);

                        if (ox[0] == 0x30 && ox[1] == 0x78)
                        {
                            string sAddress = GT.ReadASCII(cs, 8, flip);
                            byte[] blank    = GT.ReadBytes(cs, 2, flip);
                            string sString  = GT.ReadASCIItoNull(cs, cs.Position, flip, 0x0A);
                            cs.Position += sString.Length + 1;

                            if (!c2n.ContainsKey(sAddress))
                            {
                                c2n.Add(sAddress, sString);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                //---

                long lOffsetTail = GT.ReadUInt32(fs, 4, flip);
                long lTailSize   = GT.ReadUInt32(fs, 4, flip);
                long lReserved   = GT.ReadUInt32(fs, 4, flip);

                long lNumResources = lTailSize / 16;

                fs.Position = lOffsetTail;
                for (int i = 0; i < lNumResources; i++)
                {
                    byte[] bOff1       = GT.ReadBytes(fs, 4, true);
                    long   lOffsetFile = GT.ReadUInt32(fs, 4, flip); //PS2

                    long lFileSizePS2 = GT.ReadUInt32(fs, 4, flip);
                    long lFileSizeGC  = GT.ReadUInt32(fs, 4, flip);

                    string sMemory = BitConverter.ToString(bOff1).Replace("-", "").ToLower();

                    long lFileSize = (isGamecube ? lFileSizeGC : lFileSizePS2);

                    string sString;
                    if (c2n.ContainsKey(sMemory)) // Should only be used for GC
                    {
                        sString = c2n[sMemory];
                    }
                    else // Should only be used for PS2
                    {
                        sString = sMemory;
                    }

                    //Console.WriteLine(sMemory + "," + lOffsetFile + "," + lFileSize);

                    pack.Add(new Pack(sString, lOffsetFile, lFileSize));
                }
            }
            else
            {
                throw new Exception();
            }

            List <string> listFiles = new List <string>();

            foreach (Pack pf in pack)
            {
                pf.WriteOut(fs, outdir);
                listFiles.Add(pf.Filename);
            }
            return(listFiles);
        }