C# Class PERWAPI.PEFile

Base class for the PEFile (starting point)
Inheritance: Module
Show file Open project: xored/f4 Class Usage Examples

Public Methods

Method Description
AddExternalManagedResource ( ManifestResource mr, bool isPublic ) : void

Add a managed resource from another assembly.

AddExternalManagedResource ( string resName, AssemblyRef assem, bool isPublic ) : void

Add a managed resource from another assembly.

AddExternalManagedResource ( string resName, ModuleRef mod, uint offset, bool isPublic ) : void

Add a managed resource from another module in this assembly.

AddExternalManagedResource ( string resName, ResourceFile resFile, uint offset, bool isPublic ) : void

Add a managed resource from another file in this assembly.

AddManagedResource ( string resName, byte resBytes, bool isPublic ) : void

Add a managed resource to this PEFile. The resource will be embedded in this PE file.

AddUnmanagedResources ( string resFilename ) : void

Add a manifest resource to this PEFile

GetElement ( uint token ) : MetaDataElement

Get a Meta Data Element from this PE file

GetFileName ( ) : string
GetImportedAssemblies ( ) : AssemblyRef[]
GetNamesOfImports ( ) : string[]
GetNetVersion ( ) : NetVersion

Get the version of .NET for this PE file

GetNetVersionString ( ) : string

Get the .NET version for this PE file

GetResource ( string name ) : ManifestResource

Find a resource

GetResources ( ) : PERWAPI.ManifestResource[]
GetThisAssembly ( ) : Assembly

Get the descriptor for this assembly. The PEFile must have been created with hasAssembly = true

MakeDebuggable ( bool allowDebug, bool suppressOpt ) : void

Makes the assembly debuggable by attaching the DebuggableAttribute to the Assembly. Call immediately before calling WritePEFile.

MakeExternAssembly ( string assemName ) : AssemblyRef

Make a descriptor for an external assembly to this PEFile (.assembly extern)

MakeExternModule ( string name ) : ModuleRef

Make a descriptor for an external module to this PEFile (.module extern)

PEFile ( string fileName ) : System

Create a new PE File with the name "fileName". If "fileName" ends in ".dll" then the file is a dll, otherwise it is an exe file. This PE File has no assembly.

PEFile ( string fileName, string assemblyName ) : System

Create a new PE File with the name "fileName". If "fileName" ends in ".dll" then the file is a dll, otherwise it is an exe file. This file has an Assembly called "assemblyName".

ReadExportedInterface ( string filename ) : ReferenceScope

Read an existing PE File and return the exported interface (ie. anything that was specified as public). All the MetaData structures will be Refs.

ReadPEFile ( string filename ) : PEFile

Read a PE file and create all the data structures to represent it

ReadPublicClasses ( string filename ) : PEFile
SetCorFlags ( CorFlags flags ) : void

Set the flags (.corflags)

SetFileName ( string filename ) : void
SetIsDLL ( bool isDll ) : void

Specify if this PEFile is a .dll or .exe

SetNetVersion ( NetVersion nVer ) : void

Set the .NET version for this PE file

SetOutputDirectory ( string outputDir ) : void

Set the directory that the PE File will be written to. The default is the current directory.

SetOutputStream ( Stream output ) : void

Direct PE File output to an existing stream, instead of creating a new file.

SetSubSystem ( SubSystem subS ) : void

Set the subsystem (.subsystem) (Default is Windows Console mode)

WriteCILFile ( bool debug ) : void

Write out a CIL text file for this PE file

WritePEFile ( bool writePDB ) : void

Write out the PEFile (the "bake" function)

Private Methods

Method Description
AddToFileList ( ) : void
AddToResourceList ( ManifestResource res ) : void
BuildMetaData ( ) : void
ReadPDBScope ( PDBScope scope, MergeBuffer mergeBuffer, Scope parent, MethodDef thisMeth ) : Scope
SetDLLFlags ( ushort dflags ) : void
SetThisAssembly ( Assembly assem ) : void

Method Details

AddExternalManagedResource() public method

Add a managed resource from another assembly.
public AddExternalManagedResource ( ManifestResource mr, bool isPublic ) : void
mr ManifestResource
isPublic bool
return void

AddExternalManagedResource() public method

Add a managed resource from another assembly.
public AddExternalManagedResource ( string resName, AssemblyRef assem, bool isPublic ) : void
resName string The name of the resource
assem AssemblyRef The assembly where the resource is
isPublic bool Access for the resource
return void

AddExternalManagedResource() public method

Add a managed resource from another module in this assembly.
public AddExternalManagedResource ( string resName, ModuleRef mod, uint offset, bool isPublic ) : void
resName string The name of the resource
mod ModuleRef
offset uint
isPublic bool Access for the resource
return void

AddExternalManagedResource() public method

Add a managed resource from another file in this assembly.
public AddExternalManagedResource ( string resName, ResourceFile resFile, uint offset, bool isPublic ) : void
resName string The name of the resource
resFile ResourceFile
offset uint
isPublic bool Access for the resource
return void

AddManagedResource() public method

Add a managed resource to this PEFile. The resource will be embedded in this PE file.
public AddManagedResource ( string resName, byte resBytes, bool isPublic ) : void
resName string The name of the managed resource
resBytes byte The managed resource
isPublic bool Access for the resource
return void

AddUnmanagedResources() public method

Add a manifest resource to this PEFile
public AddUnmanagedResources ( string resFilename ) : void
resFilename string
return void

GetElement() public method

Get a Meta Data Element from this PE file
public GetElement ( uint token ) : MetaDataElement
token uint The meta data token for the required element
return MetaDataElement

GetFileName() public method

public GetFileName ( ) : string
return string

GetImportedAssemblies() public method

public GetImportedAssemblies ( ) : AssemblyRef[]
return AssemblyRef[]

GetNamesOfImports() public method

public GetNamesOfImports ( ) : string[]
return string[]

GetNetVersion() public method

Get the version of .NET for this PE file
public GetNetVersion ( ) : NetVersion
return NetVersion

GetNetVersionString() public method

Get the .NET version for this PE file
public GetNetVersionString ( ) : string
return string

GetResource() public method

Find a resource
public GetResource ( string name ) : ManifestResource
name string The name of the resource
return ManifestResource

GetResources() public method

public GetResources ( ) : PERWAPI.ManifestResource[]
return PERWAPI.ManifestResource[]

GetThisAssembly() public method

Get the descriptor for this assembly. The PEFile must have been created with hasAssembly = true
public GetThisAssembly ( ) : Assembly
return Assembly

MakeDebuggable() public method

Makes the assembly debuggable by attaching the DebuggableAttribute to the Assembly. Call immediately before calling WritePEFile.
public MakeDebuggable ( bool allowDebug, bool suppressOpt ) : void
allowDebug bool set true to enable debugging, false otherwise
suppressOpt bool set true to disable optimizations that affect debugging
return void

MakeExternAssembly() public method

Make a descriptor for an external assembly to this PEFile (.assembly extern)
public MakeExternAssembly ( string assemName ) : AssemblyRef
assemName string the external assembly name
return AssemblyRef

MakeExternModule() public method

Make a descriptor for an external module to this PEFile (.module extern)
public MakeExternModule ( string name ) : ModuleRef
name string the external module name
return ModuleRef

PEFile() public method

Create a new PE File with the name "fileName". If "fileName" ends in ".dll" then the file is a dll, otherwise it is an exe file. This PE File has no assembly.
public PEFile ( string fileName ) : System
fileName string Name for the output file.
return System

PEFile() public method

Create a new PE File with the name "fileName". If "fileName" ends in ".dll" then the file is a dll, otherwise it is an exe file. This file has an Assembly called "assemblyName".
public PEFile ( string fileName, string assemblyName ) : System
fileName string Name for the output file
assemblyName string Name of the assembly
return System

ReadExportedInterface() public static method

Read an existing PE File and return the exported interface (ie. anything that was specified as public). All the MetaData structures will be Refs.
public static ReadExportedInterface ( string filename ) : ReferenceScope
filename string The name of the pe file
return ReferenceScope

ReadPEFile() public static method

Read a PE file and create all the data structures to represent it
public static ReadPEFile ( string filename ) : PEFile
filename string The file name of the PE file
return PEFile

ReadPublicClasses() public static method

public static ReadPublicClasses ( string filename ) : PEFile
filename string
return PEFile

SetCorFlags() public method

Set the flags (.corflags)
public SetCorFlags ( CorFlags flags ) : void
flags CorFlags the flags value
return void

SetFileName() public method

public SetFileName ( string filename ) : void
filename string
return void

SetIsDLL() public method

Specify if this PEFile is a .dll or .exe
public SetIsDLL ( bool isDll ) : void
isDll bool
return void

SetNetVersion() public method

Set the .NET version for this PE file
public SetNetVersion ( NetVersion nVer ) : void
nVer NetVersion .NET version
return void

SetOutputDirectory() public method

Set the directory that the PE File will be written to. The default is the current directory.
public SetOutputDirectory ( string outputDir ) : void
outputDir string The directory to write the PE File to.
return void

SetOutputStream() public method

Direct PE File output to an existing stream, instead of creating a new file.
public SetOutputStream ( Stream output ) : void
output Stream The output stream
return void

SetSubSystem() public method

Set the subsystem (.subsystem) (Default is Windows Console mode)
public SetSubSystem ( SubSystem subS ) : void
subS SubSystem subsystem value
return void

WriteCILFile() public method

Write out a CIL text file for this PE file
public WriteCILFile ( bool debug ) : void
debug bool include debug information
return void

WritePEFile() public method

Write out the PEFile (the "bake" function)
public WritePEFile ( bool writePDB ) : void
writePDB bool
return void