Table of Contents

Class PEFileBuilder<TContext>

Namespace
AsmResolver.PE.Builder
Assembly
AsmResolver.PE.dll

Provides a base for a PE file builder.

public abstract class PEFileBuilder<TContext> : IPEFileBuilder where TContext : PEFileBuilderContext

Type Parameters

TContext

The type that this builder uses to store intermediate values in.

Inheritance
PEFileBuilder<TContext>
Implements
Derived
Inherited Members

Methods

AssignDataDirectories(TContext, PEFile)

Creates the data directory headers stored in the optional header of the PE file.

protected abstract void AssignDataDirectories(TContext context, PEFile outputFile)

Parameters

context TContext

The object containing the intermediate values used during the PE file construction.

outputFile PEFile

The (incomplete) PE file that contains the sections.

ComputeFileHeaderFields(TContext, PEFile)

Updates the fields in the file header of the PE file.

protected virtual void ComputeFileHeaderFields(TContext context, PEFile outputFile)

Parameters

context TContext

The object containing the intermediate values used during the PE file construction.

outputFile PEFile

The (incomplete) PE file to update.

ComputeHeaderFields(TContext, PEFile)

Updates the fields in the file header and optional header of the PE file.

protected virtual void ComputeHeaderFields(TContext context, PEFile outputFile)

Parameters

context TContext

The object containing the intermediate values used during the PE file construction.

outputFile PEFile

The (incomplete) PE file to update.

ComputeOptionalHeaderFields(TContext, PEFile)

Updates the fields in the optional header of the PE file.

protected virtual void ComputeOptionalHeaderFields(TContext context, PEFile outputFile)

Parameters

context TContext

The object containing the intermediate values used during the PE file construction.

outputFile PEFile

The (incomplete) PE file to update.

CreateContext(PEImage)

Creates a new context for temporary storage of intermediate values during the construction of a PE image.

protected abstract TContext CreateContext(PEImage image)

Parameters

image PEImage

The image to build.

Returns

TContext

The context.

CreateDataDirectoryBuffers(TContext)

Populates all buffers with data from the input image.

protected virtual void CreateDataDirectoryBuffers(TContext context)

Parameters

context TContext

The builder context.

CreateDebugDirectory(TContext)

Populates the debug directory buffer.

protected virtual void CreateDebugDirectory(TContext context)

Parameters

context TContext

The builder context.

CreateExportDirectory(TContext)

Populates the exports directory buffer.

protected virtual void CreateExportDirectory(TContext context)

Parameters

context TContext

The builder context.

CreateFile(PEImage)

Assembles a new PE file based on a PE image.

public virtual PEFile CreateFile(PEImage image)

Parameters

image PEImage

The image to assemble.

Returns

PEFile

The assembled PE file.

CreateImportDirectory(TContext)

Populates the import directory buffer.

protected virtual void CreateImportDirectory(TContext context)

Parameters

context TContext

The builder context.

CreateRelocationsDirectory(TContext)

Populates the base relocations directory buffer.

protected virtual void CreateRelocationsDirectory(TContext context)

Parameters

context TContext

The builder context.

CreateResourcesDirectory(TContext)

Populates the resources directory buffer.

protected virtual void CreateResourcesDirectory(TContext context)

Parameters

context TContext

The builder context.

CreateSections(TContext)

Creates the sections of the PE image.

protected abstract IEnumerable<PESection> CreateSections(TContext context)

Parameters

context TContext

The object containing the intermediate values used during the PE file construction.

Returns

IEnumerable<PESection>

The sections.

GetEntryPointAddress(TContext, PEFile)

Gets the relative virtual address (RVA) to the entry point of the PE file.

protected abstract uint GetEntryPointAddress(TContext context, PEFile outputFile)

Parameters

context TContext

The object containing the intermediate values used during the PE file construction.

outputFile PEFile

The (incomplete) PE file.

Returns

uint

The relative virtual address to the entry point.

GetFileAlignment(TContext, PEFile)

Gets the file alignment for the new PE file.

protected virtual uint GetFileAlignment(TContext context, PEFile outputFile)

Parameters

context TContext

The object containing the intermediate values used during the PE file construction.

outputFile PEFile

The (incomplete) PE file.

Returns

uint

The file alignment. This should be a power of 2 between 512 and 64,000.

GetImageBase(TContext, PEFile)

Gets the image base for the new PE file.

protected virtual ulong GetImageBase(TContext context, PEFile outputFile)

Parameters

context TContext

The object containing the intermediate values used during the PE file construction.

outputFile PEFile

The (incomplete) PE file.

Returns

ulong

The image base.

GetSectionAlignment(TContext, PEFile)

Gets the section alignment for the new PE file.

protected virtual uint GetSectionAlignment(TContext context, PEFile outputFile)

Parameters

context TContext

The object containing the intermediate values used during the PE file construction.

outputFile PEFile

The (incomplete) PE file.

Returns

uint

The section alignment. Must be greater or equal to the file alignment. Default is the page size for the architecture.