Example #1
0
    def do_help(self, args):
        """
        usage: help [COMMAND OR MODULE]

        Displays help information.
        """
        argv = shlex.split(args, comments=True)

        if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"):
            self.do_help("help")
            return

        if len(argv) > 0:
            if self.__module_name(argv[0]) in Module.all(
            ) or self.__module_name("." + argv[0]) in Module.all():
                self.do_run(" ".join([argv[0], "--help"]))
            else:
                try:
                    func = getattr(self, 'help_' + argv[0])
                except AttributeError:
                    try:
                        doc = getattr(self, 'do_' + argv[0]).__doc__
                        if doc:
                            self.stdout.write(
                                "%s\n" %
                                wrap(textwrap.dedent(str(doc)).strip(),
                                     width=console.get_size()[0]))
                            return
                    except AttributeError:
                        pass
                    self.stdout.write("%s\n" % str(self.nohelp) % (argv[0], ))
                    return
                func()
        else:
            cmd.Cmd.do_help(self, args)
Example #2
0
    def do_help(self, args):
        """
        usage: help [COMMAND OR MODULE]

        Displays help information.
        """
        argv = shlex.split(args, comments=True)

        if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"):
            self.do_help("help")
            return

        if len(argv) > 0:
            if self.__module_name(argv[0]) in self.modules.all(permissions=self.permissions()) or self.__module_name("." + argv[0]) in self.modules.all(permissions=self.permissions()):
                self.do_run(" ".join([argv[0], "--help"]))
            else:
                try:
                    func = getattr(self, 'help_' + argv[0])
                except AttributeError:
                    try:
                        doc = getattr(self, 'do_' + argv[0]).__doc__
                        if doc:
                            self.stdout.write("%s\n" % wrap(textwrap.dedent(str(doc)).strip(), width=console.get_size()[0]))
                            return
                    except AttributeError:
                        pass
                    self.stdout.write("%s\n" % str(self.nohelp) % (argv[0],))
                    return
                func()
        else:
            cmd.Cmd.do_help(self, args)
Example #3
0
    def __search_remotes(self, term, include_descriptions=False):
        """
        Search for modules, on remote repositories.
        """

        installer = ModuleInstaller(None)

        try:
            modules = installer.search_index(term)

            if len(modules) > 0:
                for module in modules:
                    print module

                    if include_descriptions:
                        if module.description != None:
                            print "%s\n" % text.indent(
                                text.wrap(module.description,
                                          console.get_size()[0] - 4), "    ")
                        else:
                            print text.indent("No description given.\n",
                                              "    ")
                print
            else:
                print "No modules found.\n"
        except NetworkException:
            print "There was a problem accessing one-or-more of the remote repositories.\n\nMake sure that you have a working network connection.\n"
Example #4
0
def format_dict(values, left_margin=0):
    width = { 'gutter': 2, 'left_margin': left_margin, 'total': get_size()[0] - left_margin }
    width['key'] = min([max(map(lambda k: len(k), values.keys()) + [0]), width['total'] / 3])
    width['value'] = width['total'] - (width['gutter'] + width['key'])
    
    template_key_only = "%%%ds%%-%ds\n" % (width['left_margin'], width['key']) 
    template = "%%%ds%%-%ds%%%ds%%-%ds\n" % (width['left_margin'], width['key'], width['gutter'], width['value'])

    keys = values.keys()
    keys.sort()
    
    formatted = ""
    
    for key in keys:
        value = text.wrap(values[key], width['value']).split("\n")
        
        if len(key) > width['key']:
            formatted += template_key_only % ("", key) 
            formatted += template % ("", "", "", value.pop(0))
        else:
            formatted += template % ("", key, "", value.pop(0))
        
        for line in value:
            formatted += template % ("", "", "", line)
    
    return formatted
Example #5
0
    def help_intents(self):
        """
        An intent is an abstract description of an operation to be performed. It can be used with app.activity.start to launch an Activity, app.broadcast.send to send it to any interested BroadcastReceiver components, and app.service.start to communicate with a background Service.
        
        An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.
        
        
        Intent Structure
        ----------------
        The primary pieces of information in an intent are:
        
          action: the general action to be performed
          data: the data to operate on
        
        In addition to these primary attributes, there are a number of secondary attributes that you can also include with an intent:
        
          category: gives additional information about the action to execute
          type: specifies an explicit MIME type (a MIME type) of the data
          component: specifies an explicit component class
          extras: a bundle of any additional information

        Put together, the set of actions, data types, categories, and extra data defines a language for the system allowing for the expression of phrases such as "call john smith's cell". As applications are added to the system, they can extend this language by adding new actions, types, and categories, or they can modify the behavior of existing phrases by supplying their own activities that handle them.


        Intent Formulation
        ------------------
        In drozer, intents are formulated using a set of command-line options. Some of these set a simple String in the Intent:
        
          --action ACTION
          --category CATEGORY
          --component PACKAGE COMPONENT
          --data-uri URI
          --flags FLAG [FLAG ...]
          --mimetype TYPE
        
        When specifying a component, the fully-qualified name of both the package and component must be used, for example to specify the BrowserActivity within the com.android.browser package:
        
          --component com.android.browser com.android.browser.BrowserActivity
          
        Intents can carry messages or commands inside of them in the form of extras. Applications may want to pass additional information inside of the intents they send to one another, possibly containing the data to perform a task on, or any other user-defined task to initiate from the received data.
        
        Passing the extras is a little more complex. You need to tell drozer the data type, key and value:
          
          --extra TYPE KEY VALUE
        
        drozer supports a few common types:
        
          boolean
          byte
          char
          double
          float
          integer
          short
          string
        
        """
        
        self.stdout.write(wrap(textwrap.dedent(self.help_intents.__doc__).strip() + "\n\n", console.get_size()[0]))
Example #6
0
    def __init__(self):
        cmd.Cmd.__init__(self)

        self.__output_redirected = None

        self.aliases = {}
        self.doc_header = "Commands:"
        self.doc_leader = wrap(textwrap.dedent(self.__class__.__doc__))
        self.history_file = None
        self.ruler = " "
        self.stdout = self.stdout
        self.stderr = sys.stderr
Example #7
0
    def formatted_description(self):
        """
        Build a formatted description of a module, including the description,
        usage information, examples and other metadata.
        """

        description = self.description() + "\n\n" +\
                        (self.has_examples() and "Examples:\n" + self.examples() + "\n\n" or "") +\
                        "Last Modified: " + self.module.date + "\n" +\
                        "Credit: " + self.authors() + "\n" +\
                        "License: " + self.module.license + "\n\n"

        return wrap(description, width=console.get_size()[0])
Example #8
0
    def formatted_description(self):
        """
        Build a formatted description of a module, including the description,
        usage information, examples and other metadata.
        """

        description = self.description() + "\n\n" +\
                        (self.has_examples() and "Examples:\n" + self.examples() + "\n\n" or "") +\
                        "Last Modified: " + self.module.date + "\n" +\
                        "Credit: " + self.authors() + "\n" +\
                        "License: " + self.module.license + "\n\n"

        return wrap(description, width=console.get_size()[0])
Example #9
0
    def __init__(self):
        cmd.Cmd.__init__(self)

        self.__completer_stack = []
        self.__history_stack = []
        self.__output_redirected = None

        self.aliases = {}
        self.doc_header = "Commands:"
        self.doc_leader = wrap(textwrap.dedent(self.__class__.__doc__))
        self.history_file = None
        self.ruler = " "
        self.stdout = self.stdout
        self.stderr = sys.stderr
Example #10
0
File: base.py Project: Syi/mercury
    def __description(self):
        """
        Get the description of the module, for inclusion in usage information.
        """

        description = self.__class__.description + "\n\n"
        description = description + "Examples:\n" + self.__class__.examples + "\n\n"
        description = description + "Last Modified: " + self.__class__.date + "\n"
        if isinstance(self.__class__.author, str):
            description = description + "Credit: " + self.__class__.author + "\n"
        else:
            description = description + "Credit: " + ", ".join(self.__class__.author) + "\n"
        description = description + "License: " + self.__class__.license + "\n\n"

        return wrap(description, width=console.get_size()[0])
Example #11
0
    def __description(self):
        """
        Get the description of the module, for inclusion in usage information.
        """

        description = self.__class__.description + "\n\n"
        description = description + "Examples:\n" + self.__class__.examples + "\n\n"
        description = description + "Last Modified: " + self.__class__.date + "\n"
        if isinstance(self.__class__.author, str):
            description = description + "Credit: " + self.__class__.author + "\n"
        else:
            description = description + "Credit: " + ", ".join(
                self.__class__.author) + "\n"
        description = description + "License: " + self.__class__.license + "\n\n"

        return wrap(description, width=console.get_size()[0])
Example #12
0
    def __search_remotes(self, term, include_descriptions=False):
        """
        Search for modules, on remote repositories.
        """

        installer = ModuleInstaller(None)
        modules = installer.search_index(term)

        if len(modules) > 0:
            for module in modules:
                print module

                if include_descriptions:
                    if module.description != None:
                        print "%s\n" % text.indent(text.wrap(module.description, console.get_size()[0] - 4), "    ")
                    else:
                        print text.indent("No description given.\n", "    ")
            print
        else:
            print "No modules found.\n"
Example #13
0
    def do_list(self, args):
        """
        usage: list [FILTER]

        Displays a list of the available modules, optionally filtered by name.

        Examples:

            mercury> list
            activity.forintent
            activity.info
            ... snip ...
            mercury> list debug
            information.debuggable
            mercury>
        """
        argv = shlex.split(args, comments=True)

        if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"):
            self.do_help("list")
            return

        term = len(argv) > 0 and argv[0] or None

        # recalculate the sizing, depending on the size of the user's terminal window
        width = { 'gutter': 2, 'total': console.getSize()[0] }
        width['label'] = width['total'] / 3
        width['desc'] = width['total'] - (width['gutter'] + width['label'])

        for module in filter(lambda m: term == None or m.find(term.lower()) >= 0, self.__modules()):
            name = wrap(Module.get(module).name, width['desc']).split("\n")

            if len(module[len(self.__base):]) > width['label']:
                self.stdout.write(("{:<%d}\n" % width['label']).format(module[len(self.__base):]))
                self.stdout.write(("{:<%d}  {:<%d}\n" % (width['label'], width['desc'])).format("", name.pop(0)))
            else:
                self.stdout.write(("{:<%d}  {:<%d}\n" % (width['label'], width['desc'])).format(module[len(self.__base):], name.pop(0)))

            for line in name:
                self.stdout.write(("{:<%d}  {:<%d}\n" % (width['label'], width['desc'])).format("", line))
Example #14
0
    def __search_remotes(self, term, include_descriptions=False):
        """
        Search for modules, on remote repositories.
        """

        installer = ModuleInstaller(None)
        modules = installer.search_index(term)

        if len(modules) > 0:
            for module in modules:
                print module

                if include_descriptions:
                    if module.description != None:
                        print "%s\n" % text.indent(
                            text.wrap(module.description,
                                      console.get_size()[0] - 4), "    ")
                    else:
                        print text.indent("No description given.\n", "    ")
            print
        else:
            print "No modules found.\n"
Example #15
0
    def __init__(self):
        cmd.Cmd.__init__(self)

        self.__completer_stack = []
        self.__history_stack = []
        self.__output_redirected = None

        self.aliases = {}
        self.doc_header = "Commands:"
        self.doc_leader = wrap(textwrap.dedent(self.__class__.__doc__))
        self.history_file = None
        self.ruler = " "
        self.stdout = self.stdout
        self.stderr = sys.stderr
        self.variables = {}
        "run scanner.misc.native",
        "run app.package.manifest com.boohee.light , run app.activity.start --component com.android.browser com.android.browser.BrowserActivity --flags ACTIVITY_NEW_TASK --data-uri www.baidu.com"
        self.cmds = [
            "run app.activity.start --component com.android.browser com.android.browser.BrowserActivity --flags ACTIVITY_NEW_TASK --data-uri www.baidu.com"
        ]
        self.cmds = [
            "run app.package.attacksurface com.thinksky.itools.markets"
        ]
Example #16
0
    def __search_remotes(self, term, include_descriptions=False):
        """
        Search for modules, on remote repositories.
        """
        
        installer = ModuleInstaller(None)

        try:
            modules = installer.search_index(term)
            
            if len(modules) > 0:
                for module in modules:
                    print module
                    
                    if include_descriptions:
                        if module.description != None:
                            print "%s\n" % text.indent(text.wrap(module.description, console.get_size()[0] - 4), "    ")
                        else:
                            print text.indent("No description given.\n", "    ")
                print
            else:
                print "No modules found.\n"
        except NetworkException:
            print "There was a problem accessing one-or-more of the remote repositories.\n\nMake sure that you have a working network connection.\n"
Example #17
0
    def help_intents(self):
        """
        An intent is an abstract description of an operation to be performed. It can be used with app.activity.start to launch an Activity, app.broadcast.send to send it to any interested BroadcastReceiver components, and app.service.start to communicate with a background Service.
        
        An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.
        
        
        Intent Structure
        ----------------
        The primary pieces of information in an intent are:
        
          action: the general action to be performed
          data: the data to operate on
        
        In addition to these primary attributes, there are a number of secondary attributes that you can also include with an intent:
        
          category: gives additional information about the action to execute
          type: specifies an explicit MIME type (a MIME type) of the data
          component: specifies an explicit component class
          extras: a bundle of any additional information

        Put together, the set of actions, data types, categories, and extra data defines a language for the system allowing for the expression of phrases such as "call john smith's cell". As applications are added to the system, they can extend this language by adding new actions, types, and categories, or they can modify the behavior of existing phrases by supplying their own activities that handle them.


        Intent Formulation
        ------------------
        In drozer, intents are formulated using a set of command-line options. Some of these set a simple String in the Intent:
        
          --action ACTION
          --category CATEGORY
          --component PACKAGE COMPONENT
          --data-uri URI
          --flags FLAG [FLAG ...]
          --mimetype TYPE
        
        When specifying a component, the fully-qualified name of both the package and component must be used, for example to specify the BrowserActivity within the com.android.browser package:
        
          --component com.android.browser com.android.browser.BrowserActivity
          
        Intents can carry messages or commands inside of them in the form of extras. Applications may want to pass additional information inside of the intents they send to one another, possibly containing the data to perform a task on, or any other user-defined task to initiate from the received data.
        
        Passing the extras is a little more complex. You need to tell drozer the data type, key and value:
          
          --extra TYPE KEY VALUE
        
        drozer supports a few common types:
        
          boolean
          byte
          char
          double
          float
          integer
          short
          string
        
        """

        self.stdout.write(
            wrap(
                textwrap.dedent(self.help_intents.__doc__).strip() + "\n\n",
                console.get_size()[0]))