source: research/2008-displacement/bytecode.c @ 2824

Last change on this file since 2824 was 2286, checked in by Sam Hocevar, 12 years ago
  • More scripts for part 3.
  • Implemented main.c as a seccomp bytecode for CPUShare.
File size: 1.6 KB
Line 
1/*
2 * Copyright (C) 2004-2007  Andrea Arcangeli <andrea@cpushare.com>
3 *                    2008  Sam Hocevar <sam@zoy.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * only version 2.1 of the License.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20#include <signal.h>
21#include <math.h>
22#include <string.h>
23
24#include <seccomp-loader.h>
25
26char x[1024] = "this is just here because the CPUShare server cannot "
27               "handle bytecode with no .data section";
28
29volatile int stop;
30
31void sighandler(int signal)
32{
33    if(sys_write(1, "done", 4) != 4)
34        sys_exit(3);
35    stop = 1;
36}
37
38void bytecode(unsigned char * mem, int heap_size, int stack_size)
39{
40    unsigned char n;
41    char c;
42
43    if(sys_read(0, (char *)&n, 1) != 1)
44        sys_exit(-5);
45
46    while(n-- && !stop)
47    {
48        if(sys_read(0, &c, 1) != 1)
49            sys_exit(-5);
50
51        if(c >= 'a' && c <= 'z')
52            c = 'a' + ((c - 'a' + 13) % 26);
53        else if(c >= 'A' && c <= 'Z')
54            c = 'A' + ((c - 'A' + 13) % 26);
55
56        if(sys_write(1, &c, 1) != 1)
57            sys_exit(-6);
58    }
59
60    sys_exit(0);
61}
62
Note: See TracBrowser for help on using the repository browser.