Extension creation introduction

zhaozj2021-02-16  35

Online game packaging technology is one of the concerns of most programming enthusiasts, let us study this question in this article.

Don't look at this problem, but it is very popular in technology, and there are many ways to achieve (for example, APIHOK, VXD, Winsock2 can be implemented), where we cannot be involved in each technology and method, so I will explain a detailed explanation of Winsock2 technology, even if I have a throwing brick.

Since most readers are not very well understood by the package programming, I will briefly introduce related knowledge here:

APIHOOK:

Since Windows puts the functionality provided by the kernel into the API, everyone must pass the API. In other words, we must capture the data package, you must first know and capture this API, get it from the API Packet information.

Vxd:

Directly achieve the capture of the package information directly by controlling the VXD driver, but VXD can only be used for Win9x.

Winsock2:

Winsock is a Windows network programming interface, Winsock works in the application layer, which provides a high-level data transfer programming interface with the underlying transfer protocol, Winsock2 is the service provider interface provided by Winsock 2.0, but can only be used under Win2000.

Ok, let's start entering WinSock2 blocking programming.

In the package programming, I am ready to be divided into two steps: 1. Capture of the package, 2, the sector of the package.

First we have to achieve the capture of the package:

Delphi's packaged Winsock is 1.0, very natural Winsock2 is not used. If you want to use Winsock2, we have to make an interface to Winsock2 in Delphi, you can use Winsock2.

1. How do I do WINSOCK2 interface?

1) We must first define the type used by Winsock 2.0, where we do a demonstration in the WSA_DATA type, you can give a three-to-use package to implement Winsock2.

We must know that the WSA_Data type will be used for WSAStartup (WSData: TWSADATA): Integer;, you will find that WSDATA is a reference parameter. In the incoming parameter, the number of variables is the address of the variable, so we do the following for WSA_DATA. Package:

Const

WSADESCRIPTION_LEN = 256;

WSASYS_STATUS_LEN = 128;

Type

PWSA_DATA = ^ TWSA_DATA;

WSA_DATA = Record

WVERSION: WORD;

WORHVERSION: WORD;

Szdescription: array [0..wsadescription_len] of char;

SzsystemStatus: array [0..wsasys_status_len] of char;

IMAXSOCKETS: WORD;

IMAXUDPDG: WORD;

LPVENDORINFO: PCHAR;

END;

TWSA_DATA = WSA_DATA;

2) We have to introduce Winsock2 functions from WS2_32.dll, where we also do function with WSAStartup as an example:

Function WSAStartup (WVersionRequired: Word; Var WSData: TWSADATA): Integer; stdcall;

IMPLEMENTATION

Const winsocket2 = 'ws2_32.dll';

Function WSAStartup; External Winsocket Name 'WSAStartup'; Through the above method, we can interface to Winsock2. Let's use Winsock2 to make a pack capture, but you must have a network card. Because it involves the problem of online game security issues, we are here for packet capture with IP packets. If you are not very clear, please check MSDN:

1) We want to start WSA, at this time, the WSAStartup function to use, the usage is as follows:

Integer WSAStartup

WVERSIONREQUIRED: WORD,

WSDATA: TWSA_DATA

);

2) Use the socket function to get the Socket handle, m_hsocket: = socket (AF_INET, SOCK_RAW, IPPROTO_IP); Usage is as follows:

Integer Socket (AF: Integer,

Struct: Integer,

Protocol: integer

);

m_hsocket: = Socket (AF_INET, SOCK_RAW, IPPROTO_IP); M_HSocket is the Socket handle, AF_INET, SOCK_RAW, and IPPROTO_IP are constants.

3) Define the SOCK_ADDR type, follow our network card IP to the SOCK_ADDR type, then we use the bind function to bind our network card, the Bind function is as follows:

Type

IN_ADDR = Record

S_addr: pchar;

END;

Type

TSOCK_ADDR = Record

SIN_FAMILY: WORD;

SIN_PORT: WORD;

SIN_ADDR: IN_ADDR

SIN_ZERO: ARRAY [0..7] of char;

END;

VAR

Localaddr: Tsock_addr;

Localaddr.sin_family: = af_INet;

Localaddr.sin_Port: = 0;

Localaddr.sin_addr.s_addr: = inet_addr ('192.168.1.1'); // Here your own network card IP address, and inet_addr this function is the function of Winsock2.

Bind (M_HSocket, Localaddr, Sizeof (Localaddr));

4) Use WSAIOCTL to register the WSA input and output components, which are as follows:

Integer WSAIOCTL (S: INTEGER,

DWIOCONTROLCODE: INTEGER,

LPVINBUFFER: INTEGER,

Cbinbuffer: Integer,

LPVOUTBUFFER: INTEGER,

CBoutBuffer: Integer,

LPCBBYTESRETURNED: INTEGER,

LPOVERLAPPED: INTEGER,

LPCompletionRoutine: Integer

);

5) The following is died, in the dead circulation block, to achieve the reception of data. However, the middle of the ring should be delayed in Sleep (), otherwise the program will be wrong.

6) In the cycle block, use the RECV function to receive data, the RECV function is as follows:

Integer Recv (S: Integer,

Buffer: array [0..4095] of byte,

Length: integer,

Flags: integer,

);

7) In Buffer is the data we receive, if we want to know where the data is sent, then we want to define a certain IP package structure, use copymemory () to read the IP information from the buffer. However, it is necessary to read the sixteen-based data to be converted.

I looked at the package captured, it was a little start, but I have to tell you that the package is very easy, but many game packages are encrypted, if you want to figure out What is what you need to packet decryption.

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

New Post(0)