Add TD8
This commit is contained in:
parent
7c934bcefb
commit
453d88282f
8 changed files with 588 additions and 0 deletions
27
content/secu_logicielle/td8-gdb/files/Makefile
Normal file
27
content/secu_logicielle/td8-gdb/files/Makefile
Normal file
|
@ -0,0 +1,27 @@
|
|||
CFLAGS=-g -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable -Wno-array-bounds -Wno-stringop-overflow -m32 -no-pie -fno-pie
|
||||
LDFLAGS=-m32
|
||||
LDLIBS=-lpthread
|
||||
C=$(wildcard *.c)
|
||||
O=$(C:.c=)
|
||||
O2=$(C:.c=.O2)
|
||||
|
||||
pframe:
|
||||
curl -o pframe.tgz https://dept-info.labri.fr/~thibault/SecuLog/pframe.tgz && \
|
||||
tar -xf pframe.tgz &&\
|
||||
rm -rf pframe.tgz
|
||||
|
||||
.gdbinit:
|
||||
|
||||
configure: pframe .gdbinit
|
||||
$(shell echo "python import pframe" > .gdbinit)
|
||||
%.O2: %.c
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -O2 $^ $(LDLIBS) -o $@
|
||||
|
||||
all: $O $(O2)
|
||||
|
||||
PHONY: gdb_%
|
||||
gdb_%: $(subst gdb_,,%)
|
||||
PYTHONPATH=${PWD}/pframe${PYTHONPATH:+:${PYTHONPATH}} gdb $<
|
||||
|
||||
clean:
|
||||
rm -f $O $(O2)
|
21
content/secu_logicielle/td8-gdb/files/modif-rev.c
Normal file
21
content/secu_logicielle/td8-gdb/files/modif-rev.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void f(int *x) {
|
||||
int i;
|
||||
for (i = 0; i < 10000; i++)
|
||||
(*x)++;
|
||||
(*x) *= 2;
|
||||
}
|
||||
|
||||
void g(int *y) {
|
||||
return f(y);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int b = 0;
|
||||
int a = 0;
|
||||
int c = 0;
|
||||
g(&a);
|
||||
printf("%d\n", a);
|
||||
return 0;
|
||||
}
|
18
content/secu_logicielle/td8-gdb/files/modif.c
Normal file
18
content/secu_logicielle/td8-gdb/files/modif.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void f(int *x) {
|
||||
(*x)++;
|
||||
}
|
||||
|
||||
void g(int *y) {
|
||||
return f(y);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int b = 1;
|
||||
int a = 2;
|
||||
int c = 3;
|
||||
g(&a);
|
||||
printf("%d\n", a);
|
||||
return 0;
|
||||
}
|
19
content/secu_logicielle/td8-gdb/files/modif2.c
Normal file
19
content/secu_logicielle/td8-gdb/files/modif2.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void f(char *x, int n) {
|
||||
memset(x, '\0', n);
|
||||
}
|
||||
|
||||
void g(char *y, int n) {
|
||||
return f(y, n);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int b = 1234567890;
|
||||
int c = 1234567890;
|
||||
char a[] = "Hello, you!";
|
||||
g(a, sizeof(a) + 1);
|
||||
printf("%p:%d %p:%d %p\n", &b, b, &c, c, &a);
|
||||
return 0;
|
||||
}
|
19
content/secu_logicielle/td8-gdb/files/modif3.c
Normal file
19
content/secu_logicielle/td8-gdb/files/modif3.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void f(char *x, int n) {
|
||||
memset(x, '\0', n);
|
||||
}
|
||||
|
||||
void g(char *y, int n) {
|
||||
return f(y, n);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char *a = strdup("aaa");
|
||||
g(a, sizeof(a)+1);
|
||||
printf("%p\n", &a);
|
||||
free(a);
|
||||
return 0;
|
||||
}
|
17
content/secu_logicielle/td8-gdb/files/optim.c
Normal file
17
content/secu_logicielle/td8-gdb/files/optim.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int __attribute__((noinline)) f(int x) {
|
||||
return x+1;
|
||||
}
|
||||
|
||||
int __attribute__((noinline)) g(int y) {
|
||||
int z = y+1;
|
||||
int a = f(z);
|
||||
printf("%d\n", a);
|
||||
return a;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
printf("%d\n", g(1));
|
||||
return 0;
|
||||
}
|
15
content/secu_logicielle/td8-gdb/files/stack.c
Normal file
15
content/secu_logicielle/td8-gdb/files/stack.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int f(int *x) {
|
||||
return *x+1;
|
||||
}
|
||||
|
||||
int g(int y) {
|
||||
int z = y+1;
|
||||
return f(&z);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
printf("%d\n", g(1));
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue