diff --git a/Makefile b/Makefile index 3d5e89a..7aec014 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ rtdisasm_test: $(RTDISASM_TEST_OBJ) $(RTDISASM_TEST_DEPS) $(CC) $(LDFLAGS) -o $(BIN_DIR)/$@ $(RTDISASM_TEST_OBJ) $(LIB_DIR)/librtdisasm.a blackjack: $(BLACKJACK_OBJ) $(BLACKJACK_DEPS) - $(CC) $(LDFLAGS) $(LIB_DIR)/librtdisasm.a -o $(BIN_DIR)/$@ $(BLACKJACK_OBJ) + $(CC) $(LDFLAGS) -o $(BIN_DIR)/$@ $(BLACKJACK_OBJ) $(LIB_DIR)/librtdisasm.a dummy_target: $(DUMMY_TARGET_OBJ) $(CC) $(LDFLAGS) -o $(BIN_DIR)/$@ $(DUMMY_TARGET_OBJ) diff --git a/include/process.h b/include/process.h index e72d5bb..7a6dbb4 100644 --- a/include/process.h +++ b/include/process.h @@ -37,24 +37,24 @@ int process_parse_status(pid_t pid, process_status_t* status); // list pointer must point to NULL-initialized pointer, and count pointer must pount to initialized 0 // will skip any process which status couldn't be parsed // deallocate list with free later -int processes_by_name(const char* name, process_status_t** list, size_t* count); +int process_by_name(const char* name, process_status_t** list, size_t* count); // determine parent process amongst children and set parent pointer to element in list // process list must consist of parent and children processes, // obtained from processes_by_name call. of course parent pointer shouldn't be NULL -int determine_parent_process(process_status_t* list, size_t count, process_status_t** parent); +int process_determine_parent(process_status_t* list, size_t count, process_status_t** parent); // get all process threads. for list and count same rules applies as for processes_by_name int process_get_threads(pid_t pid, process_status_t** list, size_t* count); // returns 1 if state considered active for a process/thread -int is_considered_active(process_state_t state); +int process_is_considered_active(process_state_t state); // find any active (running) thread and returns 0 and success, otherwise non zero -int find_active_thread(process_status_t* list, size_t count, process_status_t** thread); +int process_find_active(process_status_t* list, size_t count, process_status_t** thread); // check if this process has any capability or is ran as root to be able to ptrace attach -int check_ptrace_permissions(); +int process_ptrace_permissions(); // attach to all threads of the process. on error returns 1 and detaches from already attached int process_attach_all(process_status_t* threads, size_t thread_count); diff --git a/src/main.c b/src/main.c index 910e9dc..9889fc2 100644 --- a/src/main.c +++ b/src/main.c @@ -28,10 +28,10 @@ int main(int argc, char** argv) size_t count = 0; // find process - processes_by_name("dummy_target", &list, &count); + process_by_name("dummy_target", &list, &count); // get real parent process_status_t* parent; - if (determine_parent_process(list, count, &parent)) + if (process_determine_parent(list, count, &parent)) { fputs("unable to determine parent process. exiting\n", stderr); free(list); @@ -56,7 +56,7 @@ int main(int argc, char** argv) return 1; } - if (find_active_thread(threads, thread_count, &active)) + if (process_find_active(threads, thread_count, &active)) { // no active threads - free list and continue free(threads); @@ -72,7 +72,7 @@ int main(int argc, char** argv) puts("Active thread:"); print_process(active); - if (!check_ptrace_permissions()) + if (!process_ptrace_permissions()) { fputs("this process doesn't have permission to ptrace.\n", stderr); fputs("either run as root or set caps.\n", stderr); diff --git a/src/process.c b/src/process.c index aed183f..94db12b 100644 --- a/src/process.c +++ b/src/process.c @@ -71,7 +71,7 @@ static int is_numeric(const char* str) return 1; } -int processes_by_name(const char* name, process_status_t** list, size_t* count) +int process_by_name(const char* name, process_status_t** list, size_t* count) { *list = NULL; *count = 0; @@ -130,7 +130,7 @@ static process_status_t* process_by_pid_in_list(pid_t pid, process_status_t* lis return NULL; } -int determine_parent_process(process_status_t* list, size_t count, process_status_t** parent) +int process_determine_parent(process_status_t* list, size_t count, process_status_t** parent) { // we're gonna find any process that doesnt have parent in this list, // that means we hit real parent, not descendant @@ -200,17 +200,17 @@ int process_get_threads(pid_t pid, process_status_t** list, size_t* count) return 0; } -int is_considered_active(process_state_t state) +int process_is_considered_active(process_state_t state) { return state == INTERRUPTIBLE_SLEEP || state == RUNNING; } -int find_active_thread(process_status_t* list, size_t count, process_status_t** thread) +int process_find_active(process_status_t* list, size_t count, process_status_t** thread) { for (size_t i = 0; i < count; i++) { TRACE("task %d state %d\n", list[i].pid, list[i].state); - if (is_considered_active(list[i].state)) + if (process_is_considered_active(list[i].state)) { *thread = &list[i]; return 0; @@ -219,7 +219,7 @@ int find_active_thread(process_status_t* list, size_t count, process_status_t** return 1; } -int check_ptrace_permissions() +int process_ptrace_permissions() { if (!geteuid()) {