Skip to content

Commit d710bcc

Browse files
committed
add optional --timeout CLI option and bump to 0.4.3
1 parent b88f6c4 commit d710bcc

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "python-binexport"
7-
version = "0.4.2"
7+
version = "0.4.3"
88
description = "Python wrapper to manipulate binexport files (protobuf)"
99
readme = { file = "README.md", content-type = "text/markdown" }
1010
authors = [{ name = "Quarkslab", email = "diffing@quarkslab.com" }]

src/binexport/__main__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def recursive_file_iter(p: Path) -> Generator[Path, None, None]:
5656
yield from recursive_file_iter(f)
5757

5858

59-
def export_job(ingress, egress, backend: DisassemblerBackend) -> None:
59+
def export_job(ingress, egress, backend: DisassemblerBackend, timeout: int | None) -> None:
6060
while True:
6161
try:
6262
file = ingress.get(timeout=0.5)
63-
res = ProgramBinExport.generate(file.as_posix(), backend=backend)
63+
res = ProgramBinExport.generate(file.as_posix(), backend=backend, timeout=timeout)
6464
egress.put((file, res))
6565
except queue.Empty:
6666
pass
@@ -128,13 +128,20 @@ def check_disassembler_availability(disass: DisassemblerBackend, disass_path: st
128128
"(if not provided search $PATH or environment variable IDA_PATH, GHIDRA_PATH)",
129129
)
130130
@click.option("-t", "--threads", type=int, default=1, help="Thread number to use")
131+
@click.option(
132+
"--timeout",
133+
type=int,
134+
default=None,
135+
help="Per-file export timeout in seconds (if not set, no timeout is enforced)",
136+
)
131137
@click.option("-v", "--verbose", count=True, help="To activate or not the verbosity")
132138
@click.option("--stop-on-error", is_flag=True, default=False, help="Stop on error")
133139
@click.argument("input_file", type=click.Path(exists=True), metavar="<binary file|directory>")
134140
def main(disassembler: str,
135141
disass_path: str,
136142
input_file: str,
137143
threads: int,
144+
timeout: int | None,
138145
verbose: bool,
139146
stop_on_error: bool) -> None:
140147
"""
@@ -162,7 +169,7 @@ def main(disassembler: str,
162169

163170
# Launch all workers
164171
for _ in range(threads):
165-
pool.apply_async(export_job, (ingress, egress, engine))
172+
pool.apply_async(export_job, (ingress, egress, engine, timeout))
166173

167174
# Pre-fill ingress queue
168175
total = 0

src/binexport/program.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def from_binary(
130130
output_file: str | pathlib.Path = "",
131131
override: bool = False,
132132
backend: DisassemblerBackend = DisassemblerBackend.IDA,
133-
timeout: int = 600,
133+
timeout: int | None = 600,
134134
) -> ProgramBinExport:
135135
"""
136136
Generate the .BinExport file for the given program and return an instance
@@ -165,8 +165,18 @@ def generate(
165165
output_file: str | pathlib.Path = "",
166166
override: bool = False,
167167
backend: DisassemblerBackend = DisassemblerBackend.IDA,
168-
timeout: int = 600,
168+
timeout: int | None = 600,
169169
) -> pathlib.Path:
170+
"""
171+
Generate the .BinExport file for the given program.
172+
173+
:param exec_file: executable file path
174+
:param output_file: BinExport output file
175+
:param override: Override the .BinExport if already existing.
176+
:param backend: The backend to use.
177+
:param timeout: Per-file export timeout in seconds. Pass ``None`` to disable.
178+
:return: the path of the generated BinExport file
179+
"""
170180

171181
exec_file = pathlib.Path(exec_file)
172182
binexport_file = (
@@ -209,7 +219,7 @@ def generate(
209219
def _from_ida(
210220
exec_file: pathlib.Path,
211221
binexport_file: pathlib.Path,
212-
timeout: int = 600,
222+
timeout: int | None = 600,
213223
) -> bool:
214224
"""
215225
Generate the .BinExport file for the given program and return an instance
@@ -246,7 +256,7 @@ def _from_ida(
246256
def _from_binary_ninja(
247257
exec_file: pathlib.Path,
248258
binexport_file: pathlib.Path,
249-
timeout: int = 600,
259+
timeout: int | None = 600,
250260
) -> bool:
251261
"""
252262
Generate the .BinExport file for the given program and return an instance
@@ -285,7 +295,7 @@ def _from_binary_ninja(
285295
def _from_ghidra(
286296
exec_file: pathlib.Path,
287297
binexport_file: pathlib.Path,
288-
timeout: int = 600,
298+
timeout: int | None = 600,
289299
) -> bool:
290300
"""
291301
Generate the .BinExport file for the given program and return an instance

0 commit comments

Comments
 (0)