/* INFORMATION ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ NAME: IPTABLE CONTROL DESC: LIST CONNECTIONS, AND CLOSE CONNECTIONS FOR MIRC TYPE: DYNAMIC LINK LIBRARY ('DLL') AUTHOR: HASO KERIC DATE: MAY 16, 2007 I 'HASO KERIC' HEREBY ANNOUNCE THIS SOURCE CODE TO BE A PART OF THE 'ZION/ZINC' NETWORK. ALL RIGHTS HAVE BEEN PASSED OVER TO MODIFY AND DISTRIBUTE SOURCE CODE FOR PRIVATE AND COMMERCIAL USE HASOKERIC HASOKERIC@COMCAST.NET HTTP://WWW.ZINC.SG/ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*/ /* INCLUDED FILES ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ EXPORTS.def - HOLDS ALL THE FUNCTIONS FOR THE DLL CLICK_.CPP - MAIN FILE README.TXT - A BRIEF GUIDE HOW TO USE THE COMPILED DLL ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*/ #define _WIN32_WINNT 0x0501 /*----------------------[ FUNCTIONS SUPPORTED BY XP/VISTA ] */ #define WIN32_LEAN_MEAN /*----------------------[ OUT WITH THE JUNK! ] */ /*----------------------[ LIBRARY'S ] */ #pragma comment(lib,"Iphlpapi.lib") #pragma comment(lib, "wsock32.lib") /*----------------------[ FILE'S ] */ #include #include #include #include /*----------------------[ DEFINITION FOR THE MIRC CALLING FUNCTION ] */ #define func(x) int WINAPI x(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause) VOID Thread(PVOID pvoid); VOID ThreadEx(PVOID pvoid); /*-------------------------------------[ GLOBAL HANDLES ] START */ HANDLE mFile; HWND mWnd; LPSTR mData; /*------------------------------------------- END */ /*-------------------------------------[ LOADINFO STRUCTURE ] START */ typedef struct { DWORD mVersion; HWND mHwnd; // LOADINFO IS STORED HERE BOOL mKeep; } LOADINFO;/*--------------------------------------------------- END */ /*-------------------------------------[ LoadDll ] START */ void __stdcall LoadDll(LOADINFO *mIRC) { mWnd = mIRC->mHwnd; /* LOADINFO (PTR) */ mFile = CreateFileMapping(INVALID_HANDLE_VALUE,0,PAGE_READWRITE,0,4096,"mIRC"); /* FILEMAP */ mData = (LPSTR)MapViewOfFile(mFile,FILE_MAP_ALL_ACCESS,0,0,0); /* OPEN FULL ACCESS */ }/*--------------------------------------------------- END */ /*-------------------------------------[ LOADINFO STRUCTURE ] START */ int __stdcall UnloadDll(int timeout) { if (!timeout) // IF IT DID NOT TIMEOUT (Function has been called Unmap/Exit) { UnmapViewOfFile(mData); CloseHandle(mFile); } return 0; }/*------------------------------------------------------------- END */ /*-------------------------------------[ TOKEN FUNCTIONS ] START */ int string_numtok(char *data, char ch){ int counter = 0; int size = 0; int tokens = 0; size = strlen(data); while (counter < size){ if (data[counter] == ch) tokens++; counter++; } return tokens + 1; } char *string_gettoken(char *data, int num, char ch){ int counter = 0; int tok_count = 0; int pos = 0; int size = strlen(data); int tokens = string_numtok(data,ch); static char *token = NULL; if (tokens < num) return NULL; token = (char*)malloc(sizeof(char) * size); memset(token,0,size); while (counter < size){ if ((tok_count == num) && (data[counter] != ch)){ token[pos] = data[counter]; pos++; } if (data[counter] == ch){ tok_count++; } counter++; } return token; }/*--------------------------------------------------- END */ /*-------------------------------------[ LISTCONNECTIONS ] START */ func(ListConnections) { _beginthread(Thread, 0, NULL); return 0; } VOID Thread(PVOID pvoid) { DWORD dwSize = 0; DWORD dwRetVal = 0; DWORD i; PMIB_TCPTABLE pTcpTable; char *addr_ptr; unsigned short *port_ptr; if (GetTcpTable(NULL, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) { pTcpTable = (MIB_TCPTABLE *) malloc (dwSize); } if ((dwRetVal = GetTcpTable(pTcpTable, &dwSize, 0)) == NO_ERROR) { if (pTcpTable->dwNumEntries > 0) { for (i=0; idwNumEntries; i++) { addr_ptr = (char *)&pTcpTable->table[i].dwLocalAddr; wsprintf(mData,"/.signal ZIPTABLE Local Address: %s", inet_ntoa(*(struct in_addr *)addr_ptr)); SendMessage(mWnd, WM_USER+200, NULL, NULL); port_ptr = (unsigned short *)&pTcpTable->table[i].dwLocalPort; wsprintf(mData,"/.signal ZIPTABLE Local Port: %ld",htons(*port_ptr)); SendMessage(mWnd, WM_USER+200, NULL, NULL); addr_ptr = (char *)&pTcpTable->table[i].dwRemoteAddr; wsprintf(mData,"/.signal ZIPTABLE Remote Address: %s",inet_ntoa(*(struct in_addr *)addr_ptr)); SendMessage(mWnd, WM_USER+200, NULL, NULL); port_ptr = (unsigned short *)&pTcpTable->table[i].dwRemotePort; wsprintf(mData,"/.signal ZIPTABLE Remote Port: %ld",htons(*port_ptr)); SendMessage(mWnd, WM_USER+200, NULL, NULL); wsprintf(mData,"/.signal ZIPTABLE State: %ld", pTcpTable->table[i].dwState); SendMessage(mWnd, WM_USER+200, NULL, NULL); } } } else { wsprintf(mData,"/.signal ZIPTABLE ERROR_GETTING_TABLE"); } SendMessage(mWnd, WM_USER+200, NULL, NULL); }/*---------------------------------------------------------------------- END */ /*-------------------------------------[ LISTCONNECTIONS ] START */ func(ListConnectionsEx) { _beginthread(ThreadEx, 0, NULL); return 0; } VOID ThreadEx(PVOID pvoid) { DWORD dwSize = 0; DWORD dwRetVal = 0; DWORD i; PMIB_TCPTABLE pTcpTable; char *addr_ptr; //char *addr_ptr2; unsigned short *port_ptr; // unsigned short *port_ptr2; if (GetTcpTable(NULL, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) { pTcpTable = (MIB_TCPTABLE *) malloc (dwSize); } if ((dwRetVal = GetTcpTable(pTcpTable, &dwSize, 0)) == NO_ERROR) { if (pTcpTable->dwNumEntries > 0) { for (i=0; idwNumEntries; i++) { char buffer[128]; char buffer2[128]; addr_ptr = (char *)&pTcpTable->table[i].dwLocalAddr; // char * buffer1 = inet_ntoa(*(struct in_addr *)(char *)©.table[1].dwLocalAddr); port_ptr = (unsigned short *)&pTcpTable->table[i].dwLocalPort; // u_short short1 = htons(*port_ptr); wsprintf(buffer,"Local Address: %s - Local Port: %ld - ", inet_ntoa(*(struct in_addr *)addr_ptr), htons(*port_ptr)); addr_ptr = (char *)&pTcpTable->table[i].dwRemoteAddr; // char * buffer2 = inet_ntoa(*(struct in_addr *)(char *)&pTcpTable->table[i].dwRemoteAddr); port_ptr = (unsigned short *)&pTcpTable->table[i].dwRemotePort; // u_short short2 = htons(*port_ptr); wsprintf(buffer2,"Remote Address: %s - Remote Port: %ld - State: %ld", inet_ntoa(*(struct in_addr *)addr_ptr), htons(*port_ptr),pTcpTable->table[i].dwState); strcat_s(buffer, buffer2); wsprintf(mData,"/.signal ZIPTABLE %s",buffer); /* wsprintf(mData,"/.signal ZIPTABLE Remote Address: %s - Remote Port: %ld - State: %ld", inet_ntoa(*(struct in_addr *)addr_ptr),htons(*port_ptr),pTcpTable->table[i].dwState); */ SendMessage(mWnd, WM_USER+200, NULL, NULL); } } } else { wsprintf(mData,"/.signal ZIPTABLE ERROR_GETTING_TABLE"); } SendMessage(mWnd, WM_USER+200, NULL, NULL); }/*---------------------------------------------------------------------- END */ /*-------------------------------------[ KILLCONNECTION ] START */ func(KillConnection) { MIB_TCPROW pMIB; if (string_gettoken(data,3,' ') != NULL) { pMIB.dwLocalAddr = inet_addr(string_gettoken(data,0,' ')); pMIB.dwLocalPort = htons(atoi(string_gettoken(data,1,' '))); pMIB.dwRemoteAddr = inet_addr(string_gettoken(data,2,' ')); pMIB.dwRemotePort = htons(atoi(string_gettoken(data,3,' '))); } pMIB.dwState = MIB_TCP_STATE_DELETE_TCB; DWORD cFunc = SetTcpEntry(&pMIB); if (cFunc == NO_ERROR) { wsprintf(data,"Killed %s",string_gettoken(data,2,' ')); } else if (cFunc != NO_ERROR) { wsprintf(data,"ERROR"); } return 3; }/*---------------------------------------------------------- END */