Giter VIP home page Giter VIP logo

Comments (4)

cfc4n avatar cfc4n commented on May 18, 2024 1

the same code as bash_kern.c in https://github.com/iovisor/bcc/blob/master/tools/bashreadline.py

from ecapture.

huzai9527 avatar huzai9527 commented on May 18, 2024

when i use BCC to impliment bash-kern, I always get such as the picture show
image
the code just as same as the kern/bash_kern.c, can you tell me what's wrong?
THANK YOU!

from ecapture.

huzai9527 avatar huzai9527 commented on May 18, 2024

the code

from bcc import BPF
from time import sleep
text = """
#include <uapi/linux/ptrace.h>
struct event_data_t {
	u32 pid;
	u8 line[80];
	char comm[16];
};
BPF_PERF_OUTPUT(listen_evt);
int uretprobe_bash_readline(struct pt_regs *ctx) {
    s64 pid_tgid = bpf_get_current_pid_tgid();
    int pid = pid_tgid >> 32;
    struct event_data_t event = {};
    event.pid = pid;
    bpf_get_current_comm(&event.comm, sizeof(event.comm));
    bpf_probe_read(&event.line, sizeof(event.line), (void *)PT_REGS_RC(ctx));
    listen_evt.perf_submit(ctx, &event, sizeof(event));
    return 0;
}

"""
from  ctypes import *
b = BPF(text=text)
b.attach_uprobe(name="/bin/bash",sym="readline",fn_name="uretprobe_bash_readline")


def print_event(cpu, data, size):
  event = b["listen_evt"].event(data)
  #line = bytearray(event.line).decode()
  print("Rcv Event %d, %s,%s"%(event.pid, event.comm,bytes(event.line)))
b["listen_evt"].open_perf_buffer(print_event)

while True:
    try:
        b.perf_buffer_poll()
    except:
        exit()

from ecapture.

huzai9527 avatar huzai9527 commented on May 18, 2024

THANK YOU

from ecapture.

Related Issues (20)

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.