ReadInt32() public method

public ReadInt32 ( ) : int
return int
        public FirmwareMetadataEntry(BinaryReaderBigEndian reader)
        {
            reader.ReadUInt32(); // EntrySizeSignature
            Size += 4;

            reader.ReadUInt32(); // EntrySize
            Size += 4;

            reader.ReadUInt32(); // NameLengthSignature
            Size += 4;

            var nameLength = reader.ReadUInt32();

            Size += 4;

            var entryNameBytes = reader.ReadBytes((int)nameLength);

            Size += entryNameBytes.Length;

            FileName = Encoding.UTF8.GetString(entryNameBytes);

            reader.ReadUInt32(); // DataLengthSignature
            Size += 4;

            var dataLength = reader.ReadInt32();

            Size += 4;

            Data  = reader.ReadBytes(dataLength);
            Size += dataLength;
        }
Example #2
0
    public long UnpackLong()
    {
        byte b = reader.ReadByte();

        if (MsgPack.IsPositiveFixnum(b))
        {
            return(b);
        }
        if (MsgPack.IsNegativeFixnum(b))
        {
            return((sbyte)b);
        }
        switch (b)
        {
        case MsgPack.UInt8Type:
            return(reader.ReadByte());

        case MsgPack.UInt16Type:
            return(reader.ReadUInt16());

        case MsgPack.UInt32Type:
            return(reader.ReadUInt32());

        case MsgPack.UInt64Type:
            var v = reader.ReadUInt64();
            if (v > long.MaxValue)
            {
                throw new MessagePackOverflowException("long");
            }
            return((long)v);

        case MsgPack.Int8Type:
            return((sbyte)reader.ReadByte());

        case MsgPack.Int16Type:
            return(reader.ReadInt16());

        case MsgPack.Int32Type:
            return(reader.ReadInt32());

        case MsgPack.Int64Type:
            return(reader.ReadInt64());

        default:
            throw new MessageTypeException();
        }
    }
        public FirmwareFile(string filePath)
        {
            using (var fs = new FileStream(filePath, FileMode.Open))
            {
                using (var br = new BinaryReaderBigEndian(fs))
                {
                    Version = br.ReadInt32();
                    CumulativeSectionSize = br.ReadInt32();

                    var sig = br.ReadUInt32();
                    if (sig == 0x00001000)
                    {
                        MetadataSection = new FirmwareMetadataSection(br);
                    }
                    else
                    {
                        throw new FormatException($"Expected SectionA signature 0x00001000, got 0x{sig:X8}");
                    }

                    sig = br.ReadUInt32();
                    if (sig == 0x00002000)
                    {
                        DataSection = new FirmwareDataSection(br);
                    }
                    else
                    {
                        throw new FormatException($"Expected SectionB signature 0x00002000, got 0x{sig:X8}");
                    }
                }
            }

            var romBytes = new List <byte>();

            foreach (var entry in DataSection.Entries)
            {
                if (entry.Data.Length > 65000)
                {
                    romBytes.AddRange(entry.Data);
                }
            }

            ContiguousRomData = romBytes.ToArray();
        }
Example #4
0
        public static string AnalyzePS2(string directory)
        {
            string assets = directory + Path.DirectorySeparatorChar + "Resources" + Path.DirectorySeparatorChar + "Assets" + Path.DirectorySeparatorChar;

            StringBuilder builder = new StringBuilder();

            foreach(string file in Directory.GetFiles(assets))
            {
                Console.WriteLine(file);
                using(BinaryReaderBigEndian reader = new BinaryReaderBigEndian(File.Open(file, FileMode.Open)))
                {

                    int nextOffset;

                    do
                    {
                        nextOffset = reader.ReadInt32();
                        int numFiles = reader.ReadInt32();

                        for (int i = 0; i < numFiles; i++)
                        {
                            int nameLength = reader.ReadInt32();
                            string name = new string(reader.ReadChars(nameLength));
                            int offset = reader.ReadInt32();
                            int length = reader.ReadInt32();
                            uint crc32 = reader.ReadUInt32();

                            builder.AppendLine(string.Format("{0}\t{1}\t{2}", name, length, (uint)crc32));

                        }

                        reader.BaseStream.Seek(nextOffset, SeekOrigin.Begin);

                    } while (nextOffset != 0);

                }

            }
            return builder.ToString();
        }
Example #5
0
        public FirmwareDataEntry(BinaryReaderBigEndian br)
        {
            br.ReadUInt32(); // EntrySizeSignature
            Size += 4;

            br.ReadUInt32(); // EntrySize
            Size += 4;

            br.ReadUInt32(); // MetadataSizeSignature
            Size += 4;

            var metaDataSize = br.ReadInt32();

            Size += 4;

            Checksum = br.ReadBytes(metaDataSize);
            Size    += metaDataSize;

            br.ReadUInt32(); // DataSizeSignature
            Size += 4;

            var dataSize = br.ReadInt32();

            Size += 4;

            var data = br.ReadBytes(dataSize);

            Size += dataSize;

            var sb = new StringBuilder();

            foreach (var b in data)
            {
                sb.Append($"{b:X2}");
            }
            sb.Append(".bin");

            Data     = data;
            FileName = sb.ToString();
        }
Example #6
0
        public static string AnalyzePS2(string directory)
        {
            string assets = directory + Path.DirectorySeparatorChar + "Resources" + Path.DirectorySeparatorChar + "Assets" + Path.DirectorySeparatorChar;

            StringBuilder builder = new StringBuilder();

            foreach (string file in Directory.GetFiles(assets))
            {
                Console.WriteLine(file);
                using (BinaryReaderBigEndian reader = new BinaryReaderBigEndian(File.Open(file, FileMode.Open)))
                {
                    int nextOffset;

                    do
                    {
                        nextOffset = reader.ReadInt32();
                        int numFiles = reader.ReadInt32();

                        for (int i = 0; i < numFiles; i++)
                        {
                            int    nameLength = reader.ReadInt32();
                            string name       = new string(reader.ReadChars(nameLength));
                            int    offset     = reader.ReadInt32();
                            int    length     = reader.ReadInt32();
                            uint   crc32      = reader.ReadUInt32();


                            builder.AppendLine(string.Format("{0}\t{1}\t{2}", name, length, (uint)crc32));
                        }

                        reader.BaseStream.Seek(nextOffset, SeekOrigin.Begin);
                    } while (nextOffset != 0);
                }
            }
            return(builder.ToString());
        }
Example #7
0
        public static Asset LoadBinary(Pack pack, Stream stream)
        {
            BinaryReaderBigEndian reader = new BinaryReaderBigEndian(stream);

            Asset asset = new Asset(pack);

            uint count = reader.ReadUInt32();

            asset.Name           = new String(reader.ReadChars((int)count));
            asset.AbsoluteOffset = reader.ReadUInt32();
            asset.Size           = reader.ReadUInt32();
            asset.Crc32          = reader.ReadInt32();

            //determine asset type from file extension
            string extension = Path.GetExtension(asset.Name).Substring(1);
            Types  assetType = Types.Unknown;

            GetTypeFromExtension(extension, ref assetType);
            asset.Type = assetType;

            return(asset);
        }