Ticket #10: 9_beos_complete.diff

File 9_beos_complete.diff, 40.6 kB (added by zadig, 39 years ago)
  • README.BEOS

    diff -urN ./README.BEOS ../elfsh.mine/README.BEOS
    old new  
     1 
     2                        ------------------- 
     3                                  ELFSH BeOS 
     4                        ------------------- 
     5 
     6Here are some information concerning elfsh compilation on BeOS systems. Please 
     7read this text carefully to use elfsh on BeOS because if it can be compiled it 
     8does not compile "out of the box" yet. Especially the modifications done work on 
     9zeta. I suppose that these changes should work on a R5+bone system. 
     10 
     11Several files are necessary that are not bundled here: 
     12- A libpthread is required (base on haiku code). 
     13- Some include files are needed. 
     14 
     15To get these files you can ask on the elfsh irc channel. Moreover several parts 
     16of the code are stil not commited on cvs, and others are not ported: 
     17- liballocproxy is not ported yet. A stub has been written. 
     18- e2dbg abd etrace are not ported. 
     19 
     20To compile elfsh you should follow the foloowing steps: 
     21 
     22./configure --enable-32 --enable-readline --use-ctags --set-shell "\"/bin/sh\"" --set-editor "\"vi\"" --set-modpath "\"/boot/home/config/share/elfsh/\"" --prefix "\"/boot/home/config\"" --set-lib-path  "\"/boot/beos/system/lib;/boot/home/config/lib\"" 
     23 
     24In the generated Makefile, comment the generation of e2dbg, libe2dbg, etrace. 
     25You may also have to fix the generated file in: 
     26librevm/include/revm-vars.h 
     27 
     28Then just type: 
     29make 
     30make install 
     31 
  • configure

    diff -urN ./configure ../elfsh.mine/configure
    old new  
    309309    echo "RANLIB  = /usr/bin/true"        >> $CONFIGFILE 
    310310;; 
    311311 
     312BeOS*) 
     313    echo "#define BEOS 1"                 >> $LIBVARSFILE 
     314    echo "RANLIB  = ranlib"               >> $CONFIGFILE 
     315    BEOS="1"; 
     316;; 
     317 
    312318*) 
    313319 
    314320if [ "$STATIC" = "0" ]; then 
     
    386392if [ "$FREEBSD" = "1" ]; then 
    387393echo "BASEPATH = \$(DESTDIR)/usr/local"                         >> Makefile 
    388394echo "MANPATH = \$(BASEPATH)/man"                               >> Makefile 
     395elif [ "$BEOS" = "1" ]; then 
     396echo "BASEPATH = \$(DESTDIR)"                              >> Makefile 
     397echo "MANPATH = \$(BASEPATH)/share/man" >> Makefile 
    389398else 
    390399echo "BASEPATH = \$(DESTDIR)/usr/local"                         >> Makefile 
    391400echo "MANPATH = \$(BASEPATH)/share/man"                         >> Makefile 
  • doc/glob_shared.txt

    diff -urN ./doc/glob_shared.txt ../elfsh.mine/doc/glob_shared.txt
    old new  
     1global symbols injection. 
     2 
     3This document describes the injection process of global objects on beos systems. 
     4The issues on this system should be the same on other os when injecting rel 
     5objects in shared libraries. 
     6 
     7This text is based on the etrel_original test of the elfsh testsuite. 
     8 
     91- Static objects. 
     10    
     11   the object will be located in rel.o.data: 
     12 
     13   relocation: 
     14    
     152- initialized objects 
     16 
     17   the object will be located in the data section (num 3): 
     18   17: 00000000     4 OBJECT  GLOBAL DEFAULT    3 glvar_testreloc  
     19 
     20   a symbol injected should have the following specs: 
     21   98: 000025f0     4 OBJECT  GLOBAL DEFAULT  COM gi_global1 
     22          | 
     23         \|/ 
     24         got 
     25          
     26   relocation type is R_386_GOT32: 
     27   0000009c  00001103 R_386_GOT32       00000000   glvar_testreloc 
     28 
     29   Issue in 0.74: The relocation is not correct. The value points directly to 
     30   the global symbol address instead of its altgot entry. hence a crash when the 
     31   code try to access the content of the got entry that is in fact the actual 
     32   object value. 
     33 
     34   A new got entry must be allocated for this object in altgot, and the 
     35   relocation must be performed on it. 
     36 
     37   When should this entry be added ? 
     38   in extplt technique the entry is added when performing the relocation if we 
     39   do not find the symbol in the host/rel. In this case the symbol is present 
     40   but not its got entry. 
     41 
     42   So the following steps must be done: 
     43   - When allocated, the altgot rel section (.elfsh.reldyn) must be oversized to 
     44   add new entries. 
     45   - allocate a new got entry for the symbol. 
     46   - allocate a new relocation entry in elfsh.reldyn for this got entry. 
     47 
     483- uninitialized objects 
     49 
     50   the object will be located in rel.o.bss: 
  • e2dbg/include/libe2dbg.h

    diff -urN ./e2dbg/include/libe2dbg.h ../elfsh.mine/e2dbg/include/libe2dbg.h
    old new  
    1414#include "revm.h" 
    1515#include "aproxy.h" 
    1616 
     17#ifdef __BEOS__ 
     18typedef char siginfo_t; 
     19#define SA_SIGINFO NSIG 
     20#define sa_sigaction sa_handler 
     21#endif 
     22 
    1723#define         __DEBUG_E2DBG__         0 
    1824#define         __DEBUG_MUTEX__         1 
    1925#define         __DEBUG_BP__            0 
  • elfsh/Makefile

    diff -urN ./elfsh/Makefile ../elfsh.mine/elfsh/Makefile
    old new  
    3737LDFLAGS32               += -L../libedfmt/ -L../libelfsh/ -ledfmt32 -lelfsh32      \ 
    3838                        -L../libdump/ -L/usr/pkg/lib/ -L../libmjollnir/           \ 
    3939                        -lmjollnir32 $(LPTHREAD) -L../elibc -lcelfsh32            \ 
     40                        -L/boot/home/config/lib $(LPTHREAD) \ 
    4041                        -L../libasm/ -lasm $(LDUIOPT32) -g3                       \ 
    4142                        -L../liballocproxy -L../libmjollnir/                      \ 
    4243                        -L../libaspect/ -laspect32 -L../librevm/ -lrevm32         \ 
  • liballocproxy/Makefile

    diff -urN ./liballocproxy/Makefile ../elfsh.mine/liballocproxy/Makefile
    old new  
    1010 
    1111CC      ?= gcc 
    1212LD      ?= ld 
    13 SRC     = aproxy_malloc.c aproxy_strdup.c 
     13SRC     = elfsh_malloc_beos.c 
     14#SRC    = aproxy_malloc.c aproxy_strdup.c 
    1415OBJ     = $(SRC:.c=.o) 
    1516CFLAGS  += -D__STD_C -DMALLOC_DEBUG -DUSE_ARENAS -DSHARED -DUSE_TLS \ 
    1617        -fPIC -g3 -Iinclude -I../libelfsh/include/ 
  • liballocproxy/elfsh_malloc_beos.c

    diff -urN ./liballocproxy/elfsh_malloc_beos.c ../elfsh.mine/liballocproxy/elfsh_malloc_beos.c
    old new  
     1#include <stdio.h> 
     2 
     3_EXPORT void            *elfsh_calloc(size_t size, char val) 
     4{ 
     5   return(calloc(size, val)); 
     6} 
     7 
     8_EXPORT void            *elfsh_realloc(void * addr, size_t size) 
     9{ 
     10   return(realloc(addr, size)); 
     11} 
     12 
     13_EXPORT void            *elfsh_malloc(size_t size) 
     14{ 
     15   return(malloc(size)); 
     16} 
     17_EXPORT void            *elfsh_valloc(size_t t) 
     18{ 
     19   return(valloc(t)); 
     20} 
     21 
     22_EXPORT void            *elfsh_memalign(size_t t, u_int nbr) 
     23{ 
     24   return(memalign(t, nbr)); 
     25} 
     26 
     27_EXPORT void            elfsh_free(void * addr) 
     28{ 
     29   free(addr); 
     30} 
     31 
  • libasm/include/libasm.h

    diff -urN ./libasm/include/libasm.h ../elfsh.mine/libasm/include/libasm.h
    old new  
    1111 
    1212 
    1313#include <sys/types.h> 
     14#ifdef __BEOS__ 
     15#include <stdint.h> 
     16#endif 
    1417#include <stdio.h> 
    1518#include <string.h> 
    1619#include <stdlib.h> 
  • libasm/src/arch/ia32/ei386-7.c

    diff -urN ./libasm/src/arch/ia32/ei386-7.c ../elfsh.mine/libasm/src/arch/ia32/ei386-7.c
    old new  
    1515 */ 
    1616 
    1717int     i386_group12(asm_instr *new, u_char *opcode, u_int len, asm_processor *proc) { 
     18  struct s_modrm *modrm; 
    1819  new->ptr_instr = opcode; 
    1920  new->len += 1; 
    20   struct s_modrm *modrm = (struct s_modrm *) opcode + 1; 
     21  modrm = (struct s_modrm *) opcode + 1; 
    2122   
    2223  switch (modrm->r) { 
    2324    case 2: 
     
    6768 */ 
    6869 
    6970int     i386_group14(asm_instr *new, u_char *opcode, u_int len, asm_processor *proc) { 
     71  struct s_modrm *modrm; 
    7072  new->ptr_instr = opcode; 
    7173  new->len += 1; 
    72   struct s_modrm *modrm = (struct s_modrm *) opcode + 1; 
     74  modrm = (struct s_modrm *) opcode + 1; 
    7375   
    7476  switch (modrm->r) { 
    7577    case 2: 
  • libasm/src/arch/ia32/handlers/i386_group12.c

    diff -urN ./libasm/src/arch/ia32/handlers/i386_group12.c ../elfsh.mine/libasm/src/arch/ia32/handlers/i386_group12.c
    old new  
    1010 */ 
    1111 
    1212int     i386_group12(asm_instr *new, u_char *opcode, u_int len, asm_processor *proc) { 
     13  struct s_modrm *modrm; 
    1314  new->ptr_instr = opcode; 
    1415  new->len += 1; 
    15   struct s_modrm *modrm = (struct s_modrm *) opcode + 1; 
     16  modrm = (struct s_modrm *) opcode + 1; 
    1617   
    1718  switch (modrm->r) { 
    1819    case 2: 
  • libasm/src/arch/ia32/handlers/i386_group14.c

    diff -urN ./libasm/src/arch/ia32/handlers/i386_group14.c ../elfsh.mine/libasm/src/arch/ia32/handlers/i386_group14.c
    old new  
    1010 */ 
    1111 
    1212int     i386_group14(asm_instr *new, u_char *opcode, u_int len, asm_processor *proc) { 
     13  struct s_modrm *modrm; 
    1314  new->ptr_instr = opcode; 
    1415  new->len += 1; 
    15   struct s_modrm *modrm = (struct s_modrm *) opcode + 1; 
     16  modrm = (struct s_modrm *) opcode + 1; 
    1617   
    1718  switch (modrm->r) { 
    1819    case 2: 
  • libe2dbg/Makefile

    diff -urN ./libe2dbg/Makefile ../elfsh.mine/libe2dbg/Makefile
    old new  
    3535                        -I../libedfmt/include/ -I../liballocproxy/include/       \ 
    3636                        -DELFSH_INTERN -DE2DBG_INTERN $(ASMOPT) -DELFSH64 
    3737 
    38 LDFLAGS32               += $(DLOPT) $(LDMJOLLNIR) $(DYNOPT) $(EXTRAOPT) $(LDDUMPOPT) 
    39 LDFLAGS64               += $(DLOPT) $(LDMJOLLNIR) $(DYNOPT) $(EXTRAOPT) $(LDDUMPOPT) 
     38LDFLAGS32               += $(DLOPT) $(LDMJOLLNIR) $(DYNOPT) $(EXTRAOPT) $(LDDUMPOPT) -L/boot/home/config/lib $(LPTHREAD) 
     39LDFLAGS64               += $(DLOPT) $(LDMJOLLNIR) $(DYNOPT) $(EXTRAOPT) $(LDDUMPOPT) $(LPTHREAD) 
    4040 
    4141EXTRAOBJ32              = ../libasm/libasm.o ../libmjollnir/libmjollnir32.o     \ 
    4242                        ../libelfsh/libelfsh32.o ../libedfmt/libedfmt32.o       \ 
  • libe2dbg/dumpregs.c

    diff -urN ./libe2dbg/dumpregs.c ../elfsh.mine/libe2dbg/dumpregs.c
    old new  
    4646 
    4747#if defined(__amd64__) && defined(__FreeBSD__) 
    4848  #error "Register context not filled on FreeBSD / AMD64" 
    49 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) 
     49#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__BEOS__) 
    5050  e2dbg_register_dump("EAX", e2dbgworld.curthread->context->uc_mcontext.mc_eax); 
    5151  e2dbg_register_dump("EBX", e2dbgworld.curthread->context->uc_mcontext.mc_ebx); 
    5252  e2dbg_register_dump("ECX", e2dbgworld.curthread->context->uc_mcontext.mc_ecx); 
  • libe2dbg/include/libe2dbg.h

    diff -urN ./libe2dbg/include/libe2dbg.h ../elfsh.mine/libe2dbg/include/libe2dbg.h
    old new  
    1414#include "revm.h" 
    1515#include "aproxy.h" 
    1616 
     17#ifdef __BEOS__ 
     18/* TODO: this allow to compile but certainly not to run */ 
     19typedef char siginfo_t; 
     20#define SA_SIGINFO NSIG 
     21#define SA_NODEFER 0 
     22#define sa_sigaction sa_handler 
     23#endif 
     24 
    1725#define         __DEBUG_E2DBG__         0 
    1826#define         __DEBUG_BP__            0 
    1927#define         __DEBUG_EMALLOC__       0 
  • libe2dbg/xmalloc.c

    diff -urN ./libe2dbg/xmalloc.c ../elfsh.mine/libe2dbg/xmalloc.c
    old new  
    146146 
    147147 
    148148/* Wrapper for calloc */ 
    149 #if __FreeBSD__ > 5 
     149#if (__FreeBSD__ > 5) || defined(__BEOS__) 
    150150void            *calloc(size_t t, size_t nbr) 
    151151#else 
    152152void            *calloc(size_t t, u_int nbr) 
  • libedfmt/Makefile

    diff -urN ./libedfmt/Makefile ../elfsh.mine/libedfmt/Makefile
    old new  
    1818NAME32                  = libedfmt32 
    1919NAME64                  = libedfmt64 
    2020 
    21 CFLAGS32                += -Wall -fPIC -g3 -O2 -Iinclude -I ../libaspect/include/ \ 
     21CFLAGS32                += -Wall -fPIC -g -Iinclude -I ../libaspect/include/ \ 
    2222                        -I../libelfsh/include/ -I../elibc/include/ -DELFSH_INTERN \ 
    2323                        -DELFSH32 
    2424 
  • libedfmt/stabs.c

    diff -urN ./libedfmt/stabs.c ../elfsh.mine/libedfmt/stabs.c
    old new  
    219219 
    220220  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); 
    221221 
     222  if(current_file == NULL) 
     223      PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, -1); 
     224 
    222225  /* End of the current function ? */ 
    223226  if (STABS_IVD_STR(str)) 
    224227    { 
     
    281284 
    282285  if (NULL == type || STABS_IVD_STR(str)) 
    283286    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,  
    284                       "Invalid parameter", NULL); 
     287                      "Invalid parameter", -1); 
    285288 
    286289  /* First we got a type */ 
    287290  rtype = edfmt_stabs_type(str); 
     
    384387  if (isVector) 
    385388    type->u.arr.type |= STABS_ARRAY_VECTOR; 
    386389 
    387   PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, NULL);   
     390  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);   
    388391} 
    389392 
    390393/** 
     
    10001003        case STABS_TYPE_BINCL: 
    10011004          inc = 1; 
    10021005        case STABS_TYPE_SO: 
     1006          if (!current_file) 
     1007            break; 
     1008 
    10031009          /* Include or SO file */ 
    10041010          parse_str = 0; 
    10051011          if (!inc && (!str || !str[0])) 
     
    11141120        { 
    11151121          data = STABS_DATA(&str); 
    11161122 
    1117           if (data) 
     1123          if (data && current_file) 
    11181124            { 
    11191125              /* TODO: Add more informations  */ 
    11201126              switch(data->scope) 
  • libelfsh/Makefile

    diff -urN ./libelfsh/Makefile ../elfsh.mine/libelfsh/Makefile
    old new  
    3535all                     : all32 all64 
    3636 
    3737all32                   : $(OBJ32) 
    38                         @$(CC) -L../elibc/ -lcelfsh32 -L../liballocproxy/ \ 
     38                        @$(CC) -shared $(OBJ32) -o $(NAME32).so \ 
     39                        -L../elibc/ -lcelfsh32 -L../liballocproxy/ \ 
    3940                        -lallocproxy -L../libaspect/ -laspect32 -DELFSH32 \ 
    40                         -shared $(OBJ32) -o $(NAME32).so 
     41                        -L../libasm/ -lasm  
    4142                        @$(AR) $(NAME32).a $(OBJ32) 
    4243                        @$(RANLIB) $(NAME32).a 
    4344                        @$(LD) -r $(OBJ32) -o $(NAME32).o 
  • libelfsh/bss.c

    diff -urN ./libelfsh/bss.c ../elfsh.mine/libelfsh/bss.c
    old new  
    335335    if (elfsh_get_symbol_link(symtab + index) == SHN_COMMON) 
    336336      { 
    337337 
    338         /* Align symbol size as needed */ 
    339         if (symtab[index].st_value) 
    340           while (bss_size % symtab[index].st_value) 
    341             bss_size++; 
     338        /* Align symbol size as needed */ 
     339        if (symtab[index].st_value) 
     340          while (bss_size % symtab[index].st_value) 
     341            bss_size++; 
    342342 
     343        /* global symbols will added later in the injection process */ 
     344        if(elfsh_get_symbol_bind(symtab + index) == STB_LOCAL) 
     345        { 
     346          /* Create and inject symbol in ET_EXEC */ 
     347          new = elfsh_create_symbol(bss_size, 
     348              symtab[index].st_size, 
     349              STT_OBJECT, STB_LOCAL, 
     350              0, host_bss->index); 
    343351 
    344         /* Create and inject symbol in ET_EXEC */ 
    345         new = elfsh_create_symbol(bss_size, 
    346                                   symtab[index].st_size, 
    347                                   STT_OBJECT, STB_LOCAL, 
    348                                   0, host_bss->index); 
    349  
    350         name = elfsh_get_symbol_name(rel, symtab + index); 
    351         elfsh_insert_symbol(host_symtab, &new, name); 
    352         bss_size += symtab[index].st_size; 
     352          name = elfsh_get_symbol_name(rel, symtab + index); 
     353          elfsh_insert_symbol(host_symtab, &new, name); 
     354          bss_size += symtab[index].st_size; 
     355        } 
    353356      } 
    354357 
    355358  bss_size -= host_bss->shdr->sh_addr; 
  • libelfsh/extplt.c

    diff -urN ./libelfsh/extplt.c ../elfsh.mine/libelfsh/extplt.c
    old new  
    259259  elfsh_set_dynentry_val(dynent, elfsh_get_dynentry_val(dynent) + relentsz); 
    260260 
    261261  /* Insert symbol referenced by previous injected reloc entry */ 
    262   sym = elfsh_create_symbol(extplt->shdr->sh_addr + extplt->curend - elfsh_get_pltentsz(file), 
    263                             elfsh_get_pltentsz(file), STT_SECTION, 
    264                             0, 0, extplt->index); 
     262  if(elfsh_get_ostype(file) == ELFSH_OS_BEOS) 
     263  { 
     264    sym = elfsh_create_symbol(extplt->shdr->sh_addr + extplt->curend - elfsh_get_pltentsz(file), 
     265        elfsh_get_pltentsz(file), STT_FUNC, 
     266        STB_GLOBAL, STV_DEFAULT, SHN_UNDEF); 
     267  } 
     268  else 
     269  { 
     270    sym = elfsh_create_symbol(extplt->shdr->sh_addr + extplt->curend - elfsh_get_pltentsz(file), 
     271        elfsh_get_pltentsz(file), STT_SECTION, 
     272        0, 0, extplt->index); 
     273  } 
    265274  sym.st_name = dynstr->curend; 
    266275  elfsh_set_symbol_bind(&sym, STB_GLOBAL); 
    267276  memcpy(elfsh_get_raw(dynsym) + dynsym->curend, &sym, sizeof(sym)); 
  • libelfsh/got.c

    diff -urN ./libelfsh/got.c ../elfsh.mine/libelfsh/got.c
    old new  
    454454  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); 
    455455} 
    456456 
    457  
    458  
    459  
    460 /** 
    461  * Only used on BeoS  
    462  * Tested and developed by zadig@myrealbox.com 
    463  * 
    464  */ 
    465 int   elfsh_get_got_symbol_reloc(elfshobj_t     *file, 
    466                                  uint8          *name, 
    467                                  elfsh_Rel      *rel_entry) 
    468 { 
    469    elfshsect_t *got, *rel_got; 
    470    u_int       index, got_rel_index; 
    471    u_int       entsz; 
    472    int         got_index; 
    473    elfsh_Off   off; 
    474    void         *data; 
    475     
    476    PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); 
    477     
    478    /* Sanity checks */ 
    479    entsz = elfsh_get_pltentsz(file); 
    480    if (entsz < 0) 
    481      PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
    482                        "Invalid PLT entry size", -1); 
    483  
    484   if (NULL == elfsh_get_dynsymtab(file, NULL)) 
    485     PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
    486                       "Unable to get DYNSYM", -1); 
    487  
    488   if (NULL == elfsh_get_symtab(file, NULL)) 
    489     PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
    490                       "Unable to get SYMTAB", -1); 
    491    
    492   /* get got section index */ 
    493   got = elfsh_get_section_by_name(file, 
    494                                   ELFSH_SECTION_NAME_GOT, 
    495                                   &got_index, NULL, NULL); 
    496   if (got == NULL) 
    497     PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
    498                       "Unable to get GOT", -1); 
    499    
    500   /* search the got relocation section */ 
    501   rel_got = NULL; 
    502   for (got_rel_index = 0; got_rel_index < file->hdr->e_shnum; got_rel_index++) 
    503     { 
    504       rel_got = elfsh_get_section_by_index(file, got_rel_index, 
    505                                           NULL, NULL); 
    506     if (rel_got->shdr->sh_info == got_index) 
    507       break; 
    508     } 
    509    
    510   if ((rel_got == NULL) || (rel_got->shdr->sh_info != got_index)) 
    511     PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
    512                       "Unable to get GOT relocations", -1); 
    513    
    514   /* search for the requested symbol */ 
    515   off = entsz; 
    516   data = elfsh_get_raw(rel_got); 
    517   for (index = 0;  
    518        index < (rel_got->shdr->sh_size / rel_got->shdr->sh_entsize);  
    519        off += entsz, index ++) 
    520     { 
    521       elfsh_Rel *cur_rel; 
    522       cur_rel = ((elfsh_Rel*) data) + index; 
    523       if(strcmp(elfsh_get_symname_from_reloc(file, cur_rel), name) == 0) 
    524         { 
    525           *rel_entry = *cur_rel; 
    526           PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); 
    527         } 
    528     } 
    529  
    530   PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
    531                     "Symbol not found", -1); 
    532 } 
    533  
    534  
    535  
    536  
  • libelfsh/hooks.c

    diff -urN ./libelfsh/hooks.c ../elfsh.mine/libelfsh/hooks.c
    old new  
    842842                           ELFSH_OS_SOLARIS, elfsh_cflow_mips64); 
    843843  elfsh_register_cflowhook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    844844                           ELFSH_OS_LINUX, elfsh_cflow_ia32); 
     845  elfsh_register_cflowhook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     846                           ELFSH_OS_BEOS, elfsh_cflow_ia32); 
    845847 
    846848  /* Usual REL/PLT/ALTPLT targets for ET_DYN/x86 */ 
    847849  elfsh_register_plthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     
    854856                         ELFSH_OS_NETBSD, elfsh_hijack_plt_ia32); 
    855857  elfsh_register_plthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    856858                         ELFSH_OS_SOLARIS, elfsh_hijack_plt_ia32); 
     859  elfsh_register_plthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     860                         ELFSH_OS_BEOS, elfsh_hijack_plt_ia32); 
    857861  elfsh_register_relhook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN, 
    858862                         ELFSH_OS_BEOS, elfsh_relocate_ia32); 
    859863  elfsh_register_altplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     
    915919                               ELFSH_OS_OPENBSD, elfsh_encodeplt_ia32); 
    916920  elfsh_register_encodeplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    917921                               ELFSH_OS_SOLARIS, elfsh_encodeplt_ia32); 
     922  elfsh_register_encodeplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     923                               ELFSH_OS_BEOS, elfsh_encodeplt_ia32); 
    918924 
    919925  /* Usual ENCODEPLT1 targets for ET_EXEC/IA32 */ 
    920926  elfsh_register_encodeplt1hook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
     
    937943                                ELFSH_OS_OPENBSD, elfsh_encodeplt1_ia32); 
    938944  elfsh_register_encodeplt1hook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    939945                                ELFSH_OS_SOLARIS, elfsh_encodeplt1_ia32); 
     946  elfsh_register_encodeplt1hook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     947                                ELFSH_OS_BEOS, elfsh_encodeplt1_ia32); 
    940948 
    941949  /*** Now EXTPLT handlers ***/ 
    942950 
     
    961969                            ELFSH_OS_OPENBSD, elfsh_extplt_ia32); 
    962970  elfsh_register_extplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    963971                            ELFSH_OS_SOLARIS, elfsh_extplt_ia32); 
     972  elfsh_register_extplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     973                            ELFSH_OS_BEOS, elfsh_extplt_ia32); 
    964974 
    965975  /***************************************/ 
    966976  /****** ARGC arguments counting  ******/ 
  • libelfsh/ia32.c

    diff -urN ./libelfsh/ia32.c ../elfsh.mine/libelfsh/ia32.c
    old new  
    416416{ 
    417417  elfsh_Shdr *section; 
    418418  elfsh_Sym  *symbol;    
     419  elfsh_Rel  *rel_entry; 
    419420  char       *symname; 
    420421 
    421422  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); 
     
    438439      if (section == NULL) 
    439440         PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
    440441                           "Unable to find GOT for GOTOFF", -1); 
    441       *dword = cur->r_offset - section->sh_addr; 
     442      symname = elfsh_get_symname_from_reloc(mod->parent, cur);  
     443      if(symname == NULL) 
     444         PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
     445             "Unable to find symbol in host", -1); 
     446       
     447      rel_entry = elfsh_get_relent_by_name(new->parent, symname); 
     448      if(rel_entry == NULL) 
     449        *dword = addr - section->sh_addr; 
     450      else 
     451        *dword = elfsh_get_reloffset(rel_entry) - section->sh_addr; 
    442452      break; 
    443453     
    444454    case R_386_PLT32: 
     
    497507      if (section == NULL) 
    498508         PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
    499509                        "Unable to find GOT for GOTPC", -1); 
    500  
    501       *dword = section->sh_addr - (new->shdr->sh_addr + cur->r_offset) + 2; 
     510      if(elfsh_get_ostype(new->parent) == ELFSH_OS_BEOS) 
     511        *dword = section->sh_addr - (new->shdr->sh_addr + cur->r_offset) + 3; 
     512      else 
     513        *dword = section->sh_addr - (new->shdr->sh_addr + cur->r_offset) + 2; 
    502514 
    503515#if     __DEBUG_RELADD__         
    504       printf("[DEBUG_RELADD] R_386_GOTPC : *dword=%08X, non added *dword was %08X \n",  
    505              section->sh_addr - (new->shdr->sh_addr + cur->r_offset) + 2, *dword); 
     516      if(elfsh_get_ostype(new->parent) == ELFSH_OS_BEOS) 
     517      { 
     518        printf("[DEBUG_RELADD] R_386_GOTPC : *dword=%08X, non added *dword was %08X \n",  
     519            section->sh_addr - (new->shdr->sh_addr + cur->r_offset) + 3, *dword); 
     520      } 
     521      else 
     522      { 
     523        printf("[DEBUG_RELADD] R_386_GOTPC : *dword=%08X, non added *dword was %08X \n",  
     524            section->sh_addr - (new->shdr->sh_addr + cur->r_offset) + 2, *dword); 
     525      } 
    506526#endif 
    507527 
    508528      break; 
  • libelfsh/include/libelfsh.h

    diff -urN ./libelfsh/include/libelfsh.h ../elfsh.mine/libelfsh/include/libelfsh.h
    old new  
    2222#include <fcntl.h> 
    2323#include <errno.h> 
    2424#include <sys/stat.h> 
     25#ifndef __BEOS__ 
    2526#include <sys/mman.h> 
     27#endif 
    2628 
    2729#include "elfsh-libc.h" 
    2830#include <elf.h> 
     
    3032#include <libelfsh/libelfsh-compat.h> 
    3133 
    3234#ifdef __BEOS__ 
     35#include <inttypes.h> 
     36#include <stdint.h> 
    3337#include <bsd_mem.h> 
     38#include <OS.h> 
    3439#endif 
    3540 
    3641#if !defined(__USE_GNU) 
     
    3944 
    4045#include <sys/ucontext.h> 
    4146 
     47#ifndef __BEOS__ 
    4248#include <sys/user.h> 
    4349#include <sys/procfs.h> 
     50#endif 
    4451 
    4552/* Configure the DEBUG modes for various part of the code */ 
    4653#define         __DEBUG_MAP__                  0 
  • libelfsh/mips32.c

    diff -urN ./libelfsh/mips32.c ../elfsh.mine/libelfsh/mips32.c