diff --git a/core/debuggercontroller.cpp b/core/debuggercontroller.cpp index 3ce4e0f..0da24de 100644 --- a/core/debuggercontroller.cpp +++ b/core/debuggercontroller.cpp @@ -22,10 +22,13 @@ limitations under the License. using namespace BinaryNinjaDebugger; -DebuggerController::DebuggerController(BinaryViewRef data) : m_data(data) +DebuggerController::DebuggerController(BinaryViewRef data) { INIT_DEBUGGER_API_OBJECT(); + m_file = data->GetFile(); + m_viewName = data->GetTypeName(); + m_state = new DebuggerState(data, this); m_adapter = nullptr; RegisterEventCallback([this](const DebuggerEvent& event) { EventHandler(event); }, "Debugger Core"); @@ -274,7 +277,7 @@ bool DebuggerController::CreateDebugAdapter() LogWarn("Failed to get an debug adapter of type %s", m_state->GetAdapterType().c_str()); return false; } - m_adapter = type->Create(m_data); + m_adapter = type->Create(GetData()); if (!m_adapter) { LogWarn("Failed to create an adapter of type %s", m_state->GetAdapterType().c_str()); @@ -726,17 +729,18 @@ bool DebuggerController::CreateDebuggerBinaryView() if (!viewType) return false; - BinaryViewRef liveView = viewType->Create(m_data); + BinaryViewRef liveView = viewType->Create(GetData()); if (!liveView) return false; - if (!m_data->GetDefaultArchitecture() || !m_data->GetDefaultPlatform()) + BinaryViewRef data = GetData(); + if (!data->GetDefaultArchitecture() || !data->GetDefaultPlatform()) { LogWarn("Fail to create debugger view. The input view must have an architecture and platform"); return false; } - liveView->SetDefaultArchitecture(m_data->GetDefaultArchitecture()); - liveView->SetDefaultPlatform(m_data->GetDefaultPlatform()); + liveView->SetDefaultArchitecture(data->GetDefaultArchitecture()); + liveView->SetDefaultPlatform(data->GetDefaultPlatform()); SetLiveView(liveView); return true; @@ -764,22 +768,18 @@ void DebuggerController::DetectLoadedModule() } else { - FileMetadataRef fileMetadata = m_data->GetFile(); - if (remoteBase != m_data->GetStart()) + if (remoteBase != GetData()->GetStart()) { // remote base is different from the local base, first need a rebase - if (!fileMetadata->Rebase(m_data, remoteBase, [&](size_t cur, size_t total) { return true; })) + if (!m_file->Rebase(GetData(), remoteBase, [&](size_t cur, size_t total) { return true; })) { LogWarn("rebase failed"); } } - Ref rebasedView = fileMetadata->GetViewOfType(m_data->GetTypeName()); - SetData(rebasedView); + Ref rebasedView = m_file->GetViewOfType(m_viewName); - bool ok = fileMetadata->CreateSnapshotedView(rebasedView, "Debugger", [&](size_t cur, size_t total) { - return true; - }); + bool ok = m_file->CreateSnapshotedView(rebasedView, "Debugger", [&](size_t cur, size_t total) { return true; }); if (!ok) LogWarn("create snapshoted view failed"); } @@ -1051,9 +1051,9 @@ void DebuggerController::LaunchOrConnect() if (!adapterType) return; - if (adapterType->CanExecute(m_data)) + if (adapterType->CanExecute(GetData())) Launch(); - else if (adapterType->CanConnect(m_data)) + else if (adapterType->CanConnect(GetData())) Connect(); } @@ -1070,18 +1070,8 @@ DbgRef DebuggerController::GetController(BinaryViewRef data) DebuggerController* controller = g_debuggerControllers[i]; if (!controller) continue; - if (controller->GetData() == data) - return controller; - if (controller->GetLiveView() == data) + if (controller->m_file.operator==(data->GetFile())) return controller; - //if (controller->GetData()->GetFile()->GetOriginalFilename() == data->GetFile()->GetOriginalFilename()) - // return controller; - //if (controller->GetData()->GetFile()->GetOriginalFilename() == data->GetParentView()->GetFile()->GetOriginalFilename()) - // return controller; - //if (controller->GetData()->GetFile() == data->GetFile()) - // return controller; - //if (controller->GetLiveView() && (controller->GetLiveView()->GetFile() == data->GetFile())) - // return controller; } if (data->GetTypeName() == "Debugger") @@ -1137,8 +1127,8 @@ bool DebuggerController::ControllerExists(BinaryViewRef data) void DebuggerController::Destroy() { - DebuggerController::DeleteController(m_data); - m_data = nullptr; + DebuggerController::DeleteController(GetData()); + m_file = nullptr; m_liveView = nullptr; } diff --git a/core/debuggercontroller.h b/core/debuggercontroller.h index dfa174d..2053c69 100644 --- a/core/debuggercontroller.h +++ b/core/debuggercontroller.h @@ -61,7 +61,8 @@ namespace BinaryNinjaDebugger { private: DebugAdapter* m_adapter; DebuggerState* m_state; - BinaryViewRef m_data; + FileMetadataRef m_file; + std::string m_viewName; BinaryViewRef m_liveView; // inline static std::vector> g_debuggerControllers; @@ -250,8 +251,8 @@ namespace BinaryNinjaDebugger { // getters DebugAdapter* GetAdapter() { return m_adapter; } DebuggerState* GetState() { return m_state; } - BinaryViewRef GetData() const { return m_data; } - void SetData(BinaryViewRef view) { m_data = view; } + BinaryViewRef GetData() { return m_file->GetViewOfType(m_viewName); } + void SetData(BinaryViewRef view) {} BinaryViewRef GetLiveView() const { return m_liveView; } uint32_t GetExitCode(); diff --git a/ui/ui.cpp b/ui/ui.cpp index 2577c23..7386cf7 100644 --- a/ui/ui.cpp +++ b/ui/ui.cpp @@ -1235,7 +1235,6 @@ void DebuggerUI::updateUI(const DebuggerEvent& event) } Ref rebasedView = fileMetadata->GetViewOfType(data->GetTypeName()); - m_controller->SetData(rebasedView); bool result = false; QString text = QString("Adding the input view into the debugger view...");