bkcrack 1.7.1
Crack legacy zip encryption with Biham and Kocher's known plaintext attack.
Arguments.hpp
1#ifndef BKCRACK_ARGUMENTS_HPP
2#define BKCRACK_ARGUMENTS_HPP
3
4#include "Data.hpp"
5#include "Keys.hpp"
6#include "types.hpp"
7
8#include <limits>
9#include <map>
10#include <optional>
11
14{
15public:
17 class Error : public BaseError
18 {
19 public:
21 explicit Error(const std::string& description);
22 };
23
26 Arguments(int argc, const char* argv[]);
27
32 auto loadData() const -> Data;
33
34 std::optional<std::string> cipherFile;
35 std::optional<std::size_t> cipherIndex;
36 std::optional<std::string> cipherArchive;
37
38 std::optional<std::string> plainFile;
39 std::optional<std::size_t> plainIndex;
40 std::optional<std::string> plainArchive;
41
46 std::size_t plainFilePrefix = 1 << 20;
47
49 int offset = 0;
50
53 std::map<int, std::uint8_t> extraPlaintext;
54
56 bool ignoreCheckByte = false;
57
59 int attackStart = 0;
60
62 std::optional<std::string> password;
63
65 std::optional<Keys> keys;
66
68 std::optional<std::string> decipheredFile;
69
71 bool keepHeader = false;
72
74 std::optional<std::string> decryptedArchive;
75
78 {
79 std::string unlockedArchive;
80 std::string newPassword;
81 };
82
83 std::optional<ChangePassword> changePassword;
84
90 {
91 std::string unlockedArchive;
93 };
94
95 std::optional<ChangeKeys> changeKeys;
96
98 std::optional<std::vector<std::uint8_t>> bruteforce;
99
102 {
104 std::size_t minLength{0};
105
107 std::size_t maxLength{std::numeric_limits<std::size_t>::max()};
108
110 auto operator&(const LengthInterval& other) const -> LengthInterval;
111 };
112
113 std::optional<LengthInterval> length;
114
116 std::string recoveryStart;
117
119 int jobs;
120
122 bool exhaustive = false;
123
125 std::optional<std::string> infoArchive;
126
128 bool version = false;
129
131 bool help = false;
132
133private:
134 const char** m_current;
135 const char** const m_end;
136
137 auto finished() const -> bool;
138
139 void parseArgument();
140
141 enum class Option
142 {
146 plainFile,
150 offset,
154 password,
155 keys,
162 length,
163 recoverPassword,
165 jobs,
168 version,
169 help
170 };
171
172 auto readString(const std::string& description) -> std::string;
173 auto readOption(const std::string& description) -> Option;
174 auto readInt(const std::string& description) -> int;
175 auto readSize(const std::string& description) -> std::size_t;
176 auto readHex(const std::string& description) -> std::vector<std::uint8_t>;
177 auto readKey(const std::string& description) -> std::uint32_t;
178 auto readCharset() -> std::vector<std::uint8_t>;
179};
180
181#endif // BKCRACK_ARGUMENTS_HPP
Error(const std::string &description)
Constructor.
std::optional< std::string > infoArchive
Zip archive about which to display information.
Definition Arguments.hpp:125
std::optional< std::string > cipherFile
File containing the ciphertext.
Definition Arguments.hpp:34
Arguments(int argc, const char *argv[])
Constructor parsing command line arguments.
std::optional< std::string > decipheredFile
File to write the deciphered text corresponding to cipherFile.
Definition Arguments.hpp:68
std::optional< std::string > plainFile
File containing the known plaintext.
Definition Arguments.hpp:38
std::string recoveryStart
Starting point for password recovery.
Definition Arguments.hpp:116
std::optional< std::size_t > plainIndex
Index of the zip entry containing plaintext.
Definition Arguments.hpp:39
bool version
Tell whether version information is needed or not.
Definition Arguments.hpp:128
std::optional< std::string > decryptedArchive
File to write an unencrypted copy of the encrypted archive.
Definition Arguments.hpp:74
std::optional< Keys > keys
Internal password representation.
Definition Arguments.hpp:65
bool keepHeader
Tell whether to keep the encryption header or discard it when writing the deciphered text.
Definition Arguments.hpp:71
std::optional< std::string > password
Password from which to derive the internal password representation.
Definition Arguments.hpp:62
int attackStart
Staring point of the attack on Z values remaining after reduction.
Definition Arguments.hpp:59
int jobs
Number of threads to use for parallelized operations.
Definition Arguments.hpp:119
std::optional< ChangePassword > changePassword
Arguments needed to change an archive's password.
Definition Arguments.hpp:83
bool exhaustive
Tell whether to try all candidates (keys or passwords) exhaustively or stop after the first success.
Definition Arguments.hpp:122
bool ignoreCheckByte
Tell not to use the check byte derived from ciphertext entry metadata as known plaintext.
Definition Arguments.hpp:56
std::optional< ChangeKeys > changeKeys
Arguments needed to change an archive's internal password representation.
Definition Arguments.hpp:95
int offset
Plaintext offset relative to ciphertext without encryption header (may be negative)
Definition Arguments.hpp:49
std::optional< std::string > plainArchive
Zip archive containing plainFile.
Definition Arguments.hpp:40
std::map< int, std::uint8_t > extraPlaintext
Definition Arguments.hpp:53
std::size_t plainFilePrefix
Maximum number of bytes of plaintext to read from plainFile.
Definition Arguments.hpp:46
auto loadData() const -> Data
Load the data needed for an attack based on parsed arguments.
std::optional< std::vector< std::uint8_t > > bruteforce
Characters to generate password candidates.
Definition Arguments.hpp:98
std::optional< std::size_t > cipherIndex
Index of the zip entry containing ciphertext.
Definition Arguments.hpp:35
bool help
Tell whether help message is needed or not.
Definition Arguments.hpp:131
std::optional< std::string > cipherArchive
Zip archive containing cipherFile.
Definition Arguments.hpp:36
std::optional< LengthInterval > length
Range of password lengths to try during password recovery.
Definition Arguments.hpp:113
BaseError(const std::string &type, const std::string &description)
Constructor.
Keys defining the cipher state.
Definition Keys.hpp:10
Arguments needed to change an archive's internal password representation.
Definition Arguments.hpp:90
Keys newKeys
Internal password representation chosen to generate the new archive.
Definition Arguments.hpp:92
std::string unlockedArchive
File to write the new encrypted archive.
Definition Arguments.hpp:91
Arguments needed to change an archive's password.
Definition Arguments.hpp:78
std::string unlockedArchive
File to write the new encrypted archive.
Definition Arguments.hpp:79
std::string newPassword
Password chosen to generate the new archive.
Definition Arguments.hpp:80
Range of password lengths to try during password recovery.
Definition Arguments.hpp:102
std::size_t maxLength
Greatest password length to try (inclusive)
Definition Arguments.hpp:107
std::size_t minLength
Smallest password length to try (inclusive)
Definition Arguments.hpp:104
auto operator&(const LengthInterval &other) const -> LengthInterval
Compute the intersection between this interval and the given other interval.
Structure to hold the data needed for an attack.
Definition Data.hpp:10
Useful types, constants and utility functions.