summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2025-09-09 19:51:41 -0400
committerGlenn Smith <glenn@vector35.com>2025-09-09 20:43:07 -0400
commit3431848555231549392207583547533946548687 (patch)
treeb1fd999ab38ce5e776fdefd9f10912470712f449 /examples
parent3890253606296374983392205858649196758261 (diff)
Unflatten example: use source labels better
Diffstat (limited to 'examples')
-rw-r--r--examples/workflows/unflatten/library.cpp21
1 files changed, 3 insertions, 18 deletions
diff --git a/examples/workflows/unflatten/library.cpp b/examples/workflows/unflatten/library.cpp
index 4cd899ed..03f9df0b 100644
--- a/examples/workflows/unflatten/library.cpp
+++ b/examples/workflows/unflatten/library.cpp
@@ -323,25 +323,15 @@ void RewriteAction(Ref<AnalysisContext> context, bool doIt)
newMLIL = new MediumLevelILFunction(oldMLIL->GetArchitecture(), oldMLIL->GetFunction(), context->GetLowLevelILFunction());
newMLIL->PrepareToCopyFunction(oldMLIL);
- // Keep a running list of blocks and labels so we can line up the MLIL_GOTOs
- std::map<size_t, MediumLevelILLabel> blockLabels;
-
for (auto& block: oldMLIL->GetBasicBlocks())
{
newMLIL->PrepareToCopyBlock(block);
- newMLIL->SetCurrentAddress(block->GetArchitecture(), oldMLIL->GetInstruction(block->GetStart()).address);
-
- // Update block label list for the MLIL_GOTOs
- if (blockLabels.find(block->GetStart()) == blockLabels.end())
- {
- blockLabels[block->GetStart()] = MediumLevelILLabel{};
- }
- MediumLevelILLabel* label = &blockLabels[block->GetStart()];
- newMLIL->MarkLabel(*label);
for (size_t instrIndex = block->GetStart(); instrIndex < block->GetEnd(); instrIndex++)
{
auto oldInstr = oldMLIL->GetInstruction(instrIndex);
+ newMLIL->SetCurrentAddress(block->GetArchitecture(), oldInstr.address);
+
// If we find a MLIL_JUMP_TO with a known constant dest, then rewrite it
// to a MLIL_GOTO with the known dest filled in
if (oldInstr.operation == MLIL_JUMP_TO)
@@ -354,11 +344,7 @@ void RewriteAction(Ref<AnalysisContext> context, bool doIt)
return target.first == destValue;
}) != targets.end()) {
auto oldTargetIndex = targets[destValue];
- if (blockLabels.find(oldTargetIndex) == blockLabels.end())
- {
- blockLabels[oldTargetIndex] = MediumLevelILLabel{};
- }
- MediumLevelILLabel* targetLabel = &blockLabels[oldTargetIndex];
+ BNMediumLevelILLabel* targetLabel = newMLIL->GetLabelForSourceInstruction(oldTargetIndex);
newMLIL->AddInstruction(newMLIL->Goto(*targetLabel, oldInstr), oldInstr);
continue;
}
@@ -366,7 +352,6 @@ void RewriteAction(Ref<AnalysisContext> context, bool doIt)
}
// Otherwise, copy the instruction as-is
- newMLIL->SetCurrentAddress(block->GetArchitecture(), oldInstr.address);
newMLIL->AddInstruction(oldInstr.CopyTo(newMLIL), oldInstr);
}
}