Skip to content

Commit

Permalink
rename handle_bnj_arm to predict, add arg pref_addr to funciton pre…
Browse files Browse the repository at this point in the history
…dict for handling address preference
  • Loading branch information
ucgJhe committed Jul 13, 2024
1 parent 04e42e0 commit ef4b369
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions qiling/debugger/qdb/branch_predictor/branch_predictor_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ef4b369

Please sign in to comment.