diff --git a/internal/task/package_tasks.go b/internal/task/package_tasks.go index 12e12422b..3347c50dd 100644 --- a/internal/task/package_tasks.go +++ b/internal/task/package_tasks.go @@ -161,7 +161,7 @@ func DefaultPackageTaskFactories() Factories { pkgcataloging.DeclaredTag, pkgcataloging.DirectoryTag, pkgcataloging.InstalledTag, pkgcataloging.ImageTag, "binary", ), newSimplePackageTaskFactory(binary.NewELFPackageCataloger, pkgcataloging.DeclaredTag, pkgcataloging.DirectoryTag, pkgcataloging.InstalledTag, pkgcataloging.ImageTag, "binary", "elf-package", "elf"), - newSimplePackageTaskFactory(binary.NewPEPackageCataloger, pkgcataloging.DeclaredTag, pkgcataloging.DirectoryTag, pkgcataloging.InstalledTag, pkgcataloging.ImageTag, "binary", "pe-package", "pe", "dll", "exe"), + newSimplePackageTaskFactory(binary.NewPEPackageCataloger, pkgcataloging.DeclaredTag, pkgcataloging.DirectoryTag, pkgcataloging.InstalledTag, pkgcataloging.ImageTag, "binary", "pe-package", "pe", "dll", "exe", "bpl"), newSimplePackageTaskFactory(githubactions.NewActionUsageCataloger, pkgcataloging.DeclaredTag, pkgcataloging.DirectoryTag, "github", "github-actions"), newSimplePackageTaskFactory(githubactions.NewWorkflowUsageCataloger, pkgcataloging.DeclaredTag, pkgcataloging.DirectoryTag, "github", "github-actions"), newSimplePackageTaskFactory(java.NewJvmDistributionCataloger, pkgcataloging.DeclaredTag, pkgcataloging.DirectoryTag, pkgcataloging.InstalledTag, pkgcataloging.ImageTag, "java", "jvm", "jdk", "jre"), diff --git a/syft/pkg/cataloger/binary/capabilities.yaml b/syft/pkg/cataloger/binary/capabilities.yaml index 22a810cad..edee01ef6 100644 --- a/syft/pkg/cataloger/binary/capabilities.yaml +++ b/syft/pkg/cataloger/binary/capabilities.yaml @@ -957,6 +957,7 @@ catalogers: function: NewPEPackageCataloger selectors: # AUTO-GENERATED - binary + - bpl - declared - directory - dll @@ -973,6 +974,7 @@ catalogers: criteria: # AUTO-GENERATED - '**/*.dll' - '**/*.exe' + - '**/*.bpl' metadata_types: # AUTO-GENERATED - pkg.PEBinary package_types: # AUTO-GENERATED diff --git a/syft/pkg/cataloger/binary/pe_package_cataloger.go b/syft/pkg/cataloger/binary/pe_package_cataloger.go index cbe732062..ba90d8835 100644 --- a/syft/pkg/cataloger/binary/pe_package_cataloger.go +++ b/syft/pkg/cataloger/binary/pe_package_cataloger.go @@ -12,10 +12,11 @@ import ( "github.com/anchore/syft/syft/pkg/cataloger/internal/pe" ) -// NewPEPackageCataloger returns a cataloger that interprets packages from DLL and EXE files. +// NewPEPackageCataloger returns a cataloger that interprets packages from DLL, EXE, and BPL files. +// BPL (Borland Package Library) files are PE-format binaries used by Delphi and C++Builder. func NewPEPackageCataloger() pkg.Cataloger { return generic.NewCataloger("pe-binary-package-cataloger"). - WithParserByGlobs(parsePE, "**/*.dll", "**/*.exe") + WithParserByGlobs(parsePE, "**/*.dll", "**/*.exe", "**/*.bpl") } func parsePE(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) { diff --git a/syft/pkg/cataloger/binary/pe_package_cataloger_test.go b/syft/pkg/cataloger/binary/pe_package_cataloger_test.go index e5addc535..7ba3eae3f 100644 --- a/syft/pkg/cataloger/binary/pe_package_cataloger_test.go +++ b/syft/pkg/cataloger/binary/pe_package_cataloger_test.go @@ -62,3 +62,30 @@ func Test_PEPackageCataloger(t *testing.T) { } } + +func Test_PEPackageCataloger_Globs(t *testing.T) { + tests := []struct { + name string + fixture string + expected []string + }{ + { + name: "obtain PE binary files (dll, exe, bpl)", + fixture: "testdata/glob-paths", + expected: []string{ + "src/library.dll", + "src/program.exe", + "src/archive.bpl", + }, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + pkgtest.NewCatalogTester(). + FromDirectory(t, test.fixture). + ExpectsResolverContentQueries(test.expected). + TestCataloger(t, NewPEPackageCataloger()) + }) + } +} diff --git a/syft/pkg/cataloger/binary/testdata/.gitignore b/syft/pkg/cataloger/binary/testdata/.gitignore index 388e71046..cdcbc936d 100644 --- a/syft/pkg/cataloger/binary/testdata/.gitignore +++ b/syft/pkg/cataloger/binary/testdata/.gitignore @@ -8,4 +8,5 @@ classifiers/bin # allow for go-hint files and binaries !VERSION* !classifiers/snippets/**/bin/ -!*.exe \ No newline at end of file +!*.exe +!*.dll \ No newline at end of file diff --git a/syft/pkg/cataloger/binary/testdata/glob-paths/src/archive.bpl b/syft/pkg/cataloger/binary/testdata/glob-paths/src/archive.bpl new file mode 100644 index 000000000..159643c0f --- /dev/null +++ b/syft/pkg/cataloger/binary/testdata/glob-paths/src/archive.bpl @@ -0,0 +1 @@ +bogus PE contents diff --git a/syft/pkg/cataloger/binary/testdata/glob-paths/src/library.dll b/syft/pkg/cataloger/binary/testdata/glob-paths/src/library.dll new file mode 100644 index 000000000..159643c0f --- /dev/null +++ b/syft/pkg/cataloger/binary/testdata/glob-paths/src/library.dll @@ -0,0 +1 @@ +bogus PE contents diff --git a/syft/pkg/cataloger/binary/testdata/glob-paths/src/notes.txt b/syft/pkg/cataloger/binary/testdata/glob-paths/src/notes.txt new file mode 100644 index 000000000..07e5c8416 --- /dev/null +++ b/syft/pkg/cataloger/binary/testdata/glob-paths/src/notes.txt @@ -0,0 +1 @@ +not a binary diff --git a/syft/pkg/cataloger/binary/testdata/glob-paths/src/program.exe b/syft/pkg/cataloger/binary/testdata/glob-paths/src/program.exe new file mode 100644 index 000000000..159643c0f --- /dev/null +++ b/syft/pkg/cataloger/binary/testdata/glob-paths/src/program.exe @@ -0,0 +1 @@ +bogus PE contents