95 lines
1.9 KiB
C
95 lines
1.9 KiB
C
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "futil.c"
|
|
#include "elf_header.h"
|
|
|
|
// typedef enum ELFType{
|
|
// ET_None = 0, //No file type
|
|
// ET_Rel = 1, //Relocatable file
|
|
// ET_Exec = 2, //Executable file
|
|
// ET_Dyn = 3, //Shared object file
|
|
// ET_Core = 4, //Core file
|
|
// ET_LOProc = 0xff00, //Processor
|
|
// ET_HIProc = 0xffff //Specific
|
|
// } ELFType;
|
|
|
|
// typedef enum ELFMachine
|
|
// {
|
|
// EM_None = 0,
|
|
// EM_M32 = 1, //AT&T WE 32100
|
|
// EM_Sparc = 2,
|
|
// EM_386 = 3,
|
|
// EM_68k = 4,
|
|
// EM_88k = 5,
|
|
// EM_860 = 7,
|
|
// EM_MIPS = 8,
|
|
// EM_X86_64 = 62
|
|
// } ELFMachine;
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
char* bytes;
|
|
size_t size;
|
|
|
|
if (argc != 2)
|
|
{
|
|
printf("No argcs\n");
|
|
return 0;
|
|
}
|
|
|
|
if (!ReadAllString(argv[1], &bytes, &size)) return 0;
|
|
|
|
ParseObjectFile(bytes, size);
|
|
|
|
// printf("Type: ");
|
|
|
|
// switch(bytes[EI_NIDENT] + bytes[EI_NIDENT + 1])
|
|
// {
|
|
// case ET_None:
|
|
// printf("None\n");
|
|
// break;
|
|
// case ET_Rel:
|
|
// printf("Rel\n");
|
|
// break;
|
|
// case ET_Exec:
|
|
// printf("Exec\n");
|
|
// break;
|
|
// case ET_Dyn:
|
|
// printf("DYN (Position-Independent Executable file)\n");
|
|
// break;
|
|
// case ET_Core:
|
|
// printf("Core\n");
|
|
// break;
|
|
// case ET_LOProc:
|
|
// printf("LO\n");
|
|
// break;
|
|
// case ET_HIProc:
|
|
// printf("HI\n");
|
|
// break;
|
|
// default:
|
|
// fprintf(stderr, "Unknown file type\n");
|
|
// return 1;
|
|
// }
|
|
|
|
// printf("Machine: ");
|
|
|
|
// switch (bytes[EI_NIDENT + 2] + bytes[EI_NIDENT + 3]) {
|
|
// case EM_860:
|
|
// printf("Intel 80860\n");
|
|
// break;
|
|
// case EM_X86_64:
|
|
// printf("AMD x86-64 architecture\n");
|
|
// break;
|
|
// default:
|
|
// fprintf(stderr, "Failed to identify machine type\n");
|
|
// return 1;
|
|
// }
|
|
|
|
// printf("Version: %#04x\n", bytes[EI_NIDENT + 4] + bytes[EI_NIDENT + 5]);
|
|
|
|
// printf("Entry point address: %#06lX\n", entryAddress);
|
|
|
|
printf("Read %ld bytes from file '%s'\n", size, argv[1]);
|
|
} |