Jump to content
  • 0
Sign in to follow this  
Thyr

Anti RPE WPE Source from ea

Question

Hello is this can work on Hercules?

common/socket.c

Index: socket.c
===================================================================
--- socket.c	(revision 13725)
+++ socket.c	(working copy)
@@ -16,6 +16,7 @@
 
 #ifdef WIN32
 	#include <winsock2.h>
+	#include <time.h>
 	#include <io.h>
 #else
 	#include <errno.h>
@@ -112,7 +113,54 @@
 		sock_arr_len = fd+1;
 	return fd;
 }
+ 
+#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
+  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
+#else
+  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
+#endif
 
+struct timezone 
+{
+  int  tz_minuteswest; /* minutes W of Greenwich */
+  int  tz_dsttime;     /* type of dst correction */
+};
+ 
+int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+  FILETIME ft;
+  unsigned __int64 tmpres = 0;
+  static int tzflag;
+ 
+  if (NULL != tv)
+  {
+    GetSystemTimeAsFileTime(&ft);
+ 
+    tmpres |= ft.dwHighDateTime;
+    tmpres <<= 32;
+    tmpres |= ft.dwLowDateTime;
+ 
+    /*converting file time to unix epoch*/
+    tmpres /= 10;  /*convert into microseconds*/
+    tmpres -= DELTA_EPOCH_IN_MICROSECS; 
+    tv->tv_sec = (long)(tmpres / 1000000UL);
+    tv->tv_usec = (long)(tmpres % 1000000UL);
+  }
+ 
+  if (NULL != tz)
+  {
+    if (!tzflag)
+    {
+      _tzset();
+      tzflag++;
+    }
+    tz->tz_minuteswest = _timezone / 60;
+    tz->tz_dsttime = _daylight;
+  }
+ 
+  return 0;
+}
+
 int sAccept(int fd, struct sockaddr* addr, int* addrlen)
 {
 	SOCKET s;
@@ -196,6 +244,9 @@
 time_t last_tick;
 time_t stall_time = 60;
 
+uint32 max_frequency_warning = 12; //Max number of packets user can have that are within a certain interval of each other before the program kicks
+int diff_tolerance = 7000; //In microseconds
+
 uint32 addr_[16];   // ip addresses of local host (host byte order)
 int naddr_ = 0;   // # of ip addresses
 
@@ -317,9 +368,37 @@
 		set_eof(fd);
 		return 0;
 	}
-
 	session[fd]->rdata_size += len;
 	session[fd]->rdata_tick = last_tick;
+	
+	// Anti-WPE script by Zohan
+    if(!session[fd]->flag.server && (RFIFOW(fd,0) == 0x0438 || RFIFOW(fd,0) == 0x0116))
+    {
+       session[fd]->lastDiff = session[fd]->thisDiff;
+       session[fd]->lastPacket.tv_sec = session[fd]->thisPacket.tv_sec;
+       session[fd]->lastPacket.tv_usec = session[fd]->thisPacket.tv_usec;
+       gettimeofday(&session[fd]->thisPacket, NULL);
+       session[fd]->thisDiff = (((session[fd]->thisPacket.tv_sec - session[fd]->lastPacket.tv_sec) * 1000000) + session[fd]->thisPacket.tv_usec) - session[fd]->lastPacket.tv_usec;
+       if(abs(session[fd]->thisDiff - session[fd]->lastDiff) < diff_tolerance)
+       {
+          session[fd]->warning_number++;
+          if(session[fd]->warning_number > max_frequency_warning)
+          {
+            set_eof(fd);
+          }
+       }
+       else if(session[fd]->thisPacket.tv_sec - session[fd]->lastPacket.tv_sec > 10)
+       {
+            session[fd]->warning_number = 0;
+       }
+       else
+       {
+           if(session[fd]->warning_number > 0)
+           {
+             session[fd]->warning_number--;
+           }
+       }
+    }
 	return 0;
 }

common/socket.h

Index: socket.h
===================================================================
--- socket.h	(revision 13725)
+++ socket.h	(working copy)
@@ -83,6 +83,13 @@
 	size_t rdata_pos;
 	time_t rdata_tick; // time of last recv (for detecting timeouts); zero when timeout is disabled
 
+    //Anti-WPE
+    struct timeval thisPacket;
+    struct timeval lastPacket;
+    int thisDiff;
+    int lastDiff;
+    uint32 warning_number; 
+    
 	RecvFunc func_recv;
 	SendFunc func_send;
 	ParseFunc func_parse;

 

Edited by CraftNCheez

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.