Migrated first 6 gists.

This commit is contained in:
Miguel Astor
2023-01-13 18:18:55 -04:00
parent 92fcabcfba
commit 8af706e97d
16 changed files with 290 additions and 0 deletions

12
kernel.c/Makefile Normal file
View File

@@ -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

2
kernel.c/README.md Normal file
View File

@@ -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

47
kernel.c/kernel.c Normal file
View File

@@ -0,0 +1,47 @@
#include <stdint.h>
#include <stdbool.h>
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;
}

21
kernel.c/kernel.s Normal file
View File

@@ -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:

9
kernel.c/link.ld Normal file
View File

@@ -0,0 +1,9 @@
OUTPUT_FORMAT(elf32-i386)
ENTRY(start)
SECTIONS
{
. = 0x100000;
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss) }
}

1
rc4.c/README.md Normal file
View File

@@ -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

64
rc4.c/rc4.c Normal file
View File

@@ -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;
}

12
rc4.c/rc4.h Normal file
View File

@@ -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);

1
rip2iso.sh/README.md Normal file
View File

@@ -0,0 +1 @@
Rips raw data from a CD using the /dev/sr1 device (USB cd writer) to an iso image file.

17
rip2iso.sh/rip2iso.sh Normal file
View File

@@ -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

1
rmfen.l/README.md Normal file
View File

@@ -0,0 +1 @@
Flex lexer for rithmomachia boards represented in reduced modified FEN notation.

20
rmfen.l/rmfen.l Normal file
View File

@@ -0,0 +1,20 @@
%{
#include <stdio.h>
%}
%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); }

1
unknytt.py/README.md Normal file
View File

@@ -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

67
unknytt.py/unknytt.py Normal file
View File

@@ -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('<L', sizedata)
return name, size
def extractfile(f, destdir='.'):
try:
name, size = readheader(f)
except EOFError:
return False
outfilename = os.path.join(destdir, *name.split('\\'))
print("Extracting %s (%s bytes).." % (name, size))
outdir, dummy = os.path.split(outfilename)
try:
os.makedirs(outdir)
except OSError:
pass
outfile = open(outfilename, 'wb')
bytestowrite = size
while bytestowrite > 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)

1
whoami.php/README.md Normal file
View File

@@ -0,0 +1 @@
Testing things...

14
whoami.php/whoami.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
echo '<pre>';
// 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 '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>