Skip to content

Invalid branch offset #19

Description

@rva3

On the ARMv7 in the Thumb mode, unconditional BranchThumbOffset uses relative offset to the current instruction, however the conditional branches do +1 for some reason:

yaxpeax-arm/src/armv7/thumb.rs

Lines 4182 to 4186 in 5803a74

inst.opcode = Opcode::B;
let imm = instr2[0..8].load::<u8>() as i8 as i32;
inst.condition = ConditionCode::build(opcode);
inst.operands = [
Operand::BranchThumbOffset(imm + 1),

Is there a reason for this? The workaround is simple

let fixup = if code.instruction.condition == ConditionCode::AL {
    4
} else {
    2
};
let pc = code.offset + fixup;

but I don't think it matches the ARM spec (where the PC + 4 is a general rule for the PC-relative stuff).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions