-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add more syscalls and better signal handling
- Loading branch information
Showing
14 changed files
with
248 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#define _XOPEN_SOURCE | ||
#define _XOPEN_SOURCE_EXTENDED 1 | ||
|
||
#include <analysis.h> | ||
#include <ft_printf.h> | ||
#include <ft_strace_utils.h> | ||
#include <ft_string.h> | ||
#include <signal.h> | ||
#include <sys/ptrace.h> | ||
#include <syscall_strace.h> | ||
|
||
/** | ||
* @brief Handle the signal raised by the tracee | ||
* | ||
* @param pid the pid of the tracee | ||
*/ | ||
int signals_handle(pid_t pid, int *cont_signal, analysis_routine_data_t *data) | ||
{ | ||
siginfo_t siginfo = {0}; | ||
if (ptrace(PTRACE_GETSIGINFO, pid, 0, &siginfo) < 0) | ||
{ | ||
log_error("handle_signal", "ptrace(PTRACE_GETSIGINFO) failed", true); | ||
return SIG_RAISED; | ||
} | ||
if (siginfo.si_signo == SIGTRAP && siginfo.si_code == TRAP_UNK) | ||
{ | ||
return NO_STATUS; | ||
} | ||
if (siginfo.si_signo == SIGSTOP && siginfo.si_code != SI_TKILL) | ||
{ | ||
*cont_signal = SIGSTOP; | ||
return SIG_RAISED; | ||
} | ||
if (data->status == ENCOUNTERED) | ||
ft_printf("--- %s {si_signo=%s, si_code=%s, si_pid=%d, si_uid=%d} ---\n", | ||
ft_signalname(siginfo.si_signo), ft_signalname(siginfo.si_signo), | ||
ft_sicodename(siginfo.si_signo, siginfo.si_code), siginfo.si_pid, siginfo.si_uid); | ||
*cont_signal = siginfo.si_signo; | ||
return SIG_RAISED; | ||
} |
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#define _GNU_SOURCE | ||
|
||
#include "param_log.h" | ||
#include <ft_printf.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <macros.h> | ||
|
||
typedef struct { | ||
uint64_t flag; | ||
const char *str; | ||
} flag_str_t; | ||
|
||
#define FLAG_STR(flag) {flag, #flag} | ||
|
||
static const flag_str_t flags[] = { | ||
FLAG_STR(O_RDONLY), | ||
FLAG_STR(O_WRONLY), | ||
FLAG_STR(O_RDWR), | ||
FLAG_STR(O_CREAT), | ||
FLAG_STR(O_EXCL), | ||
FLAG_STR(O_NOCTTY), | ||
FLAG_STR(O_TRUNC), | ||
FLAG_STR(O_APPEND), | ||
FLAG_STR(O_NONBLOCK), | ||
FLAG_STR(O_DSYNC), | ||
FLAG_STR(O_ASYNC), | ||
FLAG_STR(O_DIRECT), | ||
FLAG_STR(O_LARGEFILE), | ||
FLAG_STR(O_DIRECTORY), | ||
FLAG_STR(O_NOFOLLOW), | ||
FLAG_STR(O_NOATIME), | ||
FLAG_STR(O_CLOEXEC), | ||
FLAG_STR(O_PATH), | ||
FLAG_STR(O_TMPFILE), | ||
}; | ||
|
||
/** | ||
* @brief Log open flags | ||
* | ||
* @param value the value to log | ||
*/ | ||
void log_OPEN_FLAGS(uint64_t value) | ||
{ | ||
bool_t first = true; | ||
for (size_t i = 0; i < ELEM_COUNT(flags); i++) | ||
{ | ||
if (value & flags[i].flag) | ||
{ | ||
if (!first) | ||
ft_dprintf(STDERR_FILENO, "|"); | ||
ft_dprintf(STDERR_FILENO, "%s", flags[i].str); | ||
first = false; | ||
value &= ~flags[i].flag; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "param_log.h" | ||
#include <ft_printf.h> | ||
|
||
/** | ||
* @brief Log open mode | ||
* | ||
* @param value the value to log | ||
*/ | ||
void log_OPEN_MODE(uint64_t value) | ||
{ | ||
ft_dprintf(STDERR_FILENO, "%#o", value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#define _GNU_SOURCE | ||
|
||
#include "param_log.h" | ||
#include <ft_printf.h> | ||
#include <ft_strace_utils.h> | ||
#include <ft_string.h> | ||
#include <registers.h> | ||
#include <sys/uio.h> | ||
|
||
#define DEFAULT_BUFFER_SIZE 32 | ||
|
||
typedef struct | ||
{ | ||
char *buffer; | ||
size_t size_buffer; | ||
size_t index; | ||
} buffer_t; | ||
|
||
static void buffer_add_char(buffer_t *buffer, char c) | ||
{ | ||
if (buffer->index >= buffer->size_buffer) | ||
{ | ||
buffer->size_buffer *= 2; | ||
buffer->buffer = realloc(buffer->buffer, buffer->size_buffer); | ||
} | ||
buffer->buffer[buffer->index++] = c; | ||
} | ||
|
||
/** | ||
* @brief log memory segment | ||
* | ||
* @param value the value | ||
* @param context the context | ||
*/ | ||
void log_STRING(uint64_t value, syscall_log_param_t *context) | ||
{ | ||
buffer_t buffer = { | ||
.buffer = malloc(DEFAULT_BUFFER_SIZE), | ||
.size_buffer = DEFAULT_BUFFER_SIZE, | ||
.index = 0, | ||
}; | ||
char c = 1; // dummy value that will be overwritten by the first read | ||
while (c != '\0') | ||
{ | ||
struct iovec local = { | ||
.iov_base = &c, | ||
.iov_len = 1, | ||
}; | ||
struct iovec remote = { | ||
.iov_base = (void *)value + buffer.index, | ||
.iov_len = 1, | ||
}; | ||
if (process_vm_readv(context->pid, &local, 1, &remote, 1, 0) < 0) | ||
{ | ||
log_error("log_STRING", "process_vm_readv failed", true); | ||
free(buffer.buffer); | ||
return; | ||
} | ||
buffer_add_char(&buffer, c); | ||
} | ||
char *escaped_buffer = ft_escape(buffer.buffer, buffer.index - 1); | ||
ft_dprintf(STDERR_FILENO, "\"%s\"", escaped_buffer); | ||
free(escaped_buffer); | ||
free(buffer.buffer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.