Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomcur/cpy-walker
A pure-Rust CPython remote-process memory walker
https://github.com/tomcur/cpy-walker
Last synced: about 14 hours ago
JSON representation
A pure-Rust CPython remote-process memory walker
- Host: GitHub
- URL: https://github.com/tomcur/cpy-walker
- Owner: tomcur
- License: mit
- Created: 2020-12-07T14:24:09.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-23T20:26:23.000Z (about 4 years ago)
- Last Synced: 2024-11-09T02:25:49.875Z (about 2 months ago)
- Language: Rust
- Size: 42 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cpy-walker
An experimental, remote CPython process memory walker.
This library enables you to connect to a CPython process and read its memory into Rust datatypes.Currently (a subset of) CPython 2.7 is implemented.
## Example
The library only knows how to read objects and follow object pointers.
It cannot find objects by itself; you need to provide a memory address to start from.```rust
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use std::process::{Command, Stdio};use cpy_walker::cpython27::*;
use cpy_walker::interpreter::*;
use cpy_walker::memory::{Memory, Process};
use cpy_walker::walker::walk;/// This spawns a Python process, but you can connect to pre-existing processes as well.
fn spawn_child() -> Result<(i32, usize), Box> {
let child = Command::new(
[env!("CARGO_MANIFEST_DIR"), "test-programs", "python27.py"]
.iter()
.collect::(),
)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::null())
.spawn()?;let pid = child.id();
let stdout = child.stdout.unwrap();let mut line = String::new();
BufReader::new(stdout).read_line(&mut line)?;
let pointer: usize = line.trim().parse().expect("memory address");Ok((pid as i32, pointer))
}fn main() -> Result<(), Box> {
let (pid, pointer) = spawn_child()?;
let mem = cpy_walker::connect(pid)?;
let ptr = Pointer::new(pointer);println!(
"Data graph: {:#x?}",
walk::(&mem, ptr)
);Ok(())
}
```## Other crates
See also:
- [py-spy](https://github.com/benfred/py-spy) - a Python process profiler. It can find Python stacks and its locals. Useful to find memory adddress entry-points.
## License
This project is licensed under the [MIT license].
[mit license]: https://github.com/tomcur/cpy-walker/blob/master/LICENSE
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in cpy-walker by you, shall be licensed as MIT, without any additional
terms or conditions.