From 61da4a110758837ccd5b48d569800162f35d6eb1 Mon Sep 17 00:00:00 2001 From: applestash Date: Fri, 29 Aug 2014 21:50:18 +1000 Subject: [PATCH] made text and data ELF regions compulsory --- makerom/elf.c | 9 +++++++-- makerom/elf.h | 9 +++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/makerom/elf.c b/makerom/elf.c index d30db0a..03adee2 100644 --- a/makerom/elf.c +++ b/makerom/elf.c @@ -113,7 +113,8 @@ finish: if(result == NOT_ELF_FILE) fprintf(stderr,"[ELF ERROR] Not ELF File\n"); else if(result == NOT_ARM_ELF) fprintf(stderr,"[ELF ERROR] Not ARM ELF\n"); else if(result == NON_EXECUTABLE_ELF) fprintf(stderr,"[ELF ERROR] Not Executeable ELF\n"); - else if(result == NOT_FIND_CODE_SECTIONS) fprintf(stderr,"[ELF ERROR] Failed to retrieve code sections from ELF\n"); + else if(result == NOT_FIND_TEXT_SEGMENT) fprintf(stderr,"[ELF ERROR] Failed to retrieve text sections from ELF\n"); + else if(result == NOT_FIND_DATA_SEGMENT) fprintf(stderr,"[ELF ERROR] Failed to retrieve data sections from ELF\n"); else fprintf(stderr,"[ELF ERROR] Failed to process ELF file (%d)\n",result); } for(int i = 0; i < elf->activeSegments; i++) @@ -239,9 +240,13 @@ int CreateExeFsCode(elf_context *elf, u8 *elfFile, ncch_settings *set) result = CreateCodeSegmentFromElf(&rwdata,elf,elfFile,set->rsfSet->ExeFs.ReadWrite,set->rsfSet->ExeFs.ReadWriteNum); if(result) return result; + /* Checking the existence of essential ELF Segments */ + if(!text.size) return NOT_FIND_TEXT_SEGMENT; + if(!rwdata.size) return NOT_FIND_DATA_SEGMENT; + /* Allocating Buffer for ExeFs Code */ u32 size = (text.maxPageNum + rodata.maxPageNum + rwdata.maxPageNum)*elf->pageSize; - u8 *code = malloc(size); + u8 *code = calloc(1,size); /* Writing Code into Buffer */ u8 *textPos = (code + 0); diff --git a/makerom/elf.h b/makerom/elf.h index 4ce9121..585af39 100644 --- a/makerom/elf.h +++ b/makerom/elf.h @@ -6,10 +6,11 @@ typedef enum NOT_ARM_ELF = -11, NON_EXECUTABLE_ELF = -12, ELF_SECTION_NOT_FOUND = -13, - NOT_FIND_CODE_SECTIONS = -14, - ELF_SEGMENT_SECTION_SIZE_MISMATCH = -15, - ELF_SEGMENTS_NOT_CONTINUOUS = -16, - ELF_SEGMENTS_NOT_FOUND = -17, + NOT_FIND_TEXT_SEGMENT = -14, + NOT_FIND_DATA_SEGMENT = -15 + ELF_SEGMENT_SECTION_SIZE_MISMATCH = -16, + ELF_SEGMENTS_NOT_CONTINUOUS = -17, + ELF_SEGMENTS_NOT_FOUND = -18, } elf_errors; typedef struct