diff paraspace/dexfile.py @ 102:7fcd555d802b

Add the function for finding method with a name
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 27 Jul 2011 09:07:36 +0800
parents b2db11aed6b8
children 61cef1662035
line wrap: on
line diff
--- a/paraspace/dexfile.py	Tue Jul 26 12:46:24 2011 +0800
+++ b/paraspace/dexfile.py	Wed Jul 27 09:07:36 2011 +0800
@@ -1741,6 +1741,34 @@
 
         clone = dexfile_insert_class(self, classdef)
         return clone
+
+    ## \brief Get name string of given method.
+    @staticmethod
+    def get_method_name(method):
+        methodid = method.methodIdx
+        namestrid = methodid.nameIdx
+        namestrdata = namestrid.stringDataOff
+        name_str = namestrdata.data.data
+        return name_str
+
+    ## \brief Find the method of given method name and class definition.
+    #
+    # \param method_name is the method name.
+    # \param classdef is a _DEX_ClassDef.
+    # \return the corresponding _DEX_Method of given method_name and classdef.
+    #
+    def find_method_name(self, method_name, classdef):
+        if not classdef.classDataOffRef.is_true:
+            return
+
+        classdata = classdef.classDataOffRef.value
+        for wmethod in classdata.directMethods.items + \
+                classdata.virtualMethods.items:
+            wmethod_name = DEXFile_linked.get_method_name(wmethod)
+            if method_name == wmethod_name:
+                return wmethod
+            pass
+        pass
     pass