summaryrefslogtreecommitdiff
path: root/examples/triage/baseaddress.cpp
diff options
context:
space:
mode:
authorBrandon Miller <brandon@vector35.com>2024-05-31 13:33:09 -0400
committerBrandon Miller <brandon@vector35.com>2024-06-04 07:36:54 -0400
commitdef0569c3e235c02e4db6c34e9c0e49cdfb7a272 (patch)
treeaa9bb55a77c1d9fde98fd53bca6d65d49e380e9e /examples/triage/baseaddress.cpp
parent437e5e1eac509b1da198ee9fe294fec4e71b7758 (diff)
BASE rebase navigation for non-mapped views
Diffstat (limited to 'examples/triage/baseaddress.cpp')
-rw-r--r--examples/triage/baseaddress.cpp77
1 files changed, 57 insertions, 20 deletions
diff --git a/examples/triage/baseaddress.cpp b/examples/triage/baseaddress.cpp
index 67d8301c..98592a6f 100644
--- a/examples/triage/baseaddress.cpp
+++ b/examples/triage/baseaddress.cpp
@@ -250,12 +250,24 @@ void BaseAddressDetectionWidget::Abort()
}
-void BaseAddressDetectionWidget::RebaseWithFullAnalysis()
+const std::string BaseAddressDetectionWidget::GetRebaseViewName()
{
- auto mappedView = m_view->GetFile()->GetViewOfType("Mapped");
- if (!mappedView)
- return;
+ auto fileMetadata = m_view->GetFile();
+ if (!fileMetadata)
+ return "";
+
+ for (const auto& viewName : fileMetadata->GetExistingViews())
+ {
+ if (viewName != "Raw" && viewName != "Debugger")
+ return viewName;
+ }
+ return "";
+}
+
+
+void BaseAddressDetectionWidget::RebaseWithFullAnalysis()
+{
auto fileMetadata = m_view->GetFile();
if (!fileMetadata)
return;
@@ -268,12 +280,45 @@ void BaseAddressDetectionWidget::RebaseWithFullAnalysis()
return;
}
- if (!fileMetadata->Rebase(mappedView, address))
- return;
+ auto rebaseViewName = GetRebaseViewName();
+ if (!rebaseViewName.empty())
+ {
+ // Found an existing view that isn't raw, rebase it
+ auto view = m_view->GetFile()->GetViewOfType(rebaseViewName);
+ if (!view)
+ return;
- BinaryNinja::Settings::Instance()->Set("analysis.mode", "full", mappedView);
- mappedView->Reanalyze();
+ bool result = false;
+ ProgressTask* task = new ProgressTask(this, "Rebase", "Rebasing...", "Cancel", [&](std::function<bool(size_t, size_t)> progress) {
+ result = fileMetadata->Rebase(view, address, progress);
+ });
+ task->wait();
+ if (!result)
+ return;
+ view->Reanalyze();
+ }
+ else
+ {
+ // Only a raw view exists - load the binary and run full analysis
+ BinaryNinja::Settings::Instance()->Set("analysis.mode", "full", m_view);
+ map<string, BinaryNinja::Ref<BinaryNinja::Metadata>> metadataMap = {
+ {"analysis.linearSweep.permissive", new BinaryNinja::Metadata(true)},
+ {"loader.imageBase", new BinaryNinja::Metadata((uint64_t) address)},
+ };
+
+ if (m_inputs.ArchitectureBox->currentText() != "auto detect")
+ metadataMap["loader.platform"] = new BinaryNinja::Metadata(m_inputs.ArchitectureBox->currentText().toStdString());
+
+ auto options = new BinaryNinja::Metadata(metadataMap);
+ auto newView = Load(m_view->GetFile()->GetViewOfType("Raw"), false, options->GetJsonString());
+ if (!newView)
+ return;
+
+ rebaseViewName = newView->GetTypeName();
+ }
+
+ // Refresh the UI and jump to Linear view
auto frame = ViewFrame::viewFrameForWidget(this);
if (!frame)
return;
@@ -286,23 +331,15 @@ void BaseAddressDetectionWidget::RebaseWithFullAnalysis()
if (!uiContext)
return;
- uiContext->recreateViewFrames(fileContext);
fileContext->refreshDataViewCache();
+ uiContext->recreateViewFrames(fileContext);
+ QCoreApplication::processEvents();
- auto newFrame = ViewFrame::viewFrameForWidget(this);
+ auto newFrame = fileContext->getCurrentViewFrame();
if (!newFrame)
return;
- auto view = newFrame->getCurrentViewInterface();
- if (!view)
- return;
-
- auto data = view->getData();
- if (!data)
- return;
-
- if (!view->navigate(address))
- data->Navigate("Linear:Mapped", address);
+ newFrame->navigate(QString("Linear:%1").arg(QString::fromStdString(rebaseViewName)), address);
}