mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-12-03 13:13:30 +01:00
129 lines
2.5 KiB
C
129 lines
2.5 KiB
C
/** @file
|
|
Implements APIs to retrieve general information about PE/COFF Images.
|
|
|
|
Copyright (c) 2020 - 2021, Marvin Häuser. All rights reserved.<BR>
|
|
Copyright (c) 2020, Vitaly Cheptsov. All rights reserved.<BR>
|
|
Copyright (c) 2020, ISP RAS. All rights reserved.<BR>
|
|
|
|
SPDX-License-Identifier: BSD-3-Clause
|
|
**/
|
|
|
|
#include <Base.h>
|
|
#include <Uefi/UefiBaseType.h>
|
|
#include <Uefi/UefiSpec.h>
|
|
|
|
#include <Library/BaseLib.h>
|
|
#include <Library/BaseOverflowLib.h>
|
|
#include <Library/DebugLib.h>
|
|
#include <Library/PcdLib.h>
|
|
#include <Library/PeCoffLib2.h>
|
|
|
|
#include "BasePeCoffLib2Internals.h"
|
|
|
|
UINT32
|
|
PeCoffGetAddressOfEntryPoint (
|
|
IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
|
)
|
|
{
|
|
ASSERT (Context != NULL);
|
|
|
|
return Context->AddressOfEntryPoint;
|
|
}
|
|
|
|
UINT16
|
|
PeCoffGetMachine (
|
|
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
|
)
|
|
{
|
|
ASSERT (Context != NULL);
|
|
|
|
return Context->Machine;
|
|
}
|
|
|
|
UINT16
|
|
PeCoffGetSubsystem (
|
|
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
|
)
|
|
{
|
|
ASSERT (Context != NULL);
|
|
|
|
return Context->Subsystem;
|
|
}
|
|
|
|
UINT32
|
|
PeCoffGetSectionAlignment (
|
|
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
|
)
|
|
{
|
|
ASSERT (Context != NULL);
|
|
|
|
return Context->SectionAlignment;
|
|
}
|
|
|
|
UINT32
|
|
PeCoffGetSizeOfImage (
|
|
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
|
)
|
|
{
|
|
ASSERT (Context != NULL);
|
|
|
|
return Context->SizeOfImage;
|
|
}
|
|
|
|
UINT64
|
|
PeCoffGetImageBase (
|
|
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
|
)
|
|
{
|
|
ASSERT (Context != NULL);
|
|
|
|
return Context->ImageBase;
|
|
}
|
|
|
|
UINT32
|
|
PeCoffGetSizeOfHeaders (
|
|
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
|
)
|
|
{
|
|
ASSERT (Context != NULL);
|
|
|
|
return Context->SizeOfHeaders;
|
|
}
|
|
|
|
UINT16
|
|
PeCoffGetSectionTable (
|
|
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context,
|
|
OUT CONST EFI_IMAGE_SECTION_HEADER **Sections
|
|
)
|
|
{
|
|
ASSERT (Context != NULL);
|
|
ASSERT (Sections != NULL);
|
|
|
|
*Sections = (CONST EFI_IMAGE_SECTION_HEADER *) (CONST VOID *) (
|
|
(CONST CHAR8 *) Context->FileBuffer + Context->SectionsOffset
|
|
);
|
|
return Context->NumberOfSections;
|
|
}
|
|
|
|
BOOLEAN
|
|
PeCoffGetRelocsStripped (
|
|
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
|
)
|
|
{
|
|
ASSERT (Context != NULL);
|
|
|
|
return Context->RelocsStripped;
|
|
}
|
|
|
|
// FIXME: Distinguish between base and buffer (XIP TE)
|
|
UINTN
|
|
PeCoffLoaderGetImageAddress (
|
|
IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
|
)
|
|
{
|
|
ASSERT (Context != NULL);
|
|
ASSERT (Context->ImageBuffer != NULL);
|
|
|
|
return (UINTN) Context->ImageBuffer;
|
|
}
|