diff paraspace/dexfile.py @ 108:18be67af7f1e

Use method redirection map for defining redirection
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 01 Aug 2011 12:27:28 +0800
parents 4b3573d039af
children 835336632aba
line wrap: on
line diff
--- a/paraspace/dexfile.py	Sat Jul 30 22:59:09 2011 +0800
+++ b/paraspace/dexfile.py	Mon Aug 01 12:27:28 2011 +0800
@@ -1784,6 +1784,11 @@
     @staticmethod
     def get_method_name(method):
         methodid = method.methodIdx
+        return DEXFile_linked.get_methodid_name(methodid)
+
+    ## \brief Get name string of given method ID.
+    @staticmethod
+    def get_methodid_name(methodid):
         namestrid = methodid.nameIdx
         namestrdata = namestrid.stringDataOff
         name_str = namestrdata.data.data
@@ -1814,11 +1819,6 @@
         idx = self.methodIds.items.index(methodid)
         return idx
 
-    ## \brief Get name of given method ID.
-    @staticmethod
-    def get_methodid_name(methoid):
-        return methoid.nameIdx.stringDataOff.data.data
-
     ## \brief Find the method ID item of given index.
     def find_methodid_idx(self, idx):
         methodid = self.methodIds.items[idx]
@@ -1827,7 +1827,7 @@
     ## \brief Find a method definition with an index to method ID.
     def find_method_idx(self, idx):
         methodid = self.find_methodid_idx(idx)
-        method_name = DEXFile_linked.get_methoid_name(methodid)
+        method_name = DEXFile_linked.get_methodid_name(methodid)
         method_proto = methodid.protoIdx
         method_typeid = methodid.classIdx
         classdef = self.find_class_typeid(method_typeid)
@@ -1849,11 +1849,15 @@
         for tl_typeid1, tl_typeid2 in map(None,
                                           typelist1.typeItems.items,
                                           typelist2.typeItems.items):
-            if tl_typeid1.typeIdx != tl_typeid2.typeIdx:
+            typename1 = DEXFile_linked.get_typeid_name(tl_typeid1.typeIdx)
+            typename2 = DEXFile_linked.get_typeid_name(tl_typeid2.typeIdx)
+            
+            if typename1 != typename2:
                 return False
             pass
         return True
 
+    ## \brief Find the method of given name, prototype and class definition.
     def find_method_name_proto(self, method_name, proto, classdef):
         if not classdef.classDataOffRef.is_true:
             return
@@ -1870,6 +1874,25 @@
             pass
         raise ValueError, 'can not find a method for given name and prototype'
 
+    ## \brief Return index of given method ID.
+    def get_idx_methodid(self, methodid):
+        idx = self.methodIds.items.index(methodid)
+        return idx
+    
+    ## \brief Return method ID for given name, proto, and typeid/
+    def find_methodid_name_proto(self, method_name, proto, typeid):
+        for methodid in self.methodIds.items:
+            if method_name != DEXFile_linked.get_methodid_name(methodid):
+                continue
+            if methodid.classIdx != typeid:
+                continue
+            if not DEXFile_linked. \
+                    _proto_is_compatible(methodid.protoIdx, proto):
+                continue
+            return methodid
+        raise ValueError, 'can not find the method ID for given name, ' \
+            'prototype and type ID'
+
     @staticmethod
     def get_param_typeids_protoid(protoid):
         if not protoid.parametersOffRef.is_true: