Giter Club home page Giter Club logo

libtracer's Introduction

libtracer

libtracer is callback based ptracing library. It's not in a usable state, and it only supports x86_64 currently and probably forever. Here's an example:

#include "../tracer.h"
#include <stdio.h>
#include <unistd.h>

int read_cb(const char *path) {
  printf("READ_CB::%s\n", path);
  return 0;
}

int main(int argc, char *argv[]) {

  if (argc < 2) {
    fprintf(stderr, "usage: %s program.\n", argv[0]);
    return 1;
  }

  pid_t pid_child = fork();
  if (pid_child == -1) {
    perror("fork()");
    return 1;
  }

  if (pid_child == 0) {
    tracee_init();
    execlp(argv[1], argv[1], (char *)NULL);
    perror("execl()");
    return -1;
  }

  else {
    struct tracer tracer;
    struct tracer_callbacks tracer_cbs = {NULL};
    tracer_cbs.file_read = &read_cb;
    tracer_init(&tracer, &tracer_cbs, pid_child);
    for (;;) {
      if (tracer_loop(&tracer) == -1)
        break;
    }
    return 0;
  }
}

Running the examples

$ git clone this..
$ cd libtracer/examples
$ make
$ ./trace_file_reads ls

the last outputs all file reads that ls makes, for example:

READ_CB::/etc/ld.so.cache
READ_CB::/lib/x86_64-linux-gnu/libselinux.so.1
READ_CB::/lib/x86_64-linux-gnu/libc.so.6
READ_CB::/lib/x86_64-linux-gnu/libpcre.so.3
READ_CB::/lib/x86_64-linux-gnu/libdl.so.2
READ_CB::/lib/x86_64-linux-gnu/libpthread.so.0
READ_CB::/proc/filesystems
READ_CB::/usr/lib/locale/locale-archive
READ_CB::.
Makefile  trace_file_reads  trace_file_reads.c

Supported Callbacks

Currently 3 callbacks are supported, file_read and file_write are gonna break soon to supply absolute path of file open.

tracer_callbacks.file_read

This gets called with the path of a file that was open for reading. Currently a relative path is supplied.

tracer_callbacks.file_write

This gets called with the path of af ile that was open for writing. Currently a relative path is supplied.

tracer_callbacks.syscall

This gets called before every syscall entry with a pointer to the registers, any modifications to the registers would be propogated to the kernel.

libtracer's People

Contributors

nullp0tr avatar

Watchers

 avatar James Cloos avatar

Forkers

kolmar7777

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.