I have seen the online game plug-in production (6)

zhaozj2021-02-16  54

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 well understood, I will introduce related knowledge here: APIHOOK: Since Windows provides the functionality provided by Windows to the API, everyone must pass the API, in other words It is to say that we have to capture the data package, you must have to know and capture this API, get the package information from the API. 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 Windows network programming interface, Winsock works in the application layer, which provides high-level data transfer programming interfaces that are independent of the underlying transfer protocol, Winsock2 is the service provider interface provided by Winsock 2.0, but can only be used in 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 of all, we have to achieve the capture of the package: the Winsock of Delphi package 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; wHighVersion: 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 need to introduce WS2_32.DLL function winsock2, and we are also here to make an example WSAStartup function introduction: function WSAStartup (wVersionRequired: Word; var wsdata: twsadata): integer; stdcall; importation

Const winSocket2 = 'ws2_32.dll'; function wsastartup; external winsocket name 'wsastartup';

Through the above methods, we can interface to Winsock2. Let's use Winsock2 to make a package capture, but you must have a network card. Because we involve a security problem that is working, we are here as an IP packet as an example, if you are not very clear, please check MSDN: 1) We want to boot WSA, this when a use to WSAStartup function, used as follows: INTEGER WSAStartup (wVersionRequired: word, WSData: TWSA_DATA); 2) obtained using the socket function socket handle, m_hSocket: = socket (AF_INET, SOCK_RAW, IPPROTO_IP); used 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 a 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 do loop, the endless loop In block, the data is received. However, the middle of the ring should be delayed in Sleep (), otherwise the program will be wrong. 6) In the circulation 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 buffer, However, it is read out that hexadecimal data needs 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.

Copyright Description: You can copy, distribute, download this document freely. However, you may not take it, change this article, or use this article to see any form of interest.

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

New Post(0)