Skip to content

Commit

Permalink
Ask the user to provide a platform when the input binary view does no…
Browse files Browse the repository at this point in the history
…t have one. Fix Vector35#206
  • Loading branch information
xusheng6 committed Jan 12, 2024
1 parent 721951d commit 42d4237
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
57 changes: 57 additions & 0 deletions ui/controlswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.
#include "binaryninjaapi.h"
#include "disassemblyview.h"
#include "theme.h"
#include "platformdialog.h"
#include "ui.h"
#include <thread>
#include "progresstask.h"
Expand Down Expand Up @@ -142,6 +143,34 @@ void DebugControlsWidget::performLaunch()
return;
}

auto data = m_controller->GetData();
if (!data->GetDefaultPlatform())
{
// No default platform, prompt user to choose one
PlatformDialog dlg(this);
if (dlg.exec() != QDialog::Accepted)
{
QMessageBox::warning(this, "No Platform", "The debugger cannot work if the binary view has no "
"platform and architecture");
return;
}

auto platform = dlg.getPlatform();
if (platform)
{
dlg.saveDefaults();
}
else
{
QMessageBox::warning(this, "Invalid Platform", "The debugger cannot work if the binary view has no "
"platform and architecture");
return;
}

data->SetDefaultArchitecture(platform->GetArchitecture());
data->SetDefaultPlatform(platform);
}

QString text = QString(
"The debugger is %1 the target and preparing the debugger binary view. \n"
"This might take a while.").arg("launching");
Expand All @@ -168,6 +197,34 @@ void DebugControlsWidget::performAttachPID()
if (pid == 0)
return;

auto data = m_controller->GetData();
if (!data->GetDefaultPlatform())
{
// No default platform, prompt user to choose one
PlatformDialog dlg(this);
if (dlg.exec() != QDialog::Accepted)
{
QMessageBox::warning(this, "No Platform", "The debugger cannot work if the binary view has no "
"platform and architecture");
return;
}

auto platform = dlg.getPlatform();
if (platform)
{
dlg.saveDefaults();
}
else
{
QMessageBox::warning(this, "Invalid Platform", "The debugger cannot work if the binary view has no "
"platform and architecture");
return;
}

data->SetDefaultArchitecture(platform->GetArchitecture());
data->SetDefaultPlatform(platform);
}

m_controller->SetPIDAttach(pid);
QString text = QString(
"The debugger is %1 the target and preparing the debugger binary view. \n"
Expand Down
43 changes: 43 additions & 0 deletions ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
#include "moduleswidget.h"
#include "stackwidget.h"
#include "uinotification.h"
#include "platformdialog.h"
#include "QPainter"
#include <QStatusBar>
#include <QCoreApplication>
Expand Down Expand Up @@ -309,6 +310,37 @@ void GlobalDebuggerUI::SetupMenu(UIContext* context)
return !controller->IsConnectedToDebugServer();
};

auto ensureBinaryViewHasPlatform = [&](BinaryViewRef data, QWidget* parent) -> bool
{
if (!data->GetDefaultPlatform())
{
// No default platform, prompt user to choose one
PlatformDialog dlg(parent);
if (dlg.exec() != QDialog::Accepted)
{
QMessageBox::warning(parent, "No Platform",
"The debugger cannot work if the binary view has no platform and architecture");
return false;
}

auto platform = dlg.getPlatform();
if (platform)
{
dlg.saveDefaults();
}
else
{
QMessageBox::warning(parent, "Invalid Platform",
"The debugger cannot work if the binary view has no platform and architecture");
return false;
}

data->SetDefaultArchitecture(platform->GetArchitecture());
data->SetDefaultPlatform(platform);
}
return true;
};

UIAction::registerAction("Debug Adapter Settings...");
context->globalActions()->bindAction("Debug Adapter Settings...",
UIAction(
Expand Down Expand Up @@ -348,6 +380,10 @@ void GlobalDebuggerUI::SetupMenu(UIContext* context)
if (QMessageBox::question(ctxt.context->mainWindow(), "Launch Target", prompt) != QMessageBox::Yes)
return;
}

if (!ensureBinaryViewHasPlatform(controller->GetData(), ctxt.context->mainWindow()))
return;

QString text = QString(
"The debugger is launching the target and preparing the debugger binary view. \n"
"This might take a while.");
Expand Down Expand Up @@ -511,6 +547,10 @@ void GlobalDebuggerUI::SetupMenu(UIContext* context)
return;

controller->SetPIDAttach(pid);

if (!ensureBinaryViewHasPlatform(controller->GetData(), ctxt.context->mainWindow()))
return;

QString text = QString(
"The debugger is attaching to the target and preparing the debugger binary view. \n"
"This might take a while.");
Expand Down Expand Up @@ -609,6 +649,9 @@ void GlobalDebuggerUI::SetupMenu(UIContext* context)
if (dialog->exec() != QDialog::Accepted)
return;

if (!ensureBinaryViewHasPlatform(controller->GetData(), ctxt.context->mainWindow()))
return;

QString text = QString(
"The debugger is connecting to the target and preparing the debugger binary view. \n"
"This might take a while.");
Expand Down

0 comments on commit 42d4237

Please sign in to comment.