Open PinkNoize opened 3 months ago
Interesting! So I'd like to hear a little bit more about your usecase, if you don't mind; it sounds like you might be using/wanting to use goblin for parsing elf structures in a no_std environment, is that correct? And if so, you why doesn't pread
work for you in that environment?
My first worry about adding Cread/Cwrite
implementations is that it will be fairly redundant for the various types w.r.t. their Pread
implementations (although many of them are also derived), which could be a maintenance burden.
I'm also wondering how useful cread is after e.g., header/program_header, section_header, etc. in general all the remaining stuff is fairly fallible, so I don't think FromCtx impls are a great match there, semantically? Anyway, that doesn't mean no, just curious to solicit more information about your usecases, and etc. :)
I'm working on making some reference implementations for elf infectors so that would be parsing, modifying and writing elf structures in a no_std and no alloc environment. As its no alloc, pread
/pwrite
aren't available for these structs.
I'm also wondering how useful cread is after e.g., header/program_header, section_header, etc. in general all the remaining stuff is fairly fallible
Cread/Cwrite isn't really necessary as all these structs are Plain
and can be converted to and from bytes with plain functions. I figured I'd ask as the scroll traits seem a bit nicer to use.
// cread
let h: Header = plain::from_mut_bytes(buf[offset..offset + mem::size_of::<Header>()]);
h.ph_num = 5;
// cwrite
let bytes = unsafe { plain::as_bytes(h) };
All the
#[repr(C)]
structs implement Pread/Pwrite but do not implement Cread/Cwrite which is useful in no_std environments.I'd be happy to implement Cread/Cwrite for the ELF structs (with tests), but wanted to know if this is something that is wanted for the project and if the implementation below is the recommend way to do this.
Here is my implementation for the ELF header: