@@ -101,6 +101,8 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly
101101 auto & haltedDisassemblyAddresses = context.GetHaltedDisassemblyAddresses ();
102102 auto & inlinedUnresolvedIndirectBranches = context.GetInlinedUnresolvedIndirectBranches ();
103103
104+ Ref<LifterInstructionData> instrData = context.GetLifterInstructionData ();
105+
104106 bool hasInvalidInstructions = false ;
105107 set<ArchAndAddr> guidedSourceBlockTargets;
106108 auto guidedSourceBlocks = function->GetGuidedSourceBlocks ();
@@ -211,9 +213,13 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly
211213 {
212214 // Instruction is in the middle of a block, need to split the basic block into two
213215 Ref<BasicBlock> splitBlock = context.CreateBasicBlock (location.arch , location.address );
214- size_t instrDataLen;
215- const uint8_t * instrData = targetBlock->GetInstructionData (location.address , &instrDataLen);
216- splitBlock->AddInstructionData (instrData, instrDataLen);
216+ if (instrData)
217+ {
218+ // Copy before appending, as Append can invalidate the span returned by Get
219+ std::span<const uint8_t > tail = instrData->Get (targetBlock, location.address );
220+ std::vector<uint8_t > splitData (tail.begin (), tail.end ());
221+ instrData->Append (splitBlock, splitData);
222+ }
217223 splitBlock->SetFallThroughToFunction (targetBlock->IsFallThroughToFunction ());
218224 splitBlock->SetUndeterminedOutgoingEdges (targetBlock->HasUndeterminedOutgoingEdges ());
219225 splitBlock->SetCanExit (targetBlock->CanExit ());
@@ -594,7 +600,8 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly
594600 }
595601
596602 location.address += info.length ;
597- block->AddInstructionData (opcode, info.length );
603+ if (instrData)
604+ instrData->Append (block, std::span<const uint8_t >(opcode, info.length ));
598605
599606 if (endsBlock && !info.delaySlots )
600607 break ;
@@ -780,12 +787,13 @@ static void ApplyExternPointerForRelocation(
780787
781788bool Architecture::DefaultLiftFunction (LowLevelILFunction* function, FunctionLifterContext& context)
782789{
783- std::unique_ptr<FastBasicBlockMap<DataBuffer>> instrData;
784790 Ref<BinaryView> data = context.GetView ();
785791 Ref<Logger> logger = context.GetLogger ();
786792 Ref<Platform> platform = context.GetPlatform ();
787793 std::set<ArchAndAddr> noReturnCalls = context.GetNoReturnCalls ();
788794 std::vector<Ref<BasicBlock>> blocks = context.GetBasicBlocks ();
795+ Ref<LifterInstructionData> lifterInstructionData = context.GetLifterInstructionData ();
796+ FastBasicBlockMap<DataBuffer> instrData (blocks);
789797 std::map<ArchAndAddr, bool > contextualReturns = context.GetContextualReturns ();
790798 std::map<ArchAndAddr, ArchAndAddr> inlinedRemapping = context.GetInlinedRemapping ();
791799 std::optional<pair<ArchAndAddr, ArchAndAddr>> indirectSource;
@@ -835,26 +843,20 @@ bool Architecture::DefaultLiftFunction(LowLevelILFunction* function, FunctionLif
835843 }
836844
837845 size_t len = 0 ;
838- const uint8_t * opcode;
839-
840- if (i->HasInstructionData ())
846+ const uint8_t * opcode = nullptr ;
847+ if (lifterInstructionData)
841848 {
842- opcode = i->GetInstructionData (addr, &len);
843-
844- if (len == 0 )
845- {
846- // Instruction data not found, emit undefined IL instruction
847- function->AddInstruction (function->AddExpr (LLIL_UNDEF , 0 , 0 ));
848- logger->LogDebug (" Instruction data not found, inserted LLIL_UNDEF at %#" PRIx64, addr);
849- break ;
850- }
849+ std::span<const uint8_t > bytes = lifterInstructionData->Get (i, addr);
850+ opcode = bytes.data ();
851+ len = bytes.size ();
851852 }
852- else
853- {
854- if (!instrData)
855- instrData = std::make_unique<FastBasicBlockMap<DataBuffer>>(blocks);
856853
857- DataBuffer& buffer = (*instrData)[i];
854+ if (!opcode)
855+ {
856+ // The instruction data has no bytes for this block (a function loaded from the
857+ // database, a block split after analysis, or an architecture that does not populate
858+ // it). Read the block from the view instead.
859+ DataBuffer& buffer = instrData[i];
858860 if (buffer.GetLength () == 0 )
859861 buffer = data->ReadBuffer (i->GetStart (), i->GetEnd () - i->GetStart ());
860862
0 commit comments