Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 63 lines (48 sloc) 1.889 kb
2c51cfe Kun Yang parsed smali files into tree structure
authored
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
9769c49 Kun Yang added some instrumentation API
authored
4 import sys
3b224ae Kun Yang Allowed running apimonitor from arbitrary directory
authored
5 import os
2c51cfe Kun Yang parsed smali files into tree structure
authored
6 import time
7 from androguard.core.bytecodes import apk
5490c17 Kun Yang Directly generate monitor's code in smali
authored
8 from apkil import smali, monitor, logger
9769c49 Kun Yang added some instrumentation API
authored
9 from subprocess import call
2c51cfe Kun Yang parsed smali files into tree structure
authored
10
3b224ae Kun Yang Allowed running apimonitor from arbitrary directory
authored
11 working_dir = sys.path[0]
12
0c9a834 Kun Yang added monitor of constructor methods
authored
13 APK = "examples/APKILTests.apk"
14 DEX = "examples/APKILTests.dex"
15 SMALI_DIR = "examples/APKILTests"
16
2c51cfe Kun Yang parsed smali files into tree structure
authored
17 NEW_OUT = "examples/new"
18 NEW_DEX = "examples/classes.dex"
19 NEW_APK = "examples/new.apk"
20
9769c49 Kun Yang added some instrumentation API
authored
21 a = apk.APK(APK)
aff4636 Kun Yang Added APIMonitor script and fixed bugs
authored
22 min_version = int(a.get_min_sdk_version())
23 target_version = int(a.get_target_sdk_version())
24
9769c49 Kun Yang added some instrumentation API
authored
25 dex_file = open(DEX, 'w')
26 dex_file.write(a.get_dex())
27 dex_file.close()
28
9040787 Kun Yang Included smali.jar and baksmali.jar
authored
29 call(args=['java', '-jar', 'smali/baksmali.jar', '-b', '-o', SMALI_DIR, DEX])
aff4636 Kun Yang Added APIMonitor script and fixed bugs
authored
30 s = smali.SmaliTree(min_version, SMALI_DIR)
31
3b224ae Kun Yang Allowed running apimonitor from arbitrary directory
authored
32 db_path = os.path.join(working_dir, "androidlib")
33
aff4636 Kun Yang Added APIMonitor script and fixed bugs
authored
34 API_LIST = [ \
35 "Landroid/net/Uri;->parse(Ljava/lang/String;)", \
36 "Landroid/content/Intent;-><init>(Ljava/lang/String;)", \
37 "Landroid/content/ContextWrapper;->openFileOutput(Ljava/lang/String;I)", \
38 "Ljava/io/OutputStreamWriter;->write(Ljava/lang/String;)", \
39 "Lapkil/tests/APKIL;->openFileInput(Ljava/lang/String;)",
cde396c Kun Yang Speeded up repackaging
authored
40 "Ljava/io/BufferedReader;->readLine()Ljava/lang/String;", \
41 "Landroid/telephony/SmsManager;->sendTextMessage(\
e095aa0 Kun Yang Fixed a bug of monitoring invoke-kind/range
authored
42 Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;\
aff4636 Kun Yang Added APIMonitor script and fixed bugs
authored
43 Landroid/app/PendingIntent;Landroid/app/PendingIntent;)", \
44 "Landroid/content/pm/PackageManager;->getInstalledApplications(I)",
0c9a834 Kun Yang added monitor of constructor methods
authored
45 ]
3b224ae Kun Yang Allowed running apimonitor from arbitrary directory
authored
46 mo = monitor.APIMonitor(db_path, API_LIST)
aff4636 Kun Yang Added APIMonitor script and fixed bugs
authored
47
48 API_CONFIG = "config/default_api_collection"
3b224ae Kun Yang Allowed running apimonitor from arbitrary directory
authored
49 mo = monitor.APIMonitor(db_path, config=API_CONFIG)
aff4636 Kun Yang Added APIMonitor script and fixed bugs
authored
50
51 s = mo.inject(s, min_version)
2c51cfe Kun Yang parsed smali files into tree structure
authored
52 s.save(NEW_OUT)
5490c17 Kun Yang Directly generate monitor's code in smali
authored
53
9040787 Kun Yang Included smali.jar and baksmali.jar
authored
54 call(args=['java', '-jar', 'smali/smali.jar', '-a', str(min_version), '-o', NEW_DEX, NEW_OUT])
2c51cfe Kun Yang parsed smali files into tree structure
authored
55
56 new_dex = open(NEW_DEX).read();
57 a.new_zip(filename=NEW_APK,
58 deleted_files="(META-INF/.)", new_files = {
59 "classes.dex" : new_dex } )
60 apk.sign_apk( NEW_APK, \
aff4636 Kun Yang Added APIMonitor script and fixed bugs
authored
61 "config/apkil.cert", "apkil", "apkilapkil" )
2c51cfe Kun Yang parsed smali files into tree structure
authored
62
Something went wrong with that request. Please try again.