Skip to content

Commit b487356

Browse files
committed
fix examples
1 parent c78c1dc commit b487356

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

jingle/examples/location.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use jingle::analysis::bounded_visit::BoundedStepLocationAnalysis;
44
use jingle::analysis::{Analysis, RunnableAnalysis};
5+
use jingle::modeling::machine::cpu::concrete::ConcretePcodeAddress;
56
use jingle_sleigh::context::image::gimli::load_with_gimli;
67
use std::env;
78

@@ -19,7 +20,7 @@ fn main() {
1920
let loaded = load_with_gimli(bin_path, "/Applications/ghidra").unwrap();
2021

2122
let mut direct = BoundedStepLocationAnalysis::new(&loaded, 20);
22-
let _states = direct.run(&loaded, direct.make_initial_state(FUNC_SWITCH.into()));
23+
let _states = direct.run(&loaded, ConcretePcodeAddress::from(FUNC_NESTED));
2324
let pcode_graph = direct.take_cfg();
2425
let addrs = pcode_graph.nodes().collect::<Vec<_>>();
2526
for addr in addrs {

jingle/examples/stack_offset.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ use jingle::analysis::direct_valuation::{
66
};
77
use jingle::analysis::pcode_store::PcodeStore;
88
use jingle::analysis::{Analysis, RunnableAnalysis};
9+
use jingle::modeling::machine::cpu::concrete::ConcretePcodeAddress;
910
use jingle_sleigh::VarNode;
1011
use jingle_sleigh::context::image::gimli::load_with_gimli;
12+
use std::collections::HashMap;
1113
use std::env;
1214

1315
const FUNC_LINE: u64 = 0x100000460;
@@ -56,35 +58,27 @@ fn main() {
5658

5759
// Run the compound analysis - construct the compound initial state explicitly
5860
// (new Analysis API requires passing a value convertible into the CPA `State`)
59-
let initial_compound_state = jingle::analysis::compound::CompoundState::new(
60-
// construct left (location) initial state using the DirectLocationAnalysis inherent helper
61-
compound_analysis.0.make_initial_state(FUNC_NESTED.into()),
62-
// construct right (valuation) initial state directly
63-
jingle::analysis::direct_valuation::DirectValuationState::new(loaded.arch_info().clone()),
64-
);
65-
let compound_states = compound_analysis.run(&loaded, initial_compound_state);
61+
62+
let compound_states = compound_analysis.run(&loaded, ConcretePcodeAddress::from(FUNC_NESTED));
6663

6764
tracing::info!("Analysis completed with {} states", compound_states.len());
6865

6966
// Extract the CFG from the DirectLocationAnalysis (left side of compound)
7067
let cfg = compound_analysis.0.take_cfg();
7168

7269
// Extract valuation information from the compound states
73-
use jingle::analysis::compound::CompoundState;
74-
use std::collections::HashMap;
7570
let mut stack_offsets = HashMap::new();
7671
let mut direct_valuations = HashMap::new();
7772

7873
for state in &compound_states {
7974
// Extract location from the outermost left (PcodeAddressLattice)
80-
if let jingle::analysis::cpa::lattice::flat::FlatLattice::Value(addr) = &state.left.inner()
81-
{
75+
if let jingle::analysis::cpa::lattice::flat::FlatLattice::Value(addr) = &state.0.inner() {
8276
// state.right is DirectValuationState
8377
// Extract stack pointer offset if available
84-
if let Some(sp_value) = state.right.get_value(&stack_pointer) {
78+
if let Some(sp_value) = state.1.get_value(&stack_pointer) {
8579
stack_offsets.insert(*addr, sp_value.clone());
8680
}
87-
direct_valuations.insert(*addr, state.right.clone());
81+
direct_valuations.insert(*addr, state.1.clone());
8882
}
8983
}
9084

jingle/src/analysis/bounded_visit/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ mod state;
33
use crate::analysis::Analysis;
44
use crate::analysis::bounded_visit::state::BoundedStepsState;
55
use crate::analysis::cfg::PcodeCfg;
6-
use crate::analysis::cpa::ConfigurableProgramAnalysis;
7-
use crate::analysis::cpa::lattice::flat::FlatLattice::Value;
6+
use crate::analysis::cpa::lattice::flat::FlatLattice::{self, Value};
7+
use crate::analysis::cpa::{ConfigurableProgramAnalysis, IntoState};
88
use crate::analysis::pcode_store::PcodeStore;
99
use crate::modeling::machine::cpu::concrete::ConcretePcodeAddress;
1010
use jingle_sleigh::PcodeOperation;
@@ -63,6 +63,12 @@ impl ConfigurableProgramAnalysis for BoundedStepsCpa {
6363
}
6464
}
6565

66+
impl IntoState<BoundedStepsCpa> for ConcretePcodeAddress {
67+
fn into_state(self, c: &BoundedStepsCpa) -> BoundedStepsState {
68+
BoundedStepsState::new(FlatLattice::Value(self), c.max_steps)
69+
}
70+
}
71+
6672
impl Analysis for BoundedStepsCpa {}
6773

6874
pub type BoundedStepLocationAnalysis = BoundedStepsCpa;

0 commit comments

Comments
 (0)