Skip to content

Commit

Permalink
Do not add an entry breakpoint if the module does not have an entry f…
Browse files Browse the repository at this point in the history
…unction
  • Loading branch information
xusheng6 committed Apr 11, 2023
1 parent feeb1f5 commit 155bdec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/adapters/lldbadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ bool LldbAdapter::ExecuteWithArgs(const std::string& path, const std::string& ar
std::thread thread([&]() { EventListener(); });
thread.detach();

if (Settings::Instance()->Get<bool>("debugger.stopAtEntryPoint"))
if (Settings::Instance()->Get<bool>("debugger.stopAtEntryPoint") && m_hasEntryFunction)
AddBreakpoint(ModuleNameAndOffset(path, m_entryPoint - m_start));

std::string launchCommand = "process launch";
Expand Down Expand Up @@ -341,7 +341,7 @@ bool LldbAdapter::Connect(const std::string& server, std::uint32_t port)
std::thread thread([&]() { EventListener(); });
thread.detach();

if (Settings::Instance()->Get<bool>("debugger.stopAtEntryPoint"))
if (Settings::Instance()->Get<bool>("debugger.stopAtEntryPoint") && m_hasEntryFunction)
AddBreakpoint(ModuleNameAndOffset(m_originalFileName, m_entryPoint - m_start));

std::string url = fmt::format("connect://{}:{}", server, port);
Expand Down
3 changes: 3 additions & 0 deletions core/debugadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ DebugAdapter::DebugAdapter(BinaryView* data)
// to get the original image base of the binary view, because LLDB requires the breakpoint address be relative to
// the original image base, and it does not work with a rebased one.
m_entryPoint = data->GetEntryPoint();
// For shared libraries which do not have a valid entry point, the GetEntryPoint will return 0x0 anyways.
// Here we check if there is actually a function at the entry point, to determine if the entry point is real.
m_hasEntryFunction = (data->GetAnalysisEntryPoint() != nullptr);
m_start = data->GetStart();
if (data->GetDefaultArchitecture())
m_defaultArchitecture = data->GetDefaultArchitecture()->GetName();
Expand Down
1 change: 1 addition & 0 deletions core/debugadapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ namespace BinaryNinjaDebugger {

protected:
uint64_t m_entryPoint;
bool m_hasEntryFunction;
uint64_t m_start;
std::string m_defaultArchitecture;
std::string m_originalFileName;
Expand Down

0 comments on commit 155bdec

Please sign in to comment.