예제 #1
0
파일: testutils.py 프로젝트: 5l1v3r1/dtf
def undeploy():

    """Delete the test project"""

    utils.delete_file(DTF_CONFIG)
    utils.delete_file(DTF_LOG_FILE)
    utils.delete_tree(LOCAL_MODULES_DIRECTORY)
예제 #2
0
def test_apktool():
    """Run test apktool command"""

    data_file = testutils.DataFile("hello-world.apk")

    stdout, stderr, rtn = included.apktool("d %s" % str(data_file))

    utils.delete_tree("hello-world")

    assert rtn == 0
예제 #3
0
파일: testutils.py 프로젝트: 5l1v3r1/dtf
    def tearDown(self):

        """Remove mock project"""

        # Remove all content and main.db
        utils.delete_file(DTF_DB)

        utils.delete_file(DTF_CONFIG)
        utils.delete_file(DTF_LOG_FILE)
        utils.delete_tree(LOCAL_MODULES_DIRECTORY)
        utils.delete_tree(REPORTS_DIRECTORY)
예제 #4
0
def test_smali():
    """Run test smali/baksmali command"""

    data_file = testutils.DataFile("hello-world.apk")

    stdout, stderr, rtn_bak = included.baksmali("-o out %s" % str(data_file))
    stdout, stderr, rtn_smali = included.smali("-o classes.dex out")

    utils.delete_tree("out")
    utils.delete_file("classes.dex")

    assert rtn_bak == 0
    assert rtn_smali == 0
예제 #5
0
def initialize_from_tar(tar_path, is_full=False, clean_up=False):
    """Initialize from a remote TAR"""

    # Step 1 is to unpack our TAR. Let's delete what was there first.
    utils.delete_tree(dtfglobals.DTF_INCLUDED_DIR)
    __unpack_included(tar_path)

    # Next, we do the the auto config. If its not clean, save the config
    if is_full:
        parser = configparser.SafeConfigParser()

        if __do_client_section(parser) != 0:
            log.e(TAG, "Error building client section of config!")
            return -1

        if __do_bindings_section(parser) != 0:
            log.e(TAG, "Error building bindings section of config!")
            return -1

        if __do_config_section(parser) != 0:
            log.e(TAG, "Error building global section of config!")
            return -1
    else:
        # Not clean means we don't want to disturb other content in the
        parser = dtfglobals.get_copy()

        if __do_bindings_section(parser) != 0:
            return -1

    # Next, we always want to set the version.
    version_string = __parse_version()
    parser.set(dtfglobals.CONFIG_SECTION_BINDINGS, 'version', version_string)

    # Save out the new config.
    __write_globals(parser)

    if clean_up:
        utils.delete_file(tar_path)

    return 0
예제 #6
0
def __do_package_delete(item):
    """Perform the package removal"""

    file_path = DTF_PACKAGES_DIR + item.install_name

    if utils.delete_tree(file_path) != 0:
        log.e(TAG, "Error removing tree! Continuing.")

    conn = sqlite3.connect(DTF_DB)
    cur = conn.cursor()

    # Remove the line first.
    sql = ('DELETE FROM packages ' "WHERE name='%s'" % item.name)

    cur.execute(sql)
    conn.commit()

    return 0
예제 #7
0
def purge():
    """Perform database purge"""

    log.i(TAG, "Starting purge....")

    dtf_db = sqlite3.connect(DTF_DB)
    cur = dtf_db.cursor()

    # Remove Binaries
    sql = ('SELECT name, install_name ' 'FROM binaries')

    for row in cur.execute(sql):

        binary_name = row[0]
        install_name = row[1]
        full_path = DTF_BINARIES_DIR + install_name
        log.d(TAG, "Removing binary '%s'" % binary_name)

        if utils.delete_file(full_path) != 0:
            log.e(TAG, "Error removing binary file! Continuing.")

    # Remove Libraries
    sql = ('SELECT name, install_name ' 'FROM libraries')

    for row in cur.execute(sql):

        library_name = row[0]
        install_name = row[1]
        full_path = DTF_LIBRARIES_DIR + install_name
        log.d(TAG, "Removing library '%s'" % library_name)

        if utils.delete_tree(full_path) != 0:
            log.e(TAG, "Error removing library! Continuing.")

    # Remove Modules
    sql = ('SELECT name, install_name ' 'FROM modules')

    for row in cur.execute(sql):

        module_name = row[0]
        install_name = row[1]
        full_path = DTF_MODULES_DIR + install_name
        log.d(TAG, "Removing module '%s'" % module_name)

        if utils.delete_file(full_path) != 0:
            log.e(TAG, "Error removing module file! Continuing.")

    # Remove Packages
    sql = ('SELECT name, install_name ' 'FROM packages')

    for row in cur.execute(sql):

        package_name = row[0]
        install_name = row[1]
        full_path = DTF_PACKAGES_DIR + install_name
        log.d(TAG, "Removing package '%s'" % package_name)

        if utils.delete_tree(full_path) != 0:
            log.e(TAG, "Error removing package! Continuing.")

    # Drop the DB.
    cur.execute("DROP TABLE IF EXISTS binaries")
    cur.execute("DROP TABLE IF EXISTS libraries")
    cur.execute("DROP TABLE IF EXISTS modules")
    cur.execute("DROP TABLE IF EXISTS packages")

    dtf_db.commit()

    # Rebuilding
    if initialize_db() != 0:
        log.e(TAG, "Unable to re-create dtf db!")
        return -1

    log.i(TAG, "Purge complete!")
    return 0
예제 #8
0
파일: testutils.py 프로젝트: 5l1v3r1/dtf
    def close(self):

        """Close the DataZip"""

        self.zip_f.close()
        utils.delete_tree(self.temp_dir)