Skip to content

Commit

Permalink
New memory (#31)
Browse files Browse the repository at this point in the history
* initial commit of reworking memory

* dropping support for symbolic execution

* remove .bak files from new memory implementation

* fixing more mips bugs

* changing dockerfile to debian stretch

* Lots of changes for large performance boost in Abstract Interpretation

* fix tarpaulin

* Return to Ubuntu Xenial Dockerfile

Debian stretch is breaking tarpaulin code coverage
  • Loading branch information
endeav0r committed Nov 4, 2017
1 parent 432bd33 commit e1deaa3
Show file tree
Hide file tree
Showing 39 changed files with 1,566 additions and 3,915 deletions.
2 changes: 1 addition & 1 deletion .ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ cd /falcon && \
cargo test && \
cargo test -- --ignored && \
cargo test --features thread_safe&& \
curl -sL https://github.com/xd009642/tarpaulin/releases/download/0.5.0/cargo-tarpaulin-0.5.0-travis.tar.gz | tar xvz -C $HOME/.cargo/bin && \
curl -sL https://github.com/xd009642/tarpaulin/releases/download/0.5.4/cargo-tarpaulin-0.5.4-travis.tar.gz | tar xvz -C $HOME/.cargo/bin && \
cargo tarpaulin -i --ignore-tests --no-count --ciserver travis-ci --coveralls $1
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ RUN curl https://sh.rustup.rs -sSf > /tmp/install.sh && \
chmod 755 /tmp/install.sh && \
/tmp/install.sh -y

RUN curl https://files.reversing.io/z3-xenial-x64-05.aug.2017.gz | gzip -d > /usr/local/bin/z3 && \
chmod 755 /usr/local/bin/z3

SHELL ["/bin/bash", "-c"]

COPY . /falcon/
26 changes: 26 additions & 0 deletions Dockerfile.stretch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM debian:stretch

RUN apt-get update && \
apt-get -y dist-upgrade && \
apt-get -y install curl gnupg2 && \
echo "deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch-4.0 main" >> /etc/apt/sources.list && \
echo "deb-src http://apt.llvm.org/stretch/ llvm-toolchain-stretch-4.0 main" >> /etc/apt/sources.list && \
curl http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
apt-get update && \
apt-get -y install build-essential \
clang-4.0 \
curl \
llvm-4.0-dev \
libcapstone3 \
libcapstone-dev \
libclang-4.0-dev \
pkg-config && \
apt-get clean

RUN curl https://sh.rustup.rs -sSf > /tmp/install.sh && \
chmod 755 /tmp/install.sh && \
/tmp/install.sh -y

SHELL ["/bin/bash", "-c"]

COPY . /falcon/
58 changes: 34 additions & 24 deletions lib/analysis/ai/kset.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
use analysis::ai::{domain, interpreter, memory};
use analysis::ai;
use analysis::ai::{domain, interpreter};
use analysis::fixed_point;
use error::*;
use executor::eval;
use il;
use std::collections::{BTreeMap, BTreeSet, HashMap};
use memory;
use std::collections::{HashMap, HashSet};
use std::fmt;
use types::Endian;


const MAX_CARDINALITY: usize = 4;


pub type KMemory = memory::Memory<KSet>;
pub type KState = domain::State<KMemory, KSet>;
pub type KMemory<'m> = ai::memory::Memory<'m, KSet>;
pub type KState<'m> = domain::State<KMemory<'m>, KSet>;


#[allow(dead_code)]
pub fn kset<'k>(function: &'k il::Function, endian: Endian, initial_memory: KMemory)
-> Result<BTreeMap<il::RefProgramLocation<'k>, KState>> {
pub fn kset<'k>(function: &'k il::Function, endian: Endian, initial_memory: KMemory<'k>)
-> Result<HashMap<il::RefProgramLocation<'k>, KState<'k>>> {

let domain = KSetDomain { endian: endian, memory: initial_memory };
let interpreter = interpreter::Interpreter {
m: ::std::marker::PhantomData,
Expand All @@ -28,10 +31,10 @@ pub fn kset<'k>(function: &'k il::Function, endian: Endian, initial_memory: KMem
}


#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum KSet {
Top(usize),
Value(BTreeSet<il::Constant>),
Value(HashSet<il::Constant>),
Bottom(usize)
}

Expand All @@ -48,7 +51,7 @@ impl KSet {
KSet::Top(bits) => KSet::Top(bits),
KSet::Bottom(bits) => KSet::Bottom(bits),
KSet::Value(ref rhs_value) => {
let mut b: BTreeSet<il::Constant> = BTreeSet::new();
let mut b: HashSet<il::Constant> = HashSet::new();
for l in lhs_value {
for r in rhs_value {
b.insert(op(l, r)?);
Expand Down Expand Up @@ -76,7 +79,7 @@ impl KSet {
KSet::Top(_) => KSet::Top(bits),
KSet::Bottom(_) => KSet::Bottom(bits),
KSet::Value(ref value) => {
let mut b: BTreeSet<il::Constant> = BTreeSet::new();
let mut b: HashSet<il::Constant> = HashSet::new();
for v in value {
b.insert(op(bits, v)?);
}
Expand Down Expand Up @@ -177,7 +180,7 @@ impl KSet {
}

pub fn constant(constant: il::Constant) -> KSet {
let mut b = BTreeSet::new();
let mut b = HashSet::new();
b.insert(constant);
KSet::Value(b)
}
Expand Down Expand Up @@ -220,7 +223,11 @@ impl Into<domain::Expression<KSet>> for KSet {
}


impl memory::MemoryValue for KSet {
impl memory::value::Value for KSet {
fn constant(constant: il::Constant) -> KSet {
KSet::constant(constant)
}

fn bits(&self) -> usize {
self.bits()
}
Expand Down Expand Up @@ -253,7 +260,10 @@ impl memory::MemoryValue for KSet {
other.clone().into()
))
}
}


impl ai::memory::Value for KSet {
fn join(&self, other: &KSet) -> Result<KSet> {
KSet::join(self, other)
}
Expand All @@ -279,7 +289,7 @@ impl domain::Value for KSet {
}


impl domain::Memory<KSet> for KMemory {
impl<'m> domain::Memory<KSet> for KMemory<'m> {
fn store(&mut self, index: &KSet, value: KSet) -> Result<()> {
if let KSet::Value(ref kindex) = *index {
for i in kindex {
Expand All @@ -302,40 +312,40 @@ impl domain::Memory<KSet> for KMemory {
}
}

fn new(endian: Endian) -> KMemory {
memory::Memory::<KSet>::new(endian)
fn new(endian: Endian) -> KMemory<'m> {
ai::memory::Memory::<KSet>::new(endian)
}

fn join(self, other: &KMemory) -> Result<KMemory> {
memory::Memory::<KSet>::join(self, other)
fn join(self, other: &KMemory) -> Result<KMemory<'m>> {
ai::memory::Memory::<KSet>::join(self, other)
}
}


struct KSetDomain {
struct KSetDomain<'m> {
endian: Endian,
memory: KMemory
memory: KMemory<'m>
}


impl domain::Domain<KMemory, KSet> for KSetDomain {
impl<'m> domain::Domain<KMemory<'m>, KSet> for KSetDomain<'m> {
fn eval(&self, expr: &domain::Expression<KSet>) -> Result<KSet> {
KSet::eval(expr)
}

fn brc(&self, _: &KSet, _: &KSet, state: KState) -> Result<KState> {
fn brc(&self, _: &KSet, _: &KSet, state: KState<'m>) -> Result<KState<'m>> {
Ok(state)
}

fn raise(&self, _: &KSet, state: KState) -> Result<KState> {
fn raise(&self, _: &KSet, state: KState<'m>) -> Result<KState<'m>> {
Ok(state)
}

fn endian(&self) -> Endian {
self.endian.clone()
}

fn new_state(&self) -> KState {
fn new_state(&self) -> KState<'m> {
KState {
variables: HashMap::new(),
memory: self.memory.clone()
Expand All @@ -359,7 +369,7 @@ impl fmt::Display for KSet {
}


impl Into<HashMap<il::Scalar, KSet>> for KState {
impl<'m> Into<HashMap<il::Scalar, KSet>> for KState<'m> {
fn into(self) -> HashMap<il::Scalar, KSet> {
self.variables
}
Expand Down
Loading

0 comments on commit e1deaa3

Please sign in to comment.