Commits

Andreas Tscharner committed 6cff434

Complete encryption: Get password from commandline (not only Encryption Type)

  • Participants
  • Parent commits a664194

Comments (0)

Files changed (1)

src/compiler/lrc.cxx

 {
 	std::cout << "lrc - Linux Resource Compiler\n";
 	std::cout << "A resource compiler for Linux (Version " << VERSION << ")\n\n";
-	std::cout << "Usage:\n" << argv[0] << " [-d] [-o <rdfFile>] [-c <compression type>] [-e <encryption type>] <RCFile>\n";
+	std::cout << "Usage:\n" << argv[0] << " [-d] [-o <rdfFile>] [-c <compression type>] [-e <encryption type> -p <password>] <RCFile>\n";
 	std::cout << "\t-h\t\t\tShow this help screen\n";
 	std::cout << "\t-d\t\t\tDeny overwriting (optional)\n";
 	std::cout << "\t-o <rdfFile>\t\tDefine final resource data file (optional)\n";
 	std::cout << "\t-c <compression type>\tDefine compression type for the whole file\n";
 	std::cout << "\t-e <encryption type>\tDefine encryption type for the whole file\n";
+	std::cout << "\t-p <password>\tPassword when encryption is used (ignored otherwise)\n";
 	std::cout << "\t<RCFile>\t\tInput file in RC format (mandatory)\n";
 }
 
 	char *rdfFile = nullptr;
 	char *compressType = nullptr;
 	char *encryptType = nullptr;
+	char *pwdStr = nullptr;
+	unsigned char *password = nullptr;
 	bool allowOverwrite = true;
 	lrc::CompressionType complCompress = lrc::NoneCompression;
 	lrc::EncryptionType complEncrypt = lrc::NoneEncryption;
 		return -1;
 	};
 
-	while ((optRet = getopt(argc, argv, "dho:c:e:")) != -1) {
+	while ((optRet = getopt(argc, argv, "dho:c:e:p:")) != -1) {
 		switch (optRet) {
 			case 'o' :
 				rdfFile = new char[strlen(optarg)+1];
 				strncpy(encryptType, optarg, (strlen(optarg)));
 				break;
 
+			case 'p' :
+				pwdStr = new char[strlen(optarg)+1];
+				memset(pwdStr, 0, (strlen(optarg)+1));
+				strncpy(pwdStr, optarg, (strlen(optarg)));
+				break;
+
 			case 'd' :
 				allowOverwrite = false;
 				break;
 			std::cout << "An encryption type must be defined with option -e\n";
 			return -1;
 		};
+		if (!pwdStr) {
+			std::cout << "A password must be provided if encryption is desired\n";
+			return -1;
+		};
 		complEncrypt = InFileParser::eval_encryption_type(encryptType);
+		try {
+			password = InFileParser::get_password(pwdStr);
+		} catch (lrcFileNotFoundException const &fnfEx) {
+			std::cout << "Password file provided in password string not found (" << fnfEx.what() << ")\n";
+			return -1;
+		};
+	} else {
+		if (pwdStr) {
+			delete[] pwdStr;
+		};
 	};
 
 	inputFile = new char[strlen(argv[optind])+1];
 		return -1;
 	};
 
-	errVal = inputDataCollector->collect(inputFileParser->get_resource_entries(), complCompress);
+	errVal = inputDataCollector->collect(inputFileParser->get_resource_entries(), complCompress, complEncrypt, password);
 	if (errVal < 0) {
 		std::cout << "Compiler exited with code " << errVal << "\n";
 		return -1;