Beispiel #1
0
        public void RefreshTable()
        {
            listDisplay = new List <DisplayValue>();
            for (int i = 0; i < numBlocks; i++)
            {
                byte[] b = new byte[4];

                Array.Copy(listBytes[i], b, 4);
                if (checkFlip.Checked)
                {
                    Array.Reverse(b);
                }

                float f = BitConverter.ToSingle(b, 0);

                if (!float.IsNaN(f) && !f.ToString().Contains('E'))
                {
                    int c = 0;
                    if (f < -1.0f || f > 1.0f)
                    {
                        c = 1;
                    }
                    listDisplay.Add(new DisplayValue(f.ToString(), c));
                }
                else
                {
                    listDisplay.Add(new DisplayValue(GT.ByteArrayToString(b, " "), -1));
                }
            }

            dataGridView1.DataSource = Table();
            dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
            foreach (DataGridViewColumn column in dataGridView1.Columns)
            {
                column.SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            if (dataGridView1.Rows.Count > 1)
            {
                for (int r = 0; r < dataGridView1.Rows.Count - 1; r++)
                {
                    for (int c = 0; c < dataGridView1.Rows[r].Cells.Count - 1; c++)
                    {
                        int index = r * (dataGridView1.Rows[r].Cells.Count - 1) + c;
                        dataGridView1.Rows[r].Cells[c + 1].Style.BackColor = listDisplay[index].GetColor();
                    }
                }
            }
        }
Beispiel #2
0
        public override void Open(OpenFileDialog openFileDialog, bool export = false, bool useGTFSView = false)
        {
            openFileDialog.FileName = "";
            openFileDialog.Filter   = "All PS2|*.pak;*.raw|"
                                      + "PS2 Raw|*.raw|"
                                      + "Pak|*.pak|"
                                      + "All Files (*.*)|*.*";

            DialogResult res = openFileDialog.ShowDialog();

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

                if (filenameParts[0].ToUpper() == "PAK")
                {
                    List <string> files = Pak.Open(openFileDialog.FileName, openFileDialog.SafeFileName);
                    FormGameTools2.ListFiles(files);
                }
                else if (filenameParts[0].ToUpper() == "RAW")
                {
                    GTFS   fs      = new GTFS(openFileDialog.FileName);
                    byte[] bHeader = GT.ReadBytes(fs, 4, false);

                    if ((bHeader[0] == 0x10 && bHeader[1] == 0x00 && bHeader[2] == 0x00 && bHeader[3] == 0x00) || //PS2 object
                        (bHeader[0] == 0x20 && bHeader[1] == 0x00 && bHeader[2] == 0x00 && bHeader[3] == 0x00))   //PS2 level
                    {
                        ModelPS2 model = new ModelPS2(openFileDialog.FileName, openFileDialog.SafeFileName, useGTFSView);
                        FormGameTools2.UseViewer(model);
                    }
                    else if ((bHeader[0] == 0x01 && bHeader[1] == 0x00 && bHeader[2] == 0x00 && bHeader[3] == 0x00) ||
                             (bHeader[0] == 0x03 && bHeader[1] == 0x00 && bHeader[2] == 0x00 && bHeader[3] == 0x00))
                    {
                        TexturePS2 texture = new TexturePS2(openFileDialog.FileName, openFileDialog.SafeFileName, useGTFSView);
                        new GameTools3D.FormTextureView(texture).Show();
                    }
                    else
                    {
                        MessageBox.Show("Unknown header (hex): " + GT.ByteArrayToString(bHeader, " "));
                    }
                }
                else
                {
                    MessageBox.Show("Unexpected file extension: " + filenameParts[0]);
                }
            }
        }
Beispiel #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            openFileDialog.FileName = "";
            openFileDialog.Filter   = "Wireshark pcapng|*.pcapng|All Files (*.*)|*.*";

            DialogResult res = openFileDialog.ShowDialog();

            if (res == DialogResult.OK)
            {
                List <USB.URB> listURB = new List <USB.URB>();

                bool flip  = false;
                GTFS fs    = new GTFS(openFileDialog.FileName);
                bool linux = false;

                while (fs.Position < fs.Length)
                {
                    int blockType   = GT.ReadInt32(fs, 4, flip);
                    int blockLength = GT.ReadInt32(fs, 4, flip);

                    if (blockType == 0xA0D0D0A)
                    {
                        //Header
                        byte[] blockBody = GT.ReadBytes(fs, blockLength - 12, flip);
                    }
                    else if (blockType == 0x01)
                    {
                        //Interface Description Block
                        int LinkType = GT.ReadInt16(fs, 2, flip); //220 is USB Linux, 249 is USB Windows
                        int Reserved = GT.ReadInt16(fs, 2, flip);
                        int SnapLen  = GT.ReadInt32(fs, 4, flip);
                        //Options
                        byte[] remaining = GT.ReadBytes(fs, blockLength - 12 - 8, flip);

                        if (LinkType == 220)
                        {
                            linux = true;
                        }
                        //I don't suspect there's any data in here I need
                    }
                    else if (blockType == 0x05)
                    {
                        //Interface Statistics Block
                        //Nothing special
                        byte[] blockBody = GT.ReadBytes(fs, blockLength - 12, flip);
                    }
                    else if (blockType == 0x06)
                    {
                        //Enhanced Packet Block
                        int InterfaceID    = GT.ReadInt32(fs, 4, flip);
                        int TimestampHigh  = GT.ReadInt32(fs, 4, flip);
                        int TimestampLow   = GT.ReadInt32(fs, 4, flip);
                        int CapturedLength = GT.ReadInt32(fs, 4, flip);
                        int PacketLength   = GT.ReadInt32(fs, 4, flip);

                        USB.URB urb;
                        if (linux)
                        {
                            urb = new USB.URBLinux(fs, PacketLength);
                        }
                        else
                        {
                            urb = new USB.URBWindows(fs, PacketLength);
                        }
                        listURB.Add(urb);

                        int paddingMod = CapturedLength % 4;
                        if (paddingMod > 0)
                        {
                            GT.ReadBytes(fs, 4 - paddingMod, flip);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Block type: " + blockType.ToString("X2"));
                        byte[] blockBody = GT.ReadBytes(fs, blockLength - 12, flip);
                    }

                    int blockLength2 = GT.ReadInt32(fs, 4, flip);
                    if (blockLength != blockLength2)
                    {
                        Console.WriteLine("Lengths not equal. Block definition wrong.");
                    }
                }

                var listURB_Iso     = listURB.Where(p => p.transfer_type == USB.URB.TransferType.Isochronous);
                var listURB_Iso_In  = listURB_Iso.Where(p => p.GetEndpointDirection() == USB.URB.EndpointDirection.In);
                var listURB_Iso_Out = listURB_Iso.Where(p => p.GetEndpointDirection() == USB.URB.EndpointDirection.Out);

                FileStream   fsIsoIn     = new FileStream("iso_in.bin", FileMode.Create);
                BinaryWriter binaryIsoIn = new BinaryWriter(fsIsoIn);

                FileStream   fsIsoOut     = new FileStream("iso_out.bin", FileMode.Create);
                BinaryWriter binaryIsoOut = new BinaryWriter(fsIsoOut);

                foreach (USB.URB urb in listURB_Iso_In)
                {
                    foreach (USB.isodesc desc in urb.listIsodesc)
                    {
                        if (desc.data != null)
                        {
                            binaryIsoIn.Write(desc.data);
                        }
                    }
                }

                foreach (USB.URB urb in listURB_Iso_Out)
                {
                    foreach (USB.isodesc desc in urb.listIsodesc)
                    {
                        if (desc.data != null)
                        {
                            binaryIsoOut.Write(desc.data);
                        }
                    }
                }

                binaryIsoIn.Close();
                binaryIsoOut.Close();

                //--

                foreach (USB.URB urb in listURB)
                {
                    string line = urb.ToString();

                    WiiSpeak.Message msg = null;
                    if (urb.remaining.Length == 10)
                    {
                        msg   = new WiiSpeak.Message(urb.remaining);
                        line += string.Format(" {0,14} = {1}", msg.Type.ToString(), GT.ByteArrayToString(urb.remaining, " "));
                    }
                    else if (urb.remaining.Length > 0 && urb.remaining.Length < 10)
                    {
                        line += string.Format(" = {0}", GT.ByteArrayToString(urb.remaining, " "));
                    }

                    listBoxMessages.Items.Add(line);
                }
            }
        }
Beispiel #4
0
        //https://www.gamefaqs.com/ds/933043-hotel-dusk-room-215/faqs/46878?print=1

        public static GTFS ToGTFS(GTFS fs)
        {
            fs.Position = 0;

            byte[] header = GT.ReadBytes(fs, 4, false);
            int    sizeun = GT.ReadInt32(fs, 4, false);
            int    sizeco = GT.ReadInt32(fs, 4, false);
            int    zero   = GT.ReadInt32(fs, 4, false);

            byte[] uncompressed = new byte[sizeun];
            byte[] expanded     = new byte[sizeun]; // i.e. doesn't fill in the gaps
            int    pos          = 0;

            byte boff1max = 0x62;

            while (fs.Position < sizeco + 16)
            {
                byte     input = GT.ReadByte(fs);
                BitArray bits  = new BitArray(new byte[] { input });

                for (int i = 0; i < 8; i++)
                {
                    if (fs.Position >= sizeco + 16)
                    {
                        break;
                    }

                    if (bits[i])
                    {
                        byte b = GT.ReadByte(fs);
                        uncompressed[pos] = b;
                        expanded[pos]     = b;
                        pos++;
                    }
                    else
                    {
                        int offsetSIGNED = GT.ReadInt16(fs, 2, false);
                        fs.Position -= 2;
                        int offset = GT.ReadUInt16(fs, 2, false);
                        fs.Position -= 2;
                        byte[] bOff = GT.ReadBytes(fs, 2, false);

                        int len = 4 + GT.ReadByte(fs);

                        /*
                         * //START DEBUG
                         * uncompressed[pos + 0] = bOff[0];
                         * uncompressed[pos + 1] = bOff[1];
                         * uncompressed[pos + 2] = (byte)(len - 4);
                         *
                         * for(int g = 3; g < len; g++) {
                         *  uncompressed[pos + g] = 0xF5;
                         * }
                         * //END DEBUG
                         */

                        /*if (bOff[1] == 0xFE || bOff[1] == 0xFF) {
                         *  Console.WriteLine("0 Problem " + GT.ByteArrayToString(bOff, " ") + " (Signed: " + offsetSIGNED + ") at " + pos + " (for len: " + len + ")");
                         * } else {*/
                        if (pos >= 196608)
                        {
                            // Shouldn't happen
                            throw new Exception();
                        }

                        if (pos >= 131072 && bOff[1] <= boff1max)
                        {
                            offsetSIGNED += 131072 + 259;
                            if (offsetSIGNED >= 0 && offsetSIGNED < pos)
                            {
                                for (int x = 0; x < len; x++)
                                {
                                    uncompressed[pos + x] = uncompressed[offsetSIGNED + x];
                                }
                            }
                            else
                            {
                                Console.WriteLine("1 Problem " + GT.ByteArrayToString(bOff, " ") + " (Signed: " + offsetSIGNED + ") at " + pos + " (for len: " + len + ")");
                                //throw new Exception();
                                for (int x = 0; x < len; x++)
                                {
                                    uncompressed[pos + x] = 0x00;
                                }
                            }
                        }
                        else if (pos >= 65536 && bOff[1] <= boff1max)
                        {
                            if (offsetSIGNED < 0)
                            {
                                offsetSIGNED = (bOff[1] << 8) + bOff[0] + 259;
                            }
                            else
                            {
                                offsetSIGNED += 65536;
                            }

                            if (offsetSIGNED >= 0 && offsetSIGNED < pos)
                            {
                                for (int x = 0; x < len; x++)
                                {
                                    uncompressed[pos + x] = uncompressed[offsetSIGNED + x];
                                }
                            } //else
                              //throw new Exception();
                        }
                        else
                        {
                            offset += 259;

                            if (bOff[1] == 0xFF)
                            {
                                //Can't use offsetSIGNED
                                for (int x = 0; x < len; x++)
                                {
                                    uncompressed[pos + x] = uncompressed[offset + x];
                                }
                            }
                            else
                            {
                                if (offsetSIGNED + 259 >= 0 && offsetSIGNED + 259 < pos)
                                {
                                    offsetSIGNED += 259;
                                    for (int x = 0; x < len; x++)
                                    {
                                        uncompressed[pos + x] = uncompressed[offsetSIGNED + x];
                                    }
                                }
                                else if (offset > pos)
                                {
                                    Console.WriteLine("3 Problem " + GT.ByteArrayToString(bOff, " ") + " (Signed: " + offsetSIGNED + ") at " + pos + " (for len: " + len + ")");
                                }
                                else if (offset >= sizeun)
                                {
                                    uncompressed[pos + 0] = bOff[0];
                                    uncompressed[pos + 1] = bOff[1];
                                    uncompressed[pos + 2] = (byte)(len - 4);

                                    for (int g = 3; g < len; g++)
                                    {
                                        uncompressed[pos + g] = 0xF5;
                                    }
                                }
                                else
                                {
                                    for (int x = 0; x < len; x++)
                                    {
                                        uncompressed[pos + x] = uncompressed[offset + x];
                                    }
                                }
                            }
                        }

                        #region Expanded
                        expanded[pos + 0] = bOff[0];
                        expanded[pos + 1] = bOff[1];
                        expanded[pos + 2] = (byte)(len - 4);

                        for (int g = 3; g < len; g++)
                        {
                            expanded[pos + g] = 0x00;
                        }
                        #endregion

                        pos += len;
                    }
                }
            }

            new FormHexCompare(expanded, uncompressed).Show();

            return(new GTFS(uncompressed));
        }