aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2019-05-29 00:07:31 -0700
committeriximeow <me@iximeow.net>2020-01-12 16:10:13 -0800
commitaa79e826869a7fed8df6b4f7e7a7503565659f89 (patch)
tree8af668e7706ac22477cf7df67ba5cb47eaf607b3
parent09df8f120f23d733df2171b4b3e2380b6889cf3c (diff)
fix some warnings and rdtsc/swapgs decode errors
-rw-r--r--src/display.rs20
-rw-r--r--src/lib.rs15
-rw-r--r--test/test.rs5
3 files changed, 15 insertions, 25 deletions
diff --git a/src/display.rs b/src/display.rs
index 76db507..dfddeca 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -1,13 +1,9 @@
extern crate yaxpeax_arch;
extern crate termion;
-use termion::color;
-
use std::fmt;
-use std::hint::unreachable_unchecked;
-
-use yaxpeax_arch::{Arch, Colorize, ColorSettings, Decodable, LengthedInstruction, ShowContextual, YaxColors};
+use yaxpeax_arch::{Colorize, ColorSettings, ShowContextual, YaxColors};
use yaxpeax_arch::display::*;
use ::{RegSpec, RegisterBank, Opcode, Operand, Instruction, Segment};
@@ -545,7 +541,7 @@ impl <T: std::fmt::Write> Colorize<T> for Instruction {
}
impl <T: std::fmt::Write> ShowContextual<u64, [Option<String>], T> for Instruction {
- fn contextualize(&self, colors: Option<&ColorSettings>, address: u64, context: Option<&[Option<String>]>, out: &mut T) -> std::fmt::Result {
+ fn contextualize(&self, colors: Option<&ColorSettings>, _address: u64, context: Option<&[Option<String>]>, out: &mut T) -> std::fmt::Result {
if self.prefixes.lock {
write!(out, "lock ")?;
}
@@ -561,7 +557,7 @@ impl <T: std::fmt::Write> ShowContextual<u64, [Option<String>], T> for Instructi
ref x @ _ => {
write!(out, " ")?;
if let Some(prefix) = self.segment_override_for_op(0) {
- write!(out, "{}:", prefix);
+ write!(out, "{}:", prefix)?;
}
x.colorize(colors, out)?;
}
@@ -580,14 +576,14 @@ impl <T: std::fmt::Write> ShowContextual<u64, [Option<String>], T> for Instructi
x @ &Operand::Register(_) => {
write!(out, ", ")?;
if let Some(prefix) = self.segment_override_for_op(1) {
- write!(out, "{}:", prefix);
+ write!(out, "{}:", prefix)?;
}
x.colorize(colors, out)
}
x @ _ => {
write!(out, ", byte ")?;
if let Some(prefix) = self.segment_override_for_op(1) {
- write!(out, "{}:", prefix);
+ write!(out, "{}:", prefix)?;
}
x.colorize(colors, out)
}
@@ -606,14 +602,14 @@ impl <T: std::fmt::Write> ShowContextual<u64, [Option<String>], T> for Instructi
x @ &Operand::Register(_) => {
write!(out, ", ")?;
if let Some(prefix) = self.segment_override_for_op(1) {
- write!(out, "{}:", prefix);
+ write!(out, "{}:", prefix)?;
}
x.colorize(colors, out)
}
x @ _ => {
write!(out, ", word ")?;
if let Some(prefix) = self.segment_override_for_op(1) {
- write!(out, "{}:", prefix);
+ write!(out, "{}:", prefix)?;
}
x.colorize(colors, out)
}
@@ -632,7 +628,7 @@ impl <T: std::fmt::Write> ShowContextual<u64, [Option<String>], T> for Instructi
x @ _ => {
write!(out, ", ")?;
if let Some(prefix) = self.segment_override_for_op(1) {
- write!(out, "{}:", prefix);
+ write!(out, "{}:", prefix)?;
}
x.colorize(colors, out)
}
diff --git a/src/lib.rs b/src/lib.rs
index bc60dfd..ab67362 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -10,13 +10,9 @@ extern crate termion;
mod display;
-use termion::color;
-
-use std::fmt;
-
use std::hint::unreachable_unchecked;
-use yaxpeax_arch::{Arch, ColorSettings, Decodable, LengthedInstruction};
+use yaxpeax_arch::{Arch, Decodable, LengthedInstruction};
#[cfg(feature="use-serde")]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
@@ -212,6 +208,7 @@ pub enum RegisterBank {
X, Y, Z, // XMM, YMM, ZMM
ST, MM, // ST, MM regs (x87, mmx)
}
+#[allow(non_camel_case_types)]
#[cfg(not(feature="use-serde"))]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum RegisterBank {
@@ -2586,11 +2583,11 @@ fn read_operands<T: Iterator<Item=u8>>(
} else if r == 7 {
if mod_bits == 0b11 {
if m == 1 {
- instruction.opcode == Opcode::SWAPGS;
+ instruction.opcode = Opcode::SWAPGS;
instruction.operands = [Operand::Nothing, Operand::Nothing];
Ok(())
} else if m == 2 {
- instruction.opcode == Opcode::RDTSCP;
+ instruction.opcode = Opcode::RDTSCP;
instruction.operands = [Operand::Nothing, Operand::Nothing];
Ok(())
} else {
@@ -2697,7 +2694,6 @@ fn read_operands<T: Iterator<Item=u8>>(
}
}
OperandCode::Rq_Cq_0 => {
- let opwidth = 8;
let modrm = match bytes_iter.next() {
Some(b) => b,
None => return Err("Out of bytes".to_string())
@@ -2717,7 +2713,6 @@ fn read_operands<T: Iterator<Item=u8>>(
Ok(())
}
OperandCode::Rq_Dq_0 => {
- let opwidth = 8;
let modrm = match bytes_iter.next() {
Some(b) => b,
None => return Err("Out of bytes".to_string())
@@ -2736,7 +2731,6 @@ fn read_operands<T: Iterator<Item=u8>>(
Ok(())
}
OperandCode::Cq_Rq_0 => {
- let opwidth = 8;
let modrm = match bytes_iter.next() {
Some(b) => b,
None => return Err("Out of bytes".to_string())
@@ -2756,7 +2750,6 @@ fn read_operands<T: Iterator<Item=u8>>(
Ok(())
}
OperandCode::Dq_Rq_0 => {
- let opwidth = 8;
let modrm = match bytes_iter.next() {
Some(b) => b,
None => return Err("Out of bytes".to_string())
diff --git a/test/test.rs b/test/test.rs
index f8dadbb..ebfda5a 100644
--- a/test/test.rs
+++ b/test/test.rs
@@ -4,7 +4,7 @@ extern crate yaxpeax_x86;
use std::fmt::Write;
use yaxpeax_arch::Decodable;
-use yaxpeax_x86::{Instruction, Opcode, decode_one};
+use yaxpeax_x86::{Instruction, decode_one};
fn decode(bytes: &[u8]) -> Option<Instruction> {
let mut instr = Instruction::invalid();
@@ -17,7 +17,7 @@ fn decode(bytes: &[u8]) -> Option<Instruction> {
fn test_display(data: &[u8], expected: &'static str) {
let mut hex = String::new();
for b in data {
- write!(hex, "{:02x}", b);
+ write!(hex, "{:02x}", b).unwrap();
}
match Instruction::decode(data.into_iter().map(|x| *x)) {
Some(instr) => {
@@ -60,6 +60,7 @@ fn test_arithmetic() {
}
#[test]
+#[allow(non_snake_case)]
fn test_E_decode() {
test_display(&[0xff, 0x75, 0xb8], "push [rbp - 0x48]");
test_display(&[0xff, 0x75, 0x08], "push [rbp + 0x8]");