diff options
Diffstat (limited to 'lowlevelil.cpp')
| -rw-r--r-- | lowlevelil.cpp | 93 |
1 files changed, 87 insertions, 6 deletions
diff --git a/lowlevelil.cpp b/lowlevelil.cpp index a006a581..d86bb523 100644 --- a/lowlevelil.cpp +++ b/lowlevelil.cpp @@ -30,9 +30,9 @@ LowLevelILLabel::LowLevelILLabel() } -LowLevelILFunction::LowLevelILFunction() +LowLevelILFunction::LowLevelILFunction(Architecture* arch) { - m_object = BNCreateLowLevelILFunction(); + m_object = BNCreateLowLevelILFunction(arch->GetObject()); } @@ -54,6 +54,25 @@ void LowLevelILFunction::SetCurrentAddress(uint64_t addr) } +void LowLevelILFunction::ClearIndirectBranches() +{ + BNLowLevelILClearIndirectBranches(m_object); +} + + +void LowLevelILFunction::SetIndirectBranches(const vector<ArchAndAddr>& branches) +{ + BNArchitectureAndAddress* branchList = new BNArchitectureAndAddress[branches.size()]; + for (size_t i = 0; i < branches.size(); i++) + { + branchList[i].arch = branches[i].arch->GetObject(); + branchList[i].address = branches[i].address; + } + BNLowLevelILSetIndirectBranches(m_object, branchList, branches.size()); + delete[] branchList; +} + + ExprId LowLevelILFunction::AddExpr(BNLowLevelILOperation operation, size_t size, uint32_t flags, ExprId a, ExprId b, ExprId c, ExprId d) { @@ -463,6 +482,40 @@ void LowLevelILFunction::MarkLabel(BNLowLevelILLabel& label) } +vector<uint64_t> LowLevelILFunction::GetOperandList(ExprId expr, size_t listOperand) +{ + size_t count; + uint64_t* operands = BNLowLevelILGetOperandList(m_object, expr, listOperand, &count); + vector<uint64_t> result; + for (size_t i = 0; i < count; i++) + result.push_back(operands[i]); + BNLowLevelILFreeOperandList(operands); + return result; +} + + +ExprId LowLevelILFunction::AddLabelList(const vector<BNLowLevelILLabel*>& labels) +{ + BNLowLevelILLabel** labelList = new BNLowLevelILLabel*[labels.size()]; + for (size_t i = 0; i < labels.size(); i++) + labelList[i] = labels[i]; + ExprId result = (ExprId)BNLowLevelILAddLabelList(m_object, labelList, labels.size()); + delete[] labelList; + return result; +} + + +ExprId LowLevelILFunction::AddOperandList(const vector<ExprId> operands) +{ + uint64_t* operandList = new uint64_t[operands.size()]; + for (size_t i = 0; i < operands.size(); i++) + operandList[i] = operands[i]; + ExprId result = (ExprId)BNLowLevelILAddOperandList(m_object, operandList, operands.size()); + delete[] operandList; + return result; +} + + ExprId LowLevelILFunction::Operand(uint32_t n, ExprId expr) { BNLowLevelILSetExprSourceOperand(m_object, expr, n); @@ -500,9 +553,9 @@ BNLowLevelILLabel* LowLevelILFunction::GetLabelForAddress(Architecture* arch, Ex } -void LowLevelILFunction::Finalize() +void LowLevelILFunction::Finalize(Function* func) { - BNFinalizeLowLevelILFunction(m_object); + BNFinalizeLowLevelILFunction(m_object, func ? func->GetObject() : nullptr); } @@ -528,11 +581,13 @@ bool LowLevelILFunction::GetExprText(Architecture* arch, ExprId expr, vector<Ins } -bool LowLevelILFunction::GetInstructionText(Architecture* arch, size_t instr, vector<InstructionTextToken>& tokens) +bool LowLevelILFunction::GetInstructionText(Function* func, Architecture* arch, size_t instr, + vector<InstructionTextToken>& tokens) { size_t count; BNInstructionTextToken* list; - if (!BNGetLowLevelILInstructionText(m_object, arch->GetObject(), instr, &list, &count)) + if (!BNGetLowLevelILInstructionText(m_object, func ? func->GetObject() : nullptr, arch->GetObject(), + instr, &list, &count)) return false; tokens.clear(); @@ -548,3 +603,29 @@ bool LowLevelILFunction::GetInstructionText(Architecture* arch, size_t instr, ve BNFreeInstructionText(list, count); return true; } + + +uint32_t LowLevelILFunction::GetTemporaryRegisterCount() +{ + return BNGetLowLevelILTemporaryRegisterCount(m_object); +} + + +uint32_t LowLevelILFunction::GetTemporaryFlagCount() +{ + return BNGetLowLevelILTemporaryFlagCount(m_object); +} + + +vector<Ref<BasicBlock>> LowLevelILFunction::GetBasicBlocks() const +{ + size_t count; + BNBasicBlock** blocks = BNGetLowLevelILBasicBlockList(m_object, &count); + + vector<Ref<BasicBlock>> result; + for (size_t i = 0; i < count; i++) + result.push_back(new BasicBlock(BNNewBasicBlockReference(blocks[i]))); + + BNFreeBasicBlockList(blocks, count); + return result; +} |
