コード例 #1
0
    def actionXref(self):
        cursor = self.textCursor()
        start = cursor.selectionStart()
        end = cursor.selectionEnd()
        selection = cursor.selection().toPlainText()
        androconf.debug("Xref asked for '%s' (%d, %d)" %
                        (selection, start, end))

        if start not in self.doc.binding.keys():
            self.mainwin.showStatus("Xref not available. No info for: '%s'." %
                                    selection)
            return

        class_ = None
        method_ = None
        t = self.doc.binding[start]
        if t[0] == 'NAME_METHOD_PROTOTYPE':
            class_ = self.path
            method_ = t[1]
            if method_ == self.title:
                method_ = 'init'
        elif t[0] == 'NAME_METHOD_INVOKE':
            class_, method_ = t[2].split(' -> ')
            if class_ == 'this':
                class_ = self.path
            else:
                class_ = classdot2class(class_)
        elif t[0] == 'NAME_PROTOTYPE':
            class_ = classdot2class(t[2] + '.' + t[1])
        else:
            self.mainwin.showStatus(
                "Xref not available. Info ok: '%s' but object not supported." %
                selection)
            return

        androconf.debug(
            "Found corresponding method: %s -> %s in source file: %s" %
            (class_, method_, self.path))

        from androguard.gui.xrefwindow import XrefDialog
        xrefs_list = XrefDialog.get_xrefs_list(self.mainwin.d,
                                               path=class_,
                                               method=method_)
        if not xrefs_list:
            self.mainwin.showStatus("No xref returned")
            return

        xwin = XrefDialog(parent=self,
                          win=self.mainwin,
                          xrefs_list=xrefs_list,
                          path=class_,
                          method=method_)
        xwin.show()
コード例 #2
0
ファイル: sourcewindow.py プロジェクト: 4b1d/androguard
    def actionGoto(self):
        cursor = self.textCursor()
        start = cursor.selectionStart()
        end = cursor.selectionEnd()
        selection = cursor.selectedText()
        androconf.debug("Goto asked for '%s' (%d, %d)" % (selection, start, end))

        if start not in self.doc.binding.keys():
            self.mainwin.showStatus("Goto not available. No info for: '%s'." % selection)
            return

        t = self.doc.binding[start]
        if t[0] == 'NAME_METHOD_INVOKE':
            class_, method_ = t[2].split(' -> ')
            if class_ == 'this':
                class_ = self.path
            else:
                class_ = classdot2class(class_)
        else:
            self.mainwin.showStatus("Goto not available. Info ok: '%s' but object not supported." % selection)
            return

        androconf.debug("Found corresponding method: %s -> %s in source file: %s" % (class_, method_, self.path))

        if not self.mainwin.doesClassExist(class_):
            self.mainwin.showStatus("Goto not available. Class: %s not in database." % class_)
            return

        self.mainwin.openSourceWindow(class_, method=method_)
コード例 #3
0
    def actionGoto(self):
        cursor = self.textCursor()
        start = cursor.selectionStart()
        end = cursor.selectionEnd()
        selection = cursor.selectedText()
        androconf.debug("Goto asked for '%s' (%d, %d)" % (selection, start, end))

        if start not in self.doc.binding.keys():
            self.mainwin.showStatus("Goto not available. No info for: '%s'." % selection)
            return

        t = self.doc.binding[start]
        if t[0] == 'NAME_METHOD_INVOKE':
            class_, method_ = t[2].split(' -> ')
            if class_ == 'this':
                class_ = self.path
            else:
                class_ = classdot2class(class_)
        else:
            self.mainwin.showStatus("Goto not available. Info ok: '%s' but object not supported." % selection)
            return

        androconf.debug("Found corresponding method: %s -> %s in source file: %s" % (class_, method_, self.path))

        if not self.mainwin.doesClassExist(class_):
            self.mainwin.showStatus("Goto not available. Class: %s not in database." % class_)
            return

        self.mainwin.openSourceWindow(class_, method=method_)
コード例 #4
0
ファイル: sourcewindow.py プロジェクト: 4b1d/androguard
    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
コード例 #5
0
ファイル: sourcewindow.py プロジェクト: 4b1d/androguard
    def actionXref(self):
        cursor = self.textCursor()
        start = cursor.selectionStart()
        end = cursor.selectionEnd()
        selection = cursor.selectedText()
        androconf.debug("Xref asked for '%s' (%d, %d)" % (selection, start, end))

        if start not in self.doc.binding.keys():
            self.mainwin.showStatus("Xref not available. No info for: '%s'." % selection)
            return

        class_ = None
        method_ = None
        t = self.doc.binding[start]
        if t[0] == 'NAME_METHOD_PROTOTYPE':
            class_ = self.path
            method_ = t[2].method
            if t[1] == self.title:
                method_ = 'init'
        elif t[0] == 'NAME_METHOD_INVOKE':
            class_, method_ = t[2].split(' -> ')
            if class_ == 'this':
                class_ = self.path
            else:
                class_ = classdot2class(class_)
        elif t[0] == 'NAME_PROTOTYPE':
            class_ = classdot2class(t[2] + '.' + t[1])
        else:
            self.mainwin.showStatus("Xref not available. Info ok: '%s' but object not supported." % selection)
            return

        androconf.debug("Found corresponding method: %s -> %s in source file: %s" % (class_, method_, self.path))

        from androguard.gui.xrefwindow import XrefDialog
        xrefs_list = XrefDialog.get_xrefs_list(self.mainwin.d, path=class_, method=method_)
        if not xrefs_list:
            self.mainwin.showStatus("No xref returned")
            return

        xwin = XrefDialog(parent=self, win=self.mainwin, xrefs_list=xrefs_list, path=class_, method=method_)
        xwin.show()
コード例 #6
0
    def item2path(self, item, column=0):
        '''Browse all parents from QTreeWidgetItem item
           in order to rebuild the complete path
           Return both complete path (ex: "Landroid/support/AccessibilityServiceInfoCompat$1;")
           and path_elts (ex: [u'Landroid', u'support', u'AccessibilityServiceInfoCompat$1;'])
        '''

        path_elts = []
        while item is not None:
            #            print item.text(column)
            path_elts.append(item.text(column))
            item = item.parent()
        path_elts.reverse()
        path = ".".join(path_elts)
        path = classdot2class(path)
        return path, path_elts
コード例 #7
0
ファイル: treewindow.py プロジェクト: AnwarMohamed/androguard
    def item2path(self, item, column=0):
        '''Browse all parents from QTreeWidgetItem item
           in order to rebuild the complete path
           Return both complete path (ex: "Landroid/support/AccessibilityServiceInfoCompat$1;")
           and path_elts (ex: [u'Landroid', u'support', u'AccessibilityServiceInfoCompat$1;'])
        '''

        path_elts = []
        while item is not None:
#            print item.text(column)
            path_elts.append(item.text(column))
            item = item.parent()
        path_elts.reverse()
        path = ".".join(path_elts)
        path = classdot2class(path)
        return path, path_elts
コード例 #8
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.current_filename))
        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
            method_ = t[1]
            if method_ == self.title:
                method_ = 'init'

            proto_ = t[2].method.proto
            androconf.debug("Found: class=%s, method=%s, proto=%s" %
                            (self.current_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

            method_class_name = self.current_class.get_name()
            method_name = method_
            method_proto = proto_
            current_analysis = self.session.get_analysis(self.current_class)

            method_item = current_analysis.get_method_by_name(
                method_class_name, method_name, method_proto)
            if not method_item:
                self.mainwin.showStatus("Impossible to find the method")
                return

            method_item.set_name(str(newname))  #unicode to ascii
        elif type_ == "CLASS":
            newname_class = classdot2class(package_ + '.' + newname)
            self.mainwin.showStatus("New name: %s" % newname_class)
            class_item = self.current_class  #getattr(self.mainwin.d, classdot2func(class_))
            class_item.set_name(str(newname_class))  #unicode to ascii
            self.mainwin.updateDockWithTree()
        elif type_ == 'FIELD':
            if self.field_name_exist(newname):
                self.mainwin.showStatus("Field name already exist")
                return
            field_item.set_name(str(newname))
        else:
            self.mainwin.showStatus("Unsupported type: %s" % str(type_))
            return
        self.reload_java_sources()
コード例 #9
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
コード例 #10
0
            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
            method_item.set_name(str(newname))  #unicode to ascii
        elif type_ == "CLASS":
            newname_class = classdot2class(package_ + '.' + newname)
            self.mainwin.showStatus("New name: %s" % newname_class)
            class_item = getattr(self.mainwin.d, classdot2func(class_))
            class_item.set_name(str(newname_class))  #unicode to ascii
            self.mainwin.updateDockWithTree()
        elif type_ == 'FIELD':
            if self.field_name_exist(newname):
                self.mainwin.showStatus("Field name already exist")
                return
            field_item.set_name(str(newname))
        else:
            self.mainwin.showStatus("Unsupported type: %s" % str(type_))
            return
        self.reload_java_sources()
コード例 #11
0
ファイル: sourcewindow.py プロジェクト: 4b1d/androguard
                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
            method_item.set_name(str(newname)) #unicode to ascii
        elif type_ == "CLASS":
            newname_class = classdot2class(package_ + '.' + newname)
            self.mainwin.showStatus("New name: %s" % newname_class)
            class_item = getattr(self.mainwin.d, classdot2func(class_))
            class_item.set_name(str(newname_class)) #unicode to ascii
            self.mainwin.updateDockWithTree()
        elif type_ == 'FIELD':
            if self.field_name_exist(newname):
                self.mainwin.showStatus("Field name already exist")
                return
            field_item.set_name(str(newname))
        else:
            self.mainwin.showStatus("Unsupported type: %s" % str(type_))
            return
        self.reload_java_sources()
コード例 #12
0
ファイル: sourcewindow.py プロジェクト: hitstar/lobotomy
    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.current_filename))
        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
            method_ = t[1]
            if method_ == self.title:
                method_ = "init"

            proto_ = t[2].method.proto
            androconf.debug("Found: class=%s, method=%s, proto=%s" % (self.current_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

            method_class_name = self.current_class.get_name()
            method_name = method_
            method_proto = proto_
            current_analysis = self.session.get_analysis(self.current_class)

            method_item = current_analysis.get_method_by_name(method_class_name, method_name, method_proto)
            if not method_item:
                self.mainwin.showStatus("Impossible to find the method")
                return

            method_item.set_name(str(newname))  # unicode to ascii
        elif type_ == "CLASS":
            newname_class = classdot2class(package_ + "." + newname)
            self.mainwin.showStatus("New name: %s" % newname_class)
            class_item = self.current_class  # getattr(self.mainwin.d, classdot2func(class_))
            class_item.set_name(str(newname_class))  # unicode to ascii
            self.mainwin.updateDockWithTree()
        elif type_ == "FIELD":
            if self.field_name_exist(newname):
                self.mainwin.showStatus("Field name already exist")
                return
            field_item.set_name(str(newname))
        else:
            self.mainwin.showStatus("Unsupported type: %s" % str(type_))
            return
        self.reload_java_sources()