Added the skeleton for the machine types.
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
gcc -o main.o elf_header.c main.c elf_osabi.c -g -Wall -DDEBUG -Wpedantic -Wextra -Wunused-result -std=c99 -pedantic-errors
|
||||
gcc -o main.o elf_header.c main.c elf_osabi.c elf_machine_type.c -g -Wall -DDEBUG -Wpedantic -Wextra -Wunused-result -std=c99 -pedantic-errors
|
||||
./main.o "$1"
|
||||
|
||||
+9
-3
@@ -1,5 +1,6 @@
|
||||
#include "elf_header.h"
|
||||
#include "elf_osabi.h"
|
||||
#include "elf_machine_type.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -19,8 +20,8 @@ typedef enum EIdent
|
||||
EI_CLASS = 4,
|
||||
EI_DATA = 5,
|
||||
EI_HEADER_VERSION = 6,
|
||||
EI_OSABI = 7,
|
||||
EI_ABIVERSION = 8,
|
||||
EI_OSABI = ELF_OSABI_IDENT_INDEX,
|
||||
EI_ABIVERSION = ELF_OSABI_VERSION_IDENT_INDEX,
|
||||
EI_PAD = 9,
|
||||
EI_NIDENT = ELF_IDENTITIFCATION_MAX_SIZE - 1, //End of reserved 16 bytes for the header.
|
||||
EI_TYPE = EI_NIDENT + 1,
|
||||
@@ -87,12 +88,17 @@ struct elf_header* ParseObjectFile(const char* bytes, size_t count) {
|
||||
if (bytes[EI_HEADER_VERSION] == 1) printf("ELF File Version: Current (1)\n");
|
||||
else printf("ELF File Version: Invalid (%d)\n", bytes[EI_HEADER_VERSION]);
|
||||
|
||||
char buffer[255];
|
||||
char buffer[256];
|
||||
|
||||
GetELFOSABIString(bytes[EI_OSABI], buffer);
|
||||
|
||||
printf("OS ABI: %s\n", buffer);
|
||||
|
||||
GetELFMachineTypeText(bytes[EI_MACHINE], buffer);
|
||||
|
||||
printf("Machine type: %s\n", buffer);
|
||||
printf("Machine: %d\n", bytes[EI_MACHINE]);
|
||||
|
||||
// int64_t entryAddress;
|
||||
|
||||
// memcpy(&entryAddress, &bytes[EI_ENTRY_ADDRESS_POINT], sizeof(int64_t));
|
||||
|
||||
@@ -21,17 +21,4 @@ typedef enum ELFType{
|
||||
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;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "elf_machine_type.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char* ELF_MACHINE_TYPE_TEXT[] = {
|
||||
"No ISA Set",
|
||||
"\x00\x01""AT&T WE 32100",
|
||||
"\x00\x3E""Advanced Micro Devices x86_64"
|
||||
};
|
||||
|
||||
void GetELFMachineTypeText(ELFMachine type, char buffer[256]) {
|
||||
if (!buffer) return;
|
||||
|
||||
memset(buffer, '\0', 256);
|
||||
|
||||
if (type == 0) {
|
||||
strncpy(buffer, ELF_MACHINE_TYPE_TEXT[0], strlen(ELF_MACHINE_TYPE_TEXT[0]));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for(unsigned int i = 1; i < sizeof(ELF_MACHINE_TYPE_TEXT) / sizeof(char*); i++) {
|
||||
char* text = ELF_MACHINE_TYPE_TEXT[i];
|
||||
|
||||
if (type == (unsigned int) text[0] + text[1]) {
|
||||
strncpy(buffer, &text[2], strlen(&text[2]));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef ELF_MACHINE_TYPES_H
|
||||
#define ELF_MACHINE_TYPES_H
|
||||
|
||||
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 = 0x3E
|
||||
} ELFMachine;
|
||||
|
||||
void GetELFMachineTypeText(ELFMachine type, char buffer[256]);
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#include "elf_osabi.h"
|
||||
#include <string.h>
|
||||
|
||||
char* ELFOSABISText[19] =
|
||||
char* ELFOSABISText[] =
|
||||
{
|
||||
"System V ABI",
|
||||
"Hewlett-Packard HP-UX ABI",
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef ELF_OSABI_H
|
||||
#define ELF_OSABI_H
|
||||
|
||||
#define ELF_OSABI_IDENT_INDEX 0x07
|
||||
#define ELF_OSABI_VERSION_IDENT_INDEX 0x08
|
||||
|
||||
typedef enum ELFOSABI
|
||||
{
|
||||
ELFOSABI_SYSTEMV = 0,
|
||||
|
||||
Reference in New Issue
Block a user