About QQWRY.DAT format

xiaoxiao2021-03-06  125

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 in the file. Pointing ★ If the byte after the IP is 0x01, then the of the IP message is repeated with the previous IP information. At this time, 3 bytes behind 0x01 are national, regional string Offset. You can go to the country according to these three bytes. ★ If the first byte of the country is 0x02, the country string is repeated with the front country or region string, and the three bytes behind the 0x02 are the offset of the string, and the front string can be found according to the offset. . ★ If the first byte of the region is 0x02, the region string is repeated to the front country or region string, and the three bytes behind the 0x02 is the offset of the string, and the front string can be found according to the offset. . ★ It is possible to appear 0x02 in the event of 0x01, and you need to jump twice to find a country, regional string. ★ The normal string is tail with NULL. ★ IP information does not allow repeated, overridden ★ Using indexes to ensure that the unknown data in the original format does not allow the IP message that can be used in linear speed search ★ new format does not allow IP messages for unknown data. If there is an IP message of unknown data, it will greatly increase the file length. The head 4 bytes of the file is the offset of the first element of the index area, and the second 4 byte is the offset of the last element of the index area. Through these two offsets, you can quickly find IP information with two bits. Such as: an IP information is that the IP to be queried is 150 Starting End Countries 100 200 China Beijing first finds the last element of the start IP less than 150 in the index area. By indexing, find the end IP, if 150 is greater than the end IP, The description is unknown; if 150 is less than or equal to end IP, it is found in the country. // ipsearch: defines the entry point for the dll application.brib.

//

#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;

}

转载请注明原文地址:https://www.9cbs.com/read-126063.html

New Post(0)