能力值:
( LV2,RANK:10 )
|
-
-
2 楼
ARM汇编网上资料还真不少: https://blog.csdn.net/lwanttowin/article/details/78385440
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
以下代码支持arm64,arm32以及thumb16指令 #if defined(__aarch64__)
static inline __always_inline int64_t calcuate_branch_aim(uint32_t *inpp, int offset) {
static constexpr uint32_t mbits = 6u;
static constexpr uint32_t mask = 0xfc000000u; // 0b11111100000000000000000000000000
static constexpr uint32_t op_b = 0x14000000u; // "b" ADDR_PCREL26
static constexpr uint32_t op_bl = 0x94000000u; // "bl" ADDR_PCREL26
const uint32_t ins = *(uint32_t *) ((uintptr_t) inpp + offset);
const uint32_t opc = ins & mask;
switch (opc) {
case op_b:
case op_bl:
return (int64_t) ((uintptr_t) inpp + offset) +
(static_cast<int32_t>(ins << mbits) >> (mbits - 2u)); // sign-extended
default:
return 0;
}
}
#endif
inline __always_inline void *getBTarget(void *symbol, int offset) {
#if defined(__aarch64__)
return (void *) calcuate_branch_aim((uint32_t *) symbol, offset);
#elif defined(__arm__)
if ((reinterpret_cast<uintptr_t>(symbol) & 0x1) == 0)
return (char *) ((uintptr_t) symbol + offset) +
(((*(int32_t *) ((uintptr_t) symbol + offset)) << 8) >> 6) + 8;
else {
offset--;
return (char *) ((uintptr_t) symbol + offset) +
(((*(int16_t *) ((uintptr_t) symbol + offset)) << 8) >> 8) + 5;
}
#else
assert(false);
return 0;
#endif
}
inline __always_inline void *getBLTarget(void *symbol, int offset) {
#if defined(__aarch64__)
return (void *) calcuate_branch_aim((uint32_t *) symbol, offset);
#elif defined(__arm__)
if ((reinterpret_cast<uintptr_t>(symbol) & 0x1) == 0)
return (char *) ((uintptr_t) symbol + offset) +
(((*(int32_t *) ((uintptr_t) symbol + offset)) << 8) >> 6) + 8;
else {
offset--;
int32_t opCode = (*(int32_t *) ((uintptr_t) symbol + offset));
int32_t high = (opCode & 0x7ff); //7ff
int32_t low = ((opCode >> 16) & 0x7ff); //7f5
return (char *) ((uintptr_t) symbol + offset) +
((((high << 12) | (low << 1)) << 9) >> 9) + 5;
}
#else
assert(false);
return 0;
#endif
}
最后于 2021-6-7 20:38
被不吃早饭编辑
,原因:
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
挺久前写的了,应该可用
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
调用时symbol表示这条指令所在的函数地址,offset表示该指令在函数内的偏移
|
能力值:
( LV3,RANK:30 )
|
-
-
6 楼
int main()
{
while(1){
int a = 0;
}
} loc_83D0
.text:000083D0 00 00 00 E3 MOV R0, #0
.text:000083D4 00 00 8D E5 STR R0, [SP,#8+var_8]
.text:000083D8 FC FF FF EA B loc_83D0 .text:000083D8 B 0x000083D0 (0x000083D0 - 0x000083D8 -0x8) >> 2 ==> FFFFFFFC
取后24位FFFFFC
与EA拼接得到 EAFFFFFC
最后于 2021-6-8 10:37
被lanoche编辑
,原因:
|
|
|