Skip to content

DOS disks should not use fs_mapper API #1375

@VinceQu

Description

@VinceQu

*Describe the bug
The 8086 DOS/MBR example in the qiling/examples folder is not running correctly.

Fresh install with pip. Ubuntu 22.04 in WSL.

Sample Code

qiling/examples> python3 doogie_8086_crack.py

Traceback (most recent call last):
  File "/qiling/examples/doogie_8086_crack.py", line 204, in <module>
    ql = first_stage()
  File "/qiling/examples/doogie_8086_crack.py", line 193, in first_stage
    ql = Qiling(["rootfs/8086/doogie/doogie.DOS_MBR"], "rootfs/8086", console=False)
  File "/home/user/.local/lib/python3.10/site-packages/qiling/core.py", line 190, in __init__
    self.loader.run()
  File "/home/user/.local/lib/python3.10/site-packages/qiling/loader/dos.py", line 86, in run
    if not self.ql.os.fs_mapper.has_mapping(0x80):
  File "/home/user/.local/lib/python3.10/site-packages/qiling/os/mapper.py", line 85, in has_mapping
    return vpath in self
  File "/home/user/.local/lib/python3.10/site-packages/qiling/os/mapper.py", line 72, in __contains__
    absvpath = self.path.virtual_abspath(vpath)
  File "/home/user/.local/lib/python3.10/site-packages/qiling/os/path.py", line 305, in virtual_abspath
    absvpath = self.__virtual_abspath(virtpath)
  File "/home/user/.local/lib/python3.10/site-packages/qiling/os/path.py", line 99, in __virtual_abspath
    vpath = self.PureVirtualPath(virtpath)
  File "/usr/lib/python3.10/pathlib.py", line 562, in __new__
    return cls._from_parts(args)
  File "/usr/lib/python3.10/pathlib.py", line 594, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/usr/lib/python3.10/pathlib.py", line 578, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not in

Expected behavior
The example should run.

Additional context
Lines 86 and 87 of qiling/loader/dos.py

            if not self.ql.os.fs_mapper.has_mapping(0x80):
                self.ql.os.fs_mapper.add_mapping(0x80, QlDisk(path, 0x80))

It seems like the "has_mapping()" function expects a "str" not an "int" as os.fspath() is later called with the passed value as an argument. Sadly i am not very familiar with the internal structure of qiling. I am guessing that simply turning the 0x80 into a string ("0x80") might lead to other problems further down the line.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions