Exemple #1
0
 def test_with_rebased_files_returns_same_args_when_there_are_no_files(self):
     args = DecompilerArguments()
     rebased_args = args.with_rebased_files(
         Directory(os.path.join(ROOT_DIR, 'inputs')),
         Directory(os.path.join(ROOT_DIR, 'outputs'))
     )
     self.assertEqual(args, rebased_args)
Exemple #2
0
 def test_two_args_having_same_data_are_equal(self):
     args1 = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         pdb_file=StandaloneFile('file.pdb'),
         config_file=StandaloneFile('file.json'),
         static_code_archive=StandaloneFile('file.a'),
         static_code_sigfile=StandaloneFile('file.sig'),
         arch='x86',
         mode='bin',
         hll='c',
         ar_index=0,
         ar_name='file.o',
         args='--arg'
     )
     args2 = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         pdb_file=StandaloneFile('file.pdb'),
         config_file=StandaloneFile('file.json'),
         static_code_archive=StandaloneFile('file.a'),
         static_code_sigfile=StandaloneFile('file.sig'),
         arch='x86',
         mode='bin',
         hll='c',
         ar_index=0,
         ar_name='file.o',
         args='--arg'
     )
     self.assertEqual(args1, args2)
Exemple #3
0
 def test_two_args_having_different_input_files_are_not_equal(self):
     args1 = DecompilerArguments(
         input_files=(StandaloneFile('file1.exe'),)
     )
     args2 = DecompilerArguments(
         input_files=(StandaloneFile('file2.exe'),)
     )
     self.assertNotEqual(args1, args2)
Exemple #4
0
 def test_two_args_having_different_static_code_sigfiles_are_not_equal(self):
     args1 = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         static_code_sigfile=StandaloneFile('file1.sig')
     )
     args2 = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         static_code_sigfile=StandaloneFile('file2.sig')
     )
     self.assertNotEqual(args1, args2)
Exemple #5
0
 def test_two_args_having_different_ar_names_are_not_equal(self):
     args1 = DecompilerArguments(
         input_files=(StandaloneFile('archive.a'),),
         ar_name='file1.o'
     )
     args2 = DecompilerArguments(
         input_files=(StandaloneFile('archive.a'),),
         ar_name='file2.o'
     )
     self.assertNotEqual(args1, args2)
Exemple #6
0
 def test_two_args_having_different_args_are_not_equal(self):
     args1 = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         args='--arg'
     )
     args2 = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         args='--other-arg'
     )
     self.assertNotEqual(args1, args2)
Exemple #7
0
 def test_two_args_having_different_modes_are_not_equal(self):
     args1 = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         mode='bin'
     )
     args2 = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         mode='raw'
     )
     self.assertNotEqual(args1, args2)
Exemple #8
0
 def test_clone_returns_other_args_equal_to_original_args(self):
     args = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         pdb_file=StandaloneFile('file.pdb'),
         config_file=StandaloneFile('file.json'),
         static_code_archive=StandaloneFile('file.a'),
         static_code_sigfile=StandaloneFile('file.sig'),
         arch='x86',
         mode='bin',
         hll='c',
         ar_index=0,
         ar_name='file.o',
         args='--arg'
     )
     cloned_args = args.clone()
     self.assertIsNot(args, cloned_args)
     self.assertEqual(args, cloned_args)
Exemple #9
0
    def test_initialize_tool_dir_and_args_just_returns_args_when_config_file_is_not_set(
            self):
        input_dir = mock.Mock()
        tool_dir = mock.Mock()
        args = DecompilerArguments(input_files=(File('file.exe', input_dir), ))

        new_args = self.decomp_runner._initialize_tool_dir_and_args(
            tool_dir, args)

        self.assertIs(new_args, args)
Exemple #10
0
    def test_initialize_tool_dir_and_args_copies_config_file_when_it_is_set(
            self):
        input_dir = mock.Mock()
        tool_dir = mock.Mock()
        tool_dir.copy_file.return_value = File('file.json', tool_dir)
        args = DecompilerArguments(input_files=(File('file.exe', input_dir), ),
                                   config_file=File('file.json', input_dir))

        new_args = self.decomp_runner._initialize_tool_dir_and_args(
            tool_dir, args)

        tool_dir.copy_file.assert_called_once_with(args.config_file)
        self.assertEqual(new_args.config_file.dir, tool_dir)
Exemple #11
0
 def test_with_rebased_files_returns_correct_args_when_there_are_files(self):
     args = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         pdb_file=StandaloneFile('file.pdb'),
         config_file=StandaloneFile('file.json'),
         static_code_archive=StandaloneFile('file.a'),
         static_code_sigfile=StandaloneFile('file.sig'),
         output_file=StandaloneFile('file.c')
     )
     rebased_args = args.with_rebased_files(
         Directory(os.path.join(ROOT_DIR, 'inputs')),
         Directory(os.path.join(ROOT_DIR, 'outputs'))
     )
     self.assertEqual(len(rebased_args.input_files), 1)
     self.assertEqual(
         rebased_args.input_files[0].path,
         os.path.join(ROOT_DIR, 'inputs', 'file.exe')
     )
     self.assertEqual(
         rebased_args.pdb_file.path,
         os.path.join(ROOT_DIR, 'inputs', 'file.pdb')
     )
     self.assertEqual(
         rebased_args.config_file.path,
         os.path.join(ROOT_DIR, 'inputs', 'file.json')
     )
     self.assertEqual(
         rebased_args.static_code_archive.path,
         os.path.join(ROOT_DIR, 'inputs', 'file.a')
     )
     self.assertEqual(
         rebased_args.static_code_sigfile.path,
         os.path.join(ROOT_DIR, 'inputs', 'file.sig')
     )
     self.assertEqual(
         rebased_args.output_file.path,
         os.path.join(ROOT_DIR, 'outputs', 'file.c')
     )
Exemple #12
0
 def test_repr_returns_executable_repr_that_creates_original_args(self):
     args = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         pdb_file=StandaloneFile('file.pdb'),
         config_file=StandaloneFile('file.json'),
         static_code_archive=StandaloneFile('file.a'),
         static_code_sigfile=StandaloneFile('file.sig'),
         arch='x86',
         mode='bin',
         hll='c',
         ar_index=0,
         ar_name='file.o',
         args='--arg'
     )
     self.assertEqual(args, eval(repr(args)))
Exemple #13
0
 def test_without_paths_and_output_files_returns_correct_args_when_there_are_files(self):
     args = DecompilerArguments(
         input_files=(File('file.exe', Directory(os.path.join(ROOT_DIR, 'inputs'))),),
         pdb_file=File('file.pdb', Directory(os.path.join(ROOT_DIR, 'inputs'))),
         config_file=File('file.json', Directory(os.path.join(ROOT_DIR, 'inputs'))),
         static_code_archive=File('file.a', Directory(os.path.join(ROOT_DIR, 'inputs'))),
         static_code_sigfile=File('file.sig', Directory(os.path.join(ROOT_DIR, 'inputs'))),
         output_file=File('file.c', Directory(os.path.join(ROOT_DIR, 'outputs')))
     )
     stripped_args = args.without_paths_and_output_files
     self.assertEqual(len(stripped_args.input_files), 1)
     self.assertEqual(stripped_args.input_files[0].path, 'file.exe')
     self.assertEqual(stripped_args.pdb_file.path, 'file.pdb')
     self.assertEqual(stripped_args.config_file.path, 'file.json')
     self.assertEqual(stripped_args.static_code_archive.path, 'file.a')
     self.assertEqual(stripped_args.static_code_sigfile.path, 'file.sig')
     self.assertIsNone(stripped_args.output_file)
Exemple #14
0
 def test_as_list_returns_empty_list_when_nothing_is_set(self):
     args = DecompilerArguments()
     self.assertEqual(args.as_list, [])
Exemple #15
0
 def test_as_list_returns_correct_list_when_just_args_is_set(self):
     args = DecompilerArguments(
         args='  --arg1   --arg2  '
     )
     self.assertEqual(args.as_list, ['--arg1', '--arg2'])
Exemple #16
0
 def test_as_list_returns_correct_list_when_just_ar_name_is_set(self):
     args = DecompilerArguments(
         ar_name='file.o',
     )
     self.assertEqual(args.as_list, ['--ar-name', 'file.o'])
Exemple #17
0
 def test_as_list_returns_correct_list_when_just_ar_index_is_set_as_str(self):
     args = DecompilerArguments(
         ar_index='0',
     )
     self.assertEqual(args.as_list, ['--ar-index', '0'])
Exemple #18
0
 def test_as_list_returns_correct_list_when_just_hll_is_set(self):
     args = DecompilerArguments(
         hll='py'
     )
     self.assertEqual(args.as_list, ['-l', 'py'])
Exemple #19
0
 def test_as_list_returns_correct_list_when_just_mode_is_set(self):
     args = DecompilerArguments(
         mode='bin'
     )
     self.assertEqual(args.as_list, ['-m', 'bin'])
Exemple #20
0
 def test_without_paths_and_output_files_returns_same_args_when_there_are_no_files(self):
     args = DecompilerArguments()
     self.assertEqual(args, args.without_paths_and_output_files)
Exemple #21
0
 def test_as_list_returns_correct_list_when_static_code_sigfile_is_set(self):
     args = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         static_code_sigfile=StandaloneFile('file.sig')
     )
     self.assertEqual(args.as_list, ['file.exe', '--static-code-sigfile', 'file.sig'])
Exemple #22
0
 def test_as_list_returns_correct_list_when_just_input_files_are_set(self):
     args = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),)
     )
     self.assertEqual(args.as_list, ['file.exe'])
Exemple #23
0
 def test_from_test_settings_output_file_has_correct_name_when_input_is_other_file(self):
     test_settings = TestSettings(input='file')
     args = DecompilerArguments.from_test_settings(test_settings)
     self.assertEqual(args.output_file.name, 'file.c')
Exemple #24
0
 def scenario_invalid_settings_error_is_raised(self, test_settings, ref_exc_substr):
     with self.assertRaises(InvalidTestSettingsError) as cm:
         DecompilerArguments.from_test_settings(test_settings)
     self.assertIn(ref_exc_substr, str(cm.exception))
Exemple #25
0
 def test_as_list_returns_correct_list_when_config_file_is_set(self):
     args = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),),
         config_file=StandaloneFile('file.json')
     )
     self.assertEqual(args.as_list, ['file.exe', '--config', 'file.json'])
Exemple #26
0
 def test_from_test_settings_args_is_present_when_set(self):
     test_settings = TestSettings(input='file.exe', args='--arg1 --arg2')
     args = DecompilerArguments.from_test_settings(test_settings)
     self.assertEqual(args.args, test_settings.args)
Exemple #27
0
 def test_input_file_returns_file_with_correct_name(self):
     args = DecompilerArguments(
         input_files=(StandaloneFile('file.exe'),)
     )
     self.assertEqual(args.input_file.name, 'file.exe')
 def test_clone_but_preserves_instance_type(self):
     args = DecompilerArguments()
     cloned_args = args.clone_but()
     self.assertIsInstance(cloned_args, DecompilerArguments)
Exemple #29
0
 def test_from_test_settings_ar_name_is_present_when_set(self):
     test_settings = TestSettings(input='archive.a', ar_name='file.o')
     args = DecompilerArguments.from_test_settings(test_settings)
     self.assertEqual(args.ar_name, test_settings.ar_name)
Exemple #30
0
 def test_as_list_returns_correct_list_when_just_arch_is_set(self):
     args = DecompilerArguments(
         arch='x86'
     )
     self.assertEqual(args.as_list, ['-a', 'x86'])