Compare commits
3 Commits
labs/03
...
d7f2db8780
| Author | SHA1 | Date | |
|---|---|---|---|
| d7f2db8780 | |||
| 88e75e848a | |||
| dd6c23d79f |
17
08-debugging/Makefile
Normal file
17
08-debugging/Makefile
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
all: test testee
|
||||||
|
|
||||||
|
test: test.o
|
||||||
|
gcc $^ -o $@ -g
|
||||||
|
|
||||||
|
test.o: test.c
|
||||||
|
gcc -c $^ -g
|
||||||
|
|
||||||
|
testee: testee.o
|
||||||
|
ld $^ -o $@
|
||||||
|
|
||||||
|
testee.o: testee.asm
|
||||||
|
nasm -felf64 $^ -o $@ -g
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm *.o test *.gch testee
|
||||||
66
08-debugging/test.c
Normal file
66
08-debugging/test.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include<stdio.h>
|
||||||
|
#include<stdlib.h>
|
||||||
|
#include<unistd.h>
|
||||||
|
#include<sys/types.h>
|
||||||
|
#include<sys/ptrace.h>
|
||||||
|
#include<sys/user.h>
|
||||||
|
#include<sys/wait.h>
|
||||||
|
|
||||||
|
#define DONT_CARE 0
|
||||||
|
|
||||||
|
int stats;
|
||||||
|
struct user_regs_struct regs;
|
||||||
|
|
||||||
|
void continue_execution(pid_t pid)
|
||||||
|
{
|
||||||
|
ptrace(PTRACE_CONT, pid, DONT_CARE, DONT_CARE);
|
||||||
|
waitpid(pid, &stats, 0);
|
||||||
|
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);
|
||||||
|
waitpid(pid, &stats, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("procces is run ");
|
||||||
|
pid_t pid;
|
||||||
|
pid = fork();
|
||||||
|
if (pid==0)
|
||||||
|
{
|
||||||
|
printf(" -- child\n");
|
||||||
|
ptrace(PTRACE_TRACEME, 0, 0, 0);
|
||||||
|
execl("./testee", "testee", NULL);
|
||||||
|
printf("____AFTER_TRACE_CHILD____\n");
|
||||||
|
}
|
||||||
|
else if(pid > 0)
|
||||||
|
{
|
||||||
|
char buff;
|
||||||
|
printf(" -- parrent\n");
|
||||||
|
continue_execution(pid); // to start app
|
||||||
|
continue_execution(pid);
|
||||||
|
if (stats & SIGTRAP)
|
||||||
|
{
|
||||||
|
while (stats != 0)
|
||||||
|
{
|
||||||
|
read(0, &buff, 1);
|
||||||
|
print_rax(pid);
|
||||||
|
step(pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("____AFTER_TRACE_PARRENT____\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
26
08-debugging/testee.asm
Normal file
26
08-debugging/testee.asm
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
global _start
|
||||||
|
|
||||||
|
section .data
|
||||||
|
msg: db "I'm alive", `\n`, 0
|
||||||
|
msg_len equ $-msg
|
||||||
|
|
||||||
|
section .text
|
||||||
|
_start:
|
||||||
|
xor rax, rax,
|
||||||
|
add rax, 1
|
||||||
|
;int3
|
||||||
|
add rax, 12
|
||||||
|
;int3
|
||||||
|
mov rax, 33
|
||||||
|
;int3
|
||||||
|
|
||||||
|
mov rax, 1
|
||||||
|
mov rdi, 1
|
||||||
|
mov rsi, msg
|
||||||
|
mov rdx, msg_len
|
||||||
|
syscall
|
||||||
|
int3
|
||||||
|
|
||||||
|
mov rax, 60
|
||||||
|
mov rdi, 0
|
||||||
|
syscall
|
||||||
Reference in New Issue
Block a user