Reading and Writing PE and PDB Files
CCI applications typically start by reading a PE file and perhaps the associated PDB file from storage. Rewriting applications write the modified PE file back to storage. CCI provides objects that simplify the reading and writing process for both file types.
For an example of how to read and write PE and PDB files, see the
PeToPe Sample Walkthrough
object provides a fast memory-efficient way to read PE files incrementally . This is an ideal way for compilers written in managed code to import metadata, because it involves no unmanaged code and no interop overhead. Applications that
load PE files from the file system typically use PeReader
indirectly, by calling
, which opens the file, passes the contents to
, and returns the appropriate interface.
To load a PDB file, create a new PdbReader
object and pass the constructor a stream representing the file’s contents.
constructs an object model to represent the PDB file from the contents of the stream. Unlike
does not return an interface to an object model. Instead, the
object itself represents the PDB file.
object provides a fast and memory-efficient way to write PE files to a stream, typically a file stream. Unlike components such as
can write any object model that implements the CCI interfaces. You do not need a compiler to construct objects. Like
uses only managed code to write PE streams.
To write a PdbReader
object model to a stream, create a PdbWriter
object and pass it to
interacts with PdbWriter
to produce an output stream. At the moment,
is a managed wrapper for an unmanaged COM component, so writing PDB files does use some unmanaged code.
Next: CCI and Code
Return to Beginning