示例#1
0
 def test_get_faf_bin_dir(self):
     bin_dir = get_faf_bin_dir()
     files_in_bin_dir = [
         os.path.basename(f) for f in get_files_in_dir(bin_dir)
     ]
     self.assertTrue(os.path.isdir(bin_dir))
     self.assertIn('src/bin', bin_dir)
     self.assertIn('passwords.txt', files_in_bin_dir)
示例#2
0
def _unpack_trx(file_path, target_dir):
    path_to_unpacker = path.join(get_faf_bin_dir(), 'untrx')
    return execute_shell_command('fakeroot {} {} {}'.format(path_to_unpacker, file_path, target_dir))
示例#3
0
from os import path

from common_helper_process import execute_shell_command

from helperFunctions.fileSystem import get_faf_bin_dir

name = 'YAFFS'
mime_patterns = ['filesystem/yaffs']
version = '0.4'

path_to_unyaffs = '/usr/bin/unyaffs'
path_to_unyaffs2 = path.join(get_faf_bin_dir(), 'unyaffs2')


def unpack_function(file_path, tmp_dir):
    '''
    file_path specifies the input file.
    tmp_dir should be used to store the extracted files.
    '''
    unpacker = '{} -e'.format(path_to_unyaffs2) if _is_big_endian(
        file_path) else '{} -v'.format(path_to_unyaffs)
    output = execute_shell_command('fakeroot {} {} {}'.format(
        unpacker, file_path, tmp_dir))
    return {'output': output}


def _is_big_endian(file_path):
    with open(file_path, 'br') as fp:
        content = fp.read(10)
        big_endian = content[7:] == b'\x01\xFF\xFF'
    return big_endian
示例#4
0
 def test_get_faf_bin_dir(self):
     bin_dir = get_faf_bin_dir()
     files_in_bin_dir = [os.path.basename(f) for f in get_files_in_dir(bin_dir)]
     self.assertTrue(os.path.isdir(bin_dir))
     self.assertIn('src/bin', bin_dir)
     self.assertIn('custommime.mgc', files_in_bin_dir)
示例#5
0
from common_helper_process import execute_shell_command
import os
from shutil import copyfile

from helperFunctions.fileSystem import get_faf_bin_dir

name = 'tpl-tool'
mime_patterns = ['firmware/tp-link']
version = '0.3'
path_to_unpacker = os.path.join(get_faf_bin_dir(), 'tpl-tool')
CONFIG_FILE = 'main.cfg'


def unpack_function(file_path, tmp_dir):
    '''
    file_path specifies the input file.
    tmp_dir should be used to store the extracted files.
    '''
    # tpl-tool unpacker unpacks files in the directory of the input file -> copy input file and delete afterwards
    tmp_file_path = os.path.join(tmp_dir, os.path.basename(file_path))
    copyfile(file_path, tmp_file_path)

    result = {}

    result['output'] = execute_shell_command('fakeroot {} -x {}'.format(
        path_to_unpacker, tmp_file_path))
    result['header-info'] = execute_shell_command('{} -s {}'.format(
        path_to_unpacker, tmp_file_path))

    os.remove(tmp_file_path)
示例#6
0
# -*- coding: utf-8 -*-

from os import path

from common_helper_process import execute_shell_command

from helperFunctions.fileSystem import get_faf_bin_dir

name = 'Ambarella_RomFS'
mime_patterns = ['filesystem/ambarella-romfs']
version = '0.3'

TOOL_PATH = path.join(get_faf_bin_dir(), "amba_romfs.py")


def unpack_function(file_path, tmp_dir):
    if not path.exists(TOOL_PATH):
        return {
            'output':
            "Error: phantom_firmware_tools not installed! Re-Run the installation script!"
        }

    output = execute_shell_command(
        '(cd {} && fakeroot {} -x -vv -p {})'.format(tmp_dir, TOOL_PATH,
                                                     file_path)) + "\n"
    meta_data = {'output': output}
    return meta_data


# ----> Do not edit below this line <----
def setup(unpack_tool):
示例#7
0
# -*- coding: utf-8 -*-

import re
from os import path, rename

from common_helper_files import get_files_in_dir, delete_file
from common_helper_process import execute_shell_command

from helperFunctions.fileSystem import get_faf_bin_dir

name = 'DJI_drones'
mime_patterns = ['firmware/dji-drone']
version = '0.3.1'

TOOL_PATH = path.join(get_faf_bin_dir(), 'dji_xv4_fwcon.py')


def unpack_function(file_path, tmp_dir):
    if not path.exists(TOOL_PATH):
        return {
            'output':
            'Error: phantom_firmware_tools not installed! Re-Run the installation script!'
        }

    output = execute_shell_command(
        '(cd {} && fakeroot python3 {} -x -vv -p {})'.format(
            tmp_dir, TOOL_PATH, file_path)) + '\n'

    _rename_files(tmp_dir)
    _remove_ini_files(tmp_dir)
    meta_data = {'output': output}
示例#8
0
import os

from common_helper_process.fail_safe_subprocess import execute_shell_command

from helperFunctions.fileSystem import get_faf_bin_dir

name = 'ROSFile'
mime_patterns = ['firmware/ros']
version = '0.7'

TOOL_PATH = os.path.join(get_faf_bin_dir(), 'ros_unpack')


def unpack_function(file_path, tmp_dir):
    '''
    file_path specifies the input file.
    tmp_dir should be used to store the extracted files.
    '''
    output = execute_shell_command(
        '(cd {} && fakeroot {} --extract {})'.format(tmp_dir, TOOL_PATH,
                                                     file_path))
    return {'output': output}


# ----> Do not edit below this line <----
def setup(unpack_tool):
    for item in mime_patterns:
        unpack_tool.register_plugin(item, (unpack_function, name, version))
示例#9
0
# -*- coding: utf-8 -*-

from common_helper_files import get_files_in_dir, delete_file
from common_helper_process import execute_shell_command
from os import path, rename
import re

from helperFunctions.fileSystem import get_faf_bin_dir

name = 'DJI_drones'
mime_patterns = ['firmware/dji-drone']
version = '0.3'

TOOL_PATH = path.join(get_faf_bin_dir(), "dji_fwcon.py")


def unpack_function(file_path, tmp_dir):
    if not path.exists(TOOL_PATH):
        return {
            'output':
            "Error: phantom_firmware_tools not installed! Re-Run the installation script!"
        }

    output = execute_shell_command(
        '(cd {} && fakeroot {} -x -vv -p {})'.format(tmp_dir, TOOL_PATH,
                                                     file_path)) + "\n"

    _rename_files(tmp_dir)
    _remove_ini_files(tmp_dir)
    meta_data = {'output': output}
    return meta_data