-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from apkutils.axml.axmlparser import AXML | ||
from asn1crypto.cms import ContentInfo | ||
from zipfile import ZipFile | ||
|
||
class ApkParser: | ||
def __init__(self, file): | ||
self._file = ZipFile(file) | ||
|
||
def getManifest(self): | ||
return AXML(self._file.read('AndroidManifest.xml')).get_xml_obj() | ||
|
||
def getPackageName(self): | ||
return self.getManifest().documentElement.getAttribute('package') | ||
|
||
def getVersionCode(self): | ||
return int(self.getManifest().documentElement.getAttribute('android:versionCode')) | ||
|
||
def getVersionName(self): | ||
return self.getManifest().documentElement.getAttribute('android:versionName') | ||
|
||
def getMinSdkVersion(self): | ||
return int(self.getManifest().documentElement.getElementsByTagName('uses-sdk')[0].getAttribute('android:minSdkVersion')) | ||
|
||
def _getCerts(self): | ||
for info in self._file.infolist(): | ||
if info.filename.startswith('META-INF/') and info.filename.endswith('.RSA'): | ||
for cert in ContentInfo.load(self._file.read(info))['content']['certificates']: | ||
yield cert.dump() | ||
|
||
def getCert(self): | ||
certs = list(self._getCerts()) | ||
if len(certs) != 1: | ||
raise Exception('Cannot read certificate') | ||
return certs[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
apkutils | ||
asn1crypto | ||
certifi | ||
comtypes==1.1.3-2 | ||
pycryptodomex | ||
|