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

DOS disks should not use fs_mapper API #1375

Open
VinceQu opened this issue Aug 20, 2023 · 1 comment
Open

DOS disks should not use fs_mapper API #1375

VinceQu opened this issue Aug 20, 2023 · 1 comment
Assignees
Labels

Comments

@VinceQu
Copy link

VinceQu commented Aug 20, 2023

*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.

@elicn
Copy link
Member

elicn commented Aug 22, 2023

Indeed, that is an expected side effect of #1336, and should be fixed.
Implementing DOS disks using fs_mapper is not quite intuitive since its API doesn't make much sense in that context. Until we figure this out, you may use the workaround you mentioned: turning the disk index (usually 0x80) into a string. As long as it is consistent, it should work just fine.

I am changing the issue subject to reflect that.

@elicn elicn changed the title DOS/MBR Example not working DOS disks should not use fs_mapper API Aug 22, 2023
@elicn elicn self-assigned this Aug 22, 2023
@elicn elicn added the os dos label Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants