Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] replace 'ir with owning pointers #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 32 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion isla-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ lalrpop-util = "0.19.0"
crossbeam = "0.7.3"
lazy_static = "1.4.0"
toml = "0.5.5"
z3-sys = "0.5.0"
z3-sys = { path = "C:\\Users\\Benni\\repositories\\z3.rs\\z3-sys" }
libc = "0.2.5"
serde = "1.0.104"
bincode = "1.2.1"
sha2 = "0.8.1"
petgraph = "0.5.0"
elfloader = { path = "C:\\Users\\Benni\\repositories\\rust-elfloader" }

[[bin]]
name = "test"
path = "src/test.rs"
63 changes: 63 additions & 0 deletions isla-lib/src/elf_loader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use std::collections::HashMap;
use std::fs;

use crate::memory::Memory;
use crate::concrete::BV;

use elfloader::*;

/// A simple ExampleLoader, that implements ElfLoader
/// but does nothing but logging
struct ExampleLoader<'ir, B: BV> {
memory: &'ir mut Memory<B>
}

impl<'ir, B: BV> ElfLoader for ExampleLoader<'ir, B> {
fn allocate(&mut self, load_headers: LoadableHeaders) -> Result<(), &'static str> {
for header in load_headers {
let base = header.virtual_addr();
let end = base + header.mem_size();
self.memory.add_concrete_region(base..end, HashMap::new());
println!(
"allocate base = {:#x} size = {:#x} flags = {}",
header.virtual_addr(),
header.mem_size(),
header.flags()
);
}
Ok(())
}

fn relocate(&mut self, _entry: &Rela<P64>) -> Result<(), &'static str> {
unimplemented!()
}

fn load(&mut self, _flags: Flags, base: VAddr, region: &[u8]) -> Result<(), &'static str> {
let start = base;
let end = base + region.len() as u64;
let mut i = 0;
for b in region {
self.memory.write_byte(start + i, *b);
i += 1;
}
println!("load region into = {:#x} -- {:#x}", start, end);
Ok(())
}

fn tls(
&mut self,
_tdata_start: VAddr,
_tdata_length: u64,
_total_size: u64,
_align: u64
) -> Result<(), &'static str> {
unimplemented!()
}
}

pub fn load_elf<'ir, B: BV>(path: &str, memory: &'ir mut Memory<B>) {
let binary_blob = fs::read(path).expect("Can't read binary");
let binary = ElfBinary::new("test", binary_blob.as_slice()).expect("Got proper ELF file");
let mut loader = ExampleLoader { memory: memory };
binary.load(&mut loader).expect("Can't load the binary?");
}
12 changes: 12 additions & 0 deletions isla-lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

use std::error::Error;
use std::fmt;
use crate::executor::Backtrace;
use crate::ir::SharedState;

#[derive(Debug)]
pub enum ExecError {
Expand Down Expand Up @@ -75,3 +77,13 @@ impl Error for ExecError {
None
}
}

impl ExecError {
pub fn to_string<'ir, B>(&self, bt: &Backtrace, shared_state: &SharedState<B>) -> String {
let mut stacktrace = format!("{}:\n", &self);
for (name, num) in bt {
stacktrace.push_str(&format!(" {} ({})\n", &shared_state.symtab.to_str(*name), num));
}
stacktrace
}
}
Loading