Example #1
0
        public XeXHeader(MemoryStream file)
        {
            MyBinaryReader reader;

            try
            {
                reader = new MyBinaryReader(file, EndianType.BigEndian);

                reader.BaseStream.Seek(0L, SeekOrigin.Begin);
                if (Encoding.ASCII.GetString(reader.ReadBytes(4)) == "XEX2")
                {
                    reader.BaseStream.Seek(20L, SeekOrigin.Begin);

                    uint   headerCount = reader.ReadUInt32();
                    byte[] infoArray   = new byte[] { 0, 4, 0, 6 };

                    for (int i = 0; i < headerCount; i++)
                    {
                        byte[] headerIdArray = reader.ReadBytes(4);

                        uint headerId = BitConverter.ToUInt32(headerIdArray, 0);

                        if (headerId == BitConverter.ToUInt32(infoArray, 0))
                        {
                            uint dataAddress = reader.ReadUInt32();

                            reader.BaseStream.Seek((long)dataAddress, SeekOrigin.Begin);
                            this.mediaId        = reader.ReadBytes(4);
                            this.version        = reader.ReadUInt32();
                            this.baseVersion    = reader.ReadUInt32();
                            this.titleId        = reader.ReadBytes(4);
                            this.platform       = reader.ReadByte();
                            this.executableType = reader.ReadByte();
                            this.discNumber     = reader.ReadByte();
                            this.discCount      = reader.ReadByte();
                            break;
                        }
                        else
                        {
                            reader.ReadUInt32();
                        }
                    }
                }
                else
                {
                    throw new Exception("Extracted file is not XEX file");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            reader.Close();
        }
Example #2
0
        /// <summary>
        /// Search for default.xex
        /// </summary>
        /// <returns>true if found; false if not found</returns>
        private bool SearchForDefaultXeX()
        {
            try
            {
                this.iso.Reader.BaseStream.Seek((long)(((long)this.iso.IsoInfo.RootDirSector * (long)this.iso.IsoInfo.SectorSize) + (long)this.iso.IsoInfo.RootOffset), System.IO.SeekOrigin.Begin);

                byte[] rootDirBuffer = this.iso.Reader.ReadBytes((int)this.iso.IsoInfo.RootDirSize);

                MemoryStream   ms     = new MemoryStream(rootDirBuffer);
                MyBinaryReader reader = new MyBinaryReader(ms);

                while (reader.BaseStream.Position < this.iso.IsoInfo.RootDirSize)
                {
                    ushort offsetLeftSubTreeTmp  = reader.ReadUInt16();
                    ushort offsetRightSubTreeTmp = reader.ReadUInt16();

                    if (offsetLeftSubTreeTmp != 0xffff && offsetRightSubTreeTmp != 0xffff)
                    {
                        uint   startingSectorOfFileTmp = reader.ReadUInt32();
                        uint   fileSizeTmp             = reader.ReadUInt32();
                        uint   fileAttribute           = (uint)reader.ReadByte();
                        byte   fileNameLengthTmp       = reader.ReadByte();
                        string fileNameTmp             = Encoding.ASCII.GetString(rootDirBuffer, (int)reader.BaseStream.Position, fileNameLengthTmp);
                        reader.BaseStream.Seek((long)fileNameLengthTmp, SeekOrigin.Current);
                        long num1 = reader.BaseStream.Position % 4L;
                        if ((reader.BaseStream.Position % 4L) != 0L)
                        {
                            reader.BaseStream.Seek(4L - (reader.BaseStream.Position % 4L), SeekOrigin.Current);
                        }

                        if (fileNameTmp.ToLower() == this.fileName.ToLower())
                        {
                            this.offsetLeftSubTree    = offsetLeftSubTreeTmp;
                            this.offsetRightSubTree   = offsetRightSubTreeTmp;
                            this.startingSectorOfFile = startingSectorOfFileTmp;
                            this.fileSize             = fileSizeTmp;
                            this.fileNameLength       = fileNameLengthTmp;
                            //this.iso.Reader.Read(this.file, (int)(this.iso.IsoInfo.RootOffset + (this.startingSectorOfFile * this.iso.IsoInfo.SectorSize)), (int)this.fileSize);
                            this.iso.Reader.BaseStream.Seek((long)((long)this.iso.IsoInfo.RootOffset + ((long)this.startingSectorOfFile * (long)this.iso.IsoInfo.SectorSize)), SeekOrigin.Begin);
                            this.file = this.iso.Reader.ReadBytes((int)this.fileSize);
                            return(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error browsing ISO for default.xex", ex);
            }

            return(false);
        }
Example #3
0
 private long SearchForDefaultXeX()
 {
     try
     {
         this.iso.Reader.BaseStream.Seek((long)((long)((long)this.iso.IsoInfo.RootDirSector * (long)this.iso.IsoInfo.SectorSize) + (long)this.iso.IsoInfo.RootOffset), SeekOrigin.Begin);
         byte[]         buffer = this.iso.Reader.ReadBytes((int)this.iso.IsoInfo.RootDirSize);
         MemoryStream   s      = new MemoryStream(buffer);
         MyBinaryReader reader = new MyBinaryReader(s);
         while (reader.BaseStream.Position < this.iso.IsoInfo.RootDirSize)
         {
             ushort num  = reader.ReadUInt16();
             ushort num2 = reader.ReadUInt16();
             if ((num != 0xffff) && (num2 != 0xffff))
             {
                 uint   num3  = reader.ReadUInt32();
                 uint   num4  = reader.ReadUInt32();
                 uint   num5  = reader.ReadByte();
                 byte   count = reader.ReadByte();
                 string str   = Encoding.ASCII.GetString(buffer, (int)reader.BaseStream.Position, count);
                 reader.BaseStream.Seek((long)count, SeekOrigin.Current);
                 long num7 = reader.BaseStream.Position % 4L;
                 if ((reader.BaseStream.Position % 4L) != 0L)
                 {
                     reader.BaseStream.Seek(4L - (reader.BaseStream.Position % 4L), SeekOrigin.Current);
                 }
                 if ((str.ToLower() == this.fileName.ToLower()) || (str.ToLower() == this.fileName2.ToLower()))
                 {
                     this.offsetLeftSubTree    = num;
                     this.offsetRightSubTree   = num2;
                     this.startingSectorOfFile = num3;
                     this.fileSize             = num4;
                     this.fileNameLength       = count;
                     this.iso.Reader.BaseStream.Seek(((long)this.iso.IsoInfo.RootOffset + (long)((long)this.startingSectorOfFile * (long)this.iso.IsoInfo.SectorSize)), SeekOrigin.Begin);
                     return(iso.Reader.BaseStream.Position);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         throw new Exception("Error browsing ISO for default.xex/xeb", exception);
     }
     return(-1);
 }
Example #4
0
        public ParsedClassFile Parse()
        {
            if (_bReader.ReadUInt32() != Magic)
            {
                throw new Exception("MagicException"); // Ошибочку нужно создать
            }
            var minorVersion = _bReader.ReadUInt16();
            var majorVersion = _bReader.ReadUInt16();

            var constantPoolCount = _bReader.ReadUInt16();
            var constantPool      = GetConstantPool(constantPoolCount);

            var acessFlags      = _bReader.ReadUInt16();
            var thisClass       = _bReader.ReadUInt16();
            var superClass      = _bReader.ReadUInt16();
            var interfacesCount = _bReader.ReadUInt16();
            var interfaces      = GetInterfaces(_interfacesCount);

            return(new ParsedClassFile(minorVersion, majorVersion, constantPoolCount, constantPool));
        }
Example #5
0
        public XeXHeader(MyBinaryReader reader)
        {
            long position = reader.BaseStream.Position;

            try
            {
                byte[] b = reader.ReadBytes(4);
                if (Encoding.ASCII.GetString(b) == "XEX2")
                {
                    reader.BaseStream.Seek(position + 20L, SeekOrigin.Begin);
                    uint num = reader.ReadUInt32();

                    UInt32 einfo  = BitConverter.ToUInt32(executioninfo, 0);
                    UInt32 tstamp = BitConverter.ToUInt32(basefiletimestamp, 0);

                    for (int i = 0; i < num; i++)
                    {
                        UInt32 val     = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
                        uint   pos     = reader.ReadUInt32();
                        long   savepos = reader.BaseStream.Position;
                        if (val == einfo)
                        {
                            reader.BaseStream.Seek((long)position + pos, SeekOrigin.Begin);
                            this.short_mediaId  = reader.ReadBytes(4);
                            this.version        = reader.ReadUInt32();
                            this.baseVersion    = reader.ReadUInt32();
                            this.titleId        = reader.ReadBytes(4);
                            this.platform       = reader.ReadByte();
                            this.executableType = reader.ReadByte();
                            this.discNumber     = reader.ReadByte();
                            this.discCount      = reader.ReadByte();
                            reader.BaseStream.Seek(savepos, SeekOrigin.Begin);
                        }
                        else if (val == tstamp)
                        {
                            reader.BaseStream.Seek((long)position + pos + 4, SeekOrigin.Begin);
                            this.date =
                                new DateTime(1970, 1, 1, 0, 0, 0).Add(
                                    TimeSpan.FromTicks((long)reader.ReadUInt32() * TimeSpan.TicksPerSecond));
                            reader.BaseStream.Seek(savepos, SeekOrigin.Begin);
                        }
                    }
                    //Read cert
                    reader.BaseStream.Seek((long)position + 0x10, SeekOrigin.Begin);
                    uint offset = reader.ReadUInt32();
                    reader.BaseStream.Seek((long)position + (long)offset + 0x140, SeekOrigin.Begin);
                    mediaid = reader.ReadBytes(16);
                    reader.BaseStream.Seek((long)position + (long)offset + 0x178, SeekOrigin.Begin);
                    regioncode = reader.ReadUInt32();
                }
                else if (Encoding.ASCII.GetString(b) == "XBEH")
                {
                    reader.EndianType = EndianType.LittleEndian;
                    reader.BaseStream.Seek(position + 0x110, SeekOrigin.Begin);
                    uint pos = reader.ReadUInt32();
                    this.date = new DateTime(1970, 1, 1, 0, 0, 0).Add(TimeSpan.FromTicks((long)reader.ReadUInt32() * TimeSpan.TicksPerSecond));
                    reader.BaseStream.Seek(position + pos + 0x8, SeekOrigin.Begin);
                    this.titleId    = new byte[4];
                    this.titleId[3] = reader.ReadByte();
                    this.titleId[2] = reader.ReadByte();
                    this.titleId[1] = reader.ReadByte();
                    this.titleId[0] = reader.ReadByte();
                    byte[] b2 = reader.ReadBytes(0x40);
                    this.title = Encoding.Unicode.GetString(b2).Replace("\0", string.Empty).Trim();
                    reader.BaseStream.Seek(position + pos + 0xA8, SeekOrigin.Begin);
                    this.discNumber = this.discCount = (byte)(reader.ReadUInt32() + 1);
                    this.version    = reader.ReadUInt32();
                }
                else
                {
                    throw new Exception("Not XEX/XEB file");
                }
            }
            catch (Exception exception)
            {
                if (reader != null)
                {
                    reader.BaseStream.Seek(position, SeekOrigin.Begin);
                }
                throw exception;
            }
            reader.BaseStream.Seek(position, SeekOrigin.Begin);
        }
Example #6
0
        private object?LoadObjectV1(int dataOffset)
        {
            Debug.Assert(System.Threading.Monitor.IsEntered(reader));
            reader.Seek(dataSectionPosition + dataOffset, SeekOrigin.Begin);
            int typeIndex = reader.Read7BitEncodedInt();

            if (typeIndex == -1)
            {
                return(null);
            }
            string typeName = FindType(typeIndex);
            int    comma    = typeName.IndexOf(',');

            if (comma > 0)
            {
                // strip assembly name
                typeName = typeName.Substring(0, comma);
            }
            switch (typeName)
            {
            case "System.String":
                return(reader.ReadString());

            case "System.Byte":
                return(reader.ReadByte());

            case "System.SByte":
                return(reader.ReadSByte());

            case "System.Int16":
                return(reader.ReadInt16());

            case "System.UInt16":
                return(reader.ReadUInt16());

            case "System.Int32":
                return(reader.ReadInt32());

            case "System.UInt32":
                return(reader.ReadUInt32());

            case "System.Int64":
                return(reader.ReadInt64());

            case "System.UInt64":
                return(reader.ReadUInt64());

            case "System.Single":
                return(reader.ReadSingle());

            case "System.Double":
                return(reader.ReadDouble());

            case "System.DateTime":
                // Ideally we should use DateTime's ToBinary & FromBinary,
                // but we can't for compatibility reasons.
                return(new DateTime(reader.ReadInt64()));

            case "System.TimeSpan":
                return(new TimeSpan(reader.ReadInt64()));

            case "System.Decimal":
                int[] bits = new int[4];
                for (int i = 0; i < bits.Length; i++)
                {
                    bits[i] = reader.ReadInt32();
                }
                return(new decimal(bits));

            default:
                return(new ResourceSerializedObject(FindType(typeIndex), this, reader.BaseStream.Position));
            }
        }