1

Is it possible to patch arm lib in a way that changes branch instruction calling one function to another function call?

I have instruction

B function_a

and want change it to:

B function_b 
1

See this answer for details on how branch instructions are encoded on ARM. Here's what you should do:

  1. Set Options->General->Number of opcode bytes to 4 (if it was 0 initially)
  2. Find any B instruction.
  3. Just to make sure you understand it, work out the displacement from pc+8 at the B instruction to the destination, and verify that the displacement in the instruction matches what you expect.
  4. Calculate the displacement to the target to which you wish to branch instead.
  5. Use Edit->Patch program->Change byte to modify the current instruction. IDA will update the display, so you can tell whether you've succeeded or not. If you haven't, keep messing with it until you get the bytes you want.
  6. To generate a patch file, you can use File->Produce file->Create .DIF file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.