Some tidying

This commit is contained in:
Nichlas Severinsen 2019-05-16 10:37:28 +02:00
parent e45367a875
commit 56e9beaa20
8 changed files with 87 additions and 47 deletions

View file

@ -1,4 +1,3 @@
# LibRay # LibRay
LibRay: A portmanteau of Libre and Blu-Ray LibRay: A portmanteau of Libre and Blu-Ray
@ -8,7 +7,41 @@ extracting, repackaging, and encrypting PS3 ISOs.
A hackable, crossplatform, alternative to ISOTools and ISO-Rebuilder. A hackable, crossplatform, alternative to ISOTools and ISO-Rebuilder.
## How to install
1. Clone this repository ```git clone https://notabug.org/necklace/libray```
2. Install dependencies with ```sudo pip install -r requirements.txt```
3. Run ```sudo python setup.py install```
Note: You will need Python 3, so you might want to use `python3` and `pip3`.
`libray` is now installed to your path. In the future I'll add this package to pypi.
## License
This project is Free and Open Source Software; FOSS, licensed under the GNU General Public License version 3. GPLv3.
## Error!
Help! I get
> ImportError: No module named Crypto.Cipher
or
> ImportError: cannot import name 'byte_string' from 'Crypto.Util.py3compat' (/usr/lib/python3.7/site-packages/Crypto/Util/py3compat.py)
This is due to multiple similarly named python crypto packages, one way to fix it is:
```
sudo pip uninstall crypto
sudo pip uninstall pycrypto
sudo pip install pycrypto
```
## Development
[see also](http://www.psdevwiki.com/ps3/Bluray_disc#Encryption) ([archive.fo](https://archive.fo/hN1E6)) [see also](http://www.psdevwiki.com/ps3/Bluray_disc#Encryption) ([archive.fo](https://archive.fo/hN1E6))
@ -16,7 +49,6 @@ A hackable, crossplatform, alternative to ISOTools and ISO-Rebuilder.
clp = compressed length prefix clp = compressed length prefix
## Todo ## Todo
- Automatically download .ird file if not given - Automatically download .ird file if not given
@ -24,6 +56,7 @@ clp = compressed length prefix
- Extract ISO (currently doable with `7z x output.iso` - Extract ISO (currently doable with `7z x output.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
## Advanced ## Advanced

9
app.yaml Normal file
View file

@ -0,0 +1,9 @@
libraries:
- name: pycrypto
version: "2.6.1"
- name: tqdm
version: "4.23.4"
- name: requests
version: "2.19.1"
- name: beautifulsoup4
version: "4.6.0"

View file

@ -2,19 +2,19 @@
# libray - Libre Blu-Ray PS3 ISO Tool # libray - Libre Blu-Ray PS3 ISO Tool
# Copyright (C) 2018 Nichlas Severinsen # Copyright (C) 2018 Nichlas Severinsen
# #
# This file is part of libray. # This file is part of libray.
# #
# libray is free software: you can redistribute it and/or modify # libray is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# libray is distributed in the hope that it will be useful, # libray is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with libray. If not, see <https://www.gnu.org/licenses/>. # along with libray. If not, see <https://www.gnu.org/licenses/>.
@ -102,12 +102,12 @@ def ird_by_game_id(game_id):
ird_name = url ird_name = url
if not ird_name: if not ird_name:
error("Unable to download IRD, couldn't find link") error("Unable to download IRD, couldn't find link")
download_ird(ird_name) download_ird(ird_name)
return(ird_name) return(ird_name)
# Main functions # Main functions
@ -118,5 +118,5 @@ def decrypt(args):
input_iso.decrypt(args) input_iso.decrypt(args)

View file

@ -2,19 +2,19 @@
# libray - Libre Blu-Ray PS3 ISO Tool # libray - Libre Blu-Ray PS3 ISO Tool
# Copyright (C) 2018 Nichlas Severinsen # Copyright (C) 2018 Nichlas Severinsen
# #
# This file is part of libray. # This file is part of libray.
# #
# libray is free software: you can redistribute it and/or modify # libray is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# libray is distributed in the hope that it will be useful, # libray is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with libray. If not, see <https://www.gnu.org/licenses/>. # along with libray. If not, see <https://www.gnu.org/licenses/>.
@ -37,9 +37,9 @@ class IRD:
TEMP_FILE = 'ird' TEMP_FILE = 'ird'
MAGIC_STRING = b"3IRD" MAGIC_STRING = b"3IRD"
def __init__(self, args): def __init__(self, args):
self.uncompress(args.ird) # TODO: Try/Except self.uncompress(args.ird) # TODO: Try/Except
self.size = core.filesize(self.TEMP_FILE) self.size = core.filesize(self.TEMP_FILE)
@ -57,12 +57,12 @@ class IRD:
if self.version == 7: if self.version == 7:
self.identifier = input_ird.read(4) self.identifier = input_ird.read(4)
header_length = (core.to_int(input_ird.read(4), self.ORDER)) header_length = (core.to_int(input_ird.read(4), self.ORDER))
self.header = input_ird.read(header_length) self.header = input_ird.read(header_length)
footer_length = (core.to_int(input_ird.read(4), self.ORDER)) footer_length = (core.to_int(input_ird.read(4), self.ORDER))
self.footer = input_ird.read(footer_length) self.footer = input_ird.read(footer_length)
self.region_count = core.to_int(input_ird.read(1), self.ORDER) self.region_count = core.to_int(input_ird.read(1), self.ORDER)
self.region_hashes = [] self.region_hashes = []
for i in range(0, self.region_count): for i in range(0, self.region_count):
@ -77,7 +77,7 @@ class IRD:
if self.version >= 9: if self.version >= 9:
self.pic = input_ird.read(115) self.pic = input_ird.read(115)
unused_bytes = input_ird.read(4) # Yeah, I don't know either. unused_bytes = input_ird.read(4) # Yeah, I don't know either.
self.data1 = input_ird.read(16) self.data1 = input_ird.read(16)
@ -91,24 +91,24 @@ class IRD:
if args.verbose: if args.verbose:
self.print_info() self.print_info()
os.remove(self.TEMP_FILE) os.remove(self.TEMP_FILE)
def get_if_exists(self, input_ird): def get_if_exists(self, input_ird):
starting_address = input_ird.tell() starting_address = input_ird.tell()
length = core.read_seven_bit_encoded_int(input_ird, self.ORDER) length = core.read_seven_bit_encoded_int(input_ird, self.ORDER)
print(length) print(length)
if length: if length:
return input_ird.read(length) return input_ird.read(length)
input_ird.seek(starting_address) input_ird.seek(starting_address)
return None return None
def uncompress(self, filename): def uncompress(self, filename):
uncompress = False uncompress = False
with open(filename, 'rb') as input_ird: with open(filename, 'rb') as input_ird:
if input_ird.read(4) != self.MAGIC_STRING: if input_ird.read(4) != self.MAGIC_STRING:
uncompress = True uncompress = True
@ -119,7 +119,7 @@ class IRD:
else: else:
shutil.copyfile(filename, self.TEMP_FILE) shutil.copyfile(filename, self.TEMP_FILE)
def print_info(self): def print_info(self):
print('Info from IRD:') print('Info from IRD:')

View file

@ -2,19 +2,19 @@
# libray - Libre Blu-Ray PS3 ISO Tool # libray - Libre Blu-Ray PS3 ISO Tool
# Copyright (C) 2018 Nichlas Severinsen # Copyright (C) 2018 Nichlas Severinsen
# #
# This file is part of libray. # This file is part of libray.
# #
# libray is free software: you can redistribute it and/or modify # libray is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# libray is distributed in the hope that it will be useful, # libray is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with libray. If not, see <https://www.gnu.org/licenses/>. # along with libray. If not, see <https://www.gnu.org/licenses/>.
@ -33,7 +33,7 @@ except ImportError:
class ISO: class ISO:
NUM_INFO_BYTES = 4 NUM_INFO_BYTES = 4
@ -76,7 +76,7 @@ class ISO:
with open(args.output, 'wb') as output_iso: with open(args.output, 'wb') as output_iso:
pbar = tqdm(total= (self.size // 2048) - 4 ) pbar = tqdm(total= (self.size // 2048) - 4 )
for i, region in enumerate(self.regions): for i, region in enumerate(self.regions):
input_iso.seek(region['start']) input_iso.seek(region['start'])
@ -96,28 +96,28 @@ class ISO:
for j in range(0,16): for j in range(0,16):
iv[16 - j - 1] = (num & 0xFF) iv[16 - j - 1] = (num & 0xFF)
num >>= 8 num >>= 8
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)
cipher = AES.new(self.disc_key, AES.MODE_CBC, bytes(iv)) cipher = AES.new(self.disc_key, AES.MODE_CBC, bytes(iv))
decrypted = cipher.decrypt(data) decrypted = cipher.decrypt(data)
output_iso.write(decrypted) output_iso.write(decrypted)
pbar.close() pbar.close()
def read_regions(self, input_iso, filename): def read_regions(self, input_iso, filename):
regions = [] regions = []
encrypted = False encrypted = False
for i in range(0, self.number_of_regions*2): for i in range(0, self.number_of_regions*2):
regions.append({ regions.append({
'start': core.to_int(input_iso.read(self.NUM_INFO_BYTES))*core.SECTOR, 'start': core.to_int(input_iso.read(self.NUM_INFO_BYTES))*core.SECTOR,
'end': core.to_int(input_iso.read(self.NUM_INFO_BYTES))*core.SECTOR, 'end': core.to_int(input_iso.read(self.NUM_INFO_BYTES))*core.SECTOR,
'enc': encrypted 'enc': encrypted
}) })
input_iso.seek(input_iso.tell() - self.NUM_INFO_BYTES) input_iso.seek(input_iso.tell() - self.NUM_INFO_BYTES)
@ -133,4 +133,3 @@ class ISO:
for i, region in enumerate(self.regions): for i, region in enumerate(self.regions):
print(i, region) print(i, region)

View file

@ -3,19 +3,19 @@
# libray - Libre Blu-Ray PS3 ISO Tool # libray - Libre Blu-Ray PS3 ISO Tool
# Copyright (C) 2018 Nichlas Severinsen # Copyright (C) 2018 Nichlas Severinsen
# #
# This file is part of libray. # This file is part of libray.
# #
# libray is free software: you can redistribute it and/or modify # libray is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# libray is distributed in the hope that it will be useful, # libray is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with libray. If not, see <https://www.gnu.org/licenses/>. # along with libray. If not, see <https://www.gnu.org/licenses/>.
@ -41,4 +41,3 @@ if __name__ == '__main__':
core.decrypt(args) core.decrypt(args)

View file

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

View file

@ -14,8 +14,8 @@ setup(
scripts=['libray/libray'], scripts=['libray/libray'],
install_requires=[ install_requires=[
'tqdm==4.23.4', 'tqdm==4.23.4',
'pycrypto==2.6.1', 'pycrypto==2.6.1',
'requests==2.19.1', 'requests==2.19.1',
'beautifulsoup4==4.6.0', 'beautifulsoup4==4.6.0',
], ],
) )