-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathget_package_name.py
executable file
·52 lines (45 loc) · 1.5 KB
/
get_package_name.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /usr/bin/python3
import os
import sys
import argparse
import hashlib
from androguard.core.bytecodes.apk import APK
from androguard.core import androconf
def get_package_name(apk_path):
"""
Extract the package name of an APK
"""
a = APK(apk_path)
return a.get_package(), a.get_androidversion_code()
def get_sha256(path):
"""
Get SHA256 hash of the given file
"""
m = hashlib.sha256()
with open(path, 'rb') as fin:
m.update(fin.read())
return m.hexdigest()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("PATH", help="Path to a file or folder")
args = parser.parse_args()
if os.path.isdir(args.PATH):
for f in os.listdir(args.PATH):
if os.path.isfile(f):
if androconf.is_android(os.path.join(args.PATH, f)) == 'APK':
pkg_name, pkg_version = get_package_name(os.path.join(args.PATH, f))
print('{:45} - {:20} - {}'.format(
f,
pkg_name,
pkg_version
)
)
elif os.path.isfile(args.PATH):
print("File:\t {}".format(os.path.basename(args.PATH)))
print("SHA256:\t {}".format(get_sha256(args.PATH)))
pkg_name, pkg_version = get_package_name(args.PATH)
print("Package: {}".format(pkg_name))
print("Version: {}".format(pkg_version))
else:
print("Invalid path")
sys.exit(-1)