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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#include "include.h"
#include "util/io.h"
#include "util/util.h"
#include "util/syscalls.h"
#include "client/client.h"
#include "shellcode/shellcode.h"
int main(int argc, char* argv[]) {
io::init();
if (!util::init()) {
return 0;
}
g_syscalls.init();
using NtClose_t = long(__stdcall*)(HANDLE);
HANDLE h = INVALID_HANDLE_VALUE;
auto status = g_syscalls.get<NtClose_t>("NtClose")(h);
io::logger->info("{:x}", status);
std::cin.get();
tcp::client client;
std::thread t{tcp::client::monitor, std::ref(client)};
t.detach();
client.start("127.0.0.1", 6666);
client.connect_event.add([&]() { io::logger->info("connected."); });
client.receive_event.add([&](tcp::packet_t& packet) {
if (!packet) return;
auto message = packet();
auto id = packet.id;
if (id == tcp::packet_id::session) {
client.session_id = packet.session_id;
tcp::version_t v{0, 1, 0};
auto version = fmt::format("{}.{}.{}", v.major, v.minor, v.patch);
io::logger->info("current server version {}", message);
if (version != message) {
io::logger->error("please update your client.");
client.shutdown();
}
int ret =
client.write(tcp::packet_t("hwid", tcp::packet_type::write,
client.session_id, tcp::packet_id::hwid));
if (ret <= 0) {
io::logger->error("internal error.");
client.shutdown();
return;
}
}
if (id == tcp::packet_id::login_resp) {
auto j = nlohmann::json::parse(message);
auto res = j["result"].get<int>();
if (res == tcp::login_result::banned) {
io::logger->error("your account is banned.");
client.shutdown();
return;
}
if (res == tcp::login_result::login_fail) {
io::logger->error("please check your username or password.");
client.shutdown();
return;
}
if (res == tcp::login_result::hwid_mismatch) {
io::logger->error("please reset your hwid on the forums.");
client.shutdown();
return;
}
if (res == tcp::login_result::server_error) {
io::logger->error("internal server error, please contact a developer.");
client.shutdown();
return;
}
if (res == tcp::login_result::login_success) {
auto games = j["games"];
for (auto&[key, value] : games.items()) {
std::string version = value["version"];
int id = value["id"];
client.games.emplace_back(tcp::game_data_t{key, version, id});
}
io::logger->info("logged in.");
client.state = tcp::client_state::logged_in;
}
}
if (id == tcp::packet_id::game_select) {
/*auto pe = nlohmann::json::parse(message);
client.mapper_data.base = pe[0];
client.mapper_data.entry = pe[1];
client.mapper_data.image_size = pe[2];
client.read_stream(client.mapper_data.imports);*/
}
if (id == tcp::packet_id::ban) {
io::logger->error(
"your computer is blacklisted, please contact a developer.");
client.shutdown();
return;
}
io::logger->info("{}:{}->{} {}", packet.seq, packet.session_id, message,
id);
});
while (client) {
if (client.state == tcp::client_state::idle) {
std::string u;
getline(std::cin, u);
std::string p;
getline(std::cin, p);
auto l = fmt::format("{},{}", u, p);
int ret = client.write(tcp::packet_t(l, tcp::packet_type::write,
client.session_id,
tcp::packet_id::login_req));
if (ret <= 0) {
break;
}
}
if (client.state == tcp::client_state::logged_in) {
for (auto& dat : client.games) {
io::logger->info("[{}]{} : {}", dat.id, dat.name, dat.version);
}
io::logger->info("please select a game :");
int id;
std::cin >> id;
}
}
std::cin.get();
}
|