diff --git a/highlevelilinstruction.cpp b/highlevelilinstruction.cpp index 6fe436180..0861cf311 100644 --- a/highlevelilinstruction.cpp +++ b/highlevelilinstruction.cpp @@ -1370,162 +1370,165 @@ void HighLevelILInstruction::VisitExprs(const std::function& subExprHandler) const + HighLevelILFunction* dest, const std::function& subExprHandler, const ILSourceLocation& sourceLocation) const { vector output, params; + + const auto& loc = sourceLocation.valid ? sourceLocation : ILSourceLocation{*this}; + switch (operation) { case HLIL_NOP: - return dest->Nop(*this); + return dest->Nop(loc); case HLIL_BLOCK: for (auto i : GetBlockExprs()) params.push_back(subExprHandler(i)); - return dest->Block(params, *this); + return dest->Block(params, loc); case HLIL_IF: return dest->If(subExprHandler(GetConditionExpr()), subExprHandler(GetTrueExpr()), - subExprHandler(GetFalseExpr()), *this); + subExprHandler(GetFalseExpr()), loc); case HLIL_WHILE: return dest->While( - subExprHandler(GetConditionExpr()), subExprHandler(GetLoopExpr()), *this); + subExprHandler(GetConditionExpr()), subExprHandler(GetLoopExpr()), loc); case HLIL_WHILE_SSA: return dest->WhileSSA(subExprHandler(GetConditionPhiExpr()), - subExprHandler(GetConditionExpr()), subExprHandler(GetLoopExpr()), *this); + subExprHandler(GetConditionExpr()), subExprHandler(GetLoopExpr()), loc); case HLIL_DO_WHILE: return dest->DoWhile( - subExprHandler(GetLoopExpr()), subExprHandler(GetConditionExpr()), *this); + subExprHandler(GetLoopExpr()), subExprHandler(GetConditionExpr()), loc); case HLIL_DO_WHILE_SSA: return dest->DoWhileSSA(subExprHandler(GetLoopExpr()), subExprHandler(GetConditionPhiExpr()), - subExprHandler(GetConditionExpr()), *this); + subExprHandler(GetConditionExpr()), loc); case HLIL_FOR: return dest->For(subExprHandler(GetInitExpr()), subExprHandler(GetConditionExpr()), - subExprHandler(GetUpdateExpr()), subExprHandler(GetLoopExpr()), *this); + subExprHandler(GetUpdateExpr()), subExprHandler(GetLoopExpr()), loc); case HLIL_FOR_SSA: return dest->ForSSA(subExprHandler(GetInitExpr()), subExprHandler(GetConditionPhiExpr()), subExprHandler(GetConditionExpr()), - subExprHandler(GetUpdateExpr()), subExprHandler(GetLoopExpr()), *this); + subExprHandler(GetUpdateExpr()), subExprHandler(GetLoopExpr()), loc); case HLIL_SWITCH: for (auto i : GetCases()) params.push_back(subExprHandler(i)); return dest->Switch(subExprHandler(GetConditionExpr()), - subExprHandler(GetDefaultExpr()), params, *this); + subExprHandler(GetDefaultExpr()), params, loc); case HLIL_CASE: for (auto i : GetValueExprs()) params.push_back(subExprHandler(i)); - return dest->Case(params, subExprHandler(GetTrueExpr()), *this); + return dest->Case(params, subExprHandler(GetTrueExpr()), loc); case HLIL_BREAK: - return dest->Break(*this); + return dest->Break(loc); case HLIL_CONTINUE: - return dest->Continue(*this); + return dest->Continue(loc); case HLIL_GOTO: - return dest->Goto(GetTarget(), *this); + return dest->Goto(GetTarget(), loc); case HLIL_LABEL: - return dest->Label(GetTarget(), *this); + return dest->Label(GetTarget(), loc); case HLIL_VAR_DECLARE: - return dest->VarDeclare(GetVariable(), *this); + return dest->VarDeclare(GetVariable(), loc); case HLIL_VAR_INIT: return dest->VarInit( - size, GetDestVariable(), subExprHandler(GetSourceExpr()), *this); + size, GetDestVariable(), subExprHandler(GetSourceExpr()), loc); case HLIL_VAR_INIT_SSA: return dest->VarInitSSA( - size, GetDestSSAVariable(), subExprHandler(GetSourceExpr()), *this); + size, GetDestSSAVariable(), subExprHandler(GetSourceExpr()), loc); case HLIL_ASSIGN: return dest->Assign( - size, subExprHandler(GetDestExpr()), subExprHandler(GetSourceExpr()), *this); + size, subExprHandler(GetDestExpr()), subExprHandler(GetSourceExpr()), loc); case HLIL_ASSIGN_UNPACK: for (auto i : GetDestExprs()) output.push_back(subExprHandler(i)); - return dest->AssignUnpack(output, subExprHandler(GetSourceExpr()), *this); + return dest->AssignUnpack(output, subExprHandler(GetSourceExpr()), loc); case HLIL_ASSIGN_MEM_SSA: return dest->AssignMemSSA(size, subExprHandler(GetDestExpr()), GetDestMemoryVersion(), subExprHandler(GetSourceExpr()), - GetSourceMemoryVersion(), *this); + GetSourceMemoryVersion(), loc); case HLIL_ASSIGN_UNPACK_MEM_SSA: for (auto i : GetDestExprs()) output.push_back(subExprHandler(i)); return dest->AssignUnpackMemSSA(output, GetDestMemoryVersion(), subExprHandler(GetSourceExpr()), - GetSourceMemoryVersion(), *this); + GetSourceMemoryVersion(), loc); case HLIL_FORCE_VER: - return dest->ForceVer(size, GetDestVariable(), GetVariable(), *this); + return dest->ForceVer(size, GetDestVariable(), GetVariable(), loc); case HLIL_FORCE_VER_SSA: - return dest->ForceVerSSA(size, GetDestSSAVariable(), GetSSAVariable(), *this); + return dest->ForceVerSSA(size, GetDestSSAVariable(), GetSSAVariable(), loc); case HLIL_ASSERT: - return dest->Assert(size, GetVariable(), GetConstraint(), *this); + return dest->Assert(size, GetVariable(), GetConstraint(), loc); case HLIL_ASSERT_SSA: - return dest->AssertSSA(size, GetSSAVariable(), GetConstraint(), *this); + return dest->AssertSSA(size, GetSSAVariable(), GetConstraint(), loc); case HLIL_VAR: - return dest->Var(size, GetVariable(), *this); + return dest->Var(size, GetVariable(), loc); case HLIL_VAR_SSA: - return dest->VarSSA(size, GetSSAVariable(), *this); + return dest->VarSSA(size, GetSSAVariable(), loc); case HLIL_VAR_PHI: - return dest->VarPhi(GetDestSSAVariable(), GetSourceSSAVariables(), *this); + return dest->VarPhi(GetDestSSAVariable(), GetSourceSSAVariables(), loc); case HLIL_MEM_PHI: - return dest->MemPhi(GetDestMemoryVersion(), GetSourceMemoryVersions(), *this); + return dest->MemPhi(GetDestMemoryVersion(), GetSourceMemoryVersions(), loc); case HLIL_STRUCT_FIELD: return dest->StructField(size, subExprHandler(GetSourceExpr()), - GetOffset(), GetMemberIndex(), *this); + GetOffset(), GetMemberIndex(), loc); case HLIL_ARRAY_INDEX: return dest->ArrayIndex(size, subExprHandler(GetSourceExpr()), - subExprHandler(GetIndexExpr()), *this); + subExprHandler(GetIndexExpr()), loc); case HLIL_ARRAY_INDEX_SSA: return dest->ArrayIndexSSA(size, subExprHandler(GetSourceExpr()), GetSourceMemoryVersion(), subExprHandler(GetIndexExpr()), - *this); + loc); case HLIL_SPLIT: return dest->Split( - size, subExprHandler(GetHighExpr()), subExprHandler(GetLowExpr()), *this); + size, subExprHandler(GetHighExpr()), subExprHandler(GetLowExpr()), loc); case HLIL_DEREF: - return dest->Deref(size, subExprHandler(GetSourceExpr()), *this); + return dest->Deref(size, subExprHandler(GetSourceExpr()), loc); case HLIL_DEREF_FIELD: return dest->DerefField(size, subExprHandler(GetSourceExpr()), GetOffset(), - GetMemberIndex(), *this); + GetMemberIndex(), loc); case HLIL_DEREF_SSA: return dest->DerefSSA( - size, subExprHandler(GetSourceExpr()), GetSourceMemoryVersion(), *this); + size, subExprHandler(GetSourceExpr()), GetSourceMemoryVersion(), loc); case HLIL_DEREF_FIELD_SSA: return dest->DerefFieldSSA(size, subExprHandler(GetSourceExpr()), GetSourceMemoryVersion(), GetOffset(), - GetMemberIndex(), *this); + GetMemberIndex(), loc); case HLIL_ADDRESS_OF: - return dest->AddressOf(subExprHandler(GetSourceExpr()), *this); + return dest->AddressOf(subExprHandler(GetSourceExpr()), loc); case HLIL_CALL: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); - return dest->Call(subExprHandler(GetDestExpr()), params, *this); + return dest->Call(subExprHandler(GetDestExpr()), params, loc); case HLIL_SYSCALL: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); - return dest->Syscall(params, *this); + return dest->Syscall(params, loc); case HLIL_TAILCALL: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); - return dest->TailCall(subExprHandler(GetDestExpr()), params, *this); + return dest->TailCall(subExprHandler(GetDestExpr()), params, loc); case HLIL_CALL_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->CallSSA(subExprHandler(GetDestExpr()), params, - GetDestMemoryVersion(), GetSourceMemoryVersion(), *this); + GetDestMemoryVersion(), GetSourceMemoryVersion(), loc); case HLIL_SYSCALL_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->SyscallSSA( - params, GetDestMemoryVersion(), GetSourceMemoryVersion(), *this); + params, GetDestMemoryVersion(), GetSourceMemoryVersion(), loc); case HLIL_RET: for (auto i : GetSourceExprs()) params.push_back(subExprHandler(i)); - return dest->Return(params, *this); + return dest->Return(params, loc); case HLIL_NORET: - return dest->NoReturn(*this); + return dest->NoReturn(loc); case HLIL_UNREACHABLE: - return dest->Unreachable(*this); + return dest->Unreachable(loc); case HLIL_NEG: case HLIL_NOT: case HLIL_SX: @@ -1544,7 +1547,7 @@ ExprId HighLevelILInstruction::CopyTo( case HLIL_FLOOR: case HLIL_CEIL: case HLIL_FTRUNC: - return dest->AddExprWithLocation(operation, *this, size, subExprHandler(AsOneOperand().GetSourceExpr())); + return dest->AddExprWithLocation(operation, loc, size, subExprHandler(AsOneOperand().GetSourceExpr())); case HLIL_ADD: case HLIL_SUB: case HLIL_AND: @@ -1590,44 +1593,44 @@ ExprId HighLevelILInstruction::CopyTo( case HLIL_FCMP_GT: case HLIL_FCMP_O: case HLIL_FCMP_UO: - return dest->AddExprWithLocation(operation, *this, size, subExprHandler(AsTwoOperand().GetLeftExpr()), + return dest->AddExprWithLocation(operation, loc, size, subExprHandler(AsTwoOperand().GetLeftExpr()), subExprHandler(AsTwoOperand().GetRightExpr())); case HLIL_ADC: case HLIL_SBB: case HLIL_RLC: case HLIL_RRC: - return dest->AddExprWithLocation(operation, *this, size, subExprHandler(AsTwoOperandWithCarry().GetLeftExpr()), + return dest->AddExprWithLocation(operation, loc, size, subExprHandler(AsTwoOperandWithCarry().GetLeftExpr()), subExprHandler(AsTwoOperandWithCarry().GetRightExpr()), subExprHandler(AsTwoOperandWithCarry().GetCarryExpr())); case HLIL_CONST: - return dest->Const(size, GetConstant(), *this); + return dest->Const(size, GetConstant(), loc); case HLIL_CONST_PTR: - return dest->ConstPointer(size, GetConstant(), *this); + return dest->ConstPointer(size, GetConstant(), loc); case HLIL_EXTERN_PTR: - return dest->ExternPointer(size, GetConstant(), GetOffset(), *this); + return dest->ExternPointer(size, GetConstant(), GetOffset(), loc); case HLIL_FLOAT_CONST: - return dest->FloatConstRaw(size, GetConstant(), *this); + return dest->FloatConstRaw(size, GetConstant(), loc); case HLIL_IMPORT: - return dest->ImportedAddress(size, GetConstant(), *this); + return dest->ImportedAddress(size, GetConstant(), loc); case HLIL_CONST_DATA: - return dest->ConstData(size, GetConstantData(), *this); + return dest->ConstData(size, GetConstantData(), loc); case HLIL_BP: - return dest->Breakpoint(*this); + return dest->Breakpoint(loc); case HLIL_TRAP: - return dest->Trap(GetVector(), *this); + return dest->Trap(GetVector(), loc); case HLIL_INTRINSIC: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); - return dest->Intrinsic(GetIntrinsic(), params, *this); + return dest->Intrinsic(GetIntrinsic(), params, loc); case HLIL_INTRINSIC_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->IntrinsicSSA(GetIntrinsic(), params, - GetDestMemoryVersion(), GetSourceMemoryVersion(), *this); + GetDestMemoryVersion(), GetSourceMemoryVersion(), loc); case HLIL_UNDEF: - return dest->Undefined(*this); + return dest->Undefined(loc); case HLIL_UNIMPL: - return dest->Unimplemented(*this); + return dest->Unimplemented(loc); default: throw HighLevelILInstructionAccessException(); } diff --git a/highlevelilinstruction.h b/highlevelilinstruction.h index 9be7d7c5e..53a3c5677 100644 --- a/highlevelilinstruction.h +++ b/highlevelilinstruction.h @@ -25,6 +25,7 @@ #include #ifdef BINARYNINJACORE_LIBRARY #include "variable.h" + #include "ilsourcelocation.h" #else #include "binaryninjaapi.h" #endif @@ -487,9 +488,10 @@ namespace BinaryNinja void VisitExprs(const std::function& preFunc, const std::function& postFunc) const; - ExprId CopyTo(HighLevelILFunction* dest) const; + ExprId CopyTo(HighLevelILFunction* dest, const ILSourceLocation& sourceLocation = {}) const; ExprId CopyTo(HighLevelILFunction* dest, - const std::function& subExprHandler) const; + const std::function& subExprHandler, + const ILSourceLocation& sourceLocation = {}) const; bool operator<(const HighLevelILInstruction& other) const; bool operator==(const HighLevelILInstruction& other) const; diff --git a/lowlevelilinstruction.cpp b/lowlevelilinstruction.cpp index 26f5055d5..649c5c99f 100644 --- a/lowlevelilinstruction.cpp +++ b/lowlevelilinstruction.cpp @@ -2064,143 +2064,146 @@ void LowLevelILInstruction::VisitExprs(const std::function& subExprHandler) const + LowLevelILFunction* dest, const std::function& subExprHandler, const ILSourceLocation& sourceLocation) const { vector params; BNLowLevelILLabel* labelA; BNLowLevelILLabel* labelB; + + const auto& loc = sourceLocation.valid ? sourceLocation : ILSourceLocation{*this}; + switch (operation) { case LLIL_NOP: - return dest->Nop(); + return dest->Nop(loc); case LLIL_SET_REG: return dest->SetRegister( - size, GetDestRegister(), subExprHandler(GetSourceExpr()), flags, *this); + size, GetDestRegister(), subExprHandler(GetSourceExpr()), flags, loc); case LLIL_SET_REG_SPLIT: return dest->SetRegisterSplit(size, GetHighRegister(), GetLowRegister(), - subExprHandler(GetSourceExpr()), flags, *this); + subExprHandler(GetSourceExpr()), flags, loc); case LLIL_SET_REG_SSA: return dest->SetRegisterSSA( - size, GetDestSSARegister(), subExprHandler(GetSourceExpr()), *this); + size, GetDestSSARegister(), subExprHandler(GetSourceExpr()), loc); case LLIL_SET_REG_SSA_PARTIAL: return dest->SetRegisterSSAPartial(size, GetDestSSARegister(), GetPartialRegister(), subExprHandler(GetSourceExpr()), - *this); + loc); case LLIL_SET_REG_SPLIT_SSA: return dest->SetRegisterSplitSSA(size, GetHighSSARegister(), GetLowSSARegister(), subExprHandler(GetSourceExpr()), - *this); + loc); case LLIL_SET_REG_STACK_REL: return dest->SetRegisterStackTopRelative(size, GetDestRegisterStack(), subExprHandler(GetDestExpr()), - subExprHandler(GetSourceExpr()), flags, *this); + subExprHandler(GetSourceExpr()), flags, loc); case LLIL_REG_STACK_PUSH: return dest->RegisterStackPush(size, GetDestRegisterStack(), - subExprHandler(GetSourceExpr()), flags, *this); + subExprHandler(GetSourceExpr()), flags, loc); case LLIL_SET_REG_STACK_REL_SSA: return dest->SetRegisterStackTopRelativeSSA(size, GetDestSSARegisterStack().regStack, GetDestSSARegisterStack().version, GetSourceSSARegisterStack().version, subExprHandler(GetDestExpr()), GetTopSSARegister(), - subExprHandler(GetSourceExpr()), *this); + subExprHandler(GetSourceExpr()), loc); case LLIL_SET_REG_STACK_ABS_SSA: return dest->SetRegisterStackAbsoluteSSA(size, GetDestSSARegisterStack().regStack, GetDestSSARegisterStack().version, GetSourceSSARegisterStack().version, GetDestRegister(), subExprHandler(GetSourceExpr()), - *this); + loc); case LLIL_SET_FLAG: - return dest->SetFlag(GetDestFlag(), subExprHandler(GetSourceExpr()), *this); + return dest->SetFlag(GetDestFlag(), subExprHandler(GetSourceExpr()), loc); case LLIL_SET_FLAG_SSA: return dest->SetFlagSSA( - GetDestSSAFlag(), subExprHandler(GetSourceExpr()), *this); + GetDestSSAFlag(), subExprHandler(GetSourceExpr()), loc); case LLIL_FORCE_VER: - return dest->ForceVer(size, GetDestRegister(), *this); + return dest->ForceVer(size, GetDestRegister(), loc); case LLIL_FORCE_VER_SSA: - return dest->ForceVerSSA(size, GetDestSSARegister(), GetSourceSSARegister(), *this); + return dest->ForceVerSSA(size, GetDestSSARegister(), GetSourceSSARegister(), loc); case LLIL_ASSERT: - return dest->Assert(size, GetSourceRegister(), GetConstraint(), *this); + return dest->Assert(size, GetSourceRegister(), GetConstraint(), loc); case LLIL_ASSERT_SSA: - return dest->AssertSSA(size, GetSourceSSARegister(), GetConstraint(), *this); + return dest->AssertSSA(size, GetSourceSSARegister(), GetConstraint(), loc); case LLIL_LOAD: - return dest->Load(size, subExprHandler(GetSourceExpr()), flags, *this); + return dest->Load(size, subExprHandler(GetSourceExpr()), flags, loc); case LLIL_LOAD_SSA: return dest->LoadSSA( - size, subExprHandler(GetSourceExpr()), GetSourceMemoryVersion(), *this); + size, subExprHandler(GetSourceExpr()), GetSourceMemoryVersion(), loc); case LLIL_STORE: return dest->Store( - size, subExprHandler(GetDestExpr()), subExprHandler(GetSourceExpr()), flags, *this); + size, subExprHandler(GetDestExpr()), subExprHandler(GetSourceExpr()), flags, loc); case LLIL_STORE_SSA: return dest->StoreSSA(size, subExprHandler(GetDestExpr()), subExprHandler(GetSourceExpr()), GetDestMemoryVersion(), - GetSourceMemoryVersion(), *this); + GetSourceMemoryVersion(), loc); case LLIL_REG: - return dest->Register(size, GetSourceRegister(), *this); + return dest->Register(size, GetSourceRegister(), loc); case LLIL_REG_SSA: - return dest->RegisterSSA(size, GetSourceSSARegister(), *this); + return dest->RegisterSSA(size, GetSourceSSARegister(), loc); case LLIL_REG_SSA_PARTIAL: return dest->RegisterSSAPartial( - size, GetSourceSSARegister(), GetPartialRegister(), *this); + size, GetSourceSSARegister(), GetPartialRegister(), loc); case LLIL_REG_SPLIT: - return dest->RegisterSplit(size, GetHighRegister(), GetLowRegister(), *this); + return dest->RegisterSplit(size, GetHighRegister(), GetLowRegister(), loc); case LLIL_REG_SPLIT_SSA: return dest->RegisterSplitSSA( - size, GetHighSSARegister(), GetLowSSARegister(), *this); + size, GetHighSSARegister(), GetLowSSARegister(), loc); case LLIL_REG_STACK_REL: return dest->RegisterStackTopRelative(size, GetSourceRegisterStack(), - subExprHandler(GetSourceExpr()), *this); + subExprHandler(GetSourceExpr()), loc); case LLIL_REG_STACK_POP: - return dest->RegisterStackPop(size, GetSourceRegisterStack(), flags, *this); + return dest->RegisterStackPop(size, GetSourceRegisterStack(), flags, loc); case LLIL_REG_STACK_FREE_REG: - return dest->RegisterStackFreeReg(GetDestRegister(), *this); + return dest->RegisterStackFreeReg(GetDestRegister(), loc); case LLIL_REG_STACK_FREE_REL: return dest->RegisterStackFreeTopRelative(GetDestRegisterStack(), - subExprHandler(GetDestExpr()), *this); + subExprHandler(GetDestExpr()), loc); case LLIL_REG_STACK_REL_SSA: return dest->RegisterStackTopRelativeSSA(size, GetSourceSSARegisterStack(), subExprHandler(GetSourceExpr()), GetTopSSARegister(), - *this); + loc); case LLIL_REG_STACK_ABS_SSA: return dest->RegisterStackAbsoluteSSA(size, GetSourceSSARegisterStack(), - GetSourceRegister(), *this); + GetSourceRegister(), loc); case LLIL_REG_STACK_FREE_REL_SSA: return dest->RegisterStackFreeTopRelativeSSA(GetDestSSARegisterStack().regStack, GetDestSSARegisterStack().version, GetSourceSSARegisterStack().version, subExprHandler(GetDestExpr()), - GetTopSSARegister(), *this); + GetTopSSARegister(), loc); case LLIL_REG_STACK_FREE_ABS_SSA: return dest->RegisterStackFreeAbsoluteSSA(GetDestSSARegisterStack().regStack, GetDestSSARegisterStack().version, GetSourceSSARegisterStack().version, - GetDestRegister(), *this); + GetDestRegister(), loc); case LLIL_FLAG: - return dest->Flag(GetSourceFlag(), *this); + return dest->Flag(GetSourceFlag(), loc); case LLIL_FLAG_SSA: - return dest->FlagSSA(GetSourceSSAFlag(), *this); + return dest->FlagSSA(GetSourceSSAFlag(), loc); case LLIL_FLAG_BIT: - return dest->FlagBit(size, GetSourceFlag(), GetBitIndex(), *this); + return dest->FlagBit(size, GetSourceFlag(), GetBitIndex(), loc); case LLIL_FLAG_BIT_SSA: - return dest->FlagBitSSA(size, GetSourceSSAFlag(), GetBitIndex(), *this); + return dest->FlagBitSSA(size, GetSourceSSAFlag(), GetBitIndex(), loc); case LLIL_JUMP: - return dest->Jump(subExprHandler(GetDestExpr()), *this); + return dest->Jump(subExprHandler(GetDestExpr()), loc); case LLIL_CALL: - return dest->Call(subExprHandler(GetDestExpr()), *this); + return dest->Call(subExprHandler(GetDestExpr()), loc); case LLIL_CALL_STACK_ADJUST: return dest->CallStackAdjust(subExprHandler(GetDestExpr()), - GetStackAdjustment(), GetRegisterStackAdjustments(), *this); + GetStackAdjustment(), GetRegisterStackAdjustments(), loc); case LLIL_TAILCALL: - return dest->TailCall(subExprHandler(GetDestExpr()), *this); + return dest->TailCall(subExprHandler(GetDestExpr()), loc); case LLIL_RET: - return dest->Return(subExprHandler(GetDestExpr()), *this); + return dest->Return(subExprHandler(GetDestExpr()), loc); case LLIL_JUMP_TO: { map labelList; @@ -2208,10 +2211,10 @@ ExprId LowLevelILInstruction::CopyTo( { labelA = dest->GetLabelForSourceInstruction(target.second); if (!labelA) - return dest->Jump(subExprHandler(GetDestExpr()), *this); + return dest->Jump(subExprHandler(GetDestExpr()), loc); labelList[target.first] = labelA; } - return dest->JumpTo(subExprHandler(GetDestExpr()), labelList, *this); + return dest->JumpTo(subExprHandler(GetDestExpr()), labelList, loc); } case LLIL_GOTO: labelA = dest->GetLabelForSourceInstruction(GetTarget()); @@ -2219,63 +2222,63 @@ ExprId LowLevelILInstruction::CopyTo( { return dest->Jump(dest->ConstPointer(function->GetArchitecture()->GetAddressSize(), function->GetInstruction(GetTarget()).address), - *this); + loc); } - return dest->Goto(*labelA, *this); + return dest->Goto(*labelA, loc); case LLIL_IF: labelA = dest->GetLabelForSourceInstruction(GetTrueTarget()); labelB = dest->GetLabelForSourceInstruction(GetFalseTarget()); if ((!labelA) || (!labelB)) - return dest->Undefined(*this); - return dest->If(subExprHandler(GetConditionExpr()), *labelA, *labelB, *this); + return dest->Undefined(loc); + return dest->If(subExprHandler(GetConditionExpr()), *labelA, *labelB, loc); case LLIL_FLAG_COND: - return dest->FlagCondition(GetFlagCondition(), GetSemanticFlagClass(), *this); + return dest->FlagCondition(GetFlagCondition(), GetSemanticFlagClass(), loc); case LLIL_FLAG_GROUP: - return dest->FlagGroup(GetSemanticFlagGroup(), *this); + return dest->FlagGroup(GetSemanticFlagGroup(), loc); case LLIL_TRAP: - return dest->Trap(GetVector(), *this); + return dest->Trap(GetVector(), loc); case LLIL_CALL_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->CallSSA(GetOutputSSARegisters(), subExprHandler(GetDestExpr()), params, GetStackSSARegister(), GetDestMemoryVersion(), - GetSourceMemoryVersion(), *this); + GetSourceMemoryVersion(), loc); case LLIL_SYSCALL_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->SystemCallSSA(GetOutputSSARegisters(), params, GetStackSSARegister(), GetDestMemoryVersion(), - GetSourceMemoryVersion(), *this); + GetSourceMemoryVersion(), loc); case LLIL_TAILCALL_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->TailCallSSA(GetOutputSSARegisters(), subExprHandler(GetDestExpr()), params, GetStackSSARegister(), - GetDestMemoryVersion(), GetSourceMemoryVersion(), *this); + GetDestMemoryVersion(), GetSourceMemoryVersion(), loc); case LLIL_REG_PHI: - return dest->RegisterPhi(GetDestSSARegister(), GetSourceSSARegisters(), *this); + return dest->RegisterPhi(GetDestSSARegister(), GetSourceSSARegisters(), loc); case LLIL_REG_STACK_PHI: return dest->RegisterStackPhi( - GetDestSSARegisterStack(), GetSourceSSARegisterStacks(), *this); + GetDestSSARegisterStack(), GetSourceSSARegisterStacks(), loc); case LLIL_FLAG_PHI: - return dest->FlagPhi(GetDestSSAFlag(), GetSourceSSAFlags(), *this); + return dest->FlagPhi(GetDestSSAFlag(), GetSourceSSAFlags(), loc); case LLIL_MEM_PHI: - return dest->MemoryPhi(GetDestMemoryVersion(), GetSourceMemoryVersions(), *this); + return dest->MemoryPhi(GetDestMemoryVersion(), GetSourceMemoryVersions(), loc); case LLIL_CONST: - return dest->Const(size, GetConstant(), *this); + return dest->Const(size, GetConstant(), loc); case LLIL_CONST_PTR: - return dest->ConstPointer(size, GetConstant(), *this); + return dest->ConstPointer(size, GetConstant(), loc); case LLIL_EXTERN_PTR: - return dest->ExternPointer(size, GetConstant(), GetOffset(), *this); + return dest->ExternPointer(size, GetConstant(), GetOffset(), loc); case LLIL_FLOAT_CONST: - return dest->FloatConstRaw(size, GetConstant(), *this); + return dest->FloatConstRaw(size, GetConstant(), loc); case LLIL_POP: case LLIL_NORET: case LLIL_SYSCALL: case LLIL_BP: case LLIL_UNDEF: case LLIL_UNIMPL: - return dest->AddExprWithLocation(operation, *this, size, flags); + return dest->AddExprWithLocation(operation, loc, size, flags); case LLIL_PUSH: case LLIL_NEG: case LLIL_NOT: @@ -2294,7 +2297,7 @@ ExprId LowLevelILInstruction::CopyTo( case LLIL_FLOOR: case LLIL_CEIL: case LLIL_FTRUNC: - return dest->AddExprWithLocation(operation, *this, size, flags, subExprHandler(AsOneOperand().GetSourceExpr())); + return dest->AddExprWithLocation(operation, loc, size, flags, subExprHandler(AsOneOperand().GetSourceExpr())); case LLIL_ADD: case LLIL_SUB: case LLIL_AND: @@ -2340,13 +2343,13 @@ ExprId LowLevelILInstruction::CopyTo( case LLIL_FCMP_GT: case LLIL_FCMP_O: case LLIL_FCMP_UO: - return dest->AddExprWithLocation(operation, *this, size, flags, subExprHandler(AsTwoOperand().GetLeftExpr()), + return dest->AddExprWithLocation(operation, loc, size, flags, subExprHandler(AsTwoOperand().GetLeftExpr()), subExprHandler(AsTwoOperand().GetRightExpr())); case LLIL_ADC: case LLIL_SBB: case LLIL_RLC: case LLIL_RRC: - return dest->AddExprWithLocation(operation, *this, size, flags, + return dest->AddExprWithLocation(operation, loc, size, flags, subExprHandler(AsTwoOperandWithCarry().GetLeftExpr()), subExprHandler(AsTwoOperandWithCarry().GetRightExpr()), subExprHandler(AsTwoOperandWithCarry().GetCarryExpr())); @@ -2354,25 +2357,25 @@ ExprId LowLevelILInstruction::CopyTo( for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->Intrinsic( - GetOutputRegisterOrFlagList(), GetIntrinsic(), params, flags, *this); + GetOutputRegisterOrFlagList(), GetIntrinsic(), params, flags, loc); case LLIL_INTRINSIC_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->IntrinsicSSA( - GetOutputSSARegisterOrFlagList(), GetIntrinsic(), params, *this); + GetOutputSSARegisterOrFlagList(), GetIntrinsic(), params, loc); case LLIL_MEMORY_INTRINSIC_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->MemoryIntrinsicSSA(GetOutputSSARegisterOrFlagList(), GetIntrinsic(), - params, GetDestMemoryVersion(), GetSourceMemoryVersion(), *this); + params, GetDestMemoryVersion(), GetSourceMemoryVersion(), loc); case LLIL_SEPARATE_PARAM_LIST_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); - return dest->SeparateParamListSSA(params, *this); + return dest->SeparateParamListSSA(params, loc); case LLIL_SHARED_PARAM_SLOT_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); - return dest->SharedParamSlotSSA(params, *this); + return dest->SharedParamSlotSSA(params, loc); default: throw LowLevelILInstructionAccessException(); } diff --git a/lowlevelilinstruction.h b/lowlevelilinstruction.h index 43c31adc7..4c3499b81 100644 --- a/lowlevelilinstruction.h +++ b/lowlevelilinstruction.h @@ -24,6 +24,7 @@ #include #include #ifdef BINARYNINJACORE_LIBRARY + #include "ilsourcelocation.h" #include "type.h" #else #include "binaryninjaapi.h" @@ -872,9 +873,10 @@ namespace BinaryNinja void VisitExprs(const std::function& func) const; - ExprId CopyTo(LowLevelILFunction* dest) const; + ExprId CopyTo(LowLevelILFunction* dest, const ILSourceLocation& sourceLocation = {}) const; ExprId CopyTo(LowLevelILFunction* dest, - const std::function& subExprHandler) const; + const std::function& subExprHandler, + const ILSourceLocation& sourceLocation = {}) const; // Templated accessors for instruction operands, use these for efficient access to a known instruction template diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp index 1894294b2..1cbabb5e8 100644 --- a/mediumlevelilinstruction.cpp +++ b/mediumlevelilinstruction.cpp @@ -1578,145 +1578,149 @@ void MediumLevelILInstruction::VisitExprs(const std::function& subExprHandler) const + const std::function& subExprHandler, + const ILSourceLocation& sourceLocation) const { vector params; BNMediumLevelILLabel* labelA; BNMediumLevelILLabel* labelB; + + const auto& loc = sourceLocation.valid ? sourceLocation : ILSourceLocation{*this}; + switch (operation) { case MLIL_NOP: - return dest->Nop(*this); + return dest->Nop(loc); case MLIL_SET_VAR: return dest->SetVar( - size, GetDestVariable(), subExprHandler(GetSourceExpr()), *this); + size, GetDestVariable(), subExprHandler(GetSourceExpr()), loc); case MLIL_SET_VAR_SSA: return dest->SetVarSSA( - size, GetDestSSAVariable(), subExprHandler(GetSourceExpr()), *this); + size, GetDestSSAVariable(), subExprHandler(GetSourceExpr()), loc); case MLIL_SET_VAR_ALIASED: return dest->SetVarAliased(size, GetDestSSAVariable().var, GetDestSSAVariable().version, GetSourceSSAVariable().version, - subExprHandler(GetSourceExpr()), *this); + subExprHandler(GetSourceExpr()), loc); case MLIL_SET_VAR_SPLIT: return dest->SetVarSplit(size, GetHighVariable(), GetLowVariable(), - subExprHandler(GetSourceExpr()), *this); + subExprHandler(GetSourceExpr()), loc); case MLIL_SET_VAR_SPLIT_SSA: return dest->SetVarSSASplit(size, GetHighSSAVariable(), GetLowSSAVariable(), subExprHandler(GetSourceExpr()), - *this); + loc); case MLIL_SET_VAR_FIELD: return dest->SetVarField(size, GetDestVariable(), GetOffset(), - subExprHandler(GetSourceExpr()), *this); + subExprHandler(GetSourceExpr()), loc); case MLIL_SET_VAR_SSA_FIELD: return dest->SetVarSSAField(size, GetDestSSAVariable().var, GetDestSSAVariable().version, GetSourceSSAVariable().version, GetOffset(), - subExprHandler(GetSourceExpr()), *this); + subExprHandler(GetSourceExpr()), loc); case MLIL_SET_VAR_ALIASED_FIELD: return dest->SetVarAliasedField(size, GetDestSSAVariable().var, GetDestSSAVariable().version, GetSourceSSAVariable().version, GetOffset(), - subExprHandler(GetSourceExpr()), *this); + subExprHandler(GetSourceExpr()), loc); case MLIL_VAR: - return dest->Var(size, GetSourceVariable(), *this); + return dest->Var(size, GetSourceVariable(), loc); case MLIL_VAR_FIELD: - return dest->VarField(size, GetSourceVariable(), GetOffset(), *this); + return dest->VarField(size, GetSourceVariable(), GetOffset(), loc); case MLIL_VAR_SPLIT: - return dest->VarSplit(size, GetHighVariable(), GetLowVariable(), *this); + return dest->VarSplit(size, GetHighVariable(), GetLowVariable(), loc); case MLIL_VAR_SSA: - return dest->VarSSA(size, GetSourceSSAVariable(), *this); + return dest->VarSSA(size, GetSourceSSAVariable(), loc); case MLIL_VAR_SSA_FIELD: return dest->VarSSAField( - size, GetSourceSSAVariable(), GetOffset(), *this); + size, GetSourceSSAVariable(), GetOffset(), loc); case MLIL_VAR_ALIASED: return dest->VarAliased(size, GetSourceSSAVariable().var, - GetSourceSSAVariable().version, *this); + GetSourceSSAVariable().version, loc); case MLIL_VAR_ALIASED_FIELD: return dest->VarAliasedField(size, GetSourceSSAVariable().var, - GetSourceSSAVariable().version, GetOffset(), *this); + GetSourceSSAVariable().version, GetOffset(), loc); case MLIL_VAR_SPLIT_SSA: return dest->VarSplitSSA( - size, GetHighSSAVariable(), GetLowSSAVariable(), *this); + size, GetHighSSAVariable(), GetLowSSAVariable(), loc); case MLIL_FORCE_VER: - return dest->ForceVer(size, GetDestVariable(), GetSourceVariable(), *this); + return dest->ForceVer(size, GetDestVariable(), GetSourceVariable(), loc); case MLIL_FORCE_VER_SSA: - return dest->ForceVerSSA(size, GetDestSSAVariable(), GetSourceSSAVariable(), *this); + return dest->ForceVerSSA(size, GetDestSSAVariable(), GetSourceSSAVariable(), loc); case MLIL_ASSERT: - return dest->Assert(size, GetSourceVariable(), GetConstraint(), *this); + return dest->Assert(size, GetSourceVariable(), GetConstraint(), loc); case MLIL_ASSERT_SSA: - return dest->AssertSSA(size, GetSourceSSAVariable(), GetConstraint(), *this); + return dest->AssertSSA(size, GetSourceSSAVariable(), GetConstraint(), loc); case MLIL_ADDRESS_OF: - return dest->AddressOf(GetSourceVariable(), *this); + return dest->AddressOf(GetSourceVariable(), loc); case MLIL_ADDRESS_OF_FIELD: return dest->AddressOfField( - GetSourceVariable(), GetOffset(), *this); + GetSourceVariable(), GetOffset(), loc); case MLIL_CALL: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); - return dest->Call(GetOutputVariables(), subExprHandler(GetDestExpr()), params, *this); + return dest->Call(GetOutputVariables(), subExprHandler(GetDestExpr()), params, loc); case MLIL_CALL_UNTYPED: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->CallUntyped(GetOutputVariables(), subExprHandler(GetDestExpr()), params, - subExprHandler(GetStackExpr()), *this); + subExprHandler(GetStackExpr()), loc); case MLIL_CALL_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->CallSSA(GetOutputSSAVariables(), subExprHandler(GetDestExpr()), - params, GetDestMemoryVersion(), GetSourceMemoryVersion(), *this); + params, GetDestMemoryVersion(), GetSourceMemoryVersion(), loc); case MLIL_CALL_UNTYPED_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->CallUntypedSSA(GetOutputSSAVariables(), subExprHandler(GetDestExpr()), params, GetDestMemoryVersion(), GetSourceMemoryVersion(), - subExprHandler(GetStackExpr()), *this); + subExprHandler(GetStackExpr()), loc); case MLIL_SYSCALL: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); - return dest->Syscall(GetOutputVariables(), params, *this); + return dest->Syscall(GetOutputVariables(), params, loc); case MLIL_SYSCALL_UNTYPED: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->SyscallUntyped(GetOutputVariables(), - params, subExprHandler(GetStackExpr()), *this); + params, subExprHandler(GetStackExpr()), loc); case MLIL_SYSCALL_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->SyscallSSA(GetOutputSSAVariables(), params, - GetDestMemoryVersion(), GetSourceMemoryVersion(), *this); + GetDestMemoryVersion(), GetSourceMemoryVersion(), loc); case MLIL_SYSCALL_UNTYPED_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->SyscallUntypedSSA(GetOutputSSAVariables(), params, GetDestMemoryVersion(), GetSourceMemoryVersion(), - subExprHandler(GetStackExpr()), *this); + subExprHandler(GetStackExpr()), loc); case MLIL_TAILCALL: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->TailCall( - GetOutputVariables(), subExprHandler(GetDestExpr()), params, *this); + GetOutputVariables(), subExprHandler(GetDestExpr()), params, loc); case MLIL_TAILCALL_UNTYPED: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->TailCallUntyped(GetOutputVariables(), subExprHandler(GetDestExpr()), params, - subExprHandler(GetStackExpr()), *this); + subExprHandler(GetStackExpr()), loc); case MLIL_TAILCALL_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->TailCallSSA(GetOutputSSAVariables(), subExprHandler(GetDestExpr()), params, GetDestMemoryVersion(), - GetSourceMemoryVersion(), *this); + GetSourceMemoryVersion(), loc); case MLIL_TAILCALL_UNTYPED_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); @@ -1724,47 +1728,47 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, subExprHandler(GetDestExpr()), params, GetDestMemoryVersion(), GetSourceMemoryVersion(), - subExprHandler(GetStackExpr()), *this); + subExprHandler(GetStackExpr()), loc); case MLIL_SEPARATE_PARAM_LIST: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); - return dest->SeparateParamList(params, *this); + return dest->SeparateParamList(params, loc); case MLIL_SHARED_PARAM_SLOT: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); - return dest->SharedParamSlot(params, *this); + return dest->SharedParamSlot(params, loc); case MLIL_RET: for (auto i : GetSourceExprs()) params.push_back(subExprHandler(i)); - return dest->Return(params, *this); + return dest->Return(params, loc); case MLIL_NORET: - return dest->NoReturn(*this); + return dest->NoReturn(loc); case MLIL_STORE: return dest->Store( - size, subExprHandler(GetDestExpr()), subExprHandler(GetSourceExpr()), *this); + size, subExprHandler(GetDestExpr()), subExprHandler(GetSourceExpr()), loc); case MLIL_STORE_STRUCT: return dest->StoreStruct(size, subExprHandler(GetDestExpr()), GetOffset(), - subExprHandler(GetSourceExpr()), *this); + subExprHandler(GetSourceExpr()), loc); case MLIL_STORE_SSA: return dest->StoreSSA(size, subExprHandler(GetDestExpr()), GetDestMemoryVersion(), GetSourceMemoryVersion(), - subExprHandler(GetSourceExpr()), *this); + subExprHandler(GetSourceExpr()), loc); case MLIL_STORE_STRUCT_SSA: return dest->StoreStructSSA(size, subExprHandler(GetDestExpr()), GetOffset(), GetDestMemoryVersion(), GetSourceMemoryVersion(), subExprHandler(GetSourceExpr()), - *this); + loc); case MLIL_LOAD: - return dest->Load(size, subExprHandler(GetSourceExpr()), *this); + return dest->Load(size, subExprHandler(GetSourceExpr()), loc); case MLIL_LOAD_STRUCT: return dest->LoadStruct( - size, subExprHandler(GetSourceExpr()), GetOffset(), *this); + size, subExprHandler(GetSourceExpr()), GetOffset(), loc); case MLIL_LOAD_SSA: return dest->LoadSSA( - size, subExprHandler(GetSourceExpr()), GetSourceMemoryVersion(), *this); + size, subExprHandler(GetSourceExpr()), GetSourceMemoryVersion(), loc); case MLIL_LOAD_STRUCT_SSA: return dest->LoadStructSSA(size, subExprHandler(GetSourceExpr()), - GetOffset(), GetSourceMemoryVersion(), *this); + GetOffset(), GetSourceMemoryVersion(), loc); case MLIL_NEG: case MLIL_NOT: case MLIL_SX: @@ -1784,7 +1788,7 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, case MLIL_FLOOR: case MLIL_CEIL: case MLIL_FTRUNC: - return dest->AddExprWithLocation(operation, *this, size, subExprHandler(AsOneOperand().GetSourceExpr())); + return dest->AddExprWithLocation(operation, loc, size, subExprHandler(AsOneOperand().GetSourceExpr())); case MLIL_ADD: case MLIL_SUB: case MLIL_AND: @@ -1830,13 +1834,13 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, case MLIL_FCMP_GT: case MLIL_FCMP_O: case MLIL_FCMP_UO: - return dest->AddExprWithLocation(operation, *this, size, subExprHandler(AsTwoOperand().GetLeftExpr()), + return dest->AddExprWithLocation(operation, loc, size, subExprHandler(AsTwoOperand().GetLeftExpr()), subExprHandler(AsTwoOperand().GetRightExpr())); case MLIL_ADC: case MLIL_SBB: case MLIL_RLC: case MLIL_RRC: - return dest->AddExprWithLocation(operation, *this, size, subExprHandler(AsTwoOperandWithCarry().GetLeftExpr()), + return dest->AddExprWithLocation(operation, loc, size, subExprHandler(AsTwoOperandWithCarry().GetLeftExpr()), subExprHandler(AsTwoOperandWithCarry().GetRightExpr()), subExprHandler(AsTwoOperandWithCarry().GetCarryExpr())); case MLIL_JUMP_TO: @@ -1846,10 +1850,10 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, { labelA = dest->GetLabelForSourceInstruction(target.second); if (!labelA) - return dest->Jump(subExprHandler(GetDestExpr()), *this); + return dest->Jump(subExprHandler(GetDestExpr()), loc); labelList[target.first] = labelA; } - return dest->JumpTo(subExprHandler(GetDestExpr()), labelList, *this); + return dest->JumpTo(subExprHandler(GetDestExpr()), labelList, loc); } case MLIL_GOTO: labelA = dest->GetLabelForSourceInstruction(GetTarget()); @@ -1857,56 +1861,56 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, { return dest->Jump(dest->ConstPointer(function->GetArchitecture()->GetAddressSize(), function->GetInstruction(GetTarget()).address), - *this); + loc); } - return dest->Goto(*labelA, *this); + return dest->Goto(*labelA, loc); case MLIL_IF: labelA = dest->GetLabelForSourceInstruction(GetTrueTarget()); labelB = dest->GetLabelForSourceInstruction(GetFalseTarget()); if ((!labelA) || (!labelB)) - return dest->Undefined(*this); - return dest->If(subExprHandler(GetConditionExpr()), *labelA, *labelB, *this); + return dest->Undefined(loc); + return dest->If(subExprHandler(GetConditionExpr()), *labelA, *labelB, loc); case MLIL_CONST: - return dest->Const(size, GetConstant(), *this); + return dest->Const(size, GetConstant(), loc); case MLIL_CONST_PTR: - return dest->ConstPointer(size, GetConstant(), *this); + return dest->ConstPointer(size, GetConstant(), loc); case MLIL_EXTERN_PTR: - return dest->ExternPointer(size, GetConstant(), GetOffset(), *this); + return dest->ExternPointer(size, GetConstant(), GetOffset(), loc); case MLIL_FLOAT_CONST: - return dest->FloatConstRaw(size, GetConstant(), *this); + return dest->FloatConstRaw(size, GetConstant(), loc); case MLIL_IMPORT: - return dest->ImportedAddress(size, GetConstant(), *this); + return dest->ImportedAddress(size, GetConstant(), loc); case MLIL_CONST_DATA: - return dest->ConstData(size, GetConstantData(), *this); + return dest->ConstData(size, GetConstantData(), loc); case MLIL_BP: - return dest->Breakpoint(*this); + return dest->Breakpoint(loc); case MLIL_TRAP: - return dest->Trap(GetVector(), *this); + return dest->Trap(GetVector(), loc); case MLIL_INTRINSIC: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); - return dest->Intrinsic(GetOutputVariables(), GetIntrinsic(), params, *this); + return dest->Intrinsic(GetOutputVariables(), GetIntrinsic(), params, loc); case MLIL_INTRINSIC_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->IntrinsicSSA( - GetOutputSSAVariables(), GetIntrinsic(), params, *this); + GetOutputSSAVariables(), GetIntrinsic(), params, loc); case MLIL_MEMORY_INTRINSIC_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->MemoryIntrinsicSSA(GetOutputSSAVariables(), GetIntrinsic(), params, GetDestMemoryVersion(), - GetSourceMemoryVersion(), *this); + GetSourceMemoryVersion(), loc); case MLIL_FREE_VAR_SLOT: - return dest->FreeVarSlot(GetDestVariable(), *this); + return dest->FreeVarSlot(GetDestVariable(), loc); case MLIL_FREE_VAR_SLOT_SSA: return dest->FreeVarSlotSSA(GetDestSSAVariable().var, GetDestSSAVariable().version, - GetSourceSSAVariable().version, *this); + GetSourceSSAVariable().version, loc); case MLIL_UNDEF: - return dest->Undefined(*this); + return dest->Undefined(loc); case MLIL_UNIMPL: - return dest->Unimplemented(*this); + return dest->Unimplemented(loc); default: throw MediumLevelILInstructionAccessException(); } diff --git a/mediumlevelilinstruction.h b/mediumlevelilinstruction.h index 077ced5ba..ef1f90170 100644 --- a/mediumlevelilinstruction.h +++ b/mediumlevelilinstruction.h @@ -26,6 +26,7 @@ #ifdef BINARYNINJACORE_LIBRARY #include "constantdata.h" #include "variable.h" + #include "ilsourcelocation.h" #else #include "binaryninjaapi.h" #endif @@ -620,9 +621,10 @@ namespace BinaryNinja void VisitExprs(const std::function& func) const; - ExprId CopyTo(MediumLevelILFunction* dest) const; + ExprId CopyTo(MediumLevelILFunction* dest, const ILSourceLocation& sourceLocation = {}) const; ExprId CopyTo(MediumLevelILFunction* dest, - const std::function& subExprHandler) const; + const std::function& subExprHandler, + const ILSourceLocation& sourceLocation = {}) const; // Templated accessors for instruction operands, use these for efficient access to a known instruction template