示例#1
0
 def test_non_absolute_path(self):
     config_lines = [('location', ['file', 'mprotect'])]
     with self.assertRaises(wxprot.WXPConfigException):
         c = wxprot.Config(
             config_lines=config_lines,
             main_options={'wxprot_emutramp_missing_default': 'MPROTECT'},
             extra_files={'emutramp_available': '1'})
示例#2
0
 def test_build_dicts_from_config_lines(self):
     config_lines = [('location', ['/file', 'mprotect']),
                     ('location', ['/file2/*', 'mprotect']),
                     ('location', ['/file2/', 'wxorx']),
                     ('location', ['/file', 'full'])]
     expected_res = [{
         'exact': True,
         'path': b'/file2/',
         'flags': 8
     }, {
         'exact': False,
         'path': b'/file2/',
         'flags': 15
     }, {
         'exact': True,
         'path': b'/file',
         'flags': 15
     }]
     logging.basicConfig(level=logging.ERROR)
     c = wxprot.Config(
         config_lines=config_lines,
         main_options={'wxprot_emutramp_missing_default': 'MPROTECT'},
         extra_files={'emutramp_available': '1'})
     logging.basicConfig(level=logging.INFO)
     self.assertTrue(len(expected_res) == len(c.dicts))
     for i, e in enumerate(expected_res):
         self.assertTrue(e['exact'] == c.dicts[i]['exact'])
         self.assertTrue(e['path'] == c.dicts[i]['path'])
         self.assertTrue(e['flags'] == c.dicts[i]['flags'])
     self.assertTrue(
         sha1(c.binary).hexdigest() ==
         'ccddb46fbe8b6ff7bdb9e1c56d22d35f1af4d76b')
示例#3
0
 def test_build_xattr_from_single_line_invalid(self):
     c = wxprot.Config(
         xattr=True,
         main_options={'wxprot_emutramp_missing_default': 'MPROTECT'},
         extra_files={'emutramp_available': '1'})
     for i in range(1, len(self.all_flags) + 1):
         for f in combinations(self.all_flags, i):
             f = set(f)
             if f not in self.ok_groups:
                 with self.assertRaises(wxprot.WXPConfigException):
                     c.build_xattr_from_single_line(
                         ['/filename', ','.join(f)])
示例#4
0
 def test_build_xattr_from_single_line_multi_emutramp(self):
     c = wxprot.Config(
         xattr=True,
         main_options={'wxprot_emutramp_missing_default': 'MPROTECT'},
         extra_files={'emutramp_available': '0'})
     with self.assertRaises(wxprot.WXPConfigException):
         c.build_xattr_from_single_line(
             ['filename', 'FULL,EMUTRAMP,EMUTRAMP_OR_MPROTECT'])
     with self.assertRaises(wxprot.WXPConfigException):
         c.build_xattr_from_single_line(
             ['filename', 'FULL,EMUTRAMP,EMUTRAMP_OR_NONE'])
     with self.assertRaises(wxprot.WXPConfigException):
         c.build_xattr_from_single_line(
             ['filename', 'FULL,EMUTRAMP_OR_NONE,EMUTRAMP_OR_MPROTECT'])
示例#5
0
 def test_build_xattr_from_single_line_with_emutramp(self):
     c = wxprot.Config(
         xattr=True,
         main_options={'wxprot_emutramp_missing_default': 'MPROTECT'},
         extra_files={'emutramp_available': '1'})
     for k, v in OK_FLAGS.items():
         for vv in permutations(v, len(v)):
             self.assertEqual(
                 k,
                 c.build_xattr_from_single_line(['/filename',
                                                 ','.join(vv)]))
             self.assertEqual(
                 k,
                 c.build_xattr_from_single_line(
                     ['/filename', ','.join(vv + vv)]))
示例#6
0
 def test_build_xattr_from_single_line_with_emutramp_big(self):
     c = wxprot.Config(
         xattr=True,
         main_options={'wxprot_emutramp_missing_default': 'MPROTECT'},
         extra_files={'emutramp_available': '1'})
     for k, v in self.big_flags.items():
         for vv in v:
             vv = list(vv)
             self.assertEqual(
                 k,
                 c.build_xattr_from_single_line(['/filename',
                                                 ','.join(vv)]))
             self.assertEqual(
                 k,
                 c.build_xattr_from_single_line(
                     ['/filename', ','.join(vv + vv)]))
示例#7
0
 def test_build_dicts_from_binary(self):
     binary = (b'SARAWXPR\x00\x00\x00\x00\x03\x00\x00\x00\x12\x99'
               b'#\xeeP\xaa\xe5Lqo\xd5\x86\xd6\xe4\xc5\x16\xd3'
               b'\xf8!\x01\x07\x00\x08\x00\x01/file2/\x07\x00\x0f'
               b'\x00\x00/file2/\x05\x00\x0f\x00\x01/file')
     config_lines = [('', ['/file2/', 'WXORX']),
                     ('', ['/file2/*', 'MPROTECT, WXORX']),
                     ('', ['/file', 'MPROTECT, WXORX'])]
     c = wxprot.Config(
         binary=binary,
         main_options={'wxprot_emutramp_missing_default': 'MPROTECT'},
         extra_files={'emutramp_available': '1'})
     self.assertTrue(len(config_lines) == len(c.config_lines))
     for i, e in enumerate(config_lines):
         self.assertTrue(e[0] == c.config_lines[i][0])
         self.assertTrue(e[1][0] == c.config_lines[i][1][0])
         self.assertTrue(e[1][1] == c.config_lines[i][1][1])
示例#8
0
 def test_build_xattr_from_single_line_no_emutramp_none(self):
     c = wxprot.Config(
         xattr=True,
         main_options={'wxprot_emutramp_missing_default': 'NONE'},
         extra_files={'emutramp_available': '0'})
     for k, v in OK_FLAGS.items():
         if 'EMUTRAMP' not in v:
             continue
         k &= 0x200
         for vv in permutations(v, len(v)):
             self.assertEqual(
                 k,
                 c.build_xattr_from_single_line(['/filename',
                                                 ','.join(vv)]))
             self.assertEqual(
                 k,
                 c.build_xattr_from_single_line(
                     ['/filename', ','.join(vv + vv)]))
示例#9
0
 def test_build_xattr_from_single_line_no_emutramp_none_big(self):
     c = wxprot.Config(
         xattr=True,
         main_options={'wxprot_emutramp_missing_default': 'NONE'},
         extra_files={'emutramp_available': '0'})
     for k, v2 in self.big_flags.items():
         for v in v2:
             if 'EMUTRAMP' not in v:
                 continue
             k &= 0x200
             vv = list(v)
             self.assertEqual(
                 k,
                 c.build_xattr_from_single_line(['/filename',
                                                 ','.join(vv)]))
             self.assertEqual(
                 k,
                 c.build_xattr_from_single_line(
                     ['/filename', ','.join(vv + vv)]))
示例#10
0
 def test_star_only_path(self):
     config_lines = [('location', ['*', 'mprotect'])]
     c = wxprot.Config(
         config_lines=config_lines,
         main_options={'wxprot_emutramp_missing_default': 'MPROTECT'},
         extra_files={'emutramp_available': '1'})