From 8af706e97d2da5e6ab0ef499b5b22b6578ada6ee Mon Sep 17 00:00:00 2001 From: Miguel Astor Date: Fri, 13 Jan 2023 18:18:55 -0400 Subject: [PATCH] Migrated first 6 gists. --- kernel.c/Makefile | 12 ++++++++ kernel.c/README.md | 2 ++ kernel.c/kernel.c | 47 ++++++++++++++++++++++++++++++ kernel.c/kernel.s | 21 ++++++++++++++ kernel.c/link.ld | 9 ++++++ rc4.c/README.md | 1 + rc4.c/rc4.c | 64 +++++++++++++++++++++++++++++++++++++++++ rc4.c/rc4.h | 12 ++++++++ rip2iso.sh/README.md | 1 + rip2iso.sh/rip2iso.sh | 17 +++++++++++ rmfen.l/README.md | 1 + rmfen.l/rmfen.l | 20 +++++++++++++ unknytt.py/README.md | 1 + unknytt.py/unknytt.py | 67 +++++++++++++++++++++++++++++++++++++++++++ whoami.php/README.md | 1 + whoami.php/whoami.php | 14 +++++++++ 16 files changed, 290 insertions(+) create mode 100644 kernel.c/Makefile create mode 100644 kernel.c/README.md create mode 100644 kernel.c/kernel.c create mode 100644 kernel.c/kernel.s create mode 100644 kernel.c/link.ld create mode 100644 rc4.c/README.md create mode 100644 rc4.c/rc4.c create mode 100644 rc4.c/rc4.h create mode 100644 rip2iso.sh/README.md create mode 100644 rip2iso.sh/rip2iso.sh create mode 100644 rmfen.l/README.md create mode 100644 rmfen.l/rmfen.l create mode 100644 unknytt.py/README.md create mode 100644 unknytt.py/unknytt.py create mode 100644 whoami.php/README.md create mode 100644 whoami.php/whoami.php diff --git a/kernel.c/Makefile b/kernel.c/Makefile new file mode 100644 index 0000000..9d6aabf --- /dev/null +++ b/kernel.c/Makefile @@ -0,0 +1,12 @@ +.PHONY: all +all: kernel-1989 + qemu-system-i386 -kernel kernel-1989 -d guest_errors + +kernel-1989: boot.s kmain.c + gcc -m32 -c boot.s -o boot.o + gcc -m32 -std=c99 -c kmain.c -o kmain.o + ld -m elf_i386 -T link.ld -o kernel-1989 boot.o kmain.o + +.PHONY: clean +clean: + rm -f *.o kernel-1989 diff --git a/kernel.c/README.md b/kernel.c/README.md new file mode 100644 index 0000000..484b8d3 --- /dev/null +++ b/kernel.c/README.md @@ -0,0 +1,2 @@ +Hello, Kernel! - An absolutely minimal barebones x86 OS kernel, based on this tutorial https://arjunsreedharan.org/post/82710718100/kernel-101-lets-write-a-kernel + diff --git a/kernel.c/kernel.c b/kernel.c/kernel.c new file mode 100644 index 0000000..86d3574 --- /dev/null +++ b/kernel.c/kernel.c @@ -0,0 +1,47 @@ +#include +#include + +void kmain(void) { + const char * str = "Hello, Kernel!"; + const char colors[16] = { 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F + }; + char * vidptr = (char *)0xB8000; + uint32_t i = 0; + uint32_t j = 0; + uint32_t k = 0; + uint32_t l = 0; + + while (true) { + while (j < 80 * 25 * 2) { + vidptr[j] = ' '; + vidptr[j + 1] = 0x00; + j = j + 2; + } + + k = 0; + i = 0; + while (k < 80 * 25) { + j = 0; + while (str[j]) { + vidptr[i] = str[j]; + vidptr[i + 1] = colors[l]; + j++; + i += 2; + l = (l + 1) % 16; + } + vidptr[i] = ' '; + vidptr[i + 1] = colors[l]; + i += 2; + k += 14; + } + + k = 0; + while (k < 1500000) + k++; + } + + return; +} diff --git a/kernel.c/kernel.s b/kernel.c/kernel.s new file mode 100644 index 0000000..d2b47cf --- /dev/null +++ b/kernel.c/kernel.s @@ -0,0 +1,21 @@ + .section .text + + // Multiboot header + .align 4 + .long 0x1BADB002 + .long 0x00 + .long -0x1BADB002 + + // Entry point + .globl start + +start: + cli + mov $stack_top, %esp + call kmain + hlt + + .section .bss + + .comm stack_bottom, 8192, 4 +stack_top: diff --git a/kernel.c/link.ld b/kernel.c/link.ld new file mode 100644 index 0000000..497c642 --- /dev/null +++ b/kernel.c/link.ld @@ -0,0 +1,9 @@ +OUTPUT_FORMAT(elf32-i386) +ENTRY(start) +SECTIONS + { + . = 0x100000; + .text : { *(.text) } + .data : { *(.data) } + .bss : { *(.bss) } + } diff --git a/rc4.c/README.md b/rc4.c/README.md new file mode 100644 index 0000000..f233a99 --- /dev/null +++ b/rc4.c/README.md @@ -0,0 +1 @@ +Backup of the RC4 algorithm implementation from https://web.archive.org/web/20080404222417/http://cypherpunks.venona.com/date/1994/09/msg00304.html diff --git a/rc4.c/rc4.c b/rc4.c/rc4.c new file mode 100644 index 0000000..e49f451 --- /dev/null +++ b/rc4.c/rc4.c @@ -0,0 +1,64 @@ +/*rc4.c */ + +#include "rc4.h" + +static void swap_byte(unsigned char *a, unsigned char *b); + +void prepare_key(unsigned char *key_data_ptr, int key_data_len, rc4_key *key) +{ + unsigned char swapByte; + unsigned char index1; + unsigned char index2; + unsigned char* state; + short counter; + + state = &key->state[0]; + for(counter = 0; counter < 256; counter++) + state[counter] = counter; + key->x = 0; + key->y = 0; + index1 = 0; + index2 = 0; + for(counter = 0; counter < 256; counter++) + { + index2 = (key_data_ptr[index1] + state[counter] + index2) % 256; + swap_byte(&state[counter], &state[index2]); + + index1 = (index1 + 1) % key_data_len; + } + } + + void rc4(unsigned char *buffer_ptr, int buffer_len, rc4_key *key) + { + unsigned char x; + unsigned char y; + unsigned char* state; + unsigned char xorIndex; + short counter; + + x = key->x; + y = key->y; + + state = &key->state[0]; + for(counter = 0; counter < buffer_len; counter ++) + { + x = (x + 1) % 256; + y = (state[x] + y) % 256; + swap_byte(&state[x], &state[y]); + + xorIndex = state[x] + (state[y]) % 256; + + buffer_ptr[counter] ^= state[xorIndex]; + } + key->x = x; + key->y = y; + } + + static void swap_byte(unsigned char *a, unsigned char *b) + { + unsigned char swapByte; + + swapByte = *a; + *a = *b; + *b = swapByte; + } diff --git a/rc4.c/rc4.h b/rc4.c/rc4.h new file mode 100644 index 0000000..4948783 --- /dev/null +++ b/rc4.c/rc4.h @@ -0,0 +1,12 @@ +/* rc4.h */ + +typedef struct rc4_key +{ + unsigned char state[256]; + unsigned char x; + unsigned char y; +} rc4_key; + +void prepare_key(unsigned char *key_data_ptr,int key_data_len, rc4_key *key); + +void rc4(unsigned char *buffer_ptr,int buffer_len,rc4_key * key); diff --git a/rip2iso.sh/README.md b/rip2iso.sh/README.md new file mode 100644 index 0000000..8109d19 --- /dev/null +++ b/rip2iso.sh/README.md @@ -0,0 +1 @@ +Rips raw data from a CD using the /dev/sr1 device (USB cd writer) to an iso image file. diff --git a/rip2iso.sh/rip2iso.sh b/rip2iso.sh/rip2iso.sh new file mode 100644 index 0000000..f108431 --- /dev/null +++ b/rip2iso.sh/rip2iso.sh @@ -0,0 +1,17 @@ +#! /bin/bash + +# Usage: ./rip2iso.sh ISO_FILE_NAME +# Output: a file named "ISO_FILE_NAME01.iso" + +cdrdao read-cd \ + --datafile $1.bin \ + --driver generic-mmc:0x20000 \ + --device /dev/sr1 \ + --read-raw \ + $1.toc + +toc2cue $1.toc $1.cue + +bchunk $1.bin $1.cue $1 + +rm -i $i.bin $i.toc $i.cue diff --git a/rmfen.l/README.md b/rmfen.l/README.md new file mode 100644 index 0000000..1c4c475 --- /dev/null +++ b/rmfen.l/README.md @@ -0,0 +1 @@ +Flex lexer for rithmomachia boards represented in reduced modified FEN notation. diff --git a/rmfen.l/rmfen.l b/rmfen.l/rmfen.l new file mode 100644 index 0000000..3bad1bc --- /dev/null +++ b/rmfen.l/rmfen.l @@ -0,0 +1,20 @@ +%{ +#include +%} + +%option outfile="rmfen.c" +%option always-interactive +%option nounput noinput + +space [1-7] +piece (c|s|t|C|S|T)([1-9][0-9]{0,2})"." +pyramid (p|P){piece}+"." +boardpiece ({pyramid}|{piece}) +row (({space}|{boardpiece}){0,7}{boardpiece})? +board ({row}"/"){15}{row} + +%% + +{board} { printf("Valid board: %s\n", yytext); } + +. { printf("Unknown text %s\n", yytext); } diff --git a/unknytt.py/README.md b/unknytt.py/README.md new file mode 100644 index 0000000..6ca009f --- /dev/null +++ b/unknytt.py/README.md @@ -0,0 +1 @@ +File extractor for Knytt Stories story files updated for Python 3. Originally from here: https://nifflas.lp1.nl/index.php?topic=2685.0 diff --git a/unknytt.py/unknytt.py b/unknytt.py/unknytt.py new file mode 100644 index 0000000..fea6e2e --- /dev/null +++ b/unknytt.py/unknytt.py @@ -0,0 +1,67 @@ +#!/usr/bin/python + +import struct +import os +import sys + +def readheader(f): + magic = f.read(2) + if magic == b'': + raise EOFError + if magic != b'NF': + raise ValueError("Bad header") + nextchar = f.read(1) + name = [] + while nextchar != b'\0': + name.append(nextchar.decode()) + nextchar = f.read(1) + name = ''.join(name) + sizedata = f.read(4) + (size,) = struct.unpack(' 0: + data = f.read(min(bytestowrite, 4096)) + if data == '': + raise EOFError("file ended prematurely") + outfile.write(data) + bytestowrite -= len(data) + + return True + +def unknytt(f, worlddir='.'): + try: + name, dummy = readheader(f) + except EOFError: + raise ValueError("not a valid knytt stories file") + + print("Creating %s\\" % name) + destdir = os.path.join(worlddir, name) + os.mkdir(destdir) + + while extractfile(f, destdir): + pass + + print("Everything is ok.") + +if __name__ == '__main__': + f = open(sys.argv[1], 'rb') + unknytt(f) diff --git a/whoami.php/README.md b/whoami.php/README.md new file mode 100644 index 0000000..bdae502 --- /dev/null +++ b/whoami.php/README.md @@ -0,0 +1 @@ +Testing things... diff --git a/whoami.php/whoami.php b/whoami.php/whoami.php new file mode 100644 index 0000000..29f8235 --- /dev/null +++ b/whoami.php/whoami.php @@ -0,0 +1,14 @@ +'; + +// Outputs all the result of shellcommand "ls", and returns +// the last output line into $last_line. Stores the return value +// of the shell command in $retval. +$last_line = system('whoami', $retval); + +// Printing additional info +echo ' + +
Last line of the output: ' . $last_line . ' +
Return value: ' . $retval; +?>