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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
use libc::{
    c_char, c_int, c_long, c_uint, c_ulong, c_void, gid_t, mode_t, size_t, time_t, uid_t,
    Elf32_Chdr, Elf32_Ehdr, Elf32_Off, Elf32_Phdr, Elf32_Shdr, Elf64_Chdr, Elf64_Ehdr, Elf64_Off,
    Elf64_Phdr, Elf64_Shdr,
};

c_enum! {
    Elf_Type {
        ELF_T_BYTE = 0,
        ELF_T_ADDR = 1,
        ELF_T_DYN = 2,
        ELF_T_EHDR = 3,
        ELF_T_HALF = 4,
        ELF_T_OFF = 5,
        ELF_T_PHDR = 6,
        ELF_T_RELA = 7,
        ELF_T_REL = 8,
        ELF_T_SHDR = 9,
        ELF_T_SWORD = 10,
        ELF_T_SYM = 11,
        ELF_T_WORD = 12,
        ELF_T_XWORD = 13,
        ELF_T_SXWORD = 14,
        ELF_T_VDEF = 15,
        ELF_T_VDAUX = 16,
        ELF_T_VNEED = 17,
        ELF_T_VNAUX = 18,
        ELF_T_NHDR = 19,
        ELF_T_SYMINFO = 20,
        ELF_T_MOVE = 21,
        ELF_T_LIB = 22,
        ELF_T_GNUHASH = 23,
        ELF_T_AUXV = 24,
        ELF_T_CHDR = 25,
    }
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct Elf_Data {
    pub d_buf: *mut c_void,
    pub d_type: Elf_Type,
    pub d_version: c_uint,
    pub d_size: size_t,
    pub d_off: i64,
    pub d_align: size_t,
}

c_enum! {
    Elf_Cmd {
        ELF_C_NULL = 0,
        ELF_C_READ = 1,
        ELF_C_RDWR = 2,
        ELF_C_WRITE = 3,
        ELF_C_CLR = 4,
        ELF_C_SET = 5,
        ELF_C_FDDONE = 6,
        ELF_C_FDREAD = 7,
        ELF_C_READ_MMAP = 8,
        ELF_C_RDWR_MMAP = 9,
        ELF_C_WRITE_MMAP = 10,
        ELF_C_READ_MMAP_PRIVATE = 11,
        ELF_C_EMPTY = 12,
    }
}

pub const ELF_F_DIRTY: c_uint = 0x1;
pub const ELF_F_LAYOUT: c_uint = 0x4;
pub const ELF_F_PERMISSIVE: c_uint = 0x8;

pub const ELF_CHF_FORCE: c_uint = 0x1;

c_enum! {
    Elf_Kind {
        ELF_K_NONE = 0,
        ELF_K_AR = 1,
        ELF_K_COFF = 2,
        ELF_K_ELF = 3,
    }
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct Elf_Arhdr {
    pub ar_name: *mut c_char,
    pub ar_date: time_t,
    pub ar_uid: uid_t,
    pub ar_gid: gid_t,
    pub ar_mode: mode_t,
    pub ar_size: i64,
    pub ar_rawname: *mut c_char,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct Elf_Arsym {
    pub as_name: *mut c_char,
    pub as_off: size_t,
    pub as_hash: c_ulong,
}

pub enum Elf {}

pub enum Elf_Scn {}

extern "C" {
    pub fn elf_begin(__fildes: c_int, __cmd: Elf_Cmd, __ref: *mut Elf) -> *mut Elf;

    pub fn elf_clone(__elf: *mut Elf, __cmd: Elf_Cmd) -> *mut Elf;

    pub fn elf_memory(__image: *mut c_char, __size: size_t) -> *mut Elf;

    pub fn elf_next(__elf: *mut Elf) -> Elf_Cmd;

    pub fn elf_end(__elf: *mut Elf) -> c_int;

    pub fn elf_update(__elf: *mut Elf, __cmd: Elf_Cmd) -> i64;

    pub fn elf_kind(__elf: *mut Elf) -> Elf_Kind;

    pub fn elf_getbase(__elf: *mut Elf) -> i64;

    pub fn elf_getident(__elf: *mut Elf, __nbytes: *mut size_t) -> *mut c_char;

    pub fn elf32_getehdr(__elf: *mut Elf) -> *mut Elf32_Ehdr;

    pub fn elf64_getehdr(__elf: *mut Elf) -> *mut Elf64_Ehdr;

    pub fn elf32_newehdr(__elf: *mut Elf) -> *mut Elf32_Ehdr;

    pub fn elf64_newehdr(__elf: *mut Elf) -> *mut Elf64_Ehdr;

    pub fn elf_getphdrnum(__elf: *mut Elf, __dst: *mut size_t) -> c_int;

    pub fn elf32_getphdr(__elf: *mut Elf) -> *mut Elf32_Phdr;

    pub fn elf64_getphdr(__elf: *mut Elf) -> *mut Elf64_Phdr;

    pub fn elf32_newphdr(__elf: *mut Elf, __cnt: size_t) -> *mut Elf32_Phdr;

    pub fn elf64_newphdr(__elf: *mut Elf, __cnt: size_t) -> *mut Elf64_Phdr;

    pub fn elf_getscn(__elf: *mut Elf, __index: size_t) -> *mut Elf_Scn;

    pub fn elf32_offscn(__elf: *mut Elf, __offset: Elf32_Off) -> *mut Elf_Scn;

    pub fn elf64_offscn(__elf: *mut Elf, __offset: Elf64_Off) -> *mut Elf_Scn;

    pub fn elf_ndxscn(__scn: *mut Elf_Scn) -> size_t;

    pub fn elf_nextscn(__elf: *mut Elf, __scn: *mut Elf_Scn) -> *mut Elf_Scn;

    pub fn elf_newscn(__elf: *mut Elf) -> *mut Elf_Scn;

    pub fn elf_scnshndx(__scn: *mut Elf_Scn) -> c_int;

    pub fn elf_getshdrnum(__elf: *mut Elf, __dst: *mut size_t) -> c_int;

    pub fn elf_getshdrstrndx(__elf: *mut Elf, __dst: *mut size_t) -> c_int;

    pub fn elf32_getshdr(__scn: *mut Elf_Scn) -> *mut Elf32_Shdr;

    pub fn elf64_getshdr(__scn: *mut Elf_Scn) -> *mut Elf64_Shdr;

    pub fn elf32_getchdr(__scn: *mut Elf_Scn) -> *mut Elf32_Chdr;

    pub fn elf64_getchdr(__scn: *mut Elf_Scn) -> *mut Elf64_Chdr;

    pub fn elf_compress(scn: *mut Elf_Scn, type_: c_int, flags: c_uint) -> c_int;

    pub fn elf_flagelf(__elf: *mut Elf, __cmd: Elf_Cmd, __flags: c_uint) -> c_uint;

    pub fn elf_flagehdr(__elf: *mut Elf, __cmd: Elf_Cmd, __flags: c_uint) -> c_uint;

    pub fn elf_flagphdr(__elf: *mut Elf, __cmd: Elf_Cmd, __flags: c_uint) -> c_uint;

    pub fn elf_flagscn(__scn: *mut Elf_Scn, __cmd: Elf_Cmd, __flags: c_uint) -> c_uint;

    pub fn elf_flagdata(__data: *mut Elf_Data, __cmd: Elf_Cmd, __flags: c_uint) -> c_uint;

    pub fn elf_flagshdr(__scn: *mut Elf_Scn, __cmd: Elf_Cmd, __flags: c_uint) -> c_uint;

    pub fn elf_getdata(__scn: *mut Elf_Scn, __data: *mut Elf_Data) -> *mut Elf_Data;

    pub fn elf_rawdata(__scn: *mut Elf_Scn, __data: *mut Elf_Data) -> *mut Elf_Data;

    pub fn elf_newdata(__scn: *mut Elf_Scn) -> *mut Elf_Data;

    pub fn elf_getdata_rawchunk(
        __elf: *mut Elf,
        __offset: i64,
        __size: size_t,
        __type: Elf_Type,
    ) -> *mut Elf_Data;

    pub fn elf_getarhdr(__elf: *mut Elf) -> *mut Elf_Arhdr;

    pub fn elf_getaroff(__elf: *mut Elf) -> i64;

    pub fn elf_rand(__elf: *mut Elf, __offset: size_t) -> size_t;

    pub fn elf_getarsym(__elf: *mut Elf, __narsyms: *mut size_t) -> *mut Elf_Arsym;

    pub fn elf_cntl(__elf: *mut Elf, __cmd: Elf_Cmd) -> c_int;

    pub fn elf_rawfile(__elf: *mut Elf, __nbytes: *mut size_t) -> *mut c_char;

    pub fn elf32_fsize(__type: Elf_Type, __count: size_t, __version: c_uint) -> size_t;

    pub fn elf64_fsize(__type: Elf_Type, __count: size_t, __version: c_uint) -> size_t;

    pub fn elf32_xlatetom(
        __dest: *mut Elf_Data,
        __src: *const Elf_Data,
        __encode: c_uint,
    ) -> *mut Elf_Data;

    pub fn elf64_xlatetom(
        __dest: *mut Elf_Data,
        __src: *const Elf_Data,
        __encode: c_uint,
    ) -> *mut Elf_Data;

    pub fn elf32_xlatetof(
        __dest: *mut Elf_Data,
        __src: *const Elf_Data,
        __encode: c_uint,
    ) -> *mut Elf_Data;

    pub fn elf64_xlatetof(
        __dest: *mut Elf_Data,
        __src: *const Elf_Data,
        __encode: c_uint,
    ) -> *mut Elf_Data;

    pub fn elf_errno() -> c_int;

    pub fn elf_errmsg(__error: c_int) -> *const c_char;

    pub fn elf_version(__version: c_uint) -> c_uint;

    pub fn elf_fill(__fill: c_int);

    pub fn elf_hash(__string: *const c_char) -> c_ulong;

    pub fn elf_gnu_hash(__string: *const c_char) -> c_ulong;

    pub fn elf32_checksum(__elf: *mut Elf) -> c_long;

    pub fn elf64_checksum(__elf: *mut Elf) -> c_long;
}