aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Cespedes <cespedes@thehackers.org>1997-03-28 14:31:14 +0100
committerJuan Cespedes <cespedes@thehackers.org>1997-03-28 14:31:14 +0100
commit1519dd0c0d81a2de425403593ffb0da8b245ef82 (patch)
tree560f5ca992368d427848c5699196983adf481162
parentf77decfea4b4c666bbf1d5d56426e70e729fd060 (diff)
downloadltrace-1519dd0c0d81a2de425403593ffb0da8b245ef82.tar.gz
Version 0.0.1997.03.27
-rw-r--r--Makefile7
-rwxr-xr-xlib/libtrace.so.1bin0 -> 2518 bytes
-rw-r--r--src/init_libtrace.c6
-rw-r--r--src/libtrace/Makefile (renamed from src/Makefile)4
-rw-r--r--src/libtrace/__setfpucw.c (renamed from src/__setfpucw.c)0
-rw-r--r--src/libtrace/init_libtrace.c68
-rw-r--r--src/ltrace/Makefile11
-rw-r--r--src/ltrace/ltrace.c15
-rw-r--r--src/test/Makefile (renamed from test/Makefile)0
-rw-r--r--src/test/hacks.c (renamed from test/hacks.c)0
-rw-r--r--src/test/test.c (renamed from test/test.c)0
-rwxr-xr-xtest/test2bin3877 -> 0 bytes
-rw-r--r--test/test2.c13
13 files changed, 101 insertions, 23 deletions
diff --git a/Makefile b/Makefile
index aa0976a..0278488 100644
--- a/Makefile
+++ b/Makefile
@@ -7,10 +7,11 @@ all:
@echo
clean:
- make -C src clean
- make -C test 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 libtrace-`date +%y%m%d`.tgz libtrace )
+ ( cd .. ; tar zcvf ltrace-`date +%y%m%d`.tgz ltrace )
diff --git a/lib/libtrace.so.1 b/lib/libtrace.so.1
new file mode 100755
index 0000000..e4b03b0
--- /dev/null
+++ b/lib/libtrace.so.1
Binary files differ
diff --git a/src/init_libtrace.c b/src/init_libtrace.c
deleted file mode 100644
index 4955791..0000000
--- a/src/init_libtrace.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <hck/syscall.h>
-
-void init_libtrace(void)
-{
- _sys_write(1,"Hola\n",5);
-}
diff --git a/src/Makefile b/src/libtrace/Makefile
index 71bf97c..cee9a61 100644
--- a/src/Makefile
+++ b/src/libtrace/Makefile
@@ -1,5 +1,6 @@
+TOPDIR = /home/cespedes/c/ltrace
CC = gcc
-CFLAGS = -Wall -O2 -I../include
+CFLAGS = -Wall -O2 -I$(TOPDIR)/include
LD = ld
OBJS = __setfpucw.o init_libtrace.o
@@ -8,6 +9,7 @@ all: libtrace.so.1
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/__setfpucw.c b/src/libtrace/__setfpucw.c
index 5b48c37..5b48c37 100644
--- a/src/__setfpucw.c
+++ b/src/libtrace/__setfpucw.c
diff --git a/src/libtrace/init_libtrace.c b/src/libtrace/init_libtrace.c
new file mode 100644
index 0000000..fb53721
--- /dev/null
+++ b/src/libtrace/init_libtrace.c
@@ -0,0 +1,68 @@
+#include <linux/elf.h>
+#include <hck/syscall.h>
+
+static int errno;
+
+void init_libtrace(void)
+{
+ unsigned long tmp[0];
+ unsigned long *stack = tmp;
+ int phnum=0, phent=0;
+ struct elf_phdr * phdr = NULL;
+ int i;
+ struct dynamic * dpnt;
+ struct elf32_sym * symtab = NULL;
+ void * strtab = NULL;
+
+/*
+ * When loading the interpreter, in linux/fs/binfmt_elf.h, the stack
+ * is filled with an auxiliary table defined in include/linux/elf.h;
+ * it has some important things such as pointers to the program
+ * headers. We are trying to find that table.
+ *
+ */
+ for(; (stack < (unsigned long *)(0xc0000000-256)); stack++) {
+ if ((stack[0]==3) && (stack[2]==4) && (stack[4]==5) && (stack[6]==6)) {
+ phdr = (struct elf_phdr *)stack[1];
+ phent = stack[3];
+ phnum = stack[5];
+ break;
+ }
+ }
+ if (!phdr) {
+ _sys_write(2,"No auxiliary table in stack?\n",29);
+ return;
+ }
+
+ for(i=0; i<phnum; i++) {
+ if (phdr->p_type == PT_DYNAMIC) {
+ break;
+ }
+ phdr = (struct elf_phdr *)((void*)phdr + phent);
+ }
+ if (!phdr || phdr->p_type != PT_DYNAMIC) {
+ _sys_write(2,"No .dynamic in file?\n",21);
+ return;
+ }
+ dpnt = (struct dynamic *)phdr->p_vaddr;
+
+ while(dpnt->d_tag) {
+ if (dpnt->d_tag == DT_SYMTAB) {
+ symtab = (struct elf32_sym *) dpnt->d_un.d_ptr;
+ }
+ if (dpnt->d_tag == DT_STRTAB) {
+ strtab = (void *) dpnt->d_un.d_ptr;
+ }
+ dpnt++;
+ }
+ if (!symtab) {
+ _sys_write(2, "No .symtab?\n",12);
+ return;
+ }
+ if (!strtab) {
+ _sys_write(2, "No .strtab?\n",12);
+ return;
+ }
+
+ _sys_write(2,"Hola\n",5);
+}
diff --git a/src/ltrace/Makefile b/src/ltrace/Makefile
new file mode 100644
index 0000000..596a48d
--- /dev/null
+++ b/src/ltrace/Makefile
@@ -0,0 +1,11 @@
+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
new file mode 100644
index 0000000..d511ba9
--- /dev/null
+++ b/src/ltrace/ltrace.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ if (argc<2) {
+ fprintf(stderr, "Usage: %s <program> [<arguments>]\n", argv[0]);
+ exit(1);
+ }
+ setenv("LD_PRELOAD", TOPDIR "/lib/libtrace.so.1", 1);
+ execve(argv[1], &argv[1], environ);
+ fprintf(stderr, "Couldn't execute %s\n", argv[1]);
+ exit(1);
+}
diff --git a/test/Makefile b/src/test/Makefile
index 482875a..482875a 100644
--- a/test/Makefile
+++ b/src/test/Makefile
diff --git a/test/hacks.c b/src/test/hacks.c
index 43e7696..43e7696 100644
--- a/test/hacks.c
+++ b/src/test/hacks.c
diff --git a/test/test.c b/src/test/test.c
index ec22a9d..ec22a9d 100644
--- a/test/test.c
+++ b/src/test/test.c
diff --git a/test/test2 b/test/test2
deleted file mode 100755
index 90c5cfc..0000000
--- a/test/test2
+++ /dev/null
Binary files differ
diff --git a/test/test2.c b/test/test2.c
deleted file mode 100644
index 988bf6c..0000000
--- a/test/test2.c
+++ /dev/null
@@ -1,13 +0,0 @@
-void function(i)
-{
- int * sp;
-
- sp = &i;
-
- printf("%d\n", sp[0]);
-}
-
-main()
-{
- function(23);
-}