public void close() throws IOException { raFile.close(); }
protected void initDirOffsetPosAndComment() throws IOException { // zip files without a comment contain the offset/position of the central directory at this fixed position this.dirOffsetPos = zipFile.length() - 6; final int dirOffset = raFile.readInt( this.dirOffsetPos - 16 ); if( dirOffset!=ENDSIG ) { // if a comment is present, search the ENDSIG constant, starting at the end of the zip file byte[] endsig = ByteArrayHelper.toByteArray((int)ZipConstants.ENDSIG); long endsigPos = raFile.lastPosOf(endsig); if( endsigPos==-1 ) { throw new ZipException("expected ENDSIC not found (marks the beginning of the central directory at end of the zip file)"); } else { this.dirOffsetPos = endsigPos+16; short commentLength = raFile.readShort( this.dirOffsetPos + 4 ); this.comment = new String( raFile.readByteArray( this.dirOffsetPos+6, commentLength ) ); } } }
public byte readByte(long pos) throws IOException { file.seek(pos); return readByte(); }
final int dirOffset = raFile.readInt( this.dirOffsetPos ); int censig = raFile.readInt( fileOffset ); if( censig!=CENSIG ) { throw new ZipException("expected CENSIC not found at entry no " + (i+1) + " in central directory at end of zip file at " + fileOffset); short fileNameLength = raFile.readShort( fileOffset + 28 ); short extraFieldLength = raFile.readShort( fileOffset + 30 ); long fileOffsetPos = fileOffset + 28 + 14; long fileDataOffset = raFile.readInt( fileOffsetPos ); int locsig = raFile.readInt( fileDataOffset ); if( locsig!=LOCSIG ) { throw new ZipException("expected LOCSIC not found at alleged position of data for file no " + (i+1)); byte[] fileNameBytes = raFile.readByteArray( fileOffsetPos+4, fileNameLength ); long nextFileOffset = raFile.getFilePointer(); String fileName = new String( fileNameBytes, charset ); zipEntry.setSize( cde.getUncompressedSize() ); long dosTime = raFile.readInt( fileOffset + 12 ); zipEntry.setTime( ExtZipEntry.dosToJavaTime(dosTime) );
int censig = raFile.readInt( fileOffset ); if( censig!=CENSIG ) { throw new ZipException("expected CENSIC not found in central directory (at end of zip file)"); short flag = raFile.readShort( fileOffset + 8 ); this.isEncrypted = (flag&1)>0; this.fileNameLength = raFile.readShort( fileOffset + 28 ); byte[] fileNameBytes = raFile.readByteArray( fileOffset + 46, fileNameLength ); this.fileName = new String( fileNameBytes, AesZipFileDecrypter.charset ); if( LOG.isLoggable(Level.FINE) ) { this.extraFieldLength = raFile.readShort( fileOffset + 30 ); this.localHeaderOffset = raFile.readInt( fileOffset + 28 + 14 ); byte[] efhid = raFile.readByteArray( this.extraFieldOffset, 2 ); if( efhid[0]!=0x01 || efhid[1]!=(byte)0x99 ) { this.extraFieldOffset = localHeaderOffset+30+fileNameLength; this.extraFieldLength = raFile.readShort( localHeaderOffset+28 ); if( LOG.isLoggable(Level.FINE) ) { LOG.fine( "local header - extraFieldOffset=" + Long.toHexString(this.extraFieldOffset) ); efhid = raFile.readByteArray( extraFieldOffset, 2); if( efhid[0]==0x01 && efhid[1]==(byte)0x99 ) { this.isAesEncrypted = true; this.actualCompressionMethod = raFile.readShort( getExtraFieldOffset() + 9 ); this.localHeaderSize = 30 + getExtraFieldLength() + getFileNameLength();
byte[] salt = raFile.readByteArray( cryptoHeaderOffset, 16 ); byte[] pwVerification = raFile.readByteArray( cryptoHeaderOffset+16, 2 ); zos.putNextEntry( tmpEntry ); raFile.seek( cde.getOffset() ); byte[] buffer = new byte[bufferSize]; int remaining = (int)zipEntry.getEncryptedDataSize(); while( remaining>0 ) { int len = (remaining>buffer.length) ? buffer.length : remaining; int read = raFile.readByteArray(buffer,len); decrypter.decrypt( buffer, read ); zos.writeBytes( buffer, 0, read ); raFile.readByteArray(storedMac,10); byte[] calcMac = decrypter.getFinalAuthentication(); if( LOG.isLoggable(Level.FINE) ) {
byte[] salt = raFile.readByteArray(cryptoHeaderOffset, 16); byte[] pwVerification = raFile.readByteArray(cryptoHeaderOffset + 16, 2); if (LOG.isLoggable(Level.FINEST)) { LOG.finest("\n" + cde.toString()); tmpEntry.setCompressedSize(zipEntry.getEncryptedDataSize()); zos.putNextEntry(tmpEntry); raFile.seek(cde.getOffset()); byte[] buffer = new byte[bufferSize]; int remaining = total - count; int len = (remaining > buffer.length) ? buffer.length : remaining; int read = raFile.readByteArray(buffer, len); decrypter.decrypt(buffer, read); zos.writeBytes(buffer, 0, read); raFile.readByteArrayFully(storedMac, 0, 10);
/** number of entries in file (files AND directories) */ public short getNumberOfEntries() throws IOException { return raFile.readShort( this.dirOffsetPos-6 ); }
public long lastPosOf(byte[] bytesToFind) throws IOException { long out = -1; for( long seekPos=file.length()-1-bytesToFind.length; seekPos>3 && out==-1; seekPos-- ) { byte[] buffer = readByteArray(seekPos,bytesToFind.length); if( Arrays.equals(bytesToFind,buffer) ) { out = seekPos; } } return out; }
public long readLong(long pos) throws IOException { file.seek(pos); return readLong(); }
public AesZipFileDecrypter( File zipFile, AESDecrypter decrypter ) throws IOException { this.zipFile = zipFile; this.decrypter = decrypter; this.raFile = new ExtRandomAccessFile( zipFile ); initDirOffsetPosAndComment(); }
public int readInt(long pos) throws IOException { file.seek(pos); return readInt(); }
final int dirOffset = raFile.readInt( this.dirOffsetPos ); int censig = raFile.readInt( fileOffset ); if( censig!=CENSIG ) { throw new ZipException("expected CENSIC not found at entry no " + (i+1) + " in central directory at end of zip file at " + fileOffset); short fileNameLength = raFile.readShort( fileOffset + 28 ); short extraFieldLength = raFile.readShort( fileOffset + 30 ); long fileOffsetPos = fileOffset + 28 + 14; long fileDataOffset = raFile.readInt( fileOffsetPos ); int locsig = raFile.readInt( fileDataOffset ); if( locsig!=LOCSIG ) { throw new ZipException("expected LOCSIC not found at alleged position of data for file no " + (i+1)); byte[] fileNameBytes = raFile.readByteArray( fileOffsetPos+4, fileNameLength ); long nextFileOffset = raFile.getFilePointer(); String fileName = new String( fileNameBytes, charset ); zipEntry.setSize( cde.getUncompressedSize() ); long dosTime = raFile.readInt( fileOffset + 12 ); zipEntry.setTime( ExtZipEntry.dosToJavaTime(dosTime) );
int censig = raFile.readInt( fileOffset ); if( censig!=CENSIG ) { throw new ZipException("expected CENSIC not found in central directory (at end of zip file)"); short flag = raFile.readShort( fileOffset + 8 ); this.isEncrypted = (flag&1)>0; this.fileNameLength = raFile.readShort( fileOffset + 28 ); byte[] fileNameBytes = raFile.readByteArray( fileOffset + 46, fileNameLength ); this.fileName = new String( fileNameBytes, AesZipFileDecrypter.charset ); if( LOG.isLoggable(Level.FINE) ) { this.extraFieldLength = raFile.readShort( fileOffset + 30 ); this.localHeaderOffset = raFile.readInt( fileOffset + 28 + 14 ); byte[] efhid = raFile.readByteArray( this.extraFieldOffset, 2 ); if( efhid[0]!=0x01 || efhid[1]!=(byte)0x99 ) { this.extraFieldOffset = localHeaderOffset+30+fileNameLength; this.extraFieldLength = raFile.readShort( localHeaderOffset+28 ); if( LOG.isLoggable(Level.FINE) ) { LOG.fine( "local header - extraFieldOffset=" + Long.toHexString(this.extraFieldOffset) ); efhid = raFile.readByteArray( extraFieldOffset, 2); if( efhid[0]==0x01 && efhid[1]==(byte)0x99 ) { this.isAesEncrypted = true; this.actualCompressionMethod = raFile.readShort( getExtraFieldOffset() + 9 ); this.localHeaderSize = 30 + getExtraFieldLength() + getFileNameLength();
byte[] salt = raFile.readByteArray(cryptoHeaderOffset, 16); byte[] pwVerification = raFile.readByteArray(cryptoHeaderOffset + 16, 2); if (LOG.isLoggable(Level.FINEST)) { LOG.finest("\n" + cde.toString()); tmpEntry.setCompressedSize(zipEntry.getEncryptedDataSize()); zos.putNextEntry(tmpEntry); raFile.seek(cde.getOffset()); byte[] buffer = new byte[bufferSize]; int remaining = (int) zipEntry.getEncryptedDataSize(); while (remaining > 0) { int len = (remaining > buffer.length) ? buffer.length : remaining; int read = raFile.readByteArray(buffer, len); decrypter.decrypt(buffer, read); zos.writeBytes(buffer, 0, read); raFile.readByteArray(storedMac, 10); byte[] calcMac = decrypter.getFinalAuthentication(); if (LOG.isLoggable(Level.FINE)) {
/** number of entries in file (files AND directories) */ public short getNumberOfEntries() throws IOException { return raFile.readShort( this.dirOffsetPos-6 ); }
public long lastPosOf(byte[] bytesToFind) throws IOException { long out = -1; for( long seekPos=file.length()-1-bytesToFind.length; seekPos>3 && out==-1; seekPos-- ) { byte[] buffer = readByteArray(seekPos,bytesToFind.length); if( Arrays.equals(bytesToFind,buffer) ) { out = seekPos; } } return out; }
public long readLong(long pos) throws IOException { file.seek(pos); return readLong(); }
public AesZipFileDecrypter( File zipFile, AESDecrypter decrypter ) throws IOException { this.zipFile = zipFile; this.decrypter = decrypter; this.raFile = new ExtRandomAccessFile( zipFile ); initDirOffsetPosAndComment(); }
public int readInt(long pos) throws IOException { file.seek(pos); return readInt(); }