这段代码没有对ida分析起到作用,是否还有其他强大的代码可用?#include <idc.idc>
void main()
{
auto start_ea = SegStart(SegByName(".text"));
auto end_ea = SegEnd(SegByName(".text"));
for (auto ea = start_ea; ea < end_ea; ea++)
{
if (GetMnem(ea) == "B" || GetMnem(ea) == "BL")
{
// B and BL instructions represent unconditional and conditional branches in ARM64
auto insn = GetInsn(ea, 0);
if (insn.size > 0)
{
auto opnd_type = GetOpType(insn, 0);
if (opnd_type == o_imm)
{
// The immediate operand holds the branch offset
auto offset = GetOperandValue(insn, 0);
// Sign-extend the 26-bit immediate to 64 bits
if (offset & (1 << 25))
offset |= ~((1 << 26) - 1); // Set all higher bits to 1
auto target_ea = ea + 4 + offset;
// Check if the target address falls within the code segment
if (SegStart(SegByName(".text")) <= target_ea && target_ea < SegEnd(SegByName(".text")))
{
// Make sure the target is marked as code
if (IsCode(GetFlags(target_ea)))
{
MakeCode(target_ea);
MakeFunction(target_ea);
// Create a branch to the target
if (GetMnem(ea) == "BL")
MakeCode(ea, ICODE_CALL); // For BL (branch with link)
else
MakeCode(ea, ICODE_JUMP); // For B (unconditional branch)
AddCodeXref(ea, target_ea, fl_CN); // Create a code cross-reference
}
}
}
}
}
}
}