Release 0.0.2

- bump version and pip freeze versions
- actually error if files are empty
- better block device check
- " to ' consistency
This commit is contained in:
Nichlas Severinsen 2019-07-07 21:18:34 +02:00
parent 3783d1c2ff
commit 552147583b
8 changed files with 55 additions and 34 deletions

View file

@ -21,6 +21,7 @@
import os
import sys
import stat
import shutil
import requests
from bs4 import BeautifulSoup
@ -56,12 +57,18 @@ ISO_SECRET = to_bytes("380bcf0b53455b3c7817ab4fa3ba90ed")
ISO_IV = to_bytes("69474772af6fdab342743aefaa186287")
def filesize(filename):
"""Get size of a file in bytes from os.stat"""
try:
return open(filename, "rb").seek(0, 2)
except:
return os.stat(filename).st_size
def size(path):
"""Get size of a file or block device in bytes"""
pathstat = os.stat(path)
# Check if it's a block device
if stat.S_ISBLK(pathstat.st_mode):
return open(path, 'rb').seek(0, os.SEEK_END)
# Otherwise, it's hopefully file
return pathstat.st_size
def read_seven_bit_encoded_int(fileobj, order):
@ -126,7 +133,7 @@ def ird_by_game_id(game_id):
def decrypt(args):
"""Try to decrypt a given .iso using relevant .ird using args from argparse
If no .ird is given this will try to automatically download an .ird file with the encryption/decryption key for the given game .iso
"""

View file

@ -48,7 +48,7 @@ class IRD:
ORDER = 'little'
TEMP_FILE = 'ird'
MAGIC_STRING = b"3IRD"
MAGIC_STRING = b'3IRD'
def __init__(self, args):
@ -56,10 +56,14 @@ class IRD:
self.uncompress(args.ird) # TODO: Try/Except?
self.size = core.filesize(self.TEMP_FILE)
self.size = core.size(self.TEMP_FILE)
if not self.size:
core.error('IRD file is empty!')
with open(self.TEMP_FILE, 'rb') as input_ird:
if input_ird.read(4) != self.MAGIC_STRING:
core.error("Either not an IRD file, corruped IRD file, or unknown IRD format")
core.error('Either not an IRD file, corruped IRD file, or unknown IRD format')
self.version = core.to_int(input_ird.read(1), self.ORDER)
self.game_id = input_ird.read(9)

View file

@ -34,7 +34,7 @@ except ImportError:
class ISO:
"""Class for handling PS3 .iso files
Attributes:
size: Size of .iso in bytes
number_of_regions: Number of regions in the .iso
@ -50,8 +50,12 @@ class ISO:
def __init__(self, args):
"""ISO constructor using args from argparse"""
self.size = core.size(args.iso)
if not self.size:
core.error('looks like ISO file/mount is empty?')
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.
@ -97,7 +101,7 @@ class ISO:
while input_iso.tell() < region['end']:
data = input_iso.read(core.SECTOR)
if not data:
core.warning("Trying to read past the end of the file")
core.warning('Trying to read past the end of the file')
break
pbar.update(1)
output_iso.write(data)
@ -112,7 +116,7 @@ class ISO:
data = input_iso.read(core.SECTOR)
if not data:
core.warning("Trying to read past the end of the file")
core.warning('Trying to read past the end of the file')
break
pbar.update(1)

View file

@ -33,11 +33,11 @@ if __name__ == '__main__':
# Parse command line arguments with argpase
parser = argparse.ArgumentParser(description='A Libre (FLOSS) Python application for unencrypting, extracting, repackaging, and encrypting PS3 ISOs')
parser.add_argument('-v', '--verbose', help="Increase verbosity", action='count')
parser.add_argument('-o', '--output', dest='output', type=str, help="Output filename", default='output.iso')
parser.add_argument('-k', '--ird', dest='ird', type=str, help="Path to .ird file", default="")
parser.add_argument('-v', '--verbose', help='Increase verbosity', action='count')
parser.add_argument('-o', '--output', dest='output', type=str, help='Output filename', default='output.iso')
parser.add_argument('-k', '--ird', dest='ird', type=str, help='Path to .ird file', default='')
required = parser.add_argument_group('required arguments')
required.add_argument('-i', '--iso', dest='iso', type=str, help="Path to .iso file", required=True)
required.add_argument('-i', '--iso', dest='iso', type=str, help='Path to .iso file', required=True)
args = parser.parse_args()
core.decrypt(args)