Skip to content

Commit 793c028

Browse files
author
Anciety
committed
Merge branch 'master' of github.com:ret2lab/bincraft
2 parents 82d46b1 + 8afe9fe commit 793c028

File tree

5 files changed

+60
-63
lines changed

5 files changed

+60
-63
lines changed

sleighcraft/build.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::env;
1818
use std::fs;
1919
use std::path::{Path, PathBuf};
2020

21-
const DECOMPILER_SOURCE_BASE_CXX: &[&'static str] = &[
21+
const DECOMPILER_SOURCE_BASE_CXX: &[&str] = &[
2222
"space.cc",
2323
"float.cc",
2424
"address.cc",
@@ -114,9 +114,9 @@ const SLEIGH_COMPILER_SOURCE_FLEX: [&'static str; 1] = [
114114
];
115115
*/
116116

117-
const DECOMPILER_SOURCE_SLEIGH_YACC: &[&'static str] = &["pcodeparse.y", "grammar.y", "xml.y"];
117+
const DECOMPILER_SOURCE_SLEIGH_YACC: &[&str] = &["pcodeparse.y", "grammar.y", "xml.y"];
118118

119-
const PROXIES: &[&'static str] = &[
119+
const PROXIES: &[&str] = &[
120120
"address_proxy.cc",
121121
"addrspace_proxy.cc",
122122
"cover_proxy.cc",
@@ -141,27 +141,23 @@ fn need_recompile(source: &Path) -> bool {
141141
let outdir = env::var("OUT_DIR").unwrap();
142142

143143
let path = Path::new(&outdir).join(source);
144-
let mut path = PathBuf::from(path);
144+
let mut path = path;
145145
path.set_extension("o");
146146
let metadata = match fs::metadata(path) {
147147
Ok(m) => m,
148148
Err(_) => return true,
149149
};
150150
let object_mtime = FileTime::from_last_modification_time(&metadata);
151151

152-
let metadata = fs::metadata(source).expect(&format!("source code {:?} not found", source));
152+
let metadata = fs::metadata(source).unwrap_or_else(|_| panic!("source code {:?} not found", source));
153153
let source_mtime = FileTime::from_last_modification_time(&metadata);
154154

155-
if source_mtime > object_mtime {
156-
true
157-
} else {
158-
false
159-
}
155+
source_mtime > object_mtime
160156
}
161157

162158
fn obj_path_from_src_path(src_path: &Path) -> PathBuf {
163159
let outdir = env::var("OUT_DIR").unwrap();
164-
let mut path = PathBuf::from(Path::new(&outdir).join(src_path));
160+
let mut path = Path::new(&outdir).join(src_path);
165161
path.set_extension("o");
166162
path
167163
}
@@ -180,7 +176,7 @@ fn prepare() -> CompileOptions {
180176
}
181177

182178
for src in DECOMPILER_SOURCE_SLEIGH_YACC.iter() {
183-
let name = src.split(".").next().unwrap();
179+
let name = src.split('.').next().unwrap();
184180
let path = Path::new("src")
185181
.join("cpp")
186182
.join("gen")
@@ -207,7 +203,7 @@ fn prepare() -> CompileOptions {
207203
}
208204
}
209205

210-
CompileOptions { objects, sources }
206+
CompileOptions { sources, objects }
211207
}
212208

213209
fn main() {
@@ -216,7 +212,7 @@ fn main() {
216212

217213
let mut target = cxx_build::bridge(sleigh_src_file);
218214

219-
for obj in compile_opts.objects.iter() {
215+
for obj in &compile_opts.objects {
220216
target.object(obj);
221217
}
222218
let disasm_src_path= Path::new("src").join("cpp").join("bridge").join("disasm.cpp");

sleighcraft/src/sleigh.rs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -932,52 +932,3 @@ pub fn arch(name: &str) -> Result<&str> {
932932
.ok_or(Error::ArchNotFound(name.to_string()))?;
933933
Ok(content)
934934
}
935-
936-
// #[test]
937-
// fn test_custom_spec() {
938-
// // let compiled = include_str!("../test/test.sla");
939-
// // let mut sleigh = Sleigh::from_spec(compiled).unwrap();
940-
// // let buf = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6];
941-
// // sleigh.decode(0, &buf, 1);
942-
// // println!("{:?}", sleigh.pcode_emit)
943-
// }
944-
945-
#[test]
946-
fn test_x86() {
947-
let mut sleigh_builder = SleighBuilder::default();
948-
let spec = arch("x86").unwrap();
949-
let buf = [0x90, 0x32, 0x31];
950-
let mut loader = PlainLoadImage::from_buf(&buf, 0);
951-
sleigh_builder.loader(&mut loader);
952-
sleigh_builder.spec(spec);
953-
let mut asm_emit = CollectingAssemblyEmit::default();
954-
let mut pcode_emit = CollectingPcodeEmit::default();
955-
sleigh_builder.asm_emit(&mut asm_emit);
956-
sleigh_builder.pcode_emit(&mut pcode_emit);
957-
let mut sleigh = sleigh_builder.try_build().unwrap();
958-
959-
sleigh.decode(0).unwrap();
960-
961-
println!("{:?}", asm_emit.asms);
962-
println!("{:?}", pcode_emit.pcode_asms);
963-
}
964-
965-
#[test]
966-
fn test_x86_case_ignoring() {
967-
let mut sleigh_builder = SleighBuilder::default();
968-
let spec = arch("x86").unwrap();
969-
let buf = [0x90, 0x32, 0x31];
970-
let mut loader = PlainLoadImage::from_buf(&buf, 0);
971-
sleigh_builder.loader(&mut loader);
972-
sleigh_builder.spec(spec);
973-
let mut asm_emit = CollectingAssemblyEmit::default();
974-
let mut pcode_emit = CollectingPcodeEmit::default();
975-
sleigh_builder.asm_emit(&mut asm_emit);
976-
sleigh_builder.pcode_emit(&mut pcode_emit);
977-
let mut sleigh = sleigh_builder.try_build().unwrap();
978-
979-
sleigh.decode(0).unwrap();
980-
981-
println!("{:?}", asm_emit.asms);
982-
println!("{:?}", pcode_emit.pcode_asms);
983-
}

sleighcraft/tests/mod.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use sleighcraft::prelude::*;
2+
3+
// #[test]
4+
// fn test_custom_spec() {
5+
// // let compiled = include_str!("../test/test.sla");
6+
// // let mut sleigh = Sleigh::from_spec(compiled).unwrap();
7+
// // let buf = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6];
8+
// // sleigh.decode(0, &buf, 1);
9+
// // println!("{:?}", sleigh.pcode_emit)
10+
// }
11+
12+
#[test]
13+
fn test_x86() {
14+
let mut sleigh_builder = SleighBuilder::default();
15+
let spec = arch("x86").unwrap();
16+
let buf = [0x90, 0x32, 0x31];
17+
let mut loader = PlainLoadImage::from_buf(&buf, 0);
18+
sleigh_builder.loader(&mut loader);
19+
sleigh_builder.spec(spec);
20+
let mut asm_emit = CollectingAssemblyEmit::default();
21+
let mut pcode_emit = CollectingPcodeEmit::default();
22+
sleigh_builder.asm_emit(&mut asm_emit);
23+
sleigh_builder.pcode_emit(&mut pcode_emit);
24+
let mut sleigh = sleigh_builder.try_build().unwrap();
25+
26+
sleigh.decode(0).unwrap();
27+
28+
println!("{:?}", asm_emit.asms);
29+
println!("{:?}", pcode_emit.pcode_asms);
30+
}
31+
32+
#[test]
33+
fn test_x86_case_ignoring() {
34+
let mut sleigh_builder = SleighBuilder::default();
35+
let spec = arch("x86").unwrap();
36+
let buf = [0x90, 0x32, 0x31];
37+
let mut loader = PlainLoadImage::from_buf(&buf, 0);
38+
sleigh_builder.loader(&mut loader);
39+
sleigh_builder.spec(spec);
40+
let mut asm_emit = CollectingAssemblyEmit::default();
41+
let mut pcode_emit = CollectingPcodeEmit::default();
42+
sleigh_builder.asm_emit(&mut asm_emit);
43+
sleigh_builder.pcode_emit(&mut pcode_emit);
44+
let mut sleigh = sleigh_builder.try_build().unwrap();
45+
46+
sleigh.decode(0).unwrap();
47+
48+
println!("{:?}", asm_emit.asms);
49+
println!("{:?}", pcode_emit.pcode_asms);
50+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)