Don't know about c# but c++.
Here is a small guide. Be kind with any mistakes.. I just wrote this down ~
You need
- Visual Studio Express 2013
- Perx x1nject
with Perx x1nject you can load your created DLL into the memory of another process (e.g. a game)
In VS Express:
new Project -> VisualC++ -> Win32 (console)-> OK -> Next
Select "DLL" as type
Code:
// dllmain.cpp : Definiert den Einstiegspunkt für die DLL-Anwendung.
#include "stdafx.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
DLL_PROCESS_ATTACH gets called on load.
Your detours will be placed here.
DLL_PROCESS_DETACH
undo your detours here
e.g. this is my packet sender dllmain.cpp
Code:
// dllmain.cpp : Definiert den Einstiegspunkt für die DLL-Anwendung.
#include "stdafx.h"
#include "encHook.h"
#include "w32hooks.h"
#include "console.h"
#include "GUIConfig.h"
packet o_encryption = nullptr;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
constants::gui::hInstance = hModule;
createConsole();
cout << "DLL_PROCESS_ATTACH" << endl;
o_encryption = (packet)DetourFunction((PBYTE)constants::addresses::encryption, (PBYTE)encHook);
game::NPCs.reserve(1000);
game::newItems.reserve(1000);
game::soldItemBlockList.reserve(100);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
DetourRemove((PBYTE)o_encryption, (PBYTE)encHook);
break;
}
return TRUE;
}
you must not create a Thread in DLL_PROCESS_ATTACH. This will lead to an error. Create a Thread in an detoured function.. that's the easiest way ;D
running custom ASM is pretty easy ~
Code:
INT functions::openNPCbyInternalID(DWORD internalNPCid)
{
ULONG lpFunction = 0x0046AF20;
ULONG lpthis = 0x00C22194;
ULONG dwRes = NULL;
__asm
{
/* Pointer to this Offset1 = 0*/
mov edi, lpthis;
mov edi, [edi];
mov ecx, edi;
push internalNPCid;
call lpFunction;
mov dwRes, eax;
}
return dwRes;
}
edit:
if you don't know what a detour is. A detour basically hooks into the specified position. When the game calls this position, you can execute your own code and then forward the call to the original funcion.
Creating a detour of a function.
Let's hook o_setsockopt
Code:
DLL_PROCESS_ATTACH:
o_setsockopt = (t_setsockopt)DetourFunction((PBYTE)GetProcAddress(GetModuleHandle(L"ws2_32.dll"), "setsockopt"), (PBYTE)&hook_setsockopt);
print out the used socket and forward to the original function.
Code:
typedef int (WINAPI* t_setsockopt)(SOCKET, int, int, const char *, int);
int WINAPI hook_setsockopt(SOCKET s, int level, int optname, const char *optval, int optlen)
{
cout << dec << "Socket :: " << s << endl;
return o_setsockopt(s, level, optname, optval, optlen);
}
hope this helped. feel free to ask more here - no pn pls . i won't read them :P