def _add_stub_class(self, className, superClassName, st ): """ @param className: Name of new class; example: Lcom/test; @param superClassName: Name of super class; example: Ljava/lang/Object; @param st: Smali tree to save class """ stub_class = ClassNode() stub_class.set_name("L" + PKG_PREFIX + "/" + className[1:]) stub_class.add_access("public") stub_class.set_super_name(superClassName) self.stub_classes[className] = stub_class self.class_map[className] = "L" + PKG_PREFIX + "/" + className[1:] method = MethodNode() method.set_desc("<init>()V") method.add_access(["public", "constructor"]) method.set_registers(1) # i1 = InsnNode("invoke-direct {p0}, Ljava/lang/Object;-><init>()V") #Error! Must not create instance of Object, but of superclass i1 = InsnNode("invoke-direct {p0}, "+superClassName+"-><init>()V") i2 = InsnNode("return-void") method.add_insn([i1, i2]) stub_class.add_method(method) st.add_class(stub_class)
def add_stub_method(self, on, m, parent_class, parent_method, package): #segs = m.split(':', 1) #method_type = segs[0] #m = segs[1] #print on,m method_type = METHOD_TYPE_BY_OPCODE[on] segs = m.rsplit("->", 1) #print on,m,method_type,segs #print parent_class.name, segs[0] # if package in parent_class.name: # print "removing",parent_class.name,package,segs[0] # self.stub_classes.pop(segs[0],None) if self.stub_classes.has_key(segs[0]): stub_class = self.stub_classes[segs[0]] else: stub_class = ClassNode() #stub_class.set_name = "Ldroidbox/java/lang/String" for Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String; invoke-static stub_class.set_name("L" + PKG_PREFIX + "/" + segs[0][1:]) stub_class.add_access("public") stub_class.set_super_name("Ljava/lang/Object;") self.stub_classes[segs[0]] = stub_class self.class_map[segs[0]] = "L" + PKG_PREFIX + "/" + segs[0][1:] #.method public constructor <init>()V # .registers 1 # invoke-direct {p0}, Ljava/lang/Object;-><init>()V # return-void #.end method method = MethodNode() method.set_desc("<init>()V") method.add_access(["public", "constructor"]) method.set_registers(1) i1 = InsnNode("invoke-direct {p0}, Ljava/lang/Object;-><init>()V") i2 = InsnNode("return-void") method.add_insn([i1, i2]) stub_class.add_method(method) method_name = segs[1][:segs[1].find("(")] #print stub_class.name,method_name,method_type,parent_class.name if method_type == "constructor": self.__add_stub_cons2(stub_class, m, parent_class, parent_method) elif method_type == "instance": self.__add_stub_inst(stub_class, on, m, parent_class, parent_method) elif method_type == "static": self.__add_stub_static(stub_class, m, parent_class, parent_method)
def add_stub_method(self, on, m): #segs = m.split(':', 1) #method_type = segs[0] #m = segs[1] method_type = METHOD_TYPE_BY_OPCODE[on] segs = m.rsplit("->", 1) if self.stub_classes.has_key(segs[0]): stub_class = self.stub_classes[segs[0]] else: stub_class = ClassNode() stub_class.set_name("L" + PKG_PREFIX + "/" + segs[0][1:]) stub_class.add_access("public") stub_class.set_super_name("Ljava/lang/Object;") self.stub_classes[segs[0]] = stub_class self.class_map[segs[0]] = "L" + PKG_PREFIX + "/" + segs[0][1:] #.method public constructor <init>()V # .registers 1 # invoke-direct {p0}, Ljava/lang/Object;-><init>()V # return-void #.end method method = MethodNode() method.set_desc("<init>()V") method.add_access(["public", "constructor"]) method.set_registers(1) i1 = InsnNode("invoke-direct {p0}, Ljava/lang/Object;-><init>()V") i2 = InsnNode("return-void") method.add_insn([i1, i2]) stub_class.add_method(method) method_name = segs[1][:segs[1].find("(")] if method_type == "constructor": self.__add_stub_cons2(stub_class, m) elif method_type == "instance": self.__add_stub_inst(stub_class, on, m) elif method_type == "static": self.__add_stub_static(stub_class, m)