From 52b9dd8b1afb9880a7231ff24648e00b5d95ba20 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Sun, 19 Feb 2023 21:10:23 +0100 Subject: [PATCH] Begin question 3 --- .../files/q3/Makefile | 39 +++++++++++++++++++ .../td4-assembleur_x86_part2/files/q3/q3_2.c | 35 +++++++++++++++++ .../files/q3/q3_2.gdb | 2 + .../td4-assembleur_x86_part2/index.md | 7 ++++ 4 files changed, 83 insertions(+) create mode 100644 content/secu_logicielle/td4-assembleur_x86_part2/files/q3/Makefile create mode 100644 content/secu_logicielle/td4-assembleur_x86_part2/files/q3/q3_2.c create mode 100644 content/secu_logicielle/td4-assembleur_x86_part2/files/q3/q3_2.gdb diff --git a/content/secu_logicielle/td4-assembleur_x86_part2/files/q3/Makefile b/content/secu_logicielle/td4-assembleur_x86_part2/files/q3/Makefile new file mode 100644 index 0000000..138afad --- /dev/null +++ b/content/secu_logicielle/td4-assembleur_x86_part2/files/q3/Makefile @@ -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 diff --git a/content/secu_logicielle/td4-assembleur_x86_part2/files/q3/q3_2.c b/content/secu_logicielle/td4-assembleur_x86_part2/files/q3/q3_2.c new file mode 100644 index 0000000..78c7a5c --- /dev/null +++ b/content/secu_logicielle/td4-assembleur_x86_part2/files/q3/q3_2.c @@ -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; +} diff --git a/content/secu_logicielle/td4-assembleur_x86_part2/files/q3/q3_2.gdb b/content/secu_logicielle/td4-assembleur_x86_part2/files/q3/q3_2.gdb new file mode 100644 index 0000000..30a5fd4 --- /dev/null +++ b/content/secu_logicielle/td4-assembleur_x86_part2/files/q3/q3_2.gdb @@ -0,0 +1,2 @@ +rbreak foo* +run diff --git a/content/secu_logicielle/td4-assembleur_x86_part2/index.md b/content/secu_logicielle/td4-assembleur_x86_part2/index.md index a2e545a..fe53c1f 100644 --- a/content/secu_logicielle/td4-assembleur_x86_part2/index.md +++ b/content/secu_logicielle/td4-assembleur_x86_part2/index.md @@ -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