summaryrefslogtreecommitdiffstats
path: root/lib/ELFHeader.cpp
blob: 5e21d3e20e51b504903bdfdd9f9695bb1dd37704 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright 2011, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "ELFHeader.h"
#include "ELF.h"

char const *ELFHeaderHelperMixin::getClassStr(int clazz) {
  switch (clazz) {
  default:
#define CASE_PAIR(A, B) case A: return B;
  CASE_PAIR(ELFCLASSNONE, "Invalid class")
  CASE_PAIR(ELFCLASS32, "32bit")
  CASE_PAIR(ELFCLASS64, "64bit")
#undef CASE_PAIR
  }
}

char const *ELFHeaderHelperMixin::getEndiannessStr(int endianness) {
  switch (endianness) {
  default:
#define CASE_PAIR(A, B) case A: return B;
  CASE_PAIR(ELFDATANONE, "Invalid endianness")
  CASE_PAIR(ELFDATA2LSB, "Little endian")
  CASE_PAIR(ELFDATA2MSB, "Big endian")
#undef CASE_PAIR
  }
}

char const *ELFHeaderHelperMixin::getOSABIStr(int abi) {
  if (abi >= 64 && abi <= 255) {
    return "Architecture specific";
  }

  switch (abi) {
  default: return "Unknown OS ABI";
#define CASE_PAIR(A, B) case A: return B;
  CASE_PAIR(ELFOSABI_NONE, "No extensions or not specified")
  CASE_PAIR(ELFOSABI_HPUX, "HP-UX")
  CASE_PAIR(ELFOSABI_NETBSD, "NetBSD")
  CASE_PAIR(ELFOSABI_LINUX, "Linux")
  CASE_PAIR(ELFOSABI_SOLARIS, "Solaris")
  CASE_PAIR(ELFOSABI_AIX, "AIX")
  CASE_PAIR(ELFOSABI_FREEBSD, "FreeBSD")
  CASE_PAIR(ELFOSABI_TRU64, "Tru64")
  CASE_PAIR(ELFOSABI_MODESTO, "Modesto")
  CASE_PAIR(ELFOSABI_OPENBSD, "OpenBSD")
#undef CASE_PAIR
  }
}

char const *ELFHeaderHelperMixin::getObjectTypeStr(uint16_t type) {
  switch (type) {
  default: return "No file type";

  case ET_REL:  return "Relocatable file";
  case ET_EXEC: return "Executable file";
  case ET_DYN:  return "Shared object file";
  case ET_CORE: return "Core file";

  case ET_LOOS: case ET_HIOS:
    return "Operating system-specific";

  case ET_LOPROC: case ET_HIPROC:
    return "Processor-specific";
  }
}

char const *ELFHeaderHelperMixin::getMachineStr(uint16_t machine) {
  switch (machine) {
    default: return "No machine or unknown";
    case EM_386: return "Intel 80386 (X86)";
    case EM_X86_64: return "AMD x86-64 architecture";
    case EM_ARM: return "Advanced RISC Machine (ARM)";
    case EM_MIPS: return "MIPS";
  }
}

char const *ELFHeaderHelperMixin::getVersionStr(uint32_t version) {
  switch (version) {
    default: return "Invalid version";
    case EV_CURRENT: return "Current version";
  }
}