Skip to content

Commit

Permalink
impl TryIntoCtx for DosStub
Browse files Browse the repository at this point in the history
  • Loading branch information
kkent030315 committed Oct 25, 2024
1 parent d204a9b commit 67e5e0f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/pe/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::error;
use crate::pe::{data_directories, debug, optional_header, section_table, symbol};
use crate::strtab;
use alloc::vec::Vec;
use scroll::{ctx, IOread, IOwrite, Pread, Pwrite, SizeWith};
use scroll::{ctx, Cwrite, IOread, IOwrite, Pread, Pwrite, SizeWith};

/// In `winnt.h` and `pe.h`, it's `IMAGE_DOS_HEADER`. It's a DOS header present in all PE binaries.
///
Expand Down Expand Up @@ -381,7 +381,7 @@ impl DosHeader {
}

#[repr(C)]
#[derive(Debug, PartialEq, Clone, Pread, Pwrite)]
#[derive(Debug, PartialEq, Clone)]
/// The DOS stub program which should be executed in DOS mode. It prints the message "This program cannot be run in DOS mode" and exits.
///
/// ## Position in a modern PE file
Expand Down Expand Up @@ -441,6 +441,15 @@ impl Default for DosStub {
}
}
}
impl ctx::TryIntoCtx<scroll::Endian> for DosStub {
type Error = error::Error;

fn try_into_ctx(self, bytes: &mut [u8], _: scroll::Endian) -> Result<usize, Self::Error> {
let offset = &mut 0;
bytes.gwrite_with(&*self.data, offset, ())?;
Ok(*offset)
}
}

impl DosStub {
/// Parse the DOS stub.
Expand Down

0 comments on commit 67e5e0f

Please sign in to comment.