Skip to content

Commit

Permalink
Merge pull request #61 from binarly-io/fix/unpacking
Browse files Browse the repository at this point in the history
Fix/unpacking
  • Loading branch information
yeggor committed Jan 31, 2024
2 parents c6880f9 + c779a38 commit 22be877
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 42 deletions.
2 changes: 1 addition & 1 deletion fwhunt_scan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion fwhunt_scan/test_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
24 changes: 8 additions & 16 deletions fwhunt_scan/uefi_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions fwhunt_scan/uefi_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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"])

Expand Down
1 change: 1 addition & 0 deletions fwhunt_scan/uefi_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

from typing import Dict

from fwhunt_scan.uefi_types import UefiGuid

PROTOCOLS_GUIDS = [
Expand Down
9 changes: 2 additions & 7 deletions fwhunt_scan/uefi_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 2 additions & 7 deletions fwhunt_scan/uefi_smm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions fwhunt_scan_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from setuptools import setup

from fwhunt_scan import __author__, __email__, __version__

with open("requirements.txt") as f:
Expand Down

0 comments on commit 22be877

Please sign in to comment.