elf/elf.c
elf_file* elf_read_exec(const void* image)
{
	const char* imagep = image;
	elf_file* elf = kmalloc(sizeof(elf_file));
	elf->header = image;
	const elf_header* header = elf->header;
	if(memcmp(header->magic,elf_magic,sizeof(elf_magic))
	   || header->magic[EI_CLASS] != ELFCLASS32
	   || header->magic[EI_DATAENC] != ELFDATA2LSB) {
		
		return NULL;
	}
	if(header->type != ELF_EXEC)
		return NULL;

	elf->program_header = NULL;
	if(header->ph_offset) {
		elf->program_header = (elf_pheader*)
		                      (imagep+header->ph_offset);
	} else return NULL;
	
	return elf;
}
//Arma la estructura de un ELF a partir de un
//buffer de memoria
Arma la estructura de un ELF a partir de un
buffer de memoria
Arma la estructura de un ELF a partir de un buffer de memoria
elf_file* elf_read_exec(const void* image)
{
	const char* imagep = image;
	elf_file* elf = kmalloc(sizeof(elf_file));
	elf->header = image;
	const elf_header* header = elf->header;
	if(memcmp(header->magic,elf_magic,sizeof(elf_magic))
	   || header->magic[EI_CLASS] != ELFCLASS32
	   || header->magic[EI_DATAENC] != ELFDATA2LSB) {
		return NULL;
	}
	if(header->type != ELF_EXEC)
		return NULL;
	elf->program_header = NULL;
	if(header->ph_offset) {
		elf->program_header = (elf_pheader*)
		                      (imagep+header->ph_offset);
	} else return NULL;
	return elf;
}
elf_file * elf_read_exec ( const void * image ) { const char * imagep = image ; elf_file * elf = kmalloc ( sizeof ( elf_file ) ) ; elf -> header = image ; const elf_header * header = elf -> header ; if ( memcmp ( header -> magic , elf_magic , sizeof ( elf_magic ) ) || header -> magic [ EI_CLASS ] != ELFCLASS32 || header -> magic [ EI_DATAENC ] != ELFDATA2LSB ) { return NULL ; } if ( header -> type != ELF_EXEC ) return NULL ; elf -> program_header = NULL ; if ( header -> ph_offset ) { elf -> program_header = ( elf_pheader * ) ( imagep + header -> ph_offset ) ; } else return NULL ; return elf ; }
Arma la estructura de un ELF a partir de un
buffer de memoria
Arma la estructura de un ELF a partir de un buffer de memoria