Skip to content

Commit

Permalink
add sleigh-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed May 31, 2024
1 parent 9833385 commit a6e494c
Show file tree
Hide file tree
Showing 83 changed files with 17,496 additions and 33 deletions.
116 changes: 115 additions & 1 deletion Cargo.lock

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

5 changes: 5 additions & 0 deletions il-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ dashmap = "5.5.3"
hex = "0.4.3"
itertools = "0.13.0"
rayon = "1.10.0"
sleigh-rs = "0.1.5"

[dependencies.rizin-rs]
path = ".."

[build-dependencies]
anyhow = "1.0.86"
sleigh2rust = "0.1.6"
24 changes: 24 additions & 0 deletions il-tests/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::env;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::PathBuf;

use anyhow::anyhow;
use sleigh2rust::generate_disassembler;

fn main() {
let p = PathBuf::from(format!(
"ghidra/Ghidra/Processors/{}/data/languages/{}.slaspec",
"tricore", "tricore"
));
let p = p
.canonicalize()
.map_err(|e| anyhow!("{} {:?} {:?}", e, env::current_dir(), &p))
.unwrap();
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let x = generate_disassembler(&p).unwrap();
let f = File::create(out_dir.join("tricore.rs")).unwrap();
let mut w = BufWriter::new(f);
rust
w.write(x.to_string().as_bytes()).unwrap();
}
3 changes: 3 additions & 0 deletions il-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod gen {
include!(concat!(env!("OUT_DIR"), "/tricore.rs"));
}
67 changes: 35 additions & 32 deletions il-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use clap::Parser;
use dashmap::DashMap;
use hex::ToHex;
use itertools::Itertools;
use il_tests::gen;

use rizin_rs::wrapper::{AnalysisOp, Core};

Expand Down Expand Up @@ -74,38 +75,40 @@ fn main() -> Result<(), Box<dyn Error>> {
core
};

let _ = (0..max)
.flat_map(|x| {
let b = x.to_le_bytes();
ADDRS
.iter()
.filter_map(|addr| {
let inst = { Instruction::from_bytes(&core, &b, addr.clone()) };
if inst.is_err() {
return None;
}
let inst = inst.unwrap();
let entry = map.get_mut(&inst.mnemonic);
match entry {
Some(x) if *x > INST_LIMIT => return None,
_ => {}
}

match entry {
None => {
map.insert(inst.mnemonic.clone(), 1);
}
Some(mut k) => {
*k += 1;
}
};
Some(inst)
})
.collect::<Vec<_>>()
})
.sorted_by_key(|x| x.mnemonic.clone())
.for_each(|x| {
let _ = x.try_to_string().map(|str| println!("{}", str));
});

// let _ = (0..max)
// .flat_map(|x| {
// let b = x.to_le_bytes();
// ADDRS
// .iter()
// .filter_map(|addr| {
// let inst = { Instruction::from_bytes(&core, &b, addr.clone()) };
// if inst.is_err() {
// return None;
// }
// let inst = inst.unwrap();
// let entry = map.get_mut(&inst.mnemonic);
// match entry {
// Some(x) if *x > INST_LIMIT => return None,
// _ => {}
// }
//
// match entry {
// None => {
// map.insert(inst.mnemonic.clone(), 1);
// }
// Some(mut k) => {
// *k += 1;
// }
// };
// Some(inst)
// })
// .collect::<Vec<_>>()
// })
// .sorted_by_key(|x| x.mnemonic.clone())
// .for_each(|x| {
// let _ = x.try_to_string().map(|str| println!("{}", str));
// });
Ok(())
}
1 change: 1 addition & 0 deletions sleigh-rs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
1 change: 1 addition & 0 deletions sleigh-rs/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 80
Loading

0 comments on commit a6e494c

Please sign in to comment.