diff options
| -rw-r--r-- | ui/util.h | 83 |
1 files changed, 71 insertions, 12 deletions
@@ -56,42 +56,101 @@ std::optional<T> visitILInstructionForToken(View* view, const HighlightTokenStat case LowLevelILSSAFormFunctionGraph: { LowLevelILFunctionRef llilFunc = view->getCurrentLowLevelILFunction(); + if (llilFunc && type == LowLevelILSSAFormFunctionGraph) llilFunc = llilFunc->GetSSAForm(); - if (llilFunc) + + if (!llilFunc) + break; + + if (token.token.exprIndex >= llilFunc->GetExprCount()) { - BinaryNinja::LowLevelILInstruction instr = llilFunc->GetExpr(token.token.exprIndex); - return llil(instr); + FunctionRef func = llilFunc->GetFunction(); + uint64_t start = func ? func->GetStart() : 0; + + BinaryNinja::LogErrorF("Invalid LowLevelIL token exprIndex {} in {} of {:x}", token.token.exprIndex, type, start); + break; } - break; + BinaryNinja::LowLevelILInstruction instr = llilFunc->GetExpr(token.token.exprIndex); + + if (instr.instructionIndex >= llilFunc->GetInstructionCount()) + { + FunctionRef func = llilFunc->GetFunction(); + uint64_t start = func ? func->GetStart() : 0; + + BinaryNinja::LogErrorF("Invalid LowLevelIL token exprIndex {} in {} of {:x} (reported instrIndex {})", token.token.exprIndex, type, start, instr.instructionIndex); + break; + } + + return llil(instr); } case MediumLevelILFunctionGraph: case MediumLevelILSSAFormFunctionGraph: { MediumLevelILFunctionRef mlilFunc = view->getCurrentMediumLevelILFunction(); + if (mlilFunc && type == MediumLevelILSSAFormFunctionGraph) mlilFunc = mlilFunc->GetSSAForm(); - if (mlilFunc) + + if (!mlilFunc) + break; + + if (token.token.exprIndex >= mlilFunc->GetExprCount()) { - BinaryNinja::MediumLevelILInstruction instr = mlilFunc->GetExpr(token.token.exprIndex); - return mlil(instr); + FunctionRef func = mlilFunc->GetFunction(); + uint64_t start = func ? func->GetStart() : 0; + + BinaryNinja::LogErrorF("Invalid MediumLevelIL token exprIndex {} in {} of {:x}", token.token.exprIndex, type, start); + break; } - break; + + BinaryNinja::MediumLevelILInstruction instr = mlilFunc->GetExpr(token.token.exprIndex); + + if (instr.instructionIndex >= mlilFunc->GetInstructionCount()) + { + FunctionRef func = mlilFunc->GetFunction(); + uint64_t start = func ? func->GetStart() : 0; + + BinaryNinja::LogErrorF("Invalid MediumLevelIL token exprIndex {} in {} of {:x} (reported instrIndex {})", token.token.exprIndex, type, start, instr.instructionIndex); + break; + } + + return mlil(instr); } case HighLevelILFunctionGraph: case HighLevelILSSAFormFunctionGraph: case HighLevelLanguageRepresentationFunctionGraph: { HighLevelILFunctionRef hlilFunc = view->getCurrentHighLevelILFunction(); + if (hlilFunc && type == HighLevelILSSAFormFunctionGraph) hlilFunc = hlilFunc->GetSSAForm(); - if (hlilFunc) + + if (!hlilFunc) + break; + + if (token.token.exprIndex >= hlilFunc->GetExprCount()) { - BinaryNinja::HighLevelILInstruction instr = hlilFunc->GetExpr(token.token.exprIndex); - return hlil(instr); + FunctionRef func = hlilFunc->GetFunction(); + uint64_t start = func ? func->GetStart() : 0; + + BinaryNinja::LogErrorF("Invalid HighLevelIL token exprIndex {} in {} of {:x}", token.token.exprIndex, type, start); + break; } - break; + + BinaryNinja::HighLevelILInstruction instr = hlilFunc->GetExpr(token.token.exprIndex); + + if (instr.instructionIndex >= hlilFunc->GetInstructionCount()) + { + FunctionRef func = hlilFunc->GetFunction(); + uint64_t start = func ? func->GetStart() : 0; + + BinaryNinja::LogErrorF("Invalid HighLevelIL token exprIndex {} in {} of {:x} (reported instrIndex {})", token.token.exprIndex, type, start, instr.instructionIndex); + break; + } + + return hlil(instr); } default: break; |
