예제 #1
0
    def renameElement(self, oldname, newname, info):
        '''Called back after a user chose a new name for an element.
        '''

        androconf.debug("Renaming %s into %s in %s" % (oldname, newname, self.path))
        start, end = info
        try:
            t = self.doc.binding[start]
        except:
            self.mainwin.showStatus("Unexpected error in renameElement")
            return

        # Determine type of the to-be-renamed element and Androguard internal objects
        type_ = None
        if t[0] == 'NAME_METHOD_PROTOTYPE': # method definition in a class
            class_ = self.path
            method_ = t[1]
            if method_ == self.title:
                method_ = 'init'
            proto_ = proto2methodprotofunc(t[2].method.proto)
            androconf.debug("Found: class=%s, method=%s, proto=%s" % (class_, method_, proto_))
            type_ = "METHOD"
        elif t[0] == 'NAME_METHOD_INVOKE': # method call in a method
            class_, method_ = t[2].split(' -> ')
            class_ = classdot2class(class_)
            if class_ == 'this':
                class_ = self.path
            proto_ = proto2methodprotofunc("".join(t[3]) + t[4])
            androconf.debug("Found: class=%s, method=%s, proto=%s" % (class_, method_, proto_))
            type_ = "METHOD"
        elif t[0] == 'NAME_PROTOTYPE': # class definition on top of a class
            class_ = t[2] + '.' + t[1]
            package_ = t[2]
            androconf.debug("Found: package=%s, class=%s" % (package_, class_))
            type_ = "CLASS"
        elif t[0] == 'NAME_FIELD':
            field_item = t[3]
            type_ = "FIELD"
        else:
            self.mainwin.showStatus("Rename not available. Info found: '%s' but object not supported." % selection)
            return

        # Do the actual renaming
        if type_ == "METHOD":
            if self.method_name_exist(newname):
                self.mainwin.showStatus("Method name already exist")
                return

            class_item = getattr(self.mainwin.d, class2func(class_))
            try:
                method_item = getattr(class_item, method2func(method_))
            except AttributeError, e:
                androconf.debug("No attribute %s found for ClassDefItem" % method2func(method_))
                try:
                    method_name = method2func(method_) + '_' + proto_
                    androconf.debug("Backporting to method with prototype in attribute name: %s" % method_name)
                    method_item = getattr(class_item, method_name)
                except AttributeError, e:
                    raise e
예제 #2
0
    def get_xrefs_list(cls, d, path, method=""):
        '''Static method called before creating a XrefDialog 
           to check if there are xrefs to display
            path: complete path of the class we are looking an xref from
            method (optional): method of the class we are looking xref from
        '''

        arg = class2func(path)
        try:
            class_item = getattr(d, arg)
        except AttributeError:
            androconf.debug("no class: %s in DalvikVMFormat d" % arg)
            return None
        if not method:
            item = class_item
        else:
            arg2 = method2func(method)
            try:
                item = getattr(class_item, arg2)
            except AttributeError:
                androconf.debug("no method: %s in class: %s" % (arg2, arg))
                return None
        androconf.debug("Getting XREFs for: %s" % arg)
        if not hasattr(item, "XREFfrom"):
            androconf.debug("No xref found")
            return None

        return XrefDialog.get_xrefs_list_from_element(item)
예제 #3
0
    def get_xrefs_list(cls, d, path, method=""):
        '''Static method called before creating a XrefDialog 
           to check if there are xrefs to display
            path: complete path of the class we are looking an xref from
            method (optional): method of the class we are looking xref from
        '''

        arg = class2func(path)
        try:
            class_item = getattr(d, arg)
        except AttributeError:
            androconf.debug("no class: %s in DalvikVMFormat d" % arg)
            return None
        if not method:
            item = class_item
        else:
            arg2 = method2func(method)
            try:
                item = getattr(class_item, arg2)
            except AttributeError:
                androconf.debug("no method: %s in class: %s" % (arg2, arg))
                return None
        androconf.debug("Getting XREFs for: %s" % arg)
        if not hasattr(item, "XREFfrom"):
            androconf.debug("No xref found")
            return None

        return XrefDialog.get_xrefs_list_from_element(item)
예제 #4
0
    def renameElement(self, oldname, newname, info):
        '''Called back after a user chose a new name for an element.
        '''

        androconf.debug("Renaming %s into %s in %s" %
                        (oldname, newname, self.path))
        start, end = info
        try:
            t = self.doc.binding[start]
        except:
            self.mainwin.showStatus("Unexpected error in renameElement")
            return

        # Determine type of the to-be-renamed element and Androguard internal objects
        type_ = None
        if t[0] == 'NAME_METHOD_PROTOTYPE':  # method definition in a class
            class_ = self.path
            method_ = t[1]
            if method_ == self.title:
                method_ = 'init'
            proto_ = proto2methodprotofunc(t[2].method.proto)
            androconf.debug("Found: class=%s, method=%s, proto=%s" %
                            (class_, method_, proto_))
            type_ = "METHOD"
        elif t[0] == 'NAME_METHOD_INVOKE':  # method call in a method
            class_, method_ = t[2].split(' -> ')
            class_ = classdot2class(class_)
            if class_ == 'this':
                class_ = self.path
            proto_ = proto2methodprotofunc("".join(t[3]) + t[4])
            androconf.debug("Found: class=%s, method=%s, proto=%s" %
                            (class_, method_, proto_))
            type_ = "METHOD"
        elif t[0] == 'NAME_PROTOTYPE':  # class definition on top of a class
            class_ = t[2] + '.' + t[1]
            package_ = t[2]
            androconf.debug("Found: package=%s, class=%s" % (package_, class_))
            type_ = "CLASS"
        elif t[0] == 'NAME_FIELD':
            field_item = t[3]
            type_ = "FIELD"
        else:
            self.mainwin.showStatus(
                "Rename not available. Info found: '%s' but object not supported."
                % selection)
            return

        # Do the actual renaming
        if type_ == "METHOD":
            if self.method_name_exist(newname):
                self.mainwin.showStatus("Method name already exist")
                return

            class_item = getattr(self.mainwin.d, class2func(class_))
            try:
                method_item = getattr(class_item, method2func(method_))
            except AttributeError, e:
                androconf.debug("No attribute %s found for ClassDefItem" %
                                method2func(method_))
                try:
                    method_name = method2func(method_) + '_' + proto_
                    androconf.debug(
                        "Backporting to method with prototype in attribute name: %s"
                        % method_name)
                    method_item = getattr(class_item, method_name)
                except AttributeError, e:
                    raise e