diff --git a/bbot/modules/apkpure.py b/bbot/modules/apkpure.py index 210dfef0e..e7d22489c 100644 --- a/bbot/modules/apkpure.py +++ b/bbot/modules/apkpure.py @@ -45,9 +45,15 @@ async def download_apk(self, app_id): path = None url = f"https://d.apkpure.com/b/XAPK/{app_id}?version=latest" self.helpers.mkdir(self.output_dir / app_id) - file_destination = self.output_dir / app_id / f"{app_id}.xapk" - result = await self.helpers.download(url, warn=False, filename=file_destination) - if result: - self.info(f'Downloaded "{app_id}" from "{url}", saved to {file_destination}') - path = file_destination + response = await self.helpers.request(url, allow_redirects=True) + if response: + attachment = response.headers.get("Content-Disposition", "") + if "filename" in attachment: + extension = attachment.split('filename="')[-1].split(".")[-1].strip('"') + content = response.content + file_destination = self.output_dir / app_id / f"{app_id}.{extension}" + with open(file_destination, "wb") as f: + f.write(content) + self.info(f'Downloaded "{app_id}" from "{url}", saved to {file_destination}') + path = file_destination return path diff --git a/bbot/modules/jadx.py b/bbot/modules/jadx.py index 829542f99..5a773c8f8 100644 --- a/bbot/modules/jadx.py +++ b/bbot/modules/jadx.py @@ -67,7 +67,7 @@ async def setup(self): async def filter_event(self, event): if "file" in event.tags: if not event.data["magic_description"].lower() in self.allowed_file_types: - return False, f"Jadx is not able to decompile this file type" + return False, f"Jadx is not able to decompile this file type: {event.data['magic_description']}" else: return False, "Event is not a file" return True diff --git a/bbot/test/test_step_2/module_tests/test_module_apkpure.py b/bbot/test/test_step_2/module_tests/test_module_apkpure.py index 17b8e0685..65919c62e 100644 --- a/bbot/test/test_step_2/module_tests/test_module_apkpure.py +++ b/bbot/test/test_step_2/module_tests/test_module_apkpure.py @@ -37,6 +37,10 @@ async def setup_after_prep(self, module_test): module_test.httpx_mock.add_response( url="https://d.apkpure.com/b/XAPK/com.bbot.test?version=latest", content=self.apk_file, + headers={ + "Content-Type": "application/vnd.android.package-archive", + "Content-Disposition": "attachment; filename=com.bbot.test.apk", + }, ) def check(self, module_test, events): @@ -61,9 +65,7 @@ def check(self, module_test, events): and e.data["url"] == "https://play.google.com/store/apps/details?id=com.bbot.test" ] ), "Failed to find bbot android app" - filesystem_event = [ - e for e in events if e.type == "FILESYSTEM" and "com.bbot.test.xapk" in e.data["path"] and "apk" in e.tags - ] + filesystem_event = [e for e in events if e.type == "FILESYSTEM" and "com.bbot.test.apk" in e.data["path"]] assert 1 == len(filesystem_event), "Failed to download apk" file = Path(filesystem_event[0].data["path"]) - assert file.is_file(), "Destination xapk doesn't exist" + assert file.is_file(), "Destination apk doesn't exist" diff --git a/bbot/test/test_step_2/module_tests/test_module_jadx.py b/bbot/test/test_step_2/module_tests/test_module_jadx.py index 9eb3c1537..f57dabad8 100644 --- a/bbot/test/test_step_2/module_tests/test_module_jadx.py +++ b/bbot/test/test_step_2/module_tests/test_module_jadx.py @@ -40,7 +40,7 @@ async def setup_after_prep(self, module_test): content=self.apk_file, headers={ "Content-Type": "application/vnd.android.package-archive", - "Content-Disposition": "attachment; filename=com.bbot.test.xapk", + "Content-Disposition": "attachment; filename=com.bbot.test.apk", }, ) @@ -48,7 +48,7 @@ def check(self, module_test, events): filesystem_events = [e for e in events if e.type == "FILESYSTEM"] apk_event = [e for e in filesystem_events if "file" in e.tags] extension, mime_type, description, confidence = get_magic_info(apk_event[0].data["path"]) - assert description == "Android application package", f"Downloaded file was detected as {description}" + assert description == "Android Application Package", f"Downloaded file was detected as {description}" extract_event = [e for e in filesystem_events if "folder" in e.tags] assert 1 == len(extract_event), "Failed to extract apk" extract_path = Path(extract_event[0].data["path"])