-
Notifications
You must be signed in to change notification settings - Fork 2
/
build
executable file
·65 lines (56 loc) · 2.28 KB
/
build
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
63
64
65
#!/usr/bin/env python3
import os
import shutil
import subprocess
import sys
import tempfile
import zipfile
if len(sys.argv) < 2:
print('Please provide path to soot-jar-with-dependencies.jar on the command line', file=sys.stderr)
sys.exit(1)
basedir = os.path.dirname(sys.argv[0]) or os.getcwd()
soot = os.path.abspath(sys.argv[1])
if 'JAVA_HOME' in os.environ:
javac = os.path.join(os.environ['JAVA_HOME'], 'bin', 'javac')
jar = os.path.join(os.environ['JAVA_HOME'], 'bin', 'jar')
else:
javac = 'javac'
jar = 'jar'
def listFiles(dir, extension):
result = []
for dirpath, dirnames, filenames in os.walk(dir):
for filename in filenames:
if os.path.splitext(filename)[1] == extension:
result.append(os.path.relpath(os.path.join(dirpath, filename), dir))
return result
classdir = tempfile.mkdtemp()
try:
source_dir = os.path.join(basedir, 'src')
sources = listFiles(source_dir, '.java')
subprocess.check_call([
javac, '-d', classdir,
'-Xlint:unchecked,deprecation',
'-sourcepath', '.',
os.path.join('info', 'palant', 'apkInstrumentation', 'Main.java')
], cwd=source_dir, env={'CLASSPATH': soot})
# Use Java 1.7 compile target for injected classes, avoid constructs that
# Android verifier will reject.
subprocess.check_call([
javac, '-d', classdir,
'-source', '1.7', '-target', '1.7',
'-Xlint:unchecked,deprecation',
'-sourcepath', '.',
os.path.join('info', 'palant', 'apkInstrumentation', 'LoggingInputStream.java'),
os.path.join('info', 'palant', 'apkInstrumentation', 'LoggingOutputStream.java')
], cwd=source_dir, env={'CLASSPATH': soot})
outfile = os.path.abspath(os.path.join(basedir, 'apk-instrumentation.jar'))
classes = listFiles(classdir, '.class')
manifest_path = os.path.abspath(os.path.join(source_dir, 'Manifest.txt'))
subprocess.check_call([jar, 'cfm', outfile, manifest_path, *classes], cwd=classdir)
finally:
shutil.rmtree(classdir)
with zipfile.ZipFile(soot, 'r') as archive_in:
with zipfile.ZipFile(outfile, 'a') as archive_out:
for entry in archive_in.infolist():
if not entry.filename.startswith('META-INF/'):
archive_out.writestr(entry, archive_in.read(entry))