From bf02a342b3122e46a91d0c5da57449c3d4a01999 Mon Sep 17 00:00:00 2001 From: Ryan Snyder Date: Tue, 24 Jun 2025 16:53:21 -0400 Subject: ui: resolve some more invalid instr cases --- ui/util.h | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 12 deletions(-) diff --git a/ui/util.h b/ui/util.h index 5f86014b..9b5a907d 100644 --- a/ui/util.h +++ b/ui/util.h @@ -56,42 +56,101 @@ std::optional 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; -- cgit v1.3.1