Skip to content

Commit

Permalink
Merge pull request #7 from 0xricksanchez/main
Browse files Browse the repository at this point in the history
Minor QoL changes (0xricksanchez#132)
  • Loading branch information
fengjixuchui authored Dec 14, 2022
2 parents 7d1b35d + 177301c commit 9c51d6a
Show file tree
Hide file tree
Showing 28 changed files with 855 additions and 300 deletions.
2 changes: 2 additions & 0 deletions .dockerfile_base
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ LABEL maintainer="Christopher Krah <[email protected]>"

ENV DEBIAN_FRONTEND noninteractive

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apt-get update && \
apt-get upgrade -yq && \
set -e && \
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
name: black

on: [push, pull_request]

on:
push:
paths:
- src/*
- .github/workflows/black.yml
pull_request:
paths:
- src/*
- .github/workflows/black.yml
jobs:
lint:
runs-on: ubuntu-22.04
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: codecov

on: [push, pull_request]
on:
push:
paths:
- src/*
- .github/workflows/codecov.yml
pull_request:
paths:
- src/*
- .github/workflows/codecov.yml
jobs:
run:
runs-on: ubuntu-22.04
Expand Down
28 changes: 16 additions & 12 deletions .github/workflows/hadolint.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
name: hadolint

on: [push, pull_request]
on:
push:
paths:
- .dockerfile*
- .github/workflows/hadolint.yml
pull_request:
paths:
- .dockerfile*
- .github/workflows/hadolint.yml
jobs:
hadolint:
runs-on: ubuntu-22.04
name: "Hadolint"
steps:
- uses: actions/checkout@v2
- uses: jbergstroem/hadolint-gh-action@v1
with:
error-level: 0
annotate: true
output_format: tty
dockerfile: ".dockerfile_base .dockerfile_dbg .dockerfile_dbge .dockerfile_kbuilder .dockerfile_rootfs"
runs-on: ubuntu-22.04
name: "Hadolint"
steps:
- uses: actions/checkout@v2
- uses: jbergstroem/hadolint-gh-action@v1
with:
dockerfile: ".dockerfile*"
14 changes: 7 additions & 7 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
name: flake8

on:
push:
paths:
- src/*
- .github/workflows/linter.yml
pull_request:
types: [opened, synchronize, reopened]

paths:
- src/*
- .github/workflows/linter.yml
jobs:
run-linters:
name: Run linters
runs-on: ubuntu-22.04

steps:
- name: Check out Git repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.9

- name: Install Python dependencies
run: pip install black flake8

- name: Run linters
uses: wearerequired/lint-action@v1
with:
Expand Down
24 changes: 16 additions & 8 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
name: shellcheck

on: [push, pull_request]

on:
push:
paths:
- io/scipts/*.sh
- ctf/misc/*.sh
- .github/workflows/shellcheck.yml
pull_request:
paths:
- io/scipts/*.sh
- ctf/misc/*.sh
- .github/workflows/shellcheck.yml
jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: -e SC2002,SC2016,SC1009,SC1073,SC1072
- uses: actions/checkout@v2
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: -e SC2002,SC2016,SC1009,SC1073,SC1072
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ linux-*
kernel_root
io/rootfs*
io/filesystem*
examples/c_kmod/compile_commands.json
patches/*
configs/kernel_configs/*.conf*
Dockerfile*
Expand Down
2 changes: 2 additions & 0 deletions configs/user.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Architecture which is targeted
# Currently only x86_64 and arm64 is supported
arch = x86_64
# Allows creating a descriptive tag so that the same kernel versions can be unpacked into different folders, to e.g.: reflect different compilation methods
kernel_tag =

[kernel_dl]
# IFF more than one specific version is set below the internal hierarchy prioritizes: mmp > tag > commit
Expand Down
42 changes: 24 additions & 18 deletions ctf/misc/extract-vmlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,44 @@
# ----------------------------------------------------------------------

check_vmlinux() {
# Use readelf to check if it's a valid ELF
readelf -h "$1" > /dev/null 2>&1 || return 1

cat "$1"
exit 0
# Use readelf to check if it's a valid ELF
readelf -h "$1" >/dev/null 2>&1 || return 1
res=$(readlink -fn "$2")
cat "$1" >"$res"
exit 0
}

try_decompress() {
# The obscure use of the "tr" filter is to work around older versions of
# "grep" that report the byte offset of the line instead of the pattern.

# Try to find the header ($1) and decompress from here
for pos in $(LC_CTYPE=C tr "$1\n$2" "\n$2=" < "$img" | grep -abo "^$2"); do
pos=${pos%%:*}
tail -c+"$pos" "$img" | $3 > "$tmp" 2> /dev/null
check_vmlinux "$tmp"
done
# The obscure use of the "tr" filter is to work around older versions of
# "grep" that report the byte offset of the line instead of the pattern.

# Try to find the header ($1) and decompress from here
for pos in $(LC_CTYPE=C tr "$1\n$2" "\n$2=" <"$img" | grep -abo "^$2"); do
pos=${pos%%:*}
tail -c+"$pos" "$img" | $3 >"$tmp" 2>/dev/null
check_vmlinux "$tmp" "$res"
done
}

# Check invocation:
me=${0##*/}
img=$1
if [ $# -ne 1 ] || [ ! -s "$img" ]; then
echo "Usage: $me <kernel-image>" >&2
exit 2
if [ $# -lt 1 ] || [ ! -s "$img" ]; then
echo "Usage: $me <kernel-image> <ouput_file>" >&2
exit 2
fi

res="vmlinux"
if [ $# -eq 2 ]; then
res="$2"
fi

# Prepare temp files:
tmp=$(mktemp /tmp/vmlinux-XXX)
trap 'rm -f $tmp' 0

# That didn't work, so retry after decompression.
echo "[>] Attempting to write output into \"$res\""
try_decompress '\037\213\010' xy gunzip
try_decompress '\3757zXZ\000' abcde unxz
try_decompress 'BZh' xy bunzip2
Expand All @@ -52,7 +58,7 @@ try_decompress '\002!L\030' xxx 'lz4 -d'
try_decompress '(\265/\375' xxx unzstd

# Finally check for uncompressed images or objects:
check_vmlinux "$img"
check_vmlinux "$img" "$res"

# Bail out:
echo "$me: Cannot find vmlinux." >&2
3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# README

This directory houses example use cases and demo configutations for LIKE-DBG.
8 changes: 5 additions & 3 deletions examples/c_kmod/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# README

This directory houses example kernel modules that can automatically be compiled into a kernel by
tweaking your `LIKE_DBG` config:
This directory houses example kernel modules that can automatically be compiled into a kernel by tweaking your `LIKE_DBG` config:
You can either provide a path to a folder housing a single kernel module such as `examples/c_kmod/ioctl_test_drv/`.
Alternatively, you can provide a path to a folder housing multiple kernel modules as well, e.g.: `examples/c_kmod/`.

```ini
[kernel_builder]
# Provide a path to a parent directory that houses custom kernel modules (see the example)
custom_modules = examples/c_kmod/
```

Every module located in `examples/c_kmod` is to be placed in a proper subdirectory, each with a sound `Makefile` and `Kconfig`.
The above example recursively tries to add all kernel modules found in the given path.
In this scenario, every module located in `examples/c_kmod` you want added to the kernel is to be placed in a proper subdirectory, each with a sound `Makefile` and `Kconfig`.
For example like so:

```bash
Expand Down
Loading

0 comments on commit 9c51d6a

Please sign in to comment.