diff --git a/src/basset.cpp b/src/basset.cpp index eeae880..46f590e 100644 --- a/src/basset.cpp +++ b/src/basset.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #undef PTRACE_CONT @@ -11,11 +12,14 @@ #undef PTRACE_TRACEME #include +#include #include #include using std::cerr; +using std::ifstream; using std::string; +using std::to_string; int main(int argc, char *argv[]) { argv++; @@ -63,8 +67,42 @@ int main(int argc, char *argv[]) { if (WSTOPSIG(wstatus) == SIGTRAP) { switch (wstatus >> 16) { + case PTRACE_EVENT_EXEC: { + char exe[PATH_MAX]; + auto ret = readlink(("/proc/" + to_string(pid) + "/exe").c_str(), + exe, sizeof(exe)); + + if (ret == -1) { + perror("cannot readlink(\"/proc/[pid]/exe\")"); + return -1; + } + + cerr << string(exe, ret) << '\n'; + + char cwd[PATH_MAX]; + ret = readlink(("/proc/" + to_string(pid) + "/cwd").c_str(), cwd, + sizeof(cwd)); + + if (ret == -1) { + perror("cannot readlink(\"/proc/[pid]/cwd\")"); + return -1; + } + + cerr << string(cwd, ret) << '\n'; + + ifstream cmdline("/proc/" + to_string(pid) + "/cmdline"); + + for (string arg; getline(cmdline, arg, '\0');) { + cerr << '\t' << arg.data() << '\n'; + } + + if (!cmdline.eof()) { + cerr << "failed to read /proc/[pid]/cmdline\n"; + } + + break; + } case PTRACE_EVENT_CLONE: - case PTRACE_EVENT_EXEC: case PTRACE_EVENT_FORK: case PTRACE_EVENT_VFORK: break;