public static PE read(IDataReader dr) throws IOException { PE pe = new PE(); pe.setDosHeader(readDos(dr)); // Check if we have an old file type if (pe.getDosHeader().getAddressOfNewExeHeader() == 0 || pe.getDosHeader().getAddressOfNewExeHeader() > 8192) { return pe; } pe.setStub(readStub(pe.getDosHeader(), dr)); pe.setSignature(readSignature(dr)); // Check signature to ensure we have a pe/coff file if (!pe.getSignature().isValid()) { return pe; } pe.setCoffHeader(readCOFF(dr)); pe.setOptionalHeader(readOptional(dr)); pe.setSectionTable(readSectionHeaders(pe, dr)); pe.set64(pe.getOptionalHeader().isPE32plus()); // Now read the rest of the file DataEntry entry = null; while ((entry = findNextEntry(pe, dr.getPosition())) != null) { if (entry.isSection) { readSection(pe, entry, dr); } else if (entry.isDebugRawData) { readDebugRawData(pe, entry, dr); } else { readImageData(pe, entry, dr); } } // Read any trailing data byte[] tb = dr.readAll(); if (tb.length > 0) { pe.getImageData().setTrailingData(tb); } return pe; }