Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

MzHeader Class Reference

Class that handles the MZ header of files. More...

#include <MzHeader.h>

List of all members.

Public Types

enum  Field {
  e_magic, e_cblp, e_cp, e_crlc,
  e_cparhdr, e_minalloc, e_maxalloc, e_ss,
  e_sp, e_csum, e_ip, e_cs,
  e_lfarlc, e_ovno, e_res, e_oemid,
  e_oeminfo, e_res2, e_lfanew
}

Public Member Functions

dword getAddressOfPeHeader () const
 Gets the e_lfanew value of the MZ header.

word getAddrOfRelocationTable () const
 Gets the e_lfarlc value of the MZ header.

word getBytesOnLastPage () const
 Gets the e_cblp value of the MZ header.

word getChecksum () const
 Gets the e_csum value of the MZ header.

word getCsValue () const
 Gets the e_cs value of the MZ header.

word getIpValue () const
 Gets the e_ip value of the MZ header.

word getMagicNumber () const
 Gets the e_magic value of the MZ header.

word getMaxExtraParagraphs () const
 Gets the e_maxalloc value of the MZ header.

word getMinExtraParagraphs () const
 Gets the e_minalloc value of the MZ header.

word getOemIdentifier () const
 Gets the e_oemid value of the MZ header.

word getOemInformation () const
 Gets the e_oeminfo value of the MZ header.

word getOverlayNumber () const
 Gets the e_ovnovalue of the MZ header.

word getPagesInFile () const
 Gets the e_cp value of the MZ header.

word getRelocations () const
 Gets the e_crlc value of the MZ header.

word getReservedWords1 (unsigned int uiNr) const
 Gets the e_res of the MZ header.

word getReservedWords2 (unsigned int uiNr) const
 Gets the e_res2 of the MZ header.

word getSizeOfHeader () const
 Gets the e_cparhdr value of the MZ header.

word getSpValue () const
 Gets the e_sp value of the MZ header.

word getSsValue () const
 Gets the e_ss value of the MZ header.

bool isValid (Field) const
bool isValid () const
 Checks if the current MZ header is valid.

void makeValid (Field)
void makeValid ()
 Corrects the current MZ header.

int read (unsigned char *pcBuffer, unsigned int uiSize, unsigned int originalOffs=0)
 Reads the MZ header from a memory location.

int read (const std::string &strFilename)
 Reads the MZ header of a file.

void rebuild (std::vector< byte > &vBuffer) const
 Rebuild the MZ header.

void setAddressOfPeHeader (dword dwValue)
 Sets the e_lfanew value of the MZ header.

void setAddrOfRelocationTable (word wValue)
 Sets the e_lfarlc value of the MZ header.

void setBytesOnLastPage (word wValue)
 Sets the e_cblp value of the MZ header.

void setChecksum (word wValue)
 Sets the e_csum value of the MZ header.

void setCsValue (word wValue)
 Sets the e_cs value of the MZ header.

void setIpValue (word wValue)
 Sets the e_ip value of the MZ header.

void setMagicNumber (word wValue)
 Sets the e_magic value of the MZ header.

void setMaxExtraParagraphs (word wValue)
 Sets the e_maxalloc value of the MZ header.

void setMinExtraParagraphs (word wValue)
 Sets the e_minalloc value of the MZ header.

void setOemIdentifier (word wValue)
 Sets the e_oemid value of the MZ header.

void setOemInformation (word wValue)
 Sets the e_oeminfo value of the MZ header.

void setOverlayNumber (word wValue)
 Sets the e_ovno value of the MZ header.

void setPagesInFile (word wValue)
 Sets the e_cp value of the MZ header.

void setRelocations (word wValue)
 Sets the e_crlc value of the MZ header.

void setReservedWords1 (unsigned int uiNr, word wValue)
 Sets the e_res value of the MZ header.

void setReservedWords2 (unsigned int uiNr, word wValue)
 Sets the e_res2 value of the MZ header.

void setSizeOfHeader (word wValue)
 Sets the e_cparhdr value of the MZ header.

void setSpValue (word wValue)
 Sets the e_sp value of the MZ header.

void setSsValue (word wValue)
 Sets the e_ss value of the MZ header.

unsigned int size () const
 Returns the size of the current MZ header.

int write (const std::string &strFilename, dword dwOffset) const
 Writes the current MZ header to offset 0 of a file.


Private Member Functions

void read (InputBuffer &ibBuffer)
 Reads data from an InputBuffer into a MZ header struct.


Private Attributes

PELIB_IMAGE_DOS_HEADER m_idhHeader
 Stores all MZ header information.

unsigned int originalOffset
 Offset of the MZ header in the original file.


Detailed Description

Class that handles the MZ header of files.

This class can read and modify MZ headers. It provides set- and get functions to access all individual members of a MZ header. Furthermore it's possible to validate and rebuild MZ headers.


Member Function Documentation

dword getAddressOfPeHeader  )  const
 

Gets the e_lfanew value of the MZ header.

Returns the MZ header's e_lfanew value.

word getAddrOfRelocationTable  )  const
 

Gets the e_lfarlc value of the MZ header.

Returns the MZ header's e_lfarlc value.

word getBytesOnLastPage  )  const
 

Gets the e_cblp value of the MZ header.

Returns the MZ header's e_cblp value.

word getChecksum  )  const
 

Gets the e_csum value of the MZ header.

Returns the MZ header's e_csum value.

word getCsValue  )  const
 

Gets the e_cs value of the MZ header.

Returns the MZ header's e_cs value.

word getIpValue  )  const
 

Gets the e_ip value of the MZ header.

Returns the MZ header's e_ip value.

word getMagicNumber  )  const
 

Gets the e_magic value of the MZ header.

Returns the MZ header's e_magic value.

word getMaxExtraParagraphs  )  const
 

Gets the e_maxalloc value of the MZ header.

Returns the MZ header's e_maxalloc value.

word getMinExtraParagraphs  )  const
 

Gets the e_minalloc value of the MZ header.

Returns the MZ header's e_minalloc value.

word getOemIdentifier  )  const
 

Gets the e_oemid value of the MZ header.

Returns the MZ header's e_oemid value.

word getOemInformation  )  const
 

Gets the e_oeminfo value of the MZ header.

Returns the MZ header's e_oeminfo value.

word getOverlayNumber  )  const
 

Gets the e_ovnovalue of the MZ header.

Returns the MZ header's e_ovno value.

word getPagesInFile  )  const
 

Gets the e_cp value of the MZ header.

Returns the MZ header's e_cp value.

word getRelocations  )  const
 

Gets the e_crlc value of the MZ header.

Returns the MZ header's e_crlc value.

word getReservedWords1 unsigned int  uiNr  )  const
 

Gets the e_res of the MZ header.

Returns the MZ header's e_res[uiNr] value. If the parameter uiNr is out of range you will get undefined behaviour.

Parameters:
uiNr The index of the word in the e_res array (valid range: 0-3)

word getReservedWords2 unsigned int  uiNr  )  const
 

Gets the e_res2 of the MZ header.

Returns the MZ header's e_res2[uiNr] value. If the parameter uiNr is out of range you will get undefined behaviour.

Parameters:
uiNr The index of the word in the e_res array (valid range: 0-9)

word getSizeOfHeader  )  const
 

Gets the e_cparhdr value of the MZ header.

Returns the MZ header's e_cparhdr value.

word getSpValue  )  const
 

Gets the e_sp value of the MZ header.

Returns the MZ header's e_sp value.

word getSsValue  )  const
 

Gets the e_ss value of the MZ header.

Returns the MZ header's e_ss value.

bool isValid  )  const
 

Checks if the current MZ header is valid.

Tests if the currently loaded MZ header is a valid MZ header. Note that this function does not check if the address to the PE header is valid as this is not possible. Actually, the only thing this function checks is if the e_magic value is set to 0x5A4D (IMAGE_DOS_SIGNATURE). Everything else is not relevant for Windows 2000 and that's the system PeLib is focusing on for now.

Returns:
A boolean value that indicates if the MZ header is correct or not.

void makeValid  ) 
 

Corrects the current MZ header.

Corrects all erroneous values of the current MZ header. Note that this function does not correct the pointer to the PE header. Actually, the only thing this function corrects is the e_magic value. Everything else is not relevant for Windows 2000 and that's the system PeLib is focusing on for now.

Here is the call graph for this function:

int read unsigned char *  pcBuffer,
unsigned int  uiSize,
unsigned int  originalOffs = 0
 

Reads the MZ header from a memory location.

Reads the MZ header from memory. A pointer to a location in memory is passed and the data at this location is treated like a MZ header structure. The MZ header does not need to be valid.

Parameters:
pcBuffer Pointer to a MZ header.
uiSize Length of the buffer.
Returns:
A non-zero value is returned if a problem occured.

Here is the call graph for this function:

int read const std::string &  strFilename  ) 
 

Reads the MZ header of a file.

Reads the MZ header from a file. Note that this function does not verify if a file is actually a MZ file. For this purpose see #PeFile::MzHeader::isValid. The reason for this is simple: Otherwise it might not be possible to load damaged PE files to repair them.

Parameters:
strFilename Name of the file which will be read.
Returns:
A non-zero value is returned if a problem occured.

Here is the call graph for this function:

void read InputBuffer &  ibBuffer  )  [private]
 

Reads data from an InputBuffer into a MZ header struct.

Reads data from an InputBuffer into the struct that represents the MZ header. It's required that the size of the input buffer is at least as big as the size of a MZ header. Otherwise we get undefined behaviour.

Parameters:
ibBuffer InputBuffer that holds the data.
Returns:
A non-zero value is returned if a problem occured.

void rebuild std::vector< byte > &  vBuffer  )  const
 

Rebuild the MZ header.

Rebuilds the MZ header so that it can be written to a file. It's not guaranteed that the MZ header will be valid. If you want to make sure that the MZ header will be valid you must call PeLib::MzHeader::makeValid first.

Parameters:
vBuffer Buffer where the rebuilt MZ header will be stored.

void setAddressOfPeHeader dword  lValue  ) 
 

Sets the e_lfanew value of the MZ header.

Sets the MZ header's e_lfanew value.

Parameters:
lValue The new value of e_lfanew.

void setAddrOfRelocationTable word  wValue  ) 
 

Sets the e_lfarlc value of the MZ header.

Sets the MZ header's e_lfarlc value.

Parameters:
wValue The new value of e_lfarlc.

void setBytesOnLastPage word  wValue  ) 
 

Sets the e_cblp value of the MZ header.

Sets the MZ header's e_cblp value.

Parameters:
wValue The new value of e_cblp.

void setChecksum word  wValue  ) 
 

Sets the e_csum value of the MZ header.

Sets the MZ header's e_csum value.

Parameters:
wValue The new value of e_csum.

void setCsValue word  wValue  ) 
 

Sets the e_cs value of the MZ header.

Sets the MZ header's e_cs value.

Parameters:
wValue The new value of e_cs.

void setIpValue word  wValue  ) 
 

Sets the e_ip value of the MZ header.

Sets the MZ header's e_ip value.

Parameters:
wValue The new value of e_ip.

void setMagicNumber word  wValue  ) 
 

Sets the e_magic value of the MZ header.

Sets the MZ header's e_magic value.

Parameters:
wValue The new value of e_magic.

void setMaxExtraParagraphs word  wValue  ) 
 

Sets the e_maxalloc value of the MZ header.

Sets the MZ header's e_maxalloc value.

Parameters:
wValue The new value of e_maxalloc.

void setMinExtraParagraphs word  wValue  ) 
 

Sets the e_minalloc value of the MZ header.

Sets the MZ header's e_minalloc value.

Parameters:
wValue The new value of e_minalloc.

void setOemIdentifier word  wValue  ) 
 

Sets the e_oemid value of the MZ header.

Sets the MZ header's e_oemid value.

Parameters:
wValue The new value of e_oemid.

void setOemInformation word  wValue  ) 
 

Sets the e_oeminfo value of the MZ header.

Sets the MZ header's e_oeminfo value.

Parameters:
wValue The new value of e_oeminfo.

void setOverlayNumber word  wValue  ) 
 

Sets the e_ovno value of the MZ header.

Sets the MZ header's e_ovno value.

Parameters:
wValue The new value of e_ovno.

void setPagesInFile word  wValue  ) 
 

Sets the e_cp value of the MZ header.

Sets the MZ header's e_cp value.

Parameters:
wValue The new value of e_cp.

void setRelocations word  wValue  ) 
 

Sets the e_crlc value of the MZ header.

Sets the MZ header's e_crlc value.

Parameters:
wValue The new value of e_crlc.

void setReservedWords1 unsigned int  uiNr,
word  wValue
 

Sets the e_res value of the MZ header.

Sets the MZ header's e_res[uiNr] value. If the parameter uiNr is out of range you will get undefined behaviour.

Parameters:
uiNr The index of the word in the e_res array (valid range: 0-3)
wValue The new value of e_res[nr].

void setReservedWords2 unsigned int  uiNr,
word  wValue
 

Sets the e_res2 value of the MZ header.

Sets the MZ header's e_res2[uiNr] value. If the parameter uiNr is out of range you will get undefined behaviour.

Parameters:
uiNr The index of the word in the e_res2 array (valid range: 0-9)
wValue The new value of e_res[nr].

void setSizeOfHeader word  wValue  ) 
 

Sets the e_cparhdr value of the MZ header.

Sets the MZ header's e_cparhdr value.

Parameters:
wValue The new value of e_cparhdr.

void setSpValue word  wValue  ) 
 

Sets the e_sp value of the MZ header.

Sets the MZ header's e_sp value.

Parameters:
wValue The new value of e_sp.

void setSsValue word  wValue  ) 
 

Sets the e_ss value of the MZ header.

Sets the MZ header's e_ss value.

Parameters:
wValue The new value of e_ss.

unsigned int size  )  const
 

Returns the size of the current MZ header.

Returns the size of the MZ header. This size is actually always sizeof(IMAGE_DOS_HEADER) (== 0x40) because the MZ header is a header of constant size if you disregard the dos stub. If you want to know the size of the MZ header + the size of the dos stub check PeLib::MzHeader::getAddressOfPeHeader.

Returns:
Size of the MZ header.

int write const std::string &  strFilename,
dword  dwOffset = 0
const
 

Writes the current MZ header to offset 0 of a file.

Writes the current MZ header to a file. The file does not have to exist. If it doesn't exist it will be created.

Parameters:
strFilename Name of the file the header will be written to.
dwOffset Offset the header will be written to (defaults to 0).
Returns:
A non-zero value is returned if a problem occured.

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Mon Jan 17 20:50:11 2005 for PeLib by doxygen 1.3.7