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
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build

on:
push:
pull_request:
workflow_dispatch:

jobs:
pre_ci:
uses: dtolnay/.github/.github/workflows/pre_ci.yml@master

build:
name: ${{matrix.name || format('Rust {0}', matrix.rust)}}
needs: pre_ci
if: needs.pre_ci.outputs.continue
runs-on: ${{matrix.os}}-latest
strategy:
fail-fast: false
matrix:
rust: [nightly, beta, stable]
os: [ubuntu]
env:
RUSTFLAGS: --cfg deny_warnings -Dwarnings
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
- run: cargo build --all-features
13 changes: 0 additions & 13 deletions .github/workflows/check.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Style

on:
push:
pull_request:
workflow_dispatch:

jobs:
pre_ci:
uses: dtolnay/.github/.github/workflows/pre_ci.yml@master

build:
name: ${{matrix.name || format('Rust {0}', matrix.rust)}}
needs: pre_ci
if: needs.pre_ci.outputs.continue
runs-on: ${{matrix.os}}-latest
strategy:
fail-fast: false
matrix:
rust: [ stable ]
os: [ ubuntu ]
env:
RUSTFLAGS: --cfg deny_warnings -Dwarnings
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
components: clippy, rustfmt
- name: cargo fmt
run: cargo fmt --all -- --check
- name: cargo clippy
run: cargo clippy --all-targets -- -D warnings
6 changes: 3 additions & 3 deletions src/bin/crackers/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ fn synthesize(config: PathBuf) -> anyhow::Result<()> {
.with(tracing_subscriber::fmt::layer().with_writer(writer))
.init();
let params = p.resolve()?;
let result = match params.combine_instructions{
true => params.build_combined(&z3).and_then(|mut c|c.decide()),
false => params.build_single(&z3).and_then(|mut c| c.decide())
let result = match params.combine_instructions {
true => params.build_combined(&z3).and_then(|mut c| c.decide()),
false => params.build_single(&z3).and_then(|mut c| c.decide()),
};
match result {
Ok(res) => match res {
Expand Down
8 changes: 4 additions & 4 deletions src/config/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub struct PointerRange {
/// Generates a state constraint that a given varnode must be equal to a given value
pub fn gen_memory_constraint(
m: MemoryEqualityConstraint,
) -> impl for<'a,> Fn(&JingleContext<'a>, &State<'a>, u64) -> Result<Bool<'a>, CrackersError>
) -> impl for<'a> Fn(&JingleContext<'a>, &State<'a>, u64) -> Result<Bool<'a>, CrackersError>
+ Send
+ Sync
+ Clone
Expand Down Expand Up @@ -162,14 +162,14 @@ pub fn gen_register_pointer_constraint<'ctx>(
let m = m.clone();
let mut bools = vec![];
let pointer = state.read_varnode(&vn)?;
for (i,byte) in value.as_bytes().iter().enumerate() {
for (i, byte) in value.as_bytes().iter().enumerate() {
let expected = BV::from_u64(jingle.z3, *byte as u64, 8);
let char_ptr = ResolvedVarnode::Indirect(ResolvedIndirectVarNode{
let char_ptr = ResolvedVarnode::Indirect(ResolvedIndirectVarNode {
// dumb but whatever
pointer_location: vn.clone(),
pointer: pointer.clone().add(i as u64),
access_size_bytes: 1,
pointer_space_idx: state.get_code_space_idx()
pointer_space_idx: state.get_code_space_idx(),
});
let actual = state.read_resolved(&char_ptr)?;
bools.push(actual._eq(&expected))
Expand Down
4 changes: 3 additions & 1 deletion src/config/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ fn load_image<T: AsRef<Path>>(path: T) -> Result<(SegmentFile, &'static str), Cr
}

/// gross hack
fn load_image_spec<T: AsRef<Path>>(path: T) -> Result<(OwnedFile, &'static str), CrackersConfigError> {
fn load_image_spec<T: AsRef<Path>>(
path: T,
) -> Result<(OwnedFile, &'static str), CrackersConfigError> {
let data = fs::read(path.as_ref())?;
let file = File::parse(&*data)?;
let arch = map_gimli_architecture(&file).ok_or(UnrecognizedArchitecture(format!(
Expand Down
4 changes: 2 additions & 2 deletions src/config/synthesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct SynthesisConfig {
pub strategy: SynthesisSelectionStrategy,
pub max_candidates_per_slot: usize,
pub parallel: usize,
pub combine_instructions: bool
pub combine_instructions: bool,
}

impl Default for SynthesisConfig {
Expand All @@ -16,7 +16,7 @@ impl Default for SynthesisConfig {
strategy: SynthesisSelectionStrategy::OptimizeStrategy,
max_candidates_per_slot: 50,
parallel: 4,
combine_instructions: true
combine_instructions: true,
}
}
}
14 changes: 11 additions & 3 deletions src/gadget/another_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ impl<'ctx, 'a, T> TraceCandidateIterator<'ctx, 'a, T>
where
T: Iterator<Item = &'a Gadget>,
{
pub(crate) fn new(jingle: &JingleContext<'ctx>, gadgets: T, trace: Vec<ModeledInstruction<'ctx>>) -> Self {
pub(crate) fn new(
jingle: &JingleContext<'ctx>,
gadgets: T,
trace: Vec<ModeledInstruction<'ctx>>,
) -> Self {
let _solver = Solver::new(jingle.z3);
Self {
jingle: jingle.clone(),
Expand All @@ -48,7 +52,11 @@ where
.trace
.iter()
.map(|i| {
trace!("Checking {} signature vs gadget {}", i.instr.disassembly, gadget);
trace!(
"Checking {} signature vs gadget {}",
i.instr.disassembly,
gadget
);

gadget_signature.covers(&GadgetSignature::from_instr(&i.instr, i))
&& has_compatible_control_flow(&i.instr, gadget)
Expand All @@ -68,7 +76,7 @@ where
}
}
})
}else{
} else {
trace!("Could not model gadget: \n{}", gadget)
}
return Some(next_entry);
Expand Down
2 changes: 1 addition & 1 deletion src/gadget/library/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct GadgetLibraryParams {
pub operation_blacklist: HashSet<OpCode>,
pub path: String,
pub sample_size: Option<usize>,
pub base_address: Option<u64>
pub base_address: Option<u64>,
}

impl GadgetLibraryParams {
Expand Down
1 change: 0 additions & 1 deletion src/gadget/library/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,3 @@ mod tests {
GadgetLibrary::build_from_image(bin_sleigh, &GadgetLibraryParams::default()).unwrap();
}
}

5 changes: 4 additions & 1 deletion src/gadget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ impl Gadget {
.any(|i| i.ops.iter().any(|o| blacklist.contains(&o.opcode())))
}

pub fn model<'ctx>(&self, jingle: &JingleContext<'ctx>) -> Result<ModeledBlock<'ctx>, CrackersError> {
pub fn model<'ctx>(
&self,
jingle: &JingleContext<'ctx>,
) -> Result<ModeledBlock<'ctx>, CrackersError> {
let blk = ModeledBlock::read(jingle, self.instructions.clone().into_iter())?;
Ok(blk)
}
Expand Down
12 changes: 7 additions & 5 deletions src/gadget/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::cmp::Ordering;

use crate::gadget::Gadget;
use jingle::modeling::ModeledBlock;
use jingle::sleigh::{GeneralizedVarNode, IndirectVarNode, Instruction, SpaceManager, SpaceType, VarNode};
use jingle::sleigh::{
GeneralizedVarNode, IndirectVarNode, Instruction, SpaceManager, SpaceType, VarNode,
};
use tracing::trace;

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -51,8 +53,8 @@ impl GadgetSignature {
for op in &value.ops {
if let Some(op) = op.output() {
if let GeneralizedVarNode::Direct(v) = &op {
if let Some(h) = t.get_space_info(v.space_index){
if h._type == SpaceType::IPTR_PROCESSOR{
if let Some(h) = t.get_space_info(v.space_index) {
if h._type == SpaceType::IPTR_PROCESSOR {
outputs.push(op);
}
}
Expand Down Expand Up @@ -87,8 +89,8 @@ impl From<&Gadget> for GadgetSignature {
for op in value.instructions.iter().flat_map(|i| &i.ops) {
if let Some(op) = op.output() {
if let GeneralizedVarNode::Direct(v) = &op {
if let Some(h) = value.get_space_info(v.space_index){
if h._type == SpaceType::IPTR_PROCESSOR{
if let Some(h) = value.get_space_info(v.space_index) {
if h._type == SpaceType::IPTR_PROCESSOR {
outputs.push(op);
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/synthesis/assignment_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ impl<'ctx, T: ModelingContext<'ctx>> AssignmentModel<'ctx, T> {
let r = self.final_state().unwrap().get_register(reg).unwrap();
for gadget in &self.gadgets {
let val = gadget.get_original_state().read_varnode(&r).unwrap();
println!("{} Before: {:?}",reg, self.model.eval(&val, false));
println!("{} Before: {:?}", reg, self.model.eval(&val, false));
let val = gadget.get_final_state().read_varnode(&r).unwrap();
println!("{} After: {:?}",reg, self.model.eval(&val, false));
println!("{} After: {:?}", reg, self.model.eval(&val, false));
}
}

pub fn initial_reg(&'ctx self, reg: &str) -> Option<BV<'ctx>> {
let r = self.final_state().unwrap().get_register(reg).unwrap();
let val = self.gadgets[0].get_original_state().read_varnode(&r).unwrap();
self.model.eval(&val, false)
let val = self.gadgets[0]
.get_original_state()
.read_varnode(&r)
.unwrap();
self.model.eval(&val, false)
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/synthesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ impl<'ctx> AssignmentSynthesis<'ctx> {
let jingle = JingleContext::new(z3, builder.gadget_library.as_ref());
let modeled_instrs: Vec<ModeledInstruction<'ctx>> = instrs
.iter()
.map(|i| {
ModeledInstruction::new(i.clone(), &jingle).unwrap()
})
.map(|i| ModeledInstruction::new(i.clone(), &jingle).unwrap())
.collect();

let candidates = CandidateBuilder::default()
Expand Down
8 changes: 3 additions & 5 deletions src/synthesis/pcode_theory/theory_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ pub(crate) fn gen_conflict_clauses(
}
if result.is_empty() {
None
} else if !semantics.is_empty() {
Some(ConflictClause::combine(semantics.as_slice()))
} else {
if !semantics.is_empty() {
Some(ConflictClause::combine(semantics.as_slice()))
} else {
Some(ConflictClause::combine(result.as_slice()))
}
Some(ConflictClause::combine(result.as_slice()))
}
}
Loading