| 24 | self.plugin = plugin |
| 25 | |
| 26 | def decrypt(self, data): |
| 27 | data = data.strip() |
| 28 | |
| 29 | data += '=' * (-len(data) % 4) |
| 30 | |
| 31 | dlc_key = data[-88:] |
| 32 | dlc_data = data[:-88].decode('base64') |
| 33 | dlc_content = self.plugin.load(self.API_URL % dlc_key) |
| 34 | |
| 35 | try: |
| 36 | rc = re.search(r'<rc>(.+)</rc>', dlc_content, re.S).group(1).decode('base64')[:16] |
| 37 | |
| 38 | except AttributeError: |
| 39 | raise BadDLC |
| 40 | |
| 41 | key = iv = Crypto.Cipher.AES.new(self.KEY, Crypto.Cipher.AES.MODE_CBC, self.IV).decrypt(rc) |
| 42 | |
| 43 | xml_data = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_CBC, iv).decrypt(dlc_data).decode('base64') |
| 44 | |
| 45 | root = xml.dom.minidom.parseString(xml_data).documentElement |
| 46 | content_node = root.getElementsByTagName("content")[0] |
| 47 | |
| 48 | packages = DLCDecrypter._parse_packages(content_node) |
| 49 | |
| 50 | return packages |
| 51 | |
| 52 | @staticmethod |
| 53 | def _parse_packages(start_node): |