Hello agains folks,
Rotana asked in the other topic about reading dll's so I'll show how to do it.
To start our function is:
It'll snap all modules inside of the process, and show all attached dll's to it.Code:void ReadModules() { HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); PROCESSENTRY32 Processie; memset(&Processie,0,sizeof(Processie)); Processie.dwSize = sizeof(Processie); while(Process32Next(snap,&Processie)) { HANDLE snapmodules = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,0); MODULEENTRY32 ModuleEntrie; memset(&ModuleEntrie,0,sizeof(ModuleEntrie)); ModuleEntrie.dwSize = sizeof(ModuleEntrie); while(Module32Next(snapmodules,&ModuleEntrie)) { printf("\nAttached Module (Dll): %s",ModuleEntrie.szModule); } CloseHandle(snapmodules); } CloseHandle(snap); }
Since we're talking gunz->antihack we should check if there is a dll we don't want running into our process using
If it finds a dll that is not allowed into the list it'll kill the process, example:Code:if(strcmp(ModuleEntrie.szModule,"ourdll.dll") && strcmp(ModuleEntrie.szModule,"kernel32.dll") != 0) EndApplication(); (...)
You have all dll's from gunz dbghelp.dll, fmod.dll, gdiplus.dll, kernel32.dll, ntdll.dll, user32.dll (...) etcetc
Check if the module read is not one of their names, if not kill gunz, but wait what if the guy names his dll to an allowed one?
Ok so we already know that that function sucks, what will be doing in this case is to check the base address from the dll.
The base address is a signature, umm, like md5, but you can't check the md5 of a running on you process, oh wait YOU CAN!
The problem is, dll's used in another version of windows may have different signatures, but not their base address, so that is why we will be using it.
To retrieve the base address of a module simply use
And it'll display the base address of all dll's inside your process.Code:void ReadModules() { HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); PROCESSENTRY32 Processie; memset(&Processie,0,sizeof(Processie)); Processie.dwSize = sizeof(Processie); while(Process32Next(snap,&Processie)) { HANDLE snapmodules = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,0); MODULEENTRY32 ModuleEntrie; memset(&ModuleEntrie,0,sizeof(ModuleEntrie)); ModuleEntrie.dwSize = sizeof(ModuleEntrie); while(Module32Next(snapmodules,&ModuleEntrie)) { printf("\nAttached Module (Dll): %s",ModuleEntrie.szModule); printf("\n Base Address %x",ModuleEntrie.modBaseAddr); } CloseHandle(snapmodules); } CloseHandle(snap); }
Now we can use a better function
We have just checked the base address of the dll running inside the process, if not one of our allowed base address one, we kill the application.Code:unsigned long kerneladdress = 0x7c000000; //not real ones just for tutorial unsigned long ntdlladdress = 0x8b000000; (...) if(ModuleEntrie.modBaseAddr != kerneladdress || ModuleEntrie.modBaseAddr != ntdlladdress) EndApplication(); (...)
Oh wait, but there is one more problem, C++ forbids the comparison between pointer and integer, so we have to come up with another function
We will first declare a HANDLE (which is void*) and copy our data into it look
Now we have a valid function to compare their base address.Code:HANDLE kerneladdress; // which can be also represented by void* kerneladdress; memcpy(&kerneladdress,"\x00\x00\x80\x7c",4); (...) if(ModuleEntrie.modBaseAddr != kerneladdress) EndApplication(); (...)
Well it's simply it! Use it however you want, If you have any idea of how can I improve this I will be glad to hear, also if you have seen I did any mistake please tell me.
Here is the full source avaliable for you to do whatever you want with it. (also the complete project below just open Project1.dev)
ATTENTION: COMPILE WITH DEV-CPP (GCC COMPILER)
Have a good time guysCode:#include <Windows.h> #include <stdio.h> #include <TlHelp32.h> void ReadModules() { HANDLE kerneladdress; memcpy(&kerneladdress,"\x00\x00\x80\x7c",4); HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); PROCESSENTRY32 Processie; memset(&Processie,0,sizeof(Processie)); Processie.dwSize = sizeof(Processie); while(Process32Next(snap,&Processie)) { if(strcmp("Project1.exe",Processie.szExeFile) == 0) //show only the dll's of our process { HANDLE snapmodules = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,0); MODULEENTRY32 ModuleEntrie; memset(&ModuleEntrie,0,sizeof(ModuleEntrie)); ModuleEntrie.dwSize = sizeof(ModuleEntrie); while(Module32Next(snapmodules,&ModuleEntrie)) { printf("\nAttached Module (Dll): %s",ModuleEntrie.szModule); printf("\nBase address : %x,",ModuleEntrie.modBaseAddr); if(kerneladdress == ModuleEntrie.modBaseAddr) { printf("Wow you have found kernel dll running in here!"); } } CloseHandle(snapmodules); } } CloseHandle(snap); } int main(int argc, char *argv[]) { SetConsoleTitle("ReadModules"); ReadModules(); system("pause>nul"); return 0; }



![[Tutorial]Reading Modules (DLLS) and DLL explanations](http://ragezone.com/hyper728.png)

