From 216d1cfd277090795f8c60a81abb08378f86205f Mon Sep 17 00:00:00 2001 From: Xusheng Date: Mon, 20 Mar 2023 15:16:07 +0800 Subject: [PATCH] Use input file path rather than the executable path when setting the entry breakpoint --- core/adapters/dbgengadapter.cpp | 17 +++++++++-------- core/adapters/lldbadapter.cpp | 2 +- core/debugadapter.h | 5 ++++- core/debuggercontroller.cpp | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/core/adapters/dbgengadapter.cpp b/core/adapters/dbgengadapter.cpp index 635e3c3c..7bee71f2 100644 --- a/core/adapters/dbgengadapter.cpp +++ b/core/adapters/dbgengadapter.cpp @@ -403,15 +403,16 @@ bool DbgEngAdapter::ExecuteWithArgsInternal(const std::string& path, const std:: ApplyBreakpoints(); auto settings = Settings::Instance(); - if (settings->Get("debugger.stopAtEntryPoint")) + if (settings->Get("debugger.stopAtEntryPoint") && m_hasEntryFunction) { - AddBreakpoint(ModuleNameAndOffset(path, m_entryPoint - m_start)); - if (!settings->Get("debugger.stopAtSystemEntryPoint")) - { - if (this->m_debugControl->SetExecutionStatus(DEBUG_STATUS_GO) != S_OK) - return false; - Wait(); - } + AddBreakpoint(ModuleNameAndOffset(configs.inputFile, m_entryPoint - m_start)); + } + + if (!settings->Get("debugger.stopAtSystemEntryPoint")) + { + if (this->m_debugControl->SetExecutionStatus(DEBUG_STATUS_GO) != S_OK) + return false; + Wait(); } return true; diff --git a/core/adapters/lldbadapter.cpp b/core/adapters/lldbadapter.cpp index b8c95b8b..1a89583d 100644 --- a/core/adapters/lldbadapter.cpp +++ b/core/adapters/lldbadapter.cpp @@ -202,7 +202,7 @@ bool LldbAdapter::ExecuteWithArgs(const std::string& path, const std::string& ar thread.detach(); if (Settings::Instance()->Get("debugger.stopAtEntryPoint") && m_hasEntryFunction) - AddBreakpoint(ModuleNameAndOffset(path, m_entryPoint - m_start)); + AddBreakpoint(ModuleNameAndOffset(configs.inputFile, m_entryPoint - m_start)); std::string launchCommand = "process launch"; if (Settings::Instance()->Get("debugger.stopAtSystemEntryPoint") || m_isElFWithoutDynamicLoader) diff --git a/core/debugadapter.h b/core/debugadapter.h index e62be5d4..2dd3144f 100644 --- a/core/debugadapter.h +++ b/core/debugadapter.h @@ -60,10 +60,13 @@ namespace BinaryNinjaDebugger { struct LaunchConfigurations { bool requestTerminalEmulator; + std::string inputFile; LaunchConfigurations() : requestTerminalEmulator(true) {} - LaunchConfigurations(bool terminal) : requestTerminalEmulator(terminal) {} + LaunchConfigurations(bool terminal, const std::string& file) : requestTerminalEmulator(terminal), + inputFile(file) + {} }; diff --git a/core/debuggercontroller.cpp b/core/debuggercontroller.cpp index a9308e72..fdbc1246 100644 --- a/core/debuggercontroller.cpp +++ b/core/debuggercontroller.cpp @@ -164,7 +164,7 @@ bool DebuggerController::Execute() std::string filePath = m_state->GetExecutablePath(); bool requestTerminal = m_state->GetRequestTerminalEmulator(); - LaunchConfigurations configs = {requestTerminal}; + LaunchConfigurations configs = {requestTerminal, m_state->GetInputFile()}; #ifdef WIN32 /* temporary solution (not great, sorry!), we probably won't have to do this once we introduce std::filesystem::path */