public class PEFile extends Object implements Signable, Closeable
| Constructor and Description |
|---|
PEFile(File file)
Create a PEFile from the specified file.
|
PEFile(SeekableByteChannel channel)
Create a PEFile from the specified channel.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the file
|
long |
computeChecksum()
Compute the checksum of the image file.
|
byte[] |
computeDigest(DigestAlgorithm algorithm)
Compute the checksum of the file using the specified digest algorithm.
|
byte[] |
computeDigest(MessageDigest digest)
Compute the digest of the file.
|
ASN1Object |
createIndirectData(DigestAlgorithm digestAlgorithm)
Creates the SpcIndirectDataContent structure containing the digest of the file.
|
long |
getAddressOfEntryPoint()
The address of the entry point relative to the image base when the
executable file is loaded into memory.
|
long |
getBaseOfCode()
The address that is relative to the image base of the beginning-of-code
section when it is loaded into memory.
|
long |
getBaseOfData()
The address that is relative to the image base of the beginning-of-data
section when it is loaded into memory (PE32 only).
|
int |
getCharacteristics()
The flags that indicate the attributes of the file.
|
long |
getCheckSum()
The image file checksum.
|
DataDirectory |
getDataDirectory(DataDirectoryType type)
Returns the data directory of the specified type.
|
int |
getDllCharacteristics() |
long |
getFileAlignment()
The alignment factor (in bytes) that is used to align the raw data of
sections in the image file.
|
PEFormat |
getFormat() |
long |
getImageBase()
The preferred address of the first byte of image when loaded into memory;
must be a multiple of 64 K.
|
long |
getLoaderFlags()
Reserved, must be zero.
|
MachineType |
getMachineType() |
int |
getMajorImageVersion()
The major version number of the image.
|
int |
getMajorLinkerVersion()
The linker major version number.
|
int |
getMajorOperatingSystemVersion()
The major version number of the required operating system.
|
int |
getMajorSubsystemVersion()
The major version number of the subsystem.
|
int |
getMinorImageVersion()
The minor version number of the image.
|
int |
getMinorLinkerVersion()
The linker minor version number.
|
int |
getMinorOperatingSystemVersion()
The minor version number of the required operating system.
|
int |
getMinorSubsystemVersion()
The minor version number of the subsystem.
|
int |
getNumberOfRvaAndSizes()
The number of data-directory entries in the remainder of the optional
header.
|
int |
getNumberOfSections()
The number of sections.
|
long |
getNumberOfSymbols()
The number of entries in the symbol table.
|
long |
getPointerToSymbolTable()
The file offset of the COFF symbol table, or zero if no COFF symbol table
is present.
|
long |
getSectionAlignment()
The alignment (in bytes) of sections when they are loaded into memory.
|
List<Section> |
getSections() |
List<CMSSignedData> |
getSignatures()
Returns the Authenticode signatures on the file.
|
long |
getSizeOfCode()
The size of the code (text) section, or the sum of all code sections
if there are multiple sections.
|
long |
getSizeOfHeaders()
The combined size of an MS DOS stub, PE header, and section headers
rounded up to a multiple of FileAlignment.
|
long |
getSizeOfHeapCommit()
The size of the local heap space to commit.
|
long |
getSizeOfHeapReserve()
The size of the local heap space to reserve.
|
long |
getSizeOfImage()
The size (in bytes) of the image, including all headers, as the image
is loaded in memory.
|
long |
getSizeOfInitializedData()
The size of the initialized data section, or the sum of all such
sections if there are multiple data sections.
|
int |
getSizeOfOptionalHeader()
The size of the optional header, which is required for executable files
but not for object files.
|
long |
getSizeOfStackCommit()
The size of the stack to commit.
|
long |
getSizeOfStackReserve()
The size of the stack to reserve.
|
long |
getSizeOfUninitializedData()
The size of the uninitialized data section (BSS), or the sum of all such
sections if there are multiple BSS sections.
|
Subsystem |
getSubsystem()
The subsystem that is required to run this image.
|
Date |
getTimeDateStamp()
The low 32 bits of the number of seconds since 00:00 January 1, 1970
(a C runtime time_t value), that indicates when the file was created.
|
long |
getWin32VersionValue()
Reserved, must be zero.
|
static boolean |
isPEFile(File file)
Tells if the specified file is a Portable Executable file.
|
void |
pad(int multiple)
Increase the size of the file up to a size that is a multiple of the specified value.
|
void |
printInfo(OutputStream out)
Print detailed informations about the PE file.
|
void |
printInfo(PrintWriter out)
Print detailed informations about the PE file.
|
void |
save()
Saves the file.
|
void |
setSignature(CMSSignedData signature)
Sets the signature of the file, overwriting the previous one.
|
void |
updateChecksum() |
void |
writeDataDirectory(DataDirectoryType type,
byte[] data)
Writes the data directory of the specified type.
|
public PEFile(File file) throws IOException
file - the file to openIOException - if an I/O error occurspublic PEFile(SeekableByteChannel channel) throws IOException
channel - the channel to read the file fromIOException - if an I/O error occurspublic void close() throws IOException
close in interface Closeableclose in interface AutoCloseableIOException - if an I/O error occurspublic long computeChecksum()
public byte[] computeDigest(DigestAlgorithm algorithm) throws IOException
algorithm - the digest algorithm, typically SHA1IOException - if an I/O error occurspublic byte[] computeDigest(MessageDigest digest) throws IOException
computeDigest in interface Signabledigest - the message digest to updateIOException - if an I/O error occurspublic ASN1Object createIndirectData(DigestAlgorithm digestAlgorithm) throws IOException
SignablecreateIndirectData in interface SignabledigestAlgorithm - the digest algorithm to useIOException - if an I/O error occurspublic long getAddressOfEntryPoint()
public long getBaseOfCode()
public long getBaseOfData()
public int getCharacteristics()
public long getCheckSum()
public DataDirectory getDataDirectory(DataDirectoryType type)
type - the type of data directorypublic int getDllCharacteristics()
public long getFileAlignment()
public long getImageBase()
public long getLoaderFlags()
public MachineType getMachineType()
public int getMajorImageVersion()
public int getMajorLinkerVersion()
public int getMajorOperatingSystemVersion()
public int getMajorSubsystemVersion()
public int getMinorImageVersion()
public int getMinorLinkerVersion()
public int getMinorOperatingSystemVersion()
public int getMinorSubsystemVersion()
public int getNumberOfRvaAndSizes()
public int getNumberOfSections()
public long getNumberOfSymbols()
public long getPointerToSymbolTable()
public long getSectionAlignment()
public List<Section> getSections()
public List<CMSSignedData> getSignatures()
SignablegetSignatures in interface Signablepublic long getSizeOfCode()
public long getSizeOfHeaders()
public long getSizeOfHeapCommit()
public long getSizeOfHeapReserve()
public long getSizeOfImage()
public long getSizeOfInitializedData()
public int getSizeOfOptionalHeader()
public long getSizeOfStackCommit()
public long getSizeOfStackReserve()
public long getSizeOfUninitializedData()
public Subsystem getSubsystem()
public Date getTimeDateStamp()
public long getWin32VersionValue()
public static boolean isPEFile(File file) throws IOException
file - the file to checktrue if the file is a Portable Executable, false otherwiseIOException - if an I/O error occurspublic void pad(int multiple) throws IOException
multiple - the size of the byte alignmentIOException - if an I/O error occurspublic void printInfo(OutputStream out)
out - the output stream where the info is printedpublic void printInfo(PrintWriter out)
out - the output writer where the info is printedpublic void save() throws IOException
Signablesave in interface SignableIOException - if an I/O error occurspublic void setSignature(CMSSignedData signature) throws IOException
SignablesetSignature in interface Signablesignature - the signature to putIOException - if an I/O error occurspublic void updateChecksum()
public void writeDataDirectory(DataDirectoryType type, byte[] data) throws IOException
type - the type of the data directorydata - the content of the data directoryIOException - if an I/O error occursCopyright © 2012–2020. All rights reserved.