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
|
** Developped by syl
** contact : syl@evilkittens.org, ccna.syl@gmail.com
** THE BEER-WARE LICENSE
**
** syl@evilkittens.org wrote this file. As long as you retain this notice you
** can do whatever you want with this stuff. If we meet some day, and you
** think this stuff is worth it, you can buy me a beer in return.
**
** Sylvestre Gallon
*/
#include <sys/exec_elf.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
const char *archtype[] = {
"No Machine",
"AT&T WE 32100",
"SPARC",
"Intel 80386",
"Motorola 68000",
*/
#include <sys/exec_elf.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
const char *archtype[] = {
"No Machine",
"AT&T WE 32100",
"SPARC",
"Intel 80386",
"Motorola 68000",
"Motorola 88000",
"Intel 80486 - unused?",
"Intel 80860",
"MIPS R3000 Big-Endian only",
"unknow",
"unknow",
"MIPS R4000 Big-Endian",
"SPARC v9 64-bit unoffical"
"",
"",
"",
"HPPA"};
const char *version[] = {
"Invalid",
"Current"
};
const char *filetype[] = {
"No file type",
"relocatable file",
"executable file",
"shared object file",
"core file"
};
int myerror(char *str)
{
perror(str);
exit(EXIT_FAILURE);
}
int elf_search_section(void *mem)
{
Elf32_Ehdr *bin;
Elf32_Shdr *sec;
bin = mem;
printf("file ==> %s\n", filetype[bin->e_type]);
printf("arch ==> %s\n", archtype[bin->e_machine]);
printf("vers ==> %s\n", version[bin->e_version]);
printf("nb section header ==> %i\n", bin->e_shnum);
printf("Section header offset ==> %08x\n", bin->e_shoff);
printf("Section header size ==> %i\n", bin->e_shentsize);
memcpy(sec,mem+bin->e_shoff, bin->e_shentsize);
printf("First Section name ====>%s\n", sec->sh_name);
printf("First Section type ====>%i\n", sec->sh_type);
return (EXIT_SUCCESS);
}
int main(int ac, char **av)
{
int fd;
struct stat s;
void *mem;
if (ac < 2)
myerror("usage: ./bite file");
if ((fd = open(av[1], O_RDONLY)) < 0)
myerror("open error");
if (fstat(fd, &s) < 0)
myerror("stat error");
if ((mem = mmap(NULL, s.st_size, PROT_READ, MAP_FILE, fd, 0)) == MAP_FAILED)
myerror("mmap error");
printf("mmap(%s): %08x\n", av[1], mem);
elf_search_section(mem);
if (munmap(mem, s.st_size) != 0)
myerror("munmap error");
if (close(fd) != 0)
myerror("close error");
return (EXIT_SUCCESS);
} |
Partager