Mercurial > paraspace
annotate paraspace/tests/injection_test.py @ 137:987fead83ce3
Fix issue that dalvik complaining fail to verify code.
- Since order of typeId and methodId are changed, index values in
code block of methods are invalid after sorting sorted arrays.
- We add dex_sort_sorted_arrays_consistent() function as a wrapper
of dex_sort_sorted_arrays(). It remap indices mentioned in code
blocks after sorting.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 10 Aug 2011 14:04:02 +0800 |
parents | f31bfe55d9c2 |
children | 372009418896 |
rev | line source |
---|---|
90
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1 from paraspace import dexfile |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
2 import os |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
3 |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
4 def _install_dexfile_4_deptracker(): |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
5 global dexfile |
93
2fa9b6f21344
Add DEXFile_linked to model linked DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
92
diff
changeset
|
6 import imp, sys |
90
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
7 from paraspace import dex_deptracker |
105
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
8 from paraspace import injection |
90
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
9 |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
10 try: |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
11 new_dexfile = imp.load_compiled('dexfile', dexfile.__file__) |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
12 except ImportError: |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
13 new_dexfile = imp.load_source('dexfile', dexfile.__file__) |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
14 pass |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
15 dex_deptracker.dexfile = new_dexfile |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
16 dexfile = new_dexfile |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
17 dex_deptracker._nest_types = (dexfile.array, dexfile.cond, dexfile.switch) |
105
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
18 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
19 injection.dex_type_2_array_attr_map = \ |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
20 injection._saved_dex_type_2_array_attr_map |
93
2fa9b6f21344
Add DEXFile_linked to model linked DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
92
diff
changeset
|
21 |
2fa9b6f21344
Add DEXFile_linked to model linked DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
92
diff
changeset
|
22 sys.modules['paraspace.dexfile'] = new_dexfile |
90
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
23 pass |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
24 |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
25 |
98
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
26 def _find_map(dex, map_type): |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
27 for map in dex.maps.items.items: |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
28 if map.type == map_type: |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
29 return map |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
30 pass |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
31 pass |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
32 |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
33 |
90
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
34 def inject_fakefile_to_helloworld_test(): |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
35 from paraspace.dex_deptracker import prepare_dep_decls |
96
1769e52bdd9d
Make dexfile_insert_class() pass the testcase
Thinker K.F. Li <thinker@codemud.net>
parents:
95
diff
changeset
|
36 from paraspace.injection import dexfile_insert_class |
90
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
37 |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
38 _install_dexfile_4_deptracker() |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
39 |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
40 all_dep_decls = prepare_dep_decls() |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
41 |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
42 srcdir = os.path.dirname(__file__) |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
43 srcroot = os.path.join(srcdir, '..', '..') |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
44 |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
45 helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex') |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
46 helloworld_dex = dexfile.DEXFile.open(helloworld_fn) |
98
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
47 |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
48 classdef_map = _find_map(helloworld_dex, 0x0006) |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
49 saved_classdef_map_sz = classdef_map.size |
100
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
50 saved_methodids_sz = len(helloworld_dex.methodIds.items) |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
51 |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
52 codeitems_map = _find_map(helloworld_dex, 0x2001) |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
53 saved_codeitems_sz = codeitems_map.size |
98
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
54 |
93
2fa9b6f21344
Add DEXFile_linked to model linked DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
92
diff
changeset
|
55 helloworld_linked = \ |
2fa9b6f21344
Add DEXFile_linked to model linked DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
92
diff
changeset
|
56 dexfile.DEXFile_linked.build_dependencies(helloworld_dex, |
2fa9b6f21344
Add DEXFile_linked to model linked DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
92
diff
changeset
|
57 all_dep_decls) |
90
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
58 |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
59 fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex') |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
60 fakefile_dex = dexfile.DEXFile.open(fakefile_fn) |
93
2fa9b6f21344
Add DEXFile_linked to model linked DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
92
diff
changeset
|
61 fakefile_linked = \ |
95
9373465643e0
Fix bug of DEXFile_linked.get_classdef_name
Thinker K.F. Li <thinker@codemud.net>
parents:
93
diff
changeset
|
62 dexfile.DEXFile_linked. \ |
9373465643e0
Fix bug of DEXFile_linked.get_classdef_name
Thinker K.F. Li <thinker@codemud.net>
parents:
93
diff
changeset
|
63 build_dependencies(fakefile_dex, all_dep_decls) |
9373465643e0
Fix bug of DEXFile_linked.get_classdef_name
Thinker K.F. Li <thinker@codemud.net>
parents:
93
diff
changeset
|
64 |
9373465643e0
Fix bug of DEXFile_linked.get_classdef_name
Thinker K.F. Li <thinker@codemud.net>
parents:
93
diff
changeset
|
65 fakefile_def = fakefile_linked. \ |
9373465643e0
Fix bug of DEXFile_linked.get_classdef_name
Thinker K.F. Li <thinker@codemud.net>
parents:
93
diff
changeset
|
66 find_class_name('Lcom/codemud/fakefile/fakefile;') |
96
1769e52bdd9d
Make dexfile_insert_class() pass the testcase
Thinker K.F. Li <thinker@codemud.net>
parents:
95
diff
changeset
|
67 |
100
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
68 fakefile_data = fakefile_def.classDataOffRef.value |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
69 assert len(fakefile_data.directMethods.items) == 1 |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
70 assert len(fakefile_data.virtualMethods.items) == 0 |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
71 fakefile_dataheader = fakefile_data.header |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
72 assert fakefile_dataheader.directMethodsSize == 1 |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
73 assert fakefile_dataheader.virtualMethodsSize == 0 |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
74 |
98
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
75 clone = dexfile_insert_class(helloworld_linked, fakefile_def) |
96
1769e52bdd9d
Make dexfile_insert_class() pass the testcase
Thinker K.F. Li <thinker@codemud.net>
parents:
95
diff
changeset
|
76 assert clone |
1769e52bdd9d
Make dexfile_insert_class() pass the testcase
Thinker K.F. Li <thinker@codemud.net>
parents:
95
diff
changeset
|
77 assert clone != fakefile_def |
97
00cd331f8aa8
Get unlinked one from a linked one
Thinker K.F. Li <thinker@codemud.net>
parents:
96
diff
changeset
|
78 |
00cd331f8aa8
Get unlinked one from a linked one
Thinker K.F. Li <thinker@codemud.net>
parents:
96
diff
changeset
|
79 helloworld_unlinked = helloworld_linked.get_unlinked() |
00cd331f8aa8
Get unlinked one from a linked one
Thinker K.F. Li <thinker@codemud.net>
parents:
96
diff
changeset
|
80 assert helloworld_unlinked |
98
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
81 |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
82 # map size for classdef must be increased by 1 |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
83 classdef_map = _find_map(helloworld_unlinked, 0x0006) |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
84 assert classdef_map.size == saved_classdef_map_sz + 1 |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
85 |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
86 classdata_map = _find_map(helloworld_unlinked, 0x2000) |
c0c127c7b37e
Check and fix issues of map sizes
Thinker K.F. Li <thinker@codemud.net>
parents:
97
diff
changeset
|
87 assert classdata_map.size == classdef_map.size |
99
3898711adb2c
Make sure string data list is consistent.
Thinker K.F. Li <thinker@codemud.net>
parents:
98
diff
changeset
|
88 |
3898711adb2c
Make sure string data list is consistent.
Thinker K.F. Li <thinker@codemud.net>
parents:
98
diff
changeset
|
89 # Check strings |
3898711adb2c
Make sure string data list is consistent.
Thinker K.F. Li <thinker@codemud.net>
parents:
98
diff
changeset
|
90 strdatas = helloworld_unlinked.stringDataItems.items |
3898711adb2c
Make sure string data list is consistent.
Thinker K.F. Li <thinker@codemud.net>
parents:
98
diff
changeset
|
91 strs = sorted([strdata.data.data for strdata in strdatas]) |
3898711adb2c
Make sure string data list is consistent.
Thinker K.F. Li <thinker@codemud.net>
parents:
98
diff
changeset
|
92 assert len(strs) == len(set(strs)) # uniquely |
3898711adb2c
Make sure string data list is consistent.
Thinker K.F. Li <thinker@codemud.net>
parents:
98
diff
changeset
|
93 assert 'Lcom/codemud/fakefile/fakefile;' in strs |
100
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
94 |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
95 # Check Method List |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
96 methodids_map = _find_map(helloworld_unlinked, 0x0005) # method ids |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
97 assert methodids_map.size == len(helloworld_unlinked.methodIds.items) |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
98 assert methodids_map.size == saved_methodids_sz + 1 |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
99 |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
100 # Check Code item List |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
101 codeitems_map = _find_map(helloworld_unlinked, 0x2001) |
355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
Thinker K.F. Li <thinker@codemud.net>
parents:
99
diff
changeset
|
102 assert codeitems_map.size == saved_codeitems_sz + 1 |
90
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
103 pass |
fe7b3f111d57
Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
104 |
105
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
105 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
106 def redirect_types_test(): |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
107 from paraspace.dex_deptracker import prepare_dep_decls |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
108 from paraspace.injection import dexfile_insert_class |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
109 from paraspace.injection import dexfile_redirect_types |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
110 from paraspace.injection import make_methodidxs_redir_map |
105
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
111 from paraspace import dalvik_opcodes |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
112 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
113 _install_dexfile_4_deptracker() |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
114 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
115 all_dep_decls = prepare_dep_decls() |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
116 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
117 srcdir = os.path.dirname(__file__) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
118 srcroot = os.path.join(srcdir, '..', '..') |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
119 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
120 helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex') |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
121 helloworld_dex = dexfile.DEXFile.open(helloworld_fn) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
122 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
123 classdef_map = _find_map(helloworld_dex, 0x0006) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
124 saved_classdef_map_sz = classdef_map.size |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
125 saved_methodids_sz = len(helloworld_dex.methodIds.items) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
126 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
127 codeitems_map = _find_map(helloworld_dex, 0x2001) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
128 saved_codeitems_sz = codeitems_map.size |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
129 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
130 helloworld_linked = \ |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
131 dexfile.DEXFile_linked.build_dependencies(helloworld_dex, |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
132 all_dep_decls) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
133 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
134 fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex') |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
135 fakefile_dex = dexfile.DEXFile.open(fakefile_fn) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
136 fakefile_linked = \ |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
137 dexfile.DEXFile_linked. \ |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
138 build_dependencies(fakefile_dex, all_dep_decls) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
139 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
140 fakefile_def = \ |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
141 fakefile_linked.find_class_name('Lcom/codemud/fakefile/fakefile;') |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
142 clone = dexfile_insert_class(helloworld_linked, fakefile_def) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
143 |
107
4b3573d039af
Fix bug of DEXFile_linked.find_method_name_proto().
Thinker K.F. Li <thinker@codemud.net>
parents:
106
diff
changeset
|
144 init_method = fakefile_linked.find_method_name('<init>', fakefile_def) |
4b3573d039af
Fix bug of DEXFile_linked.find_method_name_proto().
Thinker K.F. Li <thinker@codemud.net>
parents:
106
diff
changeset
|
145 init_protoid = init_method.methodIdx.protoIdx |
4b3573d039af
Fix bug of DEXFile_linked.find_method_name_proto().
Thinker K.F. Li <thinker@codemud.net>
parents:
106
diff
changeset
|
146 |
105
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
147 File_typeid = helloworld_linked.find_typeid_name('Ljava/io/File;') |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
148 assert File_typeid |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
149 File_typeidx = helloworld_linked.get_idx_typeid(File_typeid) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
150 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
151 clone_typeidx = helloworld_linked.get_idx_typeid(clone.classIdx) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
152 |
113
ee13c86d84f2
Let user specify redirection map for methods
Thinker K.F. Li <thinker@codemud.net>
parents:
111
diff
changeset
|
153 types_redir = {File_typeidx: clone_typeidx} |
105
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
154 excludes = set([clone_typeidx]) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
155 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
156 fakefile_data = clone.classDataOffRef.value |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
157 fakefile_methods = fakefile_data.directMethods.items |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
158 fakefile_codes = [method.codeOffRef.value for method in fakefile_methods] |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
159 |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
160 methods_redir = make_methodidxs_redir_map(helloworld_linked, |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
161 helloworld_linked, |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
162 types_redir) |
113
ee13c86d84f2
Let user specify redirection map for methods
Thinker K.F. Li <thinker@codemud.net>
parents:
111
diff
changeset
|
163 dexfile_redirect_types(helloworld_linked, types_redir, |
ee13c86d84f2
Let user specify redirection map for methods
Thinker K.F. Li <thinker@codemud.net>
parents:
111
diff
changeset
|
164 methods_redir, excludes) |
105
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
165 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
166 for code in helloworld_linked.codeItems.items: |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
167 op_vectors = dalvik_opcodes.decode_insn_blk(code.insns.data) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
168 for opcode, args in op_vectors: |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
169 if opcode == dalvik_opcodes.all_opcodes.OP_NEW_INSTANCE: |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
170 assert args[1] != File_typeidx |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
171 pass |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
172 elif opcode == dalvik_opcodes.all_opcodes.OP_INVOKE_DIRECT: |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
173 methodid = helloworld_linked.find_methodid_idx(args[2]) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
174 assert methodid.classIdx != File_typeid or \ |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
175 code in fakefile_codes |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
176 pass |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
177 pass |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
178 pass |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
179 pass |
109
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
180 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
181 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
182 def collect_types_in_method_test(): |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
183 from paraspace.dex_deptracker import prepare_dep_decls |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
184 from paraspace.injection import collect_typeidxs_in_method |
110
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
185 from paraspace.injection import collect_typeidxs_mentioned_by_class |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
186 from paraspace.dexfile import DEXFile_linked |
109
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
187 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
188 _install_dexfile_4_deptracker() |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
189 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
190 all_dep_decls = prepare_dep_decls() |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
191 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
192 srcdir = os.path.dirname(__file__) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
193 srcroot = os.path.join(srcdir, '..', '..') |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
194 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
195 fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex') |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
196 fakefile_dex = dexfile.DEXFile.open(fakefile_fn) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
197 fakefile_linked = \ |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
198 dexfile.DEXFile_linked. \ |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
199 build_dependencies(fakefile_dex, all_dep_decls) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
200 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
201 fakefile_def = \ |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
202 fakefile_linked.find_class_name('Lcom/codemud/fakefile/fakefile;') |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
203 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
204 init_method = fakefile_linked.find_method_name('<init>', fakefile_def) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
205 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
206 typeidxs = collect_typeidxs_in_method(fakefile_linked, init_method) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
207 assert len(typeidxs) == 1 |
110
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
208 |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
209 typeid = fakefile_linked.find_typeid_idx(typeidxs[0]) |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
210 typeid_name = DEXFile_linked.get_typeid_name(typeid) |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
211 assert typeid_name == 'Ljava/io/File;' |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
212 |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
213 typeidxs = collect_typeidxs_mentioned_by_class(fakefile_linked, |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
214 fakefile_def) |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
215 assert len(typeidxs) == 1 |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
216 |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
217 typeid = fakefile_linked.find_typeid_idx(typeidxs[0]) |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
218 typeid_name = DEXFile_linked.get_typeid_name(typeid) |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
219 assert typeid_name == 'Ljava/io/File;' |
109
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
220 pass |
111
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
221 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
222 |
114
867184e01852
Change interface of dexfile_insert_classdefs_relative
Thinker K.F. Li <thinker@codemud.net>
parents:
113
diff
changeset
|
223 def dexfile_insert_classdefs_relative_test(): |
111
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
224 from paraspace.dex_deptracker import prepare_dep_decls |
114
867184e01852
Change interface of dexfile_insert_classdefs_relative
Thinker K.F. Li <thinker@codemud.net>
parents:
113
diff
changeset
|
225 from paraspace.injection import dexfile_insert_classdefs_relative |
111
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
226 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
227 _install_dexfile_4_deptracker() |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
228 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
229 all_dep_decls = prepare_dep_decls() |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
230 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
231 srcdir = os.path.dirname(__file__) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
232 srcroot = os.path.join(srcdir, '..', '..') |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
233 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
234 helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex') |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
235 helloworld_dex = dexfile.DEXFile.open(helloworld_fn) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
236 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
237 classdef_map = _find_map(helloworld_dex, 0x0006) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
238 saved_classdef_map_sz = classdef_map.size |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
239 saved_methodids_sz = len(helloworld_dex.methodIds.items) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
240 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
241 codeitems_map = _find_map(helloworld_dex, 0x2001) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
242 saved_codeitems_sz = codeitems_map.size |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
243 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
244 helloworld_linked = \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
245 dexfile.DEXFile_linked.build_dependencies(helloworld_dex, |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
246 all_dep_decls) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
247 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
248 fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex') |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
249 fakefile_dex = dexfile.DEXFile.open(fakefile_fn) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
250 fakefile_linked = \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
251 dexfile.DEXFile_linked. \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
252 build_dependencies(fakefile_dex, all_dep_decls) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
253 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
254 fakefile_def = fakefile_linked. \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
255 find_class_name('Lcom/codemud/fakefile/fakefile;') |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
256 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
257 fakefile_data = fakefile_def.classDataOffRef.value |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
258 assert len(fakefile_data.directMethods.items) == 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
259 assert len(fakefile_data.virtualMethods.items) == 0 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
260 fakefile_dataheader = fakefile_data.header |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
261 assert fakefile_dataheader.directMethodsSize == 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
262 assert fakefile_dataheader.virtualMethodsSize == 0 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
263 |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
264 classdefs, typeids = dexfile_insert_classdefs_relative(helloworld_linked, |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
265 fakefile_linked, |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
266 [fakefile_def]) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
267 assert classdefs |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
268 assert len(classdefs) == 1 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
269 assert classdefs[0] != fakefile_def |
111
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
270 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
271 helloworld_unlinked = helloworld_linked.get_unlinked() |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
272 assert helloworld_unlinked |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
273 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
274 # map size for classdef must be increased by 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
275 classdef_map = _find_map(helloworld_unlinked, 0x0006) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
276 assert classdef_map.size == saved_classdef_map_sz + 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
277 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
278 classdata_map = _find_map(helloworld_unlinked, 0x2000) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
279 assert classdata_map.size == classdef_map.size |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
280 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
281 # Check strings |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
282 strdatas = helloworld_unlinked.stringDataItems.items |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
283 strs = sorted([strdata.data.data for strdata in strdatas]) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
284 assert len(strs) == len(set(strs)) # uniquely |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
285 assert 'Lcom/codemud/fakefile/fakefile;' in strs |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
286 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
287 # Check Method List |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
288 methodids_map = _find_map(helloworld_unlinked, 0x0005) # method ids |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
289 assert methodids_map.size == len(helloworld_unlinked.methodIds.items) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
290 assert methodids_map.size == saved_methodids_sz + 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
291 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
292 # Check Code item List |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
293 codeitems_map = _find_map(helloworld_unlinked, 0x2001) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
294 assert codeitems_map.size == saved_codeitems_sz + 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
295 pass |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
296 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
297 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
298 def inject_classdefs_test(): |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
299 from paraspace.dex_deptracker import prepare_dep_decls |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
300 from paraspace.injection import inject_classdefs |
118 | 301 from paraspace.injection import make_methodidxs_redir_map |
302 from paraspace.injection import dexfile_redirect_types | |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
303 from paraspace import dalvik_opcodes |
116
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
304 from paraspace.dexfile import DEXFile_linked |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
305 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
306 _install_dexfile_4_deptracker() |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
307 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
308 all_dep_decls = prepare_dep_decls() |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
309 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
310 srcdir = os.path.dirname(__file__) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
311 srcroot = os.path.join(srcdir, '..', '..') |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
312 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
313 helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex') |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
314 helloworld_dex = dexfile.DEXFile.open(helloworld_fn) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
315 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
316 classdef_map = _find_map(helloworld_dex, 0x0006) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
317 saved_classdef_map_sz = classdef_map.size |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
318 saved_methodids_sz = len(helloworld_dex.methodIds.items) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
319 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
320 codeitems_map = _find_map(helloworld_dex, 0x2001) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
321 saved_codeitems_sz = codeitems_map.size |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
322 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
323 helloworld_linked = \ |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
324 dexfile.DEXFile_linked.build_dependencies(helloworld_dex, |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
325 all_dep_decls) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
326 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
327 fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex') |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
328 fakefile_dex = dexfile.DEXFile.open(fakefile_fn) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
329 fakefile_linked = \ |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
330 dexfile.DEXFile_linked. \ |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
331 build_dependencies(fakefile_dex, all_dep_decls) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
332 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
333 fakefile_def = \ |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
334 fakefile_linked.find_class_name('Lcom/codemud/fakefile/fakefile;') |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
335 clonings = inject_classdefs(helloworld_linked, fakefile_linked, |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
336 [fakefile_def]) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
337 assert clonings |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
338 assert len(clonings) == 1 |
116
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
339 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
340 fakefile_cloning = clonings[0] |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
341 method = helloworld_linked.find_method_name('<init>', fakefile_cloning) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
342 assert isinstance(method, dexfile._DEX_Method) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
343 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
344 V_typeid = helloworld_linked.find_typeid_name('V') |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
345 file_typeid = helloworld_linked.find_typeid_name('Ljava/io/File;') |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
346 file_typeidx = helloworld_linked.get_idx_typeid(file_typeid) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
347 str_typeid = helloworld_linked.find_typeid_name('Ljava/lang/String;') |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
348 protoid = DEXFile_linked.make_protoid(V_typeid, |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
349 (file_typeid, str_typeid)) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
350 initid = helloworld_linked.find_methodid_name_proto('<init>', |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
351 protoid, |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
352 file_typeid) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
353 initidx = helloworld_linked.get_idx_methodid(initid) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
354 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
355 insns_block = DEXFile_linked.get_code_block_method(method) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
356 opvectors = dalvik_opcodes.decode_insn_blk(insns_block) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
357 assert len(opvectors) == 2 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
358 opvector = opvectors[0] |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
359 args = opvector[1] |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
360 assert args[2] == initidx |
118 | 361 |
362 fakefile_typeidx = \ | |
363 helloworld_linked.get_idx_typeid(fakefile_cloning.classIdx) | |
364 typeidxs_redir_map = {file_typeidx: fakefile_typeidx} | |
365 methodidxs_redir_map = \ | |
366 make_methodidxs_redir_map(helloworld_linked, \ | |
367 helloworld_linked, \ | |
368 typeidxs_redir_map) | |
369 dexfile_redirect_types(helloworld_linked, typeidxs_redir_map, | |
370 methodidxs_redir_map, excludes=[fakefile_typeidx]) | |
371 | |
372 cloning_initdef = \ | |
373 helloworld_linked.find_method_name_proto('<init>', \ | |
374 protoid, \ | |
375 fakefile_cloning) | |
376 fakefile_codes = [cloning_initdef.codeOffRef.value] | |
377 for code in helloworld_linked.codeItems.items: | |
378 op_vectors = dalvik_opcodes.decode_insn_blk(code.insns.data) | |
379 for opcode, args in op_vectors: | |
380 if opcode == dalvik_opcodes.all_opcodes.OP_NEW_INSTANCE: | |
381 assert args[1] != file_typeidx | |
382 pass | |
383 elif opcode == dalvik_opcodes.all_opcodes.OP_INVOKE_DIRECT: | |
384 methodid = helloworld_linked.find_methodid_idx(args[2]) | |
385 assert methodid.classIdx != file_typeid or \ | |
386 code in fakefile_codes | |
387 pass | |
388 pass | |
389 pass | |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
390 pass |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
391 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
392 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
393 ## \brief Test case for error of verifing data map. |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
394 # |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
395 # The output of inject_redir.py is not accepted by dalvik with following |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
396 # error messages. |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
397 # \pre |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
398 # E/dalvikvm( 302): Unexpected data map entry @ 0x930: expected 1001, \ |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
399 # found 2006 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
400 # E/dalvikvm( 302): Trouble with item 0 @ offset 0x25c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
401 # E/dalvikvm( 302): Cross-item verify of section type 0003 failed |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
402 # E/dalvikvm( 302): ERROR: Byte swap + verify failed |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
403 # E/dalvikvm( 302): Optimization failed |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
404 # |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
405 # The data map printed by paraspace.dexfile is |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
406 # \pre |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
407 # 0x0000(kDexTypeHeaderItem) size=1 offset=0x00000000 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
408 # 0x0001(kDexTypeStringIdItem) size=92 offset=0x00000070 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
409 # 0x0002(kDexTypeTypeIdItem) size=31 offset=0x000001e0 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
410 # 0x0003(kDexTypeProtoIdItem) size=18 offset=0x0000025c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
411 # 0x0004(kDexTypeFieldIdItem) size=7 offset=0x00000334 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
412 # 0x0005(kDexTypeMethodIdItem) size=36 offset=0x0000036c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
413 # 0x0006(kDexTypeClassDefItem) size=10 offset=0x0000048c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
414 # 0x1003(kDexTypeAnnotationSetItem) size=7 offset=0x000005cc |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
415 # 0x2001(kDexTypeCodeItem) size=17 offset=0x0000061c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
416 # 0x2006(kDexTypeAnnotationsDirectoryItem) size=7 offset=0x00000910 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
417 # 0x1001(kDexTypeTypeList) size=12 offset=0x00000980 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
418 # 0x2002(kDexTypeStringDataItem) size=92 offset=0x000009e2 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
419 # 0x2003(kDexTypeDebugInfoItem) size=17 offset=0x00000f05 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
420 # 0x2004(kDexTypeAnnotationItem) size=9 offset=0x00000fc1 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
421 # 0x2005(kDexTypeEncodedArrayItem) size=5 offset=0x00001012 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
422 # 0x2000(kDexTypeClassDataItem) size=10 offset=0x0000102d |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
423 # 0x1000(kDexTypeMapList) size=1 offset=0x000010c0 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
424 # |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
425 # It is possible restore_dependencies() does not following \ref ref |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
426 # object to set offset value on referenced attribute. |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
427 # |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
428 # It is also possible dexfile_insert_classdefs_relative() does not |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
429 # put injected objects into lists properly. |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
430 # |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
431 def map_verify_error_test(): |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
432 from paraspace.dex_deptracker import prepare_dep_decls |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
433 from paraspace.injection import inject_redir |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
434 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
435 _install_dexfile_4_deptracker() |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
436 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
437 all_dep_decls = prepare_dep_decls() |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
438 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
439 srcdir = os.path.dirname(__file__) |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
440 datapath = os.path.join(srcdir, '..', '..', 'data') |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
441 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
442 fake_path = os.path.join(datapath, 'fakefile.dex') |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
443 hello_path = os.path.join(datapath, 'helloworld.dex') |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
444 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
445 fake_dex = dexfile.DEXFile.open(fake_path) |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
446 fake_linked = dexfile.DEXFile_linked.build_dependencies(fake_dex, |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
447 all_dep_decls) |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
448 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
449 hello_dex = dexfile.DEXFile.open(hello_path) |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
450 hello_linked = dexfile.DEXFile_linked.build_dependencies(hello_dex, |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
451 all_dep_decls) |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
452 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
453 inject_redir(fake_linked, 'Lcom/codemud/fakefile/fakefile;', |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
454 hello_linked, 'Ljava/io/File;', all_dep_decls) |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
455 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
456 for idx, item in enumerate(hello_linked.maps.items.items): |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
457 if item.type == dexfile._DEX_MapItem.name_to_types['kDexTypeTypeList']: |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
458 break |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
459 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
460 else: |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
461 assert False |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
462 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
463 typelist_start = item.offset |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
464 next_item = hello_linked.maps.items.items[idx + 1] |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
465 typelist_stop = next_item.offset |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
466 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
467 for idx, protoid in enumerate(hello_linked.protoIds.items): |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
468 off = protoid.parametersOff |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
469 try: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
470 if off != 0: |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
471 assert off >= typelist_start |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
472 assert off < typelist_stop |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
473 pass |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
474 pass |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
475 except: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
476 print 'ERROR: protoid idx@%d %s 0x%x' % (idx, repr(protoid), off) |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
477 print 'start 0x%x stop 0x%x' % (typelist_start, typelist_stop) |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
478 raise |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
479 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
480 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
481 for idx, classdef in enumerate(hello_linked.classDefs.items): |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
482 off = classdef.interfacesOff |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
483 try: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
484 if off != 0: |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
485 assert off >= typelist_start |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
486 assert off < typelist_stop |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
487 pass |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
488 pass |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
489 except: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
490 print 'ERROR: classdef idx@%d %s 0x%x' % (idx, repr(classdef), off) |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
491 print 'start 0x%x stop 0x%x' % (typelist_start, typelist_stop) |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
492 raise |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
493 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
494 pass |
135
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
495 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
496 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
497 ## \brief Test case for protoid out of order. |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
498 # |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
499 # Dalvik complaints that output of inject_redir() is out-of-order in |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
500 # DEXFile.protoIds list. |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
501 # \pre |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
502 # E/dalvikvm( 298): Out-of-order proto_id arguments |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
503 # E/dalvikvm( 298): Trouble with item 14 @ offset 0x304 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
504 # E/dalvikvm( 298): Cross-item verify of section type 0003 failed |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
505 # E/dalvikvm( 298): ERROR: Byte swap + verify failed |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
506 # E/dalvikvm( 298): Optimization failed |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
507 # |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
508 def proto_id_order_verify_test(): |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
509 from paraspace.dex_deptracker import prepare_dep_decls |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
510 from paraspace.dex_deptracker import dex_sort_sorted_arrays |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
511 from paraspace.injection import inject_redir_no_restore |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
512 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
513 _install_dexfile_4_deptracker() |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
514 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
515 all_dep_decls = prepare_dep_decls() |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
516 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
517 srcdir = os.path.dirname(__file__) |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
518 datapath = os.path.join(srcdir, '..', '..', 'data') |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
519 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
520 fake_path = os.path.join(datapath, 'fakefile.dex') |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
521 hello_path = os.path.join(datapath, 'helloworld.dex') |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
522 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
523 fake_dex = dexfile.DEXFile.open(fake_path) |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
524 fake_linked = dexfile.DEXFile_linked.build_dependencies(fake_dex, |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
525 all_dep_decls) |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
526 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
527 hello_dex = dexfile.DEXFile.open(hello_path) |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
528 hello_linked = dexfile.DEXFile_linked.build_dependencies(hello_dex, |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
529 all_dep_decls) |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
530 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
531 inject_redir_no_restore(fake_linked, 'Lcom/codemud/fakefile/fakefile;', |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
532 hello_linked, 'Ljava/io/File;', all_dep_decls) |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
533 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
534 dex_sort_sorted_arrays(hello_linked) |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
535 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
536 pairs = map(None, hello_linked.protoIds.items[:-1], |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
537 hello_linked.protoIds.items[1:]) |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
538 for idx, (protoid0, protoid1) in enumerate(pairs): |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
539 try: |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
540 assert protoid0 < protoid1 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
541 except: |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
542 print 'ERROR: protoid %d is out of order' % (idx + 1) |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
543 raise |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
544 pass |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
545 pass |
136
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
546 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
547 ## \brief Test case for issue of bad offset list in _DEX_AnnotationSetItem. |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
548 # |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
549 # Values of _DEX_AnnotationSetItem.annotationOffs is corrupted after |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
550 # injection. |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
551 # \pre |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
552 # E/dalvikvm( 300): No data map entry found @ 0xf31; expected 2004 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
553 # E/dalvikvm( 300): Trouble with item 0 @ offset 0x5c0 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
554 # E/dalvikvm( 300): Cross-item verify of section type 1003 failed |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
555 # E/dalvikvm( 300): ERROR: Byte swap + verify failed |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
556 # E/dalvikvm( 300): Optimization failed |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
557 # |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
558 # It must be the issue that back_type of an array can not be a \ref depend. |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
559 # |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
560 def annotation_set_items_verify_test(): |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
561 from paraspace.dex_deptracker import prepare_dep_decls |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
562 from paraspace.dex_deptracker import dex_sort_sorted_arrays |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
563 from paraspace.injection import inject_redir_no_restore |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
564 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
565 _install_dexfile_4_deptracker() |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
566 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
567 all_dep_decls = prepare_dep_decls() |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
568 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
569 srcdir = os.path.dirname(__file__) |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
570 datapath = os.path.join(srcdir, '..', '..', 'data') |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
571 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
572 fake_path = os.path.join(datapath, 'fakefile.dex') |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
573 hello_path = os.path.join(datapath, 'helloworld.dex') |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
574 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
575 fake_dex = dexfile.DEXFile.open(fake_path) |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
576 fake_linked = dexfile.DEXFile_linked.build_dependencies(fake_dex, |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
577 all_dep_decls) |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
578 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
579 hello_dex = dexfile.DEXFile.open(hello_path) |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
580 hello_linked = dexfile.DEXFile_linked.build_dependencies(hello_dex, |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
581 all_dep_decls) |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
582 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
583 inject_redir_no_restore(fake_linked, 'Lcom/codemud/fakefile/fakefile;', |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
584 hello_linked, 'Ljava/io/File;', all_dep_decls) |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
585 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
586 dex_sort_sorted_arrays(hello_linked) |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
587 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
588 for setitem in hello_linked.annotationSetItems.items: |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
589 for anno in setitem.annotationOffs.items: |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
590 assert anno.offset in hello_linked.annotationItems.items |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
591 pass |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
592 pass |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
593 pass |
137
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
594 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
595 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
596 ## \brief Test case for dalvik complaining fail to verify code. |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
597 # |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
598 # W/dalvikvm( 317): VFY: expected 1 args, found more (I) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
599 # W/dalvikvm( 317): VFY: rejecting call to Landroid/app/Activity;\ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
600 # .setContentView (I)V |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
601 # W/dalvikvm( 317): VFY: rejecting opcode 0x6e at 0x0006 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
602 # W/dalvikvm( 317): VFY: rejected Lcom/codemud/helloworld/helloworld;\ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
603 # .onClick (Landroid/view/View;)V |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
604 # W/dalvikvm( 317): Verifier rejected class Lcom/codemud/helloworld/\ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
605 # helloworld; |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
606 # W/dalvikvm( 317): Class init failed in newInstance call (Lcom/codemud/\ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
607 # helloworl |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
608 # |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
609 # DEXFile.methodIds is a sorted array. The indices of _DEX_MethodIds would |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
610 # be changed after injection and sorting, dex_sort_sorted_arrays(). |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
611 # It means indices in code blocks are invalid. So, code blocks must be |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
612 # rewrote with valid indices. |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
613 # |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
614 def code_verify_test(): |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
615 from paraspace.dex_deptracker import prepare_dep_decls |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
616 from paraspace.injection import dex_sort_sorted_arrays_consistent |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
617 from paraspace.injection import inject_redir_no_restore |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
618 from paraspace.dalvik_opcodes import decode_insn_blk |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
619 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
620 _install_dexfile_4_deptracker() |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
621 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
622 all_dep_decls = prepare_dep_decls() |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
623 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
624 srcdir = os.path.dirname(__file__) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
625 datapath = os.path.join(srcdir, '..', '..', 'data') |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
626 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
627 fake_path = os.path.join(datapath, 'fakefile.dex') |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
628 hello_path = os.path.join(datapath, 'helloworld.dex') |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
629 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
630 fake_dex = dexfile.DEXFile.open(fake_path) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
631 fake_linked = dexfile.DEXFile_linked.build_dependencies(fake_dex, |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
632 all_dep_decls) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
633 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
634 hello_dex = dexfile.DEXFile.open(hello_path) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
635 hello_linked = dexfile.DEXFile_linked.build_dependencies(hello_dex, |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
636 all_dep_decls) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
637 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
638 helloworld_typeid = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
639 hello_linked.find_typeid_name('Lcom/codemud/helloworld/helloworld;') |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
640 helloworld_methodids = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
641 hello_linked.find_methodids_typeid(helloworld_typeid) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
642 for methodid in helloworld_methodids: |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
643 methodname = hello_linked.get_methodid_name(methodid) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
644 if methodname == 'onClick': |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
645 methodidx = hello_linked.get_idx_methodid(methodid) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
646 method = hello_linked.find_method_idx(methodidx) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
647 blk = dexfile.DEXFile_linked.get_code_block_method(method) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
648 opvectors = decode_insn_blk(blk) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
649 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
650 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
651 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
652 inject_redir_no_restore(fake_linked, 'Lcom/codemud/fakefile/fakefile;', |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
653 hello_linked, 'Ljava/io/File;', all_dep_decls) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
654 dex_sort_sorted_arrays_consistent(hello_linked) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
655 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
656 for methodid in hello_linked.methodIds.items: |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
657 methodname = hello_linked.get_methodid_name(methodid) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
658 if methodname == 'setContentView': |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
659 protoid = methodid.protoIdx |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
660 sig = hello_linked.dump_protoid(protoid) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
661 assert sig == '(I) --> V' |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
662 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
663 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
664 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
665 helloworld_typeid = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
666 hello_linked.find_typeid_name('Lcom/codemud/helloworld/helloworld;') |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
667 helloworld_methodids = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
668 hello_linked.find_methodids_typeid(helloworld_typeid) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
669 for methodid in helloworld_methodids: |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
670 methodname = hello_linked.get_methodid_name(methodid) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
671 if methodname == 'onClick': |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
672 methodidx = hello_linked.get_idx_methodid(methodid) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
673 method = hello_linked.find_method_idx(methodidx) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
674 blk = dexfile.DEXFile_linked.get_code_block_method(method) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
675 opvectors = decode_insn_blk(blk) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
676 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
677 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
678 pass |