Skip to content

Commit

Permalink
Update wait process
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyesiqiu committed Jun 24, 2024
1 parent b05dc1f commit 3ebaa2f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions shell/src/main/cpp/dpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ jstring readApplicationName(JNIEnv *env, jclass __unused) {
}

void createAntiRiskProcess() {
int child = fork();
pid_t child = fork();
if(child < 0) {
DLOGW("%s fork fail!", __FUNCTION__);
detectFrida();
Expand All @@ -233,7 +233,7 @@ void createAntiRiskProcess() {
doPtrace();
}
else {
DLOGD("%s in main process, child pid: %d", __FUNCTION__, getpid());
DLOGD("%s in main process, child pid: %d", __FUNCTION__, child);
protectChildProcess(child);
detectFrida();
}
Expand Down
20 changes: 15 additions & 5 deletions shell/src/main/cpp/dpt_risk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,26 @@ void doPtrace() {
DLOGD("doPtrace result: %d",ret);
}

void *protectProcessOnThread(__unused void *args) {
int pid = wait(NULL);
void *protectProcessOnThread(void *args) {
pid_t child = *((pid_t *)args);

DLOGD("%s waitpid %d", __FUNCTION__ ,child);

free(args);

int pid = waitpid(child, nullptr, 0);
if(pid > 0) {
DLOGD("%s detect child process %d exit!", __FUNCTION__, pid);
DLOGW("%s detect child process %d exited", __FUNCTION__, pid);
crash();
}
DLOGD("%s waitpid %d end", __FUNCTION__ ,child);

return nullptr;
}

void protectChildProcess(int pid) {
void protectChildProcess(pid_t pid) {
pthread_t t;
pthread_create(&t, nullptr,protectProcessOnThread,&pid);
pid_t *child = (pid_t *) malloc(sizeof(pid_t));
*child = pid;
pthread_create(&t, nullptr,protectProcessOnThread,child);
}
2 changes: 1 addition & 1 deletion shell/src/main/cpp/dpt_risk.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
void crash();
void detectFrida();
void doPtrace();
void protectChildProcess(int pid);
void protectChildProcess(pid_t pid);
void junkCodeDexProtect(JNIEnv *env);

#endif //DPT_DPT_RISK_H

0 comments on commit 3ebaa2f

Please sign in to comment.