Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
#[cfg(test)]
pub mod uc {
use byteorder::{ByteOrder, LittleEndian};
use unicorn_engine::unicorn_const::{uc_error, Arch, Mode, Permission};
use unicorn_engine::unicorn_const::{uc_error, Arch, Mode, Prot};

use super::load_shellcode64;
use crate::{
Expand All @@ -127,8 +127,8 @@
let section_size = section.virtual_range.end - section.virtual_range.start;
emu.mem_map(
section.virtual_range.start,
crate::util::align(section_size, PAGE_SIZE as u64) as usize,
Permission::WRITE,
crate::util::align(section_size, PAGE_SIZE as u64),
Prot::WRITE,
)
.unwrap();

Expand All @@ -147,20 +147,20 @@
page_addr += PAGE_SIZE as u64;
}

let mut prot = Permission::NONE;
let mut prot = Prot::NONE;
if section.permissions.intersects(Permissions::W) {
prot.insert(Permission::WRITE);
prot = prot | Prot::WRITE;
}
if section.permissions.intersects(Permissions::R) {
prot.insert(Permission::READ);
prot = prot | Prot::READ;
}
if section.permissions.intersects(Permissions::X) {
prot.insert(Permission::EXEC);
prot = prot | Prot::EXEC;
}

emu.mem_protect(
section.virtual_range.start,
crate::util::align(section_size, PAGE_SIZE as u64) as usize,
crate::util::align(section_size, PAGE_SIZE as u64),
prot,
)
.unwrap();
Expand Down Expand Up @@ -286,7 +286,7 @@
}
}

pub fn uc_from_shellcode64(code: &[u8]) -> Uc {

Check warning on line 289 in core/src/test.rs

View workflow job for this annotation

GitHub Actions / test

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 289 in core/src/test.rs

View workflow job for this annotation

GitHub Actions / test

hiding a lifetime that's elided elsewhere is confusing
let m = load_shellcode64(code);
let mut uc = Uc::from_module(&m);

Expand All @@ -294,7 +294,7 @@
.reg_write(unicorn_engine::RegisterX86::RIP, m.address_space.base_address)
.unwrap(); // 0x0

uc.emu.mem_map(0x5000, 0x2000, Permission::ALL).unwrap();
uc.emu.mem_map(0x5000, 0x2000, Prot::ALL).unwrap();
uc.emu.reg_write(unicorn_engine::RegisterX86::RSP, 0x6000).unwrap();
uc.emu.reg_write(unicorn_engine::RegisterX86::RBP, 0x6000).unwrap();

Expand Down
138 changes: 111 additions & 27 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,57 +1,141 @@
# build with various profiles to populate the rustc cache
warmup:
# build with cranelift
-env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly build -Zcodegen-backend
# build without cranelift (as hx will do)
-cargo build
# build in release profile
-cargo build --release
# lancelot justfile - run `just` or `just help` to see available commands

# Default recipe - show help
default: help

# Show available commands
help:
@echo "lancelot build system"
@echo ""
@echo "Usage: just <recipe>"
@echo ""
@echo "Common recipes:"
@echo " build - Build the project (stable toolchain)"
@echo " build-release - Build with optimizations"
@echo " test - Run all tests"
@echo " lint - Run all lints (check, clippy, fmt)"
@echo " ci - Run full CI pipeline (lint + test)"
@echo ""
@echo "Individual lint recipes:"
@echo " check - Run cargo check"
@echo " clippy - Run clippy lints"
@echo " fmt - Run rustfmt"
@echo " fmt-check - Check formatting without modifying"
@echo ""
@echo "Individual test recipes:"
@echo " test-core - Test lancelot core library"
@echo " test-flirt - Test lancelot-flirt library"
@echo " test-pylancelot - Test pylancelot (Rust + Python)"
@echo " test-pyflirt - Test pyflirt (Rust + Python)"
@echo ""
@echo "Development recipes (uses cranelift for faster builds, requires nightly):"
@echo " dev-build - Fast build with cranelift"
@echo " dev-check - Fast check with cranelift"
@echo " warmup - Populate rustc cache with various profiles"

# ============================================================================
# Main build recipes
# ============================================================================

# Build the project (stable toolchain)
build:
cargo build

# build unicorn dep, which is only used in tests, and takes a while
-cd core && env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly test -Zcodegen-backend
-cd core && cargo test
# Build with optimizations
build-release:
cargo build --release

# ============================================================================
# Lint recipes (matches CI workflow)
# ============================================================================

# Run cargo check
check:
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly check -Zcodegen-backend
cargo check

# Run clippy with warnings as errors (requires nightly)
clippy:
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly clippy -Zcodegen-backend
cargo +nightly clippy -- -D warnings

# Format code with rustfmt (requires nightly for all features)
fmt:
cargo +nightly fmt
cargo +nightly fmt --all

# Check formatting without modifying files
fmt-check:
cargo +nightly fmt --all -- --check

# Run all lints: check, clippy, and format check
lint: check clippy fmt-check

lint: check clippy fmt
# ============================================================================
# Test recipes (matches CI workflow)
# ============================================================================

# Run all tests
test: test-core test-flirt test-pylancelot test-pyflirt

# Test lancelot core library
test-core:
cd core && \
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly test -Zcodegen-backend
cargo test -p lancelot

# Test lancelot-flirt library
test-flirt:
cd flirt && \
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly test -Zcodegen-backend
cargo test -p lancelot-flirt

# Test pylancelot Rust code
test-pylancelot-rs:
cd pylancelot && \
cargo test # can't use cranelift when linking to python
cd pylancelot && cargo test

# Test pylancelot Python code
test-pylancelot-py:
bash .github/scripts/pytest-pylancelot.sh

# Test pylancelot (both Rust and Python)
test-pylancelot: test-pylancelot-rs test-pylancelot-py

# Test pyflirt Rust code
test-pyflirt-rs:
cd pyflirt && \
cargo test # can't use cranelift when linking to python
cd pyflirt && cargo test

# Test pyflirt Python code
test-pyflirt-py:
bash .github/scripts/pytest-pyflirt.sh

# Test pyflirt (both Rust and Python)
test-pyflirt: test-pyflirt-rs test-pyflirt-py

test: test-core test-flirt test-pylancelot test-pyflirt
# ============================================================================
# CI recipe - run the full pipeline
# ============================================================================

build:
# Run full CI pipeline (matches GitHub Actions workflow)
ci: lint test

# ============================================================================
# Development recipes (optional - uses cranelift for faster builds)
# ============================================================================

# Fast build with cranelift (requires nightly)
dev-build:
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly build -Zcodegen-backend

build-release:
cargo build --release
# Fast check with cranelift (requires nightly)
dev-check:
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly check -Zcodegen-backend

# Fast clippy with cranelift (requires nightly)
dev-clippy:
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly clippy -Zcodegen-backend

# Build with various profiles to populate the rustc cache
warmup:
# build with cranelift
-env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly build -Zcodegen-backend
# build without cranelift (as hx will do)
-cargo build
# build in release profile
-cargo build --release
# build unicorn dep, which is only used in tests, and takes a while
-cd core && env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly test -Zcodegen-backend
-cd core && cargo test
Loading