Skip to content

Qdb error when using QlLoaderBlob #1568

@antcpl

Description

@antcpl

Describe the bug
When trying to use Qdb with a baremetal binary emulation that uses QlLoaderBlob, an AttributeError raises.

Sample Code
I am working on the dev branch.
My setup is the following one :
I emulate a bare metal binary running on ARM cortex A7 processor. For the global emulation setup I followed this qiling/examples/hello_arm_uboot.py and defined a cortex_a.ql file to setup the memory as required by the blob loader.

with open("./baremetal_binary", "rb") as f:
        binary = f.read()

ql = Qiling(code=binary[0x00000000:],archtype=QL_ARCH.ARM, ostype=QL_OS.BLOB , verbose=QL_VERBOSE.DISABLED, cputype=ARM_CPU_MODEL.ARM_CORTEX_A7, profile="cortex_a.ql")

[...]

ql.debugger= "qdb"
ql.run()

Expected behavior
No error.

Screenshots

Traceback (most recent call last):
  File "/test_qilin/qiling/examples/mcu/fuzzing_test/cortex_A7/code_coverage/dev/general_script.py", line 60, in <module>
    ql.run()
  File "/test_qilin/qilingenv/lib/python3.12/site-packages/qiling/core.py", line 585, in run
    debugger = debugger(self)
               ^^^^^^^^^^^^^^
  File "/test_qilin/qilingenv/lib/python3.12/site-packages/qiling/debugger/qdb/qdb.py", line 73, in __init__
    self.dbg_hook(list(filter(lambda d: int(d, 0) != self.ql.loader.entry_point, init_hook)))
  File "/test_qilin/qilingenv/lib/python3.12/site-packages/qiling/debugger/qdb/qdb.py", line 105, in dbg_hook
    elif self.ql.loader.entry_point:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'QlLoaderBLOB' object has no attribute 'entry_point'

Additional context
The error is normal, indeed the QlLoaderBlob object doesn't have this attribute.
I found these lines in the qdb.py file (line 140) which seems to be here to handle the case but they are after different other access to self.ql.loader.entry_point atrribute previous them :

  if self.ql.os.type is QL_OS.BLOB:
            self.ql.loader.entry_point = self.ql.loader.load_address

   elif init_hook:
            for each_hook in init_hook:
                self.do_breakpoint(each_hook)

Maybe a fix could be to change the place of these lines.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions