Skip to content

Commit f624009

Browse files
Add test as examples for macho/winpe symbol matching
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 9d41f3e commit f624009

6 files changed

Lines changed: 64 additions & 2 deletions

File tree

scanpipe/pipes/symbolmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
SMALL_FILE_SYMBOLS_THRESHOLD = 20
4242
MATCHING_RATIO_RUST_SMALL_FILE = 0.4
4343
MATCHING_RATIO_ELF = 0.05
44-
MATCHING_RATIO_MACHO = 0.5
45-
MATCHING_RATIO_WINPE = 0.5
44+
MATCHING_RATIO_MACHO = 0.15
45+
MATCHING_RATIO_WINPE = 0.15
4646
MATCHING_RATIO_JAVASCRIPT = 0.7
4747
SMALL_FILE_SYMBOLS_THRESHOLD_JAVASCRIPT = 30
4848
MATCHING_RATIO_JAVASCRIPT_SMALL_FILE = 0.5
22.8 KB
Binary file not shown.
44.8 KB
Binary file not shown.
6.98 KB
Binary file not shown.
367 KB
Binary file not shown.

scanpipe/tests/pipes/test_d2d.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,68 @@ def test_scanpipe_pipes_d2d_map_elf_symbols(self):
15991599
).count(),
16001600
)
16011601

1602+
@skipIf(sys.platform == "darwin", "Test is failing on macOS")
1603+
def test_scanpipe_pipes_d2d_map_macho_symbols(self):
1604+
input_dir = self.project1.input_path
1605+
input_resources = [
1606+
self.data / "d2d-macho/from-lumen.zip",
1607+
self.data / "d2d-macho/to-lumen.zip",
1608+
]
1609+
copy_inputs(input_resources, input_dir)
1610+
self.from_files, self.to_files = d2d.get_inputs(self.project1)
1611+
inputs_with_codebase_path_destination = [
1612+
(self.from_files, self.project1.codebase_path / d2d.FROM),
1613+
(self.to_files, self.project1.codebase_path / d2d.TO),
1614+
]
1615+
for input_files, codebase_path in inputs_with_codebase_path_destination:
1616+
for input_file_path in input_files:
1617+
scancode.extract_archive(input_file_path, codebase_path)
1618+
1619+
scancode.extract_archives(
1620+
self.project1.codebase_path,
1621+
recurse=True,
1622+
)
1623+
pipes.collect_and_create_codebase_resources(self.project1)
1624+
buffer = io.StringIO()
1625+
d2d.map_macho_binaries_with_symbols(project=self.project1, logger=buffer.write)
1626+
self.assertEqual(
1627+
9,
1628+
CodebaseRelation.objects.filter(
1629+
project=self.project1, map_type="macho_symbols"
1630+
).count(),
1631+
)
1632+
1633+
@skipIf(sys.platform == "darwin", "Test is failing on macOS")
1634+
def test_scanpipe_pipes_d2d_map_winpe_symbols(self):
1635+
input_dir = self.project1.input_path
1636+
input_resources = [
1637+
self.data / "d2d-winpe/to-translucent.zip",
1638+
self.data / "d2d-winpe/from-translucent.zip",
1639+
]
1640+
copy_inputs(input_resources, input_dir)
1641+
self.from_files, self.to_files = d2d.get_inputs(self.project1)
1642+
inputs_with_codebase_path_destination = [
1643+
(self.from_files, self.project1.codebase_path / d2d.FROM),
1644+
(self.to_files, self.project1.codebase_path / d2d.TO),
1645+
]
1646+
for input_files, codebase_path in inputs_with_codebase_path_destination:
1647+
for input_file_path in input_files:
1648+
scancode.extract_archive(input_file_path, codebase_path)
1649+
1650+
scancode.extract_archives(
1651+
self.project1.codebase_path,
1652+
recurse=True,
1653+
)
1654+
pipes.collect_and_create_codebase_resources(self.project1)
1655+
buffer = io.StringIO()
1656+
d2d.map_winpe_binaries_with_symbols(project=self.project1, logger=buffer.write)
1657+
self.assertEqual(
1658+
4,
1659+
CodebaseRelation.objects.filter(
1660+
project=self.project1, map_type="winpe_symbols"
1661+
).count(),
1662+
)
1663+
16021664
@mock.patch("scanpipe.pipes.purldb.match_resources")
16031665
def test_scanpipe_pipes_d2d_match_purldb_resource_no_package_data(
16041666
self, mock_match_resource

0 commit comments

Comments
 (0)