Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to view binary streams in a table

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

​ has recently been collating the knowledge that has been deposited in game development for more than 10 years. A lot of knowledge is learned and realized deeply because of hobbies. Maybe there was a lot of energy and no priority at all. Purely in order to realize their own momentary ideas. In retrospect, I still remember the pleasure of the original harvest. It was still the era of PC games. C++ is the mainstream programming language. The database uses MSSQL.

A lot of ​ player data is stored in binary streams. Each read and write requires C++ to be loaded into memory to look at the memory data one by one through debug mode. In particular, I want to see whether the player data is normal, etc., because it is a binary stream. It is very difficult to view directly. Pain points inspire programmers to instinctively do everything in order to be lazy. Can you view the binary stream directly using the database stored procedure. It is realized by database function.

​ database is also a powerful language. So binary access can be done by the database. At the same time, fully understand the relevance of various languages in the binary stream. Learning these fully reflects that anything is related and can be transformed into each other.

The way to view binaries

-- Parameter 1: BUF; Parameter 2: view Type; Parameter 3: start position; Parameter 4: view character occupancy Bytes -- use select dbo.Peims_LookBuf ()-- View type: 1 for short, 2 for plastic surgery 3 represents the string CREATE FUNCTION Peims_LookBuf (@ Buf VARBINARY (2560), @ LookType INT, @ nBegin INT, @ nLen INT) RETURNS VARCHAR (2560) ASBEGIN DECLARE @ BackStr VARCHAR (2560) DECLARE @ nHight INT IF @ LookType = 1 BEGIN SET @ nHight = CAST (SUBSTRING (@ Buf) @ nBegin+1,1) AS INT) IF @ nHight > 127negative BEGIN SET @ BackStr=CAST ((CAST (SUBSTRING (@ Buf, @ nBegin,1) AS INT) + (CAST (SUBSTRING (@ Buf)) @ nBegin+1,1) AS INT)-256) * POWER (2) AS VARCHAR) END ELSE BEGIN SET @ BackStr=CAST ((CAST (SUBSTRING (@ Buf, @ nBegin,1) AS INT) + CAST (SUBSTRING (@ Buf)) @ nBegin+1,1) AS INT) * POWER (2Magne8) AS VARCHAR) END END IF @ LookType = 2 BEGIN SET @ nHight = CAST (SUBSTRING (@ Buf) @ nBegin+3,1) AS INT) IF @ nHight > 127negative BEGIN SET @ BackStr=CAST ((CAST (SUBSTRING (@ Buf, @ nBegin,1) AS INT) + CAST (SUBSTRING (@ Buf)) @ nBegin+1,1) AS INT) * POWER (2Magne8) + CAST (SUBSTRING (@ Buf, @ nBegin+2,1) AS INT) * POWER (2Magne16) + (CAST (SUBSTRING (@ Buf)) @ nBegin+3,1) AS INT)-256) * POWER (2Magazine 24) AS VARCHAR) END ELSE BEGIN SET @ BackStr=CAST ((CAST (SUBSTRING (@ Buf, @ nBegin,1) AS INT) + CAST (SUBSTRING (@ Buf)) @ nBegin+1,1) AS INT) * POWER (2Power8) + CAST (SUBSTRING (@ Buf, @ nBegin+2,1) AS INT) * POWER (2Mague 16) + CAST (SUBSTRING (@ Buf, @ nBegin+3,1) AS INT) * POWER (2Magi 24) AS VARCHAR) END END IF @ LookType = 3 BEGIN SET @ BackStr=CAST (SUBSTRING (@ Buf, @ nBegin) @ nLen) AS VARCHAR) END RETURN (@ BackStr) END

Database generates binary shaping

CREATE FUNCTION Peims_ADDIntBuf (@ nInt INT) RETURNS VARBINARY (256) ASBEGIN DECLARE @ BackBuf VARBINARY (256) SET @ BackBuf=CAST (@ nInt AS BINARY (4)) SET @ BackBuf=SUBSTRING (@ BackBuf,4,1) + SUBSTRING (@ BackBuf,3,1) + SUBSTRING (@ BackBuf,2,1) + SUBSTRING (@ BackBuf,1,1) RETURN (@ BackBuf) END

Database generates binary short form

CREATE FUNCTION Peims_ADDShortBuf (@ nShort SMALLINT) RETURNS VARBINARY (256) ASBEGIN DECLARE @ BackBuf VARBINARY (256) SET @ BackBuf=CAST (@ nShort AS BINARY (2)) SET @ BackBuf=SUBSTRING (@ BackBuf,2,1) + SUBSTRING (@ BackBuf,1,1) RETURN (@ BackBuf) END

Delete the data at the beginning of a certain location

CREATE FUNCTION Peims_DelBuf (@ Buf VARBINARY (2560), @ nBegin INT, @ nLen INT) RETURNS VARBINARY (2560) ASBEGIN DECLARE @ BackStr VARBINARY (2560) SET @ BackStr=SUBSTRING (@ Buf,1,@nBegin-1) + SUBSTRING (@ Buf,@nBegin+@nLen,datalength (@ Buf)-@ nBegin-@nLen+1) RETURN (@ BackStr) END

Modify the data at the beginning of a certain location

CREATE FUNCTION Peims_UpdateBuf (@ Buf VARBINARY (2560), @ vValue VARBINARY, @ nLen INT) RETURNS VARBINARY (2560) ASBEGIN DECLARE @ BackStr VARBINARY (2560) SET @ BackStr=SUBSTRING (@ Buf,1,@nBegin-1) SET @ BackStr=@BackStr+@vValue SET @ BackStr=@BackStr+SUBSTRING (@ Buf,@nBegin+@nLen,datalength (@ Buf)-@ nBegin-@nLen+1) RETURN (@ BackStr) END

Insert content in a location

CREATE FUNCTION Peims_InsertBuf (@ Buf VARBINARY (2560), @ vValue VARBINARY (2560), @ nBegin INT) RETURNS VARBINARY (2560) ASBEGIN DECLARE @ BackStr VARBINARY (2560) SET @ BackStr=SUBSTRING (@ Buf,1,@nBegin-1) SET @ BackStr=@BackStr+@vValue SET @ BackStr=@BackStr+SUBSTRING (@ Buf,@nBegin,datalength (@ Buf)-@ nBegin+1) RETURN (@ BackStr) END

Application example: analogy promotion. So binary access can be done by the database. Learning these fully reflects that anything is related and can be transformed into each other.

DECLARE @ BackBuf VARBINARY (2560) SET @ BackBuf=dbo.Peims_ADDIntBuf (2147483647) SET @ BackBuf= @ BackBuf+CAST ('pe China zhongguo' AS BINARY (3303))-- binary SET @ BackBuf= @ BackBuf+dbo.Peims_ADDShortBuf (- 23567) SET @ BackBuf= @ BackBuf+dbo.Peims_ADDIntBuf (25698456) SELECT datalength (@ BackBuf) SELECT dbo.Peims_LookBuf (@ BackBuf,2,1,4), dbo.Peims_LookBuf (@ BackBuf,3,5330), dbo.Peims_LookBuf (@ BackBuf,1,335,2) Dbo.Peims_LookBuf (@ BackBuf,2,337,4)-- Delete a piece SEt @ BackBuf=dbo.Peims_DelBuf (@ BackBuf,335,2) SELECT dbo.Peims_LookBuf (@ BackBuf,2,1,4), dbo.Peims_LookBuf (@ BackBuf,3,5330),-- dbo.Peims_LookBuf (@ BackBuf,1,5,2), dbo.Peims_LookBuf (@ BackBuf,2,335,4)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report