@@ -11106,11 +11106,20 @@ namespace BinaryNinja {
1110611106 */
1110711107 void SetLowLevelILFunction(Ref<LowLevelILFunction> lowLevelIL);
1110811108
11109- /*! Set the new Medium Level IL for the current analysis context
11109+ /*! Set the new Medium Level IL for the current analysis context.
11110+
11111+ If mapping parameters are left as default (empty), then they will be automatically
11112+ computed for you based on previous calls to AddExpr() and AddInstruction()
1111011113
1111111114 \param mediumLevelIL the new Medium Level IL
11115+ \param llilSsaToMlilInstrMap New mappings from LLIL SSA -> MLIL instruction indices
11116+ \param llilSsaToMlilExprMap New mappings from LLIL SSA -> MLIL expression indices
1111211117 */
11113- void SetMediumLevelILFunction(Ref<MediumLevelILFunction> mediumLevelIL);
11118+ void SetMediumLevelILFunction(
11119+ Ref<MediumLevelILFunction> mediumLevelIL,
11120+ std::unordered_map<size_t /* llil ssa */, size_t /* mlil */> llilSsaToMlilInstrMap = {},
11121+ std::vector<BNExprMapInfo> llilSsaToMlilExprMap = {}
11122+ );
1111411123
1111511124 /*! Set the new High Level IL for the current analysis context
1111611125
@@ -13071,21 +13080,16 @@ namespace BinaryNinja {
1307113080 uint32_t sourceOperand;
1307213081 bool valid;
1307313082
13074- ILSourceLocation() : valid(false) {}
13083+ bool ilBased;
13084+ bool ilDirect;
13085+ size_t ilExprIndex;
1307513086
13076- ILSourceLocation(uint64_t addr, uint32_t operand) : address(addr), sourceOperand(operand), valid(true) {}
13077-
13078- ILSourceLocation(const BNLowLevelILInstruction& instr) :
13079- address(instr.address), sourceOperand(instr.sourceOperand), valid(true)
13080- {}
13087+ ILSourceLocation() : valid(false), ilBased(false) {}
1308113088
13082- ILSourceLocation(const BNMediumLevelILInstruction& instr) :
13083- address(instr.address), sourceOperand(instr.sourceOperand), valid(true)
13084- {}
13085-
13086- ILSourceLocation(const BNHighLevelILInstruction& instr) :
13087- address(instr.address), sourceOperand(instr.sourceOperand), valid(true)
13088- {}
13089+ ILSourceLocation(uint64_t addr, uint32_t operand) : address(addr), sourceOperand(operand), valid(true), ilBased(false) {}
13090+ ILSourceLocation(const struct LowLevelILInstruction& instr);
13091+ ILSourceLocation(const struct MediumLevelILInstruction& instr);
13092+ ILSourceLocation(const struct HighLevelILInstruction& instr);
1308913093 };
1309013094
1309113095 struct LowLevelILInstruction;
@@ -14535,6 +14539,22 @@ namespace BinaryNinja {
1453514539 public CoreRefCountObject<BNMediumLevelILFunction, BNNewMediumLevelILFunctionReference,
1453614540 BNFreeMediumLevelILFunction>
1453714541 {
14542+ struct TranslationData
14543+ {
14544+ MediumLevelILFunction* copyingFunction = nullptr;
14545+ std::unordered_map<size_t /* old function expr index */, std::vector<std::tuple<size_t /* new function expr index */, bool /* direct */>>> mlilToMlilExprMap;
14546+ std::unordered_map<size_t /* old function instr index */, std::vector<std::tuple<size_t /* new function instr index */, bool /* direct */>>> mlilToMlilInstrMap;
14547+ // todo maybe: llil ssa -> mlil mappings
14548+ };
14549+ std::unique_ptr<TranslationData> m_translationData;
14550+
14551+ void RecordMLILToMLILExprMap(size_t newExprIndex, const ILSourceLocation& location);
14552+ void RecordMLILToMLILInstrMap(size_t newInstrIndex, const ILSourceLocation& location);
14553+ std::unordered_map<size_t /* llil ssa */, size_t /* mlil */> GetLLILSSAToMLILInstrMap(bool fromTranslation);
14554+ std::vector<BNExprMapInfo> GetLLILSSAToMLILExprMap(bool fromTranslation);
14555+
14556+ friend class AnalysisContext;
14557+
1453814558 public:
1453914559 MediumLevelILFunction(Architecture* arch, Function* func = nullptr, LowLevelILFunction* lowLevelIL = nullptr);
1454014560 MediumLevelILFunction(BNMediumLevelILFunction* func);
@@ -14774,7 +14794,7 @@ namespace BinaryNinja {
1477414794 const ILSourceLocation& loc = ILSourceLocation());
1477514795 void MarkLabel(BNMediumLevelILLabel& label);
1477614796
14777- ExprId AddInstruction(ExprId expr);
14797+ ExprId AddInstruction(ExprId expr, const ILSourceLocation& loc = ILSourceLocation() );
1477814798
1477914799 std::vector<uint64_t> GetOperandList(ExprId i, size_t listOperand);
1478014800 ExprId AddLabelMap(const std::map<uint64_t, BNMediumLevelILLabel*>& labels);
0 commit comments