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

Function init

hail-fuzz/src/debugging/check.rs:9–79  ·  view source on GitHub ↗
(vm: &mut Vm)

Source from the content-addressed store, hash-verified

7};
8
9pub fn init(vm: &mut Vm) -> anyhow::Result<()> {
10 let canary = icicle_fuzzing::parse_bool_env("ENABLE_CANARY")?.unwrap_or(false);
11 let debug = icicle_fuzzing::parse_bool_env("ENABLE_DEBUG")?.unwrap_or(false);
12
13 if let Ok(print_hook) = std::env::var("PRINT_HOOK") {
14 if let Some((addr, reglist)) = icicle_fuzzing::parse_func_hook(vm, &print_hook) {
15 match reglist.as_slice() {
16 &[reg] => {
17 let (reg, mode) = reg.split_once(":").unwrap_or((reg, "char"));
18 match mode {
19 "str" => register_cstr_printer(vm, addr, reg),
20 "char" => register_char_out_printer(vm, addr, reg),
21 _ => tracing::warn!("unknown print mode: {mode}"),
22 }
23 }
24 &[data_reg, len_reg] => register_write_printer(vm, addr, data_reg, len_reg),
25 x => tracing::warn!("Invalid number of registers for `PRINT_HOOK`: {}", x.len()),
26 }
27 }
28 else {
29 tracing::warn!("`PRINT_HOOK` is invalid: {print_hook}")
30 }
31 }
32
33 let debug = match (canary, debug) {
34 (true, false) => DebugConfig::enable_canary(),
35 (canary, true) => DebugConfig::new_with_output(canary, std::io::stderr(), true),
36 _ => return Ok(()),
37 };
38
39 let Some(target_path) =
40 vm.env_ref::<icicle_cortexm::FuzzwareEnvironment>().and_then(|x| x.elf_path.as_ref())
41 else {
42 tracing::warn!("Unable to enable debugging and canaries for unknown target");
43 return Ok(());
44 };
45
46 let Some(target) = KnownTargets::detect_from_path(target_path)
47 else {
48 tracing::warn!(
49 "Unable to enable debugging and canaries for unknown binary: {}",
50 target_path.display()
51 );
52 return Ok(());
53 };
54
55 // @todo: port remaining checkers to new approach.
56 match target {
57 KnownTargets::Gateway => debug_gateway(vm, debug),
58 KnownTargets::HeatPress => debug_heatpress(vm, debug),
59 KnownTargets::Thermostat => debug_thermostat(vm, debug),
60 KnownTargets::ZephyrSocketCan => debug_zephyr_socket_can(vm, debug),
61 KnownTargets::SteeringControl => register_write_printer(vm, 0x081060, "r1", "r2"),
62 KnownTargets::Cnc => debug_cnc(vm, debug),
63 KnownTargets::Printer => register_char_out_printer(vm, 0x80004ea, "r1"),
64 KnownTargets::Console => register_write_printer(vm, 0x15c0, "r1", "r2"),
65 KnownTargets::UtaskerModbus => debug_utasker_modbus(vm, debug),
66 KnownTargets::UtaskerUsb => debug_usb(vm, debug),

Callers 6

save_block_coverageFunction · 0.70
configure_coverageFunction · 0.50
runFunction · 0.50
new_debugMethod · 0.50
prepare_new_inputMethod · 0.50
runFunction · 0.50

Calls 15

register_cstr_printerFunction · 0.85
register_write_printerFunction · 0.85
debug_gatewayFunction · 0.85
debug_heatpressFunction · 0.85
debug_thermostatFunction · 0.85
debug_zephyr_socket_canFunction · 0.85
debug_cncFunction · 0.85
debug_utasker_modbusFunction · 0.85
debug_usbFunction · 0.85
debug_gps_trackerFunction · 0.85
debug_xml_parserFunction · 0.85

Tested by 1

runFunction · 0.40