MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / prepare_transform_path_for_driver

Method prepare_transform_path_for_driver

src/deopt.rs:604–629  ·  view source on GitHub ↗

Prepare a work dir and gadgets for Transformer to dynamically infer the fuzz-ability of a driver. The driver is a program that contains only an argument that was transformed to receive fuzzer's bytes. The infer is performed upon a corpora that is sufficient to cover the program's code. During the infer process, the content of corpora is retain unchanged and only the bytes wiil be passed to the tra

(&self, driver: &Path, corpora: &Path)

Source from the content-addressed store, hash-verified

602 // 1. copy literal corpora collected from program to corpus as the only mutatable corpora.
603 // 2. modify the driver's code to read the data directly from the passed corpora.
604 pub fn prepare_transform_path_for_driver(&self, driver: &Path, corpora: &Path) -> Result<()> {
605 log::trace!("Prepare the work dir for driver: {driver:?}");
606 let check_dir = get_file_dirname(driver);
607
608 // copy program literal as seed corpus
609 let literal_seed = driver.with_extension("seed");
610 if literal_seed.exists() {
611 let corpus_dir: PathBuf = [check_dir.clone(), "corpus".into()].iter().collect();
612 if corpus_dir.exists() {
613 std::fs::remove_dir_all(&corpus_dir)?;
614 }
615 crate::deopt::utils::create_dir_if_nonexist(&corpus_dir)?;
616 let corpus_seed: PathBuf = [corpus_dir, "seed".into()].iter().collect();
617 std::fs::copy(literal_seed, corpus_seed)?;
618 }
619
620 // copy the highest cov corpora
621 let dst_corpora: PathBuf = [check_dir, "highest_cov_corpora".into()].iter().collect();
622 std::fs::copy(corpora, dst_corpora)?;
623
624 // Change the raw data read from parameter to read from file.
625 let content = std::fs::read_to_string(driver)?;
626 let content = content.replace("FDPConsumeRawBytes", "FDPReadRawBytes");
627 std::fs::write(driver, content)?;
628 Ok(())
629 }
630}
631
632pub mod utils {

Callers 1

transform_checkMethod · 0.80

Calls 2

get_file_dirnameFunction · 0.85
create_dir_if_nonexistFunction · 0.85

Tested by

no test coverage detected