Skip to content

Commit

Permalink
feat: extractor support for pkg files
Browse files Browse the repository at this point in the history
  • Loading branch information
yashugarg committed Mar 7, 2022
1 parent e1daa5c commit 1921828
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cve_bin_tool/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, logger=None, error_mode=ErrorMode.TruncTrace):
self.extract_file_cab: {".cab"},
self.extract_file_apk: {".apk"},
self.extract_file_zst: {".zst"},
self.extract_file_pkg: {".pkg"},
self.extract_file_zip: {
".exe",
".zip",
Expand Down Expand Up @@ -117,7 +118,6 @@ async def extract_file_zst(self, filename, extraction_path):

if await aio_inpath("zstd"):
tar_path = os.path.join(extraction_path, "data.tar")
self.logger.warning(tar_path)
stdout, stderr, return_code = await aio_run_command(
["unzstd", filename, "-f", "-o", tar_path]
)
Expand All @@ -132,6 +132,19 @@ async def extract_file_zst(self, filename, extraction_path):
tar.extractall(extraction_path)
return 0

async def extract_file_pkg(self, filename, extraction_path):
"""Extract pkg files"""
if not await aio_inpath("tar"):
with ErrorHandler(mode=self.error_mode, logger=self.logger):
raise Exception("tar is required to extract .pkg files")
else:
stdout, stderr, return_code = await aio_run_command(
["tar", "xf", filename, "-C", extraction_path]
)
if (stderr or not stdout) and return_code != 0:
return 1
return 0

async def extract_file_deb(self, filename, extraction_path):
"""Extract debian packages"""
if not await aio_inpath("ar"):
Expand Down

0 comments on commit 1921828

Please sign in to comment.