5 releases
0.1.1 | Aug 29, 2022 |
---|---|
0.1.0 | Aug 22, 2022 |
0.0.3 | Aug 19, 2022 |
0.0.2 | Aug 16, 2022 |
0.0.1 | Aug 15, 2022 |
#991 in Asynchronous
25KB
535 lines
io-tubes
Provides tube functionality like the python library pwntools.
More examples and documentation can be found at docs.rs
Example
use io_tubes::tubes::Tube;
use std::io;
#[tokio::main]
async fn main() -> io::Result<()> {
let mut p = Tube::process("/usr/bin/cat")?;
// "Hello World!" will be automatically converted to `&[u8]`
// Alternatively, you can explicitly use b"Hello World!" if it contains invalid UTF-8.
p.send("Hello World!").await?;
// You can use any type that implements `AsRef<[u8]>`
let output = p.recv_until(b"World".to_vec()).await?;
assert_eq!(output, b"Hello World");
Ok(())
}
lib.rs
:
Tubes
Provides tube functionality like the python library pwntools.
The methods are provided in the struct Tube
Example:
use io_tubes::tubes::Tube;
use std::io;
#[tokio::main]
async fn demo() -> io::Result<()> {
let mut p = Tube::process("/usr/bin/cat")?;
// "Hello World!" will be automatically converted to `&[u8]`
// Alternatively, you can explicitly use b"Hello World!" if it contains invalid UTF-8.
p.send("Hello World!").await?;
// You can use any type that implements `AsRef<[u8]>`
let output = p.recv_until(b"World".to_vec()).await?;
assert_eq!(output, b"Hello World");
Ok(())
}
demo();
Any type that implement AsyncRead
+ AsyncWrite
can
make use of Tube::new
to create a new tube.
use io_tubes::tubes::{Listener, Tube};
use std::io;
use tokio::net::TcpStream;
#[tokio::main]
async fn create_remote() -> io::Result<()> {
let l = Listener::bind("0.0.0.0:1337").await?;
// The followings are equivalent `Tube<BufReader<TcpStream>>`.
let mut p = Tube::remote("127.0.0.1:1337").await?;
let mut p = Tube::new(TcpStream::connect("127.0.0.1:1337").await?);
Ok(())
}
create_remote();
Dependencies
~2.4–8MB
~60K SLoC