-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pe: add write support for COFF object files #159
Conversation
src/pe/header.rs
Outdated
@@ -41,6 +41,7 @@ pub struct CoffHeader { | |||
pub characteristics: u16, | |||
} | |||
|
|||
/// The size of `COFF_MAGIC` + `CoffHeader`. | |||
pub const SIZEOF_COFF_HEADER: usize = 24; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we should change this value to exclude COFF_MAGIC. It would be a silent breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok breaking the world if we get windows object file writers :) this is why i wanted something like this in before 1.0, because there's unknown unknowns that might break a stable api, which would otherwise have been seen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added another commit with this breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well this is a lot less worse than I thought it'd be! :)
src/pe/section_table.rs
Outdated
impl ctx::IntoCtx<scroll::Endian> for SectionTable { | ||
fn into_ctx(self, bytes: &mut [u8], ctx: scroll::Endian) { | ||
let offset = &mut 0; | ||
bytes.gwrite(&self.name[..], offset).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally one implements the TryIntoCtx variant, and just unwraps that implementation here; why isn't that done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I'm not familiar enough with scroll. I'll fix it.
Along those lines, why do many of the goblin structures have a fn parse
instead of or in addition to implementing TryFromCtx?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was for usually api reasons; I wanted the various parseable "things" to have a pub fn parse
-esque method which made no mention of scroll
in the signature, so someone wouldn't be forced to import both goblin + scroll. Probably in many cases, e.g., Elf::parse
it started off before scroll got written :D (I wrote scroll because I was sick of hand writing stupid byte order field populators, essentially, and adding new parsers or structs was tedious and boring, and refactors or bug fixes were extremely annoying - e.g., multiple times there was some typo read the wrong width out into a variable, or etc.).
I called it parse
, because I like new
to be infallible construction, so it was just parse. And adding the try_from_ctx
impl in elf and to a certain extent mach was an afterthought. If they got added (or not) is just no one has had time to go back and them, or felt the need (since most people use the Object::parse
endpoint afaics.
And that's the whole story about that 😆
E.g., this example was one possible api usage (using raw |
I've verified this is good enough to create an object file that can be linked and execute. May need more in future for exception handling, but I don't know enough about that yet. |
See https://github.com/philipc/object-write/blob/master/src/coff.rs for an example of its usage.