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

@ -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/). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [0.0.2] - 2019-07-07
### Added/Fixed
- Decrypting block devices directly (eg. cd/dvd/bd drive) instead of .iso files. For example `-i /dev/sg0` or `-i /dev/sr0`.
## [0.0.1] - 2019-05-16 ## [0.0.1] - 2019-05-16
### Added ### Added
- Manually loading .ird files with `-k` (for 'key') - Manually loading .ird files with `-k` (for 'key')

View file

@ -78,7 +78,9 @@ Then, if you want to feed it into RPCS3 just extract the contents of the .ISO:
7z x nfs_ps3_decrypted.iso 7z x nfs_ps3_decrypted.iso
``` ```
And move the resulting folders into the appropriate folder for RPCS3. And move the resulting folders into the appropriate folder for RPCS3:
- Linux: /home/username/.config/rpcs3/dev_hdd0/disc/
## License ## License
@ -112,9 +114,9 @@ clp = compressed length prefix
## Todo ## Todo
- Docstrings
- Extract ISO (currently doable with `7z x output.iso` - Extract ISO (currently doable with `7z x output.iso`
- Repackage (unextract) and reencrypt iso? - Repackage (unextract) and reencrypt iso?
- Test .irds with version < 9 - Test .irds with version < 9
- Custom command to backup all irds available - Custom command to backup all irds available
- pypi - Unit tests

View file

@ -21,6 +21,7 @@
import os import os
import sys import sys
import stat
import shutil import shutil
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@ -56,12 +57,18 @@ ISO_SECRET = to_bytes("380bcf0b53455b3c7817ab4fa3ba90ed")
ISO_IV = to_bytes("69474772af6fdab342743aefaa186287") ISO_IV = to_bytes("69474772af6fdab342743aefaa186287")
def filesize(filename): def size(path):
"""Get size of a file in bytes from os.stat""" """Get size of a file or block device in bytes"""
try: pathstat = os.stat(path)
return open(filename, "rb").seek(0, 2)
except: # Check if it's a block device
return os.stat(filename).st_size
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): def read_seven_bit_encoded_int(fileobj, order):

View file

@ -48,7 +48,7 @@ class IRD:
ORDER = 'little' ORDER = 'little'
TEMP_FILE = 'ird' TEMP_FILE = 'ird'
MAGIC_STRING = b"3IRD" MAGIC_STRING = b'3IRD'
def __init__(self, args): def __init__(self, args):
@ -56,10 +56,14 @@ class IRD:
self.uncompress(args.ird) # TODO: Try/Except? 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: with open(self.TEMP_FILE, 'rb') as input_ird:
if input_ird.read(4) != self.MAGIC_STRING: 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.version = core.to_int(input_ird.read(1), self.ORDER)
self.game_id = input_ird.read(9) self.game_id = input_ird.read(9)

View file

@ -50,8 +50,12 @@ class ISO:
def __init__(self, args): def __init__(self, args):
"""ISO constructor using args from argparse""" """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: 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)) 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. 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']: while input_iso.tell() < region['end']:
data = input_iso.read(core.SECTOR) data = input_iso.read(core.SECTOR)
if not data: 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 break
pbar.update(1) pbar.update(1)
output_iso.write(data) output_iso.write(data)
@ -112,7 +116,7 @@ class ISO:
data = input_iso.read(core.SECTOR) data = input_iso.read(core.SECTOR)
if not data: 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 break
pbar.update(1) pbar.update(1)

View file

@ -33,11 +33,11 @@ if __name__ == '__main__':
# Parse command line arguments with argpase # Parse command line arguments with argpase
parser = argparse.ArgumentParser(description='A Libre (FLOSS) Python application for unencrypting, extracting, repackaging, and encrypting PS3 ISOs') 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('-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('-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('-k', '--ird', dest='ird', type=str, help='Path to .ird file', default='')
required = parser.add_argument_group('required arguments') 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() args = parser.parse_args()
core.decrypt(args) core.decrypt(args)

View file

@ -1,4 +1,4 @@
tqdm==4.23.4 tqdm==4.32.2
pycrypto==2.6.1 pycrypto==2.6.1
requests==2.19.1 requests==2.22.0
beautifulsoup4==4.6.0 beautifulsoup4==4.7.1

View file

@ -5,7 +5,7 @@ from setuptools import setup
setup( setup(
name="libray", name="libray",
version="0.0.1", version="0.0.2",
description='A Libre (FLOSS) Python application for unencrypting, extracting, repackaging, and encrypting PS3 ISOs', description='A Libre (FLOSS) Python application for unencrypting, extracting, repackaging, and encrypting PS3 ISOs',
author="Nichlas Severinsen", author="Nichlas Severinsen",
author_email="ns@nsz.no", author_email="ns@nsz.no",
@ -13,9 +13,9 @@ setup(
packages=['libray'], packages=['libray'],
scripts=['libray/libray'], scripts=['libray/libray'],
install_requires=[ install_requires=[
'tqdm==4.23.4', 'tqdm==4.32.2',
'pycrypto==2.6.1', 'pycrypto==2.6.1',
'requests==2.19.1', 'requests==2.22.0',
'beautifulsoup4==4.6.0', 'beautifulsoup4==4.7.1',
], ],
) )