From 88e75e848af9d824569467aa8ea849973cc1d3db Mon Sep 17 00:00:00 2001 From: Miheev Egor Date: Thu, 31 Oct 2024 01:17:50 +0300 Subject: [PATCH] =?UTF-8?q?sync:=20=D1=87=D1=82=D0=BE-=D1=82=D0=BE=20?= =?UTF-8?q?=D1=85=D0=B8=D0=BC=D0=B8=D1=87=D1=83=20=D1=81=20=D1=82=D0=BE?= =?UTF-8?q?=D1=87=D0=BA=D0=B0=D0=BC=D0=B8=20=D0=BE=D1=81=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 08-debugging/Makefile | 2 +- 08-debugging/test.c | 37 +++++++++++++++++++++++++++++++------ 08-debugging/testee.asm | 4 ++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/08-debugging/Makefile b/08-debugging/Makefile index a139d69..ebce68a 100644 --- a/08-debugging/Makefile +++ b/08-debugging/Makefile @@ -14,4 +14,4 @@ testee.o: testee.asm nasm -felf64 $^ -o $@ -g clean: - rm *.o test *.gch + rm *.o test *.gch testee diff --git a/08-debugging/test.c b/08-debugging/test.c index 86afea6..be8551c 100644 --- a/08-debugging/test.c +++ b/08-debugging/test.c @@ -11,6 +11,28 @@ int stats; struct user_regs_struct regs; +void continue_execution(pid_t pid) +{ + ptrace(PTRACE_CONT, pid, DONT_CARE, DONT_CARE); + int wait_status; + int options = 0; + waitpid(pid, &wait_status, options); + return; +} + +void print_rax(pid_t pid) +{ + ptrace(PTRACE_GETREGS, pid, DONT_CARE, ®s); + printf("rax = %llu\n", regs.rax); + return; +} + +void step(pid_t pid) +{ + ptrace(PTRACE_SINGLESTEP, pid, DONT_CARE, DONT_CARE); + return; +} + int main() { printf("procces is run "); @@ -25,15 +47,18 @@ int main() } else if(pid > 0) { + char buff; printf(" -- parrent\n"); - for (int i = 0; i < 4; i++) - { + continue_execution(pid); + do { waitpid(pid, &stats, 0); - printf("____PARENT_STAT: %d____\n", stats); - ptrace(PTRACE_GETREGS, pid, DONT_CARE, ®s); - printf("rax = %llu\n", regs.rax); + printf("stats - %d", stats); + print_rax(pid); ptrace(PTRACE_SINGLESTEP, pid, DONT_CARE, DONT_CARE); - } + printf("enter any: "); + read(0, &buff, 1); + printf("\n"); + } while(stats); printf("____AFTER_TRACE_PARRENT____\n"); } return 0; diff --git a/08-debugging/testee.asm b/08-debugging/testee.asm index db63d56..e074aea 100644 --- a/08-debugging/testee.asm +++ b/08-debugging/testee.asm @@ -8,7 +8,11 @@ section .text _start: xor rax, rax, add rax, 1 + int3 add rax, 12 + ;int3 + mov rax, 33 + ;int3 mov rax, 1 mov rdi, 1