PE-sieve
Scans all running processes. Recognizes and dumps a variety of potentially malicious implants (replaced/implanted PEs, shellcodes, hooks, in-memory patches).
Loading...
Searching...
No Matches
console_color.cpp
Go to the documentation of this file.
1#include "console_color.h"
2#include <iostream>
3
4namespace pesieve {
5 namespace util {
6
7 bool get_current_color(int descriptor, WORD &color) {
8 CONSOLE_SCREEN_BUFFER_INFO info;
9 if (!GetConsoleScreenBufferInfo(GetStdHandle(descriptor), &info))
10 return false;
11 color = info.wAttributes;
12 return true;
13 }
14
15 }
16};
17
18void pesieve::util::print_in_color(int color, const std::string &text, bool is_error)
19{
20 int descriptor = is_error ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE;
21 std::ostream &stream = is_error ? std::cerr : std::cout;
22
23 WORD old_color = 7; //default
24 get_current_color(descriptor, old_color);
25
26 HANDLE hConsole = GetStdHandle(descriptor);
27 FlushConsoleInputBuffer(hConsole);
28 SetConsoleTextAttribute(hConsole, color); // back to default color
29
30 stream << text;
31
32 FlushConsoleInputBuffer(hConsole);
33 SetConsoleTextAttribute(hConsole, old_color); // back to default color
34 FlushConsoleInputBuffer(hConsole);
35
36 stream.flush();
37}
bool get_current_color(int descriptor, WORD &color)
void print_in_color(int color, const std::string &text, bool is_error=false)
std::string info()
The string with the basic information about the scanner.
Definition pe_sieve.cpp:274