Use zlib instead of gzip

This commit is contained in:
Nichlas Severinsen 2018-07-07 12:13:11 +02:00
parent de805696e2
commit cf0a529cdb
4 changed files with 25 additions and 9 deletions

View file

@ -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)

View file

@ -18,6 +18,9 @@
# You should have received a copy of the GNU General Public License
# along with libray. If not, see <https://www.gnu.org/licenses/>.
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

View file

@ -1,3 +1,4 @@
tqdm==4.23.4
pycrypto==2.6.1
requests==2.19.1
beautifulsoup4==4.6.0

View file

@ -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',
],
)