@Test public void testComputeDigest() throws Exception { PEFile file = new PEFile(new File("target/test-classes/wineyes.exe")); String sha1 = Hex.toHexString(file.computeDigest(DigestAlgorithm.SHA1)); String sha256 = Hex.toHexString(file.computeDigest(DigestAlgorithm.SHA256)); assertEquals("d27ec498912807ddfc4bec2be4f62c42814836f3", sha1); assertEquals("7bb369df020cea757619e1c1d678dbca06b638f2cc45b740b5eacfc21e76b160", sha256); }
@Override public synchronized byte[] computeDigest(MessageDigest digest) throws IOException { long checksumLocation = peHeaderOffset + 88; DataDirectory certificateTable = getDataDirectory(DataDirectoryType.CERTIFICATE_TABLE); updateDigest(digest, 0, checksumLocation); long position = checksumLocation + 4; int certificateTableOffset = getDataDirectoryOffset() + 8 * DataDirectoryType.CERTIFICATE_TABLE.ordinal(); updateDigest(digest, position, certificateTableOffset); position = certificateTableOffset + 8; if (certificateTable != null && certificateTable.exists()) { updateDigest(digest, position, certificateTable.getVirtualAddress()); position = certificateTable.getVirtualAddress() + certificateTable.getSize(); } updateDigest(digest, position, channel.size()); return digest.digest(); }
PEFile implements Signable, Closeable { @Override public synchronized byte[] computeDigest(MessageDigest digest) throws IOException { long checksumLocation = peHeaderOffset + 88; DataDirectory certificateTable = getDataDirectory(DataDirectoryType.CERTIFICATE_TABLE); updateDigest(digest, 0, checksumLocation); long position = checksumLocation + 4; int certificateTableOffset = getDataDirectoryOffset() + 8 * DataDirectoryType.CERTIFICATE_TABLE.ordinal(); updateDigest(digest, position, certificateTableOffset); position = certificateTableOffset + 8; if (certificateTable != null && certificateTable.exists()) { updateDigest(digest, position, certificateTable.getVirtualAddress()); position = certificateTable.getVirtualAddress() + certificateTable.getSize(); } updateDigest(digest, position, channel.size()); return digest.digest(); } }
PEFile implements Signable, Closeable { @Override public synchronized byte[] computeDigest(MessageDigest digest) throws IOException { long checksumLocation = peHeaderOffset + 88; DataDirectory certificateTable = getDataDirectory(DataDirectoryType.CERTIFICATE_TABLE); updateDigest(digest, 0, checksumLocation); long position = checksumLocation + 4; int certificateTableOffset = getDataDirectoryOffset() + 8 * DataDirectoryType.CERTIFICATE_TABLE.ordinal(); updateDigest(digest, position, certificateTableOffset); position = certificateTableOffset + 8; if (certificateTable != null && certificateTable.exists()) { updateDigest(digest, position, certificateTable.getVirtualAddress()); position = certificateTable.getVirtualAddress() + certificateTable.getSize(); } updateDigest(digest, position, channel.size()); return digest.digest(); } PEFile(File file);  PEFile(SeekableByteChannel channel); }
PEFile implements Signable, Closeable { @Override public synchronized byte[] computeDigest(MessageDigest digest) throws IOException { long checksumLocation = peHeaderOffset + 88; DataDirectory certificateTable = getDataDirectory(DataDirectoryType.CERTIFICATE_TABLE); updateDigest(digest, 0, checksumLocation); long position = checksumLocation + 4; int certificateTableOffset = getDataDirectoryOffset() + 8 * DataDirectoryType.CERTIFICATE_TABLE.ordinal(); updateDigest(digest, position, certificateTableOffset); position = certificateTableOffset + 8; if (certificateTable != null && certificateTable.exists()) { updateDigest(digest, position, certificateTable.getVirtualAddress()); position = certificateTable.getVirtualAddress() + certificateTable.getSize(); } updateDigest(digest, position, channel.size()); return digest.digest(); } PEFile(File file);  PEFile(SeekableByteChannel channel); static boolean isPEFile(File file); void save(); synchronized void close(); MachineType getMachineType(); int getNumberOfSections(); Date getTimeDateStamp(); long getPointerToSymbolTable(); long getNumberOfSymbols(); int getSizeOfOptionalHeader(); int getCharacteristics(); PEFormat getFormat(); int getMajorLinkerVersion(); int getMinorLinkerVersion(); long getSizeOfCode(); long getSizeOfInitializedData(); long getSizeOfUninitializedData(); long getAddressOfEntryPoint(); long getBaseOfCode(); long getBaseOfData(); long getImageBase(); long getSectionAlignment(); long getFileAlignment(); int getMajorOperatingSystemVersion(); int getMinorOperatingSystemVersion(); int getMajorImageVersion(); int getMinorImageVersion(); int getMajorSubsystemVersion(); int getMinorSubsystemVersion(); long getWin32VersionValue(); long getSizeOfImage(); long getSizeOfHeaders(); long getCheckSum(); synchronized long computeChecksum(); synchronized void updateChecksum(); Subsystem getSubsystem(); int getDllCharacteristics(); long getSizeOfStackReserve(); long getSizeOfStackCommit(); long getSizeOfHeapReserve(); long getSizeOfHeapCommit(); long getLoaderFlags(); int getNumberOfRvaAndSizes(); DataDirectory getDataDirectory(DataDirectoryType type); synchronized void writeDataDirectory(DataDirectoryType type, byte[] data); @Override synchronized List<CMSSignedData> getSignatures(); @Override void setSignature(CMSSignedData signature); synchronized List<Section> getSections(); void printInfo(OutputStream out); void printInfo(PrintWriter out); @Override synchronized byte[] computeDigest(MessageDigest digest); byte[] computeDigest(DigestAlgorithm algorithm); @Override ASN1Object createIndirectData(DigestAlgorithm digestAlgorithm); synchronized void pad(int multiple); }
PEFile implements Signable, Closeable { @Override public synchronized byte[] computeDigest(MessageDigest digest) throws IOException { long checksumLocation = peHeaderOffset + 88; DataDirectory certificateTable = getDataDirectory(DataDirectoryType.CERTIFICATE_TABLE); updateDigest(digest, 0, checksumLocation); long position = checksumLocation + 4; int certificateTableOffset = getDataDirectoryOffset() + 8 * DataDirectoryType.CERTIFICATE_TABLE.ordinal(); updateDigest(digest, position, certificateTableOffset); position = certificateTableOffset + 8; if (certificateTable != null && certificateTable.exists()) { updateDigest(digest, position, certificateTable.getVirtualAddress()); position = certificateTable.getVirtualAddress() + certificateTable.getSize(); } updateDigest(digest, position, channel.size()); return digest.digest(); } PEFile(File file);  PEFile(SeekableByteChannel channel); static boolean isPEFile(File file); void save(); synchronized void close(); MachineType getMachineType(); int getNumberOfSections(); Date getTimeDateStamp(); long getPointerToSymbolTable(); long getNumberOfSymbols(); int getSizeOfOptionalHeader(); int getCharacteristics(); PEFormat getFormat(); int getMajorLinkerVersion(); int getMinorLinkerVersion(); long getSizeOfCode(); long getSizeOfInitializedData(); long getSizeOfUninitializedData(); long getAddressOfEntryPoint(); long getBaseOfCode(); long getBaseOfData(); long getImageBase(); long getSectionAlignment(); long getFileAlignment(); int getMajorOperatingSystemVersion(); int getMinorOperatingSystemVersion(); int getMajorImageVersion(); int getMinorImageVersion(); int getMajorSubsystemVersion(); int getMinorSubsystemVersion(); long getWin32VersionValue(); long getSizeOfImage(); long getSizeOfHeaders(); long getCheckSum(); synchronized long computeChecksum(); synchronized void updateChecksum(); Subsystem getSubsystem(); int getDllCharacteristics(); long getSizeOfStackReserve(); long getSizeOfStackCommit(); long getSizeOfHeapReserve(); long getSizeOfHeapCommit(); long getLoaderFlags(); int getNumberOfRvaAndSizes(); DataDirectory getDataDirectory(DataDirectoryType type); synchronized void writeDataDirectory(DataDirectoryType type, byte[] data); @Override synchronized List<CMSSignedData> getSignatures(); @Override void setSignature(CMSSignedData signature); synchronized List<Section> getSections(); void printInfo(OutputStream out); void printInfo(PrintWriter out); @Override synchronized byte[] computeDigest(MessageDigest digest); byte[] computeDigest(DigestAlgorithm algorithm); @Override ASN1Object createIndirectData(DigestAlgorithm digestAlgorithm); synchronized void pad(int multiple);  }