1# 2# Copyright (C) 2017 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# This file contains ELF constants and offsets. 18 19# Common ELF header 20MAGIC_OFFSET = 0 21MAGIC_BYTES = b"\x7fELF" 22BITNESS_OFFSET = 4 23BITNESS_32 = 1 24BITNESS_64 = 2 25# Section type 26SHT_DYNAMIC = 6 27# Section index 28SHN_UNDEFINED = 0 29# Tag in dynamic section 30DT_NULL = 0 31DT_NEEDED = 1 32DT_STRTAB = 5 33# Section name 34DYNSYM = ".dynsym" 35DYNSTR = ".dynstr" 36# Type in symbol table 37SYMBOL_NOTYPE = 0 38# Binding in symbol table 39SYMBOL_BINDING_GLOBAL = 1 40SYMBOL_BINDING_WEAK = 2 41 42 43class ElfOffsets32(object): 44 """Offset of each entry in 32-bit ELF""" 45 # Offset from ELF header 46 SECTION_HEADER_OFFSET = 0x20 47 SECTION_HEADER_SIZE = 0x2e 48 SECTION_HEADER_COUNT = 0x30 49 SECTION_HEADER_STRTAB_INDEX = 0x32 50 # Offset from section header 51 SECTION_NAME_OFFSET = 0x00 52 SECTION_TYPE = 0x04 53 SECTION_ADDRESS = 0x0c 54 SECTION_OFFSET = 0x10 55 SECTION_SIZE = 0x14 56 SECTION_ENTRY_SIZE = 0x24 57 # Offset from symbol table entry 58 SYMBOL_NAME = 0x00 59 SYMBOL_INFO = 0x0c 60 SYMBOL_SECTION_INDEX = 0x0e 61 62 63class ElfOffsets64(object): 64 """Offset of each entry in 64-bit ELF""" 65 # Offset from ELF header 66 SECTION_HEADER_OFFSET = 0x28 67 SECTION_HEADER_SIZE = 0x3a 68 SECTION_HEADER_COUNT = 0x3c 69 SECTION_HEADER_STRTAB_INDEX = 0x3e 70 # Offset from section header 71 SECTION_NAME_OFFSET = 0x00 72 SECTION_TYPE = 0x04 73 SECTION_ADDRESS = 0x10 74 SECTION_OFFSET = 0x18 75 SECTION_SIZE = 0x20 76 SECTION_ENTRY_SIZE = 0x38 77 # Offset from symbol table entry 78 SYMBOL_NAME = 0x00 79 SYMBOL_INFO = 0x04 80 SYMBOL_SECTION_INDEX = 0x06 81