Ya I should have thought of that before.
Any way Im now going to try again, but still get no result.
So to read the PE file after I get the header of it, I need to:
Allocate using either BS->AllocatePool or AllocatePages the right amount of size.
So I'm doing right now this:
Code: Select all
UINT64 LoadStartAddress = NtHeader->OptionalHeader.ImageBase;
UINTN NumPages = NtHeader->OptionalHeader.SizeOfTheImage / EFI_PAGE_SIZE;
BS->AllocatePages(AllocateAddress, EfiLoaderData, NumPages, &LoadedStartAddress);
And than i get a memory pointer like this:
Code: Select all
UINT64 MemPointer = LoadStartAddress;
Than I need to copy the section into memory, and right now I'm doing:
Code: Select all
Shdrs = (EFI_IMAGE_SECTION_HEADER*)(((char*)OptionalHeader) + NTHeader->FileHeader.SizeOfOptionalHeader);
for(INT i = 0; i < NtHeader->FileHeader.NumberOfSection; i++)
{
CopyMem(MemPointer + Shdrs[i].VirtualAddress, MemPtr + Shdr[i].PointerData, Shdrs[i].SizeOfRawData);
}
Than later on when I have to call the entry point I'm doing:
Code: Select all
PLOADER_EFI_BLOCK LoadedBlock = AllocateZeroPool(sizeof(PLOADER_EFI_BLOCK));
typedef VOID (_stdcall *KernelEntryPoint)(PLOADER_EFI_BLOCK LoadedBlock);
KernelEntryPoint EntryPoint = (MemPointer + NtHeader->OptionalHeader.AddressOfEntryPoint);
(*Entry)(BootInfo);
So there have to be somethingh wrong as as soon as I call the (*Entry)(BootInfo) the vm crash.
I have no idea where to go!