aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--idatui/app.py43
-rw-r--r--tests/test_blob_ui.py33
2 files changed, 72 insertions, 4 deletions
diff --git a/idatui/app.py b/idatui/app.py
index ec55911..d025ed2 100644
--- a/idatui/app.py
+++ b/idatui/app.py
@@ -149,6 +149,8 @@ class ViewAnchor:
top_ea: int | None = None # first visible address
cursor_x: int = 0
flash: str | None = None
+ #: The edit changed which functions exist, so the index must be rebuilt.
+ refresh_functions: bool = False
@dataclass
@@ -3253,8 +3255,9 @@ class IdaTui(App):
n = len(self._func_index) if self._func_index else 0
note = ("this image has no functions, so nothing is lost"
if n == 0 else
- f"discards the database for this binary \u2014 {n} functions, "
- f"plus any names and comments you've added")
+ f"discards the database for this binary \u2014 {n} "
+ f"function{'s' if n != 1 else ''}, plus any names and comments "
+ f"you've added")
self.push_screen(ConfirmScreen("Reload with different options?", note),
self._on_reload_confirmed)
@@ -3419,6 +3422,11 @@ class IdaTui(App):
# An image with no functions at all is nearly always a blob described
# wrongly, and that stays true as you scroll around — so it belongs in
# the status bar, not in a one-off message the next write clobbers.
+ # It stops being true the moment a function exists, though: latching it
+ # meant the warning survived defining one with `p` and kept telling you
+ # the load was wrong when it no longer was.
+ if self._no_functions and self._func_index is not None and len(self._func_index):
+ self._no_functions = False
if self._no_functions:
text += " \u2014 no functions: wrong processor/base? Ctrl+L to reload"
try:
@@ -5202,6 +5210,7 @@ class IdaTui(App):
# anchor restore, same flash. That is the whole point of having
# one path.
elif kind == "func":
+ anchor.refresh_functions = True
r = self.program.define_func(ea)
if r.get("start") and r.get("end"):
verb = (f"created function {r['start']}\u2013{r['end']}"
@@ -5211,6 +5220,8 @@ class IdaTui(App):
s = self.program.make_string(ea)
verb = f"made string ({s[:24]!r})" if s else verb
else:
+ # Undefining can destroy a function as easily as `p` creates one.
+ anchor.refresh_functions = True
self.program.undefine(ea)
except Exception as e: # noqa: BLE001 -- surface soft/hard tool errors
self.app.call_from_thread(self._status, f"{kind}: {e}")
@@ -5249,6 +5260,34 @@ class IdaTui(App):
self._flash = anchor.flash
if anchor.flash:
self._status(anchor.flash)
+ if anchor.refresh_functions:
+ # Creating (or destroying) a function changes the index that the
+ # names pane, Ctrl+N and the "no functions" hint all read. Without
+ # this, `p` gave you a function the rest of the app couldn't see.
+ self._reindex_functions()
+
+ @work(thread=True, exclusive=True, group="load-funcs")
+ def _reindex_functions(self) -> None:
+ """Rebuild the function index in place after an edit changed it.
+
+ Deliberately not _load_functions(): that one is the BOOT path — it
+ clears the table, streams progress and then auto-lands, which would
+ yank the view away from the function you just made.
+ """
+ if self.program is None:
+ return
+ idx = self.program.functions()
+ idx.load_all()
+ self._func_index = idx
+ self.app.call_from_thread(self._after_reindex)
+
+ def _after_reindex(self) -> None:
+ idx = self._func_index
+ if idx is None:
+ return
+ if len(idx):
+ self._no_functions = False
+ self._apply_filter(self._filter_term) # repopulate the names pane
@work(thread=True, exclusive=True, group="save")
def _save(self) -> None:
diff --git a/tests/test_blob_ui.py b/tests/test_blob_ui.py
index f930401..b30bba5 100644
--- a/tests/test_blob_ui.py
+++ b/tests/test_blob_ui.py
@@ -214,14 +214,43 @@ async def run() -> int:
lst._cursor_ea() == cur_before,
f"{cur_before:#x} -> {lst._cursor_ea():#x}")
+ # -- `p` after carving: the rest of the app must notice ------ #
+ # The "no functions" hint was latched at load and only cleared on a
+ # reload, so it kept telling you the processor/base were wrong long
+ # after you'd defined a function. The function index was never
+ # rebuilt either, which meant Ctrl+N couldn't find what `p` made.
+ check("no functions yet, and the hint says so",
+ len(app._func_index) == 0
+ and "no functions" in str(app.query_one("#status", Static).render()),
+ f"n={len(app._func_index)}")
+ lst.cursor = lst.model.index_of_ea(target)
+ lst._scroll_cursor_into_view()
+ await pilot.pause(0.3)
+ mp = lst.model
+ await pilot.press("p")
+ await wait(lambda: lst.model is not mp and lst.model is not None,
+ pilot, 40)
+ await wait(lambda: app._func_index is not None
+ and len(app._func_index) > 0, pilot, 60)
+ check("`p` creates a function the index can see",
+ len(app._func_index) == 1, f"n={len(app._func_index)}")
+ status = str(app.query_one("#status", Static).render())
+ check("and the stale 'no functions' hint is gone",
+ "no functions" not in status, status[:90])
+ check("the status names the function it made",
+ "created function" in status, status[:90])
+
await pilot.press("ctrl+l")
opened = await wait(lambda: isinstance(app.screen, ConfirmScreen), pilot, 20)
check("Ctrl+L offers to reload with different options", opened,
f"screen={type(app.screen).__name__}")
if opened:
note = str(app.screen.query_one("#confirm-note", Static).render())
- check("and says nothing is lost when there's nothing to lose",
- "nothing is lost" in note, note[:70])
+ # We just made a function, so it must NOT claim nothing is lost —
+ # reloading throws the database away and that is now a real cost.
+ check("the confirmation counts what would be lost",
+ "1 function," in note and "nothing is lost" not in note,
+ note[:80])
await pilot.press("escape")
await pilot.pause(0.3)
check("declining leaves the binary open",