PDA

View Full Version : Solution The very dynamic way of getting interfaces



freax
07-11-2011, 06:46 PM
This is to stop boiiiis crying for nullpointer interfaces. Have phun...


typedef void* (*CreateInterfaceFunc)(const char *pName, int *pReturnCode);

class CSystem
{
public:
void OnLoad();

private:
void AddFactory(const string &strModule);
void *GetInterface(const string &strName) const;

private:
list<CreateInterfaceFunc> m_Factories;
};

void CSystem::OnLoad()
{
this->AddFactory("client.dll");
this->AddFactory("engine.dll");
this->AddFactory("vphysics.dll");
this->AddFactory("FileSystem_Steam.dll");
this->AddFactory("StudioRender.dll");
this->AddFactory("MaterialSystem.dll");
this->AddFactory("vguimatsurface.dll");
this->AddFactory("SteamClient.dll");

CreateInterfaceFunc AppSystemFactory = reinterpret_cast<CreateInterfaceFunc>(CSigScanner("engine.dll").Find(reinterpret_cast<unsigned char*>("\x8B\x44\x24\x04\x8B\x0D\x00\x00\x00\x00\x50\xE8\x00\x00\x00\x00\x8B\x 4C\x24\x08\x85\xC9\x74\x09"), "xxxxxx????xx????xxxxxxxx"));

if (AppSystemFactory)
{
this->m_Factories.push_front(AppSystemFactory);

ConnectTier1Libraries(&AppSystemFactory, 1);
ConnectTier2Libraries(&AppSystemFactory, 1);
ConnectTier3Libraries(&AppSystemFactory, 1);
}

ConVar_Register(0);

g_pClient = static_cast<IBaseClientDLL*>(this->GetInterface(CLIENT_DLL_INTERFACE_VERSION));
g_pEngine = static_cast<IVEngineClient*>(this->GetInterface(VENGINE_CLIENT_INTERFACE_VERSION));
// ect
}

void CSystem::AddFactory(const string &strModule)
{
HMODULE hModule = NULL;

for ( ; !hModule; hModule = GetModuleHandle(strModule.c_str()), Sleep(10));

CreateInterfaceFunc Factory = reinterpret_cast<CreateInterfaceFunc>(GetProcAddress(hModule, "CreateInterface"));

if (Factory != NULL)
{
this->m_Factories.push_back(Factory);
}
}

void *CSystem::GetInterface(const string &strName) const
{
for (list<CreateInterfaceFunc>::const_iterator it = this->m_Factories.begin(); it != this->m_Factories.end(); ++it)
{
void *pInterface = (*it)(strName.c_str(), NULL);

if (pInterface)
{
return pInterface;
}
}

string strVersion = strName.substr(strName.length() - 3, 3);

if (isdigit(strVersion[0]) && isdigit(strVersion[1]) && isdigit(strVersion[2]))
{
string strInterface = strName.substr(0, strName.length() - 3);

for (int i = 100; i >= 0; --i)
{
string strCurrent = (strInterface + g_pUtils->Format("%03d", i));

for (list<CreateInterfaceFunc>::const_iterator it = this->m_Factories.begin(); it != this->m_Factories.end(); ++it)
{
void *pInterface = (*it)(strCurrent.c_str(), NULL);

if (pInterface)
{
return pInterface;
}
}
}
}

return NULL;
}
I know that I actually could use templates to avoid static_cast, but well. I'm fucking lazy.

tang77
07-12-2011, 04:03 AM
so leeb.

darkcat
07-12-2011, 08:58 AM
very nice. I have been working on something similar you know. :D

syntroniks
07-12-2011, 05:48 PM
Two posts in this thread have been posted on GD before.
http://www.gamedeception.net/threads/17933-Auto-Airblast?p=120236#post120236
http://www.gamedeception.net/threads/18211-PeLib-A-PE-File-Format-Wrapper?p=121973#post121973

http://www.gamedeception.net/threads/18709-VEngineClient014/page2

Except freax took meaningless crap and turned it into something useful. Thank you freax.

darkcat
07-12-2011, 09:06 PM
Two posts in this thread have been posted on GD before.
http://www.gamedeception.net/threads/17933-Auto-Airblast?p=120236#post120236
http://www.gamedeception.net/threads/18211-PeLib-A-PE-File-Format-Wrapper?p=121973#post121973

http://www.gamedeception.net/threads/18709-VEngineClient014/page2

Except freax took meaningless crap and turned it into something useful. Thank you freax.

I don't know any english so i must copy+paste. sorry.

uber^
09-27-2011, 04:48 PM
is the SigScanner a function found here somewhere? i searched and found nothing here

Gumble
09-27-2011, 04:53 PM
no its a part of directx sdk.

you need to install this:

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=10084

and also boost:

http://www.boost.org/

uber^
09-27-2011, 04:58 PM
aww.. ok.. thanks.. I have the DX sdk, but not the boost..

thanks for the really fast reply

Forza
09-27-2011, 05:11 PM
Boost is free, just spend a few minutes to download it and then simply paste this code and you have a nice little base hook. :D

uber^
09-27-2011, 07:34 PM
sorry for the noob question again... but i looked all over the boost sdk, and i can not find any CSigScanner functions in any of the boost files, as it was suggested they were in.

i am looking for this function here:

CSigScanner("engine.dll").Find()

exploit
09-27-2011, 08:00 PM
LOL you got trolled hard but you prob deserved it by not attempting to use the search function.

uber^
09-27-2011, 08:07 PM
You referring to me?

I dont get how i got trolled, or what that means, but as I stated in my 1st post in this thread, i did do a search. I searched for "CSigScanner," "SigScanner," and "CSig."

Ghett0
09-27-2011, 08:52 PM
http://www.gamedeception.net/threads/7300

no you didn't

uber^
09-27-2011, 08:56 PM
I have, theres only 3 results from the searches... That thread there, has a dead link...

i even googled it, which brought up various files with different classes and structs of a SigScanner. Even koders.com has different variations of it.

Ghett0
09-28-2011, 12:05 AM
Oh, my apologies.

Anyways, http://forums.alliedmods.net/showthread.php?t=39566

There's a sig scanner class here.