| 
					
				 | 
			
			
				@@ -1,4 +1,4 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-use std::{fs, path::PathBuf, process::Command}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use std::{fs, path::{PathBuf, Path}, process::Command}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use anyhow::Context as _; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use clap::Parser; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -29,27 +29,22 @@ fn build_user(_opts: &Options) -> Result<(), anyhow::Error> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     Ok(()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-pub fn build(opts: Options) -> Result<(), anyhow::Error> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    fs::create_dir_all(&opts.output_folder).context(format!( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        "Error creating dirs for path: {}", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        opts.output_folder 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .to_str() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .unwrap_or("[path not valid unicode]") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    ))?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    build_ebpf(build_ebpf::Options { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        target: opts.bpf_target, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        release: true, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    .context("Error while building eBPF program")?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+fn build_tools(_opts: &Options) -> Result<(), anyhow::Error> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let status = Command::new("cargo") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        .args(["build", "--release"]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        .status() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        .expect("failed to build responder tools"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if !status.success() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Err(anyhow::anyhow!( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "cargo build --release failed to run: {}", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            status.to_string() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        )); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    Ok(()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    for entry in fs::read_dir( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        [r"target", opts.bpf_target.to_string().as_str(), r"release"] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .iter() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .collect::<PathBuf>(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    )? { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        let ebpf_bin = opts.output_folder.join(r"ebpf"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        fs::create_dir_all(&ebpf_bin)?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+fn copy_execs_from_dir<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<(), anyhow::Error>{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for entry in fs::read_dir(from)? { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if let Ok(entry) = entry { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             let path = entry.path(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if path.is_file() 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -60,7 +55,7 @@ pub fn build(opts: Options) -> Result<(), anyhow::Error> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     .map(|s| s.contains(".")) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     .unwrap_or(true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                let to = ebpf_bin.join(path.file_name().unwrap()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                let to = to.as_ref().join(path.file_name().unwrap()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 fs::copy(&path, &to).context(format!( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "Error copying from {} to {}", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     path.to_str().unwrap_or("[path not valid unicode]"), 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -69,6 +64,32 @@ pub fn build(opts: Options) -> Result<(), anyhow::Error> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    Ok(()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+pub fn build(opts: Options) -> Result<(), anyhow::Error> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fs::create_dir_all(&opts.output_folder).context(format!( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        "Error creating dirs for path: {}", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        opts.output_folder 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .to_str() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .unwrap_or("[path not valid unicode]") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ))?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    build_ebpf(build_ebpf::Options { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        target: opts.bpf_target, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        release: true, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    .context("Error while building eBPF program")?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let ebpf_bin = opts.output_folder.join(r"ebpf"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fs::create_dir_all(&ebpf_bin)?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    copy_execs_from_dir( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        [r"target", opts.bpf_target.to_string().as_str(), r"release"] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .iter() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .collect::<PathBuf>(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ebpf_bin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    )?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     build_user(&opts).context("Error while building userspace application")?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     fs::copy( 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -76,5 +97,11 @@ pub fn build(opts: Options) -> Result<(), anyhow::Error> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         opts.output_folder.join("responder"), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     )?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    build_tools(&opts).context("Error while building tool applications")?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let tools_bin = opts.output_folder.join(r"tools"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fs::create_dir_all(&tools_bin)?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    copy_execs_from_dir("target/release", tools_bin)?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     Ok(()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |