Skip to content

Commit acc38bc

Browse files
committed
Added command line argument parsing (boost::program_options)
1 parent 2d8fd5d commit acc38bc

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

UserPreferencesExplorer/UserPreferencesExplorer.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <openssl/evp.h>
88
#include <boost/algorithm/hex.hpp>
9+
#include <boost/program_options.hpp>
910

1011
#pragma comment(lib, "libeay32")
1112

@@ -228,22 +229,46 @@ std::string DecryptUserPreferences(const std::string& file_path, const std::stri
228229

229230
int main(int argc, char* argv[])
230231
{
232+
namespace po = boost::program_options;
231233
static const auto kSalt = std::string("6E3F032949637D2E");
232234

233235
try
234236
{
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+
);
238264

239-
auto decrypted_preferences = DecryptUserPreferences(user_preferences_path, machine_guid, salt);
240265
std::cout << decrypted_preferences << std::endl;
241266
}
242267
catch (const std::exception& ex)
243268
{
244269
std::cerr << "Failed to decrypt user preferences: " << ex.what() << std::endl;
245270
return EXIT_FAILURE;
246271
}
247-
272+
248273
return EXIT_SUCCESS;
249274
}

0 commit comments

Comments
 (0)