[How2] Ip to Country Function Using (Blocking IP Blocks)(With C++ Codes.)

05/26/2012 16:45 -TÜRK-#1
This function makes, block by ip by country (With MySQL Table.). With this function, you can blocking country ip's. ;)

OK, Now lets see.

--------------------------------------

First run this query in account database.

PHP Code:
DROP TABLE IF EXISTS `iptocountry`;
CREATE TABLE `iptocountry` (
  `
IP_FROMvarchar(30NOT NULL default '',
  `
IP_TOvarchar(30NOT NULL,
  `
COUNTRY_NAMEvarchar(30NOT NULL,
  
PRIMARY KEY  (`IP_FROM`)
ENGINE=MyISAM DEFAULT CHARSET=latin1
And then, open queried table (iptocountry)

OK now lets add some ip's.

IP_FROM: Beginning of the ip block.
IP_TO: Ending of the ip block.
COUNTRY_NAME: You need add some name... Country name etc.

Here is the example image by me:

[Only registered and activated users can see links. Click Here To Register...]

### This function tested by me and %100 working. ###

Here is the C++ code (All of this function.)

PHP Code:
int __cdecl add_blocked_country_ip(int a1)
{
  
int v1// eax@1
  
int v2// edx@1
  
char *v3// ecx@1
  
char v4// zf@1
  
int v6// [sp+20h] [bp-8h]@1

  
v1 operator new(8);
  
v6 v1;
  
v2 v1;
  
v3 = *(char **)&s_blocked_ip[4];
  
v4 = *(_DWORD *)&s_blocked_ip[4] == *(_DWORD *)&s_blocked_ip[8];
  *(
_DWORD *)v1 = *(_DWORD *)a1;
  *(
_DWORD *)(v1 4) = *(_DWORD *)(a1 4);
  if ( 
v4 )
  {
    
std__vector_T_BLOCK_IP___std__allocator_T_BLOCK_IP_______M_insert_aux((int)s_blocked_ipv3, (int)&v6);
    
v2 v6;
  }
  else
  {
    if ( 
v3 )
    {
      *(
_DWORD *)v3 v1;
      
v2 v6;
    }
    *(
_DWORD *)&s_blocked_ip[4] = v3 4;
  }
  return 
dev_log(
           (int)
"block_country.cpp",
           
86,
           (int)
"add_blocked_country_ip",
           
2048,
           
"BLOCKED_IP = %u - %u",
           *(
_DWORD *)v2,
           *(
_DWORD *)(v2 4));

2nd. Code Block

PHP Code:
signed int __cdecl is_blocked_country_ip(int arg)
{
  
int v1// eax@2
  
unsigned int v2// ecx@2
  
int v3// ecx@2
  
char v4// t0@2
  
char v5// t1@2
  
signed int result// eax@8
  
int v7// [sp+4h] [bp-24h]@7
  
int v8// [sp+8h] [bp-20h]@7
  
signed int v9// [sp+Ch] [bp-1Ch]@7
  
const char *v10// [sp+10h] [bp-18h]@7
  
int v11// [sp+14h] [bp-14h]@7
  
int v12// [sp+1Ch] [bp-Ch]@1

  
if ( __inet_aton(arg, &v12) )
  {
    
v1 = *(_DWORD *)s_blocked_ip;
    
v3 v12;
    
v4 BYTE1(v3);
    
BYTE1(v3) = v12;
    
LOBYTE(v3) = v4;
    
v2 __ROR__(v316);
    
v5 BYTE1(v2);
    
BYTE1(v2) = v2;
    
LOBYTE(v2) = v5;
    while ( 
v1 != *(_DWORD *)&s_blocked_ip[4] )
    {
      if ( **(
_DWORD **)v1 <= v2 && v2 <= *(_DWORD *)(*(_DWORD *)v1 4) )
      {
        
v11 arg;
        
v10 "BLOCKED_COUNTRY_IP (%s) : YES";
        
v9 16;
        
v8 = (int)"is_blocked_country_ip";
        
v7 128;
        goto 
LABEL_8;
      }
      
v1 += 4;
    }
    
dev_log((int)"block_country.cpp"133, (int)"is_blocked_country_ip"16"BLOCKED_COUNTRY_IP (%s) : NO"arg);
    
result 0;
  }
  else
  {
    
v11 arg;
    
v9 16;
    
v8 = (int)"is_blocked_country_ip";
    
v10 "BLOCKED_COUNTRY_IP (%s) : YES";
    
v7 118;
LABEL_8:
    
dev_log((int)"block_country.cpp"v7v8v9v10v11);
    
result 1;
  }
  return 
result;

3rd. Code Block

PHP Code:
void __cdecl __static_initialization_and_destruction_0(int a1int a2)
{
  
int v2// eax@17
  
int v3// [sp+4h] [bp-34h]@12

  
if ( a2 == 65535 )
  {
    if ( 
a1 == )
    {
      
std__ios_base__Init__Init(&std____ioinit);
      *(
_DWORD *)s_blocked_ip 0;
      *(
_DWORD *)&s_blocked_ip[4] = 0;
      *(
_DWORD *)&s_blocked_ip[8] = 0;
      *(
_DWORD *)s_block_exception 0;
      
v2 std____default_alloc_template_true_0___allocate(0);
      *(
_DWORD *)s_block_exception v2;
      *(
_DWORD *)(v2 4) = 0;
      *(
_DWORD *)v2 0;
      *(
_DWORD *)&s_block_exception[4] = 0;
      *(
_DWORD *)(*(_DWORD *)s_block_exception 8) = *(_DWORD *)s_block_exception;
      *(
_DWORD *)(*(_DWORD *)s_block_exception 12) = *(_DWORD *)s_block_exception;
    }
    if ( !
a1 )
    {
      if ( *(
_DWORD *)&s_block_exception[4] )
      {
        
std___Rb_tree_std__string_std__string_std___Identity_std__string__std__less_std__string__std__allocator_std__string_____M_erase(
          (int)
s_block_exception,
          *(
void **)(*(_DWORD *)s_block_exception 4));
        *(
_DWORD *)(*(_DWORD *)s_block_exception 8) = *(_DWORD *)s_block_exception;
        *(
_DWORD *)(*(_DWORD *)s_block_exception 4) = 0;
        *(
_DWORD *)(*(_DWORD *)s_block_exception 12) = *(_DWORD *)s_block_exception;
        *(
_DWORD *)&s_block_exception[4] = 0;
      }
      
std____default_alloc_template_true_0___deallocate(*(_DWORD *)s_block_exception20);
    }
    if ( 
a2 == 65535 )
    {
      if ( !
a1 )
      {
        if ( (*(
_DWORD *)&s_blocked_ip[8] - *(_DWORD *)s_blocked_ip) >> )
          
std____default_alloc_template_true_0___deallocate(
            *(
_DWORD *)s_blocked_ip,
            
* ((*(_DWORD *)&s_blocked_ip[8] - *(_DWORD *)s_blocked_ip) >> 2));
      }
      if ( 
a2 == 65535 )
      {
        if ( !
a1 )
          
std__ios_base__Init___Init(&std____ioinitv3);
      }
    }
  }

Greetings from turkey ;)
05/26/2012 16:49 IgorGlock#2
Badboy.

(toll, hat mein Geheimnis verraten -.-)


Viel Spaß bei'm Eintragen der IPs. Wird große Liste sein.
05/26/2012 16:56 -TÜRK-#3
Quote:
Originally Posted by IgorGlock View Post
Badboy.

(toll, hat mein Geheimnis verraten -.-)


Viel Spaß bei'm Eintragen der IPs. Wird große Liste sein.
What is problem Igor? ... -.- LolBoy...
05/26/2012 17:23 iYoshix3#4
hehe, schade :D
05/26/2012 17:39 invisionmt2#5
Why do we need the C++ code?
05/26/2012 17:45 -TÜRK-#6
Quote:
Originally Posted by invisionmt2 View Post
Why do we need the C++ code?
Only sharing...
05/26/2012 18:12 mt2bowded#7
gameyi nasıl açıp ekleyecez c++ kodlarını
05/26/2012 18:41 .Infinity#8
It isn't a C++ Source..
This is "C", decompiled with IDA.
05/26/2012 18:46 [H]olymind#9
Für was ist das code ????
05/26/2012 19:55 -TÜRK-#10
Quote:
Originally Posted by .Infinity View Post
It isn't a C++ Source..
This is "C", decompiled with IDA.
/* This file has been generated by the Hex-Rays decompiler.
Copyright (c) 2009 Hex-Rays <[Only registered and activated users can see links. Click Here To Register...]>

Detected compiler: GNU C++
*/
05/26/2012 20:00 ReckLess.#11
Quote:
Originally Posted by .Infinity View Post
It isn't a C++ Source..
This is "C", decompiled with IDA.
Dude, just a (C ANSI) pseudo-code :rolleyes:
05/26/2012 20:50 IgorGlock#12
Das ist schon C++ halt nur "nachgestellt".

Ich bin mir sicher niemand wird das wirklich machen - das mit IP's eintragen.
05/26/2012 20:56 Computerfreek#13
Quote:
Originally Posted by IgorGlock View Post
Badboy.

(toll, hat mein Geheimnis verraten -.-)


Viel Spaß bei'm Eintragen der IPs. Wird große Liste sein.
Schon, nur gibts dafür sogar schon vorgefertigte Tabellen.
Einfach einen kleinen Query dafür schreiben der das dann übernimmt und gut ist. Seh ich kein Problem drin.
Zudem muss man ja nicht alles eintragen würd ich mal sagen :]
.. und drauf kommen könnte man eig von alleine.
Hatte mir diese Funktion schon seit ich das erste mal die account-db gesehen hatte gedacht nur gibts in meinen Augen keinen wirklichen Grund das (zumindest nicht auf layer 7) abzufangen.