转:http://bbs.pediy.com/showthread.php?p=1383668&posted=1#post1383668
向后跳转
0012 00F001F8 bl .Lhelo
.Lhelo:
0018 05F0D1F7 pld [r1, r5]
计算方式:
取高位 f000, 取后11位 => 000
取低位 f801, 取后11位 => 001
计算: (000 << 12) | (001 << 1) = 2
由于这个
最高位符号位为0. 代表向后跳转, 只需要保留该值2即可
然后计算得到的目标地址为 : 0x0012 + 4 + 2 = 0x0018
向前跳转
00001164 FF F7 BE FF BL _Z4testv
_Z4testv
000010E4 07 B5 PUSH {R0-R2,LR}
计算方式:
取高位 f7ff, 取后11位 => 7ff
取低位 ffbe, 取后11位 => 7be
计算: (7ff << 12) | (7be << 1) = 7fff7c
由于这个
最高位符号位为1 代表向前跳转, 需要-1然后取反 得到值为 ff800084。取84即可
然后计算得到的目标地址为 : 0x1164 + 4 - 0x84 = 0x10e4
逆向过程:
BL <label>
由BL指令得到机器码算法:
offset = dstAddr - srcAddr;
offset = (offset -4) & 0x007fffff;
high = offset >> 12;
low = (offset & 0x00000fff) >> 1;
machineCode = ((0x
FF00 | low) << 16) | (0xF000 | high);
BLX <label>
与BL类似,只不过计算机器码算法稍有不同
offset = dstAddr - srcAddr;
offset = (offset -4) & 0x007fffff;
high = offset >> 12;
low = (offset & 0x00000fff) >> 1;
if(low%2 != 0) {
low++;
}
machineCode = ((0x
EF00 | low) << 16) | (0xF000 | high);