Beispiel #1
0
def loadScript(script_content):
    if genv.script is not None:
        genv.script.unload()
    try:
        rdev = genv.get_device()
        process_name = genv.get_pkgname()
        if process_name is None:
            logger.info("Identifier is null, please input.")
            return "no"
        if genv.isAndroid is not None and not genv.isAndroid:
            process_name = genv.allApp[process_name]

        pkg = rdev.get_process(process_name).pid
        genv.session = rdev.attach(pkg)
        # genv.session = frida.get_usb_device().attach("MyFirstIOS")
        logger.info("create_script")
        logger.info("Hook App: %s" % process_name)

        time.sleep(1)
        genv.script = genv.session.create_script(script_content)  # 注册js代码
        logger.info("script_on...")
        genv.script.on("message", on_message)  # on()方法注册message handler
        genv.script.load()
    except frida.ServerNotRunningError as e:
        logger.error("frida-server No Running ....please check.")
        return "no"
    except Exception as e:
        logger.error(
            "Script failed to load, Reason is %s, Try restarting the app to continue loading the script. "
            % e)
        try:
            process_name = genv.get_pkgname()
            if process_name is None:
                logger.info("Identifier is null, please input.")
                return "no"
            pkg = rdev.spawn([process_name])
            genv.session = rdev.attach(pkg)
            rdev.resume(pkg)

            time.sleep(1)

            logger.info("create_script")
            logger.info("Hook App: %s" % process_name)

            genv.script = genv.session.create_script(script_content)  # 注册js代码
            # print(script_content)
            logger.info("script_on...")
            genv.script.on("message", on_message)  # on()方法注册message handler
            genv.script.load()
        except Exception as e:
            logger.error("The script failed to load again, Reason is %s." % e)
            return "no"
Beispiel #2
0
def loadScript(script_content):
    try:
        rdev = genv.get_device()
        process_name = genv.get_pkgname()
        if process_name == None:
            logger.info("PackagaName is null, please input.")
            # print(colored("[ERROR] PackagaName is null, please input.", "red"))
            return
        # if genv.script != None:
        #     logger.info("Script_unload..")
        #     try:
        #         genv.script.unload()
        #     except Exception as e:
        #         print(e)
        pkg = rdev.get_process(process_name).pid
        genv.session = rdev.attach(pkg)
    except frida.ServerNotRunningError as e:
        logger.error(
            "frida-server No Running or port no forward....please check.")
        return
        # print(colored("[ERROR] frida-server No Running or port no forward....please check.", "red"))
        # app.logger.error("frida_server No Running! or port no forward! please check.")
    except frida.ProcessNotFoundError as e:
        pkg = rdev.spawn([process_name])
        genv.session = rdev.attach(pkg)
        rdev.resume(pkg)
    except Exception as e:
        logger.error("loadScript: %s" % e)
        return
        # print(colored("[ERROR] loadScript: %s" % e, "red"))
    # else:
    logger.info("create_script")
    logger.info("Hook App: %s" % process_name)
    # print(colored("[INFO] create_script", "cyan"))
    # print(colored("[INFO] Hook App: %s" % process_name, "cyan"))
    # # print(process)
    # if process:
    #     logger.error("process is null, please check")
    #     # print(colored("[ERROR] .", "red"))
    #     return
    if genv.session is None:
        logger.error("genv.session is null, please check")
        return
    genv.script = genv.session.create_script(script_content)  # 注册js代码
    time.sleep(1)
    logger.info("script_on...")
    # print(colored("[INFO] script_on...", "cyan"))
    genv.script.on("message", on_message)  # on()方法注册message handler
    genv.script.load()
def getApplication():
    try:
        rdev = genv.get_device()
        lists = []
        for i in rdev.enumerate_applications():
            dictitem = {'pkgname': i.identifier, 'name': i.name, 'pid': i.pid}
            lists.append(dictitem)
        # print(lists)
        apparr = {'result': lists}
        socketio.emit('getapp', apparr, namespace='/defchishi')
    except frida.ServerNotRunningError as e:
        logger.error(
            "frida-server No Running or port no forward....please check.")
    except frida.TransportError as e:
        logger.error("with frida_server connection is closed")
Beispiel #4
0
def sleep_load_scipt(script_content):
    try:
        rdev = genv.get_device()
        process_name = genv.get_pkgname()
        if process_name is None:
            logger.info("Identifier is null, please input.")
            return "no"
        pkg = rdev.spawn([process_name])
        genv.session = rdev.attach(pkg)

        logger.info("sleep resume app...")
        logger.info("Hook App: %s" % process_name)

        genv.script = genv.session.create_script(script_content)

        logger.info("script_on...")
        genv.script.on("message", on_message)  # on()方法注册message handler
        genv.script.load()
        rdev.resume(pkg)
    except Exception as e:
        logger.error("The script failed to load again, Reason is %s." % e)
Beispiel #5
0
def get_application():
    try:
        rdev = genv.get_device()
        if rdev is None:
            return

        lists = []
        genv.isAndroid = isAndroid(rdev)

        for i in rdev.enumerate_applications():
            dictitem = {'pkgname': i.identifier, 'name': i.name, 'pid': i.pid}
            genv.allApp[i.identifier] = i.name
            lists.append(dictitem)
        # print(lists)
        apparr = {'result': lists}
        socketio.emit('getapp', apparr, namespace='/defchishi')
    except frida.ServerNotRunningError as e:
        # logger.error(e)
        logger.error(
            "frida-server No Running or port no forward....please check.")
    except frida.TransportError as e:
        logger.error("with frida_server connection is closed")
    except Exception as e:
        logger.error("connect error, {}".format(e))