Skip to content

Commit

Permalink
✨ does not log syscalls if -c
Browse files Browse the repository at this point in the history
  • Loading branch information
froz42 committed Nov 2, 2023
1 parent f3c3673 commit 08e9999
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
9 changes: 7 additions & 2 deletions includes/signals_strace.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ void signals_block(void);
void signals_unblock(void);

/**
* @brief Handle the signal raised by the tracee
* @brief Handle signals raised by the tracee
*
* @param pid the pid of the tracee
* @param cont_signal the ptr to the signal to continue the tracee
* @param analysis_state the analysis_state of the analysis routine
* @param should_log whether the signal should be logged
* @return int SIG_RAISED if a signal was raised, NO_STATUS otherwise
*/
int signals_handle(pid_t pid, int *cont_signal, analysis_routine_data_t *analysis_state);
int signals_handle(pid_t pid, int *cont_signal, analysis_routine_data_t *analysis_state,
bool_t should_log);
10 changes: 7 additions & 3 deletions srcs/analysis/analysis_routine.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include <analysis.h>
#include <config.h>
#include <errno.h>
#include <ft_printf.h>
#include <ft_strace_utils.h>
Expand All @@ -21,20 +22,23 @@
static int handle_status(pid_t pid, int status, int *cont_signal,
analysis_routine_data_t *analysis_state)
{
const bool_t should_log = !is_option_set(OPT_MASK_STATISTICS, get_config());
if (status == NO_STATUS)
return NO_STATUS;
if (WIFEXITED(status))
{
ft_printf("+++ exited with %d +++\n", WEXITSTATUS(status));
if (should_log)
ft_printf("+++ exited with %d +++\n", WEXITSTATUS(status));
return status;
}
if (WIFSIGNALED(status))
{
ft_printf("+++ killed by %s +++\n", ft_signalname(WTERMSIG(status)));
if (should_log)
ft_printf("+++ killed by %s +++\n", ft_signalname(WTERMSIG(status)));
return status;
}
if (WIFSTOPPED(status))
return signals_handle(pid, cont_signal, analysis_state);
return signals_handle(pid, cont_signal, analysis_state, should_log);
return NO_STATUS;
}

Expand Down
11 changes: 8 additions & 3 deletions srcs/signals/signals_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
#include <syscall_strace.h>

/**
* @brief Handle the signal raised by the tracee
* @brief Handle signals raised by the tracee
*
* @param pid the pid of the tracee
* @param cont_signal the ptr to the signal to continue the tracee
* @param analysis_state the analysis_state of the analysis routine
* @param should_log whether the signal should be logged
* @return int SIG_RAISED if a signal was raised, NO_STATUS otherwise
*/
int signals_handle(pid_t pid, int *cont_signal, analysis_routine_data_t *analysis_state)
int signals_handle(pid_t pid, int *cont_signal, analysis_routine_data_t *analysis_state,
bool_t should_log)
{
siginfo_t siginfo = {0};
if (ptrace(PTRACE_GETSIGINFO, pid, 0, &siginfo) < 0)
Expand All @@ -31,7 +36,7 @@ int signals_handle(pid_t pid, int *cont_signal, analysis_routine_data_t *analysi
*cont_signal = SIGSTOP;
return SIG_RAISED;
}
if (analysis_state->status == EXECVE_ENCOUNTERED)
if (should_log && analysis_state->status == EXECVE_ENCOUNTERED)
{
ft_printf("--- %s {si_signo=%s, si_code=%s, si_pid=%d, si_uid=%d",
ft_signalname(siginfo.si_signo), ft_signalname(siginfo.si_signo),
Expand Down
5 changes: 3 additions & 2 deletions srcs/syscall/syscall_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sys/uio.h>
#include <sys/wait.h>
#include <syscall_strace.h>
#include <config.h>

/**
* @brief Handle the syscall before it is executed
Expand Down Expand Up @@ -48,7 +49,7 @@ static int handle_before_syscall(pid_t pid, analysis_routine_data_t *analysis_st
return NO_STATUS;
bool_t should_log = analysis_state->status == EXECVE_ENCOUNTERED ||
(analysis_state->status != EXECVE_ERROR && *is_execve);
if (should_log)
if (should_log && !is_option_set(OPT_MASK_STATISTICS, get_config()))
*size_written = syscall_log_name_params(pid, &regs_before, *register_type_before);
return should_log;
}
Expand Down Expand Up @@ -83,7 +84,7 @@ static int handle_syscall_after(pid_t pid, analysis_routine_data_t *analysis_sta
analysis_state->status = (int64_t)registers_get_return(&regs_after, register_type_after) < 0
? EXECVE_ERROR
: EXECVE_ENCOUNTERED;
if (should_log)
if (should_log && !is_option_set(OPT_MASK_STATISTICS, get_config()))
syscall_log_params_return(pid, syscall_no, register_type_before, &regs_after,
register_type_after, size_written);
return NO_STATUS;
Expand Down

0 comments on commit 08e9999

Please sign in to comment.