Begin question 3

This commit is contained in:
Yorick Barbanneau 2023-02-19 21:10:23 +01:00
parent 9643faa483
commit 52b9dd8b1a
4 changed files with 83 additions and 0 deletions

View file

@ -0,0 +1,39 @@
CC = gcc
CFLAGS = -Wall -Wextra -O0 -no-pie -lm -g -std=c99
SRC = $(wildcard *.c)
TGT = $(subst .c,,$(SRC))
BUILD_DIR = build
DUMP_DIR = dump
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)
$(BUILD_DIR)/%_32: %.c
$(shell mkdir -p $(BUILD_DIR))
$(CC) $(CFLAGS) -m32 -o $@ $<
$(BUILD_DIR)/%_64: %.c
$(shell mkdir -p $(BUILD_DIR))
$(CC) $(CFLAGS) -m64 -o $@ $<
build: $(addprefix $(BUILD_DIR)/, $(addsuffix _32, $(TGT))) \
$(addprefix $(BUILD_DIR)/, $(addsuffix _64, $(TGT)))
PHONY: %
%: $(addprefix $(BUILD_DIR)/, $(addsuffix _32, %))
PYTHONPATH=${PWD}/pframe${PYTHONPATH:+:${PYTHONPATH}} gdb $< --command=$@.gdb
PHONY: clean
clean:
@rm -rf $(BUILD_DIR) pframe .gdbinit

View file

@ -0,0 +1,35 @@
int foo1(int t[2]) {
return t[0]+t[1];
}
struct s {
int f0;
int f1;
};
int foo2(struct s *f) {
return f->f0 + f->f1;
}
int foo3(struct s f) {
return f.f0 + f.f1;
}
struct s2 {
int f[2];
};
int foo4(struct s2 f) {
return f.f[0] + f.f[0];
}
int t[2] = {1,2};
int main () {
foo1(t);
struct s mys = { 1, 2 };
foo2(&mys);
foo3(mys);
struct s2 mys2 = { { 1, 2 } };
foo4(mys2);
return 0;
}

View file

@ -0,0 +1,2 @@
rbreak foo*
run

View file

@ -119,3 +119,10 @@ push $0x8
mov $0x7,%r9d
mov $0x6,%r8d
```
## Question 3
Les fichiers utilisés pour cette partie sont disponibles [sur mon dépôt git].
Un `Makefie` est disponible comme pour la précédente question.
[sur mon dépôt git]:https://git.epha.se/ephase/cours_lpro-ADSILLH/src/branch/main/content/secu_logicielle/td4-assembleur_x86_part2/files/q3