Skip to content
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

Merged
merged 3 commits into from
May 3, 2019
Merged

Conversation

philipc
Copy link
Collaborator

@philipc philipc commented May 1, 2019

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;
Copy link
Collaborator Author

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.

Copy link
Owner

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

Copy link
Collaborator Author

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.

Copy link
Owner

@m4b m4b left a 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! :)

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();
Copy link
Owner

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?

Copy link
Collaborator Author

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?

Copy link
Owner

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 😆

@m4b
Copy link
Owner

m4b commented May 1, 2019

E.g., this example was one possible api usage (using raw pread), and is still possible, but it requires one to import scroll + goblin, which is annoying imho. But it sure seems cool to me to pread an elf object :) https://github.com//m4b/goblin/blob/779d0ce835bb325327f39157ea8fdb8882daa171/examples/scroll.rs#L22

@philipc philipc merged commit 119755e into m4b:master May 3, 2019
@philipc
Copy link
Collaborator Author

philipc commented May 3, 2019

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.

@philipc philipc deleted the coff branch May 3, 2019 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants