From 31d3498d88c0109526870c3ee1ee6f4938dcf5d1 Mon Sep 17 00:00:00 2001 From: WorldObservationLog Date: Tue, 28 May 2024 18:17:06 +0800 Subject: [PATCH] fix: speed up decryption --- src/decrypt.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/decrypt.py b/src/decrypt.py index eb19af1..233f258 100644 --- a/src/decrypt.py +++ b/src/decrypt.py @@ -24,12 +24,12 @@ async def decrypt(info: SongInfo, keys: list[str], manifest: Datum, device: Devi else: logger.info(f"Using device {device.serial} to decrypt song: {manifest.attributes.artistName} - {manifest.attributes.name}") try: - reader, writer = await asyncio.open_connection(device.host, device.fridaPort) + reader, writer = await asyncio.open_connection(device.host, device.fridaPort, limit=2**14) except ConnectionRefusedError: logger.warning(f"Failed to connect to device {device.serial}, re-injecting") device.restart_inject_frida() raise RetryableDecryptException - decrypted = bytes() + decrypted = [] last_index = 255 for sample in info.samples: if last_index != sample.descIndex: @@ -59,10 +59,11 @@ async def decrypt(info: SongInfo, keys: list[str], manifest: Datum, device: Devi else: logger.error(f"Failed to decrypt song: {manifest.attributes.artistName} - {manifest.attributes.name}") raise DecryptException - decrypted += result + now += 1 + decrypted.append(result) writer.write(bytes([0, 0, 0, 0])) writer.close() - return decrypted + return bytes().join(decrypted) async def decrypt_sample(writer: asyncio.StreamWriter, reader: asyncio.StreamReader, sample: SampleInfo) -> bytes: