diff --git a/libray/ird.py b/libray/ird.py index 6b1c4fd..f82da76 100644 --- a/libray/ird.py +++ b/libray/ird.py @@ -20,7 +20,7 @@ import os import sys -import gzip +import zlib import shutil try: @@ -110,13 +110,13 @@ class IRD: with open(filename, 'rb') as input_ird: if input_ird.read(4) != self.MAGIC_STRING: uncompress = True - + if uncompress: - with gzip.open(filename, 'rb') as gzfile: + with open(filename, 'rb') as gzfile: with open(self.TEMP_FILE, 'wb') as tmpfile: - tmpfile.write(gzfile.read()) - - shutil.copyfile(filename, self.TEMP_FILE) + tmpfile.write(zlib.decompress(gzfile.read(), zlib.MAX_WBITS|16)) + else: + shutil.copyfile(filename, self.TEMP_FILE) diff --git a/libray/iso.py b/libray/iso.py index fdd8a53..6024a73 100644 --- a/libray/iso.py +++ b/libray/iso.py @@ -18,6 +18,9 @@ # You should have received a copy of the GNU General Public License # along with libray. If not, see . + +import sys +from tqdm import tqdm from Crypto.Cipher import AES try: @@ -36,6 +39,7 @@ class ISO: def __init__(self, args): with open(args.iso, 'rb') as input_iso: + self.size = core.filesize(args.iso) self.number_of_regions = core.to_int(input_iso.read(self.NUM_INFO_BYTES)) unused_bytes = input_iso.read(self.NUM_INFO_BYTES) # Yeah, I don't know either. @@ -46,6 +50,10 @@ class ISO: self.ird = ird.IRD(args) + if self.ird.region_count != len(self.regions)-1: + core.error('ISO corrupted. Expected %s regions, found %s regions' % (self.ird.region_count, len(self.regions)-1)) + sys.exit() + cipher = AES.new(core.ISO_SECRET, AES.MODE_CBC, core.ISO_IV) self.disc_key = cipher.encrypt(self.ird.data1) @@ -56,12 +64,16 @@ class ISO: with open(args.iso, 'rb') as input_iso: with open(args.output, 'wb') as output_iso: + + pbar = tqdm(total=self.size) + for i, region in enumerate(self.regions): input_iso.seek(region['start']) if not region['enc']: while input_iso.tell() < region['end']: data = input_iso.read(core.SECTOR) + pbar.update(core.SECTOR) output_iso.write(data) continue else: @@ -73,12 +85,14 @@ class ISO: num >>= 8 data = input_iso.read(core.SECTOR) + pbar.update(core.SECTOR) cipher = AES.new(self.disc_key, AES.MODE_CBC, bytes(iv)) decrypted = cipher.decrypt(data) output_iso.write(decrypted) - + + pbar.close() def read_regions(self, input_iso, filename): regions = [] @@ -92,7 +106,7 @@ class ISO: }) input_iso.seek(input_iso.tell() - self.NUM_INFO_BYTES) encrypted = not encrypted - regions[-1]['end'] = core.filesize(filename) + regions[-1]['end'] = self.size return regions diff --git a/requirements.txt b/requirements.txt index f8fe951..11a2342 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +tqdm==4.23.4 pycrypto==2.6.1 requests==2.19.1 beautifulsoup4==4.6.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 9db9e0a..7121335 100755 --- a/setup.py +++ b/setup.py @@ -13,8 +13,9 @@ setup( packages=['libray'], scripts=['libray/libray'], install_requires=[ + 'tqdm==4.23.4', 'pycrypto==2.6.1', 'requests==2.19.1', - 'beautifulsoup4==4.6.0' + 'beautifulsoup4==4.6.0', ], ) \ No newline at end of file