Merge pull request #10 from schumilo/main

add set_input function
This commit is contained in:
Sergej Schumilo 2022-04-12 10:34:36 +02:00 committed by GitHub
commit 0761268962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View File

@ -181,9 +181,8 @@ pub extern "C" fn nyx_set_afl_input(nyx_process: * mut NyxProcess, buffer: *mut
assert!((nyx_process as usize) % std::mem::align_of::<NyxProcess>() == 0);
assert!((buffer as usize) % std::mem::align_of::<u8>() == 0);
std::ptr::copy(&size, (*nyx_process).process.payload.as_mut_ptr() as *mut u32, 1 as usize);
std::ptr::copy(buffer, (*nyx_process).process.payload[std::mem::size_of::<u32>()..].as_mut_ptr(), std::cmp::min(size as usize, (*nyx_process).input_buffer_size()));
}
(*nyx_process).set_input_ptr(buffer, size);
}
}

View File

@ -24,6 +24,23 @@ pub enum NyxReturnValue {
Abort, // Abort hypercall called
}
impl fmt::Display for NyxReturnValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let nyx_return_value_str = match self {
NyxReturnValue::Normal => "Normal",
NyxReturnValue::Crash => "Crash",
NyxReturnValue::Timeout => "Timeout",
NyxReturnValue::InvalidWriteToPayload => "InvalidWriteToPayload",
NyxReturnValue::Abort => "Abort",
NyxReturnValue::Error => "Error",
_ => "Unknown",
};
write!(f, "{}", nyx_return_value_str)
}
}
pub struct NyxProcess {
process: QemuProcess,
}
@ -275,4 +292,15 @@ impl NyxProcess {
}
}
}
pub fn set_input_ptr(&mut self, buffer: *const u8, size: u32) {
unsafe{
std::ptr::copy(&size, self.process.payload.as_mut_ptr() as *mut u32, 1 as usize);
std::ptr::copy(buffer, self.process.payload[std::mem::size_of::<u32>()..].as_mut_ptr(), std::cmp::min(size as usize, self.input_buffer_size()));
}
}
pub fn set_input(&mut self, buffer: &[u8], size: u32) {
self.set_input_ptr(buffer.as_ptr(), size);
}
}