MCPcopy Create free account
hub / github.com/MultiFuzz/MultiFuzz / modify_input

Function modify_input

hail-fuzz/src/debugging/mod.rs:79–120  ·  view source on GitHub ↗

Performs dynamic modifications of `input` based on environment variables

(input: &mut MultiStream)

Source from the content-addressed store, hash-verified

77
78/// Performs dynamic modifications of `input` based on environment variables
79pub fn modify_input(input: &mut MultiStream) {
80 let mut modified = false;
81
82 if let Ok(trim) = std::env::var("TRIM") {
83 modified = true;
84 if let Some((stream, offset, size)) = parse_trim(&trim) {
85 input.streams.get_mut(&stream).unwrap().bytes.drain(offset..offset + size);
86 }
87 }
88
89 if let Ok(insert) = std::env::var("INSERT") {
90 modified = true;
91 for insert in insert.split(';') {
92 if let Some((stream, offset, bytes)) = parse_modification(insert) {
93 utils::insert_slice(
94 &mut input.streams.get_mut(&stream).unwrap().bytes,
95 &bytes,
96 offset,
97 );
98 }
99 }
100 }
101
102 if let Ok(insert) = std::env::var("REPLACE") {
103 modified = true;
104 for insert in insert.split(';') {
105 if let Some((stream, offset, bytes)) = parse_modification(insert) {
106 tracing::info!("{stream:#x}@{offset} replacing {} bytes", bytes.len());
107 let dst = &mut input.streams.get_mut(&stream).unwrap().bytes;
108 dst[offset..offset + bytes.len()].copy_from_slice(&bytes);
109 }
110 else {
111 tracing::warn!("invalid modification: {insert}");
112 }
113 }
114 }
115
116 if modified {
117 // Save a copy of the modified version of the input for debugging and analysis.
118 let _ = std::fs::write("workdir/modified_input", input.to_bytes());
119 }
120}
121
122/// Parses a trim expression of the form: "<stream addr>,<stream offset>,<size>"
123fn parse_trim(trim: &str) -> Option<(u64, usize, usize)> {

Callers 2

replayFunction · 0.85
run_stageFunction · 0.85

Calls 6

parse_trimFunction · 0.85
parse_modificationFunction · 0.85
insert_sliceFunction · 0.85
get_mutMethod · 0.80
to_bytesMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected