Back to index

php5  5.3.10
elfclass.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) Christos Zoulas 2008.
00003  * All Rights Reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice immediately at the beginning of the file, without modification,
00010  *    this list of conditions, and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  *  
00015  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00016  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00018  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
00019  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00020  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00021  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00023  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00024  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00025  * SUCH DAMAGE.
00026  */
00027        if (nbytes <= sizeof(elfhdr))
00028               return 0;
00029 
00030        u.l = 1;
00031        (void)memcpy(&elfhdr, buf, sizeof elfhdr);
00032        swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
00033 
00034        type = elf_getu16(swap, elfhdr.e_type);
00035        switch (type) {
00036 #ifdef ELFCORE
00037        case ET_CORE:
00038               if (dophn_core(ms, clazz, swap, fd,
00039                   (off_t)elf_getu(swap, elfhdr.e_phoff),
00040                   elf_getu16(swap, elfhdr.e_phnum), 
00041                   (size_t)elf_getu16(swap, elfhdr.e_phentsize),
00042                   fsize, &flags) == -1)
00043                      return -1;
00044               break;
00045 #endif
00046        case ET_EXEC:
00047        case ET_DYN:
00048               if (dophn_exec(ms, clazz, swap, fd,
00049                   (off_t)elf_getu(swap, elfhdr.e_phoff),
00050                   elf_getu16(swap, elfhdr.e_phnum), 
00051                   (size_t)elf_getu16(swap, elfhdr.e_phentsize),
00052                   fsize, &flags, elf_getu16(swap, elfhdr.e_shnum))
00053                   == -1)
00054                      return -1;
00055               /*FALLTHROUGH*/
00056        case ET_REL:
00057               if (doshn(ms, clazz, swap, fd,
00058                   (off_t)elf_getu(swap, elfhdr.e_shoff),
00059                   elf_getu16(swap, elfhdr.e_shnum),
00060                   (size_t)elf_getu16(swap, elfhdr.e_shentsize),
00061                   &flags,
00062                   elf_getu16(swap, elfhdr.e_machine)) == -1)
00063                      return -1;
00064               break;
00065 
00066        default:
00067               break;
00068        }
00069        return 1;