changeset 107:4b3573d039af

Fix bug of DEXFile_linked.find_method_name_proto(). - It miss understood structure of _DEX_Method to get associated _DEX_ProtoId.
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 30 Jul 2011 22:59:09 +0800
parents 7821c6e89622
children 18be67af7f1e
files paraspace/dexfile.py paraspace/injection.py paraspace/tests/injection_test.py
diffstat 3 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dexfile.py	Fri Jul 29 16:17:15 2011 +0800
+++ b/paraspace/dexfile.py	Sat Jul 30 22:59:09 2011 +0800
@@ -1808,6 +1808,12 @@
             pass
         pass
 
+    ## \brief Return index of given method.
+    def get_idx_method(self, method):
+        methodid = method.methodIdx
+        idx = self.methodIds.items.index(methodid)
+        return idx
+
     ## \brief Get name of given method ID.
     @staticmethod
     def get_methodid_name(methoid):
@@ -1858,7 +1864,8 @@
             wmethod_name = DEXFile_linked.get_method_name(wmethod)
             if method_name != wmethod_name:
                 continue
-            if DEXFile_linked._proto_is_compatible(wmethod.protoIdx, proto):
+            wmethodid = wmethod.methodIdx
+            if DEXFile_linked._proto_is_compatible(wmethodid.protoIdx, proto):
                 return wmethod
             pass
         raise ValueError, 'can not find a method for given name and prototype'
--- a/paraspace/injection.py	Fri Jul 29 16:17:15 2011 +0800
+++ b/paraspace/injection.py	Sat Jul 30 22:59:09 2011 +0800
@@ -255,11 +255,9 @@
                 new_method = dex.find_method_name_proto(method_name,
                                                         method_proto,
                                                         classdef)
-            except:
-                print 'NOT FOUND', method_name, method_proto, dex.get_classdef_name(classdef)
-                print DEXFile_linked.dump_protoid(method_proto)
+            except ValueError:
                 return opcode, args
-            new_method_idx = dex.get_index_method(new_method)
+            new_method_idx = dex.get_idx_method(new_method)
             return opcode, (args[0], args[1], new_method_idx,
                             args[3], args[4], args[5], args[6])
         return opcode, args
--- a/paraspace/tests/injection_test.py	Fri Jul 29 16:17:15 2011 +0800
+++ b/paraspace/tests/injection_test.py	Sat Jul 30 22:59:09 2011 +0800
@@ -140,6 +140,9 @@
         fakefile_linked.find_class_name('Lcom/codemud/fakefile/fakefile;')
     clone = dexfile_insert_class(helloworld_linked, fakefile_def)
 
+    init_method = fakefile_linked.find_method_name('<init>', fakefile_def)
+    init_protoid = init_method.methodIdx.protoIdx
+
     File_typeid = helloworld_linked.find_typeid_name('Ljava/io/File;')
     assert File_typeid
     File_typeidx = helloworld_linked.get_idx_typeid(File_typeid)
@@ -163,7 +166,6 @@
                 pass
             elif opcode == dalvik_opcodes.all_opcodes.OP_INVOKE_DIRECT:
                 methodid = helloworld_linked.find_methodid_idx(args[2])
-                print fakefile_codes, code, args[2]
                 assert methodid.classIdx != File_typeid or \
                     code in fakefile_codes
                 pass