Skip to content

Commit

Permalink
Lint fixes complete
Browse files Browse the repository at this point in the history
  • Loading branch information
devttys0 committed Oct 21, 2024
1 parent c1140ee commit cc14a29
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/cliparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ pub struct CliArgs {
}

pub fn parse() -> CliArgs {
return CliArgs::parse();
CliArgs::parse()
}
1 change: 0 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Common Functions
use chrono::prelude::DateTime;
use crc32_v2;
use log::{debug, error};
use std::fs::File;
use std::io::Read;
Expand Down
57 changes: 27 additions & 30 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::collections::HashMap;
use std::io;
use std::io::Write;
use std::time;
use termsize;

const DELIM_CHARACTER: &str = "-";
const DEFAULT_TERMINAL_WIDTH: u16 = 200;
Expand All @@ -16,24 +15,22 @@ const COLUMN1_WIDTH: usize = 35;
const COLUMN2_WIDTH: usize = 35;

fn terminal_width() -> usize {
let terminal_width: u16;

match termsize::get() {
Some(ts) => terminal_width = ts.cols,
None => terminal_width = DEFAULT_TERMINAL_WIDTH,
let terminal_width: u16 = match termsize::get() {
Some(ts) => ts.cols,
None => DEFAULT_TERMINAL_WIDTH,
};

return terminal_width as usize;
terminal_width as usize
}

fn line_delimiter() -> String {
let mut delim: String = "".to_string();

for _i in 0..terminal_width() {
delim = delim + DELIM_CHARACTER;
delim += DELIM_CHARACTER;
}

return delim;
delim
}

fn center_text(text: &String) -> String {
Expand All @@ -55,7 +52,7 @@ fn center_text(text: &String) -> String {

centered_string += text;

return centered_string;
centered_string
}

fn pad_to_length(text: &str, len: usize) -> String {
Expand All @@ -72,13 +69,13 @@ fn pad_to_length(text: &str, len: usize) -> String {
}

for _i in 0..pad_size {
padded_string = padded_string + " ";
padded_string += " ";
}

return padded_string;
padded_string
}

fn line_wrap(text: &String, prefix_size: usize) -> String {
fn line_wrap(text: &str, prefix_size: usize) -> String {
let mut this_line = "".to_string();
let mut formatted_string = "".to_string();
let max_line_size: usize = terminal_width() - prefix_size;
Expand All @@ -89,7 +86,7 @@ fn line_wrap(text: &String, prefix_size: usize) -> String {
} else {
formatted_string = formatted_string + &this_line + "\n";
for _i in 0..prefix_size {
formatted_string = formatted_string + " ";
formatted_string += " ";
}
this_line = word.to_string() + " ";
}
Expand All @@ -116,7 +113,7 @@ fn print_delimiter() {
}

fn print_header(title_text: &String) {
println!("");
println!();
println!("{}", center_text(title_text).bold().magenta());
print_delimiter();
print_column_headers("DECIMAL", "HEXADECIMAL", "DESCRIPTION");
Expand All @@ -125,7 +122,7 @@ fn print_header(title_text: &String) {

fn print_footer() {
print_delimiter();
println!("");
println!();
}

fn print_signature(signature: &signatures::common::SignatureResult) {
Expand Down Expand Up @@ -169,7 +166,7 @@ fn print_extraction(
.yellow();
}
Some(extraction_result) => {
if extraction_result.success == true {
if extraction_result.success {
extraction_message = format!(
"[+] Extraction of {} data at offset {:#X} completed successfully",
signature.name, signature.offset
Expand Down Expand Up @@ -201,7 +198,7 @@ fn print_extractions(
let mut extraction_result: Option<&extractors::common::ExtractionResult> = None;

// Only print extraction results if an extraction was attempted or explicitly declined
if signature.extraction_declined == true {
if signature.extraction_declined {
printable_extraction = true
} else if extraction_results.contains_key(&signature.id) {
printable_extraction = true;
Expand All @@ -210,7 +207,7 @@ fn print_extractions(

if printable_extraction {
// Only print the delimiter line once
if delimiter_printed == false {
if !delimiter_printed {
print_delimiter();
delimiter_printed = true;
}
Expand All @@ -220,7 +217,7 @@ fn print_extractions(
}

pub fn print_analysis_results(quiet: bool, extraction_attempted: bool, results: &AnalysisResults) {
if quiet == true {
if quiet {
return;
}

Expand Down Expand Up @@ -253,7 +250,7 @@ pub fn print_signature_list(quiet: bool, signatures: &Vec<signatures::common::Si
let mut sorted_descriptions: Vec<String> = vec![];
let mut signature_lookup: HashMap<String, SignatureInfo> = HashMap::new();

if quiet == true {
if quiet {
return;
}

Expand Down Expand Up @@ -306,7 +303,7 @@ pub fn print_signature_list(quiet: bool, signatures: &Vec<signatures::common::Si
signature_count += 1;

// If there is an extractor for this signature, increment extractor count
if signature_info.has_extractor == true {
if signature_info.has_extractor {
extractor_count += 1;
}

Expand All @@ -331,15 +328,15 @@ pub fn print_signature_list(quiet: bool, signatures: &Vec<signatures::common::Si
siginfo.extractor
);

if siginfo.is_short == true {
if siginfo.is_short {
println!("{}", display_line.yellow());
} else {
println!("{}", display_line.green());
}
}

print_delimiter();
println!("");
println!();
println!("Total signatures: {}", signature_count);
println!("Extractable signatures: {}", extractor_count);
}
Expand All @@ -359,21 +356,21 @@ pub fn print_stats(
let mut units = "milliseconds";
let mut display_time: f64 = run_time.elapsed().as_millis() as f64;

if quiet == true {
if quiet {
return;
}

// Format the output time in a more human-readable manner
if display_time >= MS_IN_A_SECOND {
display_time = display_time / MS_IN_A_SECOND;
display_time /= MS_IN_A_SECOND;
units = "seconds";

if display_time >= SECONDS_IN_A_MINUTE {
display_time = display_time / SECONDS_IN_A_MINUTE;
display_time /= SECONDS_IN_A_MINUTE;
units = "minutes";

if display_time >= MINUTES_IN_AN_HOUR {
display_time = display_time / MINUTES_IN_AN_HOUR;
display_time /= MINUTES_IN_AN_HOUR;
units = "hours";
}
}
Expand All @@ -390,14 +387,14 @@ pub fn print_stats(
}

pub fn print_plain(quiet: bool, msg: &str) {
if quiet == false {
if !quiet {
print!("{}", msg);
let _ = io::stdout().flush();
}
}

pub fn println_plain(quiet: bool, msg: &str) {
if quiet == false {
if !quiet {
println!("{}", msg);
}
}
12 changes: 6 additions & 6 deletions src/entropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn blocks(data: &[u8]) -> Vec<BlockEntropy> {
offset += block_size;
}

return entropy_blocks;
entropy_blocks
}

/// Generate a plot of a file's entropy.
Expand Down Expand Up @@ -81,7 +81,7 @@ pub fn plot(file_path: impl Into<String>) -> Result<FileEntropy, EntropyError> {
let png_path = file_entropy.file.clone();

// Make sure the output file doesn't already exist
if path::Path::new(&png_path).exists() == true {
if path::Path::new(&png_path).exists() {
error!("Cannot create entropy graph {}: File exists", png_path);
return Err(EntropyError);
}
Expand Down Expand Up @@ -119,14 +119,14 @@ pub fn plot(file_path: impl Into<String>) -> Result<FileEntropy, EntropyError> {

// Set the axis colors
ctx.configure_mesh()
.axis_style(&GREEN)
.axis_style(GREEN)
.x_label_style(&GREEN)
.draw()
.unwrap();

// Line plot of the entropy points
ctx.draw_series(LineSeries::new(
points.into_iter().map(|(x, y)| (x, y)),
points, //.into_iter().map(|(x, y)| (x, y)),
&YELLOW,
))
.unwrap();
Expand All @@ -136,13 +136,13 @@ pub fn plot(file_path: impl Into<String>) -> Result<FileEntropy, EntropyError> {
* Plotter code doesn't throw any errors if graph file creation fails.
* Make sure the output file was created.
*/
if path::Path::new(&png_path).exists() == false {
if !path::Path::new(&png_path).exists() {
error!(
"Failed to create entropy graph {}: possible permissions error?",
png_path
);
return Err(EntropyError);
}

return Ok(file_entropy);
Ok(file_entropy)
}
14 changes: 5 additions & 9 deletions src/json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use log::error;
use serde::{Deserialize, Serialize};
use serde_json;
use std::fs;
use std::io;
use std::io::Seek;
Expand All @@ -23,7 +22,7 @@ pub fn log(json_file: &Option<String>, results: JSONType) {
const JSON_COMMA_SEPERATOR: &str = ",\n";

match json_file {
None => return,
None => (),
Some(file_name) => {
// Convert analysis results to JSON
match serde_json::to_string_pretty(&results) {
Expand All @@ -32,20 +31,18 @@ pub fn log(json_file: &Option<String>, results: JSONType) {
// Open file for reading and writing, create if does not already exist
match fs::OpenOptions::new()
.create(true)
.append(true)
.read(true)
.write(true)
.open(&file_name)
.open(file_name)
{
Err(e) => {
error!("Failed to open JSON log file '{}': {}", file_name, e);
return;
}
Ok(mut fp) => {
// Seek to the end of the file and get the cursor position
match fp.seek(io::SeekFrom::End(0)) {
Err(e) => {
error!("Failed to see to end of JSON file: {}", e);
return;
}
Ok(pos) => {
if pos == 0 {
Expand Down Expand Up @@ -82,8 +79,7 @@ pub fn log(json_file: &Option<String>, results: JSONType) {
}

fn write_to_json_file(mut fp: &fs::File, data: String) {
match fp.write_all(data.as_bytes()) {
Ok(_) => return,
Err(e) => error!("Failed to write to JSON log file: {}", e),
if let Err(e) = fp.write_all(data.as_bytes()) {
error!("Failed to write to JSON log file: {}", e);
}
}
Loading

0 comments on commit cc14a29

Please sign in to comment.