コード例 #1
0
 def test_clone_returns_other_args_equal_to_original_args(self):
     args = Bin2PatArguments(input_files=(StandaloneFile('mod.o'), ),
                             output_file=StandaloneFile('mod.o.yara'),
                             args='--arg')
     cloned_args = args.clone()
     self.assertIsNot(args, cloned_args)
     self.assertEqual(args, cloned_args)
コード例 #2
0
 def test_separator_in_path_is_normalized_to_match_separator_used_by_os(
         self):
     for file in [
             StandaloneFile('dir/file.txt'),
             StandaloneFile('dir\\file.txt')
     ]:
         self.assertEqual(file.path, os.path.join('dir', 'file.txt'))
コード例 #3
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)
コード例 #4
0
 def test_as_list_returns_correct_list_when_static_code_sigfile_is_set(
         self):
     args = DecompilationArguments(
         input_files=(StandaloneFile('file.exe'), ),
         static_code_sigfile=StandaloneFile('file.sig'))
     self.assertEqual(args.as_list,
                      ['file.exe', '--static-code-sigfile', 'file.sig'])
 def test_clone_returns_other_args_equal_to_original_args(self):
     args = FileinfoArguments(input_files=(StandaloneFile('file.exe'), ),
                              config_file=StandaloneFile('file.json'),
                              args='--arg')
     cloned_args = args.clone()
     self.assertIsNot(args, cloned_args)
     self.assertEqual(args, cloned_args)
コード例 #6
0
 def test_log_file_name_returns_correct_name_when_there_are_two_input_files(self):
     self.tool = self.create_tool(
         name='tool',
         args=ToolArguments(
             input_files=(StandaloneFile('file1.exe'), StandaloneFile('file2.exe'))
         )
     )
     self.assertEqual(self.tool.log_file_name, 'tool.log')
コード例 #7
0
 def test_clone_returns_other_args_equal_to_original_args(self):
     args = IDAPluginArguments(input_files=(StandaloneFile('file.exe'), ),
                               idb_file=StandaloneFile('file.idb'),
                               output_file=StandaloneFile('file.c'),
                               args='--arg')
     cloned_args = args.clone()
     self.assertIsNot(args, cloned_args)
     self.assertEqual(args, cloned_args)
コード例 #8
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)
コード例 #9
0
 def test_two_args_having_same_data_are_equal(self):
     args1 = IDAPluginArguments(input_files=(StandaloneFile('file.exe'), ),
                                idb_file=StandaloneFile('file.idb'),
                                args='--arg')
     args2 = IDAPluginArguments(input_files=(StandaloneFile('file.exe'), ),
                                idb_file=StandaloneFile('file.idb'),
                                args='--arg')
     self.assertEqual(args1, args2)
コード例 #10
0
 def test_two_args_having_different_config_files_are_not_equal(self):
     args1 = DecompilationArguments(
         input_files=(StandaloneFile('file.exe'), ),
         config_file=StandaloneFile('file1.json'))
     args2 = DecompilationArguments(
         input_files=(StandaloneFile('file.exe'), ),
         config_file=StandaloneFile('file2.json'))
     self.assertNotEqual(args1, args2)
コード例 #11
0
 def test_two_args_having_different_static_code_archives_are_not_equal(
         self):
     args1 = DecompilationArguments(
         input_files=(StandaloneFile('file.exe'), ),
         static_code_archive=StandaloneFile('file1.a'))
     args2 = DecompilationArguments(
         input_files=(StandaloneFile('file.exe'), ),
         static_code_archive=StandaloneFile('file2.a'))
     self.assertNotEqual(args1, args2)
コード例 #12
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)
コード例 #13
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)
コード例 #14
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)
コード例 #15
0
 def test_with_rebased_files_returns_correct_args_when_there_are_files(
         self):
     args = Bin2PatArguments(input_files=(StandaloneFile('mod.o'), ),
                             output_file=StandaloneFile('mod.o.yara'))
     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', 'mod.o'))
     self.assertEqual(rebased_args.output_file.path,
                      os.path.join(ROOT_DIR, 'outputs', 'mod.o.yara'))
 def test_with_rebased_files_returns_correct_args_when_there_are_files(
         self):
     args = FileinfoArguments(input_files=(StandaloneFile('file.exe'), ),
                              config_file=StandaloneFile('file.json'))
     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.config_file.path,
                      os.path.join(ROOT_DIR, 'outputs', 'file.json'))
コード例 #17
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)))
コード例 #18
0
 def _set_file_attr_if_not_none(self, test_settings, attr_name):
     """Sets ``self.(attr_name + _file)`` to ``StandaloneFile(attr)``
     provided that `test_settings.attr_name` is not ``None``.
     """
     attr = getattr(test_settings, attr_name)
     if attr is not None:
         setattr(self, attr_name + '_file', StandaloneFile(attr))
 def test_clone_but_returns_other_args_equal_to_original_args_except_for_changed_attributes(
         self):
     args = ToolArguments(input_files=(StandaloneFile('file.exe'), ),
                          args='--arg')
     cloned_args = args.clone_but(args='--other-arg')
     self.assertIsNot(args, cloned_args)
     self.assertEqual(cloned_args.input_files, args.input_files)
     self.assertEqual(cloned_args.args, '--other-arg')
コード例 #20
0
 def _remove_paths_from_files_attr(self, attr_name):
     """Removes path from the given files attribute (`str`)."""
     files = getattr(self, attr_name)
     if files is not None:
         new_attr = files.__class__(
             StandaloneFile(file.name) for file in files
         )
         setattr(self, attr_name, new_attr)
コード例 #21
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)
 def test_from_tool_arguments_returns_correct_test_case_name(self):
     name = TestCaseName.from_tool_arguments(
         test_name='Test',
         tool_arguments=ToolArguments(
             input_files=(StandaloneFile('gcd.exe'),),
             args='-a x86'
         )
     )
     self.assertEqual(name, 'Test (gcd.exe -a x86)')
コード例 #23
0
 def _set_files_attr_if_not_none(self, test_settings, attr_name):
     """Sets ``self.(attr_name + _files)`` to a tuple of
     ``StandaloneFile(file)`` provided that `test_settings.attr_name` is not
     ``None``.
     """
     attr = getattr(test_settings, attr_name)
     if attr is not None:
         if not isinstance(attr, tuple):
             attr = (attr,)
         new_attr = tuple(StandaloneFile(file) for file in attr)
         setattr(self, attr_name + '_files', new_attr)
コード例 #24
0
 def test_with_rebased_files_returns_correct_args_when_there_are_files(
         self):
     args = DecompilationArguments(
         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'))
コード例 #25
0
    def from_test_settings(cls, test_settings):
        args = UnpackerArguments()

        # Input file.
        cls._verify_attr_is_set(test_settings, 'input')
        cls._verify_attr_is_not_list(test_settings, 'input')
        args._set_files_attr_if_not_none(test_settings, 'input')

        # Output file.
        args.output_file = StandaloneFile(
            args._get_output_file_name_from_input_file_name())

        # Additional arguments.
        cls._verify_attr_is_not_list(test_settings, 'args')
        args._set_attr_if_not_none(test_settings, 'args')

        return args
コード例 #26
0
    def from_test_settings(cls, test_settings):
        args = R2PluginArguments()

        # Input file.
        cls._verify_attr_is_set(test_settings, 'input')
        cls._verify_attr_is_not_list(test_settings, 'input')
        args._set_files_attr_if_not_none(test_settings, 'input')

        # R2 project file.
        cls._verify_attr_is_not_list(test_settings, 'project')
        args._set_file_attr_if_not_none(test_settings, 'project')

        # R2 init commands.
        args._set_attr_if_not_none(test_settings, 'commands')

        # Output file.
        args.output_file = StandaloneFile(
            args._get_output_file_name_from_input_file_name())

        # Additional arguments.
        cls._verify_attr_is_not_list(test_settings, 'args')
        args._set_attr_if_not_none(test_settings, 'args')

        return args
コード例 #27
0
 def test_as_list_returns_correct_list_when_output_file_is_set(self):
     args = IDAPluginArguments(input_files=(StandaloneFile('file.exe'), ),
                               output_file=StandaloneFile('file.c'))
     self.assertEqual(args.as_list, ['file.exe', '-o', 'file.c'])
コード例 #28
0
 def test_as_list_returns_correct_list_when_just_input_files_are_set(self):
     args = IDAPluginArguments(input_files=(StandaloneFile('file.exe'), ))
     self.assertEqual(args.as_list, ['file.exe'])
コード例 #29
0
 def test_repr_returns_executable_repr_that_creates_original_args(self):
     args = IDAPluginArguments(input_files=(StandaloneFile('file.exe'), ),
                               idb_file=StandaloneFile('file.idb'),
                               output_file=StandaloneFile('file.c'),
                               args='--arg')
     self.assertEqual(args, eval(repr(args)))
コード例 #30
0
 def test_input_file_returns_file_with_correct_name(self):
     args = IDAPluginArguments(input_files=(StandaloneFile('file.exe'), ))
     self.assertEqual(args.input_file.name, 'file.exe')