b8

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

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

more precise binary layout

Diffstat:
Mb8.c | 27+++++++++++++++++++--------
Mmem.txt | 16++++++++++++++--
Mtest.asm | 11+++++++----
3 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/b8.c b/b8.c @@ -5,25 +5,36 @@ #include <stdlib.h> #include <stdio.h> +#define CHECK_STD_ERROR(predicate, name) do{\ + if(predicate){\ + perror(name);\ + exit(1);\ + }\ +}while(0) + char buf[0x40000] __attribute__ ((section ("mem_chunk"))) = {0}; int main(int argc, char *argv[]){ - int (*f)(void) = NULL; + void (*cart_fun)(void) = NULL; - if(argc < 2) + if(argc < 2) { + fprintf(stderr, "Usage: %s file.bin\n", argv[0]); return 1; + } int fd = open(argv[1], O_RDONLY); - if(fd == -1) perror("open"); + CHECK_STD_ERROR(fd == -1, "open"); int ret = mprotect(&buf, 4096, PROT_READ|PROT_WRITE|PROT_EXEC); - if(ret) perror("mprotect"); + CHECK_STD_ERROR(ret, "mprotect"); + + int rdsize = read(fd, buf, 0x20000); + CHECK_STD_ERROR(rdsize == -1, "read"); - int rdsize = read(fd, buf, 27); - if(rdsize != 27) perror("read"); + cart_fun = (void*)buf+0x20; - f = (void*)buf; + cart_fun(); - printf("%d\n",*(int*)f()); + printf("%d\n",(int)buf[0x20000]); return 0; } diff --git a/mem.txt b/mem.txt @@ -4,7 +4,19 @@ 0x20000 --------- - cart mapping + cart mapping, + header: + + 0x20000 ------- + + "#!/usr/bin/env b8\n", + 0, ... + + 0x20020 ------- + + entry point, + + cart content 0x40000 --------- @@ -21,6 +33,6 @@ 0x51000 --------- - out PCM + out PCM buffer 0x52f40 --------- diff --git a/test.asm b/test.asm @@ -1,8 +1,10 @@ org 0x20000 bits 32 -call f -ret +header: db '#!/usr/bin/env b8', 0x0a +times 32-$+header db 0x0 + +jmp f nop nop nop @@ -10,12 +12,13 @@ nop nop f: -mov eax, lol +mov eax, [lol] +mov [0x40000], eax ret nop nop -lol dd 42 +lol db 42 nop nop nop