summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2021-08-27 14:06:31 -0400
committerPikalaxALT <pikalaxalt@gmail.com>2021-08-27 14:06:31 -0400
commit1f3cb973364af318f05bbcd5a906713b46ddc59a (patch)
tree00ee94798e60584e9aaf8c6c1e5a98eae66292ed
parent5b36a2d17aa4a2e0b7ee108b9ec479629c79e3e9 (diff)
Add msgenc -D switch
-rw-r--r--tools/msgenc/MessagesConverter.cpp14
-rw-r--r--tools/msgenc/MessagesConverter.h2
-rw-r--r--tools/msgenc/msgenc.cpp6
3 files changed, 22 insertions, 0 deletions
diff --git a/tools/msgenc/MessagesConverter.cpp b/tools/msgenc/MessagesConverter.cpp
index cb07f1a9..ff75f7d7 100644
--- a/tools/msgenc/MessagesConverter.cpp
+++ b/tools/msgenc/MessagesConverter.cpp
@@ -80,4 +80,18 @@ uint16_t MessagesConverter::CalcCRC()
return crc;
}
+void MessagesConverter::WriteBinaryDecoded(string &filename)
+{
+ ofstream outfile(filename, ios::binary);
+ if (!outfile.good()) {
+ throw ios::failure("Unable to open file " + filename + " for writing");
+ }
+ outfile.write((char *)&header, sizeof(header));
+ outfile.write((char *)alloc_table.data(), alloc_table.size() * sizeof(MsgAlloc));
+ for (auto msg : vec_encoded) {
+ outfile.write((char *)msg.data(), msg.size() * 2);
+ }
+ outfile.close();
+}
+
MessagesConverter::~MessagesConverter() = default;
diff --git a/tools/msgenc/MessagesConverter.h b/tools/msgenc/MessagesConverter.h
index 7d7fb887..ad1ba5f6 100644
--- a/tools/msgenc/MessagesConverter.h
+++ b/tools/msgenc/MessagesConverter.h
@@ -96,6 +96,8 @@ public:
uint16_t GetKey() {
return header.key;
}
+
+ void WriteBinaryDecoded(string &filename);
};
#endif //GUARD_MESSAGESCONVERTER_H
diff --git a/tools/msgenc/msgenc.cpp b/tools/msgenc/msgenc.cpp
index 1d2097be..5caaf31c 100644
--- a/tools/msgenc/msgenc.cpp
+++ b/tools/msgenc/msgenc.cpp
@@ -25,6 +25,7 @@ static inline void usage() {
cout << "-k KEY The 16-bit encryption key for this message bank. Default: computes it from the binary file name" << endl;
cout << "-v Print the program version and exit." << endl;
cout << "-h Print this message and exit." << endl;
+ cout << "-D DUMPNAME Dump the intermediate binary (after decryption or before encryption)." << endl;
}
struct Options {
@@ -35,6 +36,7 @@ struct Options {
string charmap;
bool printUsage = false;
bool printVersion = false;
+ string dumpBinary;
Options(int argc, char ** argv) {
for (int i = 1; i < argc; i++) {
string arg(argv[i]);
@@ -55,6 +57,8 @@ struct Options {
key |= 0x10000;
} else if (arg == "-c") {
charmap = argv[++i];
+ } else if (arg == "-D") {
+ dumpBinary = argv[++i];
} else if (arg[0] != '-') {
posargs.push_back(arg);
} else {
@@ -100,6 +104,8 @@ int main(int argc, char ** argv) {
converter->ReadInput();
converter->ReadCharmap();
converter->Convert();
+ if (!options.dumpBinary.empty())
+ converter->WriteBinaryDecoded(options.dumpBinary);
converter->WriteOutput();
if (options.mode == CONV_DECODE) {
cout << "Key: " << hex << converter->GetKey() << endl;