Skip to content

Instantly share code, notes, and snippets.

View lighth7015's full-sized avatar
Perpetually exhausted.

Robert Butler lighth7015

Perpetually exhausted.
View GitHub Profile
@lighth7015
lighth7015 / endian.c
Created May 30, 2019 00:16
ELF loader
#include <stdint.h>
//! Byte swap unsigned short
uint16_t swap_uint16( uint16_t val )
{
return (val << 8) | (val >> 8 );
}
//! Byte swap short
int16_t swap_int16( int16_t val )
@lighth7015
lighth7015 / loader.c
Last active May 18, 2019 00:08
loader.c
#include <stdio.h>
#include <dlfcn.h>
#include <string.h>
#include <stdlib.h>
#include <libelf.h>
#include <sys/stat.h>
#include <sys/mman.h>
char* buffer;
static struct stat fileinfo;
[Unit]
Description=Minecraft Server: %i
After=network.target
[Service]
Type=simple
WorkingDirectory=/srv/minecraft/instances/%i
Environment="ServerArgs="
Environment="ServerName=minecraft_server.jar"
@lighth7015
lighth7015 / stub.asm
Last active April 19, 2019 02:08
Enter/Leave Protected Mode
org 100h
bits 16
section .text
global __start
jmp __start
Unsupported db 'This application requires at least an 80386 processor.', 0x0d, 0x0a, '$' ; $-terminated message
AlreadyInit db 'Already in Protected Mode!', 0x0d, 0x0a, '$' ; $-terminated message
A20LineFail db 'A20 Line is Disabled or Not Present.', 0x0d, 0x0a, '$' ; $-terminated message
@lighth7015
lighth7015 / stub.asm
Last active April 18, 2019 17:19
Enter/Leave Protected Mode
org 0x100
start: use16
cli ; disable interrupts
in al, 0x92 ; IO port method to enable A20
or al, 2
and al,0xFE
out 0x92, al
lgdt [descriptor] ; load GDT header into GDT register, so the CPU can find the GDT entries
@lighth7015
lighth7015 / main.asm
Created April 17, 2019 17:57
Protected Mode
;---
; Giza system bootstrap
; - check for a supported CPU, exit with error message if unsupported
; - Enter Protected Mode
; - Call system bootstrap
; - Leave Protected Mode
; - exit (status = byte obtatained)
;
Unsupported db "CPU: Not an 80386-class CPU; unable to start",0Dh,0Ah,'$'
const MyComponent = {
PostOffice: {
PaymentAuthorization: {
fromEcho: true,
isPublic: false
},
"Foo": "Bar",
},
@lighth7015
lighth7015 / stdin
Created March 29, 2019 20:17
stdin
/usr/bin/ld.bfd: /tmp/main-12cd4f.o: in function `main':
main.c:(.text+0x20): undefined reference to `_GLOBAL_OFFSET_TABLE_'
/usr/bin/ld.bfd: ../lib/libdos.a(doscrt0.o): in function `argstart':
doscrt0.c:(.text+0x1b): undefined reference to `_GLOBAL_OFFSET_TABLE_'
/usr/bin/ld.bfd: ../lib/libdos.a(conio.o): in function `_getcinfo':
conio.c:(.text+0xf): undefined reference to `_GLOBAL_OFFSET_TABLE_'
/usr/bin/ld.bfd: ../lib/libdos.a(conio.o): in function `setpage':
conio.c:(.text+0x56): undefined reference to `_GLOBAL_OFFSET_TABLE_'
/usr/bin/ld.bfd: ../lib/libdos.a(conio.o): in function `getpage':
conio.c:(.text+0xa6): undefined reference to `_GLOBAL_OFFSET_TABLE_'
$ clang -nostdlib -fno-{stack-protector,jump-tables,addrsig,builtin} -ffreestanding -I../include -oexample.com -Wall \
-Wextra -pedantic -mregparm=3 -std=c99 -Oz -m16 -march=i386 -Wl,--omagic,--script=../lib/doscom.ld -fuse-ld=bfd main.c \
../lib/libdos.a
/usr/bin/ld.bfd: /tmp/main-de9979.o: in function `main':
main.c:(.text+0x20): undefined reference to `_GLOBAL_OFFSET_TABLE_'
/usr/bin/ld.bfd: ../lib/libdos.a(doscrt0.o): in function `argstart':
doscrt0.c:(.text+0x1b): undefined reference to `_GLOBAL_OFFSET_TABLE_'
/usr/bin/ld.bfd: ../lib/libdos.a(conio.o): in function `_getcinfo':
conio.c:(.text+0xf): undefined reference to `_GLOBAL_OFFSET_TABLE_'
/usr/bin/ld.bfd: ../lib/libdos.a(conio.o): in function `setpage':
@lighth7015
lighth7015 / type.c
Created March 22, 2019 20:02
Object type system
#define _GNU_SOURCE
#define STATIC_DECLARE_INIT(sym, name, id, ...) \
sym __attribute__ ((section (id))) name = { __VA_ARGS__ };
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>