b8

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.vgx.fr/b8
Log | Files | Refs

commit d4bda8e59ffc61c65dcf4b42099d9bc71b7df46b
parent fd09537321a3855c703c57ece4f8636b2056a371
Author: Léo Villeveygoux <leo.villeveygoux@etu.u-bordeaux.fr>
Date:   Fri, 16 Jun 2017 15:04:14 +0200

just a binary code loader at the moment

Diffstat:
AMakefile | 14++++++++++++++
Ab8.c | 29+++++++++++++++++++++++++++++
Atest.asm | 24++++++++++++++++++++++++
3 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -0,0 +1,14 @@ +LDFLAGS=-Wl,--section-start=mem_chunk=0x20000 + +CARTS=$(patsubst %.asm,%.bin,$(wildcard *.asm)) + +all: b8 $(CARTS) + +clean: + -$(RM) b8 *.bin + +%.bin: %.asm + yasm -f bin $< -o $@ + +%.bin: %.s + yasm -f bin -r gas -p gas $< -o $@ diff --git a/b8.c b/b8.c @@ -0,0 +1,29 @@ +#include <sys/mman.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +char buf[0x40000] __attribute__ ((section ("mem_chunk"))) = {0}; + +int main(int argc, char *argv[]){ + int (*f)(void) = NULL; + + if(argc < 2) + return 1; + + int fd = open(argv[1], O_RDONLY); + if(fd == -1) perror("open"); + + int ret = mprotect(&buf, 4096, PROT_READ|PROT_WRITE|PROT_EXEC); + if(ret) perror("mprotect"); + + int rdsize = read(fd, buf, 27); + if(rdsize != 27) perror("read"); + + f = (void*)buf; + + printf("%d\n",*(int*)f()); + return 0; +} diff --git a/test.asm b/test.asm @@ -0,0 +1,24 @@ +org 0x20000 +bits 32 + +call f +ret +nop +nop +nop +nop +nop + +f: +mov eax, lol +ret +nop +nop + +lol dd 42 +nop +nop +nop +nop +nop +