Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
liberize committed Dec 9, 2024
1 parent 0fa3399 commit 12bcf22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/untraceable.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ FORCE_INLINE void check_debugger(bool full, bool parent) {
snprintf(path, sizeof(path), OBF("/proc/%d/status"), parent ? getppid() : getpid());
std::ifstream ifs(path);
std::string line, needle = OBF("TracerPid:\t");
int tracer_pid = 0;
pid_t tracer_pid = 0;
while (std::getline(ifs, line)) {
auto idx = line.find(needle);
if (idx != std::string::npos) {
tracer_pid = atoi(line.c_str() + idx + needle.size());
if (str_starts_with(line, needle)) {
tracer_pid = atoi(line.c_str() + needle.size());
break;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ FORCE_INLINE std::string base_name(const std::string& s) {
return s.substr(s.find_last_of("\\/") + 1);
}

FORCE_INLINE bool str_starts_with(const std::string& s, const std::string& e) {
return s.size() >= e.size() && s.compare(0, e.size(), e) == 0;
}

FORCE_INLINE bool str_ends_with(const std::string& s, const std::string& e) {
return s.size() >= e.size() && s.compare(s.size() - e.size(), e.size(), e) == 0;
}
Expand Down Expand Up @@ -180,7 +184,7 @@ FORCE_INLINE void check_pipe_reader(int fd) {
if (entry->d_type != DT_DIR)
continue;
char *end = nullptr;
auto pid = strtoul(entry->d_name, &end, 10);
auto pid = strtol(entry->d_name, &end, 10);
if (!pid || *end)
continue;
if (pid == mypid || pid == ppid)
Expand Down

0 comments on commit 12bcf22

Please sign in to comment.