ee94ee pe_read_dos_header(): integrate runtime little endian test.

Authored and Committed by midipix 8 years ago
    pe_read_dos_header(): integrate runtime little endian test.
    
        
file modified
+28 -28
src/reader/pe_read_dos_header.c CHANGED
@@ -4,10 +4,10 @@
4
4
/* Released under GPLv2 and GPLv3; see COPYING.PERK. */
5
5
/***************************************************************/
6
6
7
- #include <endian.h>
8
7
#include <string.h>
9
8
10
9
#include <perk/perk.h>
10
+ #include "perk_endian_impl.h"
11
11
#include "perk_reader_impl.h"
12
12
13
13
int pe_read_dos_header(const struct pe_image_dos_hdr * p, struct pe_meta_image_dos_hdr * m)
@@ -15,44 +15,44 @@ int pe_read_dos_header(const struct pe_image_dos_hdr * p, struct pe_meta_image_d
15
15
if ((p->dos_magic[0] != 'M') || (p->dos_magic[1] != 'Z'))
16
16
return PERK_BAD_DOS_HEADER;
17
17
18
- #if (BYTE_ORDER == LITTLE_ENDIAN)
18
+ if (PERK_LITTLE_ENDIAN) {
19
19
20
- memcpy(m,p,sizeof(*p));
20
+ memcpy(m,p,sizeof(*p));
21
21
22
- #else
22
+ } else {
23
23
24
- int i;
24
+ int i;
25
25
26
- m->dos_magic[0] = p->dos_magic[0];
27
- m->dos_magic[1] = p->dos_magic[1];
26
+ m->dos_magic[0] = p->dos_magic[0];
27
+ m->dos_magic[1] = p->dos_magic[1];
28
28
29
- m->dos_cblp = pe_read_short(p->dos_cblp);
30
- m->dos_cp = pe_read_short(p->dos_cp);
31
- m->dos_crlc = pe_read_short(p->dos_crlc);
32
- m->dos_cparhdr = pe_read_short(p->dos_cparhdr);
33
- m->dos_minalloc = pe_read_short(p->dos_minalloc);
34
- m->dos_maxalloc = pe_read_short(p->dos_maxalloc);
35
- m->dos_ss = pe_read_short(p->dos_ss);
36
- m->dos_sp = pe_read_short(p->dos_sp);
37
- m->dos_csum = pe_read_short(p->dos_csum);
38
- m->dos_ip = pe_read_short(p->dos_ip);
39
- m->dos_cs = pe_read_short(p->dos_cs);
40
- m->dos_lfarlc = pe_read_short(p->dos_lfarlc);
41
- m->dos_ovno = pe_read_short(p->dos_ovno);
29
+ m->dos_cblp = pe_read_short(p->dos_cblp);
30
+ m->dos_cp = pe_read_short(p->dos_cp);
31
+ m->dos_crlc = pe_read_short(p->dos_crlc);
32
+ m->dos_cparhdr = pe_read_short(p->dos_cparhdr);
33
+ m->dos_minalloc = pe_read_short(p->dos_minalloc);
34
+ m->dos_maxalloc = pe_read_short(p->dos_maxalloc);
35
+ m->dos_ss = pe_read_short(p->dos_ss);
36
+ m->dos_sp = pe_read_short(p->dos_sp);
37
+ m->dos_csum = pe_read_short(p->dos_csum);
38
+ m->dos_ip = pe_read_short(p->dos_ip);
39
+ m->dos_cs = pe_read_short(p->dos_cs);
40
+ m->dos_lfarlc = pe_read_short(p->dos_lfarlc);
41
+ m->dos_ovno = pe_read_short(p->dos_ovno);
42
42
43
43
44
- for (i=0; i<4; i++)
45
- m->dos_res[i] = pe_read_short(&p->dos_res[2*i]);
44
+ for (i=0; i<4; i++)
45
+ m->dos_res[i] = pe_read_short(&p->dos_res[2*i]);
46
46
47
- m->dos_oemid = pe_read_short(p->dos_oemid);
48
- m->dos_oeminfo = pe_read_short(p->dos_oeminfo);
47
+ m->dos_oemid = pe_read_short(p->dos_oemid);
48
+ m->dos_oeminfo = pe_read_short(p->dos_oeminfo);
49
49
50
- for (i=0; i<10; i++)
51
- m->dos_res2[i] = pe_read_short(&p->dos_res2[2*i]);
50
+ for (i=0; i<10; i++)
51
+ m->dos_res2[i] = pe_read_short(&p->dos_res2[2*i]);
52
52
53
- m->dos_lfanew = pe_read_long(p->dos_lfanew);
53
+ m->dos_lfanew = pe_read_long(p->dos_lfanew);
54
54
55
- #endif
55
+ }
56
56
57
57
return 0;
58
58
}