aboutsummaryrefslogtreecommitdiff
path: root/fuzz/fuzz_targets/display_does_not_panic.rs
blob: 39f5753e6005d91fb4adb58bfdcc71c3e8a95c80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate yaxpeax_x86;

fuzz_target!(|data: &[u8]| {
    let x86_64_decoder = yaxpeax_x86::long_mode::InstDecoder::default();
    let x86_32_decoder = yaxpeax_x86::protected_mode::InstDecoder::default();
    let x86_16_decoder = yaxpeax_x86::real_mode::InstDecoder::default();

    if let Ok(inst) = x86_64_decoder.decode_slice(data) {
        let mut out = String::new();
        inst.write_to(&mut out).expect("format does not panic");
        let mut text_buf = yaxpeax_x86::long_mode::InstructionTextBuffer::new();
        text_buf.format_inst(&inst.display_with(yaxpeax_x86::long_mode::DisplayStyle::Intel)).expect("can format");
        assert_eq!(text_buf.text_str(), out);
    };

    if let Ok(inst) = x86_32_decoder.decode_slice(data) {
        let mut out = String::new();
        inst.write_to(&mut out).expect("format does not panic");
        let mut text_buf = yaxpeax_x86::protected_mode::InstructionTextBuffer::new();
        text_buf.format_inst(&inst.display_with(yaxpeax_x86::protected_mode::DisplayStyle::Intel)).expect("can format");
        assert_eq!(text_buf.text_str(), out);
    };

    if let Ok(inst) = x86_16_decoder.decode_slice(data) {
        let mut out = String::new();
        inst.write_to(&mut out).expect("format does not panic");
        let mut text_buf = yaxpeax_x86::real_mode::InstructionTextBuffer::new();
        text_buf.format_inst(&inst.display_with(yaxpeax_x86::real_mode::DisplayStyle::Intel)).expect("can format");
        assert_eq!(text_buf.text_str(), out);
    };
});