Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qdb bug fix missing function handle_bnj_arm #1483

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 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 ..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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that the or operator will pick the latter not only when the former is None, but also when it is 0. If 0 is a valid value for pref_addr, then consider using:

cur_addr = self.cur_addr if pref_addr is None else pref_addr

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for the hint, i will correct this in the following fix for the issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ucgJhe please update the code ?

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
Loading