ReadUInt32() публичный Метод

public ReadUInt32 ( ) : uint
Результат uint
Пример #1
0
        public static Asset LoadBinary(Pack pack, Stream stream)
        {
            BinaryReaderBigEndian reader = new BinaryReaderBigEndian(stream);

            Asset asset = new Asset(pack);

            UInt32 count = reader.ReadUInt32();

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

            // Set the type of the asset based on the extension
            {
                // First get the extension without the leading '.'
                string extension = Path.GetExtension(asset.Name).Substring(1);
                try
                {
                    asset.Type = (Asset.Types)Enum.Parse(typeof(Types), extension, true);
                }
                catch (System.ArgumentException exception)
                {
                    // This extension isn't mapped in the enum
                    System.Diagnostics.Debug.Write(exception.ToString());
                    asset.Type = Types.Unknown;
                }
            }

            return(asset);
        }
Пример #2
0
        public static Pack LoadBinary(string path)
        {
            Pack pack = new Pack(path);

            using (FileStream fileStream = File.OpenRead(path))
            {
                BinaryReaderBigEndian binaryReader = new BinaryReaderBigEndian(fileStream);

                uint nextChunkAbsoluteOffset = 0;

                do
                {
                    fileStream.Seek(nextChunkAbsoluteOffset, SeekOrigin.Begin);

                    nextChunkAbsoluteOffset = binaryReader.ReadUInt32();
                    uint fileCount = binaryReader.ReadUInt32();

                    for (uint i = 0; i < fileCount; ++i)
                    {
                        AssetRef file = AssetRef.LoadBinary(pack, binaryReader.BaseStream);

                        pack.assetLookupCache[file.Name] = file;

                        pack.Assets.Add(file);
                    }
                } while (nextChunkAbsoluteOffset != 0);

                return(pack);
            }
        }
        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;
        }
Пример #4
0
        public static AssetRef LoadBinary(Pack pack, Stream stream)
        {
            BinaryReaderBigEndian reader = new BinaryReaderBigEndian(stream);

            AssetRef assetRef = new AssetRef(pack);

            uint count = reader.ReadUInt32();

            assetRef.Name           = new string(reader.ReadChars((int)count));
            assetRef.AbsoluteOffset = reader.ReadUInt32();
            assetRef.Size           = reader.ReadUInt32();
            assetRef.Crc32          = reader.ReadUInt32();

            // Set the type of the asset based on the extension
            {
                // First get the extension without the leading '.'
                string extension = Path.GetExtension(assetRef.Name).Substring(1);

                try
                {
                    assetRef.Type = (Types)Enum.Parse(typeof(Types), extension, true);
                }
                catch (ArgumentException)
                {
                    // This extension isn't mapped in the enum
                    Debug.LogWarning("Unknown Forgelight File Type: " + extension);
                    assetRef.Type = Types.Unknown;
                }
            }

            return(assetRef);
        }
Пример #5
0
    public ulong UnpackULong()
    {
        byte b = reader.ReadByte();

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

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

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

        case MsgPack.UInt64Type:
            return(reader.ReadUInt64());

        default:
            throw new MessageTypeException();
        }
    }
Пример #6
0
        private void ReadFile(BinaryReaderBigEndian reader)
        {
            var magic = reader.ReadUInt32();

            if (magic == 0xCAFEBABE)
            {
                ReadFatFile(reader);
                foreach (var entry in _fatEntries)
                {
                    Console.WriteLine($"Details for {entry.cputype}");
                    reader.BaseStream.Seek(entry.offset, SeekOrigin.Begin);
                    ReadFile(reader);
                    entry.path      = _path;
                    entry.archentry = _entry;
                    _entry          = null;
                }
            }
            else if (magic == 0xCEFAEDFE)
            {
                ReadFileArch32(reader);
            }
            else if (magic == 0xCFFAEDFE)
            {
                ReadFileArch64(reader);
            }
            else
            {
                throw new ApplicationException($"File {_path} contains unknown Mach-O header");
            }
        }
        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();
        }
Пример #8
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();
        }
Пример #9
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);
        }
Пример #10
0
        public static Pack LoadBinary(string path)
        {
            Pack       pack       = new Pack(path);
            FileStream fileStream = null;

            try
            {
                fileStream = File.OpenRead(path);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

                return(null);
            }

            BinaryReaderBigEndian binaryReader = new BinaryReaderBigEndian(fileStream);
            UInt32 nextChunkAbsoluteOffset     = 0;
            UInt32 fileCount = 0;

            do
            {
                fileStream.Seek(nextChunkAbsoluteOffset, SeekOrigin.Begin);

                nextChunkAbsoluteOffset = binaryReader.ReadUInt32();
                fileCount = binaryReader.ReadUInt32();

                for (UInt32 i = 0; i < fileCount; ++i)
                {
                    Asset file = Asset.LoadBinary(pack, binaryReader.BaseStream);
                    pack.assetLookupCache.Add(file.Name.GetHashCode(), file);
                    pack.Assets.Add(file);
                }
            }while (nextChunkAbsoluteOffset != 0);

            return(pack);
        }
Пример #11
0
        public static bool IsValidFile(string path)
        {
            if (!File.Exists(path))
            {
                return(false);
            }

            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
                using (var reader = new BinaryReaderBigEndian(stream))
                {
                    var magic = reader.ReadUInt32();

                    if (magic == 0xCAFEBABE || magic == 0xCEFAEDFE || magic == 0xCFFAEDFE)
                    {
                        return(true);
                    }

                    return(false);
                }
        }
Пример #12
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();
        }
Пример #13
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());
        }
Пример #14
0
        private void ReadFatFile(BinaryReaderBigEndian reader)
        {
            var numArchs = reader.ReadUInt32();

            Console.WriteLine($"Found Mach-O Universal with {numArchs} items");

            for (var i = 0; i < numArchs; i++)
            {
                var entry = new MachOFatEntry
                {
                    cputype    = (MachOCpuType)reader.ReadUInt32(),
                    cpusubtype = (MachOCpuSubType)reader.ReadUInt32(),
                    offset     = reader.ReadUInt32(),
                    size       = reader.ReadUInt32(),
                    align      = reader.ReadUInt32()
                };

                Console.WriteLine($"  - {entry.cputype} at offset {entry.offset} size {entry.size}");

                _fatEntries.Add(entry);
            }
        }