Giter VIP home page Giter VIP logo

hstrace's Introduction

Syscall tracing CLI & library

Build Status Latest Version Rust Documentation License Lines of Code

Syscall tracing from command line and as a library. See the design draft: https://github.com/blaind/hstrace/blob/master/docs/01_hstrace_plan.md

Requires Linux kernel 5.3 or later (uses PTRACE_GET_SYSCALL_INFO API)

This is a WIP implementation, and not production ready. Might not be finished. Multiple issues exist: 1) codebase is not ready to be expanded yet, major refactoring is needed especially for the AV and Value structs to be more generic, 2) attach to process is not instant, some calls are missed at beginning, 3) not all syscalls are implemented, 4) cross-platform support is missing, 5) as a comparison, strace codebase is over 200k LoC in total (incl comments), so finishing the work is quite an undertaking

Prequisites

Install dependencies:

$ apt-get install libclang1

Command line tool

Syscall-output

Install the binary:

$ cargo install hstrace

Run the command

$ hstrace -h

hstrace for stracing processes

USAGE:
    hstrace [FLAGS] [OPTIONS] <prog>...

FLAGS:
    -h, --help         Prints help information
        --no-follow    Do not follow child processes as they are created
    -V, --version      Prints version information

OPTIONS:
    -e <expr>           Expression
    -m <mode>           Run mode [default: strace]
    -o <file>           Save output to a file instead of stderr. If suffix is `.json`, will be stored in JSON-format
                        (format subject to change)
    -p <pid>            PID to trace
    -s <strsize>        Maximum length of printable strings [default: 32]

ARGS:
    <prog>...    Program to strace

Stracing library

Usage

Add this to your Cargo.toml:

[dependencies]
hstrace = "0.0.4"

And this to your code:

use hstrace::prelude::*;

fn main() {
    let mut tracer = HStraceBuilder::new().program("ps").arg("uxaw").build();

    tracer.start().unwrap();

    for syscall in tracer.iter_as_syscall() {
        match syscall.name {
            hstrace::Ident::Openat | hstrace::Ident::Fstat | hstrace::Ident::Stat => {
                println!("File operation detected: {:?}", syscall);
            }

            hstrace::Ident::Socket | hstrace::Ident::Bind | hstrace::Ident::Connect => {
                println!("Network operation detected: {:?}", syscall);
            }

            _ => (),
        }
    }
}

See examples/03_match_syscall_name.rs and other examples.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

hstrace's People

Contributors

blaind avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

lexxvir palfrey

hstrace's Issues

"primitive conversion" panic

This is a build based off of #13 but I didn't think it would break things this badly. Any idea how to solve this one?

thread 'build_zsh' panicked at 'primitive conversion', /home/palfrey/.cargo/git/checkouts/hstrace-de21f6094a22c832/6f7a453/src/call/mod.rs:29:1
stack backtrace:
   0:     0x55a9180c334c - <unknown>
   1:     0x55a9180ede5c - <unknown>
   2:     0x55a9180bb1a8 - <unknown>
   3:     0x55a9180c5927 - <unknown>
   4:     0x55a9180c55df - <unknown>
   5:     0x55a9180c618b - <unknown>
   6:     0x55a9180c5e77 - <unknown>
   7:     0x55a9180c3814 - <unknown>
   8:     0x55a9180c5b89 - <unknown>
   9:     0x55a9180ec203 - <unknown>
  10:     0x55a9180ec0c1 - <unknown>
  11:     0x55a9180ec06b - <unknown>
  12:     0x55a9180ebdb6 - <unknown>

(lots more frames with <unknown>)

Pid with Systrace

Hey, I'm looking into using hstrace for a utility im working on but strugling tracing both parent and child processes. It seems like coupling pid with syscall in the crossbeam_chanel as a touple would keep things clearer when collecting calls from parent and child processes. You could simply forward each child into a central channel or chain iterators into a single match.

Is there an easier way to do this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.