Building 70 Projects ranging from beginner to advanced so anyone can — learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company 👇
Go aicertificationcloud-engineeringcybercybersecuritycybersecurity-analystcybersecurity-certificationcybersecurity-certificationscybersecurity-educationcybersecurity-jobscybersecurity-portfoliocybersecurity-projectscybersecurity-toolsgrchackinglearningpentestingproject-repositoryprojetcspython
feat(lisdex): B14 - ninja undid the replay, and nothing in the tree recorded that it would
CarterPerez-dev450fa6faed3f
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rsindex aa6fcfaa..e7dd05f0 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs@@ -596,6 +596,19 @@ fn attempt_compile_commands_replay()};+ if prepass.generator.rebuilds_externally_modified_outputs() {+ return finish(+ Vec::new(),+ Some(format!(+ "{} builds through {}, which rebuilds an output whose bytes changed underneath \+ it using the command it recorded, so the relink step would recompile every \+ object this tier just replayed and hand back an uninstrumented library",+ prepass.system.as_str(),+ prepass.generator.as_str()+ )),+ );+ }+let (mut steps, failure) = capture_database(layout, &prepass, &database, options)?;if failure.is_some() {return finish(steps, failure);@@ -819,6 +832,7 @@ pub fn build(mod tests {use super::*;use crate::artifact::ArtifactKind;+ use crate::plan::{GENERATOR_MAKEFILES, GENERATOR_NINJA};use lisdex_ingest::detect::{Evidence, Marker};fn detection(candidates: Vec<BuildSystem>, markers: &[(Marker, &str)]) -> Detection {@@ -949,6 +963,53 @@ mod tests {assert_eq!(first_shadow, 2, "a costlier tier ran too early: {order:?}");}+ fn replay_only_attempt(name: &str, system: BuildSystem) -> Attempt {+ let dir = scratch(name);+ let layout = BuildLayout::new(&dir, dir.join("work"));+ let outcome = build(+ &detection(vec![system], &[]),+ &layout,+ &Instrumentation::instrumented(),+ &BuildOptions::new("afl", 1).with_tiers(vec![Tier::CompileCommandsReplay]),+ )+ .unwrap();+ outcome+ .attempts+ .into_iter()+ .find(|attempt| attempt.tier == Tier::CompileCommandsReplay)+ .expect("the replay tier must have been attempted")+ }++ #[test]+ fn compile_commands_replay_refuses_a_ninja_backed_tree_and_names_the_generator() {+ let attempt = replay_only_attempt("replay-ninja", BuildSystem::Meson);+ let reason = attempt+ .failure+ .expect("a ninja-backed tier must be refused");+ assert!(+ reason.contains(GENERATOR_NINJA),+ "the refusal must name the generator that undoes the replay: {reason}"+ );+ assert!(+ attempt.steps.is_empty(),+ "the tier must refuse before it builds anything, not after burning a full \+ uninstrumented build and a full replay: {:?}",+ attempt.steps+ );+ }++ #[test]+ fn compile_commands_replay_does_not_refuse_a_make_backed_tree() {+ let attempt = replay_only_attempt("replay-make", BuildSystem::CMake);+ let reason = attempt.failure.unwrap_or_default();+ assert!(+ !reason.contains(GENERATOR_NINJA),+ "cmake's prepass is pinned to {GENERATOR_MAKEFILES} and must reach the database \+ capture, or the guard rejects every tree rather than the ninja-backed ones: \+ {reason}"+ );+ }+#[test]fn every_tier_has_a_stable_name() {for tier in TIERS {@@ -1125,6 +1186,26 @@ mod tests {configure.spec.args[generator + 1],crate::plan::GENERATOR_MAKEFILES);+ assert_eq!(built.generator, Generator::Makefiles);+ }++ #[test]+ fn a_meson_prepass_reports_ninja_however_the_prepass_asked_for_makefiles() {+ let dir = scratch("generator-meson");+ let layout = BuildLayout::new(&dir, dir.join("work"));+ let built = prepass_plan(+ &detection(vec![BuildSystem::Meson], &[]),+ BuildSystem::Meson,+ &layout,+ &BuildOptions::new("afl", 1),+ )+ .unwrap();+ assert_eq!(+ built.generator,+ Generator::Ninja,+ "meson has no generator but ninja, so a plan that echoed the requested \+ {GENERATOR_MAKEFILES} back would let the replay tier believe its relink is safe"+ );}#[test]diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/plan.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/plan.rsindex 2189b09a..aae11508 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/plan.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/plan.rs@@ -127,6 +127,14 @@ impl Generator {Generator::Makefiles => GENERATOR_MAKEFILES,}}++ #[must_use]+ pub fn rebuilds_externally_modified_outputs(self) -> bool {+ match self {+ Generator::Ninja => true,+ Generator::Makefiles => false,+ }+ }}#[derive(Debug, Clone, PartialEq, Eq)]@@ -200,6 +208,7 @@ pub struct BuildStep {#[derive(Debug, Clone, PartialEq, Eq)]pub struct BuildPlan {pub system: BuildSystem,+ pub generator: Generator,pub build_dir: PathBuf,pub generated: Vec<GeneratedFile>,pub steps: Vec<BuildStep>,@@ -355,6 +364,7 @@ fn cmake_plan(BuildPlan {system: BuildSystem::CMake,+ generator: options.generator,build_dir,generated: vec![inject],steps: vec![@@ -400,6 +410,7 @@ fn meson_plan(BuildPlan {system: BuildSystem::Meson,+ generator: Generator::Ninja,build_dir,generated: vec![native],steps: vec![@@ -480,6 +491,7 @@ fn autotools_plan(Ok(BuildPlan {system: BuildSystem::Autotools,+ generator: Generator::Makefiles,build_dir,generated: Vec::new(),steps,@@ -503,6 +515,7 @@ fn make_plan(BuildPlan {system: BuildSystem::Make,+ generator: Generator::Makefiles,build_dir: layout.source.clone(),generated: Vec::new(),steps: vec![BuildStep {diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/tests/relink_generator.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/tests/relink_generator.rsnew file mode 100644index 00000000..1ae5de46--- /dev/null+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/tests/relink_generator.rs@@ -0,0 +1,99 @@+// ©AngelaMos | 2026+// relink_generator.rs++use std::path::{Path, PathBuf};+use std::process::Command;++use lisdex_build::plan::Generator;+use lisdex_core::scratch;++const MARKER: &str = "lisdex_replay_marker";+const PLAIN_SOURCE: &str = "int alpha(int x) { return x + 1; }\n";+const OBJECT: &str = "a.o";+const SOURCE: &str = "a.c";++fn lab(label: &str) -> PathBuf {+ let dir = scratch::path(label);+ let _ = std::fs::remove_dir_all(&dir);+ std::fs::create_dir_all(&dir).unwrap();+ std::fs::write(dir.join(SOURCE), PLAIN_SOURCE).unwrap();+ dir+}++fn run(program: &str, args: &[&str], cwd: &Path) -> bool {+ Command::new(program)+ .args(args)+ .current_dir(cwd)+ .status()+ .unwrap_or_else(|err| panic!("{program} is required by this test: {err}"))+ .success()+}++fn replay_over(dir: &Path) {+ let instrumented = dir.join("a_instrumented.c");+ std::fs::write(+ &instrumented,+ format!("{PLAIN_SOURCE}int {MARKER}(void) {{ return 42; }}\n"),+ )+ .unwrap();+ assert!(run("cc", &["-c", "a_instrumented.c", "-o", OBJECT], dir));+ assert!(+ object_holds_marker(dir),+ "the replay itself did not land, so the test that follows would prove nothing"+ );+}++fn object_holds_marker(dir: &Path) -> bool {+ let bytes = std::fs::read(dir.join(OBJECT)).unwrap();+ bytes+ .windows(MARKER.len())+ .any(|window| window == MARKER.as_bytes())+}++#[test]+fn ninja_rebuilds_a_replayed_object_and_make_leaves_it_alone() {+ let ninja_dir = lab("relink-ninja");+ std::fs::write(+ ninja_dir.join("build.ninja"),+ format!(+ "rule cc\n command = cc -MD -MF $out.d -c $in -o $out\n depfile = $out.d\n \+ deps = gcc\n\nbuild {OBJECT}: cc {SOURCE}\n"+ ),+ )+ .unwrap();+ assert!(run("ninja", &[], &ninja_dir));+ replay_over(&ninja_dir);+ assert!(run("ninja", &[], &ninja_dir));+ let ninja_kept = object_holds_marker(&ninja_dir);++ let make_dir = lab("relink-make");+ std::fs::write(+ make_dir.join("Makefile"),+ format!("all: {OBJECT}\n\n{OBJECT}: {SOURCE}\n\tcc -c {SOURCE} -o {OBJECT}\n"),+ )+ .unwrap();+ assert!(run("make", &[], &make_dir));+ replay_over(&make_dir);+ assert!(run("make", &[], &make_dir));+ let make_kept = object_holds_marker(&make_dir);++ assert!(+ !ninja_kept,+ "ninja no longer rebuilds an output whose bytes changed underneath it, so the \+ compile-commands-replay tier is refusing ninja-backed trees for a reason that has \+ stopped being true"+ );+ assert!(+ make_kept,+ "make rebuilt a replayed object it should have accepted as newer than its source, so \+ the make-backed replay path is broken too and refusing only ninja is not enough"+ );+ assert_ne!(+ Generator::Ninja.rebuilds_externally_modified_outputs(),+ Generator::Makefiles.rebuilds_externally_modified_outputs(),+ "the predicate the ladder gates on must distinguish the two generators this test just \+ measured apart"+ );+ assert!(Generator::Ninja.rebuilds_externally_modified_outputs());+ assert!(!Generator::Makefiles.rebuilds_externally_modified_outputs());+}