17 #include "encrypt_string.h"
19 #include "panda_getopt.h"
20 #include "preprocess_argv.h"
23 bool got_password =
false;
29 <<
" pdecrypt file.pe [file2.pe file3.pe ...]\n"
30 <<
" pdecrypt -o dest_file file.pe\n\n"
33 <<
"This program reverses the operation of a previous pencrypt command. It\n"
34 <<
"decrypts the contents of the named source file(s) and removes the .pe\n"
35 <<
"extension. The encryption algorithm need not be specified; it can be\n"
36 <<
"determined by examining the header of each encrypted file. The password\n"
37 <<
"must match the encryption password exactly. If it does not, an error may\n"
38 <<
"or may not be reported; but the file will not be decrypted correctly even\n"
39 <<
"if no error is reported.\n\n"
43 <<
" -p \"password\"\n"
44 <<
" Specifies the password to use for decryption. If this is not specified,\n"
45 <<
" the user is prompted from standard input.\n\n";
49 main(
int argc,
char **argv) {
55 const char *optstr =
"o:p:h";
58 bool got_dest_filename =
false;
60 preprocess_argv(argc, argv);
61 int flag = getopt(argc, argv, optstr);
67 got_dest_filename =
true;
81 flag = getopt(argc, argv, optstr);
92 if (got_dest_filename && argc > 2) {
93 cerr <<
"Only one input file allowed in conjunction with -o.\n";
98 for (
int i = 1; i < argc; i++) {
100 if (!got_dest_filename && source_file.
get_extension() !=
"pe") {
102 <<
" doesn't end in .pe; can't derive filename of output file.\n";
107 if (!got_dest_filename) {
112 pifstream read_stream;
114 if (!source_file.
open_read(read_stream)) {
115 cerr <<
"Couldn't read: " << source_file << endl;
120 pofstream write_stream;
122 if (!dest_file.
open_write(write_stream,
true)) {
123 cerr <<
"Failed to open: " << dest_file << endl;
129 cerr <<
"Enter password: ";
130 getline(cin, password);
134 cerr << dest_file <<
"\n";
135 bool success = decrypt_stream(read_stream, write_stream, password);
138 write_stream.close();
141 cerr <<
"Failure decrypting " << source_file <<
"\n";
146 if (!got_dest_filename) {
147 source_file.unlink();
string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
void set_binary()
Indicates that the filename represents a binary file.
bool open_read(ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
The name of a file, such as a texture file or an Egg file.
bool open_write(ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
string get_extension() const
Returns the file extension.
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).