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
|
/* libxelf - elf_verify ELF verification routines
*
* by scut / teso
*/
#include <elf.h>
#include <stdlib.h>
#include <string.h>
#include <elf_file.h>
#include <elf_verify.h>
#include <elf_util.h>
int
elf_verify_header (elf_file *elf)
{
unsigned char e_ident[EI_NIDENT] = {
ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, /* FIXED */
ELFCLASS32, ELFDATA2LSB, /* x86 dependant */
EV_CURRENT, /* ELF version dependant */
0, 0, 0, 0, 0, /* ELF version dependant */
0, 0, 0, 0 };
if (memcmp (&elf->Ehdr.e_ident[0], e_ident, EI_NIDENT) != 0) {
elf_error (elf, "Ehdr.e_ident not as expected");
return (1);
}
#if 0
if (elf->Ehdr.e_type != ET_EXEC) {
elf_error (elf, "Ehdr.e_type is not ET_EXEC");
return (1);
}
#endif
if (elf->Ehdr.e_machine != EM_386) {
elf_error (elf, "Ehdr.e_machine is not EM_386");
return (1);
}
if (elf->Ehdr.e_version != EV_CURRENT) {
elf_error (elf, "Ehdr.e_version is not EV_CURRENT");
return (1);
}
#if 0
if (elf->Ehdr.e_phoff == 0 || elf->Ehdr.e_phnum == 0 ||
elf->Ehdr.e_phentsize != sizeof (Elf32_Phdr))
{
elf_error (elf, "Ehdr.e_phoff is zero");
return (1);
}
#endif
return (0);
}
|