diff options
| author | Ryan Snyder <ryan@vector35.com> | 2025-06-24 16:53:21 -0400 |
|---|---|---|
| committer | Ryan Snyder <ryan@vector35.com> | 2025-07-01 20:22:24 -0400 |
| commit | bf02a342b3122e46a91d0c5da57449c3d4a01999 (patch) | |
| tree | 88003490e643e440c196ce2e48b9dfcef8bd366b | |
| parent | 0b2b24e4cfc6258dbc03a9675fda3f484b6f5c9a (diff) | |
ui: resolve some more invalid instr cases
| -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; |
