changeset 94:88645ab29aeb

dexfile_insert_class() returns a clone object
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 25 Jul 2011 14:22:08 +0800
parents 2fa9b6f21344
children 9373465643e0
files paraspace/dexfile.py paraspace/injection.py
diffstat 2 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dexfile.py	Mon Jul 25 13:23:02 2011 +0800
+++ b/paraspace/dexfile.py	Mon Jul 25 14:22:08 2011 +0800
@@ -1685,6 +1685,19 @@
         linked._copy_attributes(dex)
         
         return linked
+    
+    ## \brief Return name string of a linked class definition item
+    @staticmethod
+    def get_classdef_name(classdef):
+        return classdef.classIdx.descriptorIdx.stringDataOff.data
+    
+    def find_class_name(self, name):
+        for classdef in self.classDefs.items:
+            classdef_name = DEXFile_linked.get_classdef_name(classdef)
+            if classdef_name == name:
+                return classdef
+            pass
+        raise ValueError, 'can not find class definition for \'%s\'' % (name)
     pass
 
 
--- a/paraspace/injection.py	Mon Jul 25 13:23:02 2011 +0800
+++ b/paraspace/injection.py	Mon Jul 25 14:22:08 2011 +0800
@@ -175,9 +175,19 @@
         raise RuntimeError, \
             'clone a class \'%s\'that is already in the DEXFile' % \
             classdef_name(clazz)
-    pass
+    
+    clone = visit_log[id(obj)]
+    return clone
 
 
+## \brief Clone a class definition and insert into a DEXFile.
+#
+# This function clone a class definition from a linked DEXFile and
+# insert it into another one.
+#
+# \param dex is a DEXFile_linked to insert the clone.
+# \param class_def is a class definition going to be cloned.
+#
 def dexfile_insert_class(dex, class_def):
-    _clone_classdef(dex, class_def)
-    pass
+    clone = _clone_classdef(dex, class_def)
+    return clone