# HG changeset patch # User Thinker K.F. Li # Date 1312037949 -28800 # Node ID 4b3573d039af4649c5527b940864921b87f2a3ae # Parent 7821c6e896228ad4280e823659aa39a4469cb968 Fix bug of DEXFile_linked.find_method_name_proto(). - It miss understood structure of _DEX_Method to get associated _DEX_ProtoId. diff -r 7821c6e89622 -r 4b3573d039af paraspace/dexfile.py --- 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' diff -r 7821c6e89622 -r 4b3573d039af paraspace/injection.py --- 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 diff -r 7821c6e89622 -r 4b3573d039af paraspace/tests/injection_test.py --- 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('', 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