summaryrefslogtreecommitdiff
path: root/csgo-loader/csgo-module/Module.cpp
blob: 1fa638c36d8bc19a264faf7d9fd08a961fd08c8a (plain)
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
#include <Module.hpp>

/*
	TODO:
	- Finish off shellcode execution wrapper:
		- The shellcode can be executed via two ways
		- Either the code is mapped and called via CreateRemoteThread (allows custom param)
		- or the code is mapped and called via DX9 (does not allow custom param)
		- This will probably be the easiest thing to do.

	- Allocate via consecutive 64kb sections (TODO: Figure out how)

	- Free and wipe the module from memory once done
	- Have the module authenticate via HWID or some shit.. idk (AAAAAAAAAAA)
	- Do reloc/mapping stuff here
*/

DWORD ModuleThread(void *)
{
	//////////////////////////////////////////////////////////////////////////////////////////

	// Initialize the syscall manager.
	if(!Syscalls->Start())
		return 0;

	// Attempt to connect to the remote server.
	WRAP_IF_DEBUG(
		printf("[DEBUG] Server IP: %08x\n", inet_addr("35.165.60.229"));
	);

	//////////////////////////////////////////////////////////////////////////////////////////

	// Connect to server.
	Networking::TCPClientPtr Client = std::make_unique<Networking::TCPClient>();

	if(!Client->Start(LOCAL_IP, SERVER_PORT))
		return 0;

	// Header for Module.
	ByteArray Header{ 0x0A, 0x32, 0x42, 0x4D };
	Client->SendRawBytes(Header);

	//////////////////////////////////////////////////////////////////////////////////////////

	return 1;
}

int __stdcall DllMain(void *, unsigned Reason, void *)
{
	if(Reason != 1)
		return false;

	HANDLE Thread = CreateThread(nullptr, 0, ModuleThread, nullptr, 0, nullptr);

	if(Thread)
	{
		// Wait for thread to finish execution
		WaitForSingleObject(Thread, INFINITE);

		// Get exit code from thread.
		DWORD ExitCode;
		GetExitCodeThread(Thread, &ExitCode);

		// If the HWND is 0, the loader will reveal that MessageBoxA was called from
		// explorer.exe... This meme will get around that.
		HWND Window = FindWindowA(STR("Valve001"), nullptr);
		
		if(!Window)
			return true;

		if(!ExitCode)
			MessageBoxA(Window, STR("[000F:00004A00] Failed to initialize. Please contact an administrator."), "", MB_ICONERROR | MB_OK);
	}

	return true;
}