PE import start (fixed header size -> sections work)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
arch::x86_64::*,
|
||||
backend::{Instr as BInstr, Program},
|
||||
backend::{Instr as BInstr, Program, pe::Import},
|
||||
};
|
||||
use std::{fs::OpenOptions, io::Write, os::unix::fs::OpenOptionsExt, process::Command};
|
||||
|
||||
@@ -76,17 +76,25 @@ fn windows() {
|
||||
})]);
|
||||
program.entry = Some(entry);
|
||||
let linked = program.compile().expect("failed to compile");
|
||||
let binary = linked.to_pe();
|
||||
|
||||
let imports = &[Import {
|
||||
name: "KERNEL32.dll".to_string(),
|
||||
names: ["GetStdHandle", "WriteFile", "ExitProcess"]
|
||||
.map(String::from)
|
||||
.to_vec(),
|
||||
}];
|
||||
|
||||
let binary = linked.to_pe(imports);
|
||||
let path = "./x86_64_test.exe";
|
||||
write(path, &binary);
|
||||
|
||||
let mut cmd = Command::new("wine");
|
||||
cmd.arg("x86_64_test");
|
||||
let mut proc = cmd.spawn().expect("failed to run");
|
||||
let status = proc.wait().expect("failed to wait");
|
||||
if let Some(code) = status.code() {
|
||||
std::process::exit(code);
|
||||
}
|
||||
// let mut cmd = Command::new("wine");
|
||||
// cmd.arg("x86_64_test");
|
||||
// let mut proc = cmd.spawn().expect("failed to run");
|
||||
// let status = proc.wait().expect("failed to wait");
|
||||
// if let Some(code) = status.code() {
|
||||
// std::process::exit(code);
|
||||
// }
|
||||
}
|
||||
|
||||
fn write(path: &str, binary: &[u8]) {
|
||||
|
||||
Reference in New Issue
Block a user