Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb891ef

Browse files
committed
feat: enhance build system and add usage documentation
- Updated Cargo.toml to define multiple binaries: `loki` and `loki-util`. - Introduced a Justfile for simplified command execution and build processes. - Added a comprehensive usage guide (USAGE.md) for LOKI2. - Created a detailed build guide (BUILD.md) and a parity matrix for feature comparison with Loki v1. - Implemented a JSONL logger for structured logging. - Enhanced the Makefile for better build and packaging processes. - Added configuration examples and documentation for exclusions and score calculations. - Introduced a utility for updating signatures and upgrading LOKI2.
1 parent 0d1df9a commit bb891ef

21 files changed

Lines changed: 5465 additions & 276 deletions

.github/workflows/release.yml

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
name: Release Build
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # Triggers on tags like v2.0.0, v2.1.0, etc.
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
build:
13+
name: Build ${{ matrix.target }}
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
# Linux x86_64
20+
- os: ubuntu-latest
21+
target: x86_64-unknown-linux-gnu
22+
artifact_name: loki-linux-x86_64
23+
binary_name: loki
24+
archive_format: tar.gz
25+
26+
# Linux ARM64
27+
- os: ubuntu-latest
28+
target: aarch64-unknown-linux-gnu
29+
artifact_name: loki-linux-aarch64
30+
binary_name: loki
31+
archive_format: tar.gz
32+
33+
# Windows x86_64
34+
- os: windows-latest
35+
target: x86_64-pc-windows-msvc
36+
artifact_name: loki-windows-x86_64
37+
binary_name: loki.exe
38+
archive_format: zip
39+
40+
# macOS x86_64
41+
- os: macos-latest
42+
target: x86_64-apple-darwin
43+
artifact_name: loki-macos-x86_64
44+
binary_name: loki
45+
archive_format: tar.gz
46+
47+
# macOS ARM64 (Apple Silicon)
48+
- os: macos-latest
49+
target: aarch64-apple-darwin
50+
artifact_name: loki-macos-aarch64
51+
binary_name: loki
52+
archive_format: tar.gz
53+
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
with:
58+
submodules: recursive
59+
60+
- name: Install Rust
61+
uses: dtolnay/rust-toolchain@stable
62+
with:
63+
targets: ${{ matrix.target }}
64+
65+
- name: Cache Cargo registry
66+
uses: actions/cache@v4
67+
with:
68+
path: |
69+
~/.cargo/bin/
70+
~/.cargo/registry/index/
71+
~/.cargo/registry/cache/
72+
~/.cargo/git/db/
73+
target/
74+
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
75+
restore-keys: |
76+
${{ runner.os }}-cargo-${{ matrix.target }}-
77+
78+
- name: Install cross-compilation dependencies (Linux ARM64)
79+
if: matrix.target == 'aarch64-unknown-linux-gnu'
80+
run: |
81+
sudo apt-get update
82+
sudo apt-get install -y gcc-aarch64-linux-gnu
83+
84+
- name: Configure Cargo for cross-compilation (Linux ARM64)
85+
if: matrix.target == 'aarch64-unknown-linux-gnu'
86+
run: |
87+
mkdir -p .cargo
88+
echo '[target.aarch64-unknown-linux-gnu]' >> .cargo/config.toml
89+
echo 'linker = "aarch64-linux-gnu-gcc"' >> .cargo/config.toml
90+
91+
- name: Build release binary
92+
run: cargo build --release --target ${{ matrix.target }}
93+
94+
- name: Strip binary (Linux/macOS)
95+
if: runner.os != 'Windows'
96+
run: |
97+
strip target/${{ matrix.target }}/release/${{ matrix.binary_name }}
98+
99+
- name: Create release archive
100+
shell: bash
101+
run: |
102+
VERSION=${GITHUB_REF#refs/tags/}
103+
ARCHIVE_NAME="${{ matrix.artifact_name }}-${VERSION}.${{ matrix.archive_format }}"
104+
105+
if [ "${{ matrix.archive_format }}" = "tar.gz" ]; then
106+
tar czf "${ARCHIVE_NAME}" -C target/${{ matrix.target }}/release ${{ matrix.binary_name }}
107+
else
108+
cd target/${{ matrix.target }}/release
109+
zip -r "../../../${ARCHIVE_NAME}" ${{ matrix.binary_name }}
110+
cd ../../..
111+
fi
112+
113+
echo "ARCHIVE_NAME=${ARCHIVE_NAME}" >> $GITHUB_ENV
114+
echo "BINARY_NAME=${{ matrix.binary_name }}" >> $GITHUB_ENV
115+
116+
- name: Generate checksums (Linux/macOS)
117+
if: runner.os != 'Windows'
118+
shell: bash
119+
run: |
120+
sha256sum "${ARCHIVE_NAME}" > "${ARCHIVE_NAME}.sha256"
121+
echo "CHECKSUM_FILE=${ARCHIVE_NAME}.sha256" >> $GITHUB_ENV
122+
123+
- name: Generate checksums (Windows)
124+
if: runner.os == 'Windows'
125+
shell: pwsh
126+
run: |
127+
$hash = Get-FileHash -Path "${ARCHIVE_NAME}" -Algorithm SHA256
128+
$hash.Hash | Out-File -FilePath "${ARCHIVE_NAME}.sha256" -Encoding ASCII
129+
echo "CHECKSUM_FILE=${ARCHIVE_NAME}.sha256" >> $env:GITHUB_ENV
130+
131+
- name: Upload artifacts
132+
uses: actions/upload-artifact@v4
133+
with:
134+
name: ${{ matrix.artifact_name }}
135+
path: |
136+
${{ env.ARCHIVE_NAME }}
137+
${{ env.CHECKSUM_FILE }}
138+
139+
release:
140+
name: Create Release
141+
needs: build
142+
runs-on: ubuntu-latest
143+
permissions:
144+
contents: write
145+
146+
steps:
147+
- name: Checkout code
148+
uses: actions/checkout@v4
149+
150+
- name: Download all artifacts
151+
uses: actions/download-artifact@v4
152+
with:
153+
path: artifacts
154+
155+
- name: Extract version from tag
156+
id: version
157+
run: |
158+
VERSION=${GITHUB_REF#refs/tags/}
159+
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
160+
echo "Tag version: ${VERSION}"
161+
162+
- name: Create Release
163+
uses: softprops/action-gh-release@v1
164+
with:
165+
name: Release ${{ steps.version.outputs.VERSION }}
166+
body: |
167+
## Loki2 ${{ steps.version.outputs.VERSION }}
168+
169+
### Downloads
170+
171+
**Linux (x86_64)**
172+
- Binary: `loki-linux-x86_64-${{ steps.version.outputs.VERSION }}.tar.gz`
173+
- Checksum: `loki-linux-x86_64-${{ steps.version.outputs.VERSION }}.tar.gz.sha256`
174+
175+
**Linux (ARM64)**
176+
- Binary: `loki-linux-aarch64-${{ steps.version.outputs.VERSION }}.tar.gz`
177+
- Checksum: `loki-linux-aarch64-${{ steps.version.outputs.VERSION }}.tar.gz.sha256`
178+
179+
**Windows (x86_64)**
180+
- Binary: `loki-windows-x86_64-${{ steps.version.outputs.VERSION }}.zip`
181+
- Checksum: `loki-windows-x86_64-${{ steps.version.outputs.VERSION }}.zip.sha256`
182+
183+
**macOS (x86_64)**
184+
- Binary: `loki-macos-x86_64-${{ steps.version.outputs.VERSION }}.tar.gz`
185+
- Checksum: `loki-macos-x86_64-${{ steps.version.outputs.VERSION }}.tar.gz.sha256`
186+
187+
**macOS (ARM64/Apple Silicon)**
188+
- Binary: `loki-macos-aarch64-${{ steps.version.outputs.VERSION }}.tar.gz`
189+
- Checksum: `loki-macos-aarch64-${{ steps.version.outputs.VERSION }}.tar.gz.sha256`
190+
191+
### Installation
192+
193+
1. Download the appropriate binary for your platform
194+
2. Extract the archive
195+
3. Make binary executable (Linux/macOS): `chmod +x loki`
196+
4. Run: `./loki --help`
197+
198+
### Signature Base
199+
200+
You'll need to link or clone the signature-base repository:
201+
```bash
202+
git clone https://github.com/Neo23x0/signature-base.git signatures
203+
```
204+
files: |
205+
artifacts/**/*
206+
draft: false
207+
prerelease: ${{ contains(steps.version.outputs.VERSION, '-') }}
208+
tag_name: ${{ steps.version.outputs.VERSION }}
209+
210+

Cargo.toml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ name = "loki"
33
version = "2.0.0"
44
edition = "2021"
55

6+
[[bin]]
7+
name = "loki"
8+
path = "src/main.rs"
9+
10+
[[bin]]
11+
name = "loki-util"
12+
path = "src/loki_util/main.rs"
13+
614
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
715

816
[dependencies]
@@ -22,9 +30,10 @@ sha2 = "0.10.*"
2230
hex = "0.4.*"
2331
memmap = "0.7.*"
2432
chrono = "*"
25-
26-
[target.'cfg(unix)'.dependencies]
27-
yara = { version="*" }
28-
29-
[target.'cfg(windows)'.dependencies]
30-
yara = { version="*", features=["bundled-4_2_3"] }
33+
regex = "1.*"
34+
yara-x = "1.10.0"
35+
reqwest = { version = "0.11", features = ["blocking"] }
36+
zip = "0.6"
37+
flate2 = "1.0"
38+
serde = { version = "1.0", features = ["derive"] }
39+
serde_json = "1.0"

Justfile

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# LOKI2 Build System - Justfile
2+
# Modern command runner alternative to Makefile
3+
# Install: cargo install just
4+
# Usage: just <command>
5+
6+
# Default recipe
7+
default:
8+
@just --list
9+
10+
# Build the release binary
11+
build:
12+
#!/usr/bin/env bash
13+
echo "[!] The build has a bunch of dependencies"
14+
echo "[i] For information on how to fulfill these prerequisites see the workflow file in .github/workflows/"
15+
echo "[+] Building LOKI release version ..."
16+
if [[ "$(uname -s)" == "Linux" ]]; then
17+
cargo build --release --target x86_64-unknown-linux-musl
18+
echo "[+] Binary location: target/x86_64-unknown-linux-musl/release/loki"
19+
else
20+
cargo build --release
21+
echo "[+] Binary location: target/release/loki"
22+
fi
23+
echo "[+] Build successful!"
24+
25+
# Create a complete build package
26+
package: build install-signatures
27+
#!/usr/bin/env bash
28+
echo "[+] Creating build package ..."
29+
mkdir -p build/signatures build/config
30+
31+
# Copy binary
32+
if [[ "$(uname -s)" == "Linux" ]]; then
33+
cp target/x86_64-unknown-linux-musl/release/loki build/loki
34+
else
35+
cp target/release/loki build/loki
36+
fi
37+
chmod +x build/loki
38+
echo "[+] Binary copied to build/loki"
39+
40+
# Copy usage guide
41+
if [ -f USAGE.md ]; then
42+
cp USAGE.md build/
43+
else
44+
echo "# LOKI2 Usage Guide" > build/USAGE.md
45+
echo "" >> build/USAGE.md
46+
echo "See README.md for usage instructions." >> build/USAGE.md
47+
fi
48+
49+
# Copy config
50+
if [ -f config/excludes.cfg.example ]; then
51+
cp config/excludes.cfg.example build/config/excludes.cfg
52+
else
53+
echo "# LOKI2 Exclusions Configuration" > build/config/excludes.cfg
54+
fi
55+
56+
# Copy LICENSE
57+
[ -f LICENSE ] && cp LICENSE build/ || true
58+
59+
echo ""
60+
echo "[✓] Build package created successfully!"
61+
echo "[✓] Package location: build/"
62+
echo "[✓] Binary: build/loki"
63+
echo "[✓] Signatures: build/signatures/"
64+
echo "[✓] Config: build/config/"
65+
echo "[✓] Usage guide: build/USAGE.md"
66+
67+
# Install or link signatures
68+
install-signatures:
69+
#!/usr/bin/env bash
70+
echo "[+] Setting up signatures ..."
71+
mkdir -p build/signatures
72+
73+
if [ -d "./signatures" ] || [ -L "./signatures" ]; then
74+
echo "[+] Found signatures, copying ..."
75+
cp -rL ./signatures/* build/signatures/ 2>/dev/null || true
76+
else
77+
echo "[!] No local signatures found."
78+
echo " You can:"
79+
echo " 1. Clone: git clone https://github.com/Neo23x0/signature-base ../signature-base/"
80+
echo " 2. Link: ln -s ../signature-base/ ./signatures"
81+
echo " 3. Or manually copy to build/signatures/"
82+
mkdir -p build/signatures/yara build/signatures/iocs
83+
echo "# Place YARA rules (.yar files) here" > build/signatures/yara/README.txt
84+
echo "# Place IOC files here" > build/signatures/iocs/README.txt
85+
fi
86+
echo "[+] Signatures setup complete"
87+
88+
# Clean build artifacts
89+
clean:
90+
#!/usr/bin/env bash
91+
echo "[+] Cleaning up ..."
92+
rm -rf target dist tmp build
93+
echo "[+] Clean complete"
94+
95+
# Clean only build directory
96+
clean-build:
97+
#!/usr/bin/env bash
98+
echo "[+] Cleaning build directory ..."
99+
rm -rf build
100+
echo "[+] Build directory cleaned"
101+
102+
# Show help
103+
help:
104+
@just --list
105+
106+

0 commit comments

Comments
 (0)