From ef4b3692e354b422f575f3432a301801715d9852 Mon Sep 17 00:00:00 2001 From: hellcatz Date: Sat, 13 Jul 2024 22:32:52 +0800 Subject: [PATCH 1/2] rename handle_bnj_arm to predict, add arg `pref_addr` to funciton predict for handling address preference --- .../qdb/branch_predictor/branch_predictor_arm.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/qiling/debugger/qdb/branch_predictor/branch_predictor_arm.py b/qiling/debugger/qdb/branch_predictor/branch_predictor_arm.py index 97f00964c..1e6a83160 100644 --- a/qiling/debugger/qdb/branch_predictor/branch_predictor_arm.py +++ b/qiling/debugger/qdb/branch_predictor/branch_predictor_arm.py @@ -3,11 +3,14 @@ # Cross Platform and Multi Architecture Advanced Binary Emulation Framework # +from __future__ import annotations +from typing import Optional - -from .branch_predictor import * +from .branch_predictor import BranchPredictor from ..arch import ArchARM, ArchCORTEX_M + + class BranchPredictorARM(BranchPredictor, ArchARM): """ predictor for ARM @@ -40,9 +43,9 @@ def get_cpsr(bits: int) -> (bool, bool, bool, bool): bits & 0x80000000 != 0, # N, sign flag ) - def predict(self): + def predict(self, pref_addr: Optional[int] = None) -> BranchPredictor.Prophecy: prophecy = self.Prophecy() - cur_addr = self.cur_addr + cur_addr = pref_addr or self.cur_addr line = self.disasm(cur_addr) prophecy.where = cur_addr + line.size @@ -160,7 +163,7 @@ def predict(self): next_addr = cur_addr + self.THUMB_INST_SIZE for each in it_block_range: _insn = self.read_insn(next_addr) - n2_addr = handle_bnj_arm(ql, next_addr) + n2_addr = self.predict(next_addr).where if (cond_met and each == "t") or (not cond_met and each == "e"): if n2_addr != (next_addr+len(_insn)): # branch detected From 4361ed7b7a1e2be14d5e1e5a8df3cbd8c73612f2 Mon Sep 17 00:00:00 2001 From: hellcatz Date: Sun, 14 Jul 2024 01:17:41 +0800 Subject: [PATCH 2/2] fix missing function --- qiling/debugger/qdb/branch_predictor/branch_predictor_arm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiling/debugger/qdb/branch_predictor/branch_predictor_arm.py b/qiling/debugger/qdb/branch_predictor/branch_predictor_arm.py index 1e6a83160..9c89532d9 100644 --- a/qiling/debugger/qdb/branch_predictor/branch_predictor_arm.py +++ b/qiling/debugger/qdb/branch_predictor/branch_predictor_arm.py @@ -6,7 +6,7 @@ from __future__ import annotations from typing import Optional -from .branch_predictor import BranchPredictor +from .branch_predictor import * from ..arch import ArchARM, ArchCORTEX_M