Author Topic: Anti-Crash Patch Source Code & A Brief brown townysis  (Read 8268 times)

EDIT: If you just want the DLL, PM me and I'll give it to you. The source code is also available in the topic.
To use the DLL, download a program to inject the DLL into blockland. This can be done using, for example, http://www.9injector.com/extreme-injector/
(Many antiviruses like Norton will detect the program as a trojan. This is a false positive. Many will detect it as a "HackTool" since it can be used for hacking, and that's all it is.)
After that, start up blockland and open the injector program. Select the Blockland process, select the downloaded DLL and click the Inject button.


So Computermix has given the source code of his recent Anti-Crash DLL, which has been the recipient of many complaints about its legitimacy and safety.
This DLL, which is injected into the game using an external program, will prevent malicious users from crashing your server with the widely-distributed crash hack DLL.
This topic is made to prove that there is a safe version of the DLL available to download, along with the source if you want to compile it yourself.


The entire source code is really just 90 lines of code in total, and I'll put it all right here:

Code: [Select]
#include "MologieDetours\detours.h"

typedef void(__cdecl* PrintfFn)(char* szFormat, ...);
static PrintfFn Printf;

typedef void(__cdecl* SetVariableFn)(char* szName, char* szValue);
static SetVariableFn SetVariable;

typedef char*(__cdecl* szGetVariableFn)(char* szName);
static szGetVariableFn szGetVariable;

typedef char*(__cdecl* szEvaluateFn)(char* szString, bool bEcho, char* szFileName);
static szEvaluateFn szEval;

typedef void(__thiscall* ProcessFn)(DWORD dwThis, DWORD dwConnection);
static ProcessFn Process;
MologieDetours::Detour<ProcessFn>* Detour_Process;

void __fastcall Hooked_Process(DWORD dwThis, void* blank, DWORD dwConnection)
{
int iArgc = *(int*)(dwThis + 16);
char** szArgv = (char**)(dwThis + 20);
bool bIsCrashing = false;

if (!(*(unsigned char *)(dwConnection + 288) & 1)) //this just checks if its a client on a server (in contrast to hosting in-game, where packets are back and fourth)
{
for (int i = iArgc - 1; i >= 0; i--)
{
char* szArg = szArgv[i + 1];

if (*szArg == 1) //tag?
{
//check numbers bigger than table size or less than zero

int iHax = atoi(szArg + 1);

if (iHax > (**(int**)(0x7F4254)) || iHax < 0)
{
bIsCrashing = true;

//dont return just yet- let the loop fix the spam from buffer overflow
if (i > 19)
szArgv[i + 1] = 0;
}
}
}
}

if (bIsCrashing && atoi(szGetVariable("$Pref::Server::AntidoteMode")) == 1)
{
char szBuf[128];

sprintf_s(szBuf, "messageAll('', %d.name SPC \"(BLID \" @ %d.bl_id @ \") attempted to crash the server!\");", *(int*)(dwConnection + 192), *(int*)(dwConnection + 192));

szEval(szBuf, false, 0);

sprintf_s(szBuf, "serverCmdBan(0, %d, %d.bl_id, -1, \"Attempted to crash the server. (Perma'd)\");", *(int*)(dwConnection + 192), *(int*)(dwConnection + 192));

szEval(szBuf, false, 0);
}

return bIsCrashing ? 0 : Detour_Process->GetOriginalFunction()(dwThis, dwConnection);
}

DWORD WINAPI dwMainThread(LPVOID Args)
{
//not using sigs cuz chances are an update will fix the crash anyways
Printf = (PrintfFn)0x4A8040;
szGetVariable = (szGetVariableFn)0x4A7620;
SetVariable = (SetVariableFn)0x4A6DB0;
Process = (ProcessFn)0x5813D0;
szEval = (szEvaluateFn)0x4A8260;

//hook the func that causes the crash
Detour_Process = new MologieDetours::Detour<ProcessFn>(Process, (ProcessFn)Hooked_Process);

Printf("Anti-crash injected, all set! :)\nYou can edit $Pref::Server::AntidoteMode to do different things corresponding to this list:\n= 0: Simply stop the crash and nothing happens to either the server or the user.\n= 1: Permaban that starfish.\n(default is 1)");
SetVariable("$Pref::Server::AntidoteMode", "1");

//no need to delete Detour_Process, windows will wipe my ass for me (3548)
return 0;
}

int WINAPI DllMain(HINSTANCE Instance, DWORD Reason, LPVOID Reserved)
{
if (Reason == DLL_PROCESS_ATTACH)
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)dwMainThread, NULL, 0, NULL);

return true;
}

I'll be brown townyzing this code later on, but even just giving it a quick skim can verify that this code does not contain anything malicious.

If you want the source code so you can compile it yourself, you can find it here. (Mega.co.nz)

If you want the compiled DLL that was made from the source (Which is entirely comprised of the code I posted and the library found here: https://github.com/kimperator/MologieDetours ) just PM me and I'll send it to you.

Now for an brown townysis of the code.

Code: [Select]
#include "MologieDetours\detours.h"

typedef void(__cdecl* PrintfFn)(char* szFormat, ...);
static PrintfFn Printf;

typedef void(__cdecl* SetVariableFn)(char* szName, char* szValue);
static SetVariableFn SetVariable;

typedef char*(__cdecl* szGetVariableFn)(char* szName);
static szGetVariableFn szGetVariable;

typedef char*(__cdecl* szEvaluateFn)(char* szString, bool bEcho, char* szFileName);
static szEvaluateFn szEval;

typedef void(__thiscall* ProcessFn)(DWORD dwThis, DWORD dwConnection);
static ProcessFn Process;
MologieDetours::Detour<ProcessFn>* Detour_Process;
This part simply defines things for the code to use later on.

Code: [Select]
void __fastcall Hooked_Process(DWORD dwThis, void* blank, DWORD dwConnection)
{
int iArgc = *(int*)(dwThis + 16);
char** szArgv = (char**)(dwThis + 20);
bool bIsCrashing = false;

if (!(*(unsigned char *)(dwConnection + 288) & 1)) //this just checks if its a client on a server (in contrast to hosting in-game, where packets are back and fourth)
{
for (int i = iArgc - 1; i >= 0; i--)
{
...
}
}
}
The code where the dots are is coming next.

The code here seems to define a couple variables and then the variable bIsCrashing, which indicates if a crashing packet was detected.
After that it checks if the packet was received by a client on the server, and then loops through all the different parts of the packet.

Code: [Select]
char* szArg = szArgv[i + 1];

if (*szArg == 1) //tag?
{
//check numbers bigger than table size or less than zero

int iHax = atoi(szArg + 1);

if (iHax > (**(int**)(0x7F4254)) || iHax < 0)
{
bIsCrashing = true;

//dont return just yet- let the loop fix the spam from buffer overflow
if (i > 19)
szArgv[i + 1] = 0;
}
}
This code first checks if the part of the packet is a tag, and then checks if the argument is greater than the total size of the netstring table, or less than 0. Either of those would cause the server to crash. If it's detected it sets the variable to true and continues on.
I'm not entirely sure what the if statement and the line after it does, but it seems based on the comment that it cleans up the console spam that would otherwise be left by the crash attempt. (If you have any insight into this, lemme know and I'll edit it in)

Code: [Select]
if (bIsCrashing && atoi(szGetVariable("$Pref::Server::AntidoteMode")) == 1)
{
char szBuf[128];

sprintf_s(szBuf, "messageAll('', %d.name SPC \"(BLID \" @ %d.bl_id @ \") attempted to crash the server!\");", *(int*)(dwConnection + 192), *(int*)(dwConnection + 192));

szEval(szBuf, false, 0);

sprintf_s(szBuf, "serverCmdBan(0, %d, %d.bl_id, -1, \"Attempted to crash the server. (Perma'd)\");", *(int*)(dwConnection + 192), *(int*)(dwConnection + 192));

szEval(szBuf, false, 0);
}

return bIsCrashing ? 0 : Detour_Process->GetOriginalFunction()(dwThis, dwConnection);
This code checks if there has been a crashing packet detected and if the "antidote" mode has been activated through a getVariable function.
If both are true, it evals 2 lines of code that say that a certain player has tried to crash the server, and then permanently bans them.

After that, if a crashing packet was detected, it returns 0, completely skipping the other packet processing code. If not, it goes through the regular packet processing code.

The remainder of the code is just setting up the functions like the eval and getVariable functions, and handling injection into the exe.

On another note, when I compiled the source code with the same options that Computermix used (He told me which options to use as I'm not totally familiar with it) and the DLL was slightly bigger than the original that I got from wrapperup. He's explained this in a steam chat to me:


Take that how you will, but the version that is obtained from compiling this source is safe.
« Last Edit: December 21, 2014, 10:32:21 AM by Ipquarx »


so how does this benefit us? Can we make an addon now to counteract the crashing function, or detect the ddl?

so how does this benefit us? Can we make an addon now to counteract the crashing function, or detect the ddl?
Having it on at your server detects when someone tries to crash the server and auto bans them.

so how does this benefit us? Can we make an addon now to counteract the crashing function, or detect the ddl?
It allows you to completely stop your game from crashing due to people using the crash DLL hack. It detects if someone is trying to crash your server, stops them, then publicly announces it and permanently bans them. You inject the DLL into your game using one of the many readily available programs on the internet and it automatically gives you those benefits.

So basically what Ravencroft said.



Looks awesome.  Thanks for sharing.

Thought you didnt want anything to do with this stuff anymore Ipquarx.

Looks awesome.  Thanks for sharing.
Not a problem! Remember, if any of you want the DLL version that I compiled just PM me and I'll send it to you.

Thought you didnt want anything to do with this stuff anymore Ipquarx.
Sometimes to do good you gotta go a bit out of your comfort zone.

so how does this benefit us? Can we make an addon now to counteract the crashing function, or detect the ddl?
This can't be done in an add-on
This is c++ code that needs to be compiled into a dll and infected into the game

This is like, a white-hat virus.

So macs are forgeted basically?

This is like, a white-hat virus.
Just white hat DLL.
iirc the word virus implies detrimental effect.

Just white hat DLL.
iirc the word virus implies detrimental effect.

A virus is malicious code that replicates by writing itself into other executables