Mercurial > paraspace
annotate paraspace/tests/injection_test.py @ 155:6570b15d12d4 tip
Fix _DEX_ProtoId.__cmp__() with correct logic rules
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 17 Aug 2011 09:27:22 +0800 |
parents | bc213cb88636 |
children |
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 |
145
c4324c3461e8
Redirect string indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
144
diff
changeset
|
109 from paraspace.injection import dexfile_redirect_indices |
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) |
145
c4324c3461e8
Redirect string indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
144
diff
changeset
|
163 dexfile_redirect_indices(helloworld_linked, types_redir, |
152
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
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 |
152
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
diff
changeset
|
184 from paraspace.injection import \ |
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
diff
changeset
|
185 collect_typeidxs_stridxs_fieldidxs_in_method |
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
diff
changeset
|
186 from paraspace.injection import \ |
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
diff
changeset
|
187 collect_typeidxs_stridxs_fieldidxs_mentioned_by_class |
110
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
188 from paraspace.dexfile import DEXFile_linked |
109
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 _install_dexfile_4_deptracker() |
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 all_dep_decls = prepare_dep_decls() |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
193 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
194 srcdir = os.path.dirname(__file__) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
195 srcroot = os.path.join(srcdir, '..', '..') |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
196 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
197 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
|
198 fakefile_dex = dexfile.DEXFile.open(fakefile_fn) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
199 fakefile_linked = \ |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
200 dexfile.DEXFile_linked. \ |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
201 build_dependencies(fakefile_dex, all_dep_decls) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
202 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
203 fakefile_def = \ |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
204 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
|
205 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
206 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
|
207 |
152
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
diff
changeset
|
208 typeidxs, stridxs, fieldidxs = \ |
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
diff
changeset
|
209 collect_typeidxs_stridxs_fieldidxs_in_method(fakefile_linked, \ |
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
diff
changeset
|
210 init_method) |
109
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
211 assert len(typeidxs) == 1 |
110
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 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
|
214 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
|
215 assert typeid_name == 'Ljava/io/File;' |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
216 |
152
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
diff
changeset
|
217 typeidxs, stridxs, fieldidxs = \ |
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
diff
changeset
|
218 collect_typeidxs_stridxs_fieldidxs_mentioned_by_class(\ |
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
diff
changeset
|
219 fakefile_linked, fakefile_def) |
110
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
220 assert len(typeidxs) == 1 |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
221 |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
222 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
|
223 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
|
224 assert typeid_name == 'Ljava/io/File;' |
109
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
225 pass |
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 |
114
867184e01852
Change interface of dexfile_insert_classdefs_relative
Thinker K.F. Li <thinker@codemud.net>
parents:
113
diff
changeset
|
228 def dexfile_insert_classdefs_relative_test(): |
111
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
229 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
|
230 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
|
231 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
232 _install_dexfile_4_deptracker() |
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 all_dep_decls = prepare_dep_decls() |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
235 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
236 srcdir = os.path.dirname(__file__) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
237 srcroot = os.path.join(srcdir, '..', '..') |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
238 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
239 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
|
240 helloworld_dex = dexfile.DEXFile.open(helloworld_fn) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
241 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
242 classdef_map = _find_map(helloworld_dex, 0x0006) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
243 saved_classdef_map_sz = classdef_map.size |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
244 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
|
245 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
246 codeitems_map = _find_map(helloworld_dex, 0x2001) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
247 saved_codeitems_sz = codeitems_map.size |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
248 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
249 helloworld_linked = \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
250 dexfile.DEXFile_linked.build_dependencies(helloworld_dex, |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
251 all_dep_decls) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
252 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
253 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
|
254 fakefile_dex = dexfile.DEXFile.open(fakefile_fn) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
255 fakefile_linked = \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
256 dexfile.DEXFile_linked. \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
257 build_dependencies(fakefile_dex, all_dep_decls) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
258 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
259 fakefile_def = fakefile_linked. \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
260 find_class_name('Lcom/codemud/fakefile/fakefile;') |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
261 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
262 fakefile_data = fakefile_def.classDataOffRef.value |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
263 assert len(fakefile_data.directMethods.items) == 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
264 assert len(fakefile_data.virtualMethods.items) == 0 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
265 fakefile_dataheader = fakefile_data.header |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
266 assert fakefile_dataheader.directMethodsSize == 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
267 assert fakefile_dataheader.virtualMethodsSize == 0 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
268 |
150
1eb1b2ca5de4
Use classdef_rel_set to carry relative information.
Thinker K.F. Li <thinker@codemud.net>
parents:
149
diff
changeset
|
269 rel_set = dexfile_insert_classdefs_relative(helloworld_linked, |
1eb1b2ca5de4
Use classdef_rel_set to carry relative information.
Thinker K.F. Li <thinker@codemud.net>
parents:
149
diff
changeset
|
270 fakefile_linked, |
1eb1b2ca5de4
Use classdef_rel_set to carry relative information.
Thinker K.F. Li <thinker@codemud.net>
parents:
149
diff
changeset
|
271 [fakefile_def]) |
1eb1b2ca5de4
Use classdef_rel_set to carry relative information.
Thinker K.F. Li <thinker@codemud.net>
parents:
149
diff
changeset
|
272 classdefs = list(rel_set.classdefs) |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
273 assert classdefs |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
274 assert len(classdefs) == 1 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
275 assert classdefs[0] != fakefile_def |
111
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
276 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
277 helloworld_unlinked = helloworld_linked.get_unlinked() |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
278 assert helloworld_unlinked |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
279 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
280 # 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
|
281 classdef_map = _find_map(helloworld_unlinked, 0x0006) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
282 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
|
283 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
284 classdata_map = _find_map(helloworld_unlinked, 0x2000) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
285 assert classdata_map.size == classdef_map.size |
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 strings |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
288 strdatas = helloworld_unlinked.stringDataItems.items |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
289 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
|
290 assert len(strs) == len(set(strs)) # uniquely |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
291 assert 'Lcom/codemud/fakefile/fakefile;' in strs |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
292 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
293 # Check Method List |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
294 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
|
295 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
|
296 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
|
297 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
298 # Check Code item List |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
299 codeitems_map = _find_map(helloworld_unlinked, 0x2001) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
300 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
|
301 pass |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
302 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
303 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
304 def inject_classdefs_test(): |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
305 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
|
306 from paraspace.injection import inject_classdefs |
118 | 307 from paraspace.injection import make_methodidxs_redir_map |
145
c4324c3461e8
Redirect string indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
144
diff
changeset
|
308 from paraspace.injection import dexfile_redirect_indices |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
309 from paraspace import dalvik_opcodes |
116
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
310 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
|
311 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
312 _install_dexfile_4_deptracker() |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
313 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
314 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
|
315 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
316 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
|
317 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
|
318 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
319 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
|
320 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
|
321 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
326 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
|
327 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
|
328 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
329 helloworld_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.build_dependencies(helloworld_dex, |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
331 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_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
|
334 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
|
335 fakefile_linked = \ |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
336 dexfile.DEXFile_linked. \ |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
337 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
|
338 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
339 fakefile_def = \ |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
340 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
|
341 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
|
342 [fakefile_def]) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
343 assert clonings |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
344 assert len(clonings) == 1 |
116
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
345 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
346 fakefile_cloning = clonings[0] |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
347 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
|
348 assert isinstance(method, dexfile._DEX_Method) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
349 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 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
|
354 protoid = DEXFile_linked.make_protoid(V_typeid, |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
355 (file_typeid, str_typeid)) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
356 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
|
357 protoid, |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
358 file_typeid) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
359 initidx = helloworld_linked.get_idx_methodid(initid) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
360 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
361 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
|
362 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
|
363 assert len(opvectors) == 2 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
364 opvector = opvectors[0] |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
365 args = opvector[1] |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
366 assert args[2] == initidx |
118 | 367 |
368 fakefile_typeidx = \ | |
369 helloworld_linked.get_idx_typeid(fakefile_cloning.classIdx) | |
370 typeidxs_redir_map = {file_typeidx: fakefile_typeidx} | |
371 methodidxs_redir_map = \ | |
372 make_methodidxs_redir_map(helloworld_linked, \ | |
373 helloworld_linked, \ | |
374 typeidxs_redir_map) | |
145
c4324c3461e8
Redirect string indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
144
diff
changeset
|
375 dexfile_redirect_indices(helloworld_linked, typeidxs_redir_map, |
152
bc213cb88636
Inject and redirect fields
Thinker K.F. Li <thinker@codemud.net>
parents:
150
diff
changeset
|
376 methodidxs_redir_map, {}, {}, |
145
c4324c3461e8
Redirect string indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
144
diff
changeset
|
377 excludes=[fakefile_typeidx]) |
118 | 378 |
379 cloning_initdef = \ | |
380 helloworld_linked.find_method_name_proto('<init>', \ | |
381 protoid, \ | |
382 fakefile_cloning) | |
383 fakefile_codes = [cloning_initdef.codeOffRef.value] | |
384 for code in helloworld_linked.codeItems.items: | |
385 op_vectors = dalvik_opcodes.decode_insn_blk(code.insns.data) | |
386 for opcode, args in op_vectors: | |
387 if opcode == dalvik_opcodes.all_opcodes.OP_NEW_INSTANCE: | |
388 assert args[1] != file_typeidx | |
389 pass | |
390 elif opcode == dalvik_opcodes.all_opcodes.OP_INVOKE_DIRECT: | |
391 methodid = helloworld_linked.find_methodid_idx(args[2]) | |
392 assert methodid.classIdx != file_typeid or \ | |
393 code in fakefile_codes | |
394 pass | |
395 pass | |
396 pass | |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
397 pass |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
398 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
399 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
400 ## \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
|
401 # |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
402 # 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
|
403 # error messages. |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
404 # \pre |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
405 # 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
|
406 # found 2006 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
407 # 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
|
408 # 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
|
409 # 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
|
410 # E/dalvikvm( 302): Optimization failed |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
411 # |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
412 # 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
|
413 # \pre |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
414 # 0x0000(kDexTypeHeaderItem) size=1 offset=0x00000000 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
415 # 0x0001(kDexTypeStringIdItem) size=92 offset=0x00000070 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
416 # 0x0002(kDexTypeTypeIdItem) size=31 offset=0x000001e0 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
417 # 0x0003(kDexTypeProtoIdItem) size=18 offset=0x0000025c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
418 # 0x0004(kDexTypeFieldIdItem) size=7 offset=0x00000334 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
419 # 0x0005(kDexTypeMethodIdItem) size=36 offset=0x0000036c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
420 # 0x0006(kDexTypeClassDefItem) size=10 offset=0x0000048c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
421 # 0x1003(kDexTypeAnnotationSetItem) size=7 offset=0x000005cc |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
422 # 0x2001(kDexTypeCodeItem) size=17 offset=0x0000061c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
423 # 0x2006(kDexTypeAnnotationsDirectoryItem) size=7 offset=0x00000910 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
424 # 0x1001(kDexTypeTypeList) size=12 offset=0x00000980 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
425 # 0x2002(kDexTypeStringDataItem) size=92 offset=0x000009e2 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
426 # 0x2003(kDexTypeDebugInfoItem) size=17 offset=0x00000f05 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
427 # 0x2004(kDexTypeAnnotationItem) size=9 offset=0x00000fc1 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
428 # 0x2005(kDexTypeEncodedArrayItem) size=5 offset=0x00001012 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
429 # 0x2000(kDexTypeClassDataItem) size=10 offset=0x0000102d |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
430 # 0x1000(kDexTypeMapList) size=1 offset=0x000010c0 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
431 # |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
432 # 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
|
433 # 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
|
434 # |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
435 # 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
|
436 # put injected objects into lists properly. |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
437 # |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
438 def map_verify_error_test(): |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
439 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
|
440 from paraspace.injection import inject_redir |
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 _install_dexfile_4_deptracker() |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
443 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
444 all_dep_decls = prepare_dep_decls() |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
445 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
446 srcdir = os.path.dirname(__file__) |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
447 datapath = os.path.join(srcdir, '..', '..', 'data') |
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 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
|
450 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
|
451 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
452 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
|
453 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
|
454 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 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
|
457 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
|
458 all_dep_decls) |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
459 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
460 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
|
461 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
|
462 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
463 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
|
464 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
|
465 break |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
466 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
467 else: |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
468 assert False |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
469 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
470 typelist_start = item.offset |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
471 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
|
472 typelist_stop = next_item.offset |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
473 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
474 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
|
475 off = protoid.parametersOff |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
476 try: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
477 if off != 0: |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
478 assert off >= typelist_start |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
479 assert off < typelist_stop |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
480 pass |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
481 pass |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
482 except: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
483 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
|
484 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
|
485 raise |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
486 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
487 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
488 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
|
489 off = classdef.interfacesOff |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
490 try: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
491 if off != 0: |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
492 assert off >= typelist_start |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
493 assert off < typelist_stop |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
494 pass |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
495 pass |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
496 except: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
497 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
|
498 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
|
499 raise |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
500 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
501 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
|
502 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
503 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
504 ## \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
|
505 # |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
506 # 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
|
507 # 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
|
508 # \pre |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
509 # 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
|
510 # 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
|
511 # 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
|
512 # 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
|
513 # 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
|
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 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
|
516 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
|
517 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
|
518 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
|
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 _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
|
521 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
522 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
|
523 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
524 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
|
525 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
|
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 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
|
528 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
|
529 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
530 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
|
531 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
|
532 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 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
|
535 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
|
536 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
|
537 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
538 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
|
539 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
|
540 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
541 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
|
542 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
543 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
|
544 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
|
545 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
|
546 try: |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
547 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
|
548 except: |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
549 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
|
550 raise |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
551 pass |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
552 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
|
553 |
155
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
554 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
555 ## \brief Test case for protoid out of order. |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
556 # |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
557 # Dalvik complaints that output of inject_redir() is out-of-order in |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
558 # DEXFile.protoIds list. |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
559 # \pre |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
560 # E/dalvikvm( 294): Out-of-order proto_id arguments |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
561 # E/dalvikvm( 294): Trouble with item 6 @ offset 0x2bc |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
562 # E/dalvikvm( 294): Cross-item verify of section type 0003 failed |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
563 # E/dalvikvm( 294): ERROR: Byte swap + verify failed |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
564 # |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
565 # The _DEX_ProtoId.__cmp__() does not define the order well. |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
566 # It was fixed with correct logic rules. |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
567 # |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
568 def proto_id_order_verify_1_test(): |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
569 from paraspace.dex_deptracker import prepare_dep_decls |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
570 from paraspace.dex_deptracker import dex_sort_sorted_arrays |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
571 from paraspace.injection import inject_redir_no_restore |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
572 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
573 _install_dexfile_4_deptracker() |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
574 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
575 all_dep_decls = prepare_dep_decls() |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
576 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
577 srcdir = os.path.dirname(__file__) |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
578 datapath = os.path.join(srcdir, '..', '..', 'data') |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
579 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
580 fake_path = os.path.join(datapath, 'suffile.dex') |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
581 hello_path = os.path.join(datapath, 'helloworld.dex') |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
582 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
583 fake_dex = dexfile.DEXFile.open(fake_path) |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
584 fake_linked = dexfile.DEXFile_linked.build_dependencies(fake_dex, |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
585 all_dep_decls) |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
586 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
587 hello_dex = dexfile.DEXFile.open(hello_path) |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
588 hello_linked = dexfile.DEXFile_linked.build_dependencies(hello_dex, |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
589 all_dep_decls) |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
590 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
591 inject_redir_no_restore(fake_linked, 'Lcom/codemud/fakefile/fakefile;', |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
592 hello_linked, 'Ljava/io/File;', all_dep_decls) |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
593 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
594 dex_sort_sorted_arrays(hello_linked) |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
595 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
596 pairs = map(None, hello_linked.protoIds.items[:-1], |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
597 hello_linked.protoIds.items[1:]) |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
598 for idx, (protoid0, protoid1) in enumerate(pairs): |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
599 try: |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
600 assert cmp(protoid1, protoid0) > 0 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
601 except: |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
602 print 'ERROR: protoid %d is out of order' % (idx + 1) |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
603 raise |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
604 pass |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
605 pass |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
606 |
6570b15d12d4
Fix _DEX_ProtoId.__cmp__() with correct logic rules
Thinker K.F. Li <thinker@codemud.net>
parents:
152
diff
changeset
|
607 |
136
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
608 ## \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
|
609 # |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
610 # 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
|
611 # injection. |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
612 # \pre |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
613 # 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
|
614 # 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
|
615 # 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
|
616 # 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
|
617 # 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
|
618 # |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
619 # 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
|
620 # |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
621 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
|
622 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
|
623 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
|
624 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
|
625 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
626 _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
|
627 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
628 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
|
629 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
630 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
|
631 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
|
632 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
633 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
|
634 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
|
635 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
636 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
|
637 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
|
638 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
|
639 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
640 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
|
641 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
|
642 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
|
643 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
644 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
|
645 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
|
646 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
647 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
|
648 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
649 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
|
650 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
|
651 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
|
652 pass |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
653 pass |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
654 pass |
137
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 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
657 ## \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
|
658 # |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
659 # 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
|
660 # 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
|
661 # .setContentView (I)V |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
662 # 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
|
663 # 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
|
664 # .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
|
665 # 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
|
666 # helloworld; |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
667 # 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
|
668 # helloworl |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
669 # |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
670 # 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
|
671 # 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
|
672 # 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
|
673 # 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
|
674 # |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
675 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
|
676 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
|
677 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
|
678 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
|
679 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
|
680 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
681 _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
|
682 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
683 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
|
684 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
685 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
|
686 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
|
687 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
688 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
|
689 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
|
690 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
691 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
|
692 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
|
693 all_dep_decls) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
694 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
695 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
|
696 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
|
697 all_dep_decls) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
698 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
699 helloworld_typeid = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
700 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
|
701 helloworld_methodids = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
702 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
|
703 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
|
704 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
|
705 if methodname == 'onClick': |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
706 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
|
707 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
|
708 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
|
709 opvectors = decode_insn_blk(blk) |
138
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
710 methodidx = opvectors[4][1][2] |
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
711 saved_methodid0 = hello_linked.find_methodid_idx(methodidx) |
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
712 methodidx = opvectors[12][1][1] |
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
713 saved_methodid1 = hello_linked.find_methodid_idx(methodidx) |
139
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
714 elif methodname == 'write_file': |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
715 assert methodid in hello_linked.methodIds.items |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
716 methodidx = hello_linked.get_idx_methodid(methodid) |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
717 method = hello_linked.find_method_idx(methodidx) |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
718 blk = dexfile.DEXFile_linked.get_code_block_method(method) |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
719 opvectors = decode_insn_blk(blk) |
137
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
720 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
721 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
722 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
723 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
|
724 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
|
725 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
|
726 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
727 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
|
728 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
|
729 if methodname == 'setContentView': |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
730 protoid = methodid.protoIdx |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
731 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
|
732 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
|
733 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
734 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
735 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
736 helloworld_typeid = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
737 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
|
738 helloworld_methodids = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 if methodname == 'onClick': |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
743 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
|
744 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
|
745 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
|
746 opvectors = decode_insn_blk(blk) |
138
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
747 methodidx = opvectors[4][1][2] |
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
748 new_methodid0 = hello_linked.find_methodid_idx(methodidx) |
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
749 assert new_methodid0 is saved_methodid0 |
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
750 methodidx = opvectors[12][1][1] |
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
751 new_methodid1 = hello_linked.find_methodid_idx(methodidx) |
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
752 assert saved_methodid1 in hello_linked.methodIds.items |
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
753 assert new_methodid1 in hello_linked.methodIds.items |
372009418896
Fix bug of redirect methodid for XXX_RANGE istructions
Thinker K.F. Li <thinker@codemud.net>
parents:
137
diff
changeset
|
754 assert new_methodid1 is saved_methodid1 |
137
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
755 pass |
139
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
756 elif methodname == 'write_file': |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
757 assert methodid in hello_linked.methodIds.items |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
758 methodidx = hello_linked.get_idx_methodid(methodid) |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
759 method = hello_linked.find_method_idx(methodidx) |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
760 blk = dexfile.DEXFile_linked.get_code_block_method(method) |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
761 opvectors = decode_insn_blk(blk) |
144
46e40afd4558
Fix bug of typo in dex_sort_sorted_arrays_consistent()
Thinker K.F. Li <thinker@codemud.net>
parents:
143
diff
changeset
|
762 # Check correctness of typeid of a new_instance. |
46e40afd4558
Fix bug of typo in dex_sort_sorted_arrays_consistent()
Thinker K.F. Li <thinker@codemud.net>
parents:
143
diff
changeset
|
763 # This is an error of dex_sort_sorted_arrays_consistent(). |
46e40afd4558
Fix bug of typo in dex_sort_sorted_arrays_consistent()
Thinker K.F. Li <thinker@codemud.net>
parents:
143
diff
changeset
|
764 assert opvectors[2][1][1] < len(hello_linked.typeIds.items) |
139
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
765 pass |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
766 pass |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
767 pass |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
768 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
769 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
770 ## \brief Test case for checking methods of classdatas are consistent. |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
771 # |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
772 # Becase space optimization, DEX ecnode value for method indices |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
773 # in \ref _DEX_Method. This test case make sure build_dependencies() |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
774 # decode indices correctly. |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
775 # |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
776 # \see _deoptimize_classdata |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
777 # |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
778 def class_methods_consistent_test(): |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
779 from paraspace.dex_deptracker import prepare_dep_decls |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
780 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
781 _install_dexfile_4_deptracker() |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
782 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
783 all_dep_decls = prepare_dep_decls() |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
784 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
785 srcdir = os.path.dirname(__file__) |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
786 datapath = os.path.join(srcdir, '..', '..', 'data') |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
787 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
788 hello_path = os.path.join(datapath, 'helloworld.dex') |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
789 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
790 hello_dex = dexfile.DEXFile.open(hello_path) |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
791 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
792 hello_linked = dexfile.DEXFile_linked.build_dependencies(hello_dex, |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
793 all_dep_decls) |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
794 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
795 for classdata in hello_linked.classDatas.items: |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
796 allmethods = classdata.directMethods.items + \ |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
797 classdata.virtualMethods.items |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
798 if len(allmethods) < 2: |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
799 continue |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
800 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
801 firstmethod = allmethods[0] |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
802 firstmethodid = firstmethod.methodIdx |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
803 for idx, method in enumerate(allmethods[1:]): |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
804 try: |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
805 assert method.methodIdx.classIdx == firstmethodid.classIdx |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
806 except: |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
807 print 'ERROR: method %d' % (idx + 1) |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
808 raise |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
809 pass |
137
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
810 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
811 pass |
142
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
812 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
813 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
814 ## \brief Test case for getting negative indices in _DEX_ClassDAta. |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
815 # |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
816 # It, possibly, caused by appling _optimize_classdata() at end of |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
817 # restore_dependencies(). But, value was comes from |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
818 # depend_idx_rel.get_value(). It already deoptimize the value. |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
819 # |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
820 def negative_depend_idx_rel_test(): |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
821 from paraspace.dex_deptracker import prepare_dep_decls |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
822 from paraspace.dex_deptracker import dex_sort_sorted_arrays |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
823 from paraspace.injection import inject_redir |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
824 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
825 _install_dexfile_4_deptracker() |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
826 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
827 all_dep_decls = prepare_dep_decls() |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
828 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
829 srcdir = os.path.dirname(__file__) |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
830 datapath = os.path.join(srcdir, '..', '..', 'data') |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
831 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
832 fake_path = os.path.join(datapath, 'fakefile.dex') |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
833 hello_path = os.path.join(datapath, 'helloworld.dex') |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
834 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
835 fake_dex = dexfile.DEXFile.open(fake_path) |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
836 fake_linked = dexfile.DEXFile_linked.build_dependencies(fake_dex, |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
837 all_dep_decls) |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
838 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
839 hello_dex = dexfile.DEXFile.open(hello_path) |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
840 hello_linked = dexfile.DEXFile_linked.build_dependencies(hello_dex, |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
841 all_dep_decls) |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
842 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
843 inject_redir(fake_linked, 'Lcom/codemud/fakefile/fakefile;', |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
844 hello_linked, 'Ljava/io/File;', all_dep_decls) |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
845 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
846 hello_linked.to_str() |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
847 pass |