michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include "elf_utils.h" michael@0: michael@0: int michael@0: elf_verify_header(const Elf32_Ehdr *hdr) michael@0: { michael@0: if (hdr->e_ident[EI_MAG0] != ELFMAG0 michael@0: || hdr->e_ident[EI_MAG1] != ELFMAG1 michael@0: || hdr->e_ident[EI_MAG2] != ELFMAG2 michael@0: || hdr->e_ident[EI_MAG3] != ELFMAG3) { michael@0: cerr << "not an elf file" << endl; michael@0: return -1; michael@0: } michael@0: michael@0: if (hdr->e_ident[EI_CLASS] != ELFCLASS32) { michael@0: cerr << "not a 32-bit elf file" << endl; michael@0: return -1; michael@0: } michael@0: michael@0: if (hdr->e_ident[EI_DATA] != ELFDATA2LSB) { michael@0: cerr << "not a little endian elf file" << endl; michael@0: return -1; michael@0: } michael@0: michael@0: if (hdr->e_ident[EI_VERSION] != EV_CURRENT) { michael@0: cerr << "incompatible version" << endl; michael@0: return -1; michael@0: } michael@0: michael@0: return 0; michael@0: } michael@0: