示例#1
0
 def __enter__(self):
     self.db_wrapper, self.db_pool_manager = DbFactory.get_wrapper(args)
     args.apk_storage_interface = 'fs'
     (self.storage_manager,
      self.storage_elem) = get_storage_obj(args, self.db_wrapper)
     self.db_purge()
     return self.storage_elem
示例#2
0
def db_wrapper():
    # Update any walker args that need to be adjusted for this instance
    update_args_testing(args)
    # Prepare the database for the tox env
    create_databases(args)
    # Will be executed before the first test
    db_wrapper, db_pool_manager = DbFactory.get_wrapper(args)
    yield db_wrapper
    # Will be executed after the last test
    db_pool_manager.shutdown()
示例#3
0
def db_wrapper_real():
    """Use when the actual DB is required for testing. If it is, the code should be refactored so use the mocked
    version"""
    # Update any walker args that need to be adjusted for this instance
    update_args_testing(args)
    # Prepare the database for the tox env
    create_databases(args)
    # Will be executed before the first test
    db_wrapper, db_pool_manager = DbFactory.get_wrapper(args)
    yield db_wrapper
    # Will be executed after the last test
    db_pool_manager.shutdown()
示例#4
0
 def setUp(self):
     self.storage_init()
     self.db_wrapper, self.db_pool_manager = DbFactory.get_wrapper(args)
     try:
         storage_type = self.storage_type
     except AttributeError:
         storage_type = 'fs'
     if storage_type == 'fs':
         args.apk_storage_interface = 'fs'
     else:
         args.apk_storage_interface = 'db'
     (self.storage_manager, self.storage_elem) = get_storage_obj(args, self.db_wrapper)
     self.db_purge()
     self.storage_elem.delete_file(APK_Type.rgc, APK_Arch.noarch)
示例#5
0
 def __enter__(self):
     self.db_wrapper, self.db_pool_manager = DbFactory.get_wrapper(args)
     args.apk_storage_interface = 'fs'
     (self.storage_manager, self.storage_elem) = get_storage_obj(args, self.db_wrapper)
     self.db_purge()
     self.pogo_versions = {
         APKArch.armeabi_v7a: None,
         APKArch.arm64_v8a: None,
     }
     # determine supported pogo versions
     with open('configs/version_codes.json', 'rb') as fh:
         data = json.load(fh)
         for version in list(data.keys()):
             version_info = version.rsplit('_')
             if version_info[-1] == '32':
                 self.pogo_versions[APKArch.armeabi_v7a] = version_info[0]
             elif version_info[-1] == '64':
                 self.pogo_versions[APKArch.arm64_v8a] = version_info[0]
     return self
示例#6
0
class GetStorage(object):
    cleanup_tables = ['mad_apk_autosearch', 'mad_apks']
    db_wrapper = None
    db_pool_manager = None
    storage_elem = None
    db_wrapper, db_pool_manager = DbFactory.get_wrapper(args)

    def __enter__(self):
        self.db_wrapper, self.db_pool_manager = DbFactory.get_wrapper(args)
        args.apk_storage_interface = 'fs'
        (self.storage_manager,
         self.storage_elem) = get_storage_obj(args, self.db_wrapper)
        self.db_purge()
        return self.storage_elem

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.storage_manager.shutdown()
        self.db_pool_manager.shutdown()

    def db_purge(self):
        for table in GetStorage.cleanup_tables:
            self.db_wrapper.execute('DELETE FROM `%s`' % (table, ),
                                    commit=True)
示例#7
0
class GetStorage(object):
    cleanup_tables = ['mad_apk_autosearch', 'mad_apks']
    db_wrapper = None
    db_pool_manager = None
    storage_elem = None
    db_wrapper, db_pool_manager = DbFactory.get_wrapper(args)

    def __init__(self, api):
        self.api = api

    def __enter__(self):
        self.db_wrapper, self.db_pool_manager = DbFactory.get_wrapper(args)
        args.apk_storage_interface = 'fs'
        (self.storage_manager,
         self.storage_elem) = get_storage_obj(args, self.db_wrapper)
        self.db_purge()
        self.pogo_versions = {
            APKArch.armeabi_v7a: None,
            APKArch.arm64_v8a: None,
        }
        # determine supported pogo versions
        with open('configs/addresses.json', 'rb') as fh:
            data = json.load(fh)
            for version in list(data.keys()):
                version_info = version.rsplit('_')
                if version_info[-1] == '32':
                    self.pogo_versions[APKArch.armeabi_v7a] = version_info[0]
                elif version_info[-1] == '64':
                    self.pogo_versions[APKArch.arm64_v8a] = version_info[0]
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.storage_manager.shutdown()
        self.db_pool_manager.shutdown()

    def db_purge(self):
        self.storage_elem.delete_file(APKType.rgc, APKArch.noarch)
        self.storage_elem.delete_file(APKType.pd, APKArch.noarch)
        self.storage_elem.delete_file(APKType.pogo, APKArch.arm64_v8a)
        self.storage_elem.delete_file(APKType.pogo, APKArch.armeabi_v7a)
        for table in GetStorage.cleanup_tables:
            self.db_wrapper.execute('DELETE FROM `%s`' % (table, ),
                                    commit=True)

    def upload_all(self):
        self.upload_pd(reload=False)
        self.upload_pogo(reload=False)
        self.upload_rgc(reload=False)
        self.api.get('/api/mad_apk/reload')

    def upload_pd(self, reload: bool = True):
        upload_package(self.storage_elem,
                       version="0.1",
                       apk_type=APKType.pd,
                       apk_arch=APKArch.noarch)
        if reload:
            self.api.get('/api/mad_apk/reload')

    def upload_pogo(self, reload: bool = True):
        upload_package(self.storage_elem,
                       version=self.pogo_versions[APKArch.arm64_v8a],
                       apk_type=APKType.pogo,
                       apk_arch=APKArch.arm64_v8a)
        upload_package(self.storage_elem,
                       version=self.pogo_versions[APKArch.armeabi_v7a],
                       apk_type=APKType.pogo,
                       apk_arch=APKArch.armeabi_v7a)
        if reload:
            self.api.get('/api/mad_apk/reload')

    def upload_rgc(self, reload: bool = True):
        upload_package(self.storage_elem,
                       version="0.1",
                       apk_type=APKType.rgc,
                       apk_arch=APKArch.noarch)
        if reload:
            self.api.get('/api/mad_apk/reload')
示例#8
0
文件: start.py 项目: Terrycy/MAD
            logger.error(
                "Some dependencies aren't met. Required: {} (Installed: {})",
                version_error.req, version_error.dist)
            logger.error(
                "Most of the times you can fix it by running: pip3 install -r requirements.txt --upgrade"
            )
            sys.exit(1)


if __name__ == "__main__":
    check_dependencies()

    # TODO: globally destroy all threads upon sys.exit() for example
    install_thread_excepthook()

    db_wrapper, db_pool_manager = DbFactory.get_wrapper(args)
    try:
        instance_id = db_wrapper.get_instance_id()
    except:
        instance_id = None
    data_manager = DataManager(db_wrapper, instance_id)
    MADPatcher(args, data_manager)
    data_manager.clear_on_boot()

    # create folders
    create_folder(args.file_path)
    create_folder(args.upload_path)

    if not args.only_scan and not args.only_routes:
        logger.error("No runmode selected. \nAllowed modes:\n"
                     " -os    ---- start scanner/devicecontroller\n"