Created
October 6, 2022 10:26
-
-
Save eterps/d70591a2f6e7f9822e5ef49d0958b82b to your computer and use it in GitHub Desktop.
Call write syscall on x86-64 Linux in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::arch::asm; | |
fn main() { | |
let str = b"Hello world\n"; | |
unsafe { | |
let res = syswrite(str.as_ptr() as u64, str.len() as u64); | |
println!("res: {}", res); | |
} | |
} | |
unsafe fn syswrite(strptr: u64, strlen: u64) -> i64 { | |
let res: i64; | |
asm!( | |
"syscall", | |
in("rax") 1, | |
in("rdi") 1, | |
in("rsi") strptr, | |
in("rdx") strlen, | |
lateout("rax") res | |
); | |
res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment