Skip to content

Commit 84abd97

Browse files
xusheng6claude
andcommitted
emulator: return std::optional from ResolveCallTargetName
Addresses review feedback: use std::optional<std::string> instead of an empty-string sentinel to signal that a call target name could not be resolved, and update the callers accordingly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 121c53d commit 84abd97

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

plugins/emulator/core/llilemulator.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,21 +2215,21 @@ void LLILEmulator::WriteReturnValue(uint64_t value)
22152215
}
22162216

22172217

2218-
std::string LLILEmulator::ResolveCallTargetName(uint64_t addr)
2218+
std::optional<std::string> LLILEmulator::ResolveCallTargetName(uint64_t addr)
22192219
{
22202220
if (!m_view)
2221-
return "";
2221+
return std::nullopt;
22222222

22232223
Ref<Symbol> sym = m_view->GetSymbolByAddress(addr);
22242224
if (!sym)
2225-
return "";
2225+
return std::nullopt;
22262226

22272227
BNSymbolType type = sym->GetType();
22282228
if (type == ImportedFunctionSymbol || type == FunctionSymbol
22292229
|| type == LibraryFunctionSymbol || type == ExternalSymbol)
22302230
return sym->GetShortName();
22312231

2232-
return "";
2232+
return std::nullopt;
22332233
}
22342234

22352235

@@ -2308,11 +2308,11 @@ const std::unordered_map<std::string, LLILEmulator::StubFn>& LLILEmulator::GetSt
23082308

23092309
bool LLILEmulator::HandleBuiltinCall(uint64_t dest)
23102310
{
2311-
std::string name = ResolveCallTargetName(dest);
2312-
if (name.empty())
2311+
std::optional<std::string> name = ResolveCallTargetName(dest);
2312+
if (!name)
23132313
return false;
23142314

2315-
std::string normalized = NormalizeLibcName(name);
2315+
std::string normalized = NormalizeLibcName(*name);
23162316

23172317
auto& table = GetStubTable();
23182318
auto it = table.find(normalized);
@@ -2328,12 +2328,12 @@ bool LLILEmulator::HandleUnknownCall(uint64_t dest)
23282328
if (!m_nopUnknownExternals)
23292329
return false;
23302330

2331-
std::string name = ResolveCallTargetName(dest);
2332-
if (name.empty())
2331+
std::optional<std::string> name = ResolveCallTargetName(dest);
2332+
if (!name)
23332333
return false;
23342334

23352335
if (m_logLibcCalls)
2336-
LogInfo("BNIL Emulator: unhandled call to %s (0x%" PRIx64 "), returning 0", name.c_str(), dest);
2336+
LogInfo("BNIL Emulator: unhandled call to %s (0x%" PRIx64 "), returning 0", name->c_str(), dest);
23372337

23382338
WriteReturnValue(0);
23392339
return true;

plugins/emulator/core/llilemulator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "ilemulator.h"
44
#include "lowlevelilinstruction.h"
5+
#include <optional>
56

67
DECLARE_EMULATOR_API_OBJECT(BNLLILEmulator, LLILEmulator);
78

@@ -98,7 +99,7 @@ namespace BinaryNinjaEmulator
9899
void WriteReturnValue(uint64_t value);
99100
intx::uint512 ReadArgumentWide(size_t index);
100101
void WriteReturnValueWide(const intx::uint512& value);
101-
std::string ResolveCallTargetName(uint64_t addr);
102+
std::optional<std::string> ResolveCallTargetName(uint64_t addr);
102103
static std::string NormalizeLibcName(const std::string& name);
103104
bool HandleBuiltinCall(uint64_t dest);
104105
bool HandleUnknownCall(uint64_t dest);

0 commit comments

Comments
 (0)