def do_connect(self, args): """ Connect to a Mercury instance usage: connect [--port <port>] ip Use adb forward tcp:31415 tcp:31415 when using an emulator or usb-connected device """ # Define command-line arguments using argparse parser = BaseArgumentParser(prog='connect', add_help=False) parser.add_argument('ip') parser.add_argument('--port', '-p', metavar='<port>') try: # Split arguments using shlex - this means that parameters with spaces can be used - escape " characters inside with \ splitargs = parser.parse_args(shlex.split(args)) if not splitargs: return # Get session ip sessionip = splitargs.ip # Get session port if (splitargs.port): sessionport = int(splitargs.port) else: sessionport = 31415 # Create new session object - display success/failure with session id newsession = Session(splitargs.ip, sessionport, "bind") # Check if connection can be established if newsession.executeCommand("core", "ping", None).data == "pong": # Start new session subconsole = Menu(newsession) subconsole.cmdloop() else: print "\n**Network Error** Could not connect to " + sessionip + ":" + str( sessionport) + "\n" # FIXME: Choose specific exceptions to catch except Exception: print sys.exc_info()[0]
def do_connect(self, args): """ Connect to a Mercury instance usage: connect [--port <port>] ip Use adb forward tcp:31415 tcp:31415 when using an emulator or usb-connected device """ # Define command-line arguments using argparse parser = BaseArgumentParser(prog = 'connect', add_help = False) parser.add_argument('ip') parser.add_argument('--port', '-p', metavar = '<port>') try: # Split arguments using shlex - this means that parameters with spaces can be used - escape " characters inside with \ splitargs = parser.parse_args(shlex.split(args)) if not splitargs: return # Get session ip sessionip = splitargs.ip # Get session port if (splitargs.port): sessionport = int(splitargs.port) else: sessionport = 31415 # Create new session object - display success/failure with session id newsession = Session(splitargs.ip, sessionport, "bind") # Check if connection can be established if newsession.executeCommand("core", "ping", None).data == "pong": # Start new session subconsole = Menu(newsession) subconsole.cmdloop() else: print "\n**Network Error** Could not connect to " + sessionip + ":" + str(sessionport) + "\n" # FIXME: Choose specific exceptions to catch except Exception: print sys.exc_info()[0]
def main(options, arguments) : sessionip = "127.0.0.1" sessionport = 31415 if options.remotehost : sessionip = options.remotehost if options.port : sessionport = int(options.port) newsession = Session(sessionip, sessionport, "bind") # Check if connection can be established if newsession.executeCommand("core", "ping", None).data == "pong": if options.list : request = {'filter': options.list, 'permissions': None } apks_info = newsession.executeCommand("packages", "info", {}).getPaddedErrorOrData() print apks_info elif options.input and options.output : s = None if options.database != None or options.config != None : s = dalvik_elsign.MSignature( options.database, options.config, options.verbose != None, ps = dalvik_elsign.PublicSignature) request = {'filter': options.input, 'permissions': None } apks_info = newsession.executeCommand("packages", "info", request).getPaddedErrorOrData() print apks_info for i in apks_info.split("\n") : if re.match("APK path:", i) != None : name_app = i.split(":")[1][1:] print name_app, response = newsession.downloadFile(name_app, options.output) print response.data, response.error, if s != None : a = apk.APK( options.output + "/" + os.path.basename(name_app) ) if a.is_valid_APK() : display( s.check_apk( a ), options.verbose ) print else: print "\n**Network Error** Could not connect to " + sessionip + ":" + str(sessionport) + "\n"
def main(options, arguments): sessionip = "127.0.0.1" sessionport = 31415 if options.remotehost: sessionip = options.remotehost if options.port: sessionport = int(options.port) newsession = Session(sessionip, sessionport, "bind") # Check if connection can be established if newsession.executeCommand("core", "ping", None).data == "pong": if options.list: request = {'filter': options.list, 'permissions': None} apks_info = newsession.executeCommand("packages", "info", {}).getPaddedErrorOrData() print apks_info elif options.input and options.output: s = None if options.database != None or options.config != None: s = dalvik_elsign.MSignature(options.database, options.config, options.verbose != None, ps=dalvik_elsign.PublicSignature) request = {'filter': options.input, 'permissions': None} apks_info = newsession.executeCommand( "packages", "info", request).getPaddedErrorOrData() print apks_info for i in apks_info.split("\n"): if re.match("APK path:", i) != None: name_app = i.split(":")[1][1:] print name_app, response = newsession.downloadFile(name_app, options.output) print response.data, response.error, if s != None: a = apk.APK(options.output + "/" + os.path.basename(name_app)) if a.is_valid_APK(): display(s.check_apk(a), options.verbose) print else: print "\n**Network Error** Could not connect to " + sessionip + ":" + str( sessionport) + "\n"