Skip to content

Commit

Permalink
Satisfy 'cargo clippy' and 'cargo fmt' for main branch CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tnballo committed Jun 12, 2022
1 parent 7bf285f commit 691e0dd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
11 changes: 6 additions & 5 deletions src/binary/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,15 @@ pub fn get_all_param_regs(bins: &[Binary]) -> Vec<iced_x86::Register> {
}

pub fn get_supported_macho<'a>(
fat: &'a goblin::mach::MultiArch
fat: &'a goblin::mach::MultiArch,
) -> Result<goblin::mach::MachO<'a>, Box<dyn Error>> {
let macho = fat
.find(|arch| {
(arch.as_ref().unwrap().cputype() == goblin::mach::constants::cputype::CPU_TYPE_X86_64)
|| (arch.as_ref().unwrap().cputype() == goblin::mach::constants::cputype::CPU_TYPE_I386)
})
.ok_or("Failed to retrieve supported architecture from MultiArch Mach-O")??;
|| (arch.as_ref().unwrap().cputype()
== goblin::mach::constants::cputype::CPU_TYPE_I386)
})
.ok_or("Failed to retrieve supported architecture from MultiArch Mach-O")??;

Ok(macho)
}
}
4 changes: 1 addition & 3 deletions src/cli/checksec_fmt.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::fmt;

use checksec::{
colorize_bool, elf, macho, pe,
};
use checksec::{colorize_bool, elf, macho, pe};
use colored::Colorize;

// This file provides a multi-line, optional-color alternative to checksec's single line print.
Expand Down
52 changes: 29 additions & 23 deletions src/cli/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ impl Import {
reloc: &goblin::elf::Reloc,
no_color: bool,
) -> Import {
let mut imp = Import::default();

imp.name = match elf.dynstrtab.get_at(sym.st_name) {
Some(s) => s.to_string(),
None => "".to_string(),
let mut imp = Import {
name: match elf.dynstrtab.get_at(sym.st_name) {
Some(s) => s.to_string(),
None => "".to_string(),
},
source: get_elf_symbol_version_string(elf, reloc.r_sym)
.unwrap_or_else(|| "Unable to parse source".to_string()),
address: reloc.r_offset,
..Default::default()
};

imp.source = get_elf_symbol_version_string(&elf, reloc.r_sym)
imp.source = get_elf_symbol_version_string(elf, reloc.r_sym)
.unwrap_or_else(|| "Unable to parse source".to_string());

imp.address = reloc.r_offset;
Expand All @@ -38,7 +42,7 @@ impl Import {
// ELF attributes: reloc type, .plt address, symbol index, value, addend (if available)
imp.attrs = vec![
symbol_r_type,
match get_plt_address(elf, &reloc) {
match get_plt_address(elf, reloc) {
Some(a) => format!("{:#x}", a),
None => "".to_string(),
},
Expand All @@ -56,11 +60,12 @@ impl Import {
}

fn from_pe(import: &goblin::pe::import::Import, no_color: bool) -> Import {
let mut imp = Import::default();

imp.name = import.name.to_string();
imp.source = import.dll.to_string();
imp.address = import.rva as u64;
let mut imp = Import {
name: import.name.to_string(),
source: import.dll.to_string(),
address: import.rva as u64,
..Default::default()
};

let offset = format!("{:#x}", import.offset);

Expand All @@ -73,11 +78,12 @@ impl Import {
}

fn from_macho(import: goblin::mach::imports::Import, no_color: bool) -> Import {
let mut imp = Import::default();

imp.name = import.name.to_string();
imp.source = import.dylib.to_string();
imp.address = import.address;
let mut imp = Import {
name: import.name.to_string(),
source: import.dylib.to_string(),
address: import.address,
..Default::default()
};

let offset = format!("{:#x}", import.offset);
let seq_offset = format!("{:#x}", import.start_of_sequence_offset);
Expand Down Expand Up @@ -129,16 +135,16 @@ impl fmt::Display for Import {
single_quote,
{
match self.no_color {
true => format!("{}", self.name).normal(),
false => format!("{}", self.name).yellow(),
true => self.name.to_string().normal(),
false => self.name.to_string().yellow(),
}
},
single_quote,
colon,
{
match self.no_color {
true => format!("{}", self.source).normal(),
false => format!("{}", self.source).green(),
true => self.source.to_string().normal(),
false => self.source.to_string().green(),
}
},
comma,
Expand Down Expand Up @@ -304,9 +310,9 @@ pub fn dump_macho_imports(macho: &goblin::mach::MachO, no_color: bool) {
}

fn print_imports(
headers: &Vec<&str>,
headers: &[&str],
mut imports: Vec<Vec<String>>,
col_width: &Vec<usize>,
col_width: &[usize],
no_color: bool,
) {
imports.sort();
Expand Down

0 comments on commit 691e0dd

Please sign in to comment.