Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an add-on pipeline for collecting dwarfs from elfs #1068

Merged
merged 15 commits into from
Feb 19, 2024
Next Next commit
Add add-on pipeline for collecting dwarfs from elfs
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
  • Loading branch information
TG1999 committed Feb 19, 2024
commit 8051ec755cdb862027d35d0081388fab64605b7c
17 changes: 17 additions & 0 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,23 @@ def has_directory_content_fingerprint(self):
and ~Q(extra_data__directory_content__in=IGNORED_DIRECTORY_FINGERPRINTS)
)

def elfs(self):
"""
Resources that are ``files`` and their filetype startswith `elf` and contains any of thes
`executable`, `relocatable`, `shared object`.
"""
return (
self.files()
.filter(
file_type__istartswith="elf",
)
.filter(
Q(file_type__icontains="executable")
| Q(file_type__icontains="relocatable")
| Q(file_type__icontains="shared object")
)
)


class ScanFieldsModelMixin(models.Model):
"""Fields returned by the ScanCode-toolkit scans."""
Expand Down
28 changes: 28 additions & 0 deletions scanpipe/pipelines/get_dwarfs_from_elfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from pathlib import Path

from elf_inspector.dwarf import get_dwarf_paths

from scanpipe.models import CodebaseResource
from scanpipe.pipelines import Pipeline
from scanpipe.pipes import purldb
from scanpipe.pipes import scancode


class GetDwarfsFromElfs(Pipeline):
"""Get dwarfs from elfs."""

download_inputs = False
is_addon = True

@classmethod
def steps(cls):
return (cls.get_dwarfs_from_elfs,)

def get_dwarfs_from_elfs(self):
"""
Update ``extra_data`` of project with
dwarf data extracted from elf files.
"""
for elf in self.project.codebaseresources.elfs():
data = get_dwarf_paths(Path(self.project.codebase_path / elf.path))
self.project.update_extra_data({elf.path: data})
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ install_requires =
# FetchCode
fetchcode-container==1.2.3.210512; sys_platform == "linux"
# Inspectors
python-inspector==0.11.0
python-inspector==0.10.0
elf-inspector==0.0.1
aboutcode-toolkit==10.1.0
# Utilities
XlsxWriter==3.1.9
Expand Down Expand Up @@ -126,6 +127,7 @@ scancodeio_pipelines =
analyze_root_filesystem_or_vm_image = scanpipe.pipelines.root_filesystem:RootFS
analyze_windows_docker_image = scanpipe.pipelines.docker_windows:DockerWindows
find_vulnerabilities = scanpipe.pipelines.find_vulnerabilities:FindVulnerabilities
get_dwarfs_from_elfs = scanpipe.pipelines.get_dwarfs_from_elfs:GetDwarfsFromElfs
inspect_packages = scanpipe.pipelines.inspect_packages:InspectPackages
load_inventory = scanpipe.pipelines.load_inventory:LoadInventory
load_sbom = scanpipe.pipelines.load_sbom:LoadSBOM
Expand Down