Skip to content

Commit 921d90d

Browse files
reformat.
1 parent b727e78 commit 921d90d

File tree

19 files changed

+149
-154
lines changed

19 files changed

+149
-154
lines changed

mythril/src/acpi/madt.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ impl IcsType {
8181
if length == self.expected_len() as usize - 2 {
8282
Ok(())
8383
} else {
84-
error!("Invalid length={} for type=0x{:x}",
85-
*self as u8, length);
84+
error!("Invalid length={} for type=0x{:x}", *self as u8, length);
8685
Err(Error::InvalidValue)
8786
}
8887
}
@@ -255,16 +254,18 @@ impl Ics {
255254
apic_proc_uid: NativeEndian::read_u32(&bytes[10..14]),
256255
}),
257256
_ => {
258-
error!("type=0x{:x} length={} not implemented",
259-
ty as u8,
260-
bytes.len());
257+
error!(
258+
"type=0x{:x} length={} not implemented",
259+
ty as u8,
260+
bytes.len()
261+
);
261262
Err(Error::NotImplemented)
262263
}
263264
}
264265
}
265266

266267
/// Encode into the byte sequence
267-
pub fn encode<T: Array<Item=u8>>(
268+
pub fn encode<T: Array<Item = u8>>(
268269
&self,
269270
buffer: &mut ArrayVec<T>,
270271
) -> Result<()> {
@@ -295,8 +296,10 @@ impl Ics {
295296
NativeEndian::write_u32(&mut tmp_buf[8..12], gsi_base);
296297
}
297298
_ => {
298-
error!("The ICS Type {:?} has not been implemented",
299-
self.ics_type());
299+
error!(
300+
"The ICS Type {:?} has not been implemented",
301+
self.ics_type()
302+
);
300303
return Err(Error::NotImplemented);
301304
}
302305
}
@@ -393,22 +396,22 @@ impl<'a> Iterator for IcsIterator<'a> {
393396
let ty = match IcsType::try_from(self.bytes[0]) {
394397
Ok(ty) => ty,
395398
_ => {
396-
error!("Invalid ICS type: {}",
397-
self.bytes[0]);
399+
error!("Invalid ICS type: {}", self.bytes[0]);
398400
return Some(Err(Error::InvalidValue));
399401
}
400402
};
401403
let len = self.bytes[1] as usize;
402404

403405
if len > self.bytes.len() {
404-
error!("Payload for type=0x{:x} and len={} to big for buffer len={}",
405-
ty as u8,
406-
len,
407-
self.bytes.len());
406+
error!(
407+
"Payload for type=0x{:x} and len={} to big for buffer len={}",
408+
ty as u8,
409+
len,
410+
self.bytes.len()
411+
);
408412
return Some(Err(Error::InvalidValue));
409413
} else if len < 3 {
410-
error!("length `{}` provided is too small",
411-
len);
414+
error!("length `{}` provided is too small", len);
412415
return Some(Err(Error::InvalidValue));
413416
}
414417

@@ -434,7 +437,7 @@ pub struct MADTBuilder<T: Array> {
434437
structures: ArrayVec<T>,
435438
}
436439

437-
impl<T: Array<Item=Ics>> MADTBuilder<T> {
440+
impl<T: Array<Item = Ics>> MADTBuilder<T> {
438441
/// Create a new builder for the MADT SDT.
439442
pub fn new() -> MADTBuilder<T> {
440443
MADTBuilder {
@@ -462,8 +465,8 @@ impl<T: Array<Item=Ics>> MADTBuilder<T> {
462465
}
463466

464467
impl<U> SDTBuilder for MADTBuilder<U>
465-
where
466-
U: Array<Item=Ics>,
468+
where
469+
U: Array<Item = Ics>,
467470
{
468471
const SIGNATURE: [u8; 4] = [b'A', b'P', b'I', b'C'];
469472

@@ -472,7 +475,7 @@ impl<U> SDTBuilder for MADTBuilder<U>
472475
5u8
473476
}
474477

475-
fn encode_table<T: Array<Item=u8>>(
478+
fn encode_table<T: Array<Item = u8>>(
476479
&mut self,
477480
buffer: &mut ArrayVec<T>,
478481
) -> Result<()> {

mythril/src/acpi/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ pub(self) fn verify_checksum(bytes: &[u8], cksum_idx: usize) -> Result<()> {
4848
if (result & 0xff) == 0x00 {
4949
Ok(())
5050
} else {
51-
error!("Checksum mismatch checksum={:x} {:x} != 0x00", bytes[cksum_idx], result & 0xff);
51+
error!(
52+
"Checksum mismatch checksum={:x} {:x} != 0x00",
53+
bytes[cksum_idx],
54+
result & 0xff
55+
);
5256
Err(Error::InvalidValue)
5357
}
5458
}

mythril/src/acpi/rsdp.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,8 @@ impl RSDP {
117117
xsdt_addr: NativeEndian::read_u64(&bytes[offsets::XSDT_ADDR]),
118118
},
119119
_ => {
120-
error!("Invalid RSDP revision: {}",
121-
bytes[offsets::REVISION]);
122-
return Err(Error::InvalidValue)
123-
.into();
120+
error!("Invalid RSDP revision: {}", bytes[offsets::REVISION]);
121+
return Err(Error::InvalidValue).into();
124122
}
125123
};
126124

@@ -179,9 +177,11 @@ impl RSDP {
179177
Ok(&range[i..rsdp_v2_end])
180178
}
181179
_ => {
182-
error!("Invalid RSDP revision: {} at {:p}",
183-
candidate[offsets::REVISION],
184-
candidate.as_ptr());
180+
error!(
181+
"Invalid RSDP revision: {} at {:p}",
182+
candidate[offsets::REVISION],
183+
candidate.as_ptr()
184+
);
185185
Err(Error::InvalidValue)
186186
}
187187
};
@@ -205,8 +205,7 @@ impl RSDP {
205205
offsets::EXT_CHECKSUM,
206206
),
207207
_ => {
208-
error!("Invalid RSDP revision: {}",
209-
bytes[offsets::REVISION]);
208+
error!("Invalid RSDP revision: {}", bytes[offsets::REVISION]);
210209
Err(Error::InvalidValue)
211210
}
212211
}
@@ -222,11 +221,11 @@ impl RSDP {
222221
}
223222

224223
/// Builder structure for the RSDP
225-
pub struct RSDPBuilder<'a, T: Array<Item=u8>> {
224+
pub struct RSDPBuilder<'a, T: Array<Item = u8>> {
226225
builder: RSDTBuilder<'a, T>,
227226
}
228227

229-
impl<'a, T: Array<Item=u8>> RSDPBuilder<'a, T> {
228+
impl<'a, T: Array<Item = u8>> RSDPBuilder<'a, T> {
230229
/// Create a new RSDP Builder.
231230
pub fn new(
232231
map: ManagedMap<'a, [u8; 4], (ArrayVec<T>, usize)>,

mythril/src/acpi/rsdt.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,11 @@ fn write_sdt_header(
246246
// The SDT length value is the value of the entire SDT including
247247
// the header.
248248
if buffer.len() < sdt_len {
249-
error!("Buffer length should be at least `{}` but was `{}`",
250-
sdt_len,
251-
buffer.len());
249+
error!(
250+
"Buffer length should be at least `{}` but was `{}`",
251+
sdt_len,
252+
buffer.len()
253+
);
252254
return Err(Error::InvalidValue);
253255
}
254256
// Fill in the SDT header with the implementations values
@@ -338,8 +340,10 @@ impl<'a, T: Array<Item = u8>> RSDTBuilder<'a, T> {
338340
Ok(())
339341
}
340342
} else {
341-
error!("The key `{}` already exists",
342-
str::from_utf8(&U::SIGNATURE).unwrap());
343+
error!(
344+
"The key `{}` already exists",
345+
str::from_utf8(&U::SIGNATURE).unwrap()
346+
);
343347
Err(Error::InvalidValue)
344348
}
345349
}
@@ -371,10 +375,11 @@ impl<'a, T: Array<Item = u8>> RSDTBuilder<'a, T> {
371375
})?;
372376

373377
for (i, (name, (sdt, size))) in self.map.iter().enumerate() {
374-
const LEN_OF_ETC_MYTHRIL :usize = 12;
378+
const LEN_OF_ETC_MYTHRIL: usize = 12;
375379
const LEN_OF_NAME: usize = 4;
376-
let mut table_name_bytes = [0u8;LEN_OF_ETC_MYTHRIL + LEN_OF_NAME];
377-
table_name_bytes[0..LEN_OF_ETC_MYTHRIL].copy_from_slice("etc/mythril/".as_bytes());
380+
let mut table_name_bytes = [0u8; LEN_OF_ETC_MYTHRIL + LEN_OF_NAME];
381+
table_name_bytes[0..LEN_OF_ETC_MYTHRIL]
382+
.copy_from_slice("etc/mythril/".as_bytes());
378383
table_name_bytes[LEN_OF_ETC_MYTHRIL..].copy_from_slice(name);
379384
let table_name = str::from_utf8(&table_name_bytes)?;
380385

mythril/src/emulate/controlreg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn emulate_access(
6161
},
6262
_ => {
6363
error!("Unsupported CR number access");
64-
return Err(Error::InvalidValue)
64+
return Err(Error::InvalidValue);
6565
}
6666
}
6767
Ok(())

mythril/src/emulate/memio.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn read_register_value(
145145

146146
_ => {
147147
error!("Invalid register '{:?}'", register);
148-
return Err(Error::InvalidValue)
148+
return Err(Error::InvalidValue);
149149
}
150150
}
151151

@@ -351,9 +351,8 @@ fn do_mmio_read(
351351
}
352352

353353
register => {
354-
error!("mmio read into invalid register '{:?}'",
355-
register);
356-
return Err(Error::InvalidValue)
354+
error!("mmio read into invalid register '{:?}'", register);
355+
return Err(Error::InvalidValue);
357356
}
358357
},
359358
_ => return Err(Error::NotSupported),
@@ -431,10 +430,12 @@ fn process_memio_op(
431430
{
432431
do_mmio_read(addr, vcpu, guest_cpu, responses, instr, on_read)?;
433432
} else {
434-
error!("Unsupported mmio instruction: {:?} (rip=0x{:x}, bytes={:?})",
435-
instr.code(),
436-
ip,
437-
bytes);
433+
error!(
434+
"Unsupported mmio instruction: {:?} (rip=0x{:x}, bytes={:?})",
435+
instr.code(),
436+
ip,
437+
bytes
438+
);
438439
return Err(Error::InvalidValue);
439440
}
440441
Ok(())

mythril/src/error.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn check_vm_instruction(rflags: u64, error: &str) -> Result<()> {
4848
let rflags = rflags::RFlags::from_bits_truncate(rflags);
4949

5050
if rflags.contains(RFlags::FLAGS_CF) {
51-
error!("{}",error);
51+
error!("{}", error);
5252
Err(Error::VmFailInvalid)
5353
} else if rflags.contains(RFlags::FLAGS_ZF) {
5454
let errno = unsafe {
@@ -63,8 +63,8 @@ pub fn check_vm_instruction(rflags: u64, error: &str) -> Result<()> {
6363
let vm_error = VmInstructionError::try_from(errno)
6464
.unwrap_or(VmInstructionError::UnknownError);
6565

66-
error!("{:?}",vm_error);
67-
error!("{}",error);
66+
error!("{:?}", vm_error);
67+
error!("{}", error);
6868
Err(Error::VmFailValid)
6969
} else {
7070
Ok(())
@@ -88,21 +88,21 @@ pub enum Error {
8888

8989
impl<T: TryFromPrimitive> From<TryFromPrimitiveError<T>> for Error {
9090
fn from(error: TryFromPrimitiveError<T>) -> Error {
91-
error!("{}",error);
91+
error!("{}", error);
9292
Error::InvalidValue
9393
}
9494
}
9595

9696
impl From<TryFromIntError> for Error {
9797
fn from(error: TryFromIntError) -> Error {
98-
error!("{}",error);
98+
error!("{}", error);
9999
Error::InvalidValue
100100
}
101101
}
102102

103103
impl From<core::str::Utf8Error> for Error {
104104
fn from(error: core::str::Utf8Error) -> Error {
105-
error!("{}",error);
105+
error!("{}", error);
106106
Error::InvalidValue
107107
}
108108
}

0 commit comments

Comments
 (0)