first draft, should work but have to try on a x86 machine

This commit is contained in:
thrieg 2025-12-11 23:30:45 +01:00
parent a933468d61
commit 6414474ce0
4 changed files with 206 additions and 61 deletions

View file

@ -6,13 +6,13 @@
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/11 04:07:30 by thrieg #+# #+# */
/* Updated: 2025/12/11 04:59:32 by thrieg ### ########.fr */
/* Updated: 2025/12/11 23:25:15 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_strace.h"
int main_loop(size_t binary_type)
int main_loop(size_t binary_type, pid_t pid)
{
int in_syscall = 0;
while (1) {
@ -41,21 +41,22 @@ int main_loop(size_t binary_type)
// syscall-enter or syscall-exit
if (!in_syscall) {
// ENTRY
read_regs_and_print_entry(pid);
read_regs_and_print_entry(pid, binary_type);
in_syscall = 1;
} else {
// EXIT
read_regs_and_print_exit(pid);
read_regs_and_print_exit(pid, binary_type);
in_syscall = 0;
}
} else {
// A real signal: print it, then let it continue
// A real signal: print it
print_signal(pid, sig);
// pass down the signal to the actual program
if (ptrace(PTRACE_SYSCALL, pid, 0, sig) == -1) break;
waitpid(pid, &status, 0);
//waitpid(pid, &status, 0);
}
}
return (EXIT_SUCCESS);
}
int main(int argc, char **argv)
@ -104,7 +105,7 @@ int main(int argc, char **argv)
ptrace(PTRACE_SETOPTIONS, pid, 0, opts);
// 5) Enter main trace loop
return (main_loop((size_t)binary_bits));
return (main_loop((size_t)binary_bits, pid));
}
return (EXIT_SUCCESS);
}