elf_object.cc (2665:a124942bacb8) | elf_object.cc (2976:371224501196) |
---|---|
1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 139 unchanged lines hidden (view full) --- 148 opSys = ObjectFile::Solaris; 149 if (!strcmp(".stab.index", elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name))) 150 opSys = ObjectFile::Solaris; 151 152 section = elf_getscn(elf, ++secIdx); 153 } // while sections 154 } 155 | 1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 139 unchanged lines hidden (view full) --- 148 opSys = ObjectFile::Solaris; 149 if (!strcmp(".stab.index", elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name))) 150 opSys = ObjectFile::Solaris; 151 152 section = elf_getscn(elf, ++secIdx); 153 } // while sections 154 } 155 |
156 ElfObject * result = new ElfObject(fname, fd, len, data, arch, opSys); 157 158 //The number of headers in the file 159 result->_programHeaderCount = ehdr.e_phnum; 160 //Record the size of each entry 161 result->_programHeaderSize = ehdr.e_phentsize; 162 if(result->_programHeaderCount) //If there is a program header table 163 { 164 //Figure out the virtual address of the header table in the 165 //final memory image. We use the program headers themselves 166 //to translate from a file offset to the address in the image. 167 GElf_Phdr phdr; 168 uint64_t e_phoff = ehdr.e_phoff; 169 result->_programHeaderTable = 0; 170 for(int hdrnum = 0; hdrnum < result->_programHeaderCount; hdrnum++) 171 { 172 gelf_getphdr(elf, hdrnum, &phdr); 173 //Check if we've found the segment with the headers in it 174 if(phdr.p_offset <= e_phoff && 175 phdr.p_offset + phdr.p_filesz > e_phoff) 176 { 177 result->_programHeaderTable = phdr.p_vaddr + e_phoff; 178 break; 179 } 180 } 181 } 182 else 183 result->_programHeaderTable = 0; 184 185 |
|
156 elf_end(elf); | 186 elf_end(elf); |
157 return new ElfObject(fname, fd, len, data, arch, opSys); | 187 return result; |
158 } 159} 160 161 162ElfObject::ElfObject(const string &_filename, int _fd, 163 size_t _len, uint8_t *_data, 164 Arch _arch, OpSys _opSys) 165 : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys) --- 147 unchanged lines hidden --- | 188 } 189} 190 191 192ElfObject::ElfObject(const string &_filename, int _fd, 193 size_t _len, uint8_t *_data, 194 Arch _arch, OpSys _opSys) 195 : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys) --- 147 unchanged lines hidden --- |