|
1 | | -import sys, os, subprocess, ConfigParser |
| 1 | +import sys |
| 2 | +import os |
| 3 | +import subprocess |
| 4 | +import configparser |
2 | 5 | from optparse import OptionParser |
3 | 6 |
|
4 | 7 | class2jar = dict() |
5 | 8 | jars_to_process = set() |
6 | 9 |
|
7 | 10 | opt_parser = OptionParser() |
8 | 11 | opt_parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="set verbosity") |
9 | | -opt_parser.add_option("-c", "--config", dest="config", default=os.path.dirname(sys.argv[0])+"/android-jar.conf", help="configuration file path") |
| 12 | +opt_parser.add_option("-c", "--config", dest="config", default=os.path.join(os.path.dirname(sys.argv[0]), "android-jar.conf"), help="configuration file path") |
10 | 13 | (options, args) = opt_parser.parse_args() |
11 | 14 | if not os.path.isfile(options.config): |
12 | | - sys.exit('Error! No configuration file at: '+options.config) |
13 | | -config_parser = ConfigParser.SafeConfigParser() |
| 15 | + sys.exit('Error! No configuration file at: ' + options.config) |
| 16 | +config_parser = configparser.ConfigParser() |
14 | 17 | config_parser.read(options.config) |
15 | 18 | ajars_dir = config_parser.get('android-paths', 'aosp-out-dir') |
16 | 19 | stubs_jar = config_parser.get('android-paths', 'android-stubs-jar') |
|
19 | 22 | astubx_file = config_parser.get('android-model', 'astubx-path') |
20 | 23 |
|
21 | 24 | ### Finding android libraries ### |
22 | | -print "> Finding android libraries..." |
| 25 | +print("> Finding android libraries...") |
23 | 26 | # Since SDK 31, the directory structure mixes classes.jar and classes-header.jar files, we use |
24 | 27 | # only the former, as classes-header.jar files are missing methods' bytecode. |
25 | 28 | cmd = "find " + ajars_dir + " -name \"*.jar\" | grep -v classes-header.jar" |
26 | | -ajars = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout.read().splitlines() |
| 29 | +ajars = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout.read().decode().splitlines() |
27 | 30 | for ajar in ajars: |
28 | | - cmd = "jar tvf " + ajar + " | grep \"\.class$\" | awk '{print $8}'" |
29 | | - ajar_classes = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout.read().splitlines() |
| 31 | + cmd = "jar tvf " + ajar + " | grep \"\\.class$\" | awk '{print $8}'" |
| 32 | + ajar_classes = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout.read().decode().splitlines() |
30 | 33 | for ajar_class in ajar_classes: |
31 | 34 | if ajar_class in class2jar: |
32 | 35 | if options.verbose: |
33 | | - print "[Warn] Same class in multiple jars : " + ajar_class + " in " + class2jar[ajar_class] + " , " + ajar |
| 36 | + print("[Warn] Same class in multiple jars : " + ajar_class + " in " + class2jar[ajar_class] + " , " + ajar) |
34 | 37 | else: |
35 | 38 | class2jar[ajar_class] = ajar |
36 | | -cmd = "jar tvf " + stubs_jar + " | grep \"\.class$\" | awk '{print $8}'" |
37 | | -ajar_classes = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout.read().splitlines() |
| 39 | +cmd = "jar tvf " + stubs_jar + " | grep \"\\.class$\" | awk '{print $8}'" |
| 40 | +ajar_classes = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout.read().decode().splitlines() |
38 | 41 | found = 0 |
39 | 42 | for ajar_class in ajar_classes: |
40 | 43 | if ajar_class in class2jar: |
41 | 44 | found += 1 |
42 | 45 | jars_to_process.add(class2jar[ajar_class]) |
43 | 46 | else: |
44 | 47 | if options.verbose: |
45 | | - print "[Warn] Class not found in any jar : " + ajar_class |
46 | | -print ",".join(list(jars_to_process)) |
47 | | -print "Found " + str(found) + " / " + str(len(ajar_classes)) + " in " + str(len(jars_to_process)) + " jars" |
| 48 | + print("[Warn] Class not found in any jar : " + ajar_class) |
| 49 | +print(",".join(list(jars_to_process))) |
| 50 | +print("Found " + str(found) + " / " + str(len(ajar_classes)) + " in " + str(len(jars_to_process)) + " jars") |
48 | 51 |
|
49 | 52 | ### Running jarinfer ### |
50 | | -print "> Running jarinfer on android jars..." |
51 | | -cmd = "java -jar " + jarinfer + " -i " + ",".join(list(jars_to_process)) + " -o " + wrk_dir + "/" + astubx_file |
| 53 | +print("> Running jarinfer on android jars...") |
| 54 | +cmd = "java -jar " + jarinfer + " -i " + ",".join(list(jars_to_process)) + " -o " + os.path.join(wrk_dir, astubx_file) |
52 | 55 | if options.verbose: |
53 | 56 | cmd += " -dv" |
54 | | -print cmd |
| 57 | +print(cmd) |
55 | 58 | returncode = subprocess.call(cmd, shell=True) |
56 | 59 | sys.exit(returncode) |
0 commit comments