-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.cpp
183 lines (171 loc) · 6.11 KB
/
commands.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// commands.cpp
#include "headers/commands.h"
#include "headers/writedatatofile.h"
#include "headers/writefiletodata.h"
#include "headers/hexthrutable.h"
#include "headers/tabletohex.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <lib/nlohmann/json.hpp>
// Define constants for application info
const std::string APP_NAME = "HeXIP";
const std::string APP_VERSION = "Proof Of Concept - 0.0.0.1";
const std::string APP_DESCRIPTION = "Archiving solution for paranoid people.";
const std::string APP_AUTHOR = "KRWCLASSIC";
void printHelp() {
std::cout << "Usage: hexip <command> [options]\n";
std::cout << "Available commands:\n";
std::cout << "metadata [removeall | clean | add | remove | read]\n";
std::cout << "archive [encrypt/create/pack | decrypt/unpack | test | read]\n";
std::cout << "analyze\n";
std::cout << "convert\n";
std::cout << "extract\n";
std::cout << "editor\n";
std::cout << "security [add | remove | removeall]\n";
std::cout << "hash [verify | calculate]\n";
std::cout << "help\n";
std::cout << "wdtf <file1,file2,...> or <folder>\n";
std::cout << "wftd <input_file>\n";
std::cout << "hexthrutable <input_file> <output_file>\n";
std::cout << "tabletohex <input_file> <output_file>\n";
}
void handleMetadataCommand(const std::vector<std::string>& args) {
if (args.size() < 2) {
std::cout << "Metadata command requires a subcommand.\n";
return;
}
std::string subcommand = args[1];
if (subcommand == "removeall") {
std::cout << "Command: metadata removeall\n";
} else if (subcommand == "clean") {
std::cout << "Command: metadata clean\n";
} else if (subcommand == "add") {
std::cout << "Command: metadata add\n";
} else if (subcommand == "remove") {
std::cout << "Command: metadata remove\n";
} else if (subcommand == "read") {
std::cout << "Command: metadata read\n";
} else {
std::cout << "Unknown metadata subcommand.\n";
}
}
void handleArchiveCommand(const std::vector<std::string>& args) {
if (args.size() < 2) {
std::cout << "Archive command requires a subcommand.\n";
return;
}
std::string subcommand = args[1];
if (subcommand == "encrypt" || subcommand == "create" || subcommand == "pack") {
std::cout << "Command: archive " << subcommand << "\n";
} else if (subcommand == "decrypt" || subcommand == "unpack") {
std::cout << "Command: archive " << subcommand << "\n";
} else if (subcommand == "test") {
std::cout << "Command: archive test\n";
} else if (subcommand == "read") {
std::cout << "Command: archive read\n";
} else {
std::cout << "Unknown archive subcommand.\n";
}
}
void handleSecurityCommand(const std::vector<std::string>& args) {
if (args.size() < 2) {
std::cout << "Security command requires a subcommand.\n";
return;
}
std::string subcommand = args[1];
if (subcommand == "add") {
std::cout << "Command: security add\n";
} else if (subcommand == "remove") {
std::cout << "Command: security remove\n";
} else if (subcommand == "removeall") {
std::cout << "Command: security removeall\n";
} else {
std::cout << "Unknown security subcommand.\n";
}
}
void handleHashCommand(const std::vector<std::string>& args) {
if (args.size() < 2) {
std::cout << "Hash command requires an action.\n";
return;
}
std::string action = args[1];
if (action == "verify") {
std::cout << "Command: hash verify\n";
} else if (action == "calculate") {
std::cout << "Command: hash calculate\n";
} else {
std::cout << "Unknown hash action.\n";
}
}
void handleWriteDataToFile(const std::vector<std::string>& args) {
if (args.size() < 2) {
std::cout << "Usage: hexip wdtf <file1,file2,...> or <folder1,folder2,...> or <file1,folder1,...>\n";
return;
}
std::string input = args[1];
for (size_t i = 2; i < args.size(); ++i) {
input += "," + args[i];
}
writeDataToFile(input);
}
void handleWriteFileToData(const std::vector<std::string>& args) {
if (args.size() < 2) {
std::cout << "Usage: hexip wftd <input_file>\n";
return;
}
std::string inputFile = args[1];
writeFileToData(inputFile);
}
void handleInfoCommand() {
std::cout << "Application Name: " << APP_NAME << "\n";
std::cout << "Version: " << APP_VERSION << "\n";
std::cout << "Description: " << APP_DESCRIPTION << "\n";
std::cout << "Author: " << APP_AUTHOR << "\n";
}
void handleCommand(const std::vector<std::string>& args) {
if (args.empty()) {
printHelp();
return;
}
std::string command = args[0];
if (command == "help") {
printHelp();
} else if (command == "metadata") {
handleMetadataCommand(args);
} else if (command == "archive") {
handleArchiveCommand(args);
} else if (command == "analyze") {
std::cout << "Command: analyze\n";
} else if (command == "convert") {
std::cout << "Command: convert\n";
} else if (command == "extract") {
std::cout << "Command: extract\n";
} else if (command == "editor") {
std::cout << "Command: editor\n";
} else if (command == "security") {
handleSecurityCommand(args);
} else if (command == "hash") {
handleHashCommand(args);
} else if (command == "wdtf") {
handleWriteDataToFile(args);
} else if (command == "wftd") {
handleWriteFileToData(args);
} else if (command == "hexthrutable") {
if (args.size() < 3) {
std::cout << "Usage: hexip hexthrutable <input_file> <output_file>\n";
return;
}
hexThruTable(args[1], args[2]);
} else if (command == "tabletohex") {
if (args.size() < 3) {
std::cerr << "Usage: hexip tabletohex <input_file> <output_file>" << std::endl;
return;
}
tableToHex(args[1], args[2]);
} else if (command == "info") {
handleInfoCommand();
} else {
std::cout << "Unknown command: " << command << "\n";
}
}