HollowsHunter
Scans all running processes. Recognizes and dumps a variety of potentially malicious implants (replaced/implanted PEs, shellcodes, hooks, in-memory patches).
Toggle main menu visibility
Loading...
Searching...
No Matches
term_util.cpp
Go to the documentation of this file.
1
#include "
term_util.h
"
2
3
#include <windows.h>
4
5
#include <iostream>
6
#include <string>
7
#include <mutex>
8
#include <paramkit.h>
9
10
std::mutex
g_stdOutMutex
;
11
12
bool
hh::util::get_current_color
(
int
descriptor, WORD &color)
13
{
14
HANDLE hConsole = GetStdHandle(descriptor);
15
if
(hConsole == INVALID_HANDLE_VALUE || hConsole == NULL) {
16
return
false
;
17
}
18
return
paramkit::get_console_color(hConsole, color);
19
}
20
21
WORD
hh::util::set_color
(WORD color)
22
{
23
WORD old_color = 7;
24
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
25
if
(hConsole == INVALID_HANDLE_VALUE || hConsole == NULL) {
26
return
old_color;
27
}
28
if
(paramkit::get_console_color(hConsole, old_color)) {
29
SetConsoleTextAttribute(hConsole, color);
30
}
31
return
old_color;
32
}
33
34
void
hh::util::print_in_color
(WORD color,
const
std::string &text)
35
{
36
const
std::lock_guard<std::mutex> stdOutLock(
g_stdOutMutex
);
37
paramkit::print_in_color(color, text);
38
}
39
40
std::string
hh::util::wstring_to_utf8
(
const
std::wstring& wstr)
41
{
42
if
(wstr.empty())
43
return
{};
44
45
int
size = WideCharToMultiByte(
46
CP_UTF8,
47
0,
48
wstr.data(),
49
static_cast<
int
>
(wstr.size()),
50
nullptr
,
51
0,
52
nullptr
,
53
nullptr
);
54
55
if
(size == 0) {
56
//throw std::runtime_error("WideCharToMultiByte failed");
57
std::wcerr <<
"WideCharToMultiByte failed for: "
<< wstr << std::endl;
58
return
{};
59
}
60
61
62
std::string result(size,
'\0'
);
63
64
int
converted = WideCharToMultiByte(
65
CP_UTF8,
66
0,
67
wstr.data(),
68
static_cast<
int
>
(wstr.size()),
69
result.data(),
70
size,
71
nullptr
,
72
nullptr
);
73
74
if
(converted == 0) {
75
//throw std::runtime_error("WideCharToMultiByte failed");
76
std::wcerr <<
"WideCharToMultiByte failed for: "
<< wstr << std::endl;
77
return
{};
78
}
79
return
result;
80
}
81
82
83
std::wstring
hh::util::utf8_to_wstring
(
const
std::string& utf8)
84
{
85
if
(utf8.empty())
86
return
{};
87
88
int
size = MultiByteToWideChar(
89
CP_UTF8,
90
0,
91
utf8.data(),
92
static_cast<
int
>
(utf8.size()),
93
nullptr
,
94
0);
95
96
if
(size == 0) {
97
//throw std::runtime_error("MultiByteToWideChar failed");
98
std::cerr <<
"MultiByteToWideChar failed for: "
<< utf8 << std::endl;
99
return
{};
100
}
101
102
std::wstring result(size, L
'\0'
);
103
104
int
converted = MultiByteToWideChar(
105
CP_UTF8,
106
0,
107
utf8.data(),
108
static_cast<
int
>
(utf8.size()),
109
result.data(),
110
size);
111
112
if
(converted == 0) {
113
std::cerr <<
"MultiByteToWideChar failed for: "
<< utf8 << std::endl;
114
return
{};
115
}
116
return
result;
117
}
hh::util::get_current_color
bool get_current_color(int descriptor, WORD &color)
Definition
term_util.cpp:12
hh::util::print_in_color
void print_in_color(WORD color, const std::string &text)
Definition
term_util.cpp:34
hh::util::utf8_to_wstring
std::wstring utf8_to_wstring(const std::string &utf8)
Definition
term_util.cpp:83
hh::util::set_color
WORD set_color(WORD color)
Definition
term_util.cpp:21
hh::util::wstring_to_utf8
std::string wstring_to_utf8(const std::wstring &wstr)
Definition
term_util.cpp:40
g_stdOutMutex
std::mutex g_stdOutMutex
Definition
term_util.cpp:10
term_util.h
Generated by
1.17.0