Last active
March 17, 2016 10:51
-
-
Save alphaKAI/b9aaa0f693e7498f8a5e to your computer and use it in GitHub Desktop.
A Brainfuck Interpreter on UEFI Shell (Requirements: gnu-efi)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <efi.h> | |
#include <efilib.h> | |
#define MEMORY_SIZE 30000 | |
typedef unsigned char byte; | |
byte memory[MEMORY_SIZE] = {0}; | |
unsigned long memoryIndex = 0; | |
EFI_STATUS efi_main(EFI_HANDLE ImageHandle , EFI_SYSTEM_TABLE* SystemTable) { | |
INTN Argc, i; | |
CHAR16 **Argv; | |
InitializeLib(ImageHandle, SystemTable); | |
Argc = GetShellArgcArgv(ImageHandle, &Argv); | |
if (Argc != 2) { | |
Print(L"Invalid Argument\n"); | |
return EFI_SUCCESS; | |
} | |
for (i = 0; i < StrLen(Argv[1]); i++) { | |
switch(Argv[1][i]) { | |
case '>': memoryIndex++; break; | |
case '<': memoryIndex--; break; | |
case '+': memory[memoryIndex]++; break; | |
case '-': memory[memoryIndex]--; break; | |
case '.': Print(L"%c", memory[memoryIndex]); break; | |
case '[': if (memory[memoryIndex] == 0) while (Argv[1][i] != ']') i++; break; | |
case ']': if (memory[memoryIndex] != 0) while (Argv[1][i] != '[') i--; break; | |
default: break; | |
} | |
} | |
Print(L"\n"); | |
return EFI_SUCCESS; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARCH = $(shell uname -m | sed s,i[3456789]86,ia32,) | |
OBJS = main.o | |
TARGET = main.efi | |
EFIINC = /usr/include/efi | |
EFIINCS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol | |
EFILIB = /usr/lib | |
EFI_CRT_OBJS = $(EFILIB)/crt0-efi-$(ARCH).o | |
EFI_LDS = $(EFILIB)/elf_$(ARCH)_efi.lds | |
CFLAGS = $(EFIINCS) \ | |
-fno-stack-protector \ | |
-fpic \ | |
-fshort-wchar \ | |
-mno-red-zone \ | |
-Wall | |
ifeq ($(ARCH),x86_64) | |
CFLAGS += -DEFI_FUNCTION_WRAPPER | |
endif | |
LDFLAGS = -nostdlib \ | |
-znocombreloc \ | |
-T $(EFI_LDS) \ | |
-shared \ | |
-Bsymbolic \ | |
-L $(EFILIB) \ | |
$(EFI_CRT_OBJS) | |
all: $(TARGET) | |
%.so:$(OBJS) | |
ld $(OBJS) $(LDFLAGS) -o $@ -lefi -lgnuefi | |
%.efi: %.so | |
objcopy -j .text -j .sdata -j .data -j .dynamic \ | |
-j .dynsym -j .rel -j .rela -j .reloc \ | |
--target=efi-app-$(ARCH) $^ $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment