*/\r
tBinary *PE_Load(int FP)\r
{\r
- int count, i, j, k;\r
- int iPageCount;\r
+ int count, i, j;\r
+ int iSectCount;\r
tBinary *ret;\r
tPE_DOS_HEADER dosHdr;\r
tPE_IMAGE_HEADERS peHeaders;\r
VFS_Read(FP, count, peSections);\r
\r
// Count Pages\r
- iPageCount = 1; // 1st page is headers\r
+ iSectCount = 1; // 1st page is headers\r
for( i = 0; i < peHeaders.FileHeader.SectionCount; i++ )\r
{\r
// Check if the section is loadable\r
if(peSections[i].RVA + peHeaders.OptHeader.ImageBase == 0) continue;\r
\r
// Moar pages\r
- iPageCount += (peSections[i].VirtualSize + 0xFFF) >> 12;\r
+ iSectCount ++;\r
}\r
\r
- LOG("%i Pages", iPageCount);\r
+ LOG("%i Sections", iSectCount);\r
\r
// Initialise Executable Information\r
- ret = malloc(sizeof(tBinary) + sizeof(tBinaryPage)*iPageCount);\r
+ ret = malloc(sizeof(tBinary) + sizeof(tBinarySection)*iSectCount);\r
\r
ret->Entry = peHeaders.OptHeader.EntryPoint + peHeaders.OptHeader.ImageBase;\r
ret->Base = peHeaders.OptHeader.ImageBase;\r
ret->Interpreter = gsPE_DefaultInterpreter;\r
- ret->NumPages = iPageCount;\r
+ ret->NumSections = iSectCount;\r
\r
LOG("Entry=%p, BaseAddress=0x%x\n", ret->Entry, ret->Base);\r
\r
- ret->Pages[0].Virtual = peHeaders.OptHeader.ImageBase;\r
- ret->Pages[0].Physical = 0;\r
- ret->Pages[0].Size = 4096;\r
- ret->Pages[0].Flags = 0;\r
+ ret->LoadSections[0].Virtual = peHeaders.OptHeader.ImageBase;\r
+ ret->LoadSections[0].Offset = 0;\r
+ ret->LoadSections[0].FileSize = 4096;\r
+ ret->LoadSections[0].MemSize = 4096;\r
+ ret->LoadSections[0].Flags = 0;\r
\r
// Parse Sections\r
j = 1; // Page Index\r
for( i = 0; i < peHeaders.FileHeader.SectionCount; i++ )\r
{\r
+ tBinarySection *sect = &ret->LoadSections[j];\r
iVA = peSections[i].RVA + peHeaders.OptHeader.ImageBase;\r
\r
// Skip non-loadable sections\r
// Create Flags\r
iFlags = 0;\r
if(peSections[i].Flags & PE_SECTION_FLAG_MEM_EXECUTE)\r
- iFlags |= BIN_PAGEFLAG_EXEC;\r
+ iFlags |= BIN_SECTFLAG_EXEC;\r
if( !(peSections[i].Flags & PE_SECTION_FLAG_MEM_WRITE) )\r
- iFlags |= BIN_PAGEFLAG_RO;\r
+ iFlags |= BIN_SECTFLAG_RO;\r
\r
- // Create Page Listing\r
- count = (peSections[i].RawSize + 0xFFF) >> 12;\r
- for(k=0;k<count;k++)\r
- {\r
- ret->Pages[j+k].Virtual = iVA + (k<<12);\r
- ret->Pages[j+k].Physical = peSections[i].RawOffs + (k<<12); // Store the offset in the physical address\r
- if(k == count-1 && (peSections[i].RawSize & 0xFFF))\r
- ret->Pages[j+k].Size = peSections[i].RawSize & 0xFFF; // Byte count in page\r
- else\r
- ret->Pages[j+k].Size = 4096;\r
- ret->Pages[j+k].Flags = iFlags;\r
- }\r
- count = (peSections[i].VirtualSize + 0xFFF) >> 12;\r
- for(;k<count;k++)\r
- {\r
- ret->Pages[j+k].Virtual = iVA + (k<<12);\r
- ret->Pages[j+k].Physical = -1; // -1 = Fill with zeros\r
- if(k == count-1 && (peSections[i].VirtualSize & 0xFFF))\r
- ret->Pages[j+k].Size = peSections[i].VirtualSize & 0xFFF; // Byte count in page\r
- else\r
- ret->Pages[j+k].Size = 4096;\r
- ret->Pages[j+k].Flags = iFlags;\r
- }\r
- j += count;\r
+ sect->Virtual = iVA;\r
+ sect->Offset = peSections[i].RawOffs;\r
+ sect->FileSize = peSections[i].RawSize;\r
+ sect->MemSize = peSections[i].VirtualSize;\r
+ sect->Flags = iFlags;\r
+ j ++;\r
\r
LOG("%i Name:'%s', RVA: 0x%x, Size: 0x%x (0x%x), Ofs: 0x%x, Flags: 0x%x",\r
i, namebuf, \r