bkcrack 1.7.1
Crack legacy zip encryption with Biham and Kocher's known plaintext attack.
Zip Class Reference

Open a zip archive, parse zip entries metadata and read raw content. More...

#include <Zip.hpp>

Classes

struct  Entry
 Information about a zip entry. More...
class  Error
 Exception thrown when parsing a zip file fails. More...
class  Iterator
 Single-pass input iterator that reads successive Entry objects. More...

Public Types

enum class  Encryption { None , Traditional , Unsupported }
 Encryption algorithm. More...
enum class  Compression {
  Store = 0 , Shrink = 1 , Implode = 6 , Deflate = 8 ,
  Deflate64 = 9 , BZip2 = 12 , LZMA = 14 , Zstandard = 93 ,
  MP3 = 94 , XZ = 95 , JPEG = 96 , WavPack = 97 ,
  PPMd = 98
}
 Compression algorithm. More...

Public Member Functions

 Zip (std::istream &stream)
 Open a zip archive from an already opened input stream.
 Zip (const std::string &filename)
 Open a zip archive from a file.
auto begin () const -> Iterator
 Get an iterator pointing to the first entry.
auto end () const -> Iterator
 Get an end-of-stream iterator.
auto operator[] (const std::string &name) const -> Entry
 Get the first entry having the given name.
auto operator[] (std::size_t index) const -> Entry
 Get the entry at the given index.
auto seek (const Entry &entry) const -> std::istream &
 Set the underlying stream's input position indicator at the beginning the given entry's raw data.
auto load (const Entry &entry, std::size_t count=std::numeric_limits< std::size_t >::max()) const -> std::vector< std::uint8_t >
 Load at most count bytes of the given entry's raw data.
void changeKeys (std::ostream &os, const Keys &oldKeys, const Keys &newKeys, Progress &progress) const
 Copy the zip file into os changing the encrypted data using the given keys.
void decrypt (std::ostream &os, const Keys &keys, Progress &progress) const
 Copy the zip file into os removing encryption using the given keys.

Static Public Member Functions

static void checkEncryption (const Entry &entry, Encryption expected)
 Check that the given entry uses the expected encryption algorithm.

Detailed Description

Open a zip archive, parse zip entries metadata and read raw content.

Note
Zip64 extensions are supported.
Known limitations

Spanned or split zip files are not supported.

Strong encryption (SES) is not supported. In particular, central directory encryption is not supported.

Language Encoding (EFS) is not supported. (APPNOTE.TXT, Appendix D)

See also
APPNOTE.TXT

Member Enumeration Documentation

◆ Compression

enum class Zip::Compression
strong

Compression algorithm.

Note
This enumeration is not exhaustive.

◆ Encryption

enum class Zip::Encryption
strong

Encryption algorithm.

Enumerator
None 

No encryption.

Traditional 

Traditional PKWARE encryption (ZipCrypto), vulnerable to known plaintext attack.

Unsupported 

Other encryption (DES, RC2, 3DES, AES, Blowfish, Twofish, RC4)

Constructor & Destructor Documentation

◆ Zip() [1/2]

Zip::Zip ( std::istream & stream)
explicit

Open a zip archive from an already opened input stream.

Exceptions
Errorif the given input stream is not a valid zip archive

◆ Zip() [2/2]

Zip::Zip ( const std::string & filename)
explicit

Open a zip archive from a file.

Exceptions
FileErrorif the file cannot be opened
Errorif the opened file is not a valid zip archive

Member Function Documentation

◆ changeKeys()

void Zip::changeKeys ( std::ostream & os,
const Keys & oldKeys,
const Keys & newKeys,
Progress & progress ) const

Copy the zip file into os changing the encrypted data using the given keys.

Exceptions
Errorif the archive is not a valid zip archive

◆ checkEncryption()

void Zip::checkEncryption ( const Entry & entry,
Encryption expected )
static

Check that the given entry uses the expected encryption algorithm.

Exceptions
Errorif the given entry does not use the expected encryption algorithm

◆ decrypt()

void Zip::decrypt ( std::ostream & os,
const Keys & keys,
Progress & progress ) const

Copy the zip file into os removing encryption using the given keys.

Exceptions
Errorif the archive is not a valid zip archive

◆ load()

auto Zip::load ( const Entry & entry,
std::size_t count = std::numeric_limits< std::size_t >::max() ) const -> std::vector< std::uint8_t >

Load at most count bytes of the given entry's raw data.

Exceptions
Errorif the given entry's data is not at the expected offset

◆ operator[]() [1/2]

auto Zip::operator[] ( const std::string & name) const -> Entry

Get the first entry having the given name.

Exceptions
Errorif the archive does not contain an entry with the given name

◆ operator[]() [2/2]

auto Zip::operator[] ( std::size_t index) const -> Entry

Get the entry at the given index.

Exceptions
Errorif the index is out of bounds

◆ seek()

auto Zip::seek ( const Entry & entry) const -> std::istream &

Set the underlying stream's input position indicator at the beginning the given entry's raw data.

Exceptions
Errorif the given entry's data is not at the expected offset

The documentation for this class was generated from the following file: