Ticket #10: 2_beos_partial.diff

File 2_beos_partial.diff, 21.1 kB (added by zadig, 39 years ago)
  • README.BEOS

    diff -urN ./README.BEOS ../elfsh.mine/README.BEOS
    old new  
     1./configure --enable-32 --enable-readline --use-etags --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\"" 
     2 
     3config.h: 
     4remove -rdynamic 
     5 
     6export RANLIB="ranlib" 
     7 
     8Makefile: 
     9BASEPATH = $(DESTDIR) 
     10   comment libmalloc, e2dbg 
     11 
  • e2dbg/dumpregs.c

    diff -urN ./e2dbg/dumpregs.c ../elfsh.mine/e2dbg/dumpregs.c
    old new  
    4141 
    4242#if defined(__amd64__) && defined(__FreeBSD__) 
    4343 
    44 #elif defined(__FreeBSD__) 
     44#elif defined(__FreeBSD__) || defined(__BEOS__) 
    4545  vm_dumpreg("EAX", e2dbgworld.curthread->context->uc_mcontext.mc_eax); 
    4646  vm_dumpreg("EBX", e2dbgworld.curthread->context->uc_mcontext.mc_ebx); 
    4747  vm_dumpreg("ECX", e2dbgworld.curthread->context->uc_mcontext.mc_ecx); 
  • e2dbg/include/e2dbg.h

    diff -urN ./e2dbg/include/e2dbg.h ../elfsh.mine/e2dbg/include/e2dbg.h
    old new  
    99#ifndef __E2DBG_H__ 
    1010 #define __E2DBG_H__ 
    1111 
     12#ifdef __BEOS__ 
     13typedef char siginfo_t; 
     14#define SA_SIGINFO NSIG 
     15#define sa_sigaction sa_handler 
     16#endif 
     17 
    1218#define         __DEBUG_E2DBG__         0 
    1319#define         __DEBUG_MUTEX__         1 
    1420#define         __DEBUG_BP__            0 
  • e2dbg/xmalloc.c

    diff -urN ./e2dbg/xmalloc.c ../elfsh.mine/e2dbg/xmalloc.c
    old new  
    149149 
    150150 
    151151/* Wrapper for calloc */ 
    152 #if __FreeBSD__ > 5 
     152#if (__FreeBSD__ > 5) || defined(__BEOS__) 
    153153void            *calloc(size_t t, size_t nbr) 
    154154#else 
    155155void            *calloc(size_t t, u_int nbr) 
  • libasm/include/libasm.h

    diff -urN ./libasm/include/libasm.h ../elfsh.mine/libasm/include/libasm.h
    old new  
    1010 
    1111 
    1212#include <sys/types.h> 
     13#ifdef __BEOS__ 
     14#include <stdint.h> 
     15#endif 
    1316#include <stdio.h> 
    1417#include <string.h> 
    1518#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  
    1212 */ 
    1313 
    1414int     i386_group12(asm_instr *new, u_char *opcode, u_int len, asm_processor *proc) { 
     15  struct s_modrm *modrm = (struct s_modrm *) opcode + 1; 
    1516  new->ptr_instr = opcode; 
    1617  new->len += 1; 
    17   struct s_modrm *modrm = (struct s_modrm *) opcode + 1; 
    1818   
    1919  switch (modrm->r) { 
    2020    case 2: 
     
    6464 */ 
    6565 
    6666int     i386_group14(asm_instr *new, u_char *opcode, u_int len, asm_processor *proc) { 
     67  struct s_modrm *modrm = (struct s_modrm *) opcode + 1; 
    6768  new->ptr_instr = opcode; 
    6869  new->len += 1; 
    69   struct s_modrm *modrm = (struct s_modrm *) opcode + 1; 
    7070   
    7171  switch (modrm->r) { 
    7272    case 2: 
  • libelfsh/got.c

    diff -urN ./libelfsh/got.c ../elfsh.mine/libelfsh/got.c
    old new  
    420420 
    421421 
    422422 
    423  
    424 /* 
    425 ** Only used on BeoS  
    426 ** Tested and developed by zadig@myrealbox.com 
    427 ** 
    428 */ 
    429 int   elfsh_get_got_symbol_reloc(elfshobj_t     *file, 
    430                                  uint8          *name, 
    431                                  elfsh_Rel      *rel_entry) 
    432 { 
    433    elfshsect_t *got, *rel_got; 
    434    u_int       index, got_rel_index; 
    435    u_int       entsz; 
    436    int         got_index; 
    437    elfsh_Off   off; 
    438    void         *data; 
    439     
    440    ELFSH_PROFILE_IN(__FILE__, __FUNCTION__, __LINE__); 
    441     
    442    /* Sanity checks */ 
    443    entsz = elfsh_get_pltentsz(file); 
    444    if (entsz < 0) 
    445      ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__, 
    446                        "Invalid PLT entry size", -1); 
    447  
    448   if (NULL == elfsh_get_dynsymtab(file, NULL)) 
    449     ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__, 
    450                       "Unable to get DYNSYM", -1); 
    451  
    452   if (NULL == elfsh_get_symtab(file, NULL)) 
    453     ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__, 
    454                       "Unable to get SYMTAB", -1); 
    455    
    456   /* get got section index */ 
    457   got = elfsh_get_section_by_name(file, 
    458                                   ELFSH_SECTION_NAME_GOT, 
    459                                   &got_index, NULL, NULL); 
    460   if (got == NULL) 
    461     ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__, 
    462                       "Unable to get GOT", -1); 
    463    
    464   /* search the got relocation section */ 
    465   rel_got = NULL; 
    466   for (got_rel_index = 0; got_rel_index < file->hdr->e_shnum; got_rel_index++) 
    467     { 
    468       rel_got = elfsh_get_section_by_index(file, got_rel_index, 
    469                                           NULL, NULL); 
    470     if (rel_got->shdr->sh_info == got_index) 
    471       break; 
    472     } 
    473    
    474   if ((rel_got == NULL) || (rel_got->shdr->sh_info != got_index)) 
    475     ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__, 
    476                       "Unable to get GOT relocations", -1); 
    477    
    478   /* search for the requested symbol */ 
    479   off = entsz; 
    480   data = elfsh_get_raw(rel_got); 
    481   for (index = 0;  
    482        index < (rel_got->shdr->sh_size / rel_got->shdr->sh_entsize);  
    483        off += entsz, index ++) 
    484     { 
    485       elfsh_Rel *cur_rel; 
    486       cur_rel = ((elfsh_Rel*) data) + index; 
    487       if(strcmp(elfsh_get_symname_from_reloc(file, cur_rel), name) == 0) 
    488         { 
    489           *rel_entry = *cur_rel; 
    490           ELFSH_PROFILE_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); 
    491         } 
    492     } 
    493  
    494   ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__, 
    495                     "Symbol not found", -1); 
    496 } 
    497  
    498  
    499  
    500  
  • libelfsh/hooks.c

    diff -urN ./libelfsh/hooks.c ../elfsh.mine/libelfsh/hooks.c
    old new  
    641641                         ELFSH_OS_OPENBSD, elfsh_hijack_plt_ia32); 
    642642  elfsh_register_plthook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
    643643                         ELFSH_OS_SOLARIS, elfsh_hijack_plt_ia32); 
     644  elfsh_register_plthook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
     645                         ELFSH_OS_BEOS, elfsh_hijack_plt_ia32); 
    644646   
    645647  /* Usual PLT targets for ET_EXEC/Sparc32 */ 
    646648  elfsh_register_plthook(ELFSH_ARCH_SPARC32, ELFSH_TYPE_EXEC,  
     
    729731                            ELFSH_OS_OPENBSD, elfsh_void_altplthandler); 
    730732  elfsh_register_altplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
    731733                            ELFSH_OS_SOLARIS, elfsh_void_altplthandler); 
     734  elfsh_register_altplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
     735                            ELFSH_OS_BEOS, elfsh_void_altplthandler); 
    732736   
    733737  /* Usual ALTPLT targets for ET_EXEC/Sparc32 */ 
    734738  elfsh_register_altplthook(ELFSH_ARCH_SPARC32, ELFSH_TYPE_EXEC,  
     
    818822                         ELFSH_OS_OPENBSD, elfsh_relocate_ia32); 
    819823  elfsh_register_relhook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
    820824                         ELFSH_OS_SOLARIS, elfsh_relocate_ia32); 
     825  elfsh_register_relhook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
     826                         ELFSH_OS_BEOS, elfsh_relocate_ia32); 
    821827   
    822828  /* Usual REL targets for ET_EXEC/Sparc32 */ 
    823829  elfsh_register_relhook(ELFSH_ARCH_SPARC32, ELFSH_TYPE_EXEC,  
     
    906912                           ELFSH_OS_OPENBSD, elfsh_cflow_ia32); 
    907913  elfsh_register_cflowhook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
    908914                           ELFSH_OS_SOLARIS, elfsh_cflow_ia32); 
     915  elfsh_register_cflowhook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
     916                           ELFSH_OS_BEOS, elfsh_cflow_ia32); 
    909917 
    910918  /* Usual CFLOW targets for ET_EXEC/IA64 */ 
    911919  elfsh_register_cflowhook(ELFSH_ARCH_IA64, ELFSH_TYPE_EXEC,  
     
    980988                           ELFSH_OS_SOLARIS, elfsh_cflow_mips64); 
    981989  elfsh_register_cflowhook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    982990                           ELFSH_OS_LINUX, elfsh_cflow_ia32); 
     991  elfsh_register_cflowhook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     992                           ELFSH_OS_BEOS, elfsh_cflow_ia32); 
    983993 
    984994  /* Usual REL/PLT/ALTPLT targets for ET_DYN/x86 */ 
    985995  elfsh_register_plthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     
    10431053                               ELFSH_OS_OPENBSD, elfsh_encodeplt_ia32); 
    10441054  elfsh_register_encodeplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
    10451055                               ELFSH_OS_SOLARIS, elfsh_encodeplt_ia32); 
     1056  elfsh_register_encodeplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
     1057                               ELFSH_OS_BEOS, elfsh_encodeplt_ia32); 
    10461058  elfsh_register_encodeplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    10471059                               ELFSH_OS_LINUX, elfsh_encodeplt_ia32); 
    10481060  elfsh_register_encodeplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     
    10531065                               ELFSH_OS_OPENBSD, elfsh_encodeplt_ia32); 
    10541066  elfsh_register_encodeplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    10551067                               ELFSH_OS_SOLARIS, elfsh_encodeplt_ia32); 
     1068  elfsh_register_encodeplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     1069                               ELFSH_OS_BEOS, elfsh_encodeplt_ia32); 
    10561070 
    10571071  /* Usual ENCODEPLT1 targets for ET_EXEC/IA32 */ 
    10581072  elfsh_register_encodeplt1hook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
     
    10651079                                ELFSH_OS_OPENBSD, elfsh_encodeplt1_ia32); 
    10661080  elfsh_register_encodeplt1hook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
    10671081                                ELFSH_OS_SOLARIS, elfsh_encodeplt1_ia32); 
     1082  elfsh_register_encodeplt1hook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
     1083                                ELFSH_OS_BEOS, elfsh_encodeplt1_ia32); 
    10681084  elfsh_register_encodeplt1hook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    10691085                                ELFSH_OS_LINUX, elfsh_encodeplt1_ia32); 
    10701086  elfsh_register_encodeplt1hook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     
    10751091                                ELFSH_OS_OPENBSD, elfsh_encodeplt1_ia32); 
    10761092  elfsh_register_encodeplt1hook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    10771093                                ELFSH_OS_SOLARIS, elfsh_encodeplt1_ia32); 
     1094  elfsh_register_encodeplt1hook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     1095                                ELFSH_OS_BEOS, elfsh_encodeplt1_ia32); 
    10781096 
    10791097  /*** Now EXTPLT handlers ***/ 
    10801098 
     
    10891107                            ELFSH_OS_OPENBSD, elfsh_extplt_ia32); 
    10901108  elfsh_register_extplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
    10911109                            ELFSH_OS_SOLARIS, elfsh_extplt_ia32); 
     1110  elfsh_register_extplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_EXEC,  
     1111                            ELFSH_OS_BEOS, elfsh_extplt_ia32); 
    10921112  elfsh_register_extplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    10931113                            ELFSH_OS_LINUX, elfsh_extplt_ia32); 
    10941114  elfsh_register_extplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     
    10991119                            ELFSH_OS_OPENBSD, elfsh_extplt_ia32); 
    11001120  elfsh_register_extplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
    11011121                            ELFSH_OS_SOLARIS, elfsh_extplt_ia32); 
     1122  elfsh_register_extplthook(ELFSH_ARCH_IA32, ELFSH_TYPE_DYN,  
     1123                            ELFSH_OS_BEOS, elfsh_extplt_ia32); 
    11021124 
    11031125  /***************************************/ 
    11041126  /****** ARGC arguments counting  ******/ 
  • libelfsh/include/libelfsh/libelfsh-internal.h

    diff -urN ./libelfsh/include/libelfsh/libelfsh-internal.h ../elfsh.mine/libelfsh/include/libelfsh/libelfsh-internal.h
    old new  
    1414 #define                ELFSH_ERR_ARRAY         sys_errlist[sys_nerr] 
    1515#endif 
    1616 
     17#ifdef __BEOS__ 
     18/* the internal allocator is not ported yet. For elfsh it should be enough 
     19 * for the moment. The allocator will be ported to enable e2dbg support */ 
     20#define elfsh_calloc    calloc 
     21#define elfsh_realloc   realloc 
     22#define elfsh_malloc    malloc 
     23#define elfsh_valloc    valloc 
     24#define elfsh_memalign  memalign 
     25#define elfsh_free      free 
     26#define __elfsh_libc_malloc_pthread_startup(first_time) 
     27#else 
    1728/* Some calls defined in libmalloc */ 
    1829void            *elfsh_calloc(size_t, char); 
    1930void            *elfsh_realloc(void *, size_t); 
     
    2233void            *elfsh_memalign(size_t t, u_int nbr); 
    2334void            elfsh_free(void *); 
    2435void            __elfsh_libc_malloc_pthread_startup(int first_time); 
     36#endif 
    2537 
    2638/* Safe calloc() */ 
    2739#define         XALLOC(a, b, c)                                                                 \ 
  • libelfsh/include/libelfsh.h

    diff -urN ./libelfsh/include/libelfsh.h ../elfsh.mine/libelfsh/include/libelfsh.h
    old new  
    1818#include <fcntl.h> 
    1919#include <errno.h> 
    2020#include <sys/stat.h> 
     21#ifndef __BEOS__ 
    2122#include <sys/mman.h> 
     23#endif 
    2224 
    2325 
    2426#include "elfsh-libc.h" 
     
    2830#include <libelfsh/libelfsh-compat.h> 
    2931 
    3032#ifdef __BEOS__ 
    31  #include <bsd_mem.h> 
     33#include <inttypes.h> 
     34#include <stdint.h> 
     35#include <bsd_mem.h> 
     36#include <OS.h> 
     37#include <bsd_mem.h> 
    3238#endif 
    3339 
    3440 
     
    865871u_int           elfsh_set_got_val(elfsh_Addr *got, elfsh_Addr val); 
    866872elfsh_Addr      elfsh_get_got_addr(elfsh_Addr *got); 
    867873u_int           elfsh_set_got_addr(elfsh_Addr *got, elfsh_Addr val); 
    868 int             elfsh_get_got_symbol_reloc(elfshobj_t *file, uint8 *name, 
    869                                  elfsh_Rel *rel_entry); 
    870874int             elfsh_endianize_got(elfshsect_t *_new); 
    871875elfshsect_t     *elfsh_get_gotsct(elfshobj_t *file); 
    872876int             elfsh_shift_got(elfshobj_t *file, u_int size); 
  • libelfsh/mips32.c

    diff -urN ./libelfsh/mips32.c ../elfsh.mine/libelfsh/mips32.c
    old new  
    509509                 GP = GP 
    510510              */ 
    511511              *HI16_dword +=  
    512                 VERIFY16((((old_HI16_dword << 16) + (short) A) +                /* AHL */ 
     512                VERIFY16((elfsh_Addr)(((old_HI16_dword << 16) + (short) A) +            /* AHL */ 
    513513                          GP -                                                  /* GP */ 
    514514                          (new->shdr->sh_addr + HI16_cur->r_offset) -           /* P */ 
    515515                          (short) (((old_HI16_dword << 16) + (short) A) +       /* AHL */ 
     
    539539       
    540540      if (ISGPDISP(cur)) 
    541541        { 
    542           *dword = VERIFY16(((old_HI16_dword << 16) + (short) A) + GP + P + 4); 
     542          *dword = VERIFY16(((old_HI16_dword << 16) + (short) A) + (elfsh_Addr)GP + (elfsh_Addr)P + 4); 
    543543          ELFSH_PROFILE_ROUT(__FILE__, __FUNCTION__, __LINE__, (retval)); 
    544544        } 
    545545       
  • libelfsh/plt.c

    diff -urN ./libelfsh/plt.c ../elfsh.mine/libelfsh/plt.c
    old new  
    7979 
    8080  if (sym->st_size != file->secthash[ELFSH_SECTION_PLT]->shdr->sh_size) 
    8181  { 
     82    if ( (file->hdr->e_type == ET_DYN) && (sym->st_value == 0) ) 
     83      ELFSH_PROFILE_ROUT(__FILE__, __FUNCTION__, __LINE__, (1)); 
     84 
    8285    if (INTERVAL(file->secthash[ELFSH_SECTION_PLT]->shdr->sh_addr,  
    8386                 sym->st_value,  
    8487                 file->secthash[ELFSH_SECTION_PLT]->shdr->sh_addr +  
  • libelfsh/runtime.c

    diff -urN ./libelfsh/runtime.c ../elfsh.mine/libelfsh/runtime.c
    old new  
    3333 
    3434  ELFSH_PROFILE_IN(__FILE__, __FUNCTION__, __LINE__); 
    3535 
     36#ifdef __BEOS__ 
     37  if (elfsh_segment_is_readable(segment)) 
     38    prot |= B_READ_AREA; 
     39  if (elfsh_segment_is_writable(segment)) 
     40    prot |= B_WRITE_AREA; 
     41  if (elfsh_segment_is_executable(segment)) 
     42    prot |= B_READ_AREA; 
     43#else 
    3644  if (elfsh_segment_is_readable(segment)) 
    3745    prot |= PROT_READ; 
    3846  if (elfsh_segment_is_writable(segment)) 
    3947    prot |= PROT_WRITE; 
    4048  if (elfsh_segment_is_executable(segment)) 
    4149    prot |= PROT_EXEC; 
     50#endif 
    4251 
    4352#if     __DEBUG_RUNTIME__ 
    4453  printf("[DEBUG_RUNTIME] MMAP: " XFMT " of %d bytes \n", segment->p_vaddr, segment->p_memsz); 
     
    6271                           zero, 0); 
    6372 close(zero); 
    6473} 
     74#elif defined(__BEOS__) 
     75  if(create_area("ElfSh", (void **) &addr, B_ANY_ADDRESS, segment->p_memsz, 
     76           B_NO_LOCK, prot) < 0) 
     77  { 
     78     addr = 0; 
     79  } 
     80 
    6581#else   
    6682  addr = (elfsh_Addr) mmap((void *) 0, segment->p_memsz,  
    6783                           prot, 
     
    92108int             elfsh_runtime_unmap(elfsh_Phdr *segment) 
    93109{ 
    94110  int           ret; 
     111#ifdef __BEOS__ 
     112   area_id  area; 
     113#endif 
    95114 
    96115  ELFSH_PROFILE_IN(__FILE__, __FUNCTION__, __LINE__); 
    97116   
     117#ifdef __BEOS__ 
     118  area = area_for((void*)(segment->p_vaddr)); 
     119  ret = delete_area(area); 
     120#else 
    98121  ret = munmap((void *) segment->p_vaddr, segment->p_memsz); 
     122#endif 
    99123 
    100124  //if (!ret) 
    101125  //memset(segment, 0x00, sizeof(elfsh_Phdr)); 
     
    146170  elfsh_Phdr    *phdr; 
    147171  int           retval; 
    148172  int           prot; 
     173#ifdef __BEOS__ 
     174   area_id  area; 
     175#endif 
    149176 
    150177  ELFSH_PROFILE_IN(__FILE__, __FUNCTION__, __LINE__); 
    151178  if (!elfsh_is_debug_mode()) 
     
    159186  phdr = elfsh_get_parent_segment(file, sect); 
    160187  prot = 0; 
    161188 
     189#ifdef __BEOS__ 
     190  if (elfsh_segment_is_readable(phdr)) 
     191    prot |= B_READ_AREA; 
     192  if (elfsh_segment_is_writable(phdr)) 
     193    prot |= B_WRITE_AREA; 
     194  if (elfsh_segment_is_executable(phdr)) 
     195    prot |= B_READ_AREA; 
     196   
     197  area = area_for((void*)(addr)); 
     198  if(area == B_ERROR) 
     199    ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__,  
     200        "Cannot find area", -1); 
     201 
     202  retval = set_area_protection(area, B_WRITE_AREA | B_READ_AREA); 
     203#else 
    162204  if (elfsh_segment_is_readable(phdr)) 
    163205    prot |= PROT_READ; 
    164206  if (elfsh_segment_is_writable(phdr)) 
     
    168210 
    169211  retval = mprotect((void *) (addr - addr % getpagesize()),  
    170212                    getpagesize(), PROT_READ | PROT_WRITE); 
     213#endif 
    171214 
    172215  if (retval != 0) 
    173216    { 
     
    186229int             elfsh_mprotect(elfsh_Addr addr, uint32_t sz, int prot) 
    187230{ 
    188231  int           retval; 
     232#ifdef __BEOS__ 
     233   area_id  area; 
     234#endif 
    189235 
    190236  ELFSH_PROFILE_IN(__FILE__, __FUNCTION__, __LINE__); 
    191237  if (!elfsh_is_debug_mode()) 
    192238    ELFSH_PROFILE_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); 
    193239 
     240#ifdef __BEOS__ 
     241  area = area_for((void*)(addr)); 
     242  if(area == B_ERROR) 
     243    ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__,  
     244        "Cannot find area", -1); 
     245 
     246  retval = set_area_protection(area, prot); 
     247#else 
    194248  retval = mprotect((void *) addr - addr % getpagesize(),  
    195249                    getpagesize(), prot); 
     250#endif 
    196251 
    197252  if (retval != 0) 
    198253      ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__,  
  • libmalloc/include/malloc-machine.h

    diff -urN ./libmalloc/include/malloc-machine.h ../elfsh.mine/libmalloc/include/malloc-machine.h
    old new  
    2121#ifndef _GENERIC_MALLOC_MACHINE_H 
    2222#define _GENERIC_MALLOC_MACHINE_H 
    2323 
    24 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) 
     24#if defined(__BEOS__) 
     25 #include <SupportDefs.h> 
     26#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) 
    2527 #include <machine/atomic.h> 
    2628#elif !defined(IRIX) 
    2729 #include <asm/atomic.h> 
  • libui/log.c

    diff -urN ./libui/log.c ../elfsh.mine/libui/log.c
    old new  
    6060 
    6161static void             logtofile(char *str) 
    6262{ 
    63    
     63  char *tmp; 
     64    
    6465  elfshpath_t           *stripvar; 
    6566  u_int                 len; 
    6667 
     
    7374    ELFSH_NOPROFILE_OUT(); 
    7475 
    7576  /* We made only local modifications */ 
    76   char tmp[len+1]; 
     77  tmp = (char*)malloc(len+1); 
    7778  strcpy(tmp, str); 
    7879 
    7980  stripvar = hash_get(&vars_hash, ELFSH_SLOGVAR); 
     
    9495  len = strlen(tmp); 
    9596  XWRITE(world.curjob->logfd, tmp, len, ); 
    9697 
     98  free(tmp); 
    9799  ELFSH_NOPROFILE_OUT(); 
    98100} 
    99101 
  • vm/include/elfsh.h

    diff -urN ./vm/include/elfsh.h ../elfsh.mine/vm/include/elfsh.h
    old new  
    984984int             vm_getvarparams(u_int index, u_int argc, char **argv); 
    985985 
    986986/* Libasm resolve handlers */ 
    987 void            asm_do_resolve(void *data, u_int vaddr, char *, u_int); 
     987void            asm_do_resolve(void *data, elfsh_Addr vaddr, char *, u_int); 
    988988char            *vm_resolve(elfshobj_t *file, elfsh_Addr addr, elfsh_SAddr *roff); 
    989989 
    990990/* General VM functions */ 
     
    10231023int             vm_version_unk(u_int ai, u_int i, char *id, char *n, char *t); 
    10241024 
    10251025/* Disassembling and hexadecimal view functions */ 
    1026 u_int           vm_display_instr(int, u_int, u_int, u_int, u_int, 
     1026u_int           vm_display_instr(int, u_int, elfsh_Addr, u_int, u_int, 
    10271027                                 char *, u_int, char *); 
    10281028int             vm_display_section(elfshsect_t *s, char *name, elfshlist_t *re); 
    10291029int             vm_match_sht(elfshobj_t *file, elfshsect_t *l, elfshlist_t *actual); 
  • vm/trace.c

    diff -urN ./vm/trace.c ../elfsh.mine/vm/trace.c
    old new  
    296296  int           osize = strlen(tfname) + 3; 
    297297  char          rsofname[osize]; 
    298298  char          rtfname[osize]; 
     299  char          **selfuncs; 
    299300 
    300301  ELFSH_PROFILE_IN(__FILE__, __FUNCTION__, __LINE__); 
    301302 
     
    318319                      "Cannot init tmp files", (-1)); 
    319320 
    320321  /* Create temporary storage */ 
    321   char          *selfuncs[symnum + dynsymnum + 1]; 
     322  selfuncs = elfsh_malloc(symnum+1 * sizeof(char)); 
    322323 
    323324  for (index = 0; index < symnum + dynsymnum + 1; index++) 
    324325    selfuncs[index] = NULL; 
     
    334335 
    335336  /* If we didn't trace a function, we don't need to continue */ 
    336337  if (!count) 
     338  { 
     339    elfsh_free(selfuncs); 
    337340    ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__,  
    338341                      "No function found", (-1)); 
     342  } 
    339343   
    340344#if __DEBUG_TRACE__ 
    341345  printf("[DEBUG TRACE] RENAME %s to %s\n", tfname, rtfname); 
     
    343347 
    344348  /* Compile the tmp c file to create a relocatable file to inject */ 
    345349  if (rename(tfname, rtfname) < 0) 
     350  { 
     351    elfsh_free(selfuncs); 
    346352    ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__,  
    347353                      "Rename failed", (-1)); 
     354  } 
    348355 
    349356  snprintf(buf, BUFSIZ, "gcc -c %s -o %s", rtfname, rsofname); 
    350357  vm_system(buf); 
     
    352359  /* Load the new relocatable file for ET_REL injection */ 
    353360  tobj = elfsh_map_obj(rsofname); 
    354361  if (!tobj) 
     362  { 
     363    elfsh_free(selfuncs); 
    355364    ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__,  
    356365                      "Failed to load relocatable file", (-1)); 
     366  } 
    357367 
    358368  idx = elfsh_inject_etrel(world.curjob->current, tobj);           
    359369  if (idx < 0) 
     370  { 
     371    elfsh_free(selfuncs); 
    360372    ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__,  
    361373                      "Failed to inject ET_REL with workspace", (-1)); 
     374  } 
    362375 
    363376  /* Hijack functions with the new functions injected */ 
    364377  for (index = 0; index < count; index++) 
     
    382395                                        selfuncs[index],  
    383396                                        addr, NULL); 
    384397    if (err < 0) 
     398    { 
     399      elfsh_free(selfuncs); 
    385400      ELFSH_PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__,  
    386401                        "Failed to hijack a function", (-1)); 
     402    } 
    387403  } 
    388404   
    389405  vm_output("\n [*] Binary ready to be traced. You can now save and run it.\n\n"); 
    390406 
     407  elfsh_free(selfuncs); 
    391408  ELFSH_PROFILE_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); 
    392409} 
    393410