function names refactor
This commit is contained in:
parent
f21453236f
commit
0ae068762f
4 changed files with 16 additions and 16 deletions
2
Makefile
2
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
|
$(CC) $(LDFLAGS) -o $(BIN_DIR)/$@ $(RTDISASM_TEST_OBJ) $(LIB_DIR)/librtdisasm.a
|
||||||
|
|
||||||
blackjack: $(BLACKJACK_OBJ) $(BLACKJACK_DEPS)
|
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)
|
dummy_target: $(DUMMY_TARGET_OBJ)
|
||||||
$(CC) $(LDFLAGS) -o $(BIN_DIR)/$@ $(DUMMY_TARGET_OBJ)
|
$(CC) $(LDFLAGS) -o $(BIN_DIR)/$@ $(DUMMY_TARGET_OBJ)
|
||||||
|
|
|
||||||
|
|
@ -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
|
// 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
|
// will skip any process which status couldn't be parsed
|
||||||
// deallocate list with free later
|
// 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
|
// determine parent process amongst children and set parent pointer to element in list
|
||||||
// process list must consist of parent and children processes,
|
// process list must consist of parent and children processes,
|
||||||
// obtained from processes_by_name call. of course parent pointer shouldn't be NULL
|
// 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
|
// 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);
|
int process_get_threads(pid_t pid, process_status_t** list, size_t* count);
|
||||||
|
|
||||||
// returns 1 if state considered active for a process/thread
|
// 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
|
// 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
|
// 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
|
// 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);
|
int process_attach_all(process_status_t* threads, size_t thread_count);
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,10 @@ int main(int argc, char** argv)
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
|
|
||||||
// find process
|
// find process
|
||||||
processes_by_name("dummy_target", &list, &count);
|
process_by_name("dummy_target", &list, &count);
|
||||||
// get real parent
|
// get real parent
|
||||||
process_status_t* 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);
|
fputs("unable to determine parent process. exiting\n", stderr);
|
||||||
free(list);
|
free(list);
|
||||||
|
|
@ -56,7 +56,7 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
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
|
// no active threads - free list and continue
|
||||||
free(threads);
|
free(threads);
|
||||||
|
|
@ -72,7 +72,7 @@ int main(int argc, char** argv)
|
||||||
puts("Active thread:");
|
puts("Active thread:");
|
||||||
print_process(active);
|
print_process(active);
|
||||||
|
|
||||||
if (!check_ptrace_permissions())
|
if (!process_ptrace_permissions())
|
||||||
{
|
{
|
||||||
fputs("this process doesn't have permission to ptrace.\n", stderr);
|
fputs("this process doesn't have permission to ptrace.\n", stderr);
|
||||||
fputs("either run as root or set caps.\n", stderr);
|
fputs("either run as root or set caps.\n", stderr);
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ static int is_numeric(const char* str)
|
||||||
return 1;
|
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;
|
*list = NULL;
|
||||||
*count = 0;
|
*count = 0;
|
||||||
|
|
@ -130,7 +130,7 @@ static process_status_t* process_by_pid_in_list(pid_t pid, process_status_t* lis
|
||||||
return NULL;
|
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,
|
// we're gonna find any process that doesnt have parent in this list,
|
||||||
// that means we hit real parent, not descendant
|
// 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;
|
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;
|
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++)
|
for (size_t i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
TRACE("task %d state %d\n", list[i].pid, list[i].state);
|
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];
|
*thread = &list[i];
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -219,7 +219,7 @@ int find_active_thread(process_status_t* list, size_t count, process_status_t**
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_ptrace_permissions()
|
int process_ptrace_permissions()
|
||||||
{
|
{
|
||||||
if (!geteuid())
|
if (!geteuid())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue