Skip to content

Commit ba43fe8

Browse files
committed
fix: update unicorn-engine API and improve justfile discoverability
- Update test.rs to use unicorn-engine 2.x API: - Replace Permission with Prot for memory permissions - Change mem_map/mem_protect size parameter from usize to u64 - Use bitwise OR instead of insert() for Prot flags - Reorganize justfile for better discoverability: - Add help command showing all available recipes - Add ci recipe that runs full lint + test pipeline - Align recipes with CI workflow (nightly for fmt/clippy) - Organize into clear sections: build, lint, test, dev - Add fmt-check for formatting verification without changes
1 parent 87dc6a5 commit ba43fe8

File tree

2 files changed

+120
-36
lines changed

2 files changed

+120
-36
lines changed

core/src/test.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn emu_from_shellcode32(code: &[u8]) -> crate::emu::Emulator {
101101
#[cfg(test)]
102102
pub mod uc {
103103
use byteorder::{ByteOrder, LittleEndian};
104-
use unicorn_engine::unicorn_const::{uc_error, Arch, Mode, Permission};
104+
use unicorn_engine::unicorn_const::{uc_error, Arch, Mode, Prot};
105105

106106
use super::load_shellcode64;
107107
use crate::{
@@ -127,8 +127,8 @@ pub mod uc {
127127
let section_size = section.virtual_range.end - section.virtual_range.start;
128128
emu.mem_map(
129129
section.virtual_range.start,
130-
crate::util::align(section_size, PAGE_SIZE as u64) as usize,
131-
Permission::WRITE,
130+
crate::util::align(section_size, PAGE_SIZE as u64),
131+
Prot::WRITE,
132132
)
133133
.unwrap();
134134

@@ -147,20 +147,20 @@ pub mod uc {
147147
page_addr += PAGE_SIZE as u64;
148148
}
149149

150-
let mut prot = Permission::NONE;
150+
let mut prot = Prot::NONE;
151151
if section.permissions.intersects(Permissions::W) {
152-
prot.insert(Permission::WRITE);
152+
prot = prot | Prot::WRITE;
153153
}
154154
if section.permissions.intersects(Permissions::R) {
155-
prot.insert(Permission::READ);
155+
prot = prot | Prot::READ;
156156
}
157157
if section.permissions.intersects(Permissions::X) {
158-
prot.insert(Permission::EXEC);
158+
prot = prot | Prot::EXEC;
159159
}
160160

161161
emu.mem_protect(
162162
section.virtual_range.start,
163-
crate::util::align(section_size, PAGE_SIZE as u64) as usize,
163+
crate::util::align(section_size, PAGE_SIZE as u64),
164164
prot,
165165
)
166166
.unwrap();
@@ -294,7 +294,7 @@ pub mod uc {
294294
.reg_write(unicorn_engine::RegisterX86::RIP, m.address_space.base_address)
295295
.unwrap(); // 0x0
296296

297-
uc.emu.mem_map(0x5000, 0x2000, Permission::ALL).unwrap();
297+
uc.emu.mem_map(0x5000, 0x2000, Prot::ALL).unwrap();
298298
uc.emu.reg_write(unicorn_engine::RegisterX86::RSP, 0x6000).unwrap();
299299
uc.emu.reg_write(unicorn_engine::RegisterX86::RBP, 0x6000).unwrap();
300300

justfile

Lines changed: 111 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,141 @@
1-
# build with various profiles to populate the rustc cache
2-
warmup:
3-
# build with cranelift
4-
-env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly build -Zcodegen-backend
5-
# build without cranelift (as hx will do)
6-
-cargo build
7-
# build in release profile
8-
-cargo build --release
1+
# lancelot justfile - run `just` or `just help` to see available commands
2+
3+
# Default recipe - show help
4+
default: help
5+
6+
# Show available commands
7+
help:
8+
@echo "lancelot build system"
9+
@echo ""
10+
@echo "Usage: just <recipe>"
11+
@echo ""
12+
@echo "Common recipes:"
13+
@echo " build - Build the project (stable toolchain)"
14+
@echo " build-release - Build with optimizations"
15+
@echo " test - Run all tests"
16+
@echo " lint - Run all lints (check, clippy, fmt)"
17+
@echo " ci - Run full CI pipeline (lint + test)"
18+
@echo ""
19+
@echo "Individual lint recipes:"
20+
@echo " check - Run cargo check"
21+
@echo " clippy - Run clippy lints"
22+
@echo " fmt - Run rustfmt"
23+
@echo " fmt-check - Check formatting without modifying"
24+
@echo ""
25+
@echo "Individual test recipes:"
26+
@echo " test-core - Test lancelot core library"
27+
@echo " test-flirt - Test lancelot-flirt library"
28+
@echo " test-pylancelot - Test pylancelot (Rust + Python)"
29+
@echo " test-pyflirt - Test pyflirt (Rust + Python)"
30+
@echo ""
31+
@echo "Development recipes (uses cranelift for faster builds, requires nightly):"
32+
@echo " dev-build - Fast build with cranelift"
33+
@echo " dev-check - Fast check with cranelift"
34+
@echo " warmup - Populate rustc cache with various profiles"
35+
36+
# ============================================================================
37+
# Main build recipes
38+
# ============================================================================
39+
40+
# Build the project (stable toolchain)
41+
build:
42+
cargo build
943

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

48+
# ============================================================================
49+
# Lint recipes (matches CI workflow)
50+
# ============================================================================
51+
52+
# Run cargo check
1453
check:
15-
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly check -Zcodegen-backend
54+
cargo check
1655

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

60+
# Format code with rustfmt (requires nightly for all features)
2061
fmt:
21-
cargo +nightly fmt
62+
cargo +nightly fmt --all
63+
64+
# Check formatting without modifying files
65+
fmt-check:
66+
cargo +nightly fmt --all -- --check
67+
68+
# Run all lints: check, clippy, and format check
69+
lint: check clippy fmt-check
2270

23-
lint: check clippy fmt
71+
# ============================================================================
72+
# Test recipes (matches CI workflow)
73+
# ============================================================================
74+
75+
# Run all tests
76+
test: test-core test-flirt test-pylancelot test-pyflirt
2477

78+
# Test lancelot core library
2579
test-core:
26-
cd core && \
27-
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly test -Zcodegen-backend
80+
cargo test -p lancelot
2881

82+
# Test lancelot-flirt library
2983
test-flirt:
30-
cd flirt && \
31-
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly test -Zcodegen-backend
84+
cargo test -p lancelot-flirt
3285

86+
# Test pylancelot Rust code
3387
test-pylancelot-rs:
34-
cd pylancelot && \
35-
cargo test # can't use cranelift when linking to python
88+
cd pylancelot && cargo test
3689

90+
# Test pylancelot Python code
3791
test-pylancelot-py:
3892
bash .github/scripts/pytest-pylancelot.sh
3993

94+
# Test pylancelot (both Rust and Python)
4095
test-pylancelot: test-pylancelot-rs test-pylancelot-py
4196

97+
# Test pyflirt Rust code
4298
test-pyflirt-rs:
43-
cd pyflirt && \
44-
cargo test # can't use cranelift when linking to python
99+
cd pyflirt && cargo test
45100

101+
# Test pyflirt Python code
46102
test-pyflirt-py:
47103
bash .github/scripts/pytest-pyflirt.sh
48104

105+
# Test pyflirt (both Rust and Python)
49106
test-pyflirt: test-pyflirt-rs test-pyflirt-py
50107

51-
test: test-core test-flirt test-pylancelot test-pyflirt
108+
# ============================================================================
109+
# CI recipe - run the full pipeline
110+
# ============================================================================
52111

53-
build:
112+
# Run full CI pipeline (matches GitHub Actions workflow)
113+
ci: lint test
114+
115+
# ============================================================================
116+
# Development recipes (optional - uses cranelift for faster builds)
117+
# ============================================================================
118+
119+
# Fast build with cranelift (requires nightly)
120+
dev-build:
54121
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly build -Zcodegen-backend
55122

56-
build-release:
57-
cargo build --release
123+
# Fast check with cranelift (requires nightly)
124+
dev-check:
125+
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly check -Zcodegen-backend
126+
127+
# Fast clippy with cranelift (requires nightly)
128+
dev-clippy:
129+
env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly clippy -Zcodegen-backend
130+
131+
# Build with various profiles to populate the rustc cache
132+
warmup:
133+
# build with cranelift
134+
-env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly build -Zcodegen-backend
135+
# build without cranelift (as hx will do)
136+
-cargo build
137+
# build in release profile
138+
-cargo build --release
139+
# build unicorn dep, which is only used in tests, and takes a while
140+
-cd core && env CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly test -Zcodegen-backend
141+
-cd core && cargo test

0 commit comments

Comments
 (0)