Enhance/warning architecture#478 (#482)
* added enhance of architecture check #478 * changed check architecture process after output logo #478 * English msg update * fixed detect method of os-bit to windows and linux * removed mac and unix architecture and binary and updated its process of windows * fix clippy * added check on Wow64 env #478 * Update contributors.txt Co-authored-by: Tanaka Zakku <71482215+YamatoSecurity@users.noreply.github.com>
This commit is contained in:
32
src/main.rs
32
src/main.rs
@@ -26,7 +26,7 @@ use hhmmss::Hhmmss;
|
||||
use pbr::ProgressBar;
|
||||
use serde_json::Value;
|
||||
use std::cmp::Ordering;
|
||||
use std::ffi::OsStr;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::fmt::Display;
|
||||
use std::fs::create_dir;
|
||||
use std::io::{BufWriter, Write};
|
||||
@@ -34,6 +34,7 @@ use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::time::SystemTime;
|
||||
use std::{
|
||||
env,
|
||||
fs::{self, File},
|
||||
path::PathBuf,
|
||||
vec,
|
||||
@@ -43,7 +44,7 @@ use tokio::spawn;
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use {is_elevated::is_elevated, std::env};
|
||||
use is_elevated::is_elevated;
|
||||
|
||||
// 一度にtimelineやdetectionを実行する行数
|
||||
const MAX_DETECT_RECORDS: usize = 5000;
|
||||
@@ -88,6 +89,17 @@ impl App {
|
||||
&analysis_start_time.day().to_owned()
|
||||
));
|
||||
}
|
||||
|
||||
if !self.is_matched_architecture_and_binary() {
|
||||
AlertMessage::alert(
|
||||
&mut BufWriter::new(std::io::stderr().lock()),
|
||||
"The hayabusa version you ran does not match your PC architecture.\n Please use the correct architecture. (Binary ending in -x64.exe for 64-bit and -x86.exe for 32-bit.)",
|
||||
)
|
||||
.ok();
|
||||
println!();
|
||||
return;
|
||||
}
|
||||
|
||||
if configs::CONFIG
|
||||
.read()
|
||||
.unwrap()
|
||||
@@ -785,6 +797,22 @@ impl App {
|
||||
Ok("You currently have the latest rules.".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
/// check architecture
|
||||
fn is_matched_architecture_and_binary(&self) -> bool {
|
||||
if cfg!(target_os = "windows") {
|
||||
let is_processor_arch_32bit = env::var_os("PROCESSOR_ARCHITECTURE")
|
||||
.unwrap_or_default()
|
||||
.eq("x86");
|
||||
// PROCESSOR_ARCHITEW6432は32bit環境には存在しないため、環境変数存在しなかった場合は32bit環境であると判断する
|
||||
let not_wow_flag = env::var_os("PROCESSOR_ARCHITEW6432")
|
||||
.unwrap_or_else(|| OsString::from("x86"))
|
||||
.eq("x86");
|
||||
return (cfg!(target_pointer_width = "64") && !is_processor_arch_32bit)
|
||||
|| (cfg!(target_pointer_width = "32") && is_processor_arch_32bit && not_wow_flag);
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user