/* dump.c -- bytecode decompiler * Jen Smith */ /*********************************************************** Copyright 1999 by Carnegie Mellon University All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Carnegie Mellon University not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *****************************************************************/ #include "sieve_interface.h" #include "bytecode.h" #include "script.h" #include "xmalloc.h" #include #include #include #include #include #include #include "map.h" void dump2(bytecode_input_t *d, int len); int dump2_test(bytecode_input_t * d, int i); /* from bc_eval.c */ int unwrap_string(bytecode_input_t *bc, int pos, const char **str, int *len); /*this is called by xmalloc*/ void fatal(const char *s, int code) { printf("Fatal error: %s (%d)\r\n", s, code); exit(1); } int load(int fd, bytecode_input_t ** d) { const char * data=NULL; struct stat sbuf; unsigned long len=0; if (fstat(fd, &sbuf) == -1) { printf("IOERROR: fstating sieve script: %m"); return SIEVE_FAIL; } /*this reads in data and length from file*/ map_refresh(fd, 1, &(data), &len, sbuf.st_size, "sievescript", ""); *d=(bytecode_input_t *)data; printf("\n"); return (len/sizeof(int)); } int main(int argc, char * argv[]) { bytecode_input_t * bc; int script_fd; unsigned long len; if (argc!=2) { fprintf(stderr, "usage:\n %s script\n", argv[0]); exit(1); } /*get script*/ script_fd = open(argv[1], O_RDONLY); if (script_fd == -1) { printf("can not open script '%s'\n", argv[1]); exit(1); } len=load(script_fd,&bc); close(script_fd); if (bc) { dump2(bc, len ); exit(0); } else { exit(1); } } int write_list(int list_len, int i, bytecode_input_t * d) { int x; i++; for (x=0; x