def call_extraction(file_info, extracthex, reset, annotate):
    try:
        (path, filename, deps) = file_info
    except UF.CHBError as e:
        print(str(e.wrap()))
        exit(1)

    if not UF.check_executable(path, filename):
        try:
            extract(path, filename, deps, extracthex, annotate)
        except subprocess.CalledProcessError as args:
            print(args.output)
            print(args)
            return

    if reset:
        chdir = UF.get_ch_dir(path, filename)
        if os.path.isdir(chdir):
            print('Removing ' + chdir)
            shutil.rmtree(chdir)
        if not UF.unpack_tar_file(path, filename):
            print('*' * 80)
            print('Error in unpacking tar.gz file with executable content')
            print('*' * 80)
            exit(1)
Esempio n. 2
0
def extract(path, filename, args, xinfo):
    deps = args.thirdpartysummaries

    if not (xinfo.is_mips() or xinfo.is_x86()):
        print_architecture_failure(xinfo)
    if not (xinfo.is_elf() or xinfo.is_pe32()):
        print_format_failure(xinfo)

    fixup = {}
    if args.fixup:
        try:
            with open(args.fixup) as fp:
                fixup = json.load(fp)['fixups']
        except Exception as e:
            exit_with_msg('Error in loading fixup file: ' + str(e))
    try:
        if not UF.check_executable(path, filename):
            am = AM.AnalysisManager(path,
                                    filename,
                                    deps=deps,
                                    mips=xinfo.is_mips(),
                                    elf=xinfo.is_elf(),
                                    fixup=fixup)
            print('Extracting executable content into xml ...')
            result = am.extract_executable('-extract')
            if not (result == 0):
                exit_with_msg(
                    'Error in extracting executable; please check format')
            am.save_extract()
    except subprocess.CalledProcessError as e:
        print(e.output)
        print(e.args)
        exit(1)
    except UF.CHBError as e:
        print(str(e.wrap()))
        exit(1)
Esempio n. 3
0
            exit(1)
        am.save_extract()
    except subprocess.CalledProcessError as e:
        print(e.output)
        print(e.args)
        exit(1)


if __name__ == '__main__':

    args = parse()

    try:
        (path, filename,
         deps) = UF.get_path_filename_deps('x86-pe', args.filename)
        if not UF.check_executable(path, filename):
            extract(path, filename, deps, args.extracthex)
    except UF.CHBError as e:
        print(str(e.wrap()))
        exit(1)

    UF.check_analyzer()
    am = AM.AnalysisManager(path, filename, deps=deps)

    if args.reset:
        chdir = UF.get_ch_dir(path, filename)
        if os.path.isdir(chdir):
            print('Removing ' + chdir)
            shutil.rmtree(chdir)
        if not UF.unpack_tar_file(path, filename):
            print('*' * 80)