diff options
author | Juan Cespedes <cespedes@thehackers.org> | 1997-06-09 01:12:01 +0200 |
---|---|---|
committer | Juan Cespedes <cespedes@thehackers.org> | 1997-06-09 01:12:01 +0200 |
commit | 1c2be91d7491940c8f8edea251b10bfca704771b (patch) | |
tree | 1ca1462f96ce15410faf6df2f1f636115f8b2983 | |
parent | bda1dbf1cc9db66580f5afd58195d27e8edcf94b (diff) | |
download | ltrace-1c2be91d7491940c8f8edea251b10bfca704771b.tar.gz |
Version 0.0.1997.06.09
Completely new approach: use software breakpoints (INT 3, CC) in process
using ptrace(), just like gdb and strace do
37 files changed, 152 insertions, 2429 deletions
@@ -1,17 +1,11 @@ CC = gcc -CFLAGS = -Wall -O2 -Iinclude -LD = ld +CFLAGS = -Wall -Werror -O2 -all: - @echo 'Type "make dist" to make a distribution .tgz' - @echo +all: ltrace clean: - make -C src/libtrace clean - make -C src/ltrace clean - make -C src/test clean - rm -f *.o + rm -f ltrace ltrace.o dist: make clean - ( cd .. ; tar zcvf ltrace-`date +%y%m%d`.tgz ltrace ) + ( cd .. ; tar zcvf ltrace2-`date +%y%m%d`.tgz ltrace2 ) diff --git a/Makefile2 b/Makefile2 new file mode 100644 index 0000000..0278488 --- /dev/null +++ b/Makefile2 @@ -0,0 +1,17 @@ +CC = gcc +CFLAGS = -Wall -O2 -Iinclude +LD = ld + +all: + @echo 'Type "make dist" to make a distribution .tgz' + @echo + +clean: + make -C src/libtrace clean + make -C src/ltrace clean + make -C src/test clean + rm -f *.o + +dist: + make clean + ( cd .. ; tar zcvf ltrace-`date +%y%m%d`.tgz ltrace ) @@ -1,7 +1,5 @@ Funcionamiento: --------------- -* Intercepts library function '__setfpucw' - -YA NO: Ahora usa seccion 'ctors' para inicializacion de la libreria; - ya no exporta ninguna funcion. +* Puts soft breakpoints (INT 3, CC) in process using ptrace, just like + gdb/strace diff --git a/include/hck/ctype.h b/include/hck/ctype.h deleted file mode 100644 index 9a128d4..0000000 --- a/include/hck/ctype.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _HCK_CTYPE_H -#define _HCK_CTYPE_H - -#define _U 0x01 /* upper */ -#define _L 0x02 /* lower */ -#define _D 0x04 /* digit */ -#define _C 0x08 /* cntrl */ -#define _P 0x10 /* punct */ -#define _S 0x20 /* white space (space/lf/tab) */ -#define _X 0x40 /* hex digit */ -#define _SP 0x80 /* hard space (0x20) */ - -extern unsigned char _ctype[]; -extern char _ctmp; - -#define isalnum(c) ((_ctype+1)[c]&(_U|_L|_D)) -#define isalpha(c) ((_ctype+1)[c]&(_U|_L)) -#define iscntrl(c) ((_ctype+1)[c]&(_C)) -#define isdigit(c) ((_ctype+1)[c]&(_D)) -#define isgraph(c) ((_ctype+1)[c]&(_P|_U|_L|_D)) -#define islower(c) ((_ctype+1)[c]&(_L)) -#define isprint(c) ((_ctype+1)[c]&(_P|_U|_L|_D|_SP)) -#define ispunct(c) ((_ctype+1)[c]&(_P)) -#define isspace(c) ((_ctype+1)[c]&(_S)) -#define isupper(c) ((_ctype+1)[c]&(_U)) -#define isxdigit(c) ((_ctype+1)[c]&(_D|_X)) - -#define isascii(c) (((unsigned) c)<=0x7f) -#define toascii(c) (((unsigned) c)&0x7f) - -#define tolower(c) (_ctmp=c,isupper(_ctmp)?_ctmp-('A'-'a'):_ctmp) -#define toupper(c) (_ctmp=c,islower(_ctmp)?_ctmp-('a'-'A'):_ctmp) - -#endif /* _HCK_CTYPE_H */ diff --git a/include/hck/syscall.h b/include/hck/syscall.h deleted file mode 100644 index 5432fcd..0000000 --- a/include/hck/syscall.h +++ /dev/null @@ -1,237 +0,0 @@ -#ifndef _HCK_SYSCALL_H -#define _HCK_SYSCALL_H - -#include <errno.h> - -#include <utime.h> /* utime */ -#include <linux/types.h> /* chmod */ -#include <asm/signal.h> -#include <linux/resource.h> -#include <linux/dirent.h> -#include <asm/statfs.h> -#include <sys/stat.h> -#include <sys/utsname.h> -#include <linux/time.h> -#include <linux/socket.h> - -#define __NR_exit 1 -#define __NR_fork 2 -#define __NR_read 3 -#define __NR_write 4 -#define __NR_open 5 -#define __NR_close 6 -#define __NR_waitpid 7 -#define __NR_creat 8 -#define __NR_link 9 -#define __NR_unlink 10 -#define __NR_execve 11 -#define __NR_chdir 12 -#define __NR_time 13 -#define __NR_mknod 14 -#define __NR_chmod 15 -#define __NR_chown 16 -#define __NR_lseek 19 -#define __NR_getpid 20 -#define __NR_mount 21 -#define __NR_umount 22 -#define __NR_setuid 23 -#define __NR_getuid 24 -#define __NR_alarm 27 -#define __NR_pause 29 -#define __NR_utime 30 -#define __NR_access 33 -#define __NR_sync 36 -#define __NR_kill 37 -#define __NR_rename 38 -#define __NR_mkdir 39 -#define __NR_rmdir 40 -#define __NR_dup 41 -#define __NR_pipe 42 -#define __NR_brk 45 -#define __NR_getgid 47 -#define __NR_signal 48 -#define __NR_geteuid 49 -#define __NR_getegid 50 -#define __NR_ioctl 54 -#define __NR_fcntl 55 -#define __NR_umask 60 -#define __NR_dup2 63 -#define __NR_setsid 66 -#define __NR_sigaction 67 -#define __NR_setrlimit 75 -#define __NR_getrusage 77 -#define __NR_gettimeofday 78 -#define __NR_symlink 83 -#define __NR_readlink 85 -#define __NR_swapon 87 -#define __NR_reboot 88 -#define __NR_readdir 89 -#define __NR_mmap 90 -#define __NR_fchmod 94 -#define __NR_fchown 95 -#define __NR_statfs 99 -#define __NR_socketcall 102 -#define __NR_stat 106 -#define __NR_lstat 107 -#define __NR_fstat 108 -#define __NR_wait4 114 -#define __NR_swapoff 115 -#define __NR_uname 122 -#define __NR_mprotect 125 -#define __NR_llseek 140 -#define __NR_select 142 - -#define __NR__exit __NR_exit - -#ifndef _INLINE -#define _INLINE static inline -#endif - -#if 0 -#define __syscall_return(type, res) \ -do { \ - if ((unsigned long)(res) >= (unsigned long)(-125)) { \ - errno = -(res); \ - res = -1; \ - } \ - return (type) (res); \ -} while (0) -#else -#define __syscall_return(type, res) \ -do { \ - return (type) (res); \ -} while (0) -#endif - -#define _syscall0(type,name) \ -_INLINE type _sys_##name(void) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name)); \ -__syscall_return(type,__res); \ -} - -#define _syscall1(type,name,type1,arg1) \ -_INLINE type _sys_##name(type1 arg1) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name),"b" ((long)(arg1))); \ -__syscall_return(type,__res); \ -} - -#define _syscall2(type,name,type1,arg1,type2,arg2) \ -_INLINE type _sys_##name(type1 arg1,type2 arg2) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \ -__syscall_return(type,__res); \ -} - -#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ -_INLINE type _sys_##name(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3))); \ -__syscall_return(type,__res); \ -} - -#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -_INLINE type _sys_##name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3)),"S" ((long)(arg4))); \ -__syscall_return(type,__res); \ -} - -#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -_INLINE type _sys_##name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \ -__syscall_return(type,__res); \ -} - -_syscall1(void,_exit,int,exitcode) -_syscall0(int,fork) -_syscall3(int,read,int,fd,char *,buf,long,count) -_syscall3(int,write,int,fd,const char *,buf,long,count) -_syscall3(int,open,const char *,file,int,flag,int,mode) -_syscall1(int,close,int,fd) -_syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options) -_syscall2(int,creat,const char *,file,mode_t,mode) -_syscall2(int,link,const char *,oldpath,const char *,newpath) -_syscall1(int,unlink,const char *,file) -_syscall3(int,execve,const char *,file,const char **,argv,const char **,envp) -_syscall1(int,chdir,const char *,path) -_syscall1(time_t,time,time_t *,t) -_syscall3(int,mknod,const char *,pathname,mode_t,mode,dev_t,dev) -_syscall2(int,chmod,const char *,file,mode_t,mode) -_syscall3(int,chown,const char *,file,uid_t,owner,gid_t,group) -_syscall3(off_t,lseek,int,fd,off_t,offset,int,whence) -_syscall0(pid_t,getpid) -_syscall5(int,mount,const char *,file,const char *,dir,const char *,fstype,unsigned long,rwflag,const void *,data) -_syscall1(int,umount,const char *,file) -_syscall1(uid_t,setuid,uid_t,uid) -_syscall0(gid_t,getuid) -_syscall1(long,alarm,long,seconds) -_syscall0(int,pause) -_syscall2(int,utime,const char *,file,const struct utimbuf *,buf) -_syscall2(int,access,const char *,pathname,int,mode) -_syscall0(int,sync) -_syscall2(int,kill,int,pid,int,sig) -_syscall2(int,rename,const char *,oldpath,const char *,newpath) -_syscall2(int,mkdir,const char *,pathname,int,mode) -_syscall1(int,rmdir,const char *,pathname) -_syscall1(int,dup,int,oldfd) -_syscall1(int,pipe,int *,filedes) -_syscall1(void *,brk,void *,brk) -_syscall0(gid_t,getgid) -_syscall0(uid_t,geteuid) -_syscall0(gid_t,getegid) -_syscall2(__sighandler_t,signal,int,signum,__sighandler_t,handle) -_syscall3(int,ioctl,unsigned int,fd,unsigned int,cmd,unsigned long,arg) -_syscall3(int,fcntl,unsigned int,fd,unsigned int,cmd,unsigned long,arg) -_syscall1(int,umask,int,mask) -_syscall2(int,dup2,int,oldfd,int,newfd) -_syscall0(pid_t,setsid) -_syscall3(int,sigaction,int,signum,const struct sigaction *,act,const struct sigaction*,oldact) -_syscall2(int,setrlimit,int,resource,const struct rlimit *,rlim) -_syscall2(int,getrusage,int,who,struct rusage *,usage) -_syscall2(int,gettimeofday,struct timeval *,tv,struct timezone *,tz) -_syscall2(int,symlink,const char *,oldpath,const char *,newpath) -_syscall3(int,readlink,const char *,path,char *,buf,size_t,bufsiz) -_syscall2(int,swapon,const char *,path,int,swapflags) -_syscall3(int,reboot,int,magic,int,magic_too,int,flag) -_syscall3(int,readdir,unsigned int,fd,struct dirent *,dirp,unsigned int,count) -_syscall1(long,mmap,unsigned long *,buffer) -_syscall2(int,fchmod,int,fd,mode_t,mode) -_syscall3(int,fchown,int,fd,uid_t,owner,gid_t,group) -_syscall2(int,statfs,const char *,path,struct statfs *,buf) -_syscall2(int,socketcall,int,call,unsigned long *,args) -_syscall2(int,stat,const char *,file_name,struct stat *,buff) -_syscall2(int,lstat,const char *,file_name,struct stat *,buff) -_syscall2(int,fstat,int,filedes,struct stat *,buff) -_syscall4(pid_t,wait4,pid_t,pid,int *,status,int,options,struct rusage *,rusage) -_syscall1(int,swapoff,const char *,path) -_syscall1(int,uname,struct utsname *,buf) -_syscall3(int,mprotect,caddr_t,addr,size_t,len,int,prot) -_syscall5(int,llseek,int,fd,unsigned long,hi,unsigned long,lo,loff_t *,result,unsigned int,whence) -_syscall5(int,select,int,n,fd_set *,readfds,fd_set *,writefds,fd_set *,exceptfds,struct timeval *,timeout) - -#endif /* _HCK_SYSCALL_H */ diff --git a/lib/libtrace.so.1 b/lib/libtrace.so.1 Binary files differdeleted file mode 100755 index 07ed632..0000000 --- a/lib/libtrace.so.1 +++ /dev/null diff --git a/ltrace.c b/ltrace.c new file mode 100644 index 0000000..207913a --- /dev/null +++ b/ltrace.c @@ -0,0 +1,129 @@ +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/ptrace.h> +#include <sys/resource.h> +#include <sys/wait.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <linux/elf.h> +#include <sys/mman.h> +#include <string.h> + +u_long strtab; +u_long symtab; +u_long symtab_len; + +int read_elf(char *filename) +{ + struct stat sbuf; + int fd; + void * addr; + struct elf32_hdr * hdr; + Elf32_Shdr * shdr; + int i; + + strtab = symtab = symtab_len = 0; + + fd = open(filename, O_RDONLY); + if (fd==-1) { + fprintf(stderr, "Can't open \"%s\": %s\n", filename, sys_errlist[errno]); + exit(1); + } + if (fstat(fd, &sbuf)==-1) { + fprintf(stderr, "Can't stat \"%s\": %s\n", filename, sys_errlist[errno]); + exit(1); + } + if (sbuf.st_size < sizeof(struct elf32_hdr)) { + fprintf(stderr, "\"%s\" is not an ELF object\n", filename); + exit(1); + } + addr = mmap(NULL, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0); + if (addr==(void*)-1) { + fprintf(stderr, "Can't mmap \"%s\": %s\n", filename, sys_errlist[errno]); + exit(1); + } + hdr = addr; + if (strncmp(hdr->e_ident, ELFMAG, SELFMAG)) { + fprintf(stderr, "\"%s\" is not an ELF object\n", filename); + exit(1); + } + for(i=0; i<hdr->e_shnum; i++) { + shdr = addr + hdr->e_shoff + i*hdr->e_shentsize; + if (shdr->sh_type == SHT_DYNSYM) { + if (!symtab) { + symtab = shdr->sh_addr; + symtab_len = shdr->sh_size; + } + } + if (shdr->sh_type == SHT_STRTAB) { + if (!strtab) { + strtab = shdr->sh_addr; + } + } + } + fprintf(stderr, "symtab: 0x%08lx\n", symtab); + fprintf(stderr, "symtab_len: %lu\n", symtab_len); + fprintf(stderr, "strtab: 0x%08lx\n", strtab); + return 0; +} + +int main(int argc, char **argv) +{ + int pid; + int status; + struct rusage ru; + + if (argc<2) { + fprintf(stderr, "Usage: %s <program> [<arguments>]\n", argv[0]); + exit(1); + } + read_elf(argv[1]); + if (!symtab) { + fprintf(stderr, "%s: Not dynamically linked\n", argv[0]); + exit(1); + } + pid = fork(); + if (pid<0) { + perror("fork"); + exit(1); + } else if (!pid) { + if (ptrace(PTRACE_TRACEME, 0, 1, 0) < 0) { + perror("PTRACE_TRACEME"); + exit(1); + } + execvp(argv[1], argv+1); + fprintf(stderr, "Can't execute \"%s\": %s\n", argv[1], sys_errlist[errno]); + exit(1); + } + fprintf(stderr, "pid %u attached\n", pid); + while(1) { + pid = wait4(-1, &status, 0, &ru); + if (pid==-1) { + if (errno == ECHILD) { + fprintf(stderr, "No more children\n"); + exit(0); + } + perror("wait4"); + exit(1); + } + if (WIFEXITED(status)) { + fprintf(stderr, "pid %u exited\n", pid); + continue; + } + fprintf(stderr,"EIP = 0x%08x\n", ptrace(PTRACE_PEEKUSR, pid, 4*EIP, 0)); + fprintf(stderr,"EBP = 0x%08x\n", ptrace(PTRACE_PEEKUSR, pid, 4*EBP, 0)); +#if 0 + ptrace(PTRACE_SINGLESTEP, pid, 0, 0); + continue; +#endif + if (WIFSTOPPED(status)) { + fprintf(stderr, "pid %u stopped; continuing it...\n", pid); + ptrace(PTRACE_CONT, pid, 1, 0); + } else { + fprintf(stderr, "pid %u ???\n", pid); + } + } + exit(0); +} diff --git a/src/libtrace/Makefile b/src/libtrace/Makefile deleted file mode 100644 index 2bb1cce..0000000 --- a/src/libtrace/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -TOPDIR = /home/cespedes/c/ltrace -CC = gcc -CFLAGS = -Wall -O2 -I$(TOPDIR)/include -g -LD = ld - -OBJS = libtrace.o - -all: libtrace.so.1 - -libtrace.o: libtrace.c init_libtrace.c strlen.c strncmp.c getenv.c atoi.c bcopy.c sprintf.c vsprintf.c strcmp.c strnlen.c strcat.c unsetenv.c print_results.c printf.c - -libtrace.so.1: $(OBJS) - $(LD) -shared -m elf_i386 -soname $@ -o $@ $(OBJS) - cp libtrace.so.1 $(TOPDIR)/lib - -clean: - rm -f $(OBJS) libtrace.so.1 diff --git a/src/libtrace/TODO b/src/libtrace/TODO deleted file mode 100644 index a7462e7..0000000 --- a/src/libtrace/TODO +++ /dev/null @@ -1,29 +0,0 @@ -* Las funciones llamadas dentro de otras por primera vez dejan de - estar controladas por el programa (cambia su GOT sin que nos - enteremos) - -* Las funciones de no retorno (ie, longjmp), pueden fastidiar al - programa. - -SOLUCION: Olvidarnos del 'reentrant' y loggear todo; y comprobar - *todo el GOT* del programa de vez en cuando (de manera - inteligente; cuando sabemos que se ha llamado a una funcion - nueva, por ejemplo) - -WARNING: Si se quiere loggear todo, hay que tener presente que pueden - estar ejecutandose varias llamadas a la vez; no basta con - tener un 'where_to_return'; hay que tener muchos (tal vez se - podria hacer con un struct similar a 'ax_jmp_t')... - -SOLUCION 2: Para evitar que se nos pase alguna funcion (por ejemplo, - dos funciones noreturn que se llaman una detras de otra), - se podria modificar el ".plt" en lugar del ".got", y - saltar siempre luego a la direccion del ".got" que - corresponda. - -* Usar 'errno' para loggear errores de library calls - -* Usar 'msync' (o algo parecido; 'access'?) para ver si las - direcciones dereferenciadas son validas, para evitar SIGSEGV - -* Deberia usar 'pusha' e incluso 'pushf' diff --git a/src/libtrace/atoi.c b/src/libtrace/atoi.c deleted file mode 100644 index de6a173..0000000 --- a/src/libtrace/atoi.c +++ /dev/null @@ -1,13 +0,0 @@ -static unsigned long atoi(const char *cp) -{ - unsigned long result; - - result = 0; - - while(*cp >= '0' && *cp <= '9') { - result = 10*result + *cp-'0'; - cp++; - } - return(result); -} - diff --git a/src/libtrace/bcopy.c b/src/libtrace/bcopy.c deleted file mode 100644 index 1fb8f1c..0000000 --- a/src/libtrace/bcopy.c +++ /dev/null @@ -1,10 +0,0 @@ -static char * bcopy(const char * src, char * dest, int count) -{ - char *tmp = dest; - - while (count--) - *tmp++ = *src++; - - return dest; -} - diff --git a/src/libtrace/getenv.c b/src/libtrace/getenv.c deleted file mode 100644 index 2ed15d6..0000000 --- a/src/libtrace/getenv.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <sys/types.h> - -extern char **__environ; - -static char * getenv(const char *name) -{ - register const size_t len = strlen(name); - register char **ep; - - for (ep = __environ; *ep != NULL; ++ep) - if (!strncmp(*ep, name, len) && (*ep)[len] == '=') - return(&(*ep)[len + 1]); - - return(NULL); -} diff --git a/src/libtrace/init_libtrace-old.c b/src/libtrace/init_libtrace-old.c deleted file mode 100644 index c79ea37..0000000 --- a/src/libtrace/init_libtrace-old.c +++ /dev/null @@ -1,200 +0,0 @@ -#include <fcntl.h> -#include <sys/types.h> -#include <linux/elf.h> -#include <hck/syscall.h> -#include <sys/mman.h> - -static int fd = 2; - -static char ax_jmp[] = { - 0xb8, 1, 2, 3, 4, /* movl $0x04030201, %eax */ - 0xa3, 5, 6, 7, 8, /* movl %eax, 0x08070605 */ - 0xff, 0x25, 1, 2, 3, 4, /* jmp *0x04030201 */ - 0, 0, 0, 0, /* real_func */ - 0, 0, 0, 0, /* name */ - 0, 0, 0, 0 /* got */ -}; - -static char where_to_ret[] = { -}; - -struct ax_jmp_t { - char tmp1; - void * src __attribute__ ((packed)); - char tmp2; - void * dst __attribute__ ((packed)); - char tmp3,tmp4; - void * new_func __attribute__ ((packed)); - void * real_func __attribute__ ((packed)); - char * name __attribute__ ((packed)); - u_long * got __attribute__ ((packed)); -}; - -static struct ax_jmp_t * pointer_tmp; -static struct ax_jmp_t * pointer; - -static void new_func(void); -static void * new_func_ptr = NULL; - -static int current_pid; - -static void init_libtrace(void) -{ - int i,j; - void * k; - struct elf32_sym * symtab = NULL; - size_t symtab_len = 0; - char * strtab = NULL; - char * tmp; - int nsymbols = 0; - long buffer[6]; - struct ax_jmp_t * table; - - if (new_func_ptr) { - return; - } - new_func_ptr = new_func; - - current_pid = _sys_getpid(); - - tmp = getenv("LTRACE_FILENAME"); - if (tmp) { - int fd_old; - - fd_old = _sys_open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (fd_old<0) { - _sys_write(2, "Can't open LTRACE_FILENAME\n", 27); - return; - } - fd = _sys_dup2(fd_old, 234); - _sys_close(fd_old); - if (fd<0) { - _sys_write(2, "Not enough fd's?\n", 17); - return; - } - } - - tmp = getenv("LTRACE_SYMTAB"); - if (!tmp) { - _sys_write(fd, "No LTRACE_SYMTAB...\n", 20); - return; - } - symtab = (struct elf32_sym *)atoi(tmp); - - tmp = getenv("LTRACE_SYMTAB_LEN"); - if (!tmp) { - _sys_write(fd, "No LTRACE_SYMTAB_LEN...\n", 24); - return; - } - symtab_len = atoi(tmp); - - tmp = getenv("LTRACE_STRTAB"); - if (!tmp) { - _sys_write(fd, "No LTRACE_STRTAB...\n", 20); - return; - } - strtab = (char *)atoi(tmp); - - unsetenv("LD_PRELOAD"); - unsetenv("LTRACE_SYMTAB"); - unsetenv("LTRACE_SYMTAB_LEN"); - unsetenv("LTRACE_STRTAB"); - - for(i=0; i<symtab_len/sizeof(struct elf32_sym); i++) { - if (!((symtab+i)->st_shndx) && (symtab+i)->st_value) { - nsymbols++; -#if 0 - _sys_write(fd, "New symbol: ", 12); - _sys_write(fd,strtab+(symtab+i)->st_name,strlen(strtab+(symtab+i)->st_name)); - _sys_write(fd, "\n", 1); -#endif - } - } - - buffer[0] = 0; - buffer[1] = nsymbols * sizeof(struct ax_jmp_t); - buffer[2] = PROT_READ | PROT_WRITE | PROT_EXEC; - buffer[3] = MAP_PRIVATE | MAP_ANON; - buffer[4] = 0; - buffer[5] = 0; - table = (struct ax_jmp_t *)_sys_mmap(buffer); - if (!table) { - _sys_write(fd,"Cannot mmap?\n",13); - return; - } - - j=0; - for(i=0; i<symtab_len/sizeof(struct elf32_sym); i++) { - if (!((symtab+i)->st_shndx) && (symtab+i)->st_value) { - bcopy(ax_jmp, (char *)&table[j], sizeof(struct ax_jmp_t)); - table[j].src = (char *)&table[j]; - table[j].dst = &pointer_tmp; - table[j].new_func = &new_func_ptr; - table[j].name = strtab+(symtab+i)->st_name; - table[j].got = (u_long *)*(long *)(((int)((symtab+i)->st_value))+2); - table[j].real_func = (void *)*(table[j].got); - k = &table[j]; - bcopy((char*)&k, (char *)table[j].got, 4); - j++; - } - } - - _sys_write(fd,"ltrace starting...\n",19); -} - -static u_long where_to_return; -static u_long returned_value; -static u_long where_to_jump; - -static int reentrant=0; - -static void print_results(u_long arg); - -static void kk(void) -{ - char buf[1024]; - sprintf(buf, "\n%s(", pointer_tmp->name); - _sys_write(fd,buf,strlen(buf)); -} - -static void new_func(void) -{ -#if 1 - kk(); -#endif - if (reentrant) { -#if 0 -_sys_write(fd,"reentrant\n",10); -#endif - __asm__ __volatile__( - "movl %%ebp, %%esp\n\t" - "popl %%ebp\n\t" - "jmp *%%eax\n" - : : "a" (pointer_tmp->real_func) - ); - } - reentrant=1; - pointer = pointer_tmp; - where_to_jump = (u_long)pointer->real_func; - - /* This is only to avoid a GCC warning; shouldn't be here: - */ - where_to_return = (long)print_results; - - /* HCK: Is all these stuff about 'ebp' buggy? */ - __asm__ __volatile__( - "movl %ebp, %esp\n\t" - "popl %ebp\n\t" - "popl %eax\n\t" - "movl %eax, where_to_return\n\t" - "movl where_to_jump, %eax\n\t" - "call *%eax\n\t" - "movl %eax, returned_value\n\t" - "call print_results\n\t" - "movl where_to_return, %eax\n\t" - "pushl %eax\n\t" - "movl returned_value, %eax\n\t" - "movl $0, reentrant\n\t" - "ret\n" - ); -} diff --git a/src/libtrace/init_libtrace.c b/src/libtrace/init_libtrace.c deleted file mode 100644 index 914c98e..0000000 --- a/src/libtrace/init_libtrace.c +++ /dev/null @@ -1,260 +0,0 @@ -#include <fcntl.h> -#include <sys/types.h> -#include <linux/elf.h> -#include <hck/syscall.h> -#include <sys/mman.h> - -static int fd; - -static char trampoline[] = { - 1, 2, 3, 4, /* pointer to this pushl: */ - 0x68, 1, 2, 3, 4, /* pushl $0x04030201 (symbol index) */ - 0xff, 0x25, 1, 2, 3, 4 /* jmp *0x04030201 */ -}; - -struct trampoline_t { - void * aqui __attribute__ ((packed)); - char tmp1; - long function_no __attribute__ ((packed)); - char tmp2, tmp3; - void (*new_func)() __attribute__ ((packed)); -}; - -void ** GOT; /* Array indexed by 'symbol index' (value pushed) */ - /* This is the address of the real GOT corresponding to this function */ -char ** names; /* names of the functions called */ - -static void new_func(unsigned long); -static void * new_func_ptr = NULL; - -static int current_pid; - -static void init_libtrace(void) -{ - int i,j; - struct elf32_sym * symtab = NULL; - size_t symtab_len = 0; - char * tmp; - long buffer[6]; - struct trampoline_t * table; - unsigned long plt_min=-1, plt_max=0; - char * strtab = NULL; - size_t nsymbols; - - if (new_func_ptr) { - return; - } - new_func_ptr = new_func; - - current_pid = _sys_getpid(); - - tmp = getenv("LTRACE_FILENAME"); - if (tmp) { - int fd_old; - - fd_old = _sys_open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (fd_old<0) { - _sys_write(2, "Can't open LTRACE_FILENAME\n", 27); - return; - } - fd = _sys_dup2(fd_old, 234); - _sys_close(fd_old); - } else { - fd = _sys_dup2(2, 234); - } - if (fd<0) { - _sys_write(2, "Not enough fd's?\n", 17); - return; - } - - tmp = getenv("LTRACE_SYMTAB"); - if (!tmp) { - _sys_write(fd, "No LTRACE_SYMTAB...\n", 20); - return; - } - symtab = (struct elf32_sym *)atoi(tmp); - - tmp = getenv("LTRACE_SYMTAB_LEN"); - if (!tmp) { - _sys_write(fd, "No LTRACE_SYMTAB_LEN...\n", 24); - return; - } - symtab_len = atoi(tmp); - - tmp = getenv("LTRACE_STRTAB"); - if (!tmp) { - _sys_write(fd, "No LTRACE_STRTAB...\n", 20); - return; - } - strtab = (char *)atoi(tmp); - - unsetenv("LD_PRELOAD"); - unsetenv("LTRACE_SYMTAB"); - unsetenv("LTRACE_SYMTAB_LEN"); - unsetenv("LTRACE_STRTAB"); - - nsymbols = 0; - for(i=0; i<symtab_len/sizeof(struct elf32_sym); i++) { - if (!((symtab+i)->st_shndx) && (symtab+i)->st_value) { - unsigned got_tmp; - nsymbols++; - if ((symtab+i)->st_value < plt_min) { - plt_min = (symtab+i)->st_value; - } - if ((symtab+i)->st_value > plt_max) { - plt_max = (symtab+i)->st_value; - } - -#if 1 - got_tmp = (long)*(long *)(((int)((symtab+i)->st_value))+2); - - printf("New symbol: %-16s, JMP: 0x%08x, GOT: 0x%08x\n", - (strtab+(symtab+i)->st_name), - (unsigned)((symtab+i)->st_value), got_tmp); - printf("tpnt = 0x%08lx\n", - *(long *)(2+((symtab+i)->st_value)+16+(long)*(long *)(((int)((symtab+i)->st_value))+12)) - ); - -#endif - } - } - printf("Total: %d symbols; plt_min=0x%08lx, plt_max=0x%08lx\n", nsymbols, plt_min, plt_max); - - buffer[0] = 0; - buffer[1] = nsymbols * sizeof(struct trampoline_t) + 2 * nsymbols * sizeof(void *); - buffer[2] = PROT_READ | PROT_WRITE | PROT_EXEC; - buffer[3] = MAP_PRIVATE | MAP_ANON; - buffer[4] = 0; - buffer[5] = 0; - GOT = (void **)_sys_mmap(buffer); - if (!GOT) { - printf("ltrace: Cannot mmap?\n"); - return; - } - names = (char **)(GOT + nsymbols); - table = (struct trampoline_t *)(names + nsymbols); - plt_min = plt_min & ~(4096-1); - printf("plt_min=0x%08x, GOT=0x%08x, names=0x%08x, table=0x%08x\n", plt_min,GOT,names,table); - i = _sys_mprotect((void*)plt_min, plt_max-plt_min+6, PROT_READ | PROT_WRITE | PROT_EXEC); - if (i<0) { - printf("ltrace: Cannot mprotect?\n"); - return; - } - j=0; - for(i=0; i<symtab_len/sizeof(struct elf32_sym); i++) { - if (!((symtab+i)->st_shndx) && (symtab+i)->st_value) { - void * table_tmp; - GOT[j] = (void **)*(long *)(((int)((symtab+i)->st_value))+2); - names[j] = (strtab+(symtab+i)->st_name); - bcopy(trampoline, (char *)&table[j], sizeof(struct trampoline_t)); - table[j].aqui = (void *)(&table[j]) + sizeof(void *); - table[j].function_no = j; - table[j].new_func = &new_func_ptr; - printf("GOT[%d] = 0x%08x\n", j, GOT[j]); - printf("names[%d] = \"%s\"\n", j, names[j]); - printf("table[%d].aqui = 0x%08x\n", j, table[j].aqui); - printf("table[%d].function_no = 0x%08x\n", j, table[j].function_no); - printf("table[%d].new_func = 0x%08x\n", j, table[j].new_func); - table_tmp = &table[j]; -#if 1 /* HCK: aun no funciona */ - bcopy(&table_tmp, (void*)(((int)((symtab+i)->st_value))+2), sizeof(void*)); - printf("NEW_GOT[%d] = 0x%08x\n", j, (long)*(long *)(((int)((symtab+i)->st_value))+2)); -#endif - j++; - } - } - printf("OUT OF init_libtrace\n"); -#if 1 - return; -} -static void new_func(unsigned long a) -{ - unsigned long * params = &a; - printf("params[-1]=0x%08x\n", params[-1]); - printf("params[0]=0x%08x\n", params[0]); - printf("params[1]=0x%08x\n", params[1]); - _sys_sync(); - printf("Se ha llamado a la funcion numero %d (%s)\n", params[-1], names[params[-1]]); - _sys__exit(2); -} -#else - - j=0; - for(i=0; i<symtab_len/sizeof(struct elf32_sym); i++) { - if (!((symtab+i)->st_shndx) && (symtab+i)->st_value) { -#if 0 - bcopy(ax_jmp, (char *)&table[j], sizeof(struct ax_jmp_t)); - table[j].src = (char *)&table[j]; - table[j].dst = &pointer_tmp; - table[j].new_func = &new_func_ptr; - table[j].name = strtab+(symtab+i)->st_name; - table[j].got = (u_long *)*(long *)(((int)((symtab+i)->st_value))+2); - table[j].real_func = (void *)*(table[j].got); - k = &table[j]; - bcopy((char*)&k, (char *)table[j].got, 4); - j++; -#endif - } - } - - _sys_write(fd,"ltrace starting...\n",19); -} - -static u_long where_to_return; -static u_long returned_value; -static u_long where_to_jump; - -static int reentrant=0; - -static void print_results(u_long arg); - -static void kk(void) -{ - char buf[1024]; - sprintf(buf, "\n%s(", pointer_tmp->name); - _sys_write(fd,buf,strlen(buf)); -} - -static void new_func(void) -{ -#if 1 - kk(); -#endif - if (reentrant) { -#if 0 -_sys_write(fd,"reentrant\n",10); -#endif - __asm__ __volatile__( - "movl %%ebp, %%esp\n\t" - "popl %%ebp\n\t" - "jmp *%%eax\n" - : : "a" (pointer_tmp->real_func) - ); - } - reentrant=1; - pointer = pointer_tmp; - where_to_jump = (u_long)pointer->real_func; - - /* This is only to avoid a GCC warning; shouldn't be here: - */ - where_to_return = (long)print_results; - - /* HCK: Is all these stuff about 'ebp' buggy? */ - __asm__ __volatile__( - "movl %ebp, %esp\n\t" - "popl %ebp\n\t" - "popl %eax\n\t" - "movl %eax, where_to_return\n\t" - "movl where_to_jump, %eax\n\t" - "call *%eax\n\t" - "movl %eax, returned_value\n\t" - "call print_results\n\t" - "movl where_to_return, %eax\n\t" - "pushl %eax\n\t" - "movl returned_value, %eax\n\t" - "movl $0, reentrant\n\t" - "ret\n" - ); -} - -#endif diff --git a/src/libtrace/libtrace.c b/src/libtrace/libtrace.c deleted file mode 100644 index 26a57bc..0000000 --- a/src/libtrace/libtrace.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Terrible hacks... I don't want *anything* to be exported, so - * everything has to be in the same file. - */ - -#include <sys/types.h> -#include <stdarg.h> - -static void init_libtrace(void); -static size_t strlen(const char *); -static int strncmp(const char *, const char *, size_t); -static char * getenv(const char *); -static unsigned long atoi(const char *); -static char * bcopy(const char *, char *, int); -static int sprintf(char * buf, const char *fmt, ...); -static int printf(const char *fmt, ...); -static int strcmp(const char * cs,const char * ct); -static size_t strnlen(const char * s, size_t count); -static int vsprintf(char *buf, const char *fmt, va_list args); -static char * strcat(char * dest, const char * src); -static void unsetenv(const char *); - -#include "init_libtrace.c" -#include "strlen.c" -#include "strncmp.c" -#include "getenv.c" -#include "atoi.c" -#include "bcopy.c" -#if 0 -#include "print_results.c" -#endif -#include "sprintf.c" -#include "vsprintf.c" -#include "strcmp.c" -#include "strnlen.c" -#include "strcat.c" -#include "unsetenv.c" -#include "printf.c" - -__asm__(".section .init"); -void _init(void) -{ - init_libtrace(); -} diff --git a/src/libtrace/libtrace.s b/src/libtrace/libtrace.s deleted file mode 100644 index 013ee8f..0000000 --- a/src/libtrace/libtrace.s +++ /dev/null @@ -1,68 +0,0 @@ - .file "libtrace.c" - .version "01.01" -gcc2_compiled.: -.data - .align 4 - .type fd,@object - .size fd,4 -fd: - .long 2 - .type ax_jmp,@object -ax_jmp: -.byte -72 -.byte 1 -.byte 2 -.byte 3 -.byte 4 -.byte -93 -.byte 5 -.byte 6 -.byte 7 -.byte 8 -.byte -1 -.byte 37 -.byte 1 -.byte 2 -.byte 3 -.byte 4 -.byte 0 -.byte 0 -.byte 0 -.byte 0 -.byte 0 -.byte 0 -.byte 0 -.byte 0 -.byte 0 -.byte 0 -.byte 0 -.byte 0 - .size ax_jmp,28 - .align 4 - .type new_func_ptr,@object - .size new_func_ptr,4 -new_func_ptr: - .long 0 -.section .rodata -.LC0: - .string "LTRACE_FILENAME" -.LC1: - .string "Can't open LTRACE_FILENAME\n" -.LC2: - .string "Not enough fd's?\n" -.LC3: - .string "LTRACE_SYMTAB" -.LC4: - .string "No LTRACE_SYMTAB...\n" -.LC5: - .string "LTRACE_SYMTAB_LEN" -.LC6: - .string "No LTRACE_SYMTAB_LEN...\n" -.LC7: - .string "LTRACE_STRTAB" -.LC8: - .string "No LTRACE_STRTAB...\n" -.LC9: - .string "Cannot mmap?\n" -.LC10: - .string "ltrace starting...\n" diff --git a/src/libtrace/print_results-old.c b/src/libtrace/print_results-old.c deleted file mode 100644 index 2c41916..0000000 --- a/src/libtrace/print_results-old.c +++ /dev/null @@ -1,353 +0,0 @@ -static u_long * function_args; - -struct debug_functions { - const char * function_name; - int return_type; - int no_params; - int params_type[10]; -}; - -/* - * Lista de types: - */ - -#define _TYPE_UNKNOWN -1 -#define _TYPE_VOID 0 -#define _TYPE_INT 1 -#define _TYPE_UINT 2 -#define _TYPE_OCTAL 3 -#define _TYPE_CHAR 4 -#define _TYPE_STRING 5 -#define _TYPE_ADDR 6 -#define _TYPE_FILE 7 -#define _TYPE_HEX 8 - -#define MAX_STRING 30 - -static struct debug_functions * function_actual; - -static struct debug_functions functions_info[] = { - {"__libc_init", _TYPE_VOID, 0, {0}}, - {"__setjmp", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"__overflow", _TYPE_CHAR, 2, {_TYPE_FILE, _TYPE_CHAR}}, - {"__random", _TYPE_INT, 0, {0}}, - {"__setfpucw", _TYPE_VOID, 1, {_TYPE_UINT}}, - {"__srandom", _TYPE_VOID, 1, {_TYPE_UINT}}, - {"__uflow", _TYPE_INT, 1, {_TYPE_FILE}}, - {"_fxstat", _TYPE_INT, 3, {_TYPE_INT, _TYPE_INT, _TYPE_ADDR}}, - {"_lxstat", _TYPE_INT, 3, {_TYPE_INT, _TYPE_STRING, _TYPE_ADDR}}, - {"_xmknod", _TYPE_INT, 4, {_TYPE_INT, _TYPE_STRING, _TYPE_OCTAL, _TYPE_ADDR}}, - {"_xstat", _TYPE_INT, 3, {_TYPE_INT, _TYPE_STRING, _TYPE_ADDR}}, - {"XSupportsLocale",_TYPE_INT, 0, {}}, - {"access", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_INT}}, - {"alarm", _TYPE_INT, 1, {_TYPE_INT}}, - {"atexit", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"atoi", _TYPE_INT, 1, {_TYPE_STRING}}, - {"basename", _TYPE_STRING,1, {_TYPE_STRING}}, - {"bcmp", _TYPE_INT, 3, {_TYPE_ADDR, _TYPE_ADDR, _TYPE_UINT}}, - {"bind", _TYPE_INT, 3, {_TYPE_INT, _TYPE_ADDR, _TYPE_INT}}, - {"bindresvport",_TYPE_INT, 2, {_TYPE_INT, _TYPE_ADDR}}, - {"brk", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"bzero", _TYPE_VOID, 2, {_TYPE_ADDR, _TYPE_UINT}}, - {"calloc", _TYPE_ADDR, 2, {_TYPE_UINT, _TYPE_UINT}}, - {"cfgetospeed", _TYPE_UINT, 1, {_TYPE_ADDR}}, - {"creat", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_OCTAL}}, - {"dup", _TYPE_INT, 1, {_TYPE_UINT}}, - {"dup2", _TYPE_INT, 2, {_TYPE_UINT, _TYPE_UINT}}, - {"chdir", _TYPE_INT, 1, {_TYPE_STRING}}, - {"chmod", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_OCTAL}}, - {"chown", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_UINT, _TYPE_UINT}}, - {"close", _TYPE_INT, 1, {_TYPE_INT}}, - {"closedir", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"ctime", _TYPE_STRING,1, {_TYPE_ADDR}}, - {"endmntent", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"fchmod", _TYPE_INT, 2, {_TYPE_INT, _TYPE_OCTAL}}, - {"fchown", _TYPE_INT, 3, {_TYPE_INT, _TYPE_UINT, _TYPE_UINT}}, - {"fclose", _TYPE_INT, 1, {_TYPE_FILE}}, - {"fdopen", _TYPE_FILE, 2, {_TYPE_INT, _TYPE_STRING}}, - {"feof", _TYPE_INT, 1, {_TYPE_FILE}}, - {"ferror", _TYPE_INT, 1, {_TYPE_FILE}}, - {"fflush", _TYPE_INT, 1, {_TYPE_FILE}}, - {"fgetc", _TYPE_CHAR, 1, {_TYPE_FILE}}, - {"fgets", _TYPE_ADDR, 3, {_TYPE_ADDR, _TYPE_UINT, _TYPE_ADDR}}, - {"fileno", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"fopen", _TYPE_ADDR, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"fork", _TYPE_INT, 0, {0}}, - {"fprintf", _TYPE_INT, 2, {_TYPE_FILE, _TYPE_STRING}}, - {"fputc", _TYPE_INT, 2, {_TYPE_CHAR, _TYPE_FILE}}, - {"fputs", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_FILE}}, - {"fread", _TYPE_UINT, 4, {_TYPE_FILE, _TYPE_UINT, _TYPE_UINT, _TYPE_ADDR}}, - {"free", _TYPE_VOID, 1, {_TYPE_ADDR}}, - {"freopen", _TYPE_ADDR, 3, {_TYPE_STRING, _TYPE_STRING, _TYPE_ADDR}}, - {"fseek", _TYPE_INT, 3, {_TYPE_FILE, _TYPE_UINT, _TYPE_INT}}, - {"ftell", _TYPE_UINT, 1, {_TYPE_FILE}}, - {"fwrite", _TYPE_UINT, 4, {_TYPE_FILE, _TYPE_UINT, _TYPE_UINT, _TYPE_ADDR}}, - {"getdtablesize",_TYPE_INT, 0, {0}}, - {"getenv", _TYPE_STRING,1, {_TYPE_STRING}}, - {"getgid", _TYPE_INT, 0, {0}}, - {"getgrgid", _TYPE_ADDR, 1, {_TYPE_UINT}}, - {"getgrnam", _TYPE_ADDR, 1, {_TYPE_STRING}}, - {"gethostbyname",_TYPE_ADDR, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"gethostname", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_UINT, 0, 0, 0}}, - {"getmntent", _TYPE_ADDR, 1, {_TYPE_ADDR}}, - {"getopt", _TYPE_CHAR, 3, {_TYPE_INT, _TYPE_ADDR, _TYPE_STRING}}, - {"getopt_long", _TYPE_CHAR, 5, {_TYPE_INT, _TYPE_ADDR,_TYPE_STRING,_TYPE_ADDR,_TYPE_ADDR}}, - {"getpagesize", _TYPE_UINT, 0, {0}}, - {"getpgrp", _TYPE_INT, 0, {0}}, - {"getpid", _TYPE_UINT, 0, {0}}, - {"getpwnam", _TYPE_ADDR, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"getpwuid", _TYPE_ADDR, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"getservbyname",_TYPE_ADDR, 2, {_TYPE_STRING, _TYPE_STRING, 0, 0, 0}}, - {"gettimeofday",_TYPE_INT, 2, {_TYPE_ADDR, _TYPE_ADDR, 0, 0, 0}}, - {"htonl", _TYPE_UINT, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"inet_addr", _TYPE_ADDR, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"inet_ntoa", _TYPE_STRING,1, {_TYPE_ADDR, 0, 0, 0, 0}}, - {"ioctl", _TYPE_INT, 2, {_TYPE_INT, _TYPE_HEX}}, - {"isalnum", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isalpha", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isascii", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isatty", _TYPE_INT, 1, {_TYPE_INT, 0, 0, 0, 0}}, - {"iscntrl", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isdigit", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isgraph", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"islower", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isprint", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"ispunct", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isspace", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isupper", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isxdigit", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"malloc", _TYPE_ADDR, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"memmove", _TYPE_ADDR, 3, {_TYPE_ADDR, _TYPE_ADDR, _TYPE_INT, 0, 0}}, - {"memset", _TYPE_ADDR, 3, {_TYPE_ADDR, _TYPE_HEX, _TYPE_UINT}}, - {"mmap", _TYPE_ADDR, 5, {_TYPE_UINT, _TYPE_UINT, _TYPE_UINT, _TYPE_INT,_TYPE_UINT}}, - {"mprotect", _TYPE_INT, 3, {_TYPE_ADDR, _TYPE_ADDR, _TYPE_HEX}}, - {"ntohl", _TYPE_UINT, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"ntohs", _TYPE_UINT, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"open", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_INT, _TYPE_OCTAL, 0, 0}}, - {"opendir", _TYPE_ADDR, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"perror", _TYPE_VOID, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"pipe", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"printf", _TYPE_INT, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"putenv", _TYPE_INT, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"puts", _TYPE_INT, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"qsort", _TYPE_VOID, 4, {_TYPE_ADDR, _TYPE_UINT, _TYPE_UINT, _TYPE_ADDR, 0}}, - {"read", _TYPE_INT, 3, {_TYPE_INT, _TYPE_ADDR, _TYPE_UINT, 0, 0}}, - {"readdir", _TYPE_ADDR, 1, {_TYPE_ADDR, 0, 0, 0, 0}}, - {"readline", _TYPE_STRING,0, {0, 0, 0, 0, 0}}, - {"readlink", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_ADDR, _TYPE_UINT, 0, 0}}, - {"realloc", _TYPE_ADDR, 2, {_TYPE_ADDR, _TYPE_UINT, 0, 0, 0}}, - {"rewind", _TYPE_VOID, 1, {_TYPE_FILE, 0, 0, 0, 0}}, - {"rewinddir", _TYPE_VOID, 1, {_TYPE_FILE, 0, 0, 0, 0}}, - {"rindex", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_INT, 0, 0, 0}}, - {"sbrk", _TYPE_ADDR, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"select", _TYPE_INT, 5, {_TYPE_INT, _TYPE_ADDR, _TYPE_ADDR, _TYPE_ADDR,_TYPE_ADDR}}, - {"setbuf", _TYPE_VOID, 2, {_TYPE_ADDR, _TYPE_ADDR, 0, 0, 0}}, - {"setgid", _TYPE_INT, 1, {_TYPE_UINT}}, - {"setlinebuf", _TYPE_VOID, 1, {_TYPE_FILE, 0, 0, 0, 0}}, - {"setlocale", _TYPE_STRING,2, {_TYPE_INT, _TYPE_STRING, 0, 0, 0}}, - {"setmntent", _TYPE_ADDR, 2, {_TYPE_STRING, _TYPE_STRING, 0, 0, 0}}, - {"setuid", _TYPE_INT, 1, {_TYPE_INT, 0, 0, 0, 0}}, - {"setvbuf", _TYPE_INT, 4, {_TYPE_ADDR, _TYPE_ADDR, _TYPE_INT, _TYPE_UINT, 0}}, - {"sigaction", _TYPE_INT, 3, {_TYPE_INT, _TYPE_ADDR, _TYPE_ADDR, 0, 0}}, - {"sleep", _TYPE_UINT, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"sprintf", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"sscanf", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"strcasecmp", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"stpcpy", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_STRING}}, - {"strcmp", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"strcpy", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_STRING}}, - {"strcoll", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"strcspn", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"strdup", _TYPE_STRING,1, {_TYPE_STRING}}, - {"strerror", _TYPE_STRING,1, {_TYPE_INT}}, - {"strncmp", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_STRING, _TYPE_INT}}, - {"strpbrk", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_STRING, 0, 0, 0}}, - {"strrchr", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_CHAR, 0, 0, 0}}, - {"strspn", _TYPE_UINT, 2, {_TYPE_STRING, _TYPE_STRING, 0, 0, 0}}, - {"strtok", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_STRING, 0, 0, 0}}, - {"strtol", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_ADDR, _TYPE_UINT, 0, 0}}, - {"strtoul", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_ADDR, _TYPE_UINT, 0, 0}}, - {"tcgetattr", _TYPE_INT, 2, {_TYPE_INT, _TYPE_ADDR, 0, 0, 0}}, - {"tcsetattr", _TYPE_INT, 2, {_TYPE_INT, _TYPE_ADDR, 0, 0, 0}}, - {"time", _TYPE_UINT, 1, {_TYPE_ADDR}}, - {"toascii", _TYPE_CHAR, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"tolower", _TYPE_CHAR, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"toupper", _TYPE_CHAR, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"unlink", _TYPE_INT, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"uname", _TYPE_INT, 1, {_TYPE_ADDR, 0, 0, 0, 0}}, - {"ungetc", _TYPE_CHAR, 2, {_TYPE_INT, _TYPE_ADDR, 0, 0, 0}}, - {"utime", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_ADDR, 0, 0, 0}}, - {"vfprintf", _TYPE_INT, 2, {_TYPE_ADDR, _TYPE_STRING, 0, 0, 0}}, - {"wait", _TYPE_UINT, 1, {_TYPE_ADDR, 0, 0, 0, 0}}, - {"wait3", _TYPE_UINT, 3, {_TYPE_ADDR, _TYPE_INT, _TYPE_ADDR, 0, 0}}, - {"waitpid", _TYPE_UINT, 3, {_TYPE_UINT, _TYPE_ADDR, _TYPE_ADDR, 0, 0}}, - {"write", _TYPE_INT, 3, {_TYPE_INT, _TYPE_ADDR, _TYPE_UINT, 0, 0}}, - {NULL, _TYPE_UNKNOWN, 1, {_TYPE_UNKNOWN, 0, 0, 0, 0}} -}; - -static char * print_char(unsigned long value) -{ - static char result[5]; - - result[0]='\\'; - switch(value) { - case '\r': result[1]='r'; result[2]='\0'; break; - case '\n': result[1]='n'; result[2]='\0'; break; - case '\t': result[1]='t'; result[2]='\0'; break; - case '\\': result[1]='\\'; result[2]='\0'; break; - default: - if ((value<32) || ((value>126) && (value<256))) { - sprintf(result+1, "%lo", value); - } else { - result[0]=value; result[1]='\0'; break; - } - } - return result; -} - -static char * print_param(int type, unsigned long value) -{ - static char result[1024]; - - switch(type) { - case _TYPE_INT: - sprintf(result, "%d", (int)value); - break; - case _TYPE_UINT: - sprintf(result, "%u", (unsigned int)value); - break; - case _TYPE_ADDR: - if (!value) { - sprintf(result, "NULL"); - } else { - sprintf(result, "0x%08x", (unsigned int)value); - } - break; - case _TYPE_FILE: -#if 0 - if (value==(unsigned long)stdin) { - sprintf(result, "stdin"); - } else if (value==(unsigned long)stdout) { - sprintf(result, "stdout"); - } else if (value==(unsigned long)stderr) { - sprintf(result, "stderr"); - } else { -#endif - return print_param(_TYPE_ADDR, value); -#if 0 - } -#endif - break; - case _TYPE_OCTAL: - sprintf(result, "0%o", (unsigned int)value); - break; - case _TYPE_CHAR: - if (value==-1) { - sprintf(result, "EOF"); - } else { - sprintf(result, "'%s'", print_char(value)); - } - break; - case _TYPE_STRING: - if (value==0) { - sprintf(result, "<NULL>"); - } else { - int i; - sprintf(result, "\""); - for(i=0; *((char*)value+i) && i<MAX_STRING; i++) { - strcat(result, print_char(*((char*)value+i))); - } - strcat(result, "\""); - if (i==MAX_STRING) { - strcat(result, "..."); - } - } - break; - case _TYPE_HEX: - sprintf(result, "0x%lx", value); - break; - case _TYPE_VOID: - sprintf(result, "<void>"); - break; - case _TYPE_UNKNOWN: - sprintf(result, "???"); - break; - default: - sprintf(result, "???"); - } - return result; -} - -static void print_results(u_long arg) -{ - char message[1024]; - int i; - -#if 0 - if (!current_pid) { - return; - } -#endif - - if (pointer != (void *)*(pointer->got)) { - pointer->real_func = (void *)*(pointer->got); - bcopy((char *)&pointer, (char *)pointer->got, 4); - } - -#if 0 -_sys_write(fd, pointer->name, strlen(pointer->name)); -_sys_write(fd, ":\n", 2); -#endif - - function_actual = functions_info; - while(function_actual->function_name) { - if (!strcmp(pointer->name, function_actual->function_name)) { - break; - } - function_actual++; - } - - function_args = &arg; - -#if 0 - if (!strcmp(pointer->name, "fork")) { - if (_sys_getpid() != current_pid) { - _sys_close(fd); - current_pid=0; - return; - } - } -#endif - -#if 0 -sprintf(message,"call to = 0x%08x\n" - "got = 0x%08x\n" - "return = 0x%08x\n" - "args[0] = 0x%08x\n" - "args[1] = 0x%08x\n" - "args[2] = 0x%08x\n" - "args[3] = 0x%08x\n" - "args[4] = 0x%08x\n" - "args[5] = 0x%08x\n", - pointer, pointer->got, where_to_return, - function_args[0], function_args[1], function_args[2], - function_args[3], function_args[4], function_args[5]); -_sys_write(fd, message, strlen(message)); -#endif - - message[0] = '\0'; -#if 0 - sprintf(message, "%s%s(", message, pointer->name); -#endif - if (function_actual->no_params > 0) { - sprintf(message, "%s%s", message, - print_param(function_actual->params_type[0], function_args[0])); - } - for(i=1; i<function_actual->no_params; i++) { - sprintf(message, "%s,%s", message, - print_param(function_actual->params_type[i], function_args[i])); - } - sprintf(message, "%s) = %s\n", message, - print_param(function_actual->return_type, returned_value)); - _sys_write(fd, message, strlen(message)); -} diff --git a/src/libtrace/print_results.c b/src/libtrace/print_results.c deleted file mode 100644 index 2c41916..0000000 --- a/src/libtrace/print_results.c +++ /dev/null @@ -1,353 +0,0 @@ -static u_long * function_args; - -struct debug_functions { - const char * function_name; - int return_type; - int no_params; - int params_type[10]; -}; - -/* - * Lista de types: - */ - -#define _TYPE_UNKNOWN -1 -#define _TYPE_VOID 0 -#define _TYPE_INT 1 -#define _TYPE_UINT 2 -#define _TYPE_OCTAL 3 -#define _TYPE_CHAR 4 -#define _TYPE_STRING 5 -#define _TYPE_ADDR 6 -#define _TYPE_FILE 7 -#define _TYPE_HEX 8 - -#define MAX_STRING 30 - -static struct debug_functions * function_actual; - -static struct debug_functions functions_info[] = { - {"__libc_init", _TYPE_VOID, 0, {0}}, - {"__setjmp", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"__overflow", _TYPE_CHAR, 2, {_TYPE_FILE, _TYPE_CHAR}}, - {"__random", _TYPE_INT, 0, {0}}, - {"__setfpucw", _TYPE_VOID, 1, {_TYPE_UINT}}, - {"__srandom", _TYPE_VOID, 1, {_TYPE_UINT}}, - {"__uflow", _TYPE_INT, 1, {_TYPE_FILE}}, - {"_fxstat", _TYPE_INT, 3, {_TYPE_INT, _TYPE_INT, _TYPE_ADDR}}, - {"_lxstat", _TYPE_INT, 3, {_TYPE_INT, _TYPE_STRING, _TYPE_ADDR}}, - {"_xmknod", _TYPE_INT, 4, {_TYPE_INT, _TYPE_STRING, _TYPE_OCTAL, _TYPE_ADDR}}, - {"_xstat", _TYPE_INT, 3, {_TYPE_INT, _TYPE_STRING, _TYPE_ADDR}}, - {"XSupportsLocale",_TYPE_INT, 0, {}}, - {"access", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_INT}}, - {"alarm", _TYPE_INT, 1, {_TYPE_INT}}, - {"atexit", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"atoi", _TYPE_INT, 1, {_TYPE_STRING}}, - {"basename", _TYPE_STRING,1, {_TYPE_STRING}}, - {"bcmp", _TYPE_INT, 3, {_TYPE_ADDR, _TYPE_ADDR, _TYPE_UINT}}, - {"bind", _TYPE_INT, 3, {_TYPE_INT, _TYPE_ADDR, _TYPE_INT}}, - {"bindresvport",_TYPE_INT, 2, {_TYPE_INT, _TYPE_ADDR}}, - {"brk", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"bzero", _TYPE_VOID, 2, {_TYPE_ADDR, _TYPE_UINT}}, - {"calloc", _TYPE_ADDR, 2, {_TYPE_UINT, _TYPE_UINT}}, - {"cfgetospeed", _TYPE_UINT, 1, {_TYPE_ADDR}}, - {"creat", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_OCTAL}}, - {"dup", _TYPE_INT, 1, {_TYPE_UINT}}, - {"dup2", _TYPE_INT, 2, {_TYPE_UINT, _TYPE_UINT}}, - {"chdir", _TYPE_INT, 1, {_TYPE_STRING}}, - {"chmod", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_OCTAL}}, - {"chown", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_UINT, _TYPE_UINT}}, - {"close", _TYPE_INT, 1, {_TYPE_INT}}, - {"closedir", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"ctime", _TYPE_STRING,1, {_TYPE_ADDR}}, - {"endmntent", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"fchmod", _TYPE_INT, 2, {_TYPE_INT, _TYPE_OCTAL}}, - {"fchown", _TYPE_INT, 3, {_TYPE_INT, _TYPE_UINT, _TYPE_UINT}}, - {"fclose", _TYPE_INT, 1, {_TYPE_FILE}}, - {"fdopen", _TYPE_FILE, 2, {_TYPE_INT, _TYPE_STRING}}, - {"feof", _TYPE_INT, 1, {_TYPE_FILE}}, - {"ferror", _TYPE_INT, 1, {_TYPE_FILE}}, - {"fflush", _TYPE_INT, 1, {_TYPE_FILE}}, - {"fgetc", _TYPE_CHAR, 1, {_TYPE_FILE}}, - {"fgets", _TYPE_ADDR, 3, {_TYPE_ADDR, _TYPE_UINT, _TYPE_ADDR}}, - {"fileno", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"fopen", _TYPE_ADDR, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"fork", _TYPE_INT, 0, {0}}, - {"fprintf", _TYPE_INT, 2, {_TYPE_FILE, _TYPE_STRING}}, - {"fputc", _TYPE_INT, 2, {_TYPE_CHAR, _TYPE_FILE}}, - {"fputs", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_FILE}}, - {"fread", _TYPE_UINT, 4, {_TYPE_FILE, _TYPE_UINT, _TYPE_UINT, _TYPE_ADDR}}, - {"free", _TYPE_VOID, 1, {_TYPE_ADDR}}, - {"freopen", _TYPE_ADDR, 3, {_TYPE_STRING, _TYPE_STRING, _TYPE_ADDR}}, - {"fseek", _TYPE_INT, 3, {_TYPE_FILE, _TYPE_UINT, _TYPE_INT}}, - {"ftell", _TYPE_UINT, 1, {_TYPE_FILE}}, - {"fwrite", _TYPE_UINT, 4, {_TYPE_FILE, _TYPE_UINT, _TYPE_UINT, _TYPE_ADDR}}, - {"getdtablesize",_TYPE_INT, 0, {0}}, - {"getenv", _TYPE_STRING,1, {_TYPE_STRING}}, - {"getgid", _TYPE_INT, 0, {0}}, - {"getgrgid", _TYPE_ADDR, 1, {_TYPE_UINT}}, - {"getgrnam", _TYPE_ADDR, 1, {_TYPE_STRING}}, - {"gethostbyname",_TYPE_ADDR, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"gethostname", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_UINT, 0, 0, 0}}, - {"getmntent", _TYPE_ADDR, 1, {_TYPE_ADDR}}, - {"getopt", _TYPE_CHAR, 3, {_TYPE_INT, _TYPE_ADDR, _TYPE_STRING}}, - {"getopt_long", _TYPE_CHAR, 5, {_TYPE_INT, _TYPE_ADDR,_TYPE_STRING,_TYPE_ADDR,_TYPE_ADDR}}, - {"getpagesize", _TYPE_UINT, 0, {0}}, - {"getpgrp", _TYPE_INT, 0, {0}}, - {"getpid", _TYPE_UINT, 0, {0}}, - {"getpwnam", _TYPE_ADDR, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"getpwuid", _TYPE_ADDR, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"getservbyname",_TYPE_ADDR, 2, {_TYPE_STRING, _TYPE_STRING, 0, 0, 0}}, - {"gettimeofday",_TYPE_INT, 2, {_TYPE_ADDR, _TYPE_ADDR, 0, 0, 0}}, - {"htonl", _TYPE_UINT, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"inet_addr", _TYPE_ADDR, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"inet_ntoa", _TYPE_STRING,1, {_TYPE_ADDR, 0, 0, 0, 0}}, - {"ioctl", _TYPE_INT, 2, {_TYPE_INT, _TYPE_HEX}}, - {"isalnum", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isalpha", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isascii", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isatty", _TYPE_INT, 1, {_TYPE_INT, 0, 0, 0, 0}}, - {"iscntrl", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isdigit", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isgraph", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"islower", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isprint", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"ispunct", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isspace", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isupper", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"isxdigit", _TYPE_INT, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"malloc", _TYPE_ADDR, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"memmove", _TYPE_ADDR, 3, {_TYPE_ADDR, _TYPE_ADDR, _TYPE_INT, 0, 0}}, - {"memset", _TYPE_ADDR, 3, {_TYPE_ADDR, _TYPE_HEX, _TYPE_UINT}}, - {"mmap", _TYPE_ADDR, 5, {_TYPE_UINT, _TYPE_UINT, _TYPE_UINT, _TYPE_INT,_TYPE_UINT}}, - {"mprotect", _TYPE_INT, 3, {_TYPE_ADDR, _TYPE_ADDR, _TYPE_HEX}}, - {"ntohl", _TYPE_UINT, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"ntohs", _TYPE_UINT, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"open", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_INT, _TYPE_OCTAL, 0, 0}}, - {"opendir", _TYPE_ADDR, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"perror", _TYPE_VOID, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"pipe", _TYPE_INT, 1, {_TYPE_ADDR}}, - {"printf", _TYPE_INT, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"putenv", _TYPE_INT, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"puts", _TYPE_INT, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"qsort", _TYPE_VOID, 4, {_TYPE_ADDR, _TYPE_UINT, _TYPE_UINT, _TYPE_ADDR, 0}}, - {"read", _TYPE_INT, 3, {_TYPE_INT, _TYPE_ADDR, _TYPE_UINT, 0, 0}}, - {"readdir", _TYPE_ADDR, 1, {_TYPE_ADDR, 0, 0, 0, 0}}, - {"readline", _TYPE_STRING,0, {0, 0, 0, 0, 0}}, - {"readlink", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_ADDR, _TYPE_UINT, 0, 0}}, - {"realloc", _TYPE_ADDR, 2, {_TYPE_ADDR, _TYPE_UINT, 0, 0, 0}}, - {"rewind", _TYPE_VOID, 1, {_TYPE_FILE, 0, 0, 0, 0}}, - {"rewinddir", _TYPE_VOID, 1, {_TYPE_FILE, 0, 0, 0, 0}}, - {"rindex", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_INT, 0, 0, 0}}, - {"sbrk", _TYPE_ADDR, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"select", _TYPE_INT, 5, {_TYPE_INT, _TYPE_ADDR, _TYPE_ADDR, _TYPE_ADDR,_TYPE_ADDR}}, - {"setbuf", _TYPE_VOID, 2, {_TYPE_ADDR, _TYPE_ADDR, 0, 0, 0}}, - {"setgid", _TYPE_INT, 1, {_TYPE_UINT}}, - {"setlinebuf", _TYPE_VOID, 1, {_TYPE_FILE, 0, 0, 0, 0}}, - {"setlocale", _TYPE_STRING,2, {_TYPE_INT, _TYPE_STRING, 0, 0, 0}}, - {"setmntent", _TYPE_ADDR, 2, {_TYPE_STRING, _TYPE_STRING, 0, 0, 0}}, - {"setuid", _TYPE_INT, 1, {_TYPE_INT, 0, 0, 0, 0}}, - {"setvbuf", _TYPE_INT, 4, {_TYPE_ADDR, _TYPE_ADDR, _TYPE_INT, _TYPE_UINT, 0}}, - {"sigaction", _TYPE_INT, 3, {_TYPE_INT, _TYPE_ADDR, _TYPE_ADDR, 0, 0}}, - {"sleep", _TYPE_UINT, 1, {_TYPE_UINT, 0, 0, 0, 0}}, - {"sprintf", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"sscanf", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"strcasecmp", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"stpcpy", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_STRING}}, - {"strcmp", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"strcpy", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_STRING}}, - {"strcoll", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"strcspn", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_STRING}}, - {"strdup", _TYPE_STRING,1, {_TYPE_STRING}}, - {"strerror", _TYPE_STRING,1, {_TYPE_INT}}, - {"strncmp", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_STRING, _TYPE_INT}}, - {"strpbrk", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_STRING, 0, 0, 0}}, - {"strrchr", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_CHAR, 0, 0, 0}}, - {"strspn", _TYPE_UINT, 2, {_TYPE_STRING, _TYPE_STRING, 0, 0, 0}}, - {"strtok", _TYPE_STRING,2, {_TYPE_STRING, _TYPE_STRING, 0, 0, 0}}, - {"strtol", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_ADDR, _TYPE_UINT, 0, 0}}, - {"strtoul", _TYPE_INT, 3, {_TYPE_STRING, _TYPE_ADDR, _TYPE_UINT, 0, 0}}, - {"tcgetattr", _TYPE_INT, 2, {_TYPE_INT, _TYPE_ADDR, 0, 0, 0}}, - {"tcsetattr", _TYPE_INT, 2, {_TYPE_INT, _TYPE_ADDR, 0, 0, 0}}, - {"time", _TYPE_UINT, 1, {_TYPE_ADDR}}, - {"toascii", _TYPE_CHAR, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"tolower", _TYPE_CHAR, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"toupper", _TYPE_CHAR, 1, {_TYPE_CHAR, 0, 0, 0, 0}}, - {"unlink", _TYPE_INT, 1, {_TYPE_STRING, 0, 0, 0, 0}}, - {"uname", _TYPE_INT, 1, {_TYPE_ADDR, 0, 0, 0, 0}}, - {"ungetc", _TYPE_CHAR, 2, {_TYPE_INT, _TYPE_ADDR, 0, 0, 0}}, - {"utime", _TYPE_INT, 2, {_TYPE_STRING, _TYPE_ADDR, 0, 0, 0}}, - {"vfprintf", _TYPE_INT, 2, {_TYPE_ADDR, _TYPE_STRING, 0, 0, 0}}, - {"wait", _TYPE_UINT, 1, {_TYPE_ADDR, 0, 0, 0, 0}}, - {"wait3", _TYPE_UINT, 3, {_TYPE_ADDR, _TYPE_INT, _TYPE_ADDR, 0, 0}}, - {"waitpid", _TYPE_UINT, 3, {_TYPE_UINT, _TYPE_ADDR, _TYPE_ADDR, 0, 0}}, - {"write", _TYPE_INT, 3, {_TYPE_INT, _TYPE_ADDR, _TYPE_UINT, 0, 0}}, - {NULL, _TYPE_UNKNOWN, 1, {_TYPE_UNKNOWN, 0, 0, 0, 0}} -}; - -static char * print_char(unsigned long value) -{ - static char result[5]; - - result[0]='\\'; - switch(value) { - case '\r': result[1]='r'; result[2]='\0'; break; - case '\n': result[1]='n'; result[2]='\0'; break; - case '\t': result[1]='t'; result[2]='\0'; break; - case '\\': result[1]='\\'; result[2]='\0'; break; - default: - if ((value<32) || ((value>126) && (value<256))) { - sprintf(result+1, "%lo", value); - } else { - result[0]=value; result[1]='\0'; break; - } - } - return result; -} - -static char * print_param(int type, unsigned long value) -{ - static char result[1024]; - - switch(type) { - case _TYPE_INT: - sprintf(result, "%d", (int)value); - break; - case _TYPE_UINT: - sprintf(result, "%u", (unsigned int)value); - break; - case _TYPE_ADDR: - if (!value) { - sprintf(result, "NULL"); - } else { - sprintf(result, "0x%08x", (unsigned int)value); - } - break; - case _TYPE_FILE: -#if 0 - if (value==(unsigned long)stdin) { - sprintf(result, "stdin"); - } else if (value==(unsigned long)stdout) { - sprintf(result, "stdout"); - } else if (value==(unsigned long)stderr) { - sprintf(result, "stderr"); - } else { -#endif - return print_param(_TYPE_ADDR, value); -#if 0 - } -#endif - break; - case _TYPE_OCTAL: - sprintf(result, "0%o", (unsigned int)value); - break; - case _TYPE_CHAR: - if (value==-1) { - sprintf(result, "EOF"); - } else { - sprintf(result, "'%s'", print_char(value)); - } - break; - case _TYPE_STRING: - if (value==0) { - sprintf(result, "<NULL>"); - } else { - int i; - sprintf(result, "\""); - for(i=0; *((char*)value+i) && i<MAX_STRING; i++) { - strcat(result, print_char(*((char*)value+i))); - } - strcat(result, "\""); - if (i==MAX_STRING) { - strcat(result, "..."); - } - } - break; - case _TYPE_HEX: - sprintf(result, "0x%lx", value); - break; - case _TYPE_VOID: - sprintf(result, "<void>"); - break; - case _TYPE_UNKNOWN: - sprintf(result, "???"); - break; - default: - sprintf(result, "???"); - } - return result; -} - -static void print_results(u_long arg) -{ - char message[1024]; - int i; - -#if 0 - if (!current_pid) { - return; - } -#endif - - if (pointer != (void *)*(pointer->got)) { - pointer->real_func = (void *)*(pointer->got); - bcopy((char *)&pointer, (char *)pointer->got, 4); - } - -#if 0 -_sys_write(fd, pointer->name, strlen(pointer->name)); -_sys_write(fd, ":\n", 2); -#endif - - function_actual = functions_info; - while(function_actual->function_name) { - if (!strcmp(pointer->name, function_actual->function_name)) { - break; - } - function_actual++; - } - - function_args = &arg; - -#if 0 - if (!strcmp(pointer->name, "fork")) { - if (_sys_getpid() != current_pid) { - _sys_close(fd); - current_pid=0; - return; - } - } -#endif - -#if 0 -sprintf(message,"call to = 0x%08x\n" - "got = 0x%08x\n" - "return = 0x%08x\n" - "args[0] = 0x%08x\n" - "args[1] = 0x%08x\n" - "args[2] = 0x%08x\n" - "args[3] = 0x%08x\n" - "args[4] = 0x%08x\n" - "args[5] = 0x%08x\n", - pointer, pointer->got, where_to_return, - function_args[0], function_args[1], function_args[2], - function_args[3], function_args[4], function_args[5]); -_sys_write(fd, message, strlen(message)); -#endif - - message[0] = '\0'; -#if 0 - sprintf(message, "%s%s(", message, pointer->name); -#endif - if (function_actual->no_params > 0) { - sprintf(message, "%s%s", message, - print_param(function_actual->params_type[0], function_args[0])); - } - for(i=1; i<function_actual->no_params; i++) { - sprintf(message, "%s,%s", message, - print_param(function_actual->params_type[i], function_args[i])); - } - sprintf(message, "%s) = %s\n", message, - print_param(function_actual->return_type, returned_value)); - _sys_write(fd, message, strlen(message)); -} diff --git a/src/libtrace/printf.c b/src/libtrace/printf.c deleted file mode 100644 index 85b254d..0000000 --- a/src/libtrace/printf.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * linux/lib/vsprintf.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - -/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ -/* - * Wirzenius wrote this portably, Torvalds fucked it up :-) - */ - -#include <stdarg.h> - -static int printf(const char *fmt, ...) -{ - va_list args; - int i; - char buf[1024]; - - va_start(args, fmt); - i=vsprintf(buf,fmt,args); - va_end(args); - - _sys_write(fd, buf, strlen(buf)); - - return i; -} - diff --git a/src/libtrace/sprintf.c b/src/libtrace/sprintf.c deleted file mode 100644 index d00e087..0000000 --- a/src/libtrace/sprintf.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * linux/lib/vsprintf.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - -/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ -/* - * Wirzenius wrote this portably, Torvalds fucked it up :-) - */ - -#include <stdarg.h> - -static int sprintf(char * buf, const char *fmt, ...) -{ - va_list args; - int i; - - va_start(args, fmt); - i=vsprintf(buf,fmt,args); - va_end(args); - - return i; -} - diff --git a/src/libtrace/strcat.c b/src/libtrace/strcat.c deleted file mode 100644 index cb01564..0000000 --- a/src/libtrace/strcat.c +++ /dev/null @@ -1,12 +0,0 @@ -static char * strcat(char * dest, const char * src) -{ - char *tmp = dest; - - while (*dest) - dest++; - while ((*dest++ = *src++) != '\0') - ; - - return tmp; -} - diff --git a/src/libtrace/strcmp.c b/src/libtrace/strcmp.c deleted file mode 100644 index 8392ec3..0000000 --- a/src/libtrace/strcmp.c +++ /dev/null @@ -1,12 +0,0 @@ -int strcmp(const char * cs,const char * ct) -{ - register signed char __res; - - while (1) { - if ((__res = *cs - *ct++) != 0 || !*cs++) - break; - } - - return(__res); -} - diff --git a/src/libtrace/strlen.c b/src/libtrace/strlen.c deleted file mode 100644 index f3f44e0..0000000 --- a/src/libtrace/strlen.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <sys/types.h> - -static size_t strlen(const char * s) -{ - const char *sc; - - for (sc = s; *sc != '\0'; ++sc) - /* nothing */; - return sc - s; -} diff --git a/src/libtrace/strncmp.c b/src/libtrace/strncmp.c deleted file mode 100644 index 96512e6..0000000 --- a/src/libtrace/strncmp.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <sys/types.h> - -int strncmp(const char * cs,const char * ct,size_t count) -{ - register signed char __res = 0; - - while (count) { - if ((__res = *cs - *ct++) != 0 || !*cs++) - break; - count--; - } - - return __res; -} diff --git a/src/libtrace/strnlen.c b/src/libtrace/strnlen.c deleted file mode 100644 index 715dbce..0000000 --- a/src/libtrace/strnlen.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <sys/types.h> - -size_t strnlen(const char * s, size_t count) -{ - const char *sc; - - for (sc = s; count-- && *sc != '\0'; ++sc) - /* nothing */; - return sc - s; -} - diff --git a/src/libtrace/unsetenv.c b/src/libtrace/unsetenv.c deleted file mode 100644 index 11fc691..0000000 --- a/src/libtrace/unsetenv.c +++ /dev/null @@ -1,17 +0,0 @@ -#include <sys/types.h> - -static void unsetenv(const char *name) -{ - register char **ep; - register char **dp; - const size_t namelen = strlen (name); - - for (dp = ep = __environ; *ep != NULL; ++ep) - if (memcmp (*ep, name, namelen) || (*ep)[namelen] != '=') - { - *dp = *ep; - ++dp; - } - *dp = NULL; - -} diff --git a/src/libtrace/vsprintf.c b/src/libtrace/vsprintf.c deleted file mode 100644 index 9805115..0000000 --- a/src/libtrace/vsprintf.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - * linux/lib/vsprintf.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - -/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ -/* - * Wirzenius wrote this portably, Torvalds fucked it up :-) - */ - -#include <stdarg.h> -#include <hck/ctype.h> - -/* we use this so that we can do without the ctype library */ -#define is_digit(c) ((c) >= '0' && (c) <= '9') - -static __inline__ int skip_atoi(const char **s) -{ - int i=0; - - while (is_digit(**s)) - i = i*10 + *((*s)++) - '0'; - return i; -} - -#define ZEROPAD 1 /* pad with zero */ -#define SIGN 2 /* unsigned/signed long */ -#define PLUS 4 /* show plus */ -#define SPACE 8 /* space if plus */ -#define LEFT 16 /* left justified */ -#define SPECIAL 32 /* 0x */ -#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ - -#define do_div(n,base) ({ \ -int __res; \ -__res = ((unsigned long) n) % (unsigned) base; \ -n = ((unsigned long) n) / (unsigned) base; \ -__res; }) - -static char * number(char * str, long num, int base, int size, int precision - ,int type) -{ - char c,sign,tmp[66]; - const char *digits="0123456789abcdefghijklmnopqrstuvwxyz"; - int i; - - if (type & LARGE) - digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - if (type & LEFT) - type &= ~ZEROPAD; - if (base < 2 || base > 36) - return 0; - c = (type & ZEROPAD) ? '0' : ' '; - sign = 0; - if (type & SIGN) { - if (num < 0) { - sign = '-'; - num = -num; - size--; - } else if (type & PLUS) { - sign = '+'; - size--; - } else if (type & SPACE) { - sign = ' '; - size--; - } - } - if (type & SPECIAL) { - if (base == 16) - size -= 2; - else if (base == 8) - size--; - } - i = 0; - if (num == 0) - tmp[i++]='0'; - else while (num != 0) - tmp[i++] = digits[do_div(num,base)]; - if (i > precision) - precision = i; - size -= precision; - if (!(type&(ZEROPAD+LEFT))) - while(size-->0) - *str++ = ' '; - if (sign) - *str++ = sign; - if (type & SPECIAL) - if (base==8) - *str++ = '0'; - else if (base==16) { - *str++ = '0'; - *str++ = digits[33]; - } - if (!(type & LEFT)) - while (size-- > 0) - *str++ = c; - while (i < precision--) - *str++ = '0'; - while (i-- > 0) - *str++ = tmp[i]; - while (size-- > 0) - *str++ = ' '; - return str; -} - -static int vsprintf(char *buf, const char *fmt, va_list args) -{ - int len; - unsigned long num; - int i, base; - char * str; - const char *s; - - int flags; /* flags to number() */ - - int field_width; /* width of output field */ - int precision; /* min. # of digits for integers; max - number of chars for from string */ - int qualifier; /* 'h', 'l', or 'L' for integer fields */ - - for (str=buf ; *fmt ; ++fmt) { - if (*fmt != '%') { - *str++ = *fmt; - continue; - } - - /* process flags */ - flags = 0; - repeat: - ++fmt; /* this also skips first '%' */ - switch (*fmt) { - case '-': flags |= LEFT; goto repeat; - case '+': flags |= PLUS; goto repeat; - case ' ': flags |= SPACE; goto repeat; - case '#': flags |= SPECIAL; goto repeat; - case '0': flags |= ZEROPAD; goto repeat; - } - - /* get field width */ - field_width = -1; - if (is_digit(*fmt)) - field_width = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - field_width = va_arg(args, int); - if (field_width < 0) { - field_width = -field_width; - flags |= LEFT; - } - } - - /* get the precision */ - precision = -1; - if (*fmt == '.') { - ++fmt; - if (is_digit(*fmt)) - precision = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - precision = va_arg(args, int); - } - if (precision < 0) - precision = 0; - } - - /* get the conversion qualifier */ - qualifier = -1; - if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { - qualifier = *fmt; - ++fmt; - } - - /* default base */ - base = 10; - - switch (*fmt) { - case 'c': - if (!(flags & LEFT)) - while (--field_width > 0) - *str++ = ' '; - *str++ = (unsigned char) va_arg(args, int); - while (--field_width > 0) - *str++ = ' '; - continue; - - case 's': - s = va_arg(args, char *); - if (!s) - s = "<NULL>"; - - len = strnlen(s, precision); - - if (!(flags & LEFT)) - while (len < field_width--) - *str++ = ' '; - for (i = 0; i < len; ++i) - *str++ = *s++; - while (len < field_width--) - *str++ = ' '; - continue; - - case 'p': - if (field_width == -1) { - field_width = 2*sizeof(void *); - flags |= ZEROPAD; - } - str = number(str, - (unsigned long) va_arg(args, void *), 16, - field_width, precision, flags); - continue; - - - case 'n': - if (qualifier == 'l') { - long * ip = va_arg(args, long *); - *ip = (str - buf); - } else { - int * ip = va_arg(args, int *); - *ip = (str - buf); - } - continue; - - /* integer number formats - set up the flags and "break" */ - case 'o': - base = 8; - break; - - case 'X': - flags |= LARGE; - case 'x': - base = 16; - break; - - case 'd': - case 'i': - flags |= SIGN; - case 'u': - break; - - default: - if (*fmt != '%') - *str++ = '%'; - if (*fmt) - *str++ = *fmt; - else - --fmt; - continue; - } - if (qualifier == 'l') - num = va_arg(args, unsigned long); - else if (qualifier == 'h') - if (flags & SIGN) - num = va_arg(args, short); - else - num = va_arg(args, unsigned short); - else if (flags & SIGN) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - str = number(str, num, base, field_width, precision, flags); - } - *str = '\0'; - return str-buf; -} diff --git a/src/ltrace/Makefile b/src/ltrace/Makefile deleted file mode 100644 index 596a48d..0000000 --- a/src/ltrace/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -TOPDIR = /home/cespedes/c/ltrace -CC = gcc -CFLAGS = -Wall -O2 -I$(TOPDIR)/include -DTOPDIR=\"$(TOPDIR)\" -LD = ld - -OBJS = ltrace.o - -all: ltrace - -clean: - rm -f $(OBJS) ltrace diff --git a/src/ltrace/ltrace.c b/src/ltrace/ltrace.c deleted file mode 100644 index abb7b8b..0000000 --- a/src/ltrace/ltrace.c +++ /dev/null @@ -1,128 +0,0 @@ -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <linux/elf.h> -#include <string.h> - -int main(int argc, char **argv) -{ - int fd; - struct stat sbuf; - size_t filesize; - void * addr; - struct elf32_hdr * hdr; - Elf32_Shdr * shdr; - int i; - u_long strtab = 0; - u_long symtab = 0; - u_long symtab_len = 0; - char buf[1024]; - char * debug_filename = NULL; - - if (argc<2) { - fprintf(stderr, "Usage: %s [options] <program> [<arguments>]\n", argv[0]); - exit(1); - } - - while ((argv[1][0] == '-') && argv[1][1] && !argv[1][2]) { - switch(argv[1][1]) { - case 'o': - debug_filename = argv[2]; - argc--; argv++; - break; - default: - fprintf(stderr, "Unknown option: '%c'\n", argv[1][1]); - } - argc--; argv++; - } - - if (argc<2) { - fprintf(stderr, "Usage: %s [options] <program> [<arguments>]\n", argv[0]); - exit(1); - } - - fd = open(argv[1], O_RDONLY); - - if (fd<0) { - fprintf(stderr, "Can't open \"%s\" for reading: %s\n", argv[1], sys_errlist[errno]); - exit(1); - } - - if (fstat(fd, &sbuf)<0) { - fprintf(stderr, "Can't stat \"%s\": %s\n", argv[1], sys_errlist[errno]); - exit(1); - } - filesize = sbuf.st_size; - if (filesize < sizeof(struct elf32_hdr)) { - fprintf(stderr, "\"%s\" is not an ELF object\n", argv[1]); - exit(1); - } - - addr = mmap(NULL, filesize, PROT_READ, MAP_SHARED, fd, 0); - if (!addr) { - fprintf(stderr, "Can't mmap \"%s\": %s\n", argv[1], sys_errlist[errno]); - exit(1); - } - - if (debug_filename) { - setenv("LTRACE_FILENAME", debug_filename, 1); - printf("LTRACE_FILENAME=%s\n", debug_filename); - } - -/* - * Tengo que decirle a libtrace: - * - Comienzo y tamanno de '.dynsym' LTRACE_SYMTAB_ADDR, LTRACE_SYMTAB_SIZE - * - Comienzo de '.dynstr' LTRACE_STRTAB_ADDR - * - Comienzo y tamanno de '.got' LTRACE_GOT_ADDR, LTRACE_GOT_SIZE - * - * Todo ello especificado en decimal (por elegir algo) - */ - - hdr = addr; - - if (strncmp(hdr->e_ident, ELFMAG, SELFMAG)) { - fprintf(stderr, "%s is not an ELF object\n", argv[1]); - exit(1); - } - - for(i=0; i<hdr->e_shnum; i++) { - shdr = addr + hdr->e_shoff + i*hdr->e_shentsize; - if (shdr->sh_type == SHT_DYNSYM) { - if (!symtab) { - symtab = shdr->sh_addr; - symtab_len = shdr->sh_size; - } - } - if (shdr->sh_type == SHT_STRTAB) { - if (!strtab) { - strtab = shdr->sh_addr; - } - } - } - if (!symtab) { - fprintf(stderr, "No .dynsym in file. Not dynamically linked?\n"); - exit(1); - } - if (!strtab) { - fprintf(stderr, "No .dynstr in file. Not dynamically linked?\n"); - exit(1); - } - - sprintf(buf,"%lu", symtab); - printf("LTRACE_SYMTAB=%lu\n", symtab); - setenv("LTRACE_SYMTAB", buf, 1); - sprintf(buf,"%lu", symtab_len); - printf("LTRACE_SYMTAB_LEN=%lu\n", symtab_len); - setenv("LTRACE_SYMTAB_LEN", buf, 1); - sprintf(buf,"%lu", strtab); - printf("LTRACE_STRTAB=%lu\n", strtab); - setenv("LTRACE_STRTAB", buf, 1); - - setenv("LD_PRELOAD", TOPDIR "/lib/libtrace.so.1", 1); - execve(argv[1], &argv[1], environ); - fprintf(stderr, "Couldn't execute \"%s\": %s\n", argv[1], sys_errlist[errno]); - exit(1); -} diff --git a/src/test/Makefile b/src/test/Makefile deleted file mode 100644 index 7df7f90..0000000 --- a/src/test/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -CC = gcc -CFLAGS = -Wall -O2 -I../include -LD = ld - -all: show-elf libtest.so - -show-elf: show-elf.o hacks.o - -libtest.so: libtest.o - ld -shared -m elf_i386 -soname libtest.so -o libtest.so libtest.o - -libtest.o: libtest.s - -clean: - rm -f show-elf libtest.so *.o diff --git a/src/test/hacks.c b/src/test/hacks.c deleted file mode 100644 index 43e7696..0000000 --- a/src/test/hacks.c +++ /dev/null @@ -1,51 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#define BUF 4*1024 - -void * fd_to_memory(int fd, unsigned long * length) -{ - void *ptr1; - unsigned long size_alloc, size_read; - unsigned long i; - - ptr1 = malloc(size_alloc = (BUF+sizeof(unsigned long))); - if (!ptr1) { - fprintf(stderr, "Not enough memory\n"); - return NULL; - } - size_read = i = read(fd, ptr1, BUF); - while(i > 0) { - if ((size_alloc - size_read) < BUF) { - ptr1 = realloc(ptr1, size_alloc+=BUF); - if (!ptr1) { - fprintf(stderr, "Not enough memory\n"); - return NULL; - } - } - i = read(fd, ptr1+size_read, BUF); - size_read += i; - } - if (i>=0) { - ptr1 = realloc(ptr1, size_read); - *length = size_read; - return ptr1; - } else { - perror("read"); - return NULL; - } -} - -#ifdef STANDALONE -void main(void) -{ - void * ptr; - unsigned long length; - - ptr = fd_to_memory(0, &length); - fprintf(stderr, "Length: %lu\n", length); - write(1, ptr, length); -} -#endif - diff --git a/src/test/kk.c b/src/test/kk.c deleted file mode 100644 index 9ad7e34..0000000 --- a/src/test/kk.c +++ /dev/null @@ -1,11 +0,0 @@ -static void initialize(void) -{ - printf("Hola\n"); -} - -__asm__(".section .init"); - -void _init(void) -{ - initialize(); -} diff --git a/src/test/kk.s b/src/test/kk.s deleted file mode 100644 index 8b3a6df..0000000 --- a/src/test/kk.s +++ /dev/null @@ -1,52 +0,0 @@ - .file "kk.c" - .version "01.01" -gcc2_compiled.: -.section .rodata -.LC0: - .string "Hola\n" -.text - .align 16 - .type initialize,@function -initialize: - pushl %ebp - movl %esp,%ebp - pushl %ebx - call .L2 -.L2: - popl %ebx - addl $_GLOBAL_OFFSET_TABLE_+[.-.L2],%ebx - leal .LC0@GOTOFF(%ebx),%edx - movl %edx,%eax - pushl %eax - call printf@PLT - addl $4,%esp -.L1: - movl -4(%ebp),%ebx - movl %ebp,%esp - popl %ebp - ret -.Lfe1: - .size initialize,.Lfe1-initialize -#APP - .section .init -#NO_APP - .align 16 -.globl _init - .type _init,@function -_init: - pushl %ebp - movl %esp,%ebp - pushl %ebx - call .L4 -.L4: - popl %ebx - addl $_GLOBAL_OFFSET_TABLE_+[.-.L4],%ebx - call initialize@PLT -.L3: - movl -4(%ebp),%ebx - movl %ebp,%esp - popl %ebp - ret -.Lfe2: - .size _init,.Lfe2-_init - .ident "GCC: (GNU) 2.7.2" diff --git a/src/test/kk.so b/src/test/kk.so Binary files differdeleted file mode 100755 index b41df15..0000000 --- a/src/test/kk.so +++ /dev/null diff --git a/src/test/libtest.c b/src/test/libtest.c deleted file mode 100644 index ec6513b..0000000 --- a/src/test/libtest.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <stdio.h> - -static void initialize(void) -{ - printf("Hello, world\n"); -} diff --git a/src/test/libtest.s b/src/test/libtest.s deleted file mode 100644 index 3bdb821..0000000 --- a/src/test/libtest.s +++ /dev/null @@ -1,24 +0,0 @@ - .file "libtest.c" - .version "01.01" -gcc2_compiled.: -.section .rodata -.LC0: - .string "Hello, world\n" -.text - .align 16 - .type initialize,@function -initialize: - pushl %ebp - movl %esp,%ebp - pushl $.LC0 - call printf - movl %ebp,%esp - popl %ebp - ret -.Lfe1: - .size initialize,.Lfe1-initialize - .ident "GCC: (GNU) 2.7.2" -.section .init - movl $36,%eax - int $0x80 - ret $0x0 diff --git a/src/test/show-elf.c b/src/test/show-elf.c deleted file mode 100644 index ec22a9d..0000000 --- a/src/test/show-elf.c +++ /dev/null @@ -1,88 +0,0 @@ -#include <stdio.h> -#include <fcntl.h> -#include <string.h> -#include <linux/elf.h> - -extern void * fd_to_memory(int fd, unsigned long * length); - -int main(int argc, char **argv) -{ - int fd; - unsigned long length; - int i; - void * addr; - Elf32_Ehdr * hdr; - struct elf_phdr * phdr; - Elf32_Shdr * shdr; - - if (argc!=2) { - fprintf(stderr, "Usage: %s <elf_executable>\n", argv[0]); - exit(1); - } - - fd = open(argv[1], O_RDONLY); - if (fd<0) { - fprintf(stderr, "Cannot open %s\n", argv[1]); - exit(1); - } - - addr = fd_to_memory(fd, &length); - if (!addr) { - exit(1); - } - - hdr = addr; - - if (strncmp(hdr->e_ident, ELFMAG, SELFMAG)) { - fprintf(stderr, "%s is not an ELF object\n", argv[1]); - exit(1); - } - printf("Filename: %s\n", argv[1]); - printf("* hdr: 0x%08x\n", 0x08000000); - printf("EI_CLASS: %d\n", hdr->e_ident[EI_CLASS]); - printf("EI_DATA: %d\n", hdr->e_ident[EI_DATA]); - printf("EI_VERSION: %d\n", hdr->e_ident[EI_VERSION]); - printf("e_type: %d\n", hdr->e_type); - printf("e_machine: %d\n", hdr->e_machine); - printf("e_version: %ld\n", hdr->e_version); - printf("e_entry: 0x%08lx\n", hdr->e_entry); - printf("e_phoff: %ld\n", hdr->e_phoff); - printf("e_shoff: %ld\n", hdr->e_shoff); - printf("e_flags: 0x%08lx\n", hdr->e_flags); - printf("e_ehsize: %d\n", hdr->e_ehsize); - printf("e_phentsize: %d\n", hdr->e_phentsize); - printf("e_phnum: %d\n", hdr->e_phnum); - printf("e_shentsize: %d\n", hdr->e_shentsize); - printf("e_shnum: %d\n", hdr->e_shnum); - printf("e_shstrndx: %d\n", hdr->e_shstrndx); - - for(i=0; i<hdr->e_phnum; i++) { - printf("-- phdr number %d --\n", i); - phdr = addr + hdr->e_phoff + i*hdr->e_phentsize; - printf("* phdr: 0x%08x\n", (u_int)phdr - (u_int)hdr + 0x08000000); - printf("p_type: %ld\n", phdr->p_type); - printf("p_offset: %ld\n", phdr->p_offset); - printf("p_vaddr: 0x%08lx\n", phdr->p_vaddr); - printf("p_paddr: 0x%08lx\n", phdr->p_paddr); - printf("p_filesz: %ld\n", phdr->p_filesz); - printf("p_memsz: %ld\n", phdr->p_memsz); - printf("p_flags: %ld\n", phdr->p_flags); - printf("p_align: %ld\n", phdr->p_align); - } - for(i=0; i<hdr->e_shnum; i++) { - printf("-- shdr number %d --\n", i); - shdr = addr + hdr->e_shoff + i*hdr->e_shentsize; - printf("* shdr: 0x%08x\n", (u_int)shdr); - printf("sh_name: %ld\n",shdr->sh_name); - printf("sh_type: %ld\n",shdr->sh_type); - printf("sh_flags: %ld\n",shdr->sh_flags); - printf("sh_addr: 0x%08lx\n",shdr->sh_addr); - printf("sh_offset: %ld\n",shdr->sh_offset); - printf("sh_size: %ld\n",shdr->sh_size); - printf("sh_link: %ld\n",shdr->sh_link); - printf("sh_addralign: %ld\n",shdr->sh_addralign); - printf("sh_entsize: %ld\n",shdr->sh_entsize); - } - - exit(0); -} |