binaryninja-api
binaryninja-api copied to clipboard
Add callback for when analysis has finished for a function
What is the feature you'd like to have? A callback to let me know when analysis has finished for a certain function.
Is your feature request related to a problem?
If you re-analyze a function, there does not appear to be a concrete way to know when the analysis has finished for that function. Some notification callbacks exist, like function_updated
, but these only let you know that a particular update has occurred - not that updates are finished. We do have AnalysisCompletionEvent
, but in my understanding, that would be triggered when all analysis has been completed for the entire BinaryView
, not necessarily just a certain function.
Are any alternative solutions acceptable?
If I'm wrong and this exists (or if AnalysisCompletionEvent
is guaranteed to fire in this situation and it can be used as-is), we may simply need better/more discoverable documentation (and/or an example) to show how to do this.
maybe a func.reanalyze_and_wait()
like some of the rest of the API has?
We discussed this as a group today and this is really an intractable, unsolvable problem for us. There are two reasons:
- Analysis for one function may update analysis for another function. So, we might update a function multiple times during normal analysis. This is basically the entire cause of the problem in the first place - otherwise, you could just use the
function_updated
callback directly (if we only ever updated once per analysis run). - Analysis is multithreaded, so we don't know (if the function is updated) if another update is underway, but on a different thread. So, just waiting for
function_updated
to fire and then doing something (without analysis being finished) could cause issues and there's really no way for you to know.
So, the best option I can offer for this is to use function_updated
to log all functions that have been updated, then wait for AnalysisCompletionEvent
to be triggered. At that point, you'll know that analysis is done and that specific functions have been updated.
We recognize this is not ideal and we do have some ideas for workflows that might be able to solve this better in the future. But, for now, this is the best I can do.