binarly-io / fwhunt-scan

Tools for analyzing UEFI firmware and checking UEFI modules with FwHunt rules
GNU General Public License v3.0
214 stars 30 forks source link

UefiAnalyzer(blob) seems broken in git #38

Closed hughsie closed 2 years ago

hughsie commented 2 years ago

Using master, this works:

uefi_analyzer = UefiAnalyzer(image_path=image_path)

but using this failed:

blob = open(image_path, "rb").read()
uefi_analyzer = UefiAnalyzer(blob=blob)

It doesn't produce any output... interestingly in the lvfs-website self tests I get:

  File "/home/hughsie/Code/lvfs-website/plugins/uefi_scanner/__init__.py", line 105, in _run_test_on_shard
    with UefiAnalyzer(blob=shard.blob, rizinhome=rizinhome) as uefi_analyzer:
  File "/home/hughsie/Code/lvfs-website/env/lib/python3.10/site-packages/uefi_r2/uefi_analyzer.py", line 89, in __init__
    self._rz.cmd("aaaa")
  File "/home/hughsie/Code/lvfs-website/env/lib/python3.10/site-packages/rzpipe/open_base.py", line 244, in cmd
    res = self._cmd(cmd, **kwargs)
  File "/home/hughsie/Code/lvfs-website/env/lib/python3.10/site-packages/rzpipe/open_sync.py", line 104, in _cmd_process
    self.process.stdin.write((cmd + "\n").encode("utf8"))
BrokenPipeError: [Errno 32] Broken pipe
hughsie commented 2 years ago

e.g.

diff --git a/uefi_r2_analyzer.py b/uefi_r2_analyzer.py
index c0c66f6..4205df8 100755
--- a/uefi_r2_analyzer.py
+++ b/uefi_r2_analyzer.py
@@ -64,7 +64,8 @@ def scan(image_path: str, rule: List[str]) -> bool:
     # on linux platforms you can pass blob via shm://
     # uefi_analyzer = UefiAnalyzer(blob=data)

-    uefi_analyzer = UefiAnalyzer(image_path=image_path)
+    data = open(image_path, "rb").read()
+    uefi_analyzer = UefiAnalyzer(blob=data)

     uefi_rules: List[UefiRule] = list()
hughsie commented 2 years ago

Ignore me, sorry for the noise: installing rizin-0.3.1-1.fc36 fixed this.