Skip to content

Commit 7d3c66e

Browse files
committed
feat: do not enable cuckoo feature by default
1 parent 2051ae5 commit 7d3c66e

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
run: |
7878
cd boreal-py
7979
uv sync --dev
80-
uv run pytest
80+
uv run --config-setting "build-args=--features=cuckoo" pytest
8181
8282
strategy:
8383
fail-fast: false
@@ -313,7 +313,7 @@ jobs:
313313
314314
# And run the python bindings tests
315315
cd boreal-py
316-
uv run --config-setting 'build-args=--profile=dev' pytest
316+
uv run --config-setting 'build-args=--profile=dev --features=cuckoo' pytest
317317
cd ..
318318
319319
# Finally, generate the report

boreal-py/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ name = "boreal"
1616
crate-type = ["cdylib"]
1717

1818
[features]
19-
default = ["cuckoo"]
19+
default = []
2020

2121
cuckoo = ["boreal/cuckoo"]
2222

boreal-py/src/lib.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ffi::CString;
55

66
use pyo3::exceptions::{PyException, PyTypeError};
77
use pyo3::prelude::*;
8-
use pyo3::types::PyDict;
8+
use pyo3::types::{PyDict, PyString};
99
use pyo3::{create_exception, ffi, intern};
1010

1111
use ::boreal::compiler;
@@ -25,6 +25,7 @@ create_exception!(boreal, AddRuleError, PyException, "error when adding rules");
2525
#[pymodule]
2626
fn boreal(m: &Bound<'_, PyModule>) -> PyResult<()> {
2727
m.add_function(wrap_pyfunction!(compile, m)?)?;
28+
m.add_function(wrap_pyfunction!(available_modules, m)?)?;
2829

2930
m.add("AddRuleError", m.py().get_type::<AddRuleError>())?;
3031
m.add("ScanError", m.py().get_type::<scanner::ScanError>())?;
@@ -56,17 +57,7 @@ fn compile(
5657
includes: bool,
5758
error_on_warning: bool,
5859
) -> PyResult<scanner::Scanner> {
59-
let mut compiler = compiler::CompilerBuilder::new()
60-
.add_module(::boreal::module::Console::with_callback(|log| {
61-
// XXX: when targetting python 3.12 or above, this could be simplified
62-
// by using the "%.*s" format, avoiding the CString conversion.
63-
if let Ok(cstr) = CString::new(log) {
64-
// Safety: see <https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_FromFormat>
65-
// for the format. A '%s" expects a c-string pointer, which has just been built.
66-
unsafe { ffi::PySys_FormatStdout(c"%s\n".as_ptr(), cstr.as_ptr()) }
67-
}
68-
}))
69-
.build();
60+
let mut compiler = build_compiler();
7061

7162
compiler.set_params(
7263
compiler::CompilerParams::default()
@@ -159,6 +150,28 @@ fn compile(
159150
Ok(scanner::Scanner::new(compiler.into_scanner(), warnings))
160151
}
161152

153+
#[pyfunction]
154+
fn available_modules(py: Python<'_>) -> Vec<Bound<'_, PyString>> {
155+
build_compiler()
156+
.available_modules()
157+
.map(|s| PyString::new(py, s))
158+
.collect()
159+
}
160+
161+
fn build_compiler() -> compiler::Compiler {
162+
compiler::CompilerBuilder::new()
163+
.add_module(::boreal::module::Console::with_callback(|log| {
164+
// XXX: when targetting python 3.12 or above, this could be simplified
165+
// by using the "%.*s" format, avoiding the CString conversion.
166+
if let Ok(cstr) = CString::new(log) {
167+
// Safety: see <https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_FromFormat>
168+
// for the format. A '%s" expects a c-string pointer, which has just been built.
169+
unsafe { ffi::PySys_FormatStdout(c"%s\n".as_ptr(), cstr.as_ptr()) }
170+
}
171+
}))
172+
.build()
173+
}
174+
162175
fn convert_compiler_error(err: &compiler::AddRuleError, input_name: &str, input: &str) -> String {
163176
err.to_short_description(input_name, input)
164177
}

boreal-py/tests/test_scanner.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ def test_match_console_log(module, is_yara, capsys):
249249

250250
# TODO: find a way to compile yara python with cuckoo?
251251
def test_match_modules_data():
252+
# Test only works if the cuckoo module is present
253+
if 'cuckoo' not in boreal.available_modules():
254+
return
255+
252256
rules = boreal.compile(source="""
253257
import "cuckoo"
254258

0 commit comments

Comments
 (0)