ReadUInt32() private method

private ReadUInt32 ( ) : uint
return uint
        internal override void Read(BinaryReader reader)
        {
            Version = reader.ReadUInt16();
            VersionNeededToExtract = reader.ReadUInt16();
            Flags = (HeaderFlags) reader.ReadUInt16();
            CompressionMethod = (ZipCompressionMethod) reader.ReadUInt16();
            LastModifiedTime = reader.ReadUInt16();
            LastModifiedDate = reader.ReadUInt16();
            Crc = reader.ReadUInt32();
            CompressedSize = reader.ReadUInt32();
            UncompressedSize = reader.ReadUInt32();
            ushort nameLength = reader.ReadUInt16();
            ushort extraLength = reader.ReadUInt16();
            ushort commentLength = reader.ReadUInt16();
            DiskNumberStart = reader.ReadUInt16();
            InternalFileAttributes = reader.ReadUInt16();
            ExternalFileAttributes = reader.ReadUInt32();
            RelativeOffsetOfEntryHeader = reader.ReadUInt32();

            byte[] name = reader.ReadBytes(nameLength);
            Name = DecodeString(name);
            byte[] extra = reader.ReadBytes(extraLength);
            byte[] comment = reader.ReadBytes(commentLength);
            Comment = DecodeString(comment);
            LoadExtra(extra);
        }
Example #2
0
 public MpqBlock(BinaryReader br, uint HeaderOffset)
 {
     FilePos = br.ReadUInt32() + HeaderOffset;
     CompressedSize = br.ReadUInt32();
     FileSize = br.ReadUInt32();
     Flags = (MpqFileFlags)br.ReadUInt32();
 }
Example #3
0
        internal Steam2ChecksumData( byte[] blob )
        {
            maps = new List<ChecksumMapEntry>();
            checksums = new Dictionary<uint, int>();

            data = blob;

            using ( MemoryStream ms = new MemoryStream( data ) )
            {
                using ( BinaryReader br = new BinaryReader( ms ) )
                {
                    // we don't care about the first two, always the same
                    br.ReadBytes( 8 );

                    itemCount = br.ReadUInt32();
                    checksumCount = br.ReadUInt32();

                    uint count;
                    uint start = 0;
                    for ( int i = 0 ; i < itemCount ; i++ )
                    {
                        count = br.ReadUInt32();
                        start = br.ReadUInt32();
                        maps.Add( new ChecksumMapEntry( count, start ) );
                    }

                    for ( uint i = 0 ; i < checksumCount ; i++ )
                    {
                        long pos = br.BaseStream.Position;
                        checksums[ i ] = br.ReadInt32();
                    }
                }
            }
        }
 private void PlayerInfo(BinaryReader gr)
 {
     AppendFormatLine("FreePoints: {0}", gr.ReadUInt32());
     var speccount=gr.ReadByte();
     AppendFormatLine("SpectsCount: {0}", speccount);
     AppendFormatLine("ActiveSpec: {0}", gr.ReadByte());
     if (speccount > 0)
     {
         for (int id = 0; id < 1; id++)
         {
             var talidcount = gr.ReadByte();
             AppendFormatLine("TalentIDCount: {0}", talidcount);
             for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 12; j++)
               {
                   AppendFormatLine("TalentID {0}", gr.ReadUInt32());
                     AppendFormatLine("CurRanc: {0}", gr.ReadByte());
                 }
             }
             var GLYPHMAX = gr.ReadByte();
             AppendFormatLine("GLYPHMAX: {0}", GLYPHMAX);
           for (int g = 0; g < GLYPHMAX; g++)
             {
                 AppendFormatLine("GLYPID: {0}", gr.ReadUInt16());
             }
         }
     }
 }
Example #5
0
        public void Load(string destinationDirectory, string resourceName, BinaryReader binaryReader)
        {
            var start = binaryReader.BaseStream.Position;
            uint totalLength = binaryReader.ReadUInt32();
            var container = new string(binaryReader.ReadChars(4));

            switch (container) {
                case "FORM":
                case "RIFF":
                    uint length = binaryReader.ReadUInt32(); // this is probably not really a length, with values like 0xcccccccc
                    var header = new string(binaryReader.ReadChars(4));
                    switch (header) {
                        case "XMID":
                        case "XDIR":
                            new XMidiLoader().Load(destinationDirectory, resourceName, binaryReader, totalLength);
                            break;
                        case "WAVE":
                            break;
                    }
                    break;
                default:
                    // Possibly a WAV but without a header
                    binaryReader.BaseStream.Seek(start, SeekOrigin.Begin);
                    new WaveLoader().Load(destinationDirectory, resourceName, binaryReader, (int)totalLength, true);
                    break;
            }
        }
 public CasHeader(BinaryReader b)
 {
     this.magic = b.ReadUInt32();
     this.sha1 = b.ReadBytes(20);
     this.size = b.ReadUInt32();
     this._null = b.ReadUInt32();
 }
 void Parse(Stream s)
 {
     BinaryReader br = new BinaryReader(s);
     unknown1 = br.ReadUInt32();
     data = br.ReadBytes(2 * br.ReadInt32());
     unknown2 = br.ReadUInt32();
 }
Example #8
0
        // 1ST TIER FUNCTIONS

        Index GetIndex(BinaryReader binReader)
        {
            Index getIndex = new Index
            {
                zone = (Zone) binReader.ReadUInt32(),
                unknown02 = binReader.ReadUInt32(),
                unknown03 = binReader.ReadUInt32(),
                unknown04 = binReader.ReadUInt32()
            };
            binReader.ReadBytes(12); // nulls
            getIndex.triangle = GetTriangles(binReader);
            binReader.ReadBytes(8); // nulls
            getIndex.triangles = binReader.ReadUInt16();
            getIndex.positions = binReader.ReadUInt16();
            getIndex.unknown05 = binReader.ReadUInt16();
            binReader.ReadBytes(8); // nulls
            getIndex.diffuse = GetString(binReader);
            getIndex.normal = GetString(binReader);
            getIndex.glow = GetString(binReader);
            getIndex.specular = GetString(binReader);
            getIndex.light = GetString(binReader);
            binReader.ReadBytes(38); // nulls
            binReader.ReadBytes(8);// Another 8 nulls... this shouldnt be according to old code

            return getIndex;
        }
        /// <summary>
        /// Creates a new FAR3Archive instance from a path.
        /// </summary>
        /// <param name="Path">The path to the archive.</param>
        public FAR3Archive(string Path)
        {
            m_ArchivePath = Path;

            if (isReadingSomething == false)
            {
                isReadingSomething = true;

                try
                {
                    m_Reader = new BinaryReader(File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.Read));
                }
                catch (Exception)
                {
                    throw new FAR3Exception("Could not open the specified archive - " + Path + "! (FAR3Archive())");
                }

                string Header = Encoding.ASCII.GetString(m_Reader.ReadBytes(8));
                uint Version = m_Reader.ReadUInt32();

                if ((Header != "FAR!byAZ") || (Version != 3))
                {
                    throw new FAR3Exception("Archive wasn't a valid FAR V.3 archive! (FAR3Archive())");
                }

                uint ManifestOffset = m_Reader.ReadUInt32();
                m_ManifestOffset = ManifestOffset;

                m_Reader.BaseStream.Seek(ManifestOffset, SeekOrigin.Begin);

                uint NumFiles = m_Reader.ReadUInt32();

                for (int i = 0; i < NumFiles; i++)
                {
                    Far3Entry Entry = new Far3Entry();
                    Entry.DecompressedFileSize = m_Reader.ReadUInt32();
                    byte[] Dummy = m_Reader.ReadBytes(3);
                    Entry.CompressedFileSize = (uint)((Dummy[0] << 0) | (Dummy[1] << 8) | (Dummy[2]) << 16);
                    Entry.DataType = m_Reader.ReadByte();
                    Entry.DataOffset = m_Reader.ReadUInt32();
                    //Entry.HasFilename = m_Reader.ReadUInt16();
                    Entry.IsCompressed = m_Reader.ReadByte();
                    Entry.AccessNumber = m_Reader.ReadByte();
                    Entry.FilenameLength = m_Reader.ReadUInt16();
                    Entry.TypeID = m_Reader.ReadUInt32();
                    Entry.FileID = m_Reader.ReadUInt32();
                    Entry.Filename = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength));

                    if (!m_Entries.ContainsKey(Entry.Filename))
                        m_Entries.Add(Entry.Filename, Entry);
                    m_EntriesList.Add(Entry);

                    m_EntryByID.Add(Entry.FileID, Entry); //isn't this a bad idea? i have a feeling this is a bad idea...
                }

                //Keep the stream open, it helps peformance.
                //m_Reader.Close();
                isReadingSomething = false;
            }
        }
Example #10
0
        public IPHeader(ArraySegment<byte> buffer)
        {

            using (var memoryStream = new MemoryStream(buffer.Array, buffer.Offset, buffer.Count))
            {
                using (var binaryReader = new BinaryReader(memoryStream))
                {
                    var versionAndHeaderLength = binaryReader.ReadByte();
                    var differentiatedServices = binaryReader.ReadByte();

                    DifferentiatedServices = (byte)(differentiatedServices >> 2);
                    CongestionNotification = (byte)(differentiatedServices & 0x03);

                    TotalLength = (ushort) IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                    Debug.Assert(TotalLength >= 20, "Invalid IP packet Total Lenght");
                    Identification = (ushort) IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                    _flagsAndOffset = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                    Ttl = binaryReader.ReadByte();

                    _protocol = binaryReader.ReadByte();

                    Checksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                    SourceAddress = new IPAddress(binaryReader.ReadUInt32());
                    DestinationAddress = new IPAddress(binaryReader.ReadUInt32());

                    HeaderLength = (versionAndHeaderLength & 0x0f) * 4;
                }
            }

            Raw = buffer;
            Data = new ArraySegment<byte>(buffer.Array, buffer.Offset + HeaderLength, MessageLength);
        }
        internal override void Read(BinaryReader reader)
        {
            Version = reader.ReadUInt16();
            VersionNeededToExtract = reader.ReadUInt16();
            Flags = (HeaderFlags) reader.ReadUInt16();
            CompressionMethod = (ZipCompressionMethod) reader.ReadUInt16();
            LastModifiedTime = reader.ReadUInt16();
            LastModifiedDate = reader.ReadUInt16();
            Crc = reader.ReadUInt32();
            CompressedSize = reader.ReadUInt32();
            UncompressedSize = reader.ReadUInt32();
            ushort nameLength = reader.ReadUInt16();
            ushort extraLength = reader.ReadUInt16();
            ushort commentLength = reader.ReadUInt16();
            DiskNumberStart = reader.ReadUInt16();
            InternalFileAttributes = reader.ReadUInt16();
            ExternalFileAttributes = reader.ReadUInt32();
            RelativeOffsetOfEntryHeader = reader.ReadUInt32();

            byte[] name = reader.ReadBytes(nameLength);
            Name = DecodeString(name);
            byte[] extra = reader.ReadBytes(extraLength);
            byte[] comment = reader.ReadBytes(commentLength);
            Comment = DecodeString(comment);
            LoadExtra(extra);

            var unicodePathExtra = Extra.FirstOrDefault(u => u.Type == ExtraDataType.UnicodePathExtraField);
            if (unicodePathExtra != null)
            {
                Name = ((ExtraUnicodePathExtraField)unicodePathExtra).UnicodeName;
            }
        }
Example #12
0
        public static CpuArchitectures GetPEArchitecture(string pFilePath)
        {
            ushort architecture = 0;

            ushort[] coffHeader = new ushort[10];

            using (FileStream fStream = new FileStream(pFilePath, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader bReader = new BinaryReader(fStream))
                {
                    if (bReader.ReadUInt16() == 23117) //check the MZ signature
                    {
                        fStream.Seek(0x3A, SeekOrigin.Current); // Go to the location of the location of the NT header
                        fStream.Seek(bReader.ReadUInt32(), SeekOrigin.Begin); // seek to the start of the NT header.
                        if (bReader.ReadUInt32() == 17744) //check the PE\0\0 signature.
                        {
                            for (int i = 0; i < 10; i++) // Read COFF Header
                                coffHeader[i] = bReader.ReadUInt16();
                            if (coffHeader[8] > 0) // Read Optional Header
                                architecture = bReader.ReadUInt16();
                        }
                    }
                }
            }

            switch (architecture)
            {
                case 0x20b:
                    return CpuArchitectures.x64;
                case 0x10b:
                    return ((coffHeader[9] & 0x100) == 0) ? CpuArchitectures.AnyCpu : CpuArchitectures.x86;
                default:
                    return CpuArchitectures.Unknown;
            }
        }
        public IEnumerable<Packet> ReadPackets(string file)
        {
            using (var gr = new BinaryReader(new FileStream(file, FileMode.Open, FileAccess.Read), Encoding.ASCII))
            {
                gr.ReadBytes(3); // PKT
                gr.ReadBytes(2); // 0x02, 0x02
                gr.ReadByte(); // 0x06
                Build = gr.ReadUInt16(); // build
                gr.ReadBytes(4); // client locale
                gr.ReadBytes(20); // packet key
                gr.ReadBytes(64); // realm name

                var packets = new List<Packet>();
                while (gr.PeekChar() >= 0)
                {
                    Direction direction = gr.ReadByte() == 0xff ? Direction.Server : Direction.Client;
                    uint unixtime = gr.ReadUInt32();
                    uint tickcount = gr.ReadUInt32();
                    uint size = gr.ReadUInt32();
                    OpCodes opcode = (direction == Direction.Client) ? (OpCodes)gr.ReadUInt32() : (OpCodes)gr.ReadUInt16();
                    byte[] data = gr.ReadBytes((int)size - ((direction == Direction.Client) ? 4 : 2));

                    packets.Add(new Packet(direction, opcode, data, unixtime, tickcount));
                }
                return packets;
            }
        }
Example #14
0
        /// <summary>
        /// Opens an existing FAR archive.
        /// </summary>
        /// <param name="Path">The path to the archive.</param>
        public FARArchive(string Path)
        {
            m_Reader = new BinaryReader(File.Open(Path, FileMode.Open, FileAccess.Read));
            m_FarEntries = new List<FarEntry>();

            string Header = Encoding.ASCII.GetString(m_Reader.ReadBytes(8));
            uint Version = m_Reader.ReadUInt32();

            if ((Header != "FAR!byAZ") || (Version != 1))
            {
                MessageBox.Show("Archive wasn't a valid FAR V.1 archive!");
                return;
            }

            uint ManifestOffset = m_Reader.ReadUInt32();
            m_ManifestOffset = ManifestOffset;

            m_Reader.BaseStream.Seek(ManifestOffset, SeekOrigin.Begin);

            uint NumFiles = m_Reader.ReadUInt32();

            for (int i = 0; i < NumFiles; i++)
            {
                FarEntry Entry = new FarEntry();
                Entry.DataLength = m_Reader.ReadInt32();
                Entry.DataLength2 = m_Reader.ReadInt32();
                Entry.DataOffset = m_Reader.ReadInt32();
                Entry.FilenameLength = m_Reader.ReadInt16();
                Entry.Filename = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength));

                m_FarEntries.Add(Entry);
            }

            //Reader.Close();
        }
 public bool Load(string path)
 {
     using (FileStream fs = new FileStream(path, FileMode.Open))
     {
         using (BinaryReader reader = new BinaryReader(fs))
         {
             for (int i = 0; i < 8; ++i)
             {
                 reader.ReadBytes(4);
             }
             uint count = reader.ReadUInt32();
             uint offset = reader.ReadUInt32();
             fs.Position = (long)offset;
             try
             {
                 for (int i = 0; i < count; ++i)
                 {
                     ulong ext = reader.ReadUInt64();
                     ulong fpath = reader.ReadUInt64();
                     uint language = reader.ReadUInt32();
                     reader.ReadBytes(4);
                     uint id = reader.ReadUInt32();
                     reader.ReadBytes(4);
                     this.Add(ext, fpath, language, id);
                 }
             }
             catch (Exception)
             {
                 return false;
             }
         }
     }
     return true;
 }
Example #16
0
        public bool Analyze(Stream patchStream)
        {
            if (patchStream == null) throw new ArgumentNullException();
            if (patchStream.CanSeek == false) throw new ArgumentException();

            Clear();

            var br = new BinaryReader(patchStream);
            // Make sure the magic word is here.
            uint seed = br.ReadUInt32();
            if (seed != MAGIC) {
                return false;
            }

            // Read file count field (note: contains funky bits.)
            uint fileCount = br.ReadUInt32();
            bool md5Mode = ((fileCount & 0x80000000) != 0);

            // Clear the weird bits from the file count.
            fileCount &= 0x00FFFFFF;

            // We only support newer MD5 versions of files.
            if (!md5Mode) return false;

            mPatFileInfo.BlockCount = br.ReadUInt32();
            mPatFileInfo.SourceChecksum = br.ReadBytes(16);
            mPatFileInfo.TargetChecksum = br.ReadBytes(16);
            mPatFileInfo.BodySize = br.ReadUInt32();

            return true;
        }
Example #17
0
        public InstallShieldPackage(string filename, int priority)
        {
            this.priority = priority;
            s = FileSystem.Open(filename);

            // Parse package header
            BinaryReader reader = new BinaryReader(s);
            uint signature = reader.ReadUInt32();
            if (signature != 0x8C655D13)
                throw new InvalidDataException("Not an Installshield package");

            reader.ReadBytes(8);
            /*var FileCount = */reader.ReadUInt16();
            reader.ReadBytes(4);
            /*var ArchiveSize = */reader.ReadUInt32();
            reader.ReadBytes(19);
            var TOCAddress = reader.ReadInt32();
            reader.ReadBytes(4);
            var DirCount = reader.ReadUInt16();

            // Parse the directory list
            s.Seek(TOCAddress, SeekOrigin.Begin);
            BinaryReader TOCreader = new BinaryReader(s);
            for (var i = 0; i < DirCount; i++)
                ParseDirectory(TOCreader);
        }
Example #18
0
        public Metadata(BinaryReader reader)
        {
            magic = reader.ReadUInt32();
            if (magic != 0x424A5342)
                return;

            offset = (uint)reader.BaseStream.Position - 4;
            majorVersion = reader.ReadUInt16();
            minorVersion = reader.ReadUInt16();
            reserved = reader.ReadUInt32();
            versionString = readString(reader, reader.ReadInt32());
            flags = reader.ReadUInt16();
            int numStreams = reader.ReadUInt16();
            streams = new DotNetStream[numStreams];
            uint lastOffset = offset;
            for (int i = 0; i < numStreams; i++) {
                uint fileOffset = offset + reader.ReadUInt32();
                uint size = reader.ReadUInt32();
                string name = readAsciizString(reader);
                streams[i] = new DotNetStream(name, fileOffset, size);
                lastOffset = Math.Max(lastOffset, fileOffset + size);
            }
            lastOffset = Math.Max(lastOffset, (uint)reader.BaseStream.Position);
            length = lastOffset - offset;
            headerLength = (uint)reader.BaseStream.Position - offset;
        }
        public PacketParser(Stream file)
        {
            var reader = new BinaryReader(file);
            Console.WriteLine("Reading packets!");

            while (file.Position != file.Length)
            {
                var packetOpcode = reader.ReadUInt32();
                var packetLength = reader.ReadUInt32();
                var packetTimestamp = reader.ReadUInt32();
                var packetType = reader.ReadByte();

                //Console.WriteLine("Opcode: 0x{0:X4}, Length: {1}", packetOpcode, packetLength);
                var packetBuffer = new byte[packetLength];
                for (var i = 0; i < packetLength; ++i)
                {
                    packetBuffer[i] = reader.ReadByte();
                }

                // ReSharper disable once ObjectCreationAsStatement
                // Handle the packet
                var p = new Packet(packetOpcode, packetLength, packetTimestamp, packetType, packetBuffer);
            }

            // Prevent exit.
            Console.ReadLine();
        }
Example #20
0
        public void RecvAuthRsp(BinaryReader s)
        {
            Console.WriteLine("SessionClient.RecvAuthRsp");

            UInt32 sessionId;
            UInt32 sessionStatus;

            sessionId = s.ReadUInt32();
            sessionStatus = s.ReadUInt32();

            if (sessionStatus != 0)
            {
                Console.WriteLine("Session Authentication Failed: {0}", sessionStatus);
                listener.OnSessionOperationFail("Session Authentication Failed");
                return;
            }
            else if (sessionId != this.sessionId)
            {
                Console.WriteLine("Session Authentication Failed:" + sessionId + "!=" + this.sessionId);
                listener.OnSessionOperationFail("Session Authentication Failed");
                return;
            }

            listener.OnSessionAuthenticationSuccess();
        }
Example #21
0
        public static void ReadBlendomatic(FileStream file)
        {
            BinaryReader reader = new BinaryReader(file);

            NumberOfBlendingModes = reader.ReadUInt32();
            NumberOfTiles = reader.ReadUInt32();

            BlendingModes = new Dictionary<byte, BlendingMode>();

            Console.WriteLine("Number of blending modes: " + NumberOfBlendingModes);
            Console.WriteLine("Number of tiles: " + NumberOfTiles);

            for (var i = 0; i < NumberOfBlendingModes; i++ )
            {
                BlendingMode mode;
                mode.TileSize = reader.ReadUInt32();
                mode.Tiles = new Dictionary<byte, byte[]>();

                var TileFlags = reader.ReadBytes(31); // all 1 wtf

                reader.ReadBytes((int)mode.TileSize * 4);
                for (var j = 0; j < NumberOfTiles; j++)
                {
                    mode.Tiles[(byte)j] = reader.ReadBytes((int)mode.TileSize);
                }

                BlendingModes[(byte)i] = mode;
            }
        }
Example #22
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        public override void Parse( Stream input )
        {
            BinaryReader br = new BinaryReader( input );

            _MatrixX = br.ReadByte();
            _MatrixY = br.ReadByte();
            _DivisorFLOAT = br.ReadUInt32();
            _BiasFLOAT = br.ReadUInt32();
            _MatrixValues = new List<uint>();
            for ( int i = 0; i < ( _MatrixX * _MatrixY ); i++ )
            {
                UInt32 a = br.ReadUInt32();
                _MatrixValues.Add( a );
            }
            _DefaultColor = new Rgba( this.Version );
            _DefaultColor.Parse( input );
            BitStream bits = new BitStream( input );

            uint reserved = bits.GetBits( 6 );
            if ( 0 != reserved )
            {
                throw new SwfFormatException( "ConvolutionFilter uses reserved bits" );
            }

            _Clamp = ( 0 != bits.GetBits( 1 ) );
            _PreserveAlpha = ( 0 != bits.GetBits( 1 ) );
        }
        public override void Read(BinaryReader reader, Resource resource)
        {
            reader.BaseStream.Position = this.Offset;

            CRC32 = reader.ReadUInt32();

            var size = reader.ReadUInt16();
            int headerSize = 4 + 2;

            for (var i = 0; i < size; i++)
            {
                var entry = new NameEntry
                {
                    Name = reader.ReadNullTermString(Encoding.UTF8),
                    CRC32 = reader.ReadUInt32(),
                };

                Names.Add(entry);

                headerSize += entry.Name.Length + 1 + 4; // string length + null byte + 4 bytes
            }

            Data = reader.ReadBytes((int)this.Size - headerSize);

            if (Crc32.Compute(Data) != CRC32)
            {
                throw new InvalidDataException("CRC32 mismatch for read data.");
            }
        }
Example #24
0
        public FAR1Archive(string Path)
        {
            m_Path = Path;
            m_Reader = new BinaryReader(File.Open(Path, FileMode.Open));

            string Header = Encoding.ASCII.GetString(m_Reader.ReadBytes(8));
            uint Version = m_Reader.ReadUInt32();

            if ((Header != "FAR!byAZ") || (Version != 1))
            {
                throw(new Exception("Archive wasn't a valid FAR V.1 archive!"));
            }

            m_ManifestOffset = m_Reader.ReadUInt32();
            m_Reader.BaseStream.Seek(m_ManifestOffset, SeekOrigin.Begin);

            m_NumFiles = m_Reader.ReadUInt32();
            
            for (int i = 0; i < m_NumFiles; i++)
            {
                FarEntry Entry = new FarEntry();
                Entry.DataLength = m_Reader.ReadInt32();
                Entry.DataLength2 = m_Reader.ReadInt32();
                Entry.DataOffset = m_Reader.ReadInt32();
                Entry.FilenameLength = m_Reader.ReadInt16();
                Entry.Filename = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength));

                m_Entries.Add(Entry);
            }

            m_Reader.Close();
        }
Example #25
0
        public uint PacketNumber = 0;   // if we detect any changes, update the packet number

		/// <summary>
		/// Searches xbox memory for XInputGetState(). Average execution time of 15ms.
		/// </summary>
		/// <returns></returns>
		uint GetXInputGetStateAddress()
		{
			// assumes everything we need is in header...why would they put it elsewhere???

			// buffer to store our xbe header
            byte[] xbeh = Xbox.GetMemory(0x10000, (uint)0x1000);
            BinaryReader header = new BinaryReader(new System.IO.MemoryStream(xbeh));

			header.BaseStream.Position = 0x11C;
			uint SegmentCount = header.ReadUInt32();                //gets segment count
			uint SegmentBase = header.ReadUInt32() - 0x10000;       //gets base address of segment info table

			//loops through each segment
			for (int i = 0; i < SegmentCount; i++)
			{
				header.BaseStream.Position = (uint)(SegmentBase + i * 56) + 4;
				uint SegAddress = header.ReadUInt32();
				uint SegSize = header.ReadUInt32();
				header.BaseStream.Position += 8;
				header.BaseStream.Position = header.ReadUInt32() - 0x10000;
				string SegName = System.Text.ASCIIEncoding.ASCII.GetString(header.ReadBytes(3));

				if (SegName.Equals("XPP"))
				{
					//dumps xpp segment
                    byte[] SegDump = Xbox.GetMemory(SegAddress, SegSize);

					//searches for xinputgetstate function
					for (int j = 0; j < SegSize; j++)
						if ((BitConverter.ToUInt64(SegDump, j) & 0xFFFFFFFFFFFF) == 0x000015FFDB335653)
							return (uint)(SegAddress + j);
				}
			}
			throw new Exception("Unable to find XInputGetState() in memory, you must manually specify this address instead if you wish to initialize a controller hook.");
		}
Example #26
0
        /// <summary>
        ///     Gets the name of the first model on a CGFX file.
        ///     Returns null if the file doesn't contain any model.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string getName(MemoryStream data)
        {
            BinaryReader input = new BinaryReader(data);

            cgfxHeader header = new cgfxHeader();
            header.magic = IOUtils.readString(input, 0, 4);
            header.endian = input.ReadUInt16();
            header.length = input.ReadUInt16();
            header.revision = input.ReadUInt32();
            header.fileLength = input.ReadUInt32();
            header.entries = input.ReadUInt32();

            data.Seek(header.length + 8, SeekOrigin.Begin);
            List<dictEntry> models = getDictionary(input);

            if (models.Count > 0)
            {
                data.Seek(models[0].dataOffset + 0xc, SeekOrigin.Begin);
                string name = IOUtils.readString(input, getRelativeOffset(input));
                data.Close();
                return name;
            }
            else
            {
                data.Close();
                return null;
            }
        }
Example #27
0
 public BAR(Stream file)
 {
     if (!file.CanRead || !file.CanSeek)
     {
         throw new NotSupportedException("Cannot read or seek in stream");
     }
     using (var br = new BinaryReader(file))
     {
         if (file.Length < 16 || br.ReadUInt32() != 0x01524142)
         {
             throw new InvalidDataException("Invalid signature");
         }
         int fileC = br.ReadInt32();
         fileList = new List<BARFile>(fileC);
         Debug.WriteLine("Loading BAR with " + fileC + " files");
         file.Position = 16;
         for (int i = 0; i < fileC; i++)
         {
             var bf = new BARFile();
             bf.type = br.ReadUInt32();
             {
                 byte[] b = br.ReadBytes(4);
                 Buffer.BlockCopy(b, 0, bf._id, 0, 4);
             }
             long lpos = file.Position + 8;
             uint pos = br.ReadUInt32();
             int len = br.ReadInt32();
             file.Position = pos;
             bf.data = br.ReadBytes(len);
             fileList.Add(bf);
             file.Position = lpos;
         }
     }
     //BinaryReader should close file
 }
Example #28
0
        public Binding(byte[] FileData)
        {
            MemoryStream MemStream = new MemoryStream(FileData);
            BinaryReader Reader = new BinaryReader(MemStream);

            m_Version = Endian.SwapUInt32(Reader.ReadUInt32());

            byte StrLength = Reader.ReadByte();
            string m_BoneName = Encoding.ASCII.GetString(Reader.ReadBytes(StrLength));

            //Should be 8.
            uint MeshAssetIDSize = Endian.SwapUInt32(Reader.ReadUInt32());

            //AssetID prefix, typical useless Maxis value...
            Reader.ReadUInt32();

            m_MeshAssetID = Endian.SwapUInt64(Reader.ReadUInt64());

            //Should be 8.
            uint TextureAssetIDSize = Endian.SwapUInt32(Reader.ReadUInt32());

            //AssetID prefix, typical useless Maxis value...
            Reader.ReadUInt32();

            m_TextureAssetID = Endian.SwapUInt64(Reader.ReadUInt64());
        }
Example #29
0
        /// <summary>
        /// Reads a *.anim file into this Anim instance.
        /// </summary>
        /// <param name="FileData">The filedata for the *.anim file.</param>
        public Anim(byte[] FileData)
        {
            MemoryStream MemStream = new MemoryStream(FileData);
            BinaryReader Reader = new BinaryReader(MemStream);

            m_Version = Endian.SwapUInt32(Reader.ReadUInt32());
            m_Name = Encoding.ASCII.GetString(Reader.ReadBytes(Endian.SwapInt16(Reader.ReadInt16())));
            m_Duration = Reader.ReadSingle() / 1000; //Why does this have to be divided by 1000? o_O
            m_Distance = Reader.ReadSingle();
            m_IsMoving = Reader.ReadByte();

            m_NumTranslations = Endian.SwapUInt32(Reader.ReadUInt32());
            m_TranslationsTableOffset = Reader.BaseStream.Position;

            Reader.BaseStream.Seek(m_TranslationsTableOffset + 12 * m_NumTranslations, SeekOrigin.Begin);

            m_NumRotations = Endian.SwapUInt32(Reader.ReadUInt32());
            m_RotationsTableOffset = Reader.BaseStream.Position;

            Reader.BaseStream.Seek(m_RotationsTableOffset + 16 * m_NumRotations, SeekOrigin.Begin);

            m_MotionCount = Endian.SwapUInt32(Reader.ReadUInt32());

            for (int i = 0; i < m_MotionCount; i++)
                m_Motions.Add(ReadMotion(Reader));
        }
Example #30
0
File: PACK.cs Project: MetLob/tinke
        public static sFolder Unpack(string file, IPluginHost pluginHost)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));
            sFolder unpacked = new sFolder();
            unpacked.files = new List<sFile>();

            uint num_files = (br.ReadUInt32() / 0x04) - 1;
            br.ReadUInt32(); // Pointer table
            for (int i = 0; i < num_files; i++)
            {
                uint startOffset = br.ReadUInt32();
                long currPos = br.BaseStream.Position;
                br.BaseStream.Position = startOffset;

                sFile newFile = new sFile();
                newFile.name = "File " + (i + 1).ToString("X") + ".bin";
                newFile.offset = startOffset + 4;
                newFile.path = file;
                newFile.size = br.ReadUInt32();

                br.BaseStream.Position = currPos;
                unpacked.files.Add(newFile);
            }

            br.Close();
            return unpacked;
        }