/
genericconsole.cpp
122 lines (105 loc) · 2.63 KB
/
genericconsole.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
#include "genericconsole.h"
#include <stdlib.h>
#include <string>
#include "windows_wrap.h"
using std::bind;
namespace Common
{
GenericConsole::GenericConsole()
{
AddCommand("color", &GenericConsole::Color);
AddCommand("cls", &GenericConsole::Cls);
AddCommand("quit", &GenericConsole::Quit);
AddCommand("exit", &GenericConsole::Quit);
AddCommand("crash", &GenericConsole::Crash);
AddCommand("int3", &GenericConsole::Int3);
AddCommand("echo", &GenericConsole::Echo);
AddCommand("pid", &GenericConsole::Pid);
AddCommand("term", &GenericConsole::Terminate);
AddCommand("terminate", &GenericConsole::Terminate);
AddCommand("help", &GenericConsole::Cmds);
AddCommand("cmds", &GenericConsole::Cmds);
AddCommand("sleep", &GenericConsole::Sleep);
}
bool GenericConsole::Sleep(const CmdArgs &args)
{
auto amt = atoi(args[1]);
::Sleep(amt);
return true;
}
bool GenericConsole::Cmds(const CmdArgs &args)
{
std::string buf = "";
for (const auto &pair : commands)
{
buf += pair.first;
buf.push_back(' ');
}
Print(buf);
return true;
}
bool GenericConsole::Terminate(const CmdArgs &args)
{
TerminateProcess(GetCurrentProcess(), 0);
return false; // Well, returning here is certainly a failure
}
bool GenericConsole::Pid(const CmdArgs &args)
{
auto pid = GetCurrentProcessId();
Printf("%d %x", pid, pid);
return true;
}
bool GenericConsole::Color(const CmdArgs &args)
{
uint8_t color = (uint8_t)strtoul(args[2], 0, 16);
if (strcmp(args[1], "bg") == 0)
colors[Color::bg] = color;
else if (strcmp(args[1], "text") == 0)
colors[Color::text] = color;
else if (strcmp(args[1], "own") == 0)
colors[Color::own] = color;
else if (strcmp(args[1], "border") == 0)
colors[Color::border] = color;
else if (strcmp(args[1], "typo") == 0)
colors[Color::typo] = color;
else if (strcmp(args[1], "fail") == 0)
colors[Color::fail] = color;
else
return false;
dirty = true;
return true;
}
bool GenericConsole::Cls(const CmdArgs &args)
{
ClearScreen();
return true;
}
bool GenericConsole::Quit(const CmdArgs &args)
{
exit(0);
return true;
}
bool GenericConsole::Crash(const CmdArgs &args)
{
*(int *)42 = 42;
return true;
}
bool GenericConsole::Int3(const CmdArgs &args)
{
INT3();
return true;
}
bool GenericConsole::Echo(const CmdArgs &args)
{
int i = 0;
std::string str;
while (strcmp(args[i], "") != 0)
{
if (!str.empty())
str += ' ';
str += args[++i];
}
Print(str);
return true;
}
} // namespace console