Home | History | Annotate | Download | only in lib
      1 /*
      2  * Copyright 2011, The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "ELFHeader.h"
     18 #include "ELF.h"
     19 
     20 char const *ELFHeaderHelperMixin::getClassStr(int clazz) {
     21   switch (clazz) {
     22   default:
     23 #define CASE_PAIR(A, B) case A: return B;
     24   CASE_PAIR(ELFCLASSNONE, "Invalid class")
     25   CASE_PAIR(ELFCLASS32, "32bit")
     26   CASE_PAIR(ELFCLASS64, "64bit")
     27 #undef CASE_PAIR
     28   }
     29 }
     30 
     31 char const *ELFHeaderHelperMixin::getEndiannessStr(int endianness) {
     32   switch (endianness) {
     33   default:
     34 #define CASE_PAIR(A, B) case A: return B;
     35   CASE_PAIR(ELFDATANONE, "Invalid endianness")
     36   CASE_PAIR(ELFDATA2LSB, "Little endian")
     37   CASE_PAIR(ELFDATA2MSB, "Big endian")
     38 #undef CASE_PAIR
     39   }
     40 }
     41 
     42 char const *ELFHeaderHelperMixin::getOSABIStr(int abi) {
     43   if (abi >= 64 && abi <= 255) {
     44     return "Architecture specific";
     45   }
     46 
     47   switch (abi) {
     48   default: return "Unknown OS ABI";
     49 #define CASE_PAIR(A, B) case A: return B;
     50   CASE_PAIR(ELFOSABI_NONE, "No extensions or not specified")
     51   CASE_PAIR(ELFOSABI_HPUX, "HP-UX")
     52   CASE_PAIR(ELFOSABI_NETBSD, "NetBSD")
     53   CASE_PAIR(ELFOSABI_LINUX, "Linux")
     54   CASE_PAIR(ELFOSABI_SOLARIS, "Solaris")
     55   CASE_PAIR(ELFOSABI_AIX, "AIX")
     56   CASE_PAIR(ELFOSABI_FREEBSD, "FreeBSD")
     57   CASE_PAIR(ELFOSABI_TRU64, "Tru64")
     58   CASE_PAIR(ELFOSABI_MODESTO, "Modesto")
     59   CASE_PAIR(ELFOSABI_OPENBSD, "OpenBSD")
     60 #undef CASE_PAIR
     61   }
     62 }
     63 
     64 char const *ELFHeaderHelperMixin::getObjectTypeStr(uint16_t type) {
     65   switch (type) {
     66   default: return "No file type";
     67 
     68   case ET_REL:  return "Relocatable file";
     69   case ET_EXEC: return "Executable file";
     70   case ET_DYN:  return "Shared object file";
     71   case ET_CORE: return "Core file";
     72 
     73   case ET_LOOS: case ET_HIOS:
     74     return "Operating system-specific";
     75 
     76   case ET_LOPROC: case ET_HIPROC:
     77     return "Processor-specific";
     78   }
     79 }
     80 
     81 char const *ELFHeaderHelperMixin::getMachineStr(uint16_t machine) {
     82   switch (machine) {
     83     default: return "No machine or unknown";
     84     case EM_386: return "Intel 80386 (X86)";
     85     case EM_X86_64: return "AMD x86-64 architecture";
     86     case EM_ARM: return "Advanced RISC Machine (ARM)";
     87     case EM_MIPS: return "MIPS";
     88   }
     89 }
     90 
     91 char const *ELFHeaderHelperMixin::getVersionStr(uint32_t version) {
     92   switch (version) {
     93     default: return "Invalid version";
     94     case EV_CURRENT: return "Current version";
     95   }
     96 }
     97