-
Notifications
You must be signed in to change notification settings - Fork 0
/
signAndroid.py
executable file
·64 lines (52 loc) · 2.76 KB
/
signAndroid.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
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python2.7
import argparse;
import signApks;
from WillirPy2_7Utils import argarsePathFileRoType, getAndAssertApkList, ArgsAndroidSystemDir;
from signApks import SignBehavior, signListOfApk;
from certUniqPrint import getDictApkCertsWithInfo
def signAndroidBySignsMap(signsMap, certPath, storePass, keyPass):
'''
Signs all apk specified (by signsMap) files in android.
@param signsMap: Apk files and them signs which will be resigned.
dict{str(sign) => dict {str(apk.package.name) => str(/path/to/apk)} }
Results of certUniquePrint.getDictApkCertsWithInfo method.
@param certPath: Path to jks certificate store by which apk files will be signed.
@param storePass: Password from certificate store.
@param keyPass: Password from all certificate in store.
'''
behavior = SignBehavior.FORCE;
for cert in signsMap.iterkeys():
alias = __getAliasNameByPackageSet(set(signsMap[cert].keys()))
apkList = signsMap[cert].values();
signListOfApk(apkList, certPath, alias, storePass, keyPass, behavior);
def signAndroid(systemPath, certPath, storePass, keyPass):
apkList = getAndAssertApkList(args.systemPath, recursive=True, withSign=False);
signsMap = getDictApkCertsWithInfo(apkList);
signAndroidBySignsMap(signsMap, certPath, storePass, keyPass);
def __getAliasNameByPackageSet(packageSet):
packToAliasDict = {'android' : 'platform',
'com.android.providers.media' : 'media',
'com.android.launcher' : 'shared'};
matchApkSet = set(packToAliasDict.keys()) & packageSet;
if len(matchApkSet) > 1:
raise RuntimeError("More than one package match to packageSet.\n" \
"intersect:" + matchApkSet + "\n"\
"packageSet:" + packageSet);
elif not matchApkSet:
return 'other';
else:
return packToAliasDict[matchApkSet.pop()];
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Signs all apk files in android.");
parser.add_argument("--store", type=argarsePathFileRoType, required=True,
help="Path to key store");
parser.add_argument("--store-pass", type=str, dest="storePass",
help="Password for key store");
parser.add_argument("--alias-pass", type=str, dest="aliasPass",
help="Password for key in key store");
parser.add_argument("systemPath", action=ArgsAndroidSystemDir,
help="Path to android system folder.");
args = parser.parse_args();
storePass, keyPass = signApks.getPasses(args);
signAndroid(systemPath=args.systemPath, certPath=args.store,
storePass=storePass, keyPass=keyPass)