Beispiel #1
0
        /*************************************************************
        *************************************************************/
        public bool AnalyseISO(ODD odd)
        {
            bool IsPlain = true;

            try
            {
                using (DiscStream inputStream = new DiscStream(odd))
                {
                    byte[] buffer = new byte[0x1000];
                    inputStream.Read(buffer, 0, 0x1000);

                    NumPlainRegions = BitConverter.ToUInt32(buffer, 0).Swap();
                    Regions         = new Region[(NumPlainRegions * 2) - 1];

                    if (buffer[0xF70 + 0xA] != '3' || buffer[0xF70 + 0xB] != 'K')
                    {
                        Interaction.Instance.ReportMessage("Invalid ISO file. This file does not contain PIC/D1/D2 data");
                        return(false);
                    }

                    IsDecrypting = buffer[0xF70] != 0x44;                       // Begins with E or D
                    IsBuildedISO = buffer[0xF70 + 0xD] == 0x42;                 // End in BLD
                    IsValidHash  = IsBuildedISO && buffer[0xF70 + 0xF] != 0x44; // Ends in BLF

                    int    pos     = 8;
                    UInt32 Current = BitConverter.ToUInt32(buffer, pos).Swap();
                    pos += 4;
                    for (UInt32 i = 0; i < (2 * NumPlainRegions) - 1; i++)
                    {
                        UInt32 Next = BitConverter.ToUInt32(buffer, pos).Swap();
                        pos += 4;
                        if (IsPlain)
                        {
                            Regions[i] = new PlainRegion(i, IsDecrypting, IsBuildedISO, IsValidHash, Current, Next);
                        }
                        else
                        {
                            Regions[i] = IsDecrypting
                                             ? (Region) new CryptedRegion(i, inputStream.Data1, inputStream.Data2, Current, Next, false)
                                             : new DecryptedRegion(i, inputStream.Data1, inputStream.Data2, Current, Next, false);
                        }
                        IsPlain = !IsPlain;
                        Current = Next;
                    }
                    /* Record this for later */
                    amountOfSectors = Current;

                    // Game ID is at offset 0x810, length = 10
                    GameID = Encoding.ASCII.GetString(buffer, 0x810, 10);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public static Region[] GetRegions(this Stream s)
        {
            using (BinaryReader br = new BinaryReaderExt(s, Encoding.ASCII, true))
            {
                s.Seek(0xF70, SeekOrigin.Begin);
                bool isDecrypting = br.ReadByte() != 0x44;                // Begins with E or D
                s.Seek(0xF70 + 0xD, SeekOrigin.Begin);
                bool isBuildedISO = br.ReadByte() == 0x42;                // End in BLD
                s.Seek(0xF70 + 0xF, SeekOrigin.Begin);
                bool isValidHash = isBuildedISO && br.ReadByte() != 0x44; // Ends in BLF

                /* Read the game Key */
                s.Seek(0xF80, SeekOrigin.Begin);
                byte[] d1 = br.ReadBytes(0x10);
                byte[] d2 = br.ReadBytes(0x10);

                s.Seek(0, SeekOrigin.Begin);
                uint     plainRegions = br.ReadUInt32().Swap();
                Region[] regions      = new Region[(plainRegions * 2) - 1];

                s.Seek(4, SeekOrigin.Current);
                uint current = br.ReadUInt32().Swap();
                bool isPlain = true;
                for (uint i = 0; i < regions.Length; i++)
                {
                    uint next = br.ReadUInt32().Swap();
                    if (isPlain)
                    {
                        regions[i] = new PlainRegion(i, isDecrypting, isBuildedISO, isValidHash, current, next);
                    }
                    else
                    {
                        regions[i] = isDecrypting
                                         ? (Region) new CryptedRegion(i, d1, d2, current, next, false)
                                         : new DecryptedRegion(i, d1, d2, current, next, false);
                    }
                    isPlain = !isPlain;
                    current = next;
                }
                s.Seek(0, SeekOrigin.Begin);
                return(regions);
            }
        }
Beispiel #3
0
        /*************************************************************
        *************************************************************/
        public bool AnalyseISO(string fileName)
        {
            bool IsPlain = true;

            try
            {
                string dir = Path.GetDirectoryName(fileName);
                baseName = string.IsNullOrEmpty(dir)
                               ? Path.GetFileNameWithoutExtension(fileName)
                               : Path.Combine(dir, Path.GetFileNameWithoutExtension(fileName));

                if (baseName.EndsWith(".zip")) // In case of multipart file
                {
                    baseName = string.IsNullOrEmpty(dir)
                                   ? Path.GetFileNameWithoutExtension(baseName)
                                   : Path.Combine(dir, Path.GetFileNameWithoutExtension(baseName));
                }

                inputFilename = fileName;
                using (Ripp3rStream inputStream = new Ripp3rStream(fileName, false))
                {
                    byte[] buffer = new byte[0x1000];
                    inputStream.Read(buffer, 0, 0x1000);

                    NumPlainRegions = BitConverter.ToUInt32(buffer, 0).Swap();
                    Regions         = new Region[(NumPlainRegions * 2) - 1];

                    if (buffer[0xF70 + 0xA] != '3' || buffer[0xF70 + 0xB] != 'K')
                    {
                        Interaction.Instance.ReportMessage("Invalid ISO file. This file does not contain PIC/D1/D2 data");
                        return(false);
                    }

                    IsDecrypting = buffer[0xF70] != 0x44;                       // Begins with E or D
                    IsBuildedISO = buffer[0xF70 + 0xD] == 0x42;                 // End in BLD
                    IsValidHash  = IsBuildedISO && buffer[0xF70 + 0xF] != 0x44; // Ends in BLF

                    /* Read the game Key */
                    byte[] d1 = new byte[0x10];
                    Array.Copy(buffer, 0xF80, d1, 0, 0x10);
                    byte[] d2 = new byte[0x10];
                    Array.Copy(buffer, 0xF90, d2, 0, 0x10);

                    int    pos     = 8;
                    UInt32 Current = BitConverter.ToUInt32(buffer, pos).Swap();
                    pos += 4;
                    for (UInt32 i = 0; i < (2 * NumPlainRegions) - 1; i++)
                    {
                        UInt32 Next = BitConverter.ToUInt32(buffer, pos).Swap();
                        pos += 4;
                        if (IsPlain)
                        {
                            Regions[i] = new PlainRegion(i, IsDecrypting, IsBuildedISO, IsValidHash, Current, Next);
                        }
                        else
                        {
                            Regions[i] = IsDecrypting
                                             ? (Region) new CryptedRegion(i, d1, d2, Current, Next, inputStream.StreamType == StreamType.Zip)
                                             : new DecryptedRegion(i, d1, d2, Current, Next, inputStream.StreamType == StreamType.Zip);
                        }
                        IsPlain = !IsPlain;
                        Current = Next;
                    }
                    /* Record this for later */
                    amountOfSectors = Current;

                    // Game ID is at offset 0x810, length = 10
                    GameID = Encoding.ASCII.GetString(buffer, 0x810, 10);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }

            return(true);
        }