Skip to content

Commit 02c16b4

Browse files
committed
Fix build
1 parent 8d3cf97 commit 02c16b4

File tree

6 files changed

+48
-38
lines changed

6 files changed

+48
-38
lines changed

crackers/src/synthesis/assignment_model.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ impl<'ctx, T: ModelingContext<'ctx>> AssignmentModel<'ctx, T> {
2121
&self.model
2222
}
2323

24-
pub fn initial_state(&'ctx self) -> Option<&'ctx State<'ctx>> {
24+
pub fn initial_state<'a>(&'a self) -> Option<&'a State<'ctx>> {
2525
self.gadgets.first().map(|f| f.get_original_state())
2626
}
2727

28-
pub fn final_state(&'ctx self) -> Option<&'ctx State<'ctx>> {
28+
pub fn final_state<'a>(&'a self) -> Option<&'a State<'ctx>> {
2929
self.gadgets.last().map(|f| f.get_final_state())
3030
}
3131

32-
pub fn read_original(&'ctx self, vn: GeneralizedVarNode) -> Option<BV<'ctx>> {
32+
pub fn read_original<'a>(&'a self, vn: GeneralizedVarNode) -> Option<BV<'ctx>> {
3333
self.initial_state().and_then(|f| f.read(vn).ok())
3434
}
3535

36-
pub fn read_output(&'ctx self, vn: GeneralizedVarNode) -> Option<BV<'ctx>> {
36+
pub fn read_output<'a>(&'a self, vn: GeneralizedVarNode) -> Option<BV<'ctx>> {
3737
self.final_state().and_then(|f| f.read(vn).ok())
3838
}
3939

40-
pub fn read_resolved(&'ctx self, vn: &ResolvedVarnode<'ctx>) -> Option<BV<'ctx>> {
40+
pub fn read_resolved<'a>(&'a self, vn: &ResolvedVarnode<'ctx>) -> Option<BV<'ctx>> {
4141
self.final_state().and_then(|f| f.read_resolved(vn).ok())
4242
}
4343

44-
pub fn print_trace_of_reg(&'ctx self, reg: &str) {
44+
pub fn print_trace_of_reg(&self, reg: &str) {
4545
let r = self.final_state().unwrap().get_register(reg).unwrap();
4646
for gadget in &self.gadgets {
4747
let val = gadget.get_original_state().read_varnode(r).unwrap();
@@ -51,7 +51,7 @@ impl<'ctx, T: ModelingContext<'ctx>> AssignmentModel<'ctx, T> {
5151
}
5252
}
5353

54-
pub fn initial_reg(&'ctx self, reg: &str) -> Option<BV<'ctx>> {
54+
pub fn initial_reg<'a>(&'a self, reg: &str) -> Option<BV<'ctx>> {
5555
let r = self.final_state().unwrap().get_register(reg).unwrap();
5656
let val = self.gadgets[0]
5757
.get_original_state()

crackers/src/synthesis/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use jingle::modeling::{ModeledBlock, ModeledInstruction, ModelingContext, State};
1+
use jingle::modeling::{ModeledBlock, ModeledInstruction, ModelingContext};
22
use jingle::sleigh::Instruction;
33
use jingle::JingleContext;
44
use std::cmp::Ordering;
@@ -192,7 +192,10 @@ impl<'ctx> AssignmentSynthesis<'ctx> {
192192
let jingle = JingleContext::new(self.z3, self.library.as_ref());
193193
let a: PcodeAssignment<'ctx> =
194194
t.build_assignment(&jingle, response.assignment)?;
195-
event!(Level::DEBUG, "Workers Terminated; building and checking model");
195+
event!(
196+
Level::DEBUG,
197+
"Workers Terminated; building and checking model"
198+
);
196199
let solver = Solver::new(self.z3);
197200
let jingle = JingleContext::new(self.z3, self.library.as_ref());
198201
let model = a.check(&jingle, &solver)?;

crackers_python/src/config/constraint.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ impl TryFrom<PythonConstraintConfig> for ConstraintConfig {
4747
let precondition = Some(value.precondition.borrow(py).clone().try_into()?);
4848
let postcondition = Some(value.postcondition.borrow(py).clone().try_into()?);
4949
let pointer = Some(value.pointer.borrow(py).clone().try_into()?);
50-
Ok(ConstraintConfig { precondition, postcondition, pointer })
50+
Ok(ConstraintConfig {
51+
precondition,
52+
postcondition,
53+
pointer,
54+
})
5155
})
5256
}
5357
}
@@ -111,8 +115,8 @@ pub struct PythonPointerRangeConstraints {
111115
impl Clone for PythonPointerRangeConstraints {
112116
fn clone(&self) -> Self {
113117
Python::with_gil(|_| Self {
114-
read: self.read.iter().map(|f| f.clone()).collect(),
115-
write: self.write.iter().map(|f| f.clone()).collect(),
118+
read: self.read.to_vec(),
119+
write: self.write.to_vec(),
116120
})
117121
}
118122
}
@@ -145,10 +149,10 @@ impl TryFrom<PythonPointerRangeConstraints> for PointerRangeConstraints {
145149
type Error = PyErr;
146150
fn try_from(value: PythonPointerRangeConstraints) -> Result<Self, Self::Error> {
147151
Python::with_gil(|py| {
148-
let read: Vec<_> = value.read.iter().map(|f| f.borrow(py).clone()).collect();
149-
let read = if read.len() > 0 { Some(read) } else { None };
150-
let write: Vec<_> = value.write.iter().map(|f| f.borrow(py).clone()).collect();
151-
let write = if write.len() > 0 { Some(write) } else { None };
152+
let read: Vec<_> = value.read.iter().map(|f| *f.borrow(py)).collect();
153+
let read = if !read.is_empty() { Some(read) } else { None };
154+
let write: Vec<_> = value.write.iter().map(|f| *f.borrow(py)).collect();
155+
let write = if !write.is_empty() { Some(write) } else { None };
152156
Ok(Self { read, write })
153157
})
154158
}

crackers_python/src/config/mod.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ impl TryFrom<&PythonCrackersConfig> for CrackersConfig {
4747
type Error = PyErr;
4848

4949
fn try_from(value: &PythonCrackersConfig) -> Result<Self, Self::Error> {
50-
Python::with_gil(|py|{
51-
52-
Ok(CrackersConfig{
53-
meta: value.meta.borrow(py).clone(),
54-
specification: value.spec.borrow(py).clone(),
55-
library: value.library.borrow(py).clone(),
56-
sleigh: value.sleigh.borrow(py).clone(),
57-
synthesis: value.synthesis.borrow(py).clone(),
58-
constraint: value.constraint.extract::<PythonConstraintConfig>(py)?.try_into().ok(),
59-
})
50+
Python::with_gil(|py| {
51+
Ok(CrackersConfig {
52+
meta: value.meta.borrow(py).clone(),
53+
specification: value.spec.borrow(py).clone(),
54+
library: value.library.borrow(py).clone(),
55+
sleigh: value.sleigh.borrow(py).clone(),
56+
synthesis: value.synthesis.borrow(py).clone(),
57+
constraint: value
58+
.constraint
59+
.extract::<PythonConstraintConfig>(py)?
60+
.try_into()
61+
.ok(),
62+
})
6063
})
6164
}
6265
}
@@ -75,6 +78,6 @@ impl PythonCrackersConfig {
7578
pub fn resolve_config(&self) -> PyResult<PythonSynthesisParams> {
7679
let cfg = CrackersConfig::try_from(self)?;
7780
let syn = cfg.resolve()?;
78-
Ok(PythonSynthesisParams{inner: syn})
81+
Ok(PythonSynthesisParams { inner: syn })
7982
}
8083
}

crackers_python/src/decision/assignment_model.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub struct PythonAssignmentModel {
1515

1616
#[pymethods]
1717
impl PythonAssignmentModel {
18-
1918
fn eval_bv(&self, bv: Py<PyAny>, model_completion: bool) -> PyResult<Py<PyAny>> {
2019
let bv = BV::try_from_python(bv)?;
2120
let val = self
@@ -48,14 +47,14 @@ impl PythonAssignmentModel {
4847
}
4948

5049
pub fn inputs(&self) -> Option<VarNodeIterator> {
51-
let state = self.inner.initial_state()?;
52-
Some(VarNodeIterator::new(
53-
state.clone(),
54-
self.inner
55-
.gadgets
56-
.iter()
57-
.flat_map(|g| g.get_inputs().into_iter()),
58-
))
50+
let state = self.inner.initial_state()?.clone();
51+
let gadgets = self
52+
.inner
53+
.gadgets
54+
.clone()
55+
.into_iter()
56+
.flat_map(|g| g.get_inputs().into_iter());
57+
Some(VarNodeIterator::new(state, gadgets))
5958
}
6059

6160
pub fn outputs(&self) -> Option<VarNodeIterator> {
@@ -64,7 +63,8 @@ impl PythonAssignmentModel {
6463
state.clone(),
6564
self.inner
6665
.gadgets
67-
.iter()
66+
.clone()
67+
.into_iter()
6868
.flat_map(|g| g.get_outputs().into_iter()),
6969
))
7070
}

crackers_python/src/synthesis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::decision::assignment_model::PythonAssignmentModel;
22
use crate::decision::PythonDecisionResult;
33
use crackers::synthesis::builder::SynthesisParams;
44
use crackers::synthesis::DecisionResult;
5-
use jingle::python::bitvec::get_python_z3;
5+
use jingle::python::z3::get_python_z3;
66
use pyo3::{pyclass, pymethods, Py, PyResult, Python};
77

88
#[pyclass]

0 commit comments

Comments
 (0)