Mercurial > paraspace
annotate paraspace/tests/injection_test.py @ 145:c4324c3461e8
Redirect string indices.
- Change names of *redirect_types*() to *redirect_indices*().
- Redirect string indices in method_redirect_indices() too.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 15 Aug 2011 15:25:39 +0800 |
parents | 46e40afd4558 |
children | d4533a59c694 |
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, |
c4324c3461e8
Redirect string indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
144
diff
changeset
|
164 methods_redir, excludes) |
105
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
165 |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
166 for code in helloworld_linked.codeItems.items: |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
167 op_vectors = dalvik_opcodes.decode_insn_blk(code.insns.data) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
168 for opcode, args in op_vectors: |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
169 if opcode == dalvik_opcodes.all_opcodes.OP_NEW_INSTANCE: |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
170 assert args[1] != File_typeidx |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
171 pass |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
172 elif opcode == dalvik_opcodes.all_opcodes.OP_INVOKE_DIRECT: |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
173 methodid = helloworld_linked.find_methodid_idx(args[2]) |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
174 assert methodid.classIdx != File_typeid or \ |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
175 code in fakefile_codes |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
176 pass |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
177 pass |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
178 pass |
f14c32108164
Test dexfile_redirect_types
Thinker K.F. Li <thinker@codemud.net>
parents:
100
diff
changeset
|
179 pass |
109
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
180 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
181 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
182 def collect_types_in_method_test(): |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
183 from paraspace.dex_deptracker import prepare_dep_decls |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
184 from paraspace.injection import collect_typeidxs_in_method |
110
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
185 from paraspace.injection import collect_typeidxs_mentioned_by_class |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
186 from paraspace.dexfile import DEXFile_linked |
109
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
187 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
188 _install_dexfile_4_deptracker() |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
189 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
190 all_dep_decls = prepare_dep_decls() |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
191 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
192 srcdir = os.path.dirname(__file__) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
193 srcroot = os.path.join(srcdir, '..', '..') |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
194 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
195 fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex') |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
196 fakefile_dex = dexfile.DEXFile.open(fakefile_fn) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
197 fakefile_linked = \ |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
198 dexfile.DEXFile_linked. \ |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
199 build_dependencies(fakefile_dex, all_dep_decls) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
200 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
201 fakefile_def = \ |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
202 fakefile_linked.find_class_name('Lcom/codemud/fakefile/fakefile;') |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
203 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
204 init_method = fakefile_linked.find_method_name('<init>', fakefile_def) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
205 |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
206 typeidxs = collect_typeidxs_in_method(fakefile_linked, init_method) |
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
207 assert len(typeidxs) == 1 |
110
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
208 |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
209 typeid = fakefile_linked.find_typeid_idx(typeidxs[0]) |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
210 typeid_name = DEXFile_linked.get_typeid_name(typeid) |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
211 assert typeid_name == 'Ljava/io/File;' |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
212 |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
213 typeidxs = collect_typeidxs_mentioned_by_class(fakefile_linked, |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
214 fakefile_def) |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
215 assert len(typeidxs) == 1 |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
216 |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
217 typeid = fakefile_linked.find_typeid_idx(typeidxs[0]) |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
218 typeid_name = DEXFile_linked.get_typeid_name(typeid) |
6380730a80b4
Add collect_typeidxs_mentioned_by_class()
Thinker K.F. Li <thinker@codemud.net>
parents:
109
diff
changeset
|
219 assert typeid_name == 'Ljava/io/File;' |
109
835336632aba
Add collect_typeidxs_in_method()
Thinker K.F. Li <thinker@codemud.net>
parents:
107
diff
changeset
|
220 pass |
111
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
221 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
222 |
114
867184e01852
Change interface of dexfile_insert_classdefs_relative
Thinker K.F. Li <thinker@codemud.net>
parents:
113
diff
changeset
|
223 def dexfile_insert_classdefs_relative_test(): |
111
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
224 from paraspace.dex_deptracker import prepare_dep_decls |
114
867184e01852
Change interface of dexfile_insert_classdefs_relative
Thinker K.F. Li <thinker@codemud.net>
parents:
113
diff
changeset
|
225 from paraspace.injection import dexfile_insert_classdefs_relative |
111
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
226 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
227 _install_dexfile_4_deptracker() |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
228 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
229 all_dep_decls = prepare_dep_decls() |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
230 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
231 srcdir = os.path.dirname(__file__) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
232 srcroot = os.path.join(srcdir, '..', '..') |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
233 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
234 helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex') |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
235 helloworld_dex = dexfile.DEXFile.open(helloworld_fn) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
236 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
237 classdef_map = _find_map(helloworld_dex, 0x0006) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
238 saved_classdef_map_sz = classdef_map.size |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
239 saved_methodids_sz = len(helloworld_dex.methodIds.items) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
240 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
241 codeitems_map = _find_map(helloworld_dex, 0x2001) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
242 saved_codeitems_sz = codeitems_map.size |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
243 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
244 helloworld_linked = \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
245 dexfile.DEXFile_linked.build_dependencies(helloworld_dex, |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
246 all_dep_decls) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
247 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
248 fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex') |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
249 fakefile_dex = dexfile.DEXFile.open(fakefile_fn) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
250 fakefile_linked = \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
251 dexfile.DEXFile_linked. \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
252 build_dependencies(fakefile_dex, all_dep_decls) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
253 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
254 fakefile_def = fakefile_linked. \ |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
255 find_class_name('Lcom/codemud/fakefile/fakefile;') |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
256 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
257 fakefile_data = fakefile_def.classDataOffRef.value |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
258 assert len(fakefile_data.directMethods.items) == 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
259 assert len(fakefile_data.virtualMethods.items) == 0 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
260 fakefile_dataheader = fakefile_data.header |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
261 assert fakefile_dataheader.directMethodsSize == 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
262 assert fakefile_dataheader.virtualMethodsSize == 0 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
263 |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
264 classdefs, typeids = dexfile_insert_classdefs_relative(helloworld_linked, |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
265 fakefile_linked, |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
266 [fakefile_def]) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
267 assert classdefs |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
268 assert len(classdefs) == 1 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
269 assert classdefs[0] != fakefile_def |
111
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
270 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
271 helloworld_unlinked = helloworld_linked.get_unlinked() |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
272 assert helloworld_unlinked |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
273 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
274 # map size for classdef must be increased by 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
275 classdef_map = _find_map(helloworld_unlinked, 0x0006) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
276 assert classdef_map.size == saved_classdef_map_sz + 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
277 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
278 classdata_map = _find_map(helloworld_unlinked, 0x2000) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
279 assert classdata_map.size == classdef_map.size |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
280 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
281 # Check strings |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
282 strdatas = helloworld_unlinked.stringDataItems.items |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
283 strs = sorted([strdata.data.data for strdata in strdatas]) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
284 assert len(strs) == len(set(strs)) # uniquely |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
285 assert 'Lcom/codemud/fakefile/fakefile;' in strs |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
286 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
287 # Check Method List |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
288 methodids_map = _find_map(helloworld_unlinked, 0x0005) # method ids |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
289 assert methodids_map.size == len(helloworld_unlinked.methodIds.items) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
290 assert methodids_map.size == saved_methodids_sz + 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
291 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
292 # Check Code item List |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
293 codeitems_map = _find_map(helloworld_unlinked, 0x2001) |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
294 assert codeitems_map.size == saved_codeitems_sz + 1 |
3820379b34e8
Add dexfile_insert_class_relative()
Thinker K.F. Li <thinker@codemud.net>
parents:
110
diff
changeset
|
295 pass |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
296 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
297 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
298 def inject_classdefs_test(): |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
299 from paraspace.dex_deptracker import prepare_dep_decls |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
300 from paraspace.injection import inject_classdefs |
118 | 301 from paraspace.injection import make_methodidxs_redir_map |
145
c4324c3461e8
Redirect string indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
144
diff
changeset
|
302 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
|
303 from paraspace import dalvik_opcodes |
116
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
304 from paraspace.dexfile import DEXFile_linked |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
305 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
306 _install_dexfile_4_deptracker() |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
307 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
308 all_dep_decls = prepare_dep_decls() |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
309 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
310 srcdir = os.path.dirname(__file__) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
311 srcroot = os.path.join(srcdir, '..', '..') |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
312 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
313 helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex') |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
314 helloworld_dex = dexfile.DEXFile.open(helloworld_fn) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
315 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
316 classdef_map = _find_map(helloworld_dex, 0x0006) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
317 saved_classdef_map_sz = classdef_map.size |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
318 saved_methodids_sz = len(helloworld_dex.methodIds.items) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
319 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
320 codeitems_map = _find_map(helloworld_dex, 0x2001) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
321 saved_codeitems_sz = codeitems_map.size |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
322 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
323 helloworld_linked = \ |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
324 dexfile.DEXFile_linked.build_dependencies(helloworld_dex, |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
325 all_dep_decls) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
326 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
327 fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex') |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
328 fakefile_dex = dexfile.DEXFile.open(fakefile_fn) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
329 fakefile_linked = \ |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
330 dexfile.DEXFile_linked. \ |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
331 build_dependencies(fakefile_dex, all_dep_decls) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
332 |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
333 fakefile_def = \ |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
334 fakefile_linked.find_class_name('Lcom/codemud/fakefile/fakefile;') |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
335 clonings = inject_classdefs(helloworld_linked, fakefile_linked, |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
336 [fakefile_def]) |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
337 assert clonings |
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
338 assert len(clonings) == 1 |
116
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
339 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
340 fakefile_cloning = clonings[0] |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
341 method = helloworld_linked.find_method_name('<init>', fakefile_cloning) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
342 assert isinstance(method, dexfile._DEX_Method) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
343 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
344 V_typeid = helloworld_linked.find_typeid_name('V') |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
345 file_typeid = helloworld_linked.find_typeid_name('Ljava/io/File;') |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
346 file_typeidx = helloworld_linked.get_idx_typeid(file_typeid) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
347 str_typeid = helloworld_linked.find_typeid_name('Ljava/lang/String;') |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
348 protoid = DEXFile_linked.make_protoid(V_typeid, |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
349 (file_typeid, str_typeid)) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
350 initid = helloworld_linked.find_methodid_name_proto('<init>', |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
351 protoid, |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
352 file_typeid) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
353 initidx = helloworld_linked.get_idx_methodid(initid) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
354 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
355 insns_block = DEXFile_linked.get_code_block_method(method) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
356 opvectors = dalvik_opcodes.decode_insn_blk(insns_block) |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
357 assert len(opvectors) == 2 |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
358 opvector = opvectors[0] |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
359 args = opvector[1] |
c5f59bdbc916
Fix issue of proto matching.
Thinker K.F. Li <thinker@codemud.net>
parents:
115
diff
changeset
|
360 assert args[2] == initidx |
118 | 361 |
362 fakefile_typeidx = \ | |
363 helloworld_linked.get_idx_typeid(fakefile_cloning.classIdx) | |
364 typeidxs_redir_map = {file_typeidx: fakefile_typeidx} | |
365 methodidxs_redir_map = \ | |
366 make_methodidxs_redir_map(helloworld_linked, \ | |
367 helloworld_linked, \ | |
368 typeidxs_redir_map) | |
145
c4324c3461e8
Redirect string indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
144
diff
changeset
|
369 dexfile_redirect_indices(helloworld_linked, typeidxs_redir_map, |
c4324c3461e8
Redirect string indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
144
diff
changeset
|
370 methodidxs_redir_map, {}, |
c4324c3461e8
Redirect string indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
144
diff
changeset
|
371 excludes=[fakefile_typeidx]) |
118 | 372 |
373 cloning_initdef = \ | |
374 helloworld_linked.find_method_name_proto('<init>', \ | |
375 protoid, \ | |
376 fakefile_cloning) | |
377 fakefile_codes = [cloning_initdef.codeOffRef.value] | |
378 for code in helloworld_linked.codeItems.items: | |
379 op_vectors = dalvik_opcodes.decode_insn_blk(code.insns.data) | |
380 for opcode, args in op_vectors: | |
381 if opcode == dalvik_opcodes.all_opcodes.OP_NEW_INSTANCE: | |
382 assert args[1] != file_typeidx | |
383 pass | |
384 elif opcode == dalvik_opcodes.all_opcodes.OP_INVOKE_DIRECT: | |
385 methodid = helloworld_linked.find_methodid_idx(args[2]) | |
386 assert methodid.classIdx != file_typeid or \ | |
387 code in fakefile_codes | |
388 pass | |
389 pass | |
390 pass | |
115
d112c27f657a
Add inject_classdefs() for injecting classdef to DEX
Thinker K.F. Li <thinker@codemud.net>
parents:
114
diff
changeset
|
391 pass |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
392 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
393 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
394 ## \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
|
395 # |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
396 # 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
|
397 # error messages. |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
398 # \pre |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
399 # 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
|
400 # found 2006 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
401 # 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
|
402 # 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
|
403 # 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
|
404 # E/dalvikvm( 302): Optimization failed |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
405 # |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
406 # 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
|
407 # \pre |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
408 # 0x0000(kDexTypeHeaderItem) size=1 offset=0x00000000 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
409 # 0x0001(kDexTypeStringIdItem) size=92 offset=0x00000070 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
410 # 0x0002(kDexTypeTypeIdItem) size=31 offset=0x000001e0 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
411 # 0x0003(kDexTypeProtoIdItem) size=18 offset=0x0000025c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
412 # 0x0004(kDexTypeFieldIdItem) size=7 offset=0x00000334 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
413 # 0x0005(kDexTypeMethodIdItem) size=36 offset=0x0000036c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
414 # 0x0006(kDexTypeClassDefItem) size=10 offset=0x0000048c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
415 # 0x1003(kDexTypeAnnotationSetItem) size=7 offset=0x000005cc |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
416 # 0x2001(kDexTypeCodeItem) size=17 offset=0x0000061c |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
417 # 0x2006(kDexTypeAnnotationsDirectoryItem) size=7 offset=0x00000910 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
418 # 0x1001(kDexTypeTypeList) size=12 offset=0x00000980 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
419 # 0x2002(kDexTypeStringDataItem) size=92 offset=0x000009e2 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
420 # 0x2003(kDexTypeDebugInfoItem) size=17 offset=0x00000f05 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
421 # 0x2004(kDexTypeAnnotationItem) size=9 offset=0x00000fc1 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
422 # 0x2005(kDexTypeEncodedArrayItem) size=5 offset=0x00001012 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
423 # 0x2000(kDexTypeClassDataItem) size=10 offset=0x0000102d |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
424 # 0x1000(kDexTypeMapList) size=1 offset=0x000010c0 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
425 # |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
426 # 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
|
427 # 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
|
428 # |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
429 # 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
|
430 # put injected objects into lists properly. |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
431 # |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
432 def map_verify_error_test(): |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
433 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
|
434 from paraspace.injection import inject_redir |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
435 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
436 _install_dexfile_4_deptracker() |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
437 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
438 all_dep_decls = prepare_dep_decls() |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
439 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
440 srcdir = os.path.dirname(__file__) |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
441 datapath = os.path.join(srcdir, '..', '..', 'data') |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
442 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
443 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
|
444 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
|
445 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
446 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
|
447 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
|
448 all_dep_decls) |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
449 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
450 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
|
451 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
|
452 all_dep_decls) |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
453 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
454 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
|
455 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
|
456 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
457 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
|
458 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
|
459 break |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
460 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
461 else: |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
462 assert False |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
463 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
464 typelist_start = item.offset |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
465 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
|
466 typelist_stop = next_item.offset |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
467 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
468 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
|
469 off = protoid.parametersOff |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
470 try: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
471 if off != 0: |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
472 assert off >= typelist_start |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
473 assert off < typelist_stop |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
474 pass |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
475 pass |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
476 except: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
477 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
|
478 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
|
479 raise |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
480 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
481 |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
482 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
|
483 off = classdef.interfacesOff |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
484 try: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
485 if off != 0: |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
486 assert off >= typelist_start |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
487 assert off < typelist_stop |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
488 pass |
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
489 pass |
131
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
490 except: |
132
75a31967ebee
Following the ref in resotre_dependencies()
Thinker K.F. Li <thinker@codemud.net>
parents:
131
diff
changeset
|
491 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
|
492 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
|
493 raise |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
494 pass |
044bfc415577
Fix issue of data map verification.
Thinker K.F. Li <thinker@codemud.net>
parents:
118
diff
changeset
|
495 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
|
496 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
497 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
498 ## \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
|
499 # |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
500 # 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
|
501 # 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
|
502 # \pre |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
503 # E/dalvikvm( 298): 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
|
504 # 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
|
505 # 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
|
506 # 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
|
507 # 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
|
508 # |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
509 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
|
510 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
|
511 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
|
512 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
|
513 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
514 _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
|
515 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
516 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
|
517 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
518 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
|
519 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
|
520 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
521 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
|
522 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
|
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 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
|
525 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
|
526 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
|
527 |
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_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
|
529 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
|
530 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
|
531 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
532 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
|
533 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
|
534 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
535 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
|
536 |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
537 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
|
538 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
|
539 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
|
540 try: |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
541 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
|
542 except: |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
543 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
|
544 raise |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
545 pass |
b488ca519709
Make sure elements are absolute incremental for sorted arrays when injecting.
Thinker K.F. Li <thinker@codemud.net>
parents:
132
diff
changeset
|
546 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
|
547 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
548 ## \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
|
549 # |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
550 # 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
|
551 # injection. |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
552 # \pre |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
553 # E/dalvikvm( 300): 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
|
554 # 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
|
555 # 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
|
556 # 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
|
557 # 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
|
558 # |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
559 # 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
|
560 # |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
561 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
|
562 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
|
563 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
|
564 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
|
565 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
566 _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
|
567 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
568 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
|
569 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
570 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
|
571 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
|
572 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
573 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
|
574 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
|
575 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
576 fake_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
|
577 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
|
578 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
|
579 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
580 hello_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
|
581 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
|
582 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
|
583 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
584 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
|
585 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
|
586 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
587 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
|
588 |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
589 for 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
|
590 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
|
591 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
|
592 pass |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
593 pass |
f31bfe55d9c2
Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection
Thinker K.F. Li <thinker@codemud.net>
parents:
135
diff
changeset
|
594 pass |
137
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
595 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
596 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
597 ## \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
|
598 # |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
599 # W/dalvikvm( 317): VFY: 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
|
600 # 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
|
601 # .setContentView (I)V |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
602 # W/dalvikvm( 317): VFY: 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
|
603 # 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
|
604 # .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
|
605 # 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
|
606 # helloworld; |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
607 # 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
|
608 # helloworl |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
609 # |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
610 # 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
|
611 # 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
|
612 # 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
|
613 # 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
|
614 # |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
615 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
|
616 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
|
617 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
|
618 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
|
619 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
|
620 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
621 _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
|
622 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
623 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
|
624 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
625 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
|
626 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
|
627 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
628 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
|
629 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
|
630 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
631 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
|
632 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
|
633 all_dep_decls) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
634 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
635 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
|
636 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
|
637 all_dep_decls) |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
638 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
639 helloworld_typeid = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
640 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
|
641 helloworld_methodids = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
642 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
|
643 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
|
644 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
|
645 if methodname == 'onClick': |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
646 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
|
647 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
|
648 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
|
649 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
|
650 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
|
651 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
|
652 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
|
653 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
|
654 elif methodname == 'write_file': |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
655 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
|
656 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
|
657 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
|
658 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
|
659 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
|
660 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
661 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
662 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
663 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
|
664 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
|
665 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
|
666 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
667 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
|
668 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
|
669 if methodname == 'setContentView': |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
670 protoid = methodid.protoIdx |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
671 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
|
672 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
|
673 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
674 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
675 |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
676 helloworld_typeid = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
677 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
|
678 helloworld_methodids = \ |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
679 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
|
680 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
|
681 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
|
682 if methodname == 'onClick': |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
683 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
|
684 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
|
685 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
|
686 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
|
687 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
|
688 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
|
689 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
|
690 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
|
691 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
|
692 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
|
693 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
|
694 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
|
695 pass |
139
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
696 elif methodname == 'write_file': |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
697 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
|
698 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
|
699 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
|
700 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
|
701 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
|
702 # 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
|
703 # 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
|
704 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
|
705 pass |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
706 pass |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
707 pass |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
708 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
709 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
710 ## \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
|
711 # |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
712 # 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
|
713 # 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
|
714 # decode indices correctly. |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
715 # |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
716 # \see _deoptimize_classdata |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
717 # |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
718 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
|
719 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
|
720 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
721 _install_dexfile_4_deptracker() |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
722 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
723 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
|
724 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
725 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
|
726 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
|
727 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
728 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
|
729 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
730 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
|
731 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
732 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
|
733 all_dep_decls) |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
734 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
735 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
|
736 allmethods = classdata.directMethods.items + \ |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
737 classdata.virtualMethods.items |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
738 if len(allmethods) < 2: |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
739 continue |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
740 |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
741 firstmethod = allmethods[0] |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
742 firstmethodid = firstmethod.methodIdx |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
743 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
|
744 try: |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
745 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
|
746 except: |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
747 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
|
748 raise |
0704e23009e4
Fix bug of not dealing encoded method indices.
Thinker K.F. Li <thinker@codemud.net>
parents:
138
diff
changeset
|
749 pass |
137
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
750 pass |
987fead83ce3
Fix issue that dalvik complaining fail to verify code.
Thinker K.F. Li <thinker@codemud.net>
parents:
136
diff
changeset
|
751 pass |
142
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
752 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
753 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
754 ## \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
|
755 # |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
756 # 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
|
757 # 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
|
758 # 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
|
759 # |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
760 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
|
761 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
|
762 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
|
763 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
|
764 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
765 _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
|
766 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
767 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
|
768 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
769 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
|
770 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
|
771 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
772 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
|
773 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
|
774 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
775 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
|
776 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
|
777 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
|
778 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
779 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
|
780 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
|
781 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
|
782 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
783 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
|
784 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
|
785 |
50d09eba5166
Fix the issue of getting negative indices for _DEX_ClassData.
Thinker K.F. Li <thinker@codemud.net>
parents:
141
diff
changeset
|
786 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
|
787 pass |