A method and related apparatuses facilitate the compression of firmware
modules that follow a portable executable (PE) format. An example method
includes an operation of storing a firmware module in memory, wherein the
firmware module follows a PE format, thus having subdivisions that
include an MS-DOS header. The method also includes an operation of
flattening the firmware module by replacing existing content within at
least one field within the MS-DOS header with fill data that is more
compressible than the existing content. For example, fill data may be
loaded into an MS-DOS stub field within the MS-DOS header. Alternatively,
the method may flatten the firmware module by ensuring that fill data
occupies all fields within the MS-DOS header except for an lfanew field
and an e-magic field. In some embodiments, additional or alternative
operations to flatten the firmware module may be performed, such as
loading fill data into one or more fields within an optional file header
of the firmware module.