Skip to content
Snippets Groups Projects
Commit 00a4c141 authored by Ximin Luo's avatar Ximin Luo
Browse files

comparators/apk: less kludgy way of detecting APKs

parent 40ea27b1
No related branches found
No related tags found
No related merge requests found
......@@ -146,10 +146,18 @@ class ApkContainer(Archive):
return differences
class ApkFile(File):
RE_FILE_TYPE = re.compile(r'^((Java|Zip) archive data|DOS/MBR boot sector).*\b')
RE_FILE_TYPE_FALLBACK_HEADER = b"PK\x03\x04"
RE_FILE_TYPE = re.compile(r'^(Java|Zip) archive data.*\b')
RE_FILE_EXTENSION = re.compile(r'\.apk$')
CONTAINER_CLASS = ApkContainer
@staticmethod
def recognizes(file):
if not ApkFile.RE_FILE_EXTENSION.search(file.name):
return False
return (ApkFile.RE_FILE_TYPE.search(file.magic_file_type) or
file.file_header[:4] == ApkFile.RE_FILE_TYPE_FALLBACK_HEADER)
def compare_details(self, other, source=None):
zipinfo_difference = Difference.from_command(Zipinfo, self.path, other.path) or \
Difference.from_command(ZipinfoVerbose, self.path, other.path)
......
......@@ -149,6 +149,13 @@ class File(object, metaclass=abc.ABCMeta):
self._magic_file_type = File.guess_file_type(self.path)
return self._magic_file_type
@property
def file_header(self):
if not hasattr(self, '_file_header'):
with open(self.path, 'rb') as f:
self._file_header = f.read(16)
return self._file_header
@property
def file_type(self):
for x, y in (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment