aboutsummaryrefslogtreecommitdiff
path: root/client/src
diff options
context:
space:
mode:
authorauth12 <[email protected]>2020-08-28 17:02:54 +0100
committerauth12 <[email protected]>2020-08-28 17:02:54 +0100
commit1b7783f8e0b864d81c8ab7bb4d83cd2f789b0d48 (patch)
treeda0324fe611754ac7a816c9a96eafa84a8cf5e4b /client/src
parentImproved CPU usage drastically. (diff)
downloadloader-1b7783f8e0b864d81c8ab7bb4d83cd2f789b0d48.tar.xz
loader-1b7783f8e0b864d81c8ab7bb4d83cd2f789b0d48.zip
Added version checks on server.
Changed main thread behaviour. Fixed events bug where packet seq would get corrupted. Changed session packet behaviour.
Diffstat (limited to 'client/src')
-rw-r--r--client/src/client/client.h17
-rw-r--r--client/src/client/packet.h1
-rw-r--r--client/src/main.cpp105
-rw-r--r--client/src/security/security.cpp34
-rw-r--r--client/src/ui/ui.cpp4
-rw-r--r--client/src/util/events.h4
-rw-r--r--client/src/util/io.cpp2
-rw-r--r--client/src/util/io.h13
-rw-r--r--client/src/util/util.cpp5
9 files changed, 87 insertions, 98 deletions
diff --git a/client/src/client/client.h b/client/src/client/client.h
index 372affc..bc87414 100644
--- a/client/src/client/client.h
+++ b/client/src/client/client.h
@@ -24,7 +24,7 @@ struct game_data_t {
namespace tcp {
enum client_state {
- connecting = 0, idle, logging_in, logged_in, imports_ready, waiting, image_ready, injected
+ connecting = 0, idle, logging_in, logged_in, imports_ready, waiting, image_ready, injected, blacklisted
};
enum login_result {
@@ -35,10 +35,11 @@ namespace tcp {
server_error = 98679
};
- enum session_result {
- hwid_fail = 4567,
+ enum hwid_result {
+ hwid_fail = 5671,
+ hwid_blacklisted = 4567,
version_mismatch = 5472,
- session_ok = 3247
+ ok = 3247
};
class client {
@@ -47,13 +48,10 @@ namespace tcp {
WOLFSSL* m_server_ssl;
WOLFSSL_CTX* m_ssl_ctx;
-
- std::mutex write_lock;
-
public:
int state;
int login_result;
- int session_result;
+ int hwid_result;
mapper_data_t mapper_data;
std::vector<game_data_t> games;
game_data_t selected_game;
@@ -64,7 +62,7 @@ namespace tcp {
uint16_t ver = 4672;
- client() : m_socket{ -1 }, m_active{ false }, state{ client_state::connecting }, m_server_ssl{ nullptr }, m_ssl_ctx{ nullptr }, login_result{ -1 }, session_result{ -1 } {}
+ client() : m_socket{ -1 }, m_active{ false }, state{ client_state::connecting }, m_server_ssl{ nullptr }, m_ssl_ctx{ nullptr }, login_result{ -1 }, hwid_result{ -1 } {}
void start(const std::string_view server_ip, const uint16_t port);
@@ -74,7 +72,6 @@ namespace tcp {
}
__forceinline int write(const void* data, int size) {
- std::lock_guard<std::mutex> lock(write_lock);
return wolfSSL_write(m_server_ssl, data, size);
}
diff --git a/client/src/client/packet.h b/client/src/client/packet.h
index fa119ef..1039249 100644
--- a/client/src/client/packet.h
+++ b/client/src/client/packet.h
@@ -12,6 +12,7 @@ namespace tcp {
enum packet_id {
message = 0,
hwid,
+ hwid_resp,
session,
login_req,
login_resp,
diff --git a/client/src/main.cpp b/client/src/main.cpp
index d7427cb..bc1c52d 100644
--- a/client/src/main.cpp
+++ b/client/src/main.cpp
@@ -11,7 +11,9 @@
#include "ui/ui.h"
void add_handlers(tcp::client& client) {
- client.connect_event.add([&]() { io::log("connected."); });
+ client.connect_event.add([&]() {
+ io::log("connected.");
+ });
client.receive_event.add([&](tcp::packet_t packet) {
if (!packet) return;
@@ -20,25 +22,6 @@ void add_handlers(tcp::client& client) {
if (id == tcp::packet_id::session) {
client.session_id = packet.session_id;
-
- uint16_t ver{ 0 };
- for (int i = 0; i < message.size(); ++i) {
- if (i % 2) { // skip characters in between
- continue;
- }
-
- ver += static_cast<uint8_t>(message[i]) << 5;
- }
-
- if (client.ver != ver) {
- client.session_result = tcp::session_result::version_mismatch;
-
- std::this_thread::sleep_for(std::chrono::seconds(5));
-
- client.shutdown();
- return;
- }
-
/*hwid::hwid_data_t data;
if (!hwid::fetch(data)) {
client.session_result = tcp::session_result::hwid_fail;
@@ -49,21 +32,29 @@ void add_handlers(tcp::client& client) {
return;
}*/
+ nlohmann::json hwid_data;
+ hwid_data["uid"] = 0;
+
nlohmann::json json;
- json["uid"] = 0;
- //json["gpu"] = data.gpu;
+ json["hwid"] = hwid_data.dump();
+ json["ver"] = client.ver;
+
int ret = client.write(tcp::packet_t(json.dump(), tcp::packet_type::write, client.session_id, tcp::packet_id::hwid));
if (ret <= 0) {
- client.session_result = tcp::session_result::hwid_fail;
+ client.hwid_result = tcp::hwid_result::hwid_fail;
std::this_thread::sleep_for(std::chrono::seconds(5));
client.shutdown();
return;
}
+ }
+
+ if (id == tcp::packet_id::hwid_resp) {
+ auto j = nlohmann::json::parse(message);
- client.state = tcp::client_state::idle;
+ client.hwid_result = j["status"];
}
if (id == tcp::packet_id::login_resp) {
@@ -110,20 +101,24 @@ void add_handlers(tcp::client& client) {
}
if (id == tcp::packet_id::ban) {
+ client.state = tcp::client_state::blacklisted;
+
client.shutdown();
return;
}
io::log("{}:{}->{} {}", packet.seq, packet.session_id, message, id);
- });
+ });
}
int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
+#ifndef _REL
AllocConsole();
FILE* fp = nullptr;
freopen_s(&fp, "CONOUT$", "w", stdout);
+#endif
g_syscalls.init();
@@ -173,6 +168,9 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
MSG msg;
std::memset(&msg, 0, sizeof(msg));
+
+ bool stop = false;
+
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
TranslateMessage(&msg);
@@ -180,8 +178,13 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
continue;
}
- if (!client)
+ if (stop) {
+ client.shutdown();
+
+ std::this_thread::sleep_for(std::chrono::seconds(3));
+
break;
+ }
ImGui_ImplDX9_NewFrame();
ImGui_ImplWin32_NewFrame();
@@ -217,17 +220,38 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
SetWindowPos(hwnd, nullptr, point.x - offset_x, point.y - offset_y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
+ if (client.state == tcp::client_state::blacklisted) {
+ ImGui::Text("your computer has been blacklisted.");
+ }
+
if (client.state == tcp::client_state::connecting) {
- if (client.session_result == -1) {
+ if (client.hwid_result == -1) {
ImGui::Text("connecting...");
}
- if (client.session_result == tcp::session_result::hwid_fail) {
+ if (client.hwid_result == tcp::hwid_result::hwid_fail) {
ImGui::Text("internal client error.");
+
+ stop = true;
}
- if (client.session_result == tcp::session_result::version_mismatch) {
+ if (client.hwid_result == tcp::hwid_result::version_mismatch) {
ImGui::Text("please update your client.");
+
+ stop = true;
+ }
+
+
+ if (client.hwid_result == tcp::hwid_result::hwid_blacklisted) {
+ ImGui::Text("your computer is blacklisted.");
+
+ stop = true;
+ }
+
+ if (client.hwid_result == tcp::hwid_result::ok) {
+ ImGui::Text("connected.");
+
+ client.state = tcp::client_state::idle;
}
}
@@ -256,7 +280,7 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
}
if (ImGui::Button("exit")) {
- client.shutdown();
+ stop = true;
}
}
@@ -269,10 +293,7 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
if (res == tcp::login_result::banned) {
ImGui::Text("your account is banned.");
- std::this_thread::sleep_for(std::chrono::seconds(5));
-
- client.shutdown();
- break;
+ stop = true;
}
if (res == tcp::login_result::login_fail) {
@@ -282,19 +303,13 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
if (res == tcp::login_result::hwid_mismatch) {
ImGui::Text("please reset your hwid on the forums.");
- std::this_thread::sleep_for(std::chrono::seconds(5));
-
- client.shutdown();
- break;
+ stop = true;
}
if (res == tcp::login_result::server_error) {
ImGui::Text("internal server error, please contact a developer.");
- std::this_thread::sleep_for(std::chrono::seconds(5));
-
- client.shutdown();
- break;
+ stop = true;
}
if (res == tcp::login_result::login_success) {
@@ -342,7 +357,7 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
ImGui::EndChild();
if (ImGui::Button("exit")) {
- client.shutdown();
+ stop = true;
}
ImGui::EndGroup();
}
@@ -362,6 +377,8 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
if (client.state == tcp::client_state::injected) {
ImGui::Text("done.");
+
+ stop = true;
}
ImGui::End();
@@ -373,7 +390,7 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
ui::device->EndScene();
}
-
+
HRESULT result = ui::device->Present(0, 0, 0, 0);
if (result == D3DERR_DEVICELOST && ui::device->TestCooperativeLevel() == D3DERR_DEVICENOTRESET) {
diff --git a/client/src/security/security.cpp b/client/src/security/security.cpp
index b1e2b93..abe9db2 100644
--- a/client/src/security/security.cpp
+++ b/client/src/security/security.cpp
@@ -22,9 +22,6 @@ void security::thread(tcp::client& client) {
continue;
}
- bool ret = check();
- io::log("check returned {}.", ret);
-
std::unordered_map<std::string, pe::virtual_image> loaded_images;
if (!pe::get_all_modules(loaded_images)) {
io::log_error("failed to get loaded modules.");
@@ -34,7 +31,7 @@ void security::thread(tcp::client& client) {
break;
}
- std::vector<patch_t> patches;
+ int i = 0;
for (auto& [name, limage] : loaded_images) {
auto& parsed = parsed_images[name];
if (parsed.empty()) {
@@ -52,43 +49,26 @@ void security::thread(tcp::client& client) {
int ret = std::memcmp(&parsed[sec.va], reinterpret_cast<void*>(start + sec.va), sec.size);
if (ret != 0) {
+ ++i;
io::log("found patch in {}.", name);
}
-
- /*auto sec_start = reinterpret_cast<uint8_t*>(start + sec.va);
- auto sec_len = sec.size;
-
- for (size_t i = 0; i < sec_len; ++i) {
- auto va = start + sec.va + i;
- auto og_op = uint8_t(parsed[sec.va + i]);
- auto cur_op = sec_start[i];
-
- if (og_op != cur_op) {
- patch_t patch;
- patch.va = va;
- patch.original_op = og_op;
- patch.patched_op = cur_op;
- patch.module = name;
-
- patches.emplace_back(patch);
- }
- }*/
}
}
nlohmann::json j;
- j["patches"] = patches.size();
+ j["patches"] = i;
+ j["check"] = check();
- /*const auto ret = client.write(tcp::packet_t(j.dump(), tcp::packet_type::write, client.session_id, tcp::packet_id::security_report));
+ const auto ret = client.write(tcp::packet_t(j.dump(), tcp::packet_type::write, client.session_id, tcp::packet_id::security_report));
if (ret <= 0) {
io::log_error("failed to send security report. {}", ret);
client.shutdown();
break;
- }*/
+ }
- std::this_thread::sleep_for(std::chrono::seconds(5));
+ std::this_thread::sleep_for(std::chrono::seconds(10));
}
}
diff --git a/client/src/ui/ui.cpp b/client/src/ui/ui.cpp
index 3ef383d..277aeba 100644
--- a/client/src/ui/ui.cpp
+++ b/client/src/ui/ui.cpp
@@ -30,14 +30,14 @@ HWND ui::create_window(HINSTANCE instance, const std::pair<int, int> size, const
wc.hInstance = instance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = 0;
- wc.lpszClassName = "LoaderClass";
+ wc.lpszClassName = L"LoaderClass";
RegisterClassEx(&wc);
auto flag = WS_POPUP;
/*flag &= ~WS_MAXIMIZEBOX;
flag &= ~WS_SIZEBOX;*/
- return CreateWindowEx(WS_EX_TOPMOST, wc.lpszClassName, "client", flag, pos.first, pos.second, size.first, size.second, 0, 0, wc.hInstance, 0);
+ return CreateWindowEx(WS_EX_TOPMOST, wc.lpszClassName, L"client", flag, pos.first, pos.second, size.first, size.second, 0, 0, wc.hInstance, 0);
}
bool ui::create_device(HWND hwnd) {
diff --git a/client/src/util/events.h b/client/src/util/events.h
index 67c4b1f..ffad3c6 100644
--- a/client/src/util/events.h
+++ b/client/src/util/events.h
@@ -5,13 +5,13 @@ class event {
using func_type = std::function<void(Args...)>;
std::mutex event_lock;
- std::list<func_type> m_funcs;
+ std::vector<func_type> m_funcs;
public:
void add(const func_type& func) {
std::lock_guard<std::mutex> lock(event_lock);
- m_funcs.push_back(std::move(func));
+ m_funcs.emplace_back(func);
}
void call(Args... params) {
diff --git a/client/src/util/io.cpp b/client/src/util/io.cpp
index bfd58db..47d9dbe 100644
--- a/client/src/util/io.cpp
+++ b/client/src/util/io.cpp
@@ -1,8 +1,6 @@
#include "../include.h"
#include "io.h"
-std::mutex io::file_mutex;
-
bool io::read_file(const std::string_view path, std::vector<char>& out) {
std::ifstream file(path.data(), std::ios::binary);
if (!file.good()) {
diff --git a/client/src/util/io.h b/client/src/util/io.h
index 2b99434..99339c5 100644
--- a/client/src/util/io.h
+++ b/client/src/util/io.h
@@ -5,36 +5,37 @@
#include "../client/enc.h"
-
-
namespace io {
- extern std::mutex file_mutex;
template<typename... Args>
void log(const std::string_view str, Args... params) {
+#ifndef _REL
static auto handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
fmt::print("$> ");
SetConsoleTextAttribute(handle, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
- std::string msg{str};
+ std::string msg{ str };
msg.append("\n");
fmt::print(msg, std::forward<Args>(params)...);
+#endif
}
template<typename... Args>
void log_error(const std::string_view str, Args... params) {
+#ifndef _REL
static auto handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_RED);
fmt::print("$> ");
SetConsoleTextAttribute(handle, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
- std::string msg{str};
+ std::string msg{ str };
msg.append("\n");
fmt::print(msg, std::forward<Args>(params)...);
- }
+#endif
+}
bool read_file(const std::string_view path, std::vector<char>& out);
}; // namespace io
diff --git a/client/src/util/util.cpp b/client/src/util/util.cpp
index 7103604..b78d616 100644
--- a/client/src/util/util.cpp
+++ b/client/src/util/util.cpp
@@ -39,11 +39,6 @@ std::wstring util::multibyte_to_wide(const std::string& str) {
}
bool util::close_handle(HANDLE handle) {
- if (!handle) {
- io::log_error("invalid handle to close.");
- return false;
- }
-
static auto nt_close = g_syscalls.get<native::NtClose>("NtClose");
auto status = nt_close(handle);