|
6 | 6 |
|
7 | 7 | #include <openssl/evp.h> |
8 | 8 | #include <boost/algorithm/hex.hpp> |
| 9 | +#include <boost/program_options.hpp> |
9 | 10 |
|
10 | 11 | #pragma comment(lib, "libeay32") |
11 | 12 |
|
@@ -228,22 +229,46 @@ std::string DecryptUserPreferences(const std::string& file_path, const std::stri |
228 | 229 |
|
229 | 230 | int main(int argc, char* argv[]) |
230 | 231 | { |
| 232 | + namespace po = boost::program_options; |
231 | 233 | static const auto kSalt = std::string("6E3F032949637D2E"); |
232 | 234 |
|
233 | 235 | try |
234 | 236 | { |
235 | | - auto user_preferences_path = GetPathToUserPreferencesBag(); |
236 | | - auto machine_guid = GetMachineGuid(); |
237 | | - auto salt = kSalt; |
| 237 | + auto arg_salt = po::value<std::string>()->default_value(kSalt, ""); |
| 238 | + auto arg_guid = po::value<std::string>()->default_value(GetMachineGuid(), ""); |
| 239 | + auto arg_path = po::value<std::string>()->default_value(GetPathToUserPreferencesBag(), ""); |
| 240 | + |
| 241 | + auto commandline_descriptions = po::options_description("Arguments"); |
| 242 | + commandline_descriptions.add_options() |
| 243 | + ("help", "Help") |
| 244 | + ("salt", arg_salt, "Salt used for key generation.") |
| 245 | + ("guid", arg_guid, "GUID used for key generation.") |
| 246 | + ("path", arg_path, "Path to the UserPreferences.bag to decrypt."); |
| 247 | + |
| 248 | + auto parsed_options = po::parse_command_line(argc, argv, commandline_descriptions); |
| 249 | + po::variables_map vm; |
| 250 | + po::store(parsed_options, vm); |
| 251 | + po::notify(vm); |
| 252 | + |
| 253 | + if (vm.count("help")) |
| 254 | + { |
| 255 | + std::cout << commandline_descriptions << std::endl; |
| 256 | + return EXIT_SUCCESS; |
| 257 | + } |
| 258 | + |
| 259 | + auto decrypted_preferences = DecryptUserPreferences( |
| 260 | + vm["path"].as<std::string>(), |
| 261 | + vm["guid"].as<std::string>(), |
| 262 | + vm["salt"].as<std::string>() |
| 263 | + ); |
238 | 264 |
|
239 | | - auto decrypted_preferences = DecryptUserPreferences(user_preferences_path, machine_guid, salt); |
240 | 265 | std::cout << decrypted_preferences << std::endl; |
241 | 266 | } |
242 | 267 | catch (const std::exception& ex) |
243 | 268 | { |
244 | 269 | std::cerr << "Failed to decrypt user preferences: " << ex.what() << std::endl; |
245 | 270 | return EXIT_FAILURE; |
246 | 271 | } |
247 | | - |
| 272 | + |
248 | 273 | return EXIT_SUCCESS; |
249 | 274 | } |
0 commit comments