-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathcli.cpp
120 lines (103 loc) · 3.36 KB
/
cli.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
/*! @file
*
* This file contains the cli main functionality.
*/
// Includes.
#include "ini.h"
#include <iostream>
#include <cobf.hpp>
// Processed line handler.
void ini_line_handler(void* data, unsigned int line, const char* sec, const char* nam, const char* val)
{
// Cast the needed pointer.
cobf* p_obf_file = (cobf*)data;
cobf_error ret_err;
char error[MAX_PATH];
// Saving the old section.
static string s_sec = "";
if (sec)
{
// Get the dll name.
s_sec = sec;
return;
};
// Name/ordinals checking.
if (*nam != '#' && *val != '#') ret_err = p_obf_file->obf_sym(s_sec.c_str(), nam, val);
else if (*nam != '#' && *val == '#') ret_err = p_obf_file->obf_sym(s_sec.c_str(), nam, atoi(val + 1));
else if (*nam == '#' && *val != '#') ret_err = p_obf_file->obf_sym(s_sec.c_str(), atoi(nam + 1), val);
else ret_err = p_obf_file->obf_sym(s_sec.c_str(), atoi(nam + 1), atoi(val + 1));
// Check the error.
if (ret_err != cobf_error::COBF_NO_ERROR)
{
// Error at processing.
cobf_format_message(ret_err, error, sizeof(error));
cout << "[-] Error at the config at line " << line << ": " << error << endl;
};
};
// The main entry.
int main(int argc, char** argv)
{
// Expecting the input file, out file and the config file.
if (argc < 3 || argc > 4)
{
// Print help.
cout << *argv << " <input file> <out file> [config file]" << endl;
return 1;
};
// Getting the data.
char* input_file = argv[1];
char* out_file = argv[2];
char* config_file = argc == 4 ? argv[3] : (char*)"config.ini";
// Needed locals.
cobf_error ret_err;
char error[MAX_PATH];
try
{
// Loading the input file.
cobf obf_file = cobf(input_file);
if ((ret_err = obf_file.load_pe()) != cobf_error::COBF_NO_ERROR)
{
// Error at loading.
cobf_format_message(ret_err, error, sizeof(error));
cout << "[-] Error at loading the file: " << error << endl;
return 1;
};
// Log.
cout << "[+] File loaded successfully." << endl;
// Process the config file.
if (!parse_ini_file(config_file, ini_line_handler, &obf_file))
{
// Error at processing the config.
cout << "[-] Error occurred while processing the config file." << endl;
return 1;
};
// Obfuscating it.
if ((ret_err = obf_file.generate(out_file)) != cobf_error::COBF_NO_ERROR)
{
// Error at obfuscating.
cobf_format_message(ret_err, error, sizeof(error));
cout << "[-] Error at obfuscating the file: " << error << endl;
return 1;
};
// Log.
cout << "[+] File obfuscated successfully." << endl;
// Unloading it.
if ((ret_err = obf_file.unload_pe()) != cobf_error::COBF_NO_ERROR)
{
// Error at unloading.
cobf_format_message(ret_err, error, sizeof(error));
cout << "[-] Error at unloading the file: " << error << endl;
return 1;
};
// Log.
cout << "[+] File unloaded successfully." << endl;
}
catch (...)
{
// Log.
cout << "[!] Unhandled exception occurred." << endl;
return 1;
};
// Done.
return 0;
};