From 51e23ac98d6eea877f5d1c71663e35151b3f2059 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 18 Jan 2008 23:48:21 +0100 Subject: [PATCH] Generate a table of all known syscalls and use it to show syscall names instead of numbers. --- Makefile | 8 +++++++- src/box.c | 38 ++++++++++++++++++++++++++++++++++++-- src/mk-syscall-table | 9 +++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100755 src/mk-syscall-table diff --git a/Makefile b/Makefile index 79846d9..8c13b71 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ VERSION=1.0.1 #DEBUG=-ggdb CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -Winline $(DEBUG) -std=gnu99 -CC=gcc-4.1.1 +#CC=gcc-4.1.1 # Comment out if you are using a recent gcc CFLAGS+=-Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers @@ -26,10 +26,16 @@ bin/iwrapper: src/iwrapper.o bin/md5crypt: src/md5crypt.o src/md5.o bin/pedant: src/pedant.o +src/box.o: src/box.c src/syscall-table.h + +src/syscall-table.h: + src/mk-syscall-table + submit: clean:: rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core` + rm -f src/syscall-table.h rm -f bin/box bin/iwrapper bin/md5crypt bin/pedant distclean: clean diff --git a/src/box.c b/src/box.c index 126452a..fe1c22f 100644 --- a/src/box.c +++ b/src/box.c @@ -91,6 +91,39 @@ msg(char *msg, ...) va_end(args); } +struct syscall { + const char *name; + int override; +}; + +static struct syscall syscall_tab[] = { +#include "syscall-table.h" +}; +#define NUM_SYSCALLS (sizeof(syscall_tab)/sizeof(syscall_tab[0])) + +static const char * +syscall_name(unsigned int id, char *buf) +{ + if (id < NUM_SYSCALLS && syscall_tab[id].name) + return syscall_tab[id].name; + else + { + sprintf(buf, "#%d", id); + return buf; + } +} + +#if 0 +static struct syscall * +syscall_by_name(char *name) +{ + for (unsigned int i=0; i> Traceme request caught\n"); else if (stop_count & 1) /* Syscall entry */ { - msg(">> Syscall %3ld (%08lx,%08lx,%08lx) ", u.regs.orig_eax, u.regs.ebx, u.regs.ecx, u.regs.edx); + char namebuf[32]; + msg(">> Syscall %-12s (%08lx,%08lx,%08lx) ", syscall_name(u.regs.orig_eax, namebuf), u.regs.ebx, u.regs.ecx, u.regs.edx); if (!exec_seen) { msg("[master] "); @@ -440,7 +474,7 @@ boxkeeper(void) u.regs.orig_eax = 0xffffffff; if (ptrace(PTRACE_SETREGS, box_pid, NULL, &u) < 0) die("ptrace(PTRACE_SETREGS): %m"); - die("Forbidden syscall %d", sys); + die("Forbidden syscall %s", syscall_name(sys, namebuf)); } } else /* Syscall return */ diff --git a/src/mk-syscall-table b/src/mk-syscall-table new file mode 100755 index 0000000..e90334d --- /dev/null +++ b/src/mk-syscall-table @@ -0,0 +1,9 @@ +#!/bin/sh +set -e +( +echo '/* Syscall table automatically generated by mk-syscall-table */' +echo +echo '#include ' | + gcc -E -dM - | + sed 's/^#define __NR_\([^ ]\+\).*/[ __NR_\1 ] = { "\1", 0 },/;t;d' +) >src/syscall-table.h -- 2.39.2