Skip to content

Commit

Permalink
add qcow2 support to the debugee (#134)
Browse files Browse the repository at this point in the history
* add qcow2 support to the debugee
  • Loading branch information
0xricksanchez authored Dec 27, 2022
1 parent 205eee2 commit aef7e64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/debuggee.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def infer_qemu_fs_mount(self) -> str:
return f" -initrd {rootfs}"
elif b"filesystem data" in magic.stdout:
return f" -drive file={rootfs},format=raw"
elif b"qemu qcow" in magic.stdout.lower():
return f" -drive file={rootfs}"
else:
logger.error(f"Unsupported rootfs type: {magic.stdout}")
exit(-1)
Expand Down
14 changes: 12 additions & 2 deletions src/tests/test_debuggee.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pathlib import Path
from unittest.mock import MagicMock, patch

from src.debuggee import Debuggee
from unittest.mock import patch, MagicMock
import pytest

from src.debuggee import Debuggee


@patch("subprocess.run")
def test_infer_qemu_fs_mount_cpio(sp_mock) -> None:
Expand All @@ -23,6 +24,15 @@ def test_infer_qemu_fs_mount_filesystem(sp_mock) -> None:
assert d.infer_qemu_fs_mount() == f" -drive file={d.rootfs},format=raw"


@patch("subprocess.run")
def test_infer_qemu_fs_mount_qcow2(sp_mock) -> None:
d = Debuggee(**{"kroot": "foo"})
mock = MagicMock()
mock.configure_mock(**{"stdout": b"filesystem.qcow2: QEMU QCOW Image (v3), 12344321 bytes (v3), 12345678 bytes"})
sp_mock.return_value = mock
assert d.infer_qemu_fs_mount() == f" -drive file={d.rootfs}"


@patch("subprocess.run")
def test_infer_qemu_fs_mount_error(sp_mock) -> None:
d = Debuggee(**{"kroot": "foo"})
Expand Down

0 comments on commit aef7e64

Please sign in to comment.