This commit is contained in:
Yorick Barbanneau 2023-04-17 18:00:20 +02:00
parent 7c934bcefb
commit 453d88282f
8 changed files with 588 additions and 0 deletions

View 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)

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}