About QQWRY format
Author CNSS 2004-8-18 Copyright Reprint, please indicate http://blog.9cbs.net/cnss
Recently I have written a better format than QQWRY, click here. I saw a blog on QQWRY format: http://blog.9cbs.net/taft/archive/2004/08/18/77559.aspx
I can't think of qqwry, this is designed two years ago, this format should be eliminated. Why do you say that it is index binary look to reduce memory occupancy and improve the lookup speed.
Since IP data is used, IP data should be divided into minimal sheets, and there are two data of A, B, and B data completely override A data, then converted to QQWRY two data becomes three. If the original data is very If you have an article, you can avoid this phenomenon, but this is impossible, tens of thousands of data will become more chaotic, so the size of QQWRY will increase rapidly, and the growth is not particularly fast, because the format has a replicated data compression.
Qqwry.dat: "咦? I didn't eat so much, how is it fat !?"
The article is the format of the author, I will send it once again .0x2 0x0 0x0 0x0 is not wrong, it may be placed on the copyright information to the wind, and attached to the ipsearch.dll source code.
----------------------------------------------- New format description
Mainly divided into data area and index zone ★ Data area element: store IP information: End IP (4 bytes), country (unordered long), region (unordered long) arrangement sequence: no requirements ★ Index area Element: Store IP Information in the information: start IP (4 bytes), index value (3 bytes) Arrangement sequence: Start IP is arranged in ascending order ★ IP is 4 bytes, such as "255.0.0.0" is 0xff000000, existing files To 00 00 00 00 ff (byte) ★ The index value is the location of the IP message
//
#include "stdafx.h"
#include
#include
Extern "C" __DECLSPEC (DLLEXPORT) VOID * __CDECL _Getaddress (const char * gg); void * RET [2]; // for return
Char * ptr = null; // ptr of image
Char * p = null; // point to index
Unsigned int total; // ip count
Inline unsigned int GET_3B (Const Char * MEM)
{
Return 0x00fffffff & * (unsigned int *) (MEM);
}
Inline Void Load (Void)
{
Handle hnd; // file handle
DWORD NUMBEROFBYTESREAD; // LEN
Char Text [2048]; // Patch
Char * TEMP;
Unsigned int Len;
// Get Patch
IF (! getModuleFileName (0, Text, 2048))
Return;
Temp = Strrchr (Text, 92); // 92 = '/'
* (TEMP 1) = null;
STRCAT (TEMP, "QQWRY.DAT");
// CreateFile
HND = CREATEFILE (text, generic_read, file_share_read, null,
Open_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
IF (Invalid_Handle_Value == HND)
{
:: MessageBox (Null, Text, "You can't open the file!", Null);
Return;
}
// Get Len
Len = setfilepointer (HND, NULL, NULL, FILE_END);
SetFilePointer (HND, NULL, NULL, FILE_BEGIN);
// malloc
PTR = (char *) Malloc (Len 9);
IF (! PTR)
{
CloseHandle (HND);
:: MessageBox (NULL, "You cannot assign memory!", Null, null;
Return;
}
// read
IF (! Readfile (HND, PTR, Len, & NumberofbytesRead, NULL))
{
CloseHandle (HND);
Free (PTR);
:: MessageBox (Null, Text, "You can't read files!", Null;
Return;
}
CloseHandle (HND);
// Calc Total - 1
Total = (* (unsigned int *) PTR 1) - * (unsigned int *) PTR);
// Check file
IF (Total% 7! = 0)
{
Free (PTR);
:: MessageBox (null, text, "Qqwry.dat file is damaged!", Null;
Return;
}
Total / = 7;
Total
P = PTR * (unsigned int *) PTR; // PTR OF INDEX Area
}
Inline Unsigned Int Str2ip (Const Char * LP)
{
Unsigned int RET = 0;
Unsigned int now = 0; while (* lp)
{
IF ('.' == * LP)
{
RET = 256 * RET NOW;
NOW = 0;
}
Else
Now = 10 * Now * lp - '0';
LP;
}
RET = 256 * RET NOW;
Return Ret;
}
Void * __cdecl _getaddress (const char * ipStr)
{
IF (NULL == P)
{
RET [0] = "Unable to open data";
RET [1] = ""
Return Ret;
}
Unsigned int ip = str2ip (IPSTR);
Char * now_P;
Unsigned int based = 0, end = Total;
While (1)
{
IF (begin> = End - 1)
Break;
IF (iP <* (unsigned int *) (P (Begin End) / 2 * 7))
End = (Begin End) / 2;
Else
Begin = (Begin End) / 2;
}
Unsigned int Temp = GET_3B (P 7 * Begin 4);
IF (ip <= * (unsigned int *) // ok, found
{
Now_P = PTR TEMP 4;
IF (0x01 == * now_P)
Now_P = PTR GET_3B (now_P 1);
// country
IF (0x02 == * now_P) // jump
{
RET [0] = PTR GET_3B (now_P 1);
NOW_P = 4;
}
Else
{
Ret [0] = now_P;
For (; * now_p; now_p)
;
now_P;
}
// local
IF (0x02 == * now_P) // jump
RET [1] = PTR GET_3B (now_P 1);
Else
RET [1] = now_P;
}
Else
{
RET [0] = "Unknown data";
RET [1] = ""
}
Return Ret;
}
Bool apientry dllmain (Handle Hmodule,
DWORD UL_REASON_FOR_CALL,
LPVOID LPRESERVED
)
{
Switch (ul_reason_for_call)
{
// Case DLL_THREAD_ATTACH:
// Case DLL_THREAD_DETACH:
Case DLL_Process_attach: // attach
{
LOAD ();
}
Break;
// ------------------------------------
Case DLL_PROCESS_DETACH: // Detach
{
Free (PTR);
}
}
Return True;
}