Skip to content

Commit

Permalink
Use yaxpeax for decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
novafacing committed Dec 20, 2023
1 parent 1f8f972 commit f0d9d27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions qemu-plugin/examples/tracer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ typed-builder = "0.18.0"
serde = { version = "1.0.193", features = ["derive"] }
memfd-exec = "0.2.1"
serde_json = "1.0.108"
yaxpeax-x86 = "1.2.2"
12 changes: 10 additions & 2 deletions qemu-plugin/examples/tracer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::{
sync::{Arc, Mutex},
};
use typed_builder::TypedBuilder;
use yaxpeax_x86::amd64::InstDecoder;

#[derive(TypedBuilder, Clone, Debug, Deserialize, Serialize)]
pub struct InstructionEvent {
Expand All @@ -28,12 +29,19 @@ impl TryFrom<&Instruction<'_>> for InstructionEvent {
type Error = Error;

fn try_from(value: &Instruction) -> Result<Self> {
let data = value.data();
let decoder = InstDecoder::default();
let disas = decoder
.decode_slice(&data)
.map(|d| d.to_string())
.or_else(|_| value.disas())?;

Ok(Self::builder()
.vaddr(value.vaddr())
.haddr(value.haddr())
.disas(value.disas()?)
.disas(disas)
.symbol(value.symbol()?)
.data(value.data())
.data(data)
.build())
}
}
Expand Down

0 comments on commit f0d9d27

Please sign in to comment.