Skip to content

Commit

Permalink
examples(pe): add a section adder
Browse files Browse the repository at this point in the history
  • Loading branch information
RaitoBezarius committed Oct 4, 2023
1 parent f85c139 commit 7b5f7f1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/pe_add_section.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::borrow::Cow;

use goblin::pe::{PE, writer::PEWriter, section_table::{SectionTable, Section, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ}};
use scroll::Pwrite;

fn main() {
stderrlog::new().verbosity(1).init().unwrap();
let args: Vec<String> = std::env::args().collect();

let file = std::fs::read(&args[1]).unwrap();
let file = &file[..];
let pe = PE::parse(file).unwrap();
println!("{}", file.len());
let mut pe_writer = PEWriter::new(pe).expect("Failed to create a wrapper");

let section_name: [u8; 8] = [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0];
pe_writer.insert_section(
Section::new(
&section_name,
Some(Cow::Borrowed(&[0x0])),
IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ
).expect("Failed to create a section")
).unwrap();

let new_pe = pe_writer.write_into().unwrap();
}

0 comments on commit 7b5f7f1

Please sign in to comment.