Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wizzard apkm/zip split packages. #1387

Open
wants to merge 10 commits into
base: async
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions mapadroid/mad_apk/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from apksearch.entities import PackageBase, PackageVariant
from apksearch.search import HEADERS
from apkutils.apkfile import BadZipFile, LargeZipFile
from bs4 import BeautifulSoup
from loguru import logger

from mapadroid.utils import global_variables
Expand Down Expand Up @@ -537,12 +538,13 @@ def normalize_package(self) -> NoReturn:
apk = apkutils.APK().from_io(bytes_of_apk).parse_resource()
manifest = apk.get_manifest()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like manifest is no longer used. Should be good to remove the line.

try:
self.package_version = manifest['@android:versionName']
self.package_name = manifest['@package']
soup = BeautifulSoup(manifest, 'lxml-xml')
self.package_version = soup.manifest['android:versionName']
self.package_name = soup.manifest['package']
except KeyError:
pass
try:
filename = manifest['@split']
filename = soup.manifest['@split']
if filename[-3:] == 'dpi':
continue
except KeyError:
Expand Down
9 changes: 6 additions & 3 deletions mapadroid/madmin/endpoints/api/apks/MadApkEndpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from mapadroid.mad_apk.wizard import APKWizard, PackageImporter, WizardError
from mapadroid.madmin.AbstractMadminRootEndpoint import (
AbstractMadminRootEndpoint, check_authorization_header)
from mapadroid.madmin.functions import allowed_file
from mapadroid.utils.apk_enums import APKArch, APKType
from mapadroid.utils.custom_types import MADapks

Expand All @@ -39,6 +38,10 @@ async def get(self):
except KeyError:
return await self._json_response(data=data[apk_type])

def allowed_file(self, filename):
ALLOWED_EXTENSIONS = set(['apk', 'apkm', 'zip'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is equivalent to ALLOWED_EXTENSIONS = {'apk', 'apkm', 'zip'} which is more efficient as it doesnt create a list then convert it to a set. I dont think it matters in this context though.

This should be a global variable thats initialized once and referenced instead of initialized on every call.

return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

async def post(self):
apk_type_raw: str = self.request.match_info.get('apk_type')
apk_arch_raw: str = self.request.match_info.get('apk_arch')
Expand All @@ -58,7 +61,7 @@ async def post(self):
elif not file.filename:
await self._add_notice_message('No file selected for uploading')
raise web.HTTPFound(self._url_for("upload"))
elif not allowed_file(file.filename):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is allowed_file utilized anywhere else? If not, the code should be removed to have a cleaner code base.

elif not self.allowed_file(file.filename):
await self._add_notice_message('Allowed file type is apk only!')
raise web.HTTPFound(self._url_for("upload"))
filename = secure_filename(file.filename)
Expand Down Expand Up @@ -118,7 +121,7 @@ async def handle_file_upload(self, apk: io.BytesIO, apk_arch: Optional[APKArch],
except KeyError:
return web.Response(text="Non-supported Type / Architecture", status=406)
filename_split = filename.rsplit('.', 1)
if filename_split[1] in ['zip', 'apks']:
if filename_split[1] in ['zip', 'apkm']:
mimetype = 'application/zip'
elif filename_split[1] == 'apk':
mimetype = 'application/vnd.android.package-archive'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from aiohttp import web

from loguru import logger

from mapadroid.mad_apk.utils import stream_package
from mapadroid.mitm_receiver.endpoints.AbstractMitmReceiverRootEndpoint import AbstractMitmReceiverRootEndpoint

Expand All @@ -20,6 +22,8 @@ async def head(self):
return response

async def get(self):
logger.info("Device {} downloading package {} (arch: {})", self.request.headers["origin"],
self.request.match_info.get('apk_type'), self.request.match_info.get('apk_arch'))
data_generator, response = await self.__handle_download_request()
async for data in data_generator:
await response.write(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from aiohttp import web

from loguru import logger

from mapadroid.mad_apk.utils import lookup_package_info, supported_pogo_version
from mapadroid.mitm_receiver.endpoints.AbstractMitmReceiverRootEndpoint import \
AbstractMitmReceiverRootEndpoint
Expand All @@ -20,6 +22,8 @@ class MadApkInfoEndpoint(AbstractMitmReceiverRootEndpoint):

# TODO: Auth/preprocessing for autoconfig?
async def get(self):
logger.info("Device {} checking package {} (arch: {}) version", self.request.headers["origin"],
self.request.match_info.get('apk_type'), self.request.match_info.get('apk_arch'))
parsed = self._parse_frontend()
if type(parsed) == web.Response:
return parsed
Expand Down
Loading