Skip to content

Commit 66be5a4

Browse files
committed
Add add-on pipeline for collecting dwarfs from elfs
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 6873047 commit 66be5a4

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

scanpipe/models.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,23 @@ def has_directory_content_fingerprint(self):
19271927
and ~Q(extra_data__directory_content__in=IGNORED_DIRECTORY_FINGERPRINTS)
19281928
)
19291929

1930+
def elfs(self):
1931+
"""
1932+
Resources that are ``files`` and their filetype startswith `elf` and contains any of thes
1933+
`executable`, `relocatable`, `shared object`.
1934+
"""
1935+
return (
1936+
self.files()
1937+
.filter(
1938+
file_type__istartswith="elf",
1939+
)
1940+
.filter(
1941+
Q(file_type__icontains="executable")
1942+
| Q(file_type__icontains="relocatable")
1943+
| Q(file_type__icontains="shared object")
1944+
)
1945+
)
1946+
19301947

19311948
class ScanFieldsModelMixin(models.Model):
19321949
"""Fields returned by the ScanCode-toolkit scans."""
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from pathlib import Path
2+
3+
from elf_inspector.dwarf import get_dwarf_paths
4+
5+
from scanpipe.models import CodebaseResource
6+
from scanpipe.pipelines import Pipeline
7+
from scanpipe.pipes import purldb
8+
from scanpipe.pipes import scancode
9+
10+
11+
class GetDwarfsFromElfs(Pipeline):
12+
"""Get dwarfs from elfs."""
13+
14+
download_inputs = False
15+
is_addon = True
16+
17+
@classmethod
18+
def steps(cls):
19+
return (cls.get_dwarfs_from_elfs,)
20+
21+
def get_dwarfs_from_elfs(self):
22+
"""
23+
Update ``extra_data`` of project with
24+
dwarf data extracted from elf files.
25+
"""
26+
for elf in self.project.codebaseresources.elfs():
27+
data = get_dwarf_paths(Path(self.project.codebase_path / elf.path))
28+
self.project.update_extra_data({elf.path: data})

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ install_requires =
7777
fetchcode-container==1.2.3.210512; sys_platform == "linux"
7878
# Inspectors
7979
python-inspector==0.10.0
80+
elf-inspector==0.0.1
8081
aboutcode-toolkit==10.1.0
8182
# Utilities
8283
XlsxWriter==3.1.9
@@ -126,6 +127,7 @@ scancodeio_pipelines =
126127
analyze_root_filesystem_or_vm_image = scanpipe.pipelines.root_filesystem:RootFS
127128
analyze_windows_docker_image = scanpipe.pipelines.docker_windows:DockerWindows
128129
find_vulnerabilities = scanpipe.pipelines.find_vulnerabilities:FindVulnerabilities
130+
get_dwarfs_from_elfs = scanpipe.pipelines.get_dwarfs_from_elfs:GetDwarfsFromElfs
129131
inspect_packages = scanpipe.pipelines.inspect_packages:InspectPackages
130132
load_inventory = scanpipe.pipelines.load_inventory:LoadInventory
131133
map_deploy_to_develop = scanpipe.pipelines.deploy_to_develop:DeployToDevelop

0 commit comments

Comments
 (0)