Skip to content

Commit 7b5f7f1

Browse files
committed
examples(pe): add a section adder
1 parent f85c139 commit 7b5f7f1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

examples/pe_add_section.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use std::borrow::Cow;
2+
3+
use goblin::pe::{PE, writer::PEWriter, section_table::{SectionTable, Section, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ}};
4+
use scroll::Pwrite;
5+
6+
fn main() {
7+
stderrlog::new().verbosity(1).init().unwrap();
8+
let args: Vec<String> = std::env::args().collect();
9+
10+
let file = std::fs::read(&args[1]).unwrap();
11+
let file = &file[..];
12+
let pe = PE::parse(file).unwrap();
13+
println!("{}", file.len());
14+
let mut pe_writer = PEWriter::new(pe).expect("Failed to create a wrapper");
15+
16+
let section_name: [u8; 8] = [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0];
17+
pe_writer.insert_section(
18+
Section::new(
19+
&section_name,
20+
Some(Cow::Borrowed(&[0x0])),
21+
IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ
22+
).expect("Failed to create a section")
23+
).unwrap();
24+
25+
let new_pe = pe_writer.write_into().unwrap();
26+
}

0 commit comments

Comments
 (0)