Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

bytecode.c 1.6 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include <signal.h>
  20. #include <math.h>
  21. #include <string.h>
  22. #include <seccomp-loader.h>
  23. char x[1024] = "this is just here because the CPUShare server cannot "
  24. "handle bytecode with no .data section";
  25. volatile int stop;
  26. void sighandler(int signal)
  27. {
  28. if(sys_write(1, "done", 4) != 4)
  29. sys_exit(3);
  30. stop = 1;
  31. }
  32. void bytecode(unsigned char * mem, int heap_size, int stack_size)
  33. {
  34. unsigned char n;
  35. char c;
  36. if(sys_read(0, (char *)&n, 1) != 1)
  37. sys_exit(-5);
  38. while(n-- && !stop)
  39. {
  40. if(sys_read(0, &c, 1) != 1)
  41. sys_exit(-5);
  42. if(c >= 'a' && c <= 'z')
  43. c = 'a' + ((c - 'a' + 13) % 26);
  44. else if(c >= 'A' && c <= 'Z')
  45. c = 'A' + ((c - 'A' + 13) % 26);
  46. if(sys_write(1, &c, 1) != 1)
  47. sys_exit(-6);
  48. }
  49. sys_exit(0);
  50. }