Skip to content

Commit

Permalink
Removes internet download of app icon (#41)
Browse files Browse the repository at this point in the history
* Remove icon download from internet from core
  • Loading branch information
pnu-s authored Jun 28, 2020
1 parent 9dae650 commit e145fc0
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 36 deletions.
35 changes: 2 additions & 33 deletions exodus_core/analysis/static_analysis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from bs4 import BeautifulSoup
from collections import namedtuple
from cryptography.x509.name import _SENTINEL, ObjectIdentifier, _NAMEOID_DEFAULT_TYPE, _ASN1Type, NameAttribute
from hashlib import sha256, sha1
Expand Down Expand Up @@ -323,30 +322,6 @@ def _get_icon_from_details(self, path):

raise Exception('Unable to download the icon from details')

def _get_icon_from_gplay(self, handle, path):
"""
Download the application icon from Google Play website
:param handle: application handle
:param path: file to be saved
:return: path of the saved icon
:raises Exception: if unable to download icon
"""
address = 'https://play.google.com/store/apps/details?id=%s' % handle
gplay_page_content = requests.get(address).text
soup = BeautifulSoup(gplay_page_content, 'html.parser')
icon_images = soup.find_all('img', {'alt': 'Cover art'})
if len(icon_images) > 0:
icon_url = '{}'.format(icon_images[0]['src'])
if not icon_url.startswith('http'):
icon_url = 'https:{}'.format(icon_url)
f = requests.get(icon_url)
with open(path, mode='wb') as fp:
fp.write(f.content)
if os.path.isfile(path) and os.path.getsize(path) > 0:
return path
else:
raise Exception('Unable to download the icon from GPlay')

@staticmethod
def _render_drawable_to_png(self, bxml, path):
ap = axml.AXMLPrinter(bxml)
Expand All @@ -370,6 +345,8 @@ def save_icon(self, path):
return path
except Exception:
logging.warning('Unable to get the icon from the APK')
return None

# TODO: Set this back once details download is working again
# logging.warning('Downloading icon from details')
# try:
Expand All @@ -378,14 +355,6 @@ def save_icon(self, path):
# return saved_path
# except Exception as e:
# logging.warning(e)
logging.warning('Downloading icon from Google Play')
try:
saved_path = self._get_icon_from_gplay(self.get_package(), path)
logging.debug('Icon downloaded from Google Play')
return saved_path
except Exception as e:
logging.error(e)
return None

def get_icon_phash(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion exodus_core/analysis/test_exodus_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_trackers_list(self):
self.assertGreater(len(sa.signatures), 70)

def test_icon_phash_greater_than_zero(self):
apps = ['nextcloud', 'francetv']
apps = ['francetv']
for app in apps:
with self.subTest(app=app):
icon_phash = phash('./apks/{}.apk'.format(app))
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ androguard==3.3.5
args==0.1.0
asn1crypto==0.24.0
backcall==0.1.0
beautifulsoup4==4.6.0
certifi==2019.3.9
cffi==1.12.3
chardet==3.0.4
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def is_exe(fpath):
'protobuf==3.11.0',
"jellyfish==0.5.6",
'cryptography==2.6.1',
"beautifulsoup4==4.6.0",
'androguard==3.3.5'
]

Expand Down

0 comments on commit e145fc0

Please sign in to comment.