123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- /*++
- Copyright (c) 2014 Minoca Corp. All Rights Reserved
- Module Name:
- elfconv.h
- Abstract:
- This header contains internal definitions for the ELF conversion program.
- Author:
- Evan Green 7-Mar-2014
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include "peimage.h"
- #include "elfimage.h"
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // Set this flag to print additional information.
- //
- #define ELFCONV_OPTION_VERBOSE 0x00000001
- //
- // Define the name of the HII .rsrc section.
- //
- #define ELFCONV_HII_SECTION_NAME ".hii"
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- typedef enum _ELFCONV_SECTION_FILTER {
- ElfconvSectionInvalid,
- ElfconvSectionText,
- ElfconvSectionData,
- ElfconvSectionHii,
- ElfconvSectionStabs,
- } ELFCONV_SECTION_FILTER, *PELFCONV_SECTION_FILTER;
- /*++
- Structure Description:
- This structure defines the application context information for the ElfConv
- utility.
- Members:
- Flags - Stores a bitfield of flags. See ELFCONV_OPTION_* definition.
- OutputName - Stores the name of the output image.
- InputName - Stores the name of the input image.
- SubsystemType - Stores the desired subsystem type.
- CoffSectionsOffset - Stores the COFF section offset buffer.
- CoffOffset - Stores the current offset in the COFF file.
- NtHeaderOffset - Stores the offset of the NT header in the COFF file.
- TableOffset - Stores the offset of the section table in the COFF file.
- TextOffset - Stores the offset of the text section in the COFF file.
- DataOffset - Stores the offset of the data section in the COFF file.
- HiiRsrcOffset - Stores the offset of the .rsrc HII section in the COFF file.
- RelocationOffset - Stores the offset of the relocation information in the
- COFF file.
- CoffFile - Store the COFF output file buffer.
- Timestamp - Stores the image timestamp.
- CoffBaseRelocation - Stores a pointer to the first relocation entry for the
- current relocation page.
- CoffNextRelocation - Stores a pointer to the next available relocation
- entry.
- StringTable - Stores a pointer to the string table, needed for sections
- that are larger than 8 characters.
- StringTableSize - Stores the size of the string table in bytes.
- --*/
- typedef struct _ELFCONV_CONTEXT {
- UINT32 Flags;
- CHAR8 *OutputName;
- CHAR8 *InputName;
- CHAR8 SubsystemType;
- VOID *InputFile;
- UINT32 InputFileSize;
- UINT32 *CoffSectionsOffset;
- UINT32 CoffOffset;
- UINT32 NtHeaderOffset;
- UINT32 TableOffset;
- UINT32 TextOffset;
- UINT32 DataOffset;
- UINT32 HiiRsrcOffset;
- UINT32 RelocationOffset;
- UINT8 *CoffFile;
- UINT32 ImageTimestamp;
- EFI_IMAGE_BASE_RELOCATION *CoffBaseRelocation;
- UINT16 *CoffNextRelocation;
- CHAR8 *StringTable;
- UINT32 StringTableSize;
- } ELFCONV_CONTEXT, *PELFCONV_CONTEXT;
- typedef
- BOOLEAN
- (*PELFCONV_SCAN_SECTIONS) (
- PELFCONV_CONTEXT Context
- );
- /*++
- Routine Description:
- This routine scans the ELF sections in preparation for conversion.
- Arguments:
- Context - Supplies a pointer to the conversion context.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- typedef
- BOOLEAN
- (*PELFCONV_WRITE_SECTIONS) (
- PELFCONV_CONTEXT Context,
- ELFCONV_SECTION_FILTER FilterType
- );
- /*++
- Routine Description:
- This routine writes ELF sections to the PE image buffer.
- Arguments:
- Context - Supplies a pointer to the conversion context.
- FilterType - Supplies the section filter to apply.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- typedef
- BOOLEAN
- (*PELFCONV_WRITE_RELOCATIONS) (
- PELFCONV_CONTEXT Context
- );
- /*++
- Routine Description:
- This routine writes the relocation section for the new PE image.
- Arguments:
- Context - Supplies a pointer to the conversion context.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- typedef
- BOOLEAN
- (*PELFCONV_WRITE_DEBUG) (
- PELFCONV_CONTEXT Context
- );
- /*++
- Routine Description:
- This routine writes debug sections into the new PE image.
- Arguments:
- Context - Supplies a pointer to the conversion context.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- typedef
- VOID
- (*PELFCONV_SET_IMAGE_SIZE) (
- PELFCONV_CONTEXT Context
- );
- /*++
- Routine Description:
- This routine sets the final PE image size.
- Arguments:
- Context - Supplies a pointer to the conversion context.
- Return Value:
- None.
- --*/
- typedef
- VOID
- (*PELFCONV_CLEAN_UP) (
- PELFCONV_CONTEXT Context
- );
- /*++
- Routine Description:
- This routine finalizes the new PE image and performs clean-up actions.
- Arguments:
- Context - Supplies a pointer to the conversion context.
- Return Value:
- None.
- --*/
- /*++
- Structure Description:
- This structure defines the function table for converting an ELF image to
- a PE image.
- Members:
- ScanSections - Stores a pointer to a function used to scan the ELF image
- sections.
- WriteSections - Stores a pointer to a function used to write the PE
- image sections.
- WriteRelocations - Stores a pointer to a function used to write the
- relocation information into the PE image.
- WriteDebug - Stores a pointer to a function used to write debug information
- into the PE image.
- SetImageSize - Stores a pointer to a function used to set the final image
- size.
- CleanUp - Stores a pointer to a function called to clean up the
- conversion state and finalize the PE image.
- --*/
- typedef struct _ELFCONV_FUNCTION_TABLE {
- PELFCONV_SCAN_SECTIONS ScanSections;
- PELFCONV_WRITE_SECTIONS WriteSections;
- PELFCONV_WRITE_RELOCATIONS WriteRelocations;
- PELFCONV_WRITE_DEBUG WriteDebug;
- PELFCONV_SET_IMAGE_SIZE SetImageSize;
- PELFCONV_CLEAN_UP CleanUp;
- } ELFCONV_FUNCTION_TABLE, *PELFCONV_FUNCTION_TABLE;
- //
- // -------------------------------------------------------------------- Globals
- //
- extern CHAR8 *ElfconvDebugSections[];
- //
- // -------------------------------------------------------- Function Prototypes
- //
- //
- // Common ELF functions
- //
- VOID
- ElfconvSetHiiResourceHeader (
- UINT8 *HiiBinData,
- UINT32 OffsetToFile
- );
- /*++
- Routine Description:
- This routine sets up the HII resource data in the destination image.
- Arguments:
- HiiBinData - Supplies a pointer to the raw resource data.
- OffsetToFile - Supplies the offset within the file where the data is going
- to reside.
- Return Value:
- None.
- --*/
- VOID
- ElfconvCreateSectionHeader (
- PELFCONV_CONTEXT Context,
- CHAR8 *Name,
- UINT32 Offset,
- UINT32 Size,
- UINT32 Flags
- );
- /*++
- Routine Description:
- This routine initializes a PE section header in the output file buffer.
- Arguments:
- Context - Supplies a pointer to the conversion context.
- Name - Supplies a pointer to a string containing the name of the section.
- Offset - Supplies the file offset to the start of the section.
- Size - Supplies the size of the section in bytes.
- Flags - Supplies the section flags.
- Return Value:
- None.
- --*/
- BOOLEAN
- ElfconvCoffAddFixup (
- PELFCONV_CONTEXT Context,
- UINT32 Offset,
- UINT8 Type
- );
- /*++
- Routine Description:
- This routine adds a COFF relocation to the destination image buffer.
- Arguments:
- Context - Supplies a pointer to the conversion context.
- Offset - Supplies the file offset to the relocation.
- Type - Supplies the relocation type.
- Return Value:
- TRUE on success.
- FALSE on allocation failure.
- --*/
- VOID
- ElfconvCoffAddFixupEntry (
- PELFCONV_CONTEXT Context,
- UINT16 Value
- );
- /*++
- Routine Description:
- This routine adds a relocation entry to the current COFF location.
- Arguments:
- Context - Supplies a pointer to the application context.
- Value - Supplies the relocation value to add.
- Return Value:
- None.
- --*/
- //
- // 32-bit ELF functions
- //
- BOOLEAN
- ElfconvInitializeElf32 (
- PELFCONV_CONTEXT Context,
- PELFCONV_FUNCTION_TABLE FunctionTable
- );
- /*++
- Routine Description:
- This routine attempts to bind an ELF conversion context to an ELF32 image.
- Arguments:
- Context - Supplies a pointer to the ELF context.
- FunctionTable - Supplies a pointer to the ELF conversion functions on
- success.
- Return Value:
- TRUE on success.
- FALSE if the image is not a valid ELF32 image.
- --*/
|