diff --git a/.gitignore b/.gitignore index eaf1eb9..1063044 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.ird *.gz *.db +*.zip PS3_GAME/ PS3_UPDATE/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bc2ff6..66644c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [0.0.8] - 2021-11-27 +### Fixed +- Issue #7: fix manually supplied .ird files not being used. + ## [0.0.7] - 2021-06-29 ### Added - PARAM.SFO reader (sfo.py) diff --git a/libray/ird.py b/libray/ird.py index fbcc1db..a2d28f9 100644 --- a/libray/ird.py +++ b/libray/ird.py @@ -51,10 +51,10 @@ class IRD: MAGIC_STRING = b'3IRD' - def __init__(self, args): + def __init__(self, ird_path, verbose=False): """IRD constructor using args from argparse.""" - self.uncompress(args.ird) # TODO: Try/Except? + self.uncompress(ird_path) # TODO: Try/Except? self.size = core.size(self.TEMP_FILE) @@ -107,7 +107,7 @@ class IRD: if self.version < 7: self.uid = core.to_int(input_ird.read(4), self.ORDER) - if args.verbose: + if verbose: self.print_info() os.remove(self.TEMP_FILE) diff --git a/libray/iso.py b/libray/iso.py index bef83bb..12eb09f 100644 --- a/libray/iso.py +++ b/libray/iso.py @@ -174,8 +174,6 @@ class ISO: db = sqlite3.connect((pathlib.Path(__file__).resolve() / 'data/') / 'keys.db') c = db.cursor() - - #core.vprint('Calculating crc32', args) #input_iso.seek(0) @@ -228,7 +226,7 @@ class ISO: core.warning('No IRD file specified, finding required file', args) args.ird = core.ird_by_game_id(self.game_id) # Download ird - self.ird = ird.IRD(args) + self.ird = ird.IRD(args.ird) if self.ird.region_count != len(self.regions)-1: core.error('Corrupt ISO or error in IRD. Expected %s regions, found %s regions' % (self.ird.region_count, len(self.regions)-1)) @@ -237,6 +235,21 @@ class ISO: core.error('Corrupt ISO or error in IRD. Expected filesize larger than %.2f GiB, actual size is %.2f GiB' % (self.regions[-1]['start'] / 1024**3, self.size / 1024**3 ) ) self.disc_key = cipher.encrypt(self.ird.data1) + + else: + + # .ird file given with -k / --ird + + self.ird = ird.IRD(args.ird) + + if self.ird.region_count != len(self.regions)-1: + core.error('Corrupt ISO or error in IRD. Expected %s regions, found %s regions' % (self.ird.region_count, len(self.regions)-1)) + + if self.regions[-1]['start'] > self.size: + core.error('Corrupt ISO or error in IRD. Expected filesize larger than %.2f GiB, actual size is %.2f GiB' % (self.regions[-1]['start'] / 1024**3, self.size / 1024**3 ) ) + + self.disc_key = cipher.encrypt(self.ird.data1) + else: self.disc_key = core.to_bytes(args.decryption_key) diff --git a/setup.py b/setup.py index 2f97505..9827536 100755 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ with open('README.md') as f: setup( name="libray", - version="0.0.7", + version="0.0.8", description='A Libre (FLOSS) Python application for unencrypting, extracting, repackaging, and encrypting PS3 ISOs', long_description=long_description, long_description_content_type='text/markdown', diff --git a/tools/keys2db.py b/tools/keys2db.py index f5bd78c..8c7423a 100755 --- a/tools/keys2db.py +++ b/tools/keys2db.py @@ -47,6 +47,12 @@ if __name__ == '__main__': cwd = pathlib.Path(__file__).resolve().parent + keys_path = cwd / 'keys' + + if not keys_path.exists(): + print('Error: No keys/ folder. Place the .key files in a tools/keys/ folder') + sys.exit() + any_dats = [x for x in cwd.glob('*.dat')] if not any_dats: @@ -82,6 +88,11 @@ if __name__ == '__main__': db.close() + data_path = (cwd.parent / 'libray') / 'data/' + + if not data_path.exists(): + data_path.mkdir() + shutil.copyfile(db_path, ((cwd.parent / 'libray') / 'data/') / db_path.name) print('Warning: no keyfiles for %s titles' % str(warnings))