-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.h
193 lines (161 loc) · 3.15 KB
/
types.h
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Copyright 2010 Sven Peter <svenpeter@gmail.com>
// Licensed under the terms of the GNU GPL, version 2
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
#ifndef TYPES_H__
#define TYPES_H__
#include "stdint.h"
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
struct elf_phdr {
u32 p_type;
u64 p_off;
u64 p_vaddr;
u64 p_paddr;
u64 p_filesz;
u64 p_memsz;
u32 p_flags;
u64 p_align;
void *ptr;
};
struct elf_shdr {
u32 sh_name;
u32 sh_type;
u32 sh_flags;
u64 sh_addr;
u64 sh_offset;
u32 sh_size;
u32 sh_link;
u32 sh_info;
u32 sh_addralign;
u32 sh_entsize;
};
#define ET_NONE 0
#define ET_REL 1
#define ET_EXEC 2
#define ET_DYN 3
#define ET_CORE 4
#define ET_LOOS 0xfe00
#define ET_HIOS 0xfeff
#define ET_LOPROC 0xff00
#define ET_HIPROC 0xffff
struct elf_hdr {
char e_ident[16];
u16 e_type;
u16 e_machine;
u32 e_version;
u64 e_entry;
u64 e_phoff;
u64 e_shoff;
u32 e_flags;
u16 e_ehsize;
u16 e_phentsize;
u16 e_phnum;
u16 e_shentsize;
u16 e_shnum;
u16 e_shtrndx;
};
typedef struct {
uint64_t data_offset;
uint64_t data_size;
uint32_t type; // 1 = shdr, 2 == phdr, 3 == unknown
uint32_t program_idx;
uint32_t hashed; //2=yes
uint32_t sha1_idx;
uint32_t encrypted; // 3=yes; 1=no
uint32_t key_idx;
uint32_t iv_idx;
uint32_t compressed; // 2=yes; 1=no
} METADATA_SECTION_HEADER;
static u8 be8(u8 *p)
{
return *p;
}
static u8 le8(u8 *p)
{
return *p;
}
static u16 be16(u8 *p)
{
u16 a;
a = p[0] << 8;
a |= p[1];
return a;
}
static u16 le16(u8 *p)
{
u16 a;
a = p[1] << 8;
a |= p[0];
return a;
}
static u32 be32(u8 *p)
{
u32 a;
a = p[0] << 24;
a |= p[1] << 16;
a |= p[2] << 8;
a |= p[3] << 0;
return a;
}
static u32 le32(u8 *p)
{
u32 a;
a = p[3] << 24;
a |= p[2] << 16;
a |= p[1] << 8;
a |= p[0] << 0;
return a;
}
static u64 be64(u8 *p)
{
u32 a, b;
a = be32(p);
b = be32(p + 4);
return ((u64)a<<32) | b;
}
static u64 le64(u8 *p)
{
u32 a, b;
b = le32(p);
a = le32(p + 4);
return ((u64)a<<32) | b;
}
static void wbe16(u8 *p, u16 v)
{
p[0] = (u8)(v >> 8);
p[1] = (u8)v;
}
static void wle16(u8 *p, u16 v)
{
p[1] = (u8)(v >> 8);
p[0] = (u8)v;
}
static void wbe32(u8 *p, u32 v)
{
p[0] = v >> 24;
p[1] = v >> 16;
p[2] = v >> 8;
p[3] = v;
}
static void wle32(u8 *p, u32 v)
{
p[3] = v >> 24;
p[2] = v >> 16;
p[1] = v >> 8;
p[0] = v;
}
static void wbe64(u8 *p, u64 v)
{
wbe32(p + 4, (u32)v);
v >>= 32;
wbe32(p, (u32)v);
}
static void wle64(u8 *p, u64 v)
{
wbe32(p , (u32)v);
v >>= 32;
wbe32(p+4, (u32)v);
}
#endif