Skip to content

Commit

Permalink
Merge pull request #1359 from Yamato-Security/1358-embed-non-configur…
Browse files Browse the repository at this point in the history
…able-files-into-binary

embedded non configurable files into binary
  • Loading branch information
YamatoSecurity authored Jun 8, 2024
2 parents 356fde1 + 1ef8154 commit b394cc2
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 54 deletions.
124 changes: 124 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tokio = { version = "1", features = ["full"] }
ureq = "*"
wildmatch = "2.*"
yaml-rust = "0.4.*"
rust-embed={version = "8.4.0", features = ["include-exclude", "debug-embed"]}

[profile.dev]
debug-assertions = false
Expand Down
66 changes: 34 additions & 32 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ use hayabusa::timeline::computer_metrics::countup_event_by_computer;
use hayabusa::{detections::configs, timeline::timelines::Timeline};
use hayabusa::{detections::utils::write_color_buffer, filter};
use hayabusa::{options, yaml};
use rust_embed::Embed;

#[derive(Embed)]
#[folder = "art/"]
struct Arts;

#[derive(Embed)]
#[folder = "./"]
#[include = "contributors.txt"]
struct Contributors;

#[cfg(target_os = "windows")]
use is_elevated::is_elevated;

Expand Down Expand Up @@ -967,23 +978,16 @@ impl App {
}

fn print_contributors(&self) {
match fs::read_to_string(
utils::check_setting_path(&CURRENT_EXE_PATH.to_path_buf(), "contributors.txt", true)
.unwrap(),
) {
Ok(contents) => {
write_color_buffer(
&BufferWriter::stdout(ColorChoice::Always),
None,
&contents,
true,
)
.ok();
}
Err(err) => {
AlertMessage::alert(&format!("{err}")).ok();
}
}
let contributors = Contributors::get("contributors.txt").unwrap();
let content = std::str::from_utf8(contributors.data.as_ref()).unwrap_or_default();

write_color_buffer(
&BufferWriter::stdout(ColorChoice::Always),
None,
content,
true,
)
.ok();
}

fn analysis_files(
Expand Down Expand Up @@ -2247,9 +2251,8 @@ impl App {

/// output logo
fn output_logo(&self, stored_static: &StoredStatic) {
let fp = utils::check_setting_path(&CURRENT_EXE_PATH.to_path_buf(), "art/logo.txt", true)
.unwrap();
let content = fs::read_to_string(fp).unwrap_or_default();
let logo = Arts::get("logo.txt").unwrap();
let content = std::str::from_utf8(logo.data.as_ref()).unwrap_or_default();
let output_color = if stored_static.common_options.no_color {
None
} else {
Expand All @@ -2258,7 +2261,7 @@ impl App {
write_color_buffer(
&BufferWriter::stdout(ColorChoice::Always),
output_color,
&content,
content,
true,
)
.ok();
Expand All @@ -2267,24 +2270,23 @@ impl App {
/// output easter egg arts
fn output_eggs(&self, exec_datestr: &str) {
let mut eggs: HashMap<&str, (&str, Color)> = HashMap::new();
eggs.insert("01/01", ("art/happynewyear.txt", Color::Rgb(255, 0, 0))); // Red
eggs.insert("02/22", ("art/ninja.txt", Color::Rgb(0, 171, 240))); // Cerulean
eggs.insert("05/09", ("art/goku.txt", Color::Rgb(243, 156, 22))); // Middle Washed Orange
eggs.insert("08/08", ("art/takoyaki.txt", Color::Rgb(181, 101, 29))); // Light Brown
eggs.insert("10/31", ("art/halloween.txt", Color::Rgb(255, 87, 51))); // Pumpkin Orange
eggs.insert("12/24", ("art/christmas.txt", Color::Rgb(70, 192, 22))); // Green
eggs.insert("12/25", ("art/christmas.txt", Color::Rgb(70, 192, 22))); // Green
eggs.insert("01/01", ("happynewyear.txt", Color::Rgb(255, 0, 0))); // Red
eggs.insert("02/22", ("ninja.txt", Color::Rgb(0, 171, 240))); // Cerulean
eggs.insert("05/09", ("goku.txt", Color::Rgb(243, 156, 22))); // Middle Washed Orange
eggs.insert("08/08", ("takoyaki.txt", Color::Rgb(181, 101, 29))); // Light Brown
eggs.insert("10/31", ("halloween.txt", Color::Rgb(255, 87, 51))); // Pumpkin Orange
eggs.insert("12/24", ("christmas.txt", Color::Rgb(70, 192, 22))); // Green
eggs.insert("12/25", ("christmas.txt", Color::Rgb(70, 192, 22))); // Green

match eggs.get(exec_datestr) {
None => {}
Some((path, color)) => {
let egg_path =
utils::check_setting_path(&CURRENT_EXE_PATH.to_path_buf(), path, true).unwrap();
let content = fs::read_to_string(egg_path).unwrap_or_default();
let art = Arts::get(path).unwrap();
let content = std::str::from_utf8(art.data.as_ref()).unwrap_or_default();
write_color_buffer(
&BufferWriter::stdout(ColorChoice::Always),
Some(color.to_owned()),
&content,
content,
true,
)
.ok();
Expand Down
51 changes: 29 additions & 22 deletions src/options/htmlreport.rs

Large diffs are not rendered by default.

0 comments on commit b394cc2

Please sign in to comment.