From 1623101a8c2714c24ae446f1ae4084a468d7695b Mon Sep 17 00:00:00 2001 From: yeggor Date: Wed, 31 Jan 2024 22:32:21 +0000 Subject: [PATCH 1/2] minor fix --- fwhunt_scan/__init__.py | 2 +- fwhunt_scan/test_internal.py | 2 +- fwhunt_scan/uefi_analyzer.py | 24 ++++++++---------------- fwhunt_scan/uefi_extractor.py | 16 ++++++++-------- fwhunt_scan/uefi_protocols.py | 1 + fwhunt_scan/uefi_scanner.py | 9 ++------- fwhunt_scan/uefi_smm.py | 9 ++------- 7 files changed, 23 insertions(+), 40 deletions(-) diff --git a/fwhunt_scan/__init__.py b/fwhunt_scan/__init__.py index 10796c1..798f733 100644 --- a/fwhunt_scan/__init__.py +++ b/fwhunt_scan/__init__.py @@ -9,9 +9,9 @@ __version__ = "2.3.4" from .uefi_analyzer import UefiAnalyzer, UefiAnalyzerError +from .uefi_extractor import UefiBinary, UefiExtractor from .uefi_scanner import UefiRule, UefiScanner, UefiScannerError from .uefi_te import TerseExecutableParser -from .uefi_extractor import UefiBinary, UefiExtractor __all__ = [ "UefiAnalyzer", diff --git a/fwhunt_scan/test_internal.py b/fwhunt_scan/test_internal.py index e05d5a7..a2c5610 100644 --- a/fwhunt_scan/test_internal.py +++ b/fwhunt_scan/test_internal.py @@ -8,7 +8,7 @@ import unittest -from .uefi_protocols import PROTOCOLS_GUIDS, GUID_FROM_VALUE +from .uefi_protocols import GUID_FROM_VALUE, PROTOCOLS_GUIDS class TestInternal(unittest.TestCase): diff --git a/fwhunt_scan/uefi_analyzer.py b/fwhunt_scan/uefi_analyzer.py index 23c8759..0a38114 100644 --- a/fwhunt_scan/uefi_analyzer.py +++ b/fwhunt_scan/uefi_analyzer.py @@ -18,23 +18,15 @@ import fwhunt_scan.uefi_smm as uefi_smm from fwhunt_scan.uefi_protocols import GUID_FROM_BYTES -from fwhunt_scan.uefi_tables import ( - BS_PROTOCOLS_INFO_64_BIT, - EFI_BOOT_SERVICES_64_BIT, - EFI_PEI_SERVICES_32_BIT, - EFI_RUNTIME_SERVICES_64_BIT, - OFFSET_TO_SERVICE, -) +from fwhunt_scan.uefi_tables import (BS_PROTOCOLS_INFO_64_BIT, + EFI_BOOT_SERVICES_64_BIT, + EFI_PEI_SERVICES_32_BIT, + EFI_RUNTIME_SERVICES_64_BIT, + OFFSET_TO_SERVICE) from fwhunt_scan.uefi_te import TerseExecutableError, TerseExecutableParser -from fwhunt_scan.uefi_types import ( - ChildSwSmiHandler, - NvramVariable, - SmiHandler, - UefiGuid, - UefiProtocol, - UefiProtocolGuid, - UefiService, -) +from fwhunt_scan.uefi_types import (ChildSwSmiHandler, NvramVariable, + SmiHandler, UefiGuid, UefiProtocol, + UefiProtocolGuid, UefiService) from fwhunt_scan.uefi_utils import get_current_insn_index, get_int if sys.version_info.major == 3 and sys.version_info.minor >= 8: diff --git a/fwhunt_scan/uefi_extractor.py b/fwhunt_scan/uefi_extractor.py index 8208ad6..dcfd3b7 100644 --- a/fwhunt_scan/uefi_extractor.py +++ b/fwhunt_scan/uefi_extractor.py @@ -75,10 +75,10 @@ def _compressed_search(self, object: Any, root_guid: str) -> None: for component in object.iterate_objects(): attrs = component.get("attrs", None) if attrs is not None: - type = attrs.get("type", None) - if type in UefiExtractor.UI: + section_type = attrs.get("type", None) + if section_type in UefiExtractor.UI: self._info[root_guid]["name"] = component["label"] - if type in UefiExtractor.SECTION_TYPES: + if section_type in UefiExtractor.SECTION_TYPES: self._info[root_guid]["content"] = component["_self"].content self._compressed_search(component["_self"], root_guid) @@ -103,15 +103,15 @@ def _append_binaries(self, object: Any) -> None: if guid is not None and attrs is not None: if guid not in self._info: self._info[guid] = {"name": None, "ext": None, "content": None} - type = attrs.get("type", None) - if type in UefiExtractor.UI: + section_type = attrs.get("type", None) + if section_type in UefiExtractor.UI: self._info[guid]["name"] = component["label"] - if type in UefiExtractor.FILE_TYPES: + if section_type in UefiExtractor.FILE_TYPES: if self._info[guid]["ext"] is None: - ext = UefiExtractor.FILE_TYPES[type][1] + ext = UefiExtractor.FILE_TYPES[section_type][1] self._info[guid]["ext"] = f".{ext}" self._compressed_handle(component["_self"], guid) - if type in UefiExtractor.SECTION_TYPES: + if section_type in UefiExtractor.SECTION_TYPES: self._info[guid]["content"] = component["_self"].content self._append_binaries(component["_self"]) diff --git a/fwhunt_scan/uefi_protocols.py b/fwhunt_scan/uefi_protocols.py index 7f3f7c6..fd5bb88 100644 --- a/fwhunt_scan/uefi_protocols.py +++ b/fwhunt_scan/uefi_protocols.py @@ -7,6 +7,7 @@ """ from typing import Dict + from fwhunt_scan.uefi_types import UefiGuid PROTOCOLS_GUIDS = [ diff --git a/fwhunt_scan/uefi_scanner.py b/fwhunt_scan/uefi_scanner.py index d1d46a5..e88dfcb 100644 --- a/fwhunt_scan/uefi_scanner.py +++ b/fwhunt_scan/uefi_scanner.py @@ -11,13 +11,8 @@ import yaml -from fwhunt_scan.uefi_analyzer import ( - NvramVariable, - UefiAnalyzer, - UefiGuid, - UefiProtocol, - UefiService, -) +from fwhunt_scan.uefi_analyzer import (NvramVariable, UefiAnalyzer, UefiGuid, + UefiProtocol, UefiService) class CodePattern: diff --git a/fwhunt_scan/uefi_smm.py b/fwhunt_scan/uefi_smm.py index 509ef6e..f9522b5 100644 --- a/fwhunt_scan/uefi_smm.py +++ b/fwhunt_scan/uefi_smm.py @@ -8,13 +8,8 @@ from fwhunt_scan.uefi_protocols import UefiGuid from fwhunt_scan.uefi_types import ChildSwSmiHandler, SmiHandler, SmiKind -from fwhunt_scan.uefi_utils import ( - get_current_insn_index, - get_int, - get_xrefs_to_data, - get_xrefs_to_guids, -) - +from fwhunt_scan.uefi_utils import (get_current_insn_index, get_int, + get_xrefs_to_data, get_xrefs_to_guids) SMI_KINDS = { SmiKind.SW_SMI: [ From c779a38284e586e960cddb649992903c0d9248c2 Mon Sep 17 00:00:00 2001 From: yeggor Date: Wed, 31 Jan 2024 22:45:16 +0000 Subject: [PATCH 2/2] minor fix in dumped module names --- fwhunt_scan_analyzer.py | 4 ++-- setup.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fwhunt_scan_analyzer.py b/fwhunt_scan_analyzer.py index d7eefb4..5de0d76 100644 --- a/fwhunt_scan_analyzer.py +++ b/fwhunt_scan_analyzer.py @@ -215,11 +215,11 @@ def extract(image_path: str, extract_path: str) -> bool: for binary in extractor.binaries: if not binary.guid or not len(binary.content): continue - fpath = os.path.join(extract_path, f"{binary.guid}-{binary.name}{binary.ext}") + fpath = os.path.join(extract_path, f"{binary.name}-{binary.guid}{binary.ext}") with open(fpath, "wb") as f: f.write(binary.content) - click.echo(f"{binary.guid} -> {fpath}") + click.echo(f"{binary.guid}: {fpath}") return True diff --git a/setup.py b/setup.py index d5bed79..ca60428 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ from setuptools import setup + from fwhunt_scan import __author__, __email__, __version__ with open("requirements.txt") as f: