Skip to content

Commit 53fab4b

Browse files
xusheng6claude
andcommitted
[emulator] Require a valid architecture as an emulator invariant
The emulator half-supported a null architecture with scattered guards that silently no-op'd or fell back to little-endian. Instead reject creation of an emulator whose view/IL has no architecture (BNCreateLLILEmulator* returns null with a logged error) and drop the now-unnecessary null-arch guards, so m_arch is a hard invariant everywhere it is used. Addresses emesare review comment on PR #8314. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 02fd0ac commit 53fab4b

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

plugins/emulator/core/llilemulator.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void LLILEmulator::SetEntryPoint(LowLevelILFunction* il, size_t instrIndex)
6969

7070
void LLILEmulator::SetArgument(size_t index, const intx::uint512& value)
7171
{
72-
if (!m_view || !m_arch)
72+
if (!m_view)
7373
return;
7474

7575
Ref<Platform> platform = m_view->GetDefaultPlatform();
@@ -185,9 +185,8 @@ intx::uint512 LLILEmulator::SignedDivideOrModulo(
185185

186186
BNEndianness LLILEmulator::GetEndianness() const
187187
{
188-
if (m_arch)
189-
return m_arch->GetEndianness();
190-
return LittleEndian;
188+
// A valid architecture is an invariant established at construction.
189+
return m_arch->GetEndianness();
191190
}
192191

193192

@@ -516,7 +515,7 @@ uint64_t LLILEmulator::GetNativeReturnAddress() const
516515
uint64_t callAddr = m_il->GetInstruction(m_instrIndex).address;
517516

518517
// Use the architecture to get the native instruction length
519-
if (m_view && m_arch)
518+
if (m_view)
520519
{
521520
uint8_t buf[16];
522521
size_t bytesRead = m_view->Read(buf, callAddr, sizeof(buf));
@@ -3598,13 +3597,30 @@ bool LLILEmulator::StubFread(uint64_t)
35983597

35993598
BNLLILEmulator* BNCreateLLILEmulatorForView(BNBinaryView* view)
36003599
{
3601-
return EMU_API_OBJECT_CREATE(new LLILEmulator(new BinaryView(BNNewViewReference(view))));
3600+
LLILEmulator* emu = new LLILEmulator(new BinaryView(BNNewViewReference(view)));
3601+
// A valid architecture is an invariant of the emulator; reject creation without one
3602+
// rather than half-supporting a null architecture throughout.
3603+
if (!emu->GetArchitecture())
3604+
{
3605+
LogError("Cannot create LLIL emulator: the binary view has no default architecture");
3606+
emu->ReleaseAPIRef();
3607+
return nullptr;
3608+
}
3609+
return EMU_API_OBJECT_CREATE(emu);
36023610
}
36033611

36043612

36053613
BNLLILEmulator* BNCreateLLILEmulator(BNLowLevelILFunction* il, BNBinaryView* view)
36063614
{
3607-
return EMU_API_OBJECT_CREATE(new LLILEmulator(new LowLevelILFunction(BNNewLowLevelILFunctionReference(il)), new BinaryView(BNNewViewReference(view))));
3615+
LLILEmulator* emu = new LLILEmulator(
3616+
new LowLevelILFunction(BNNewLowLevelILFunctionReference(il)), new BinaryView(BNNewViewReference(view)));
3617+
if (!emu->GetArchitecture())
3618+
{
3619+
LogError("Cannot create LLIL emulator: the IL function has no architecture");
3620+
emu->ReleaseAPIRef();
3621+
return nullptr;
3622+
}
3623+
return EMU_API_OBJECT_CREATE(emu);
36083624
}
36093625

36103626

0 commit comments

Comments
 (0)