Пример #1
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            uint numSectors = (uint)Utilities.RoundToSector(count);

            // We read by whole sectors only, so check if the count is a multiple of the sector size
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            // Read as much as required
            // We will read as much sectors as needed, but always up to a whole sector
            byte[] completeBuffer = new byte[numSectors * Utilities.SectorSize];

            // Read the bytes requested
            if (ODD.ReadWithRetry(completeBuffer, _sectorPosition, numSectors) == false)
            {
                // Abort here, this won't work...
                throw new BadReadException("Can't read sectors at position " + _sectorPosition +
                                           ". Please check the disc for errors");
            }
            Array.Copy(completeBuffer, _positionInSector + offset, buffer, offset, count);

            PatchBuffer(buffer, count);

            SetPosition(_position + count);
            return(count);
        }
Пример #2
0
        private static byte[] MakeData2Random(byte[] data2)
        {
            byte[] d2 = new byte[data2.Length];
            ODD.AESDecrypt(Utilities.D2_KEY, Utilities.D2_IV, data2, 0, data2.Length, d2, 0);

            // Fetch the last 4 bytes
            int val = BitConverter.ToInt32(d2, 12);

            if (val == 0)
            {
                return(data2);
            }

            // Fill the last part with a 1, and let the iso builder fill it with crap
            int newval = new Random().Next(1, 0x1FFFFF);

            byte[] rnd = BitConverter.GetBytes(newval).Swap();
            Array.Copy(rnd, 0, d2, 12, rnd.Length);

            ODD.AESEncrypt(Utilities.D2_KEY, Utilities.D2_IV, d2, 0, d2.Length, data2, 0);
            return(data2);
        }
Пример #3
0
        public DiscStream(ODD odd)
        {
            _cdb = ODD.CDB;
            _odd = odd;
            byte[] picData = new byte[0x73];
            byte[] data1   = new byte[0x10];
            byte[] data2   = new byte[0x10];

            if (_cdb.DoReadPICZone(picData) != CDB.IoResult.OK)
            {
                throw new BadReadException("Can't read PIC data");
            }
            PicData = picData;

            // Establish the session with the DVD drive
            if (odd.EstablishSessionKeys(0, ODD.Key1, ODD.Key2) == false)
            {
                throw new AuthenticationException("Can't authenticate with the drive for D1/D2 extraction.");
            }
            if (odd.GetData(data1, data2) == false)
            {
                throw new AuthenticationException("Can't extract D1/D2 values");
            }
            if (odd.EstablishSessionKeys(1, _odd.FixedKey30, _odd.FixedKey31) == false)
            {
                throw new AuthenticationException("Can't authenticate with the drive for data extraction.");
            }

            Data1 = data1;
            Data2 = data2;

            uint NumSectors = odd.GetNumSectors();

            _length = NumSectors * Utilities.SectorSize;

            _cdb.DoSetCDROMSpeed(0xFFFF);
        }