Exemplo n.º 1
0
    def default(self):
        """Default command"""

        if self.app.pargs.location and self.app.pargs.suffix:
            self.location = self.app.pargs.location
            self.suffix = self.app.pargs.suffix

            # Create new parser
            parser = SmaliParser(self.location, self.suffix)
            parser.run()

            # Output results
            if (self.app.pargs.output) and (self.app.pargs.fileformat):
                results = parser.get_results()
                app = App(__name__)

                # Add additional info
                app.add_location(self.location)
                app.add_parser("%s - %s" %
                               (config.PROJECT_NAME, config.PROJECT_VERSION))

                # Append classes
                for c in results:
                    app.add_class_obj(c)

                # Write results to JSON
                if self.app.pargs.fileformat == 'json':
                    log.info("Exporting results to JSON")
                    app.write_json(self.app.pargs.output)
                    log.info("\tWrote results to %s" % self.app.pargs.output)

                # Write results to sqlite
                elif self.app.pargs.fileformat == 'sqlite':
                    appSQL = AppSQLModel(self.app.pargs.output)

                    try:
                        log.info("Exporting results to SQLite")
                        # Add classes
                        log.info("\tExtract classes ...")
                        for c in app.get_classes():
                            appSQL.add_class(c)

                        # Add properties
                        log.info("\tExtract class properties ...")
                        for p in app.get_properties():
                            appSQL.add_property(p)

                        # Add const-strings
                        log.info("\tExtract class const-strings ...")
                        for c in app.get_const_strings():
                            appSQL.add_const_string(c)

                        # Add methods
                        log.info("\tExtract class methods ...")
                        for m in app.get_methods():
                            appSQL.add_method(m)

                        # Add calls
                        log.info("\tExtract calls ...")
                        for c in app.get_calls():
                            appSQL.add_call(c)

                        # Commit changes
                        log.info("\tCommit changes to SQLite DB")
                        appSQL.commit()
                        log.info("\tWrote results to %s" %
                                 self.app.pargs.output)

                    finally:
                        log.info("Finished scanning")
    def default(self):
        """Default command"""

        if self.app.pargs.location and self.app.pargs.suffix:
            self.location = self.app.pargs.location
            self.suffix = self.app.pargs.suffix

            # How many jobs (workers)?
            if self.app.pargs.jobs and self.app.pargs.jobs > 0:
                self.jobs = self.app.pargs.jobs
            else:
                self.jobs = multiprocessing.cpu_count()

            # Walk location to which depth?
            if self.app.pargs.depth and self.app.pargs.depth > 0:
                self.depth = self.app.pargs.depth
            else:
                self.depth = 1

            # Create new concurrent parser instance
            concurrent_parser = ConcurrentParser(
                self.location, self.suffix,
                self.jobs, self.depth)
            concurrent_parser.walk_location()
            concurrent_parser.run()

            # Output results
            if (self.app.pargs.output) and (self.app.pargs.fileformat):
                results = concurrent_parser.get_results()
                app = App(__name__)

                # Add additional info
                app.add_location(self.location)
                app.add_parser("%s - %s" % (config.PROJECT_NAME, config.PROJECT_VERSION))

                # Append classes
                for c in results:
                    app.add_class_obj(c)

                # Write results to JSON
                if self.app.pargs.fileformat == 'json':
                    log.info("Exporting results to JSON")
                    app.write_json(self.app.pargs.output)
                    log.info("\tWrote results to %s" % self.app.pargs.output)

                # Write results to sqlite
                elif self.app.pargs.fileformat == 'sqlite':
                    appSQL = AppSQLModel(self.app.pargs.output)

                    try:
                        log.info("Exporting results to SQLite")
                        # Add classes
                        log.info("\tExtract classes ...")
                        for c in app.get_classes():
                            appSQL.add_class(c)

                        # Add properties
                        log.info("\tExtract class properties ...")
                        for p in app.get_properties():
                            appSQL.add_property(p)

                        # Add const-strings
                        log.info("\tExtract class const-strings ...")
                        for c in app.get_const_strings():
                            appSQL.add_const_string(c)

                        # Add methods
                        log.info("\tExtract class methods ...")
                        for m in app.get_methods():
                            appSQL.add_method(m)

                        # Add calls
                        log.info("\tExtract calls ...")
                        for c in app.get_calls():
                            appSQL.add_call(c)

                        # Commit changes
                        log.info("\tCommit changes to SQLite DB")
                        appSQL.commit()
                        log.info("\tWrote results to %s" % self.app.pargs.output)

                    finally:
                        log.info("Finished scanning")