Skip to content

Commit 71bf234

Browse files
committed
decomp: use TempFile for multi-plateform compatibility
1 parent cbcd1b2 commit 71bf234

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/pyrrha_mapper/exedecomp/binmapper.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
from collections import defaultdict, namedtuple
2121
from dataclasses import dataclass
2222
from pathlib import Path
23+
from tempfile import NamedTemporaryFile
2324

25+
# third-party imports
2426
from idascript import IDA
2527
from numbat import SourcetrailDB
26-
27-
# third-party imports
2828
from quokka import Function, Program
2929
from quokka.types import FunctionType
3030
from rich.progress import (
@@ -216,16 +216,14 @@ def add_source_file(
216216
info: DecompiledFunction,
217217
log_prefix: str = "",
218218
) -> bool:
219-
tmp = Path("/tmp/" + mangled_name)
220-
with open(tmp, "w") as f:
221-
f.write(info.text)
222-
223-
# Record file
224-
file_id = db.record_file(Path(tmp)) # , indexed=False)
225-
if file_id is None:
226-
return False
227-
db.record_file_language(file_id, "cpp")
228-
tmp.unlink() # QUESTION: Maybe we want to keep it for further analyses ?
219+
with NamedTemporaryFile(mode="wt", delete_on_close=False) as tmp:
220+
tmp.write(info.text)
221+
tmp.close()
222+
# Record file
223+
file_id = db.record_file(Path(tmp.name), name=mangled_name)
224+
if file_id is None:
225+
return False
226+
db.record_file_language(file_id, "cpp")
229227

230228
# Add the function to the file
231229
logging.debug(f"{log_prefix}: add function to file {file_id}")
@@ -285,7 +283,11 @@ def map_binary(db: SourcetrailDB, program_path: Path) -> bool:
285283
f.name,
286284
parent_id=None,
287285
is_indexed=not is_imp,
288-
) # , hover_display=f"{f.type.name.lower()} function")
286+
)
287+
if f_id is None:
288+
logging.error(f"{log_prefix}: error while recording function in db")
289+
progress.update(func_map, advance=1)
290+
continue
289291
f_mapping[f_addr] = f_id
290292

291293
if not is_imp:

0 commit comments

Comments
 (0)