Skip to content

Commit 3528bf9

Browse files
committed
pasado desde gitlab
0 parents  commit 3528bf9

25 files changed

+1850
-0
lines changed

Makefile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
CFLAGS=-Wall -Wextra -pedantic -std=c99 -Wconversion -Og -ggdb -no-pie
2+
CC=gcc
3+
AS=nasm
4+
ASFLAGS=-f elf64 -g -FDWARF
5+
EJ1OBJS=ej1_asm.o lib_c.o ej1_c.o
6+
EJ2OBJS=ej2_asm.o lib_c.o ej2_c.o
7+
EJ3OBJS=ej3_asm.o lib_c.o ej3_c.o
8+
EJ4OBJS=ej4_asm.o lib_c.o ej4_c.o
9+
10+
all: ej1 ej2 ej3 ej4
11+
12+
format:
13+
clang-format -style=Chromium -i *.c *.h
14+
15+
%_asm.o: %.asm
16+
$(AS) $(ASFLAGS) $^ -o $@
17+
18+
%_c.o: %.c
19+
$(CC) $(CFLAGS) $^ -c -o $@
20+
21+
ej1: $(EJ1OBJS)
22+
$(CC) $(CFLAGS) $^ -o $@
23+
24+
ej2: $(EJ2OBJS)
25+
$(CC) $(CFLAGS) $^ -o $@
26+
27+
ej3: $(EJ3OBJS)
28+
$(CC) $(CFLAGS) $^ -o $@
29+
30+
ej4: $(EJ4OBJS)
31+
$(CC) $(CFLAGS) $^ -o $@
32+
33+
clean:
34+
rm -f *.o ej1 ej2 ej3 ej4

abi_enforcer.mac

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
; Version simple del abi_enforcer. Sin mensajes de error ni nada.
2+
; Uso: %include "abi_enforcer.mac" en cada archivo .asm, o agregar
3+
; -p "abi_enforcer.mac" al NASMFLAGS de cada Makefile.
4+
;
5+
; Features:
6+
; * Pisa todos los registros que no se preservan en cada call y ret
7+
; (rcx, rdx, rdi, rsi, r8, r9, r10, r11)
8+
; * Pisa 50 valores en el stack para asegurarnos que nadie referencie
9+
; a variables del stack luego de un call.
10+
; * Chequea que la pila este alineada antes de cada call.
11+
;
12+
; No tiene mensajes de error lindos. El codigo simplemente va a crashear.
13+
; No chequea que los registros que hay que preservar se preserven.
14+
15+
; Macro regcrash pisa todos los registros que no se preservan.
16+
%macro regcrash 0
17+
mov rdi, 0x001122334455667788
18+
mov rsi, 0x001122334455667788
19+
mov rdx, 0x001122334455667788
20+
mov rcx, 0x001122334455667788
21+
mov r8, 0x001122334455667788
22+
mov r9, 0x001122334455667788
23+
mov r10, 0x001122334455667788
24+
mov r11, 0x001122334455667788
25+
%endmacro
26+
27+
; Macro stackcrash llena el stack de basura.
28+
%macro stackcrash 0
29+
times 50 push 0x11bbccdd
30+
add rsp, 50*8
31+
%endmacro
32+
33+
; Macro stackcheck crashea si el stack no está alineado.
34+
%macro stackcheck 0
35+
test rsp, 0xF
36+
jz %%aligned
37+
ud2
38+
%%aligned:
39+
%endmacro
40+
41+
; Macro que reemplaza la instruccion call.
42+
; Antes de ejecutar el call verdadero, chequea que el stack este alineado
43+
; Luego de ejecutar el call, pone basura en todos los registros y el stack.
44+
%imacro call 1
45+
stackcheck
46+
call %1
47+
regcrash
48+
stackcrash
49+
%endmacro
50+
51+
; Macro que reemplaza la instruccion ret.
52+
; Antes de hacer el ret, pone basura en todos los registros y el stack.
53+
%imacro ret 0
54+
regcrash
55+
stackcrash
56+
ret
57+
%endmacro

ej1

36.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)