3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 int buffer_copy (unsigned offset
, char *data
, unsigned size
)
30 memcpy (buffer
+offset
, data
, size
);
40 int buffer_write (char *file
)
42 int fd
= open (file
, O_CREAT
| O_WRONLY
);
45 printf ("error -> file '%s' not found !\n", file
);
49 if (!write (fd
, buffer
, 10240-1)) {
50 printf ("error -> something is wrong !\n");
61 buffer
= (char *) malloc (sizeof (char) * 10240);
68 memset (&elf
, 0, sizeof (elf_file_t
));
70 elf
.magic
= 0x464C457FL
;
78 elf
.phtab_offset
= 0x34;
79 elf
.shtab_offset
= 0x204c;
81 elf
.file_hdr_size
= 0x34;
82 elf
.phtab_ent_size
= 0x20;
83 elf
.num_phtab_ents
= 0x2;
84 elf
.shtab_ent_size
= 0x28;
86 elf
.shstrtab_index
= 0x6;
90 memset (§
, 0, sizeof (elf_sect_t
));
100 sect
.align
= 0x65041580;
103 buffer_copy (0, (void *) &elf
, sizeof (elf_file_t
));
104 buffer_copy (sizeof (elf_file_t
), (void *) §
, sizeof (elf_sect_t
));
108 unsigned s
= elf
.shtab_ent_size
; // section size
111 memset (§
, 0, sizeof (elf_sect_t
));
112 buffer_copy (elf
.shtab_offset
, (void *) §
, sizeof (elf_sect_t
));
115 sect
.sect_name
= 0x0b;
118 sect
.virt_adr
= 0x801000;
119 sect
.offset
= 0x1000;
125 buffer_copy (elf
.shtab_offset
+s
, (void *) §
, sizeof (elf_sect_t
));
128 sect
.sect_name
= 0x11;
131 sect
.virt_adr
= 0x802000;
132 sect
.offset
= 0x1000;
138 buffer_copy (elf
.shtab_offset
+s
*2, (void *) §
, sizeof (elf_sect_t
));
140 /* s = 3 - .rodata */
141 sect
.sect_name
= 0x17;
144 sect
.virt_adr
= 0x802000;
145 sect
.offset
= 0x2000;
151 buffer_copy (elf
.shtab_offset
+s
*3, (void *) §
, sizeof (elf_sect_t
));
154 sect
.sect_name
= 0x1f;
157 sect
.virt_adr
= 0x802c00;
164 buffer_copy (elf
.shtab_offset
+s
*4, (void *) §
, sizeof (elf_sect_t
));
166 /* s = 5 - .comment */
167 sect
.sect_name
= 0x24;
170 sect
.virt_adr
= 0x803000;
171 sect
.offset
= 0x2000;
177 buffer_copy (elf
.shtab_offset
+s
*5, (void *) §
, sizeof (elf_sect_t
));
179 /* s = 6 - .shstrtab */
180 sect
.sect_name
= 0x1;
184 sect
.offset
= 0x201c0000;
190 buffer_copy (elf
.shtab_offset
+s
*6, (void *) §
, sizeof (elf_sect_t
));