Skip to content

Commit

Permalink
fix(main): kill_event not implement in replay command
Browse files Browse the repository at this point in the history
  • Loading branch information
qjerome committed Oct 15, 2024
1 parent c69d04e commit adeca41
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions kunai/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use std::cmp::max;
use std::collections::{HashMap, HashSet, VecDeque};

use std::fs::{self, DirBuilder, File};
use std::io::{self, BufRead, BufReader, Write};
use std::io::{self, BufRead, BufReader, Read, Write};
use std::net::IpAddr;

use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt, PermissionsExt};
Expand Down Expand Up @@ -141,6 +141,30 @@ impl SystemInfo {
}
}

enum Input {
Stdin(std::io::Stdin),
File(std::fs::File),
}

impl Input {
fn from_file(f: fs::File) -> Self {
Self::File(f)
}

fn from_stdin() -> Self {
Self::Stdin(std::io::stdin())
}
}

impl Read for Input {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
match self {
Self::Stdin(stdin) => stdin.read(buf),
Self::File(f) => f.read(buf),
}
}
}

pub enum Output {
Stdout(std::io::Stdout),
Stderr(std::io::Stderr),
Expand Down Expand Up @@ -2414,15 +2438,14 @@ impl Command {

let mut p = EventConsumer::with_config(conf.stdout_output())?;
for f in log_files {
let f = {
if f == "-" {
"/dev/stdin".into()
} else {
f
}
let reader = if f == "-" {
std::io::BufReader::new(Input::from_stdin())
} else {
std::io::BufReader::new(Input::from_file(fs::File::open(f)?))
};
let reader = std::io::BufReader::new(fs::File::open(f)?);

let mut de = serde_json::Deserializer::from_reader(reader);

while let Ok(v) = serde_json::Value::deserialize(&mut de) {
// we attempt at getting event name from json
if let Some(name) = v
Expand All @@ -2445,7 +2468,7 @@ impl Command {
Type::Execve | Type::ExecveScript => scan_event!(p, ExecveData),
Type::Clone => scan_event!(p, CloneData),
Type::Prctl => scan_event!(p, PrctlData),
Type::Kill => unimplemented!(),
Type::Kill => scan_event!(p, KillData),
Type::MmapExec => scan_event!(p, MmapExecData),
Type::MprotectExec => scan_event!(p, MprotectData),
Type::Connect => scan_event!(p, ConnectData),
Expand Down

0 comments on commit adeca41

Please sign in to comment.