uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

commit 589b111f08cbc5d928bdc414ed9edff9ff27ea6a
parent 049691a223a32b264e9eb34d08d1b4d4bdb81d04
Author: Christos Margiolis <christos@margiolis.net>
Date:   Thu,  2 Jun 2022 17:36:05 +0300

donecompilers done

Diffstat:
Alex_yacc_compilers/part4/02_B1_PART_B3.pdf | 0
Alex_yacc_compilers/part4/Makefile | 8++++++++
Alex_yacc_compilers/part4/input.txt | 12++++++++++++
Alex_yacc_compilers/part4/lex.l | 48++++++++++++++++++++++++++++++++++++++++++++++++
Alex_yacc_compilers/part4/output.txt | 6++++++
Alex_yacc_compilers/part4/syntax.y | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rc_security/ex1/doc/doc.pdf -> security/ex1/doc/doc.pdf | 0
Rc_security/ex1/doc/doc.tex -> security/ex1/doc/doc.tex | 0
Rc_security/ex1/doc/doc.toc -> security/ex1/doc/doc.toc | 0
Rc_security/ex1/doc/res/uniwalogo.png -> security/ex1/doc/res/uniwalogo.png | 0
Rc_security/ex1/src/Makefile -> security/ex1/src/Makefile | 0
Rc_security/ex1/src/atoh -> security/ex1/src/atoh | 0
Rc_security/ex1/src/dat/c0.pem -> security/ex1/src/dat/c0.pem | 0
Rc_security/ex1/src/dat/cert.in -> security/ex1/src/dat/cert.in | 0
Rc_security/ex1/src/dat/decrypt.in -> security/ex1/src/dat/decrypt.in | 0
Rc_security/ex1/src/dat/encrypt.in -> security/ex1/src/dat/encrypt.in | 0
Rc_security/ex1/src/dat/priv.in -> security/ex1/src/dat/priv.in | 0
Rc_security/ex1/src/dat/verify1_cor.in -> security/ex1/src/dat/verify1_cor.in | 0
Rc_security/ex1/src/dat/verify1_inc.in -> security/ex1/src/dat/verify1_inc.in | 0
Rc_security/ex1/src/dat/verify2.in -> security/ex1/src/dat/verify2.in | 0
Rc_security/ex1/src/decrypt.c -> security/ex1/src/decrypt.c | 0
Rc_security/ex1/src/encrypt.c -> security/ex1/src/encrypt.c | 0
Rc_security/ex1/src/htoa -> security/ex1/src/htoa | 0
Rc_security/ex1/src/priv.c -> security/ex1/src/priv.c | 0
Rc_security/ex1/src/sign.c -> security/ex1/src/sign.c | 0
Rc_security/ex1/src/tests -> security/ex1/src/tests | 0
Rc_security/ex1/src/verify.c -> security/ex1/src/verify.c | 0
Rc_security/ex2/Makefile -> security/ex2/Makefile | 0
Rc_security/ex2/dash_shellcode.c -> security/ex2/dash_shellcode.c | 0
Rc_security/ex2/exploit.c -> security/ex2/exploit.c | 0
Rc_security/ex2/shellcode.c -> security/ex2/shellcode.c | 0
Rc_security/ex2/stack.c -> security/ex2/stack.c | 0
32 files changed, 207 insertions(+), 0 deletions(-)

diff --git a/lex_yacc_compilers/part4/02_B1_PART_B3.pdf b/lex_yacc_compilers/part4/02_B1_PART_B3.pdf Binary files differ. diff --git a/lex_yacc_compilers/part4/Makefile b/lex_yacc_compilers/part4/Makefile @@ -0,0 +1,8 @@ +all: + bison -d syntax.y + flex lex.l + cc syntax.tab.c lex.yy.c -lm -o uniclips + ./uniclips input.txt output.txt + +clean: + rm -f *.yy.c *.output *.tab.c *.tab.h uniclips *.core diff --git a/lex_yacc_compilers/part4/input.txt b/lex_yacc_compilers/part4/input.txt @@ -0,0 +1,12 @@ +(printout "hello" "hello") +(bind ?var 1) +(bind ?var (+ 1 2)) +(test (= 1 2)) +(= 1 (+ 2 3)) + +(defrule move-up + (+ 1 2) + (- 1 (+ 1 (* 1 2))) + (test (= 1 2)) + -> + (printout "hello")) diff --git a/lex_yacc_compilers/part4/lex.l b/lex_yacc_compilers/part4/lex.l @@ -0,0 +1,48 @@ +%option noyywrap +%{ +#include <stdlib.h> +#include "syntax.tab.h" + +int cw = 0; /* correct words */ +int ww = 0; /* wrong words */ +%} + +/* + * Με βάση το μέρος Α2, υλοποιούμε τις κανονικές εκφράσεις και τις + * αντιστοιχούμε στα κατάλληλα tokens. + */ +ARITH "+"|"-"|"*"|"/"|"=" +DELIM [ \t\n]+ +INT 0|[+-]?[1-9]+[0-9]* +FLOAT [+-]?[0-9]+((\.[0-9]+)([eE][+-]?[0-9]*)?|([eE][+-]?[0-9]*)?) +STR \"[^\"\\]*(?:\\.[^\"\\]*)*\" +DEFIN [A-Za-z]+[A-Za-z0-9_-]* +VAR \?[A-Za-z0-9]+ +COMMENT ;.* + +/* + * Όταν βρίσκει οποιοδήποτε token, επιστρέφει την αντίστοιχη κατηγορία στο + * οποίο ανήκει + */ +%% +"deffacts" { cw++; return DEFFACTS; } +"defrule" { cw++; return DEFRULE; } +"bind" { cw++; return BIND; } +"read" { cw++; return READ; } +"printout" { cw++; return PRINT; } +"test" { cw++; return TEST; } +"=" { cw++; return COMP; } +"(" { return LPAR; } +")" { return RPAR; } +"->" { return ARROW; } +{ARITH} { cw++; return ARITH; } +{INT} { cw++; return INT; } +{FLOAT} { cw++; return FLOAT;} +{STR} { cw++; return STR; } +{DEFIN} { cw++; return DEFIN; } +{VAR} { cw++; return VAR; } +{DELIM} { /* ignore whitespace */ } +{COMMENT} { /* skip comments */ } +"\n" { return NEWLINE; } +. { ww++; return UNKNOWN; } +%% diff --git a/lex_yacc_compilers/part4/output.txt b/lex_yacc_compilers/part4/output.txt @@ -0,0 +1,6 @@ +input.txt: success + +correct words: 38 +correct expressions: 12 +wrong words: 0 +wrong expressions: 0 diff --git a/lex_yacc_compilers/part4/syntax.y b/lex_yacc_compilers/part4/syntax.y @@ -0,0 +1,133 @@ +%{ +#include <err.h> +#include <stdio.h> +#include <stdlib.h> + +/* Silence warnings... */ +extern int yylex(void); + +/* Input and output files. */ +extern FILE *yyin, *yyout; + +extern int cw; /* correct words */ +extern int ww; /* wrong words */ +int ce = 0; /* correct expressions */ +int we = 0; /* wrong expressions */ + +void yyerror(const char *); +%} + +/* Tokens declared from flex. */ +%token DEFFACTS DEFRULE BIND READ PRINT TEST ARITH INT FLOAT COMP +%token STR DEFIN VAR LPAR RPAR ARROW NEWLINE UNKNOWN + +%start prog + +%% +/* Start here. */ +prog: + | prog NEWLINE + | prog expr + ; + +/* + * Declare numbers. Variables only accept numerical values so add them here as + * well. + */ +num: + INT + | FLOAT + | VAR + ; + +/* Accept any number of strings (for use in printout) */ +str: + STR + | str STR + ; + +/* (= (expr)) */ +cmp: + LPAR COMP expr expr RPAR + ; + +/* (test (= (expr))) */ +test: + LPAR TEST cmp RPAR + ; + +/* (prinout (str)...) */ +print: + LPAR PRINT str RPAR + ; + +fact: + expr + | fact expr + ; + +/* We match expressions here. */ +expr: + num /* numbers */ + | cmp { ce++; } /* comparisons */ + | test { ce++; } /* test keyword */ + | print { ce++; } /* (printout "str"...) */ + | LPAR READ RPAR { ce++; } /* (read) */ + | LPAR ARITH expr expr RPAR { ce++; } /* (arithmetic_op (expr)...) */ + | LPAR BIND VAR expr RPAR { ce++; } /* (bind ?var (expr)) */ + | LPAR DEFFACTS DEFIN fact RPAR { ce++; } /* (deffacts DEF facts...) */ + /* (defrule DEF + * (facts) + * ... + * (test) + * -> + * (printout)) + */ + | LPAR DEFRULE DEFIN fact test ARROW print RPAR { ce++; } + | error { we++; if (ce > 0) ce--; } + ; +%% + +/* Print errors. */ +void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +main(int argc, char *argv[]) +{ + /* We need at least 1 input and 1 output file... */ + if (argc < 3) { + fprintf(stderr, "usage: %s input... output\n", *argv); + return (-1); + } + + /* Open last file as output. */ + if ((yyout = fopen(argv[--argc], "w")) == NULL) + err(1, "fopen(%s)", argv[argc]); + + /* Parse all input files in reverse order. */ + while (argc-- > 1) { + if ((yyin = fopen(argv[argc], "r")) == NULL) + err(1, "fopen(%s)", argv[argc]); + /* Parse file */ + if (yyparse() == 0) + fprintf(yyout, "%s: success\n", argv[argc]); + else + fprintf(yyout, "%s: failure\n", argv[argc]); + fclose(yyin); + } + + /* Print results. */ + fprintf(yyout, "\n"); + fprintf(yyout, "correct words: %d\n", cw); + fprintf(yyout, "correct expressions: %d\n", ce); + fprintf(yyout, "wrong words: %d\n", ww); + fprintf(yyout, "wrong expressions: %d\n", we); + + fclose(yyout); + + return (0); +} diff --git a/c_security/ex1/doc/doc.pdf b/security/ex1/doc/doc.pdf Binary files differ. diff --git a/c_security/ex1/doc/doc.tex b/security/ex1/doc/doc.tex diff --git a/c_security/ex1/doc/doc.toc b/security/ex1/doc/doc.toc diff --git a/c_security/ex1/doc/res/uniwalogo.png b/security/ex1/doc/res/uniwalogo.png Binary files differ. diff --git a/c_security/ex1/src/Makefile b/security/ex1/src/Makefile diff --git a/c_security/ex1/src/atoh b/security/ex1/src/atoh diff --git a/c_security/ex1/src/dat/c0.pem b/security/ex1/src/dat/c0.pem diff --git a/c_security/ex1/src/dat/cert.in b/security/ex1/src/dat/cert.in diff --git a/c_security/ex1/src/dat/decrypt.in b/security/ex1/src/dat/decrypt.in diff --git a/c_security/ex1/src/dat/encrypt.in b/security/ex1/src/dat/encrypt.in diff --git a/c_security/ex1/src/dat/priv.in b/security/ex1/src/dat/priv.in diff --git a/c_security/ex1/src/dat/verify1_cor.in b/security/ex1/src/dat/verify1_cor.in diff --git a/c_security/ex1/src/dat/verify1_inc.in b/security/ex1/src/dat/verify1_inc.in diff --git a/c_security/ex1/src/dat/verify2.in b/security/ex1/src/dat/verify2.in diff --git a/c_security/ex1/src/decrypt.c b/security/ex1/src/decrypt.c diff --git a/c_security/ex1/src/encrypt.c b/security/ex1/src/encrypt.c diff --git a/c_security/ex1/src/htoa b/security/ex1/src/htoa diff --git a/c_security/ex1/src/priv.c b/security/ex1/src/priv.c diff --git a/c_security/ex1/src/sign.c b/security/ex1/src/sign.c diff --git a/c_security/ex1/src/tests b/security/ex1/src/tests diff --git a/c_security/ex1/src/verify.c b/security/ex1/src/verify.c diff --git a/c_security/ex2/Makefile b/security/ex2/Makefile diff --git a/c_security/ex2/dash_shellcode.c b/security/ex2/dash_shellcode.c diff --git a/c_security/ex2/exploit.c b/security/ex2/exploit.c diff --git a/c_security/ex2/shellcode.c b/security/ex2/shellcode.c diff --git a/c_security/ex2/stack.c b/security/ex2/stack.c