pe work
This commit is contained in:
+38
-10
@@ -5,6 +5,11 @@ use crate::{
|
||||
use std::{fs::OpenOptions, io::Write, os::unix::fs::OpenOptionsExt, process::Command};
|
||||
|
||||
pub fn run() {
|
||||
windows();
|
||||
// linux();
|
||||
}
|
||||
|
||||
fn linux() {
|
||||
let mut program = Program::<X86_64>::default();
|
||||
let text = b"Hello world!\n";
|
||||
let text_sym = program.ro_data(text);
|
||||
@@ -39,16 +44,7 @@ pub fn run() {
|
||||
let linked = program.compile().expect("failed to compile");
|
||||
let binary = linked.to_elf();
|
||||
let path = "./x86_64_test";
|
||||
let mut file = OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.mode(0o750)
|
||||
.open(path)
|
||||
.expect("Failed to create file");
|
||||
file.write_all(&binary).expect("Failed to write to file");
|
||||
file.sync_all().expect("Failed to sync file");
|
||||
drop(file);
|
||||
write(path, &binary);
|
||||
println!("running...");
|
||||
let gdb = false;
|
||||
let mut proc = if gdb {
|
||||
@@ -72,3 +68,35 @@ pub fn run() {
|
||||
std::process::exit(code);
|
||||
}
|
||||
}
|
||||
|
||||
fn windows() {
|
||||
let mut program = Program::<X86_64>::default();
|
||||
let entry = program.func([BInstr::Asm(Asm {
|
||||
instrs: vec![push(39), pop(rax), Instr::Ret],
|
||||
})]);
|
||||
program.entry = Some(entry);
|
||||
let linked = program.compile().expect("failed to compile");
|
||||
let binary = linked.to_pe();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
fn write(path: &str, binary: &[u8]) {
|
||||
let mut file = OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.mode(0o750)
|
||||
.open(path)
|
||||
.expect("Failed to create file");
|
||||
file.write_all(binary).expect("Failed to write to file");
|
||||
file.sync_all().expect("Failed to sync file");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user