1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/reorder/elf_utils.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,36 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include <fstream> 1.9 +#include "elf_utils.h" 1.10 + 1.11 +int 1.12 +elf_verify_header(const Elf32_Ehdr *hdr) 1.13 +{ 1.14 + if (hdr->e_ident[EI_MAG0] != ELFMAG0 1.15 + || hdr->e_ident[EI_MAG1] != ELFMAG1 1.16 + || hdr->e_ident[EI_MAG2] != ELFMAG2 1.17 + || hdr->e_ident[EI_MAG3] != ELFMAG3) { 1.18 + cerr << "not an elf file" << endl; 1.19 + return -1; 1.20 + } 1.21 + 1.22 + if (hdr->e_ident[EI_CLASS] != ELFCLASS32) { 1.23 + cerr << "not a 32-bit elf file" << endl; 1.24 + return -1; 1.25 + } 1.26 + 1.27 + if (hdr->e_ident[EI_DATA] != ELFDATA2LSB) { 1.28 + cerr << "not a little endian elf file" << endl; 1.29 + return -1; 1.30 + } 1.31 + 1.32 + if (hdr->e_ident[EI_VERSION] != EV_CURRENT) { 1.33 + cerr << "incompatible version" << endl; 1.34 + return -1; 1.35 + } 1.36 + 1.37 + return 0; 1.38 +} 1.39 +