Fix bx after add lr, pc, 0 in arm32 (#3326)

Co-authored-by: pancake <pancake@nopcode.org>
This commit is contained in:
Giovanni 2023-01-28 15:10:14 +08:00 committed by GitHub
parent b740cba35d
commit 21333133d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View file

@ -656,6 +656,7 @@ static RzAnalysisBBEndCause run_basic_block_analysis(RzAnalysisTaskItem *item, R
bool last_is_reg_mov_lea = false;
bool last_is_push = false;
bool last_is_mov_lr_pc = false;
bool last_is_add_lr_pc = false;
ut64 last_push_addr = UT64_MAX;
if (analysis->limit && addr + idx < analysis->limit->from) {
gotoBeach(RZ_ANALYSIS_RET_END);
@ -1010,6 +1011,13 @@ static RzAnalysisBBEndCause run_basic_block_analysis(RzAnalysisTaskItem *item, R
break;
// Case of valid but unused "add [rax], al"
case RZ_ANALYSIS_OP_TYPE_ADD:
if (is_arm && analysis->bits == 32) {
if (!memcmp(buf, "\x00\xe0\x8f\xe2", 4)) {
// TODO: support different values, not just 0
// add lr, pc, 0 //
last_is_add_lr_pc = true;
}
}
if (analysis->opt.ijmp) {
if ((op.size + 4 <= bytes_read) && !memcmp(buf + op.size, "\x00\x00\x00\x00", 4)) {
rz_analysis_block_set_size(bb, bb->size - oplen);
@ -1252,8 +1260,11 @@ static RzAnalysisBBEndCause run_basic_block_analysis(RzAnalysisTaskItem *item, R
// Ignore
break;
}
}
if (is_arm && last_is_mov_lr_pc) {
} else if (is_arm && analysis->bits == 32 && last_is_mov_lr_pc) {
break;
} else if (is_arm && analysis->bits == 32 && last_is_add_lr_pc) {
op.type = RZ_ANALYSIS_OP_TYPE_CALL;
op.fail = op.addr + 4;
break;
}
/* fall through */

View file

@ -1151,3 +1151,23 @@ mnemonic: adds
mnemonic: mov
EOF
RUN
NAME=arm32 function is NOT cut off when setting lr with add before bx
FILE==
CMDS=<<EOF
e asm.arch=arm
e asm.bits=32
wx 10402de90040a0e100e08fe214ff2fe11080bde8
af
pdf
EOF
EXPECT=<<EOF
/ fcn.00000000 (int32_t arg1);
| ; arg int32_t arg1 @ r0
| 0x00000000 push {r4, lr}
| 0x00000004 mov r4, r0 ; arg1
| 0x00000008 add lr, pc, 0
| 0x0000000c bx r4
\ 0x00000010 pop {r4, pc}
EOF
RUN