X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fbin%2Fpe.c;h=0e7d1acde47c8a47ef9badec9fa4637b0e2d364e;hb=c4af47e284ab94dc5e365b02f7d91e43f7880280;hp=aa83ac9f3397971200612a0e58226e36fa8f5aa3;hpb=d95ad83dd0bfb3a8f6919f93ce5ead77a5905421;p=tpg%2Facess2.git diff --git a/Kernel/bin/pe.c b/Kernel/bin/pe.c index aa83ac9f..0e7d1acd 100644 --- a/Kernel/bin/pe.c +++ b/Kernel/bin/pe.c @@ -13,11 +13,11 @@ tBinary *PE_Load(int fp); tBinary *MZ_Open(int fp); int PE_Relocate(void *Base); - int PE_GetSymbol(void *Base, char *Name, Uint *Ret); + int PE_GetSymbol(void *Base, const char *Name, Uint *Ret); // === GLOBALS === MODULE_DEFINE(0, 0x0032, BinPE, PE_Install, NULL, NULL); -char *gsPE_DefaultInterpreter = "/Acess/Libs/ld-acess.so"; +const char *gsPE_DefaultInterpreter = "/Acess/Libs/ld-acess.so"; tBinaryType gPE_Loader = { NULL, ('M'|('Z'<<8)), 0xFFFF, // 'MZ' @@ -29,7 +29,7 @@ tBinaryType gPE_Loader = { int PE_Install(char **Arguments) { Binary_RegisterType(&gPE_Loader); - return 1; + return MODULE_ERR_OK; } /** @@ -37,8 +37,8 @@ int PE_Install(char **Arguments) */ tBinary *PE_Load(int FP) { - int count, i, j, k; - int iPageCount; + int count, i, j; + int iSectCount; tBinary *ret; tPE_DOS_HEADER dosHdr; tPE_IMAGE_HEADERS peHeaders; @@ -83,7 +83,7 @@ tBinary *PE_Load(int FP) VFS_Read(FP, count, peSections); // Count Pages - iPageCount = 1; // 1st page is headers + iSectCount = 1; // 1st page is headers for( i = 0; i < peHeaders.FileHeader.SectionCount; i++ ) { // Check if the section is loadable @@ -91,30 +91,32 @@ tBinary *PE_Load(int FP) if(peSections[i].RVA + peHeaders.OptHeader.ImageBase == 0) continue; // Moar pages - iPageCount += (peSections[i].VirtualSize + 0xFFF) >> 12; + iSectCount ++; } - LOG("%i Pages", iPageCount); + LOG("%i Sections", iSectCount); // Initialise Executable Information - ret = malloc(sizeof(tBinary) + sizeof(tBinaryPage)*iPageCount); + ret = malloc(sizeof(tBinary) + sizeof(tBinarySection)*iSectCount); ret->Entry = peHeaders.OptHeader.EntryPoint + peHeaders.OptHeader.ImageBase; ret->Base = peHeaders.OptHeader.ImageBase; ret->Interpreter = gsPE_DefaultInterpreter; - ret->NumPages = iPageCount; + ret->NumSections = iSectCount; LOG("Entry=%p, BaseAddress=0x%x\n", ret->Entry, ret->Base); - ret->Pages[0].Virtual = peHeaders.OptHeader.ImageBase; - ret->Pages[0].Physical = 0; - ret->Pages[0].Size = 4096; - ret->Pages[0].Flags = 0; + ret->LoadSections[0].Virtual = peHeaders.OptHeader.ImageBase; + ret->LoadSections[0].Offset = 0; + ret->LoadSections[0].FileSize = 4096; + ret->LoadSections[0].MemSize = 4096; + ret->LoadSections[0].Flags = 0; // Parse Sections j = 1; // Page Index for( i = 0; i < peHeaders.FileHeader.SectionCount; i++ ) { + tBinarySection *sect = &ret->LoadSections[j]; iVA = peSections[i].RVA + peHeaders.OptHeader.ImageBase; // Skip non-loadable sections @@ -127,34 +129,16 @@ tBinary *PE_Load(int FP) // Create Flags iFlags = 0; if(peSections[i].Flags & PE_SECTION_FLAG_MEM_EXECUTE) - iFlags |= BIN_PAGEFLAG_EXEC; + iFlags |= BIN_SECTFLAG_EXEC; if( !(peSections[i].Flags & PE_SECTION_FLAG_MEM_WRITE) ) - iFlags |= BIN_PAGEFLAG_RO; + iFlags |= BIN_SECTFLAG_RO; - // Create Page Listing - count = (peSections[i].RawSize + 0xFFF) >> 12; - for(k=0;kPages[j+k].Virtual = iVA + (k<<12); - ret->Pages[j+k].Physical = peSections[i].RawOffs + (k<<12); // Store the offset in the physical address - if(k == count-1 && (peSections[i].RawSize & 0xFFF)) - ret->Pages[j+k].Size = peSections[i].RawSize & 0xFFF; // Byte count in page - else - ret->Pages[j+k].Size = 4096; - ret->Pages[j+k].Flags = iFlags; - } - count = (peSections[i].VirtualSize + 0xFFF) >> 12; - for(;kPages[j+k].Virtual = iVA + (k<<12); - ret->Pages[j+k].Physical = -1; // -1 = Fill with zeros - if(k == count-1 && (peSections[i].VirtualSize & 0xFFF)) - ret->Pages[j+k].Size = peSections[i].VirtualSize & 0xFFF; // Byte count in page - else - ret->Pages[j+k].Size = 4096; - ret->Pages[j+k].Flags = iFlags; - } - j += count; + sect->Virtual = iVA; + sect->Offset = peSections[i].RawOffs; + sect->FileSize = peSections[i].RawSize; + sect->MemSize = peSections[i].VirtualSize; + sect->Flags = iFlags; + j ++; LOG("%i Name:'%s', RVA: 0x%x, Size: 0x%x (0x%x), Ofs: 0x%x, Flags: 0x%x", i, namebuf, @@ -198,6 +182,7 @@ int PE_Relocate(void *Base) ENTER("pBase", Base); dosHdr = Base; peHeaders = (void*)( iBase + dosHdr->PeHdrOffs ); + LOG("Prefered Base %p", peHeaders->OptHeader.ImageBase); peSections = (void*)( iBase + sizeof(tPE_IMAGE_HEADERS) ); directory = (void*)(peSections[0].RVA + iBase); @@ -230,7 +215,7 @@ int PE_Relocate(void *Base) return 0; } -int PE_GetSymbol(void *Base, char *Name, Uint *Ret) +int PE_GetSymbol(void *Base, const char *Name, Uint *Ret) { return 0; }