From ea01c62019cac315c75bdc1338cf6967253a5f0c Mon Sep 17 00:00:00 2001 From: SP193 Date: Sat, 16 Feb 2019 12:49:01 +0800 Subject: [PATCH] CDVDMAN: revised algorithm for unscrambling the PS2 logo. Fixes failures to correctly unscramble the logo if the first byte of subsequent passes does not represent a black pixel. --- modules/iopcore/cdvdman/cdvdman.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/iopcore/cdvdman/cdvdman.c b/modules/iopcore/cdvdman/cdvdman.c index cff3bf108..4e021ae99 100644 --- a/modules/iopcore/cdvdman/cdvdman.c +++ b/modules/iopcore/cdvdman/cdvdman.c @@ -385,12 +385,18 @@ static int cdvdman_read_sectors(u32 lsn, unsigned int sectors, void *buf) break; } - // PS2LOGO Decryptor algorithm; based on misfire's code (https://github.com/mlafeldt/ps2logo) + /* PS2LOGO Decryptor algorithm; based on misfire's code (https://github.com/mlafeldt/ps2logo) + The PS2 logo is stored within the first 12 sectors, scrambled. + This algorithm exploits the characteristic that the value used for scrambling will be recorded, + when it is XOR'ed against a black pixel. The first pixel is black, hence the value of the first byte + was the value used for scrambling. */ if (lsn < 13) { u32 j; u8 *logo = (u8 *)ptr; - u8 key = logo[0]; - if (logo[0] != 0) { + static u8 key = 0; + if (lsn == 0) //First sector? Copy the first byte as the value for unscrambling the logo. + key = logo[0]; + if (key != 0) { for (j = 0; j < (SectorsToRead * 2048); j++) { logo[j] ^= key; logo[j] = (logo[j] << 3) | (logo[j] >> 5);