Exemple #1
0
int coreCheck(void* image)
{
	if (!elfCheck(image))
		return -1;
	Elf32_Ehdr *elfHeader = (Elf32_Ehdr*) image;
	if (elfHeader->e_entry < 0xC0000000)
	return -2;

	Elf32_Off address = elfHeader->e_phoff;
	if (address == 0)
		return 0;

	void *programHeader = (void*)(((unsigned long)elfHeader) +
                                                      ((unsigned long)address));
	void *thisHeader = NULL;
	int noHdrs = elfHeader->e_phnum;
	int hdrSize = elfHeader->e_phentsize;
	int i = 0;

	for (thisHeader = programHeader; i < noHdrs; i++)
	{
	Elf32_Phdr* hdr = (Elf32_Phdr*)thisHeader;
	if (*(int*)(hdr->p_offset+(unsigned int) image) == 0xC0DEBABE)
		return 0;
	thisHeader+=hdrSize;
	}
	return 3;
}
Exemple #2
0
/*
 * Run the elf image passed on to this function. Shouldn't return at all
 * but just in case it does, the return types are:
 * 0 for failure
 * 1 for success
 */
int elfExec(void* image)
{
	if (elfCheck(image))
	{
		Elf32_Ehdr *elfHeader = (Elf32_Ehdr*) image;
		Elf32_Off address = elfHeader->e_phoff;
		if (address == 0)
			return 0;

		void *programHeader = (void*)(((unsigned long)elfHeader) +
                                                      ((unsigned long)address));
		void *thisHeader = NULL;
		int noHdrs = elfHeader->e_phnum;
		int hdrSize = elfHeader->e_phentsize;
		int i = 0;
		printf("Program header\n");
		for (thisHeader = programHeader; i < noHdrs; i++)
		{
			Elf32_Phdr* hdr = (Elf32_Phdr*)thisHeader;
			printf("Type:\t0x%X\tOffset:\t0x%X\nvaddr:\t0x%X\tSize:"
							      "\t0x%X\nAlign:\t"
						       "0x%X\tFlags:\t0x%X\n\n",
				       hdr->p_type, hdr->p_offset, hdr->p_vaddr,
				      hdr->p_memsz, hdr->p_align, hdr->p_flags);
			thisHeader+=hdrSize;
		}
#ifdef ELFDBG
		int j;
		for (j = 0; j < 0x1FFFFFFF; j++);
#endif
		Elf32_Off sectionAddress = elfHeader->e_shoff;
		if (address != 0 && FALSE)
		{
			void *sectionHeader = (void*)(((unsigned long)elfHeader)
					     + ((unsigned long)sectionAddress));
			void *thisSection = NULL;
// 			int noSHdrs = elfHeader->e_shnum;
// 			int shdrSize = elfHeader->e_shentsize;
			i = 0;
			printf("Section header\n");
			for (thisSection = sectionHeader; i < noHdrs; i++)
			{
				Elf32_Shdr* hdr = (Elf32_Shdr*)thisSection;
				printf("Type:\t0x%X\tOffset:\t0x%X\nAddr:\t0x%X"
						       "\tSize:\t0x%X\nAlign:\t"
					  "0x%X\tFlags:\t0x%X\nName:\t0x%X\n\n",
				     hdr->sh_type, hdr->sh_offset, hdr->sh_addr,
						 hdr->sh_size, hdr->sh_addralign,
						   hdr->sh_flags, hdr->sh_name);
#ifdef ELFDBG
				for (j = 0; j < 0xfffffff; j++);
#endif
			}
		}
	}
	return 1;
}
Exemple #3
0
/*****************************************************************************
	DISCRIPTION	: ELFロード
	ARGUMENT	: pElfHead	= ELF構造体
	RETURN		: 0			= 正常終了
				: 0以外		= 異常終了
	NOTE		: -
	UPDATED		: 2013-09-03
*****************************************************************************/
char* elfLoad(char* pcBuf)
{
	ELF_HEAD* pElfHead = (ELF_HEAD*)pcBuf;
	int16 iRet;
	if((iRet = elfCheck(pElfHead)) < 0){
		DPUTS((uint08*)"elfCheck() error!! > ");
		DPHEX(iRet, 8, 1);
		DPUTS((uint08*)"\n");
		return NULL;
	}

	if((iRet = elfLoadProgram(pElfHead)) < 0){
		DPUTS((uint08*)"elfLoadProgram() error!!\n");
		DPHEX(iRet, 8, 1);
		DPUTS((uint08*)"\n");
		return NULL;
	}
	return (char*)pElfHead->lEntryPoint;
}