forked from athre0z/disas-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
bench-iced-fmt | ||
bench-iced-no-fmt | ||
Cargo.lock | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "iced-bench" | ||
version = "0.0.0" | ||
authors = ["iximeow <me@iximeow.net>"] | ||
description = "benchmarking wrapper for iced-x86, for use in disas-bench" | ||
edition = "2018" | ||
|
||
[[bin]] | ||
name = "iced-bench" | ||
path = "src/main.rs" | ||
|
||
[profile.release] | ||
opt-level = 3 | ||
lto = true | ||
|
||
[dependencies] | ||
iced-x86 = "1.8.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
make-bench-iced-x86: | ||
cargo build --release | ||
cp target/release/iced-bench bench-iced-fmt | ||
RUSTFLAGS="--cfg DISAS_BENCH_NO_FORMAT" cargo build --release | ||
cp target/release/iced-bench bench-iced-no-fmt | ||
|
||
clean: | ||
cargo clean | ||
rm bench-iced-fmt | ||
rm bench-iced-no-fmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use std::fs::File; | ||
use std::io::Read; | ||
use std::io::Seek; | ||
use std::io::SeekFrom; | ||
|
||
use iced_x86::{Decoder, DecoderError, DecoderOptions, Instruction}; | ||
|
||
#[cfg(not(DISAS_BENCH_NO_FORMAT))] | ||
use iced_x86::{Formatter, NasmFormatter}; | ||
|
||
// translated from `load_bin.inc` | ||
|
||
const XUL_TEXT_OFFS: u64 = 0x400; | ||
const XUL_TEXT_LEN: usize = 0x2460400; | ||
|
||
fn read_xul_dll() -> std::io::Result<Box<[u8]>> { | ||
let mut f = File::open("../../input/xul.dll")?; | ||
f.seek(SeekFrom::Start(XUL_TEXT_OFFS))?; | ||
let mut code = vec![0; XUL_TEXT_LEN]; | ||
f.read_exact(&mut code)?; | ||
Ok(code.into_boxed_slice()) | ||
} | ||
|
||
pub fn main() { | ||
let xul_code = match read_xul_dll() { | ||
Ok(code) => code, | ||
Err(_) => { | ||
eprintln!("Can't read xul.dll"); | ||
return; | ||
} | ||
}; | ||
|
||
let mut decoder = Decoder::new( | ||
64, // 64-bit | ||
&xul_code, | ||
DecoderOptions::NONE | ||
); | ||
|
||
#[cfg(not(DISAS_BENCH_NO_FORMAT))] | ||
let mut text = String::new(); | ||
#[cfg(not(DISAS_BENCH_NO_FORMAT))] | ||
let mut formatter = NasmFormatter::new(); | ||
|
||
let mut instruction = Instruction::default(); | ||
|
||
let mut num_valid_insns: usize = 0; | ||
let mut num_bad_insns: usize = 0; | ||
for _round in 0..20 { | ||
decoder.set_position(0); | ||
while decoder.can_decode() { | ||
let offset = decoder.position(); | ||
decoder.decode_out(&mut instruction); | ||
|
||
if decoder.last_error() == DecoderError::None { | ||
#[cfg(not(DISAS_BENCH_NO_FORMAT))] | ||
{ | ||
text.clear(); | ||
formatter.format(&instruction, &mut text); | ||
} | ||
|
||
num_valid_insns += 1; | ||
// position is automatically updated in the happy path | ||
} else { | ||
num_bad_insns += 1; | ||
// manually seek forward one byte to try again | ||
decoder.set_position(offset + 1); | ||
} | ||
} | ||
} | ||
|
||
println!("Disassembled {} instructions ({} valid, {} bad)", | ||
num_valid_insns + num_bad_insns, | ||
num_valid_insns, | ||
num_bad_insns, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters