Skip to content

Commit

Permalink
Detect compiler calls; detach if compiler detected
Browse files Browse the repository at this point in the history
  • Loading branch information
i-ky committed Feb 25, 2023
1 parent d7ad848 commit 98dc27d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/basset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <linux/ptrace.h>

#undef PTRACE_CONT
#undef PTRACE_DETACH
#undef PTRACE_SETOPTIONS
#undef PTRACE_TRACEME

Expand Down Expand Up @@ -134,7 +135,12 @@ int main(int argc, char *argv[]) {
return -1;
}

out << string(exe, ret) << '\n';
string executable(exe, ret);

if (executable.find("gcc") == string::npos &&
executable.find("g++") == string::npos) {
break;
}

char cwd[PATH_MAX];
ret = readlink(("/proc/" + to_string(pid) + "/cwd").c_str(), cwd,
Expand All @@ -158,7 +164,12 @@ int main(int argc, char *argv[]) {
return -1;
}

break;
if (ptrace(PTRACE_DETACH, pid, nullptr, nullptr) == -1) {
perror("cannot ptrace(PTRACE_DETACH)");
return -1;
}

continue;
}
case PTRACE_EVENT_CLONE:
case PTRACE_EVENT_FORK:
Expand Down

0 comments on commit 98dc27d

Please sign in to comment.