-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.cpp
132 lines (118 loc) · 4.69 KB
/
main.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
#include <iostream>
#include "headers/main.h"
#include "headers/Algorithm.h"
using namespace std;
void banner(){
cout <<
"\033[1;92m ___ ___ .__ .___ .___ __ __ \n"
" / | \\|__| __| _/__| _/____ ____/ \\ / \\________ __ ____ \n"
"/ ~ \\ |/ __ |/ __ |/ __ \\ / \\ \\/\\/ /\\__ \\ \\/ // __ \\ \n"
"\\ Y / / /_/ / /_/ \\ ___/| | \\ / / __ \\ /\\ ___/ \n"
" \\___|_ /|__\\____ \\____ |\\___ >___| /\\__/\\ / (____ /\\_/ \\___ >\n"
" \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ \n"
" \033[92mHide Your Secret Files in Audio Files.\033[0m\n\n"
" [Author: \033[1;92mTheHackersBrain\033[0m]\n\n";
}
void help(string packageName){
cout << "Usage: " << packageName << " [-h] [-i AUDIOFILE] [-m SECRETMSG] [-o OUTFILE]\n\nArguments:\n"
" -h Show this help message and exit\n"
" -i INPUTFILE Select Audio File\n"
" -m SECRETMSG Enter Your Message\n"
" -f SECRETFILE Select the Secret File\n"
" -o OUTPUTFILE Name of the output file (with .wav extension)\n\n" << endl;
}
int argsHandler(int argc, char** argv) {
// int mode; // hide mode (message)
if (argc == 7) {
if ((string) argv[1] == "-i" && (string) argv[3] == "-m" && (string) argv[5] == "-o") {
return 1; // hide mode (message)
} else if ((string) argv[1] == "-i" && (string) argv[3] == "-f" && (string) argv[5] == "-o") {
return 3; // hide mode (file)
} else {
help((string) argv[0]);
}
} else if (argc == 3) {
if ((string) argv[1] == "-i") {
return 2; // extract mode (message or file)
} else {
help((string) argv[0]);
exit(0);
}
}
else {
help((string) argv[0]);
exit(0);
}
return 0;
}
int fileHandler(int mode, char** argv) {
string message, outfile, fileExt, inputExt, inputfile;
inputfile = (string) argv[2];
ifstream binStreamFile;
streampos binFileSize;
vector<char> msgBuffer;
if (mode == 3) {
fileExt = GetFileExtension(string(argv[4]));
inputExt = GetFileExtension(string(argv[2]));
binStreamFile.open(string(argv[4]), ios::binary);
binFileSize = binStreamFile.tellg();
msgBuffer.reserve(binFileSize); // Reserve the amount of memory for file size on vector.
}
// loading the input file in the stream
ifstream input(inputfile, ios::binary);
if (!input.is_open()) {
cout << "[\033[0;91m-\033[0;0m] \033[0;91mError Encountered while opening the file...\033[0;0m" << endl;
return 0;
}
// copying the audio file into a buffer and closing it.
vector<char> buffer((istreambuf_iterator<char>(input)), (istreambuf_iterator<char>()));
if (mode == 3) {
msgBuffer.assign((istreambuf_iterator<char>(binStreamFile)), (istreambuf_iterator<char>()));
binStreamFile.close();
}
input.close();
// Modes:
// 1 => Hide a String
// 2 => Hide a File or Binary
// 3 => Extract the file
if (mode == 1) {
message = (string) argv[4];
inputExt = GetFileExtension((string) argv[2]);
int status = PlayWithWaveBuffer(buffer, message, inputExt);
if (status == SUCCESS) {
cout << "[\033[0;92m+\033[0;0m] \033[0;92mData Hidden Successfully...\033[0;0m\n[\033[0;92m+\033[0;0m] \033[0;92mCleaning Memory...\033[0;0m" << endl;
} else if (status == ERROR) {
cout << "[\033[0;91m-\033[0;0m] \033[0;91mSomething went wrong...\033[0;0m\n[\033[0;92m+\033[0;0m] \033[0;92mCleaning Memory...\033[0;0m" << endl;
}
} else if (mode == 3) {
int status = PlayWithWaveBuffer(buffer, msgBuffer, fileExt, inputExt);
if (status == SUCCESS) {
cout << "[\033[0;92m+\033[0;0m] \033[0;92mData Hidden Successfully...\033[0;0m\n[\033[0;92m+\033[0;0m] \033[0;92mCleaning Memory...\033[0;0m" << endl;
} else if (status == ERROR) {
cout << "[\033[0;91m-\033[0;0m] \033[0;91mSomething went wrong...\033[0;0m\n[\033[0;92m+\033[0;0m] \033[0;92mCleaning Memory...\033[0;0m" << endl;
}
} else if (mode == 2) {
int status = FindHiddenMessage(buffer);
if (status == SUCCESS) {
cout << "[\033[0;92m+\033[0;0m] \033[0;92mData Extracted Successfully...\033[0;0m\n[\033[0;92m+\033[0;0m] \033[0;92mCleaning Memory...\033[0;0m" << endl;
} else if (status == ERROR) {
cout << "[\033[0;91m-\033[0;0m] \033[0;91mSomething went wrong...\033[0;0m\n[\033[0;92m+\033[0;0m] \033[0;92mCleaning Memory...\033[0;0m" << endl;
}
}
// Force remove the buffer from memory
vector<char>().swap(buffer);
vector<char>().swap(msgBuffer);
return 0;
}
int main(int argc, char** argv) {
banner();
int mode = argsHandler(argc, argv);
fileHandler(mode, argv);
return 0;
}
string GetFileExtension(const string& fileName) {
if (fileName.find_last_of(".") != string::npos) {
return fileName.substr(fileName.find_last_of(".") + 1);
}
return "";
}