Skip to content

Commit

Permalink
chore: update CI and fix linter issues (#146)
Browse files Browse the repository at this point in the history
* chore: Update CI
* chore: fix linter issues
  • Loading branch information
0xricksanchez authored Sep 26, 2023
1 parent 4468e9a commit 6432fa8
Show file tree
Hide file tree
Showing 24 changed files with 280 additions and 202 deletions.
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 10
target-branch: "main"
commit-message:
prefix: "chore"
include: "scope"
labels:
- dependency-update
assignees:
- "0xricksanchez"
reviewers:
- "0xricksanchez"
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- .github/workflows/black.yml
jobs:
lint:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- .github/workflows/codecov.yml
jobs:
run:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Setup Python
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/linter.yml

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: ruff

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Install poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Install dependencies
run: poetry install

- name: Check lock file
run: poetry check --lock

- name: Run ruff
run: poetry run ruff check . --fix --show-source --show-fixes --exit-non-zero-on-fix
2 changes: 1 addition & 1 deletion .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run ShellCheck
Expand Down
77 changes: 27 additions & 50 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 41 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
[tool.black]
line-length = 150
target-version = ['py39']


[tool.pytest.ini_options]
pythonpath = ["src"]
testpaths = ["src"]
console_output_style = ["progress"]


[tool.poetry]
name = "like-dbg"
name = "like_dbg"
version = "0.1.0"
description = "Fully dockerized Linux kernel debugging environment"
authors = ["434b <admin@0x434b.dev>"]
license = "MIT"
readme = "README.md"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.dependencies]
python = "^3.11"
loguru = "^0.7.2"
Expand All @@ -26,13 +19,44 @@ docker = "^6.1.3"
tqdm = "^4.66.1"
requests = "^2.31.0"


[tool.poetry.group.dev.dependencies]
black = "^23.9.1"
flake8 = "^6.1.0"
pytest = "^7.4.2"
pytest-cov = "^4.1.0"
ruff = "^0.0.291"

[tool.ruff]
# https://docs.astral.sh/ruff/settings
select = ["E", "F", "C4", "PTH", "TID", "PERF", "N", "C90"]
# Group violations by containing file.
format = "grouped"
line-length = 120
# Never enforce `E501` (line length violations).
ignore = ["E501"]
# Assume Python 3.10
target-version = "py310"
fix = true
unfixable = [
"ERA", # do not autoremove commented out code
]

[tool.ruff.mccabe]
# Flag errors (`C901`) whenever the complexity level exceeds 10.
max-complexity = 10

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.isort]
force-single-line = true
lines-between-types = 1
lines-after-imports = 2

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.black]
line-length = 120
target-version = ['py310']

[tool.pytest.ini_options]
pythonpath = ["src"]
testpaths = ["src"]
console_output_style = ["progress"]
16 changes: 9 additions & 7 deletions src/debuggee.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env python3

import subprocess as sp
from pathlib import Path

from loguru import logger

from .docker_runner import DockerRunner
from .misc import adjust_qemu_arch, cfg_setter, tmux, tmux_shell
from src.docker_runner import DockerRunner
from src.misc import adjust_qemu_arch, cfg_setter, tmux, tmux_shell


# +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
Expand All @@ -16,7 +14,9 @@ class Debuggee(DockerRunner):
def __init__(self, **kwargs):
super().__init__(**kwargs)
user_cfg = kwargs.get("user_cfg", "")
cfg_setter(self, ["general", "debuggee", "debuggee_docker", "rootfs_general"], user_cfg, exclude_keys=["kernel_root"])
cfg_setter(
self, ["general", "debuggee", "debuggee_docker", "rootfs_general"], user_cfg, exclude_keys=["kernel_root"]
)
if self.ctf:
self.ctf_mount = kwargs.get("ctf_mount")
self.kernel = Path(self.docker_mnt) / kwargs.get("ctf_kernel", "")
Expand All @@ -25,7 +25,7 @@ def __init__(self, **kwargs):
self.kernel = Path(self.docker_mnt) / self.kernel_root / "arch" / self.arch / "boot" / "Image"
self.rootfs = Path(self.docker_mnt) / self.rootfs_dir / (self.rootfs_base + self.arch + self.rootfs_ftype)
self.qemu_arch = adjust_qemu_arch(self.arch)
self.cmd = None
self.cmd = ""

def run(self):
super().run(check_existing=True)
Expand Down Expand Up @@ -103,7 +103,9 @@ def run_container(self):
self.cmd += " pti=on"
self.cmd += f' oops=panic panic={self.infer_panic_behavior()}"'
self.cmd += self.infer_qemu_fs_mount()
self.cmd += " -net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 -net nic,model=e1000 -nographic -pidfile vm.pid"
self.cmd += (
" -net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 -net nic,model=e1000 -nographic -pidfile vm.pid"
)
if self.kvm and self.qemu_arch == "x86_64":
self.cmd += " -enable-kvm"
if self.gdb:
Expand Down
17 changes: 11 additions & 6 deletions src/debugger.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/usr/bin/env python3

import subprocess as sp
from glob import glob
from pathlib import Path

from loguru import logger

from .docker_runner import DockerRunner
from .misc import SYSTEM_CFG, cfg_setter, get_sha256_from_file, get_value_from_section_by_key, new_context, tmux, tmux_shell
from src.docker_runner import DockerRunner
from src.misc import (
SYSTEM_CFG,
cfg_setter,
get_sha256_from_file,
get_value_from_section_by_key,
new_context,
tmux,
tmux_shell,
)

GDB_SCRIPT_HIST = Path(".gdb_hist")

Expand Down Expand Up @@ -40,7 +45,7 @@ def _set_ctf_ctx(self, kwargs) -> None:
exit(-1)

def _extract_vmlinux(self) -> int:
vml_ext = Path(glob("**/extract-vmlinux.sh", recursive=True)[0]).resolve().absolute()
vml_ext = next(Path.cwd().rglob("extract-vmlinux.sh")).resolve().absolute()
pkernel = self.ctf_kernel.resolve().absolute()
with new_context(self.ctf_dir):
cmd = f"{vml_ext} {pkernel}"
Expand Down
Loading

0 comments on commit 6432fa8

Please sign in to comment.