From cb9e67a5437ddfafd6a93f5a208b9faf3f2d5575 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 29 Jan 2015 15:56:57 +0100 Subject: Some file encoding fixup + optimizations --- module/plugins/container/DLC.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'module/plugins/container/DLC.py') diff --git a/module/plugins/container/DLC.py b/module/plugins/container/DLC.py index 53349c5c7..184a7b25a 100644 --- a/module/plugins/container/DLC.py +++ b/module/plugins/container/DLC.py @@ -9,13 +9,15 @@ from base64 import standard_b64decode from Crypto.Cipher import AES from module.plugins.Container import Container -from module.utils import decode +from module.utils import decode, fs_encode class DLC(Container): - __name__ = "DLC" - __version__ = "0.22" - __pattern__ = r'.+\.dlc$' + __name__ = "DLC" + __type__ = "container" + __version__ = "0.23" + + __pattern__ = r'.+\.dlc$' __description__ = """DLC container decrypter plugin""" __license__ = "GPLv3" @@ -26,31 +28,33 @@ class DLC(Container): ("Walter Purcaro", "vuolter@gmail.com")] - def setup(self): - self.key = "cb99b5cbc24db398" - self.iv = "9bc24cb995cb8db3" - self.api_url = "http://service.jdownloader.org/dlcrypt/service.php?srcType=dlc&destType=pylo&data=" + KEY = "cb99b5cbc24db398" + IV = "9bc24cb995cb8db3" + API_URL = "http://service.jdownloader.org/dlcrypt/service.php?srcType=dlc&destType=pylo&data=%s" def decrypt(self, pyfile): - with open(pyfile.url.replace("\n", "")) as dlc: + file = fs_encode(pyfile.url.strip()) + with open(file) as dlc: data = dlc.read().strip() data += '=' * (-len(data) % 4) dlckey = data[-88:] - dlcdata = data[:-88] - dlcdata = standard_b64decode(dlcdata) + dlcdata = standard_b64decode(data[:-88]) + + try: + rc = re.search(r'(.+)', self.load(self.API_URL % dlckey)).group(1) + + except Exception: + self.fail(_("DLC file is corrupted")) - rc = self.load(self.api_url + dlckey) - rc = re.search(r'(.+)', rc).group(1) - rc = standard_b64decode(rc) + else: + rc = standard_b64decode(rc) - obj = AES.new(self.key, AES.MODE_CBC, self.iv) - dlckey = obj.decrypt(rc) - obj = AES.new(dlckey, AES.MODE_CBC, dlckey) + dlckey = AES.new(self.KEY, AES.MODE_CBC, self.IV).decrypt(rc) - self.data = standard_b64decode(obj.decrypt(dlcdata)) + self.data = standard_b64decode(AES.new(dlckey, AES.MODE_CBC, dlckey).decrypt(dlcdata)) self.packages = [(entry[0] if entry[0] else pyfile.name, entry[1], entry[0] if entry[0] else pyfile.name) \ for entry in self.getPackages()] -- cgit v1.2.3