CN114818656B - Binary file analysis method, device, equipment and medium based on gray scale upgrading - Google Patents

Binary file analysis method, device, equipment and medium based on gray scale upgrading Download PDF

Info

Publication number
CN114818656B
CN114818656B CN202210756625.5A CN202210756625A CN114818656B CN 114818656 B CN114818656 B CN 114818656B CN 202210756625 A CN202210756625 A CN 202210756625A CN 114818656 B CN114818656 B CN 114818656B
Authority
CN
China
Prior art keywords
data
line
field
length
file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210756625.5A
Other languages
Chinese (zh)
Other versions
CN114818656A (en
Inventor
王义开
秦玮
何磊
宋江坤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huarui Distributed Technology Changsha Co ltd
Shenzhen Huarui Distributed Technology Co ltd
Original Assignee
Huarui Distributed Technology Changsha Co ltd
Shenzhen Huarui Distributed Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huarui Distributed Technology Changsha Co ltd, Shenzhen Huarui Distributed Technology Co ltd filed Critical Huarui Distributed Technology Changsha Co ltd
Priority to CN202210756625.5A priority Critical patent/CN114818656B/en
Publication of CN114818656A publication Critical patent/CN114818656A/en
Application granted granted Critical
Publication of CN114818656B publication Critical patent/CN114818656B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/205Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Human Computer Interaction (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to the field of data processing, and provides a binary file parsing method, a binary file parsing device, binary file parsing equipment and a binary file parsing medium based on gray scale upgrading, which can configure the file format of a binary file as a target format when gray scale upgrading is executed, to assist in file parsing, further parsing the message header of the target file according to the target format to obtain a data pattern of the target file, determining the length of each line of data in the target file according to the line data mode so as to pertinently determine the length of each line of data according to different line data modes, determining the initial index of each line of data according to the length of each line of data, analyzing the target file according to the initial index of each line of data by using an old version program, and then the effective analysis of the newly defined binary file after the gray scale upgrade is realized by the old version program, and the problems that the binary file cannot be analyzed by the old version program after the gray scale upgrade and the analysis is wrong are avoided.

Description

Binary file analysis method, device, equipment and medium based on gray scale upgrading
Technical Field
The invention relates to the technical field of data processing, in particular to a binary file analysis method, a binary file analysis device, binary file analysis equipment and binary file analysis media based on gray scale upgrading.
Background
The binary file is a file format with a compact structure, and the size of the file can be reduced to the maximum extent, but the self-resolving capability and readability of the file are lost at the same time.
The use of binary file formats in the prior art does not support gray scale upgrades. Since the format of the file is changed after the gray scale upgrade, the index confusion will occur when the old version program is used to analyze the new binary file.
However, under the background that the system complexity is higher and the system stability is more and more important, the gray scale upgrade has become an important measure for reducing the upgrade risk, and in order to complete the gray scale upgrade in a minimized manner, besides requiring the new version to be compatible with the old version of the file, the new version needs to provide the capability of analyzing the new file, so how to utilize the binary file to interact normally in the programs of the new version and the old version during the gray scale upgrade becomes an urgent problem to be solved, and especially how to utilize the old version of the file to analyze the binary file is very important.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a binary file parsing method, apparatus, device and medium based on gray scale upgrading, which aims to solve the problem that the binary file cannot be parsed by using an old version program during gray scale upgrading.
A binary file analysis method based on gray scale upgrading comprises the following steps:
when gray scale upgrading is executed, configuring a file format of a binary file as a target format;
when detecting that an old version program receives any binary file, determining the any binary file as a target file;
analyzing the message header of the target file according to the target format to obtain a line data mode of the target file;
determining the length of each line of data in the target file according to the line data mode;
determining the initial index of each line of data according to the length of each line of data;
and analyzing the target file by utilizing the old version program according to the initial index of each line of data.
According to the preferred embodiment of the present invention, the configuring the file format of the binary file as the target format includes:
configuring a first field for recording a message header size of the binary file;
configuring a second field for recording a row data pattern of the binary file;
when the line data mode is a fixed line width mode, configuring a third field for recording the fixed line width of each line of data of the binary file, and adding the first field, the second field and the third field in a message header of the binary file; or
And when the line width mode is a non-fixed line width mode, adding the first field and the second field in a message header of the binary file, respectively configuring each fourth field for recording the line width of each line of data of the binary file, and correspondingly adding each fourth field at the initial position of a message body of each line of data of the binary file.
According to a preferred embodiment of the present invention, the analyzing the message header of the target file according to the target format to obtain the line data pattern of the target file includes:
reading the second field from the message header of the target file according to the target format;
and determining the line data mode of the target file according to the data content of the second field.
According to a preferred embodiment of the present invention, the determining the length of each line of data in the target file according to the line data pattern includes:
when the line width mode is the fixed line width mode, reading the third field from the message header of the target file, and determining the length of each line of data in the target file according to the data content of the third field; or
And when the line data mode is the non-fixed line width mode, reading a fourth field of each line of data from a message body of the target file, and determining the length of each line of data in the target file according to the data content of the fourth field of each line of data.
According to a preferred embodiment of the present invention, the determining the start index of each line of data according to the length of each line of data includes:
reading the first field from a message header of the target file;
determining the message header length of the target file according to the data content of the first field;
determining the initial position of the message body of the target file according to the length of the message header as the initial index of the head line data of the target file;
determining the length of the head line data according to the length of each line of data;
calculating the difference value between the length of the head line data and the length of the message header to obtain the length of the message body of the head line data;
determining the length of each line of data as the message body length of each line of data from the second line of data;
and splitting the message body according to the length of the message body of each line of data to obtain the initial index of each line of data.
According to a preferred embodiment of the present invention, the parsing the target file according to the start index of each line of data by using the old version program includes:
acquiring the length of an analyzable field of each line of data of the old version program;
for each line of data, when detecting that the length of the field analyzed by the old version program reaches the length of the corresponding analyzable field, skipping the current line of data, and determining the next line of data of the current line of data according to the initial index of each line of data;
and continuing to analyze the target file from the next line of data.
A grayscale upgrade based binary file parsing apparatus, comprising:
a configuration unit for configuring a file format of the binary file as a target format when performing the gray scale upgrade;
the determining unit is used for determining any binary file as a target file when detecting that the old version program receives the binary file;
the analysis unit is used for analyzing the message header of the target file according to the target format to obtain a line data mode of the target file;
the determining unit is further configured to determine the length of each line of data in the target file according to the line data pattern;
the determining unit is further configured to determine a start index of each line of data according to the length of each line of data;
and the analysis unit is also used for analyzing the target file by utilizing the old version program according to the initial index of each line of data.
According to a preferred embodiment of the present invention, the configuration unit is specifically configured to:
configuring a first field for recording a message header size of the binary file;
configuring a second field for recording a row data pattern of the binary file;
when the line data mode is a fixed line width mode, configuring a third field for recording the fixed line width of each line of data of the binary file, and adding the first field, the second field and the third field in a message header of the binary file; or
And when the line width mode is a non-fixed line width mode, adding the first field and the second field in a message header of the binary file, respectively configuring each fourth field for recording the line width of each line of data of the binary file, and correspondingly adding each fourth field at the initial position of a message body of each line of data of the binary file.
A computer device, the computer device comprising:
a memory storing at least one instruction; and
and the processor executes the instructions stored in the memory to realize the binary file analysis method based on the gray scale upgrading.
A computer-readable storage medium having stored therein at least one instruction for execution by a processor in a computer device to implement the gray scale based binary file parsing method.
According to the technical scheme, the method can realize accurate analysis of the binary file by the old version program during gray scale upgrading.
Drawings
FIG. 1 is a flowchart of a binary file parsing method based on gray scale upgrading according to a preferred embodiment of the present invention.
Fig. 2 is a functional block diagram of a binary file parsing apparatus based on gray scale upgrading according to a preferred embodiment of the present invention.
Fig. 3 is a schematic structural diagram of a computer device according to a preferred embodiment of the present invention for implementing a binary file parsing method based on gray scale upgrading.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in detail with reference to the accompanying drawings and specific embodiments.
Fig. 1 is a flow chart of a binary file parsing method based on gray scale upgrading according to a preferred embodiment of the present invention. The order of the steps in the flow chart may be changed and some steps may be omitted according to different needs.
The binary file parsing method based on gray scale upgrading is applied to one or more computer devices, where the computer devices are devices capable of automatically performing numerical calculation and/or information processing according to preset or stored instructions, and hardware thereof includes, but is not limited to, a microprocessor, an Application Specific Integrated Circuit (ASIC), a Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), an embedded device, and the like.
The computer device may be any electronic product capable of performing human-computer interaction with a user, for example, a Personal computer, a tablet computer, a smart phone, a Personal Digital Assistant (PDA), a game machine, an interactive web Television (IPTV), an intelligent wearable device, and the like.
The computer device may also include a network device and/or a user device. The network device includes, but is not limited to, a single network server, a server group consisting of a plurality of network servers, or a Cloud Computing (Cloud Computing) based Cloud consisting of a large number of hosts or network servers.
The server may be an independent server, or may be a cloud server that provides basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a Network service, cloud communication, a middleware service, a domain name service, a security service, a Content Delivery Network (CDN), a big data and artificial intelligence platform, and the like.
Among them, Artificial Intelligence (AI) is a theory, method, technique and application system that simulates, extends and expands human Intelligence using a digital computer or a machine controlled by a digital computer, senses the environment, acquires knowledge and uses the knowledge to obtain the best result.
The artificial intelligence base technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a robot technology, a biological recognition technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and the like.
The Network in which the computer device is located includes, but is not limited to, the internet, a wide area Network, a metropolitan area Network, a local area Network, a Virtual Private Network (VPN), and the like.
S10, when performing the gradation upgrade, the file format of the binary file is configured as the target format.
The gray scale upgrading is a local upgrading mode, and adverse effects caused by the upgraded program bug can be reduced to the greatest extent.
The traditional binary file does not support the gray scale upgrading, and when the program version is inconsistent with the file version, the situation of disordered analysis or abnormal program occurs.
Therefore, the present embodiment reconfigures the file format of the binary file, and uses the file as a new format of all the binary files after the gray scale upgrade.
Specifically, the file format of the configuration binary file as the target format includes:
configuring a first field for recording a message header size of the binary file;
configuring a second field for recording a line data mode of the binary file;
when the line data mode is a fixed line width mode, configuring a third field for recording the fixed line width of each line of data of the binary file, and adding the first field, the second field and the third field in a message header of the binary file; or
And when the line width mode is a non-fixed line width mode, adding the first field and the second field in a message header of the binary file, respectively configuring each fourth field for recording the line width of each line of data of the binary file, and correspondingly adding each fourth field at the initial position of a message body of each line of data of the binary file.
The fixed line width mode refers to that each line of data of the binary file has the same line width, that is, the length of each line of data is the same.
The non-fixed line width mode means that each line of data of the binary file does not have the same line width, that is, the length of each line of data is the same and also different.
In this embodiment, other fields may also be added to the message header of the binary file according to actual requirements. For example: a field representing a partition number (which can be adjusted according to actual service requirements) can be added, or a field representing a node name can be added, or a field representing signature information can be added, and the like.
Taking the line data mode as the fixed line width mode as an example, a fixed length (53 bytes) field is added as a message header, and then the first 53 bytes of the first message starting from the 54 th byte as the message header may respectively include the following fields:
[0,8) bytes (i.e., the first field): the first 8 bytes are used to define the header size, here 53;
[8,9) bytes (i.e., the second field): 1 byte is used to define a row data pattern;
[9,41) bytes: 32 bytes are used for defining signature information such as node names or file descriptions;
[41,49) bytes (i.e., the third field): 8 bytes are used to define the length of each line of data (from which old version programs can automatically calculate the starting index of the next line of messages);
[49,53) bytes: the last 4 bytes are used to define the total number of data lines of the binary file.
Taking the row data mode as the non-fixed row width mode as an example, the third field may be deleted from the message header in the above example, and a corresponding fourth field may be added at the beginning byte of each row of data in the message body. For example: the fourth field may be 4 bytes, representing the length of each row of data.
The length of each row of data in the binary file is determined by reconfiguring the file format of the binary file, so that the program of any new or old version can analyze the binary file according to the length of each row of data, and the problem of messy message bytes is avoided.
And S11, when detecting that the old version program receives any binary file, determining the any binary file as a target file.
The arbitrary binary file may be a file redefined after the gray scale is upgraded, that is, a file with a newly added field at a suffix of each row of records. For such newly defined files, in the conventional parsing scheme, when the old version program parses the fields built in the program, the newly added field error is parsed into the starting byte of the next record, and actually, the newly added field is the last byte of the current record, which may cause a parsing error.
The arbitrary binary file may also be a file that is not redefined after the grayscale is upgraded, and at this time, the program of any version, whether it is a new version or an old version, may perform normal parsing on the arbitrary binary file.
S12, analyzing the message header of the target file according to the target format to obtain the line data mode of the target file.
In this embodiment, the analyzing the message header of the target file according to the target format to obtain the line data pattern of the target file includes:
reading the second field from the message header of the target file according to the target format;
and determining the line data mode of the target file according to the data content of the second field.
Wherein the second field is defined in a header of the target file for representing a line data pattern of the target file.
Wherein the row data pattern may include, but is not limited to: fixed line width mode, non-fixed line width mode.
And S13, determining the length of each line of data in the target file according to the line data mode.
In this embodiment, the determining the length of each line of data in the target file according to the line data pattern includes:
when the line width mode is the fixed line width mode, reading the third field from the message header of the target file, and determining the length of each line of data in the target file according to the data content of the third field; or
And when the line data mode is the non-fixed line width mode, reading a fourth field of each line of data from the message body of the target file, and determining the length of each line of data in the target file according to the data content of the fourth field of each line of data.
That is, when the line data pattern is the fixed line width pattern, since each line of data has the same line width, the length of each line of data can be obtained by directly obtaining the data content of the corresponding field from the message header.
When the line data mode is the non-fixed line width mode, the length of each line of data may be different, so that the data content of the corresponding field of the message body of each line of data may be read to obtain the length of each line of data respectively.
And S14, determining the initial index of each line of data according to the length of each line of data.
In this embodiment, the determining the start index of each line of data according to the length of each line of data includes:
reading the first field from a message header of the target file;
determining the message header length of the target file according to the data content of the first field;
determining the initial position of the message body of the target file according to the length of the message header as the initial index of the first line data of the target file;
determining the length of the head line data according to the length of each line of data;
calculating the difference value between the length of the head line data and the length of the message header to obtain the length of the message body of the head line data;
determining the length of each line of data as the message body length of each line of data from the second line of data;
and splitting the message body according to the length of the message body of each line of data to obtain the initial index of each line of data.
For example: when the length of the message header is 50 bytes, starting from the 51 th byte of the first line data as the initial index of the first line data of the target file, when the length of the first line data is determined to be 100 bytes, the length of the message body of the first line data is 100-50=50 bytes, at this time, the initial index of the second line of data is 101 th byte, if the length of the second line of data of the message body is determined to be 100, starting from the 101 th and 200 th bytes as the message body of the second line of data, the initial index of the third line of data is 201 th byte, and so on, the initial index of each line of data is obtained.
And S15, analyzing the target file by using the old version program according to the initial index of each line of data.
In this embodiment, the parsing the target file according to the start index of each line of data by using the old version program includes:
acquiring the length of an analyzable field of each line of data of the old version program;
for each line of data, when detecting that the length of the field analyzed by the old version program reaches the length of the corresponding analyzable field, skipping the current line of data, and determining the next line of data of the current line of data according to the initial index of each line of data;
and continuing to analyze the target file from the next line of data.
It will be appreciated that the old version program will configure the parse-able field length for each row of data and parse the binary file according to the parse-able field length for each row of data.
For example: when the resolvable field length of each line of data of the old version program is 100 bytes, in the resolving process, if the current line of data has 200 bytes in total but the resolving field length of the current line of data reaches 100 bytes, the resolving of the current line of data is stopped, and the next line of data is directly jumped to continue resolving, so as to avoid invalid resolving, realize the compatibility of the old version program to the newly defined binary file, and avoid resolving errors.
Moreover, since fields which are not analyzed and skipped in each line of data are newly added fields, the old version program cannot process the fields, so that even if the fields are not analyzed, the execution of the old version program is not influenced, program errors are avoided, and the analysis efficiency is improved.
Moreover, the new version program has adaptability to the binary file newly defined after the gray scale is upgraded, so that the binary file format reconfigured by the embodiment can realize the up-down compatibility of the new version program and the old version program after the gray scale is upgraded, the flexibility and the adaptability of the gray scale upgrade are increased, and the new version program has a higher application prospect in the fields of stock exchange trade systems and the like.
According to the technical scheme, the method can configure the file format of the binary file as the target format to assist in file analysis when gray scale upgrading is executed, determine any binary file as the target file when an old version program is detected to receive any binary file, analyze the message header of the target file according to the target format to obtain the line data mode of the target file, determine the length of each line of data in the target file according to the line data mode so as to pointedly determine the length of each line of data according to different line data modes, determine the initial index of each line of data according to the length of each line of data, analyze the target file according to the initial index of each line of data by using the old version program, and further realize effective analysis of the newly defined binary file after gray scale upgrading by the old version program, the problems that the old version program cannot analyze the binary file and the analysis is wrong after the gray scale is upgraded are solved.
Fig. 2 is a functional block diagram of a binary file parsing apparatus based on gray scale upgrading according to a preferred embodiment of the present invention. The binary file parsing device 11 based on gray scale includes a configuration unit 110, a determination unit 111, and a parsing unit 112. A module/unit as referred to herein is a series of computer program segments stored in a memory that can be executed by a processor and that can perform a fixed function. In the present embodiment, the functions of the modules/units will be described in detail in the following embodiments.
The configuration unit 110 configures a file format of a binary file as a target format when performing a gray scale up.
The gray scale upgrading is a local upgrading mode, and adverse effects caused by upgraded program bug can be reduced to the greatest extent.
The traditional binary file does not support the gray scale upgrading, and when the program version is inconsistent with the file version, the situation of disordered analysis or program abnormity occurs.
Therefore, the present embodiment reconfigures the file format of the binary file, and uses the file as a new format of all the binary files after the gray scale upgrade.
Specifically, the configuring unit 110 configures a file format of the binary file as the target format, including:
configuring a first field for recording a message header size of the binary file;
configuring a second field for recording a line data mode of the binary file;
when the line data mode is a fixed line width mode, configuring a third field for recording the fixed line width of each line of data of the binary file, and adding the first field, the second field and the third field in a message header of the binary file; or
And when the line width mode is a non-fixed line width mode, adding the first field and the second field in a message header of the binary file, respectively configuring each fourth field for recording the line width of each line of data of the binary file, and correspondingly adding each fourth field at the initial position of a message body of each line of data of the binary file.
The fixed line width mode refers to that each line of data of the binary file has the same line width, that is, the length of each line of data is the same.
The non-fixed line width mode means that each line of data of the binary file does not have the same line width, that is, the length of each line of data is the same and also different.
In this embodiment, other fields may also be added to the message header of the binary file according to actual requirements. For example: a field representing a partition number (which may be adjusted according to actual traffic requirements) may be added, or a field representing a node name, or a field of signature information, etc. may be added.
Taking the line data mode as the fixed line width mode as an example, a fixed length (53 bytes) field is added as a message header, and then the first 53 bytes of the first message starting from the 54 th byte as the message header may respectively include the following fields:
[0,8) bytes (i.e., the first field): the first 8 bytes are used to define the header size, here 53;
[8,9) bytes (i.e., the second field): 1 byte is used to define a row data pattern;
[9,41) bytes: 32 bytes are used for defining signature information such as node names or file descriptions;
[41,49) bytes (i.e., the third field): 8 bytes are used to define the length of each line of data (from which old version programs can automatically calculate the starting index of the next line of messages);
[49,53) bytes: the last 4 bytes are used to define the total number of data lines of the binary file.
Taking the row data mode as the non-fixed row width mode as an example, the third field may be deleted from the message header in the above example, and a corresponding fourth field may be added at the beginning byte of each row of data in the message body. For example: the fourth field may be 4 bytes, representing the length of each row of data.
The length of each line of data in the binary file is determined by reconfiguring the file format of the binary file, so that the program of any new or old version can analyze the binary file according to the length of each line of data, and the problem of messy message bytes is avoided.
When detecting that the old version program receives an arbitrary binary file, the determination unit 111 determines the arbitrary binary file as a target file.
The arbitrary binary file may be a file redefined after the gray scale is upgraded, that is, a file with a newly added field at a suffix of each row of records. For such newly defined files, in the conventional parsing scheme, when the old version program parses the fields built in the program, the newly added field error is parsed into the starting byte of the next record, and actually, the newly added field is the last byte of the current record, which may result in a parsing error.
The arbitrary binary file may also be a file that is not redefined after the gray scale is upgraded, and at this time, the program of any new or old version may perform normal analysis on the arbitrary binary file.
The parsing unit 112 parses the message header of the target file according to the target format to obtain the line data pattern of the target file.
In this embodiment, the parsing unit 112 parses the message header of the target file according to the target format, and obtaining the line data pattern of the target file includes:
reading the second field from the message header of the target file according to the target format;
and determining the line data mode of the target file according to the data content of the second field.
Wherein the second field is defined in a header of the target file for representing a line data pattern of the target file.
Wherein the row data pattern may include, but is not limited to: fixed line width mode, non-fixed line width mode.
The determining unit 111 determines the length of each line of data in the target file according to the line data pattern.
In this embodiment, the determining unit 111 determines the length of each line of data in the target file according to the line data pattern, including:
when the line width mode is the fixed line width mode, reading the third field from the message header of the target file, and determining the length of each line of data in the target file according to the data content of the third field; or alternatively
And when the line data mode is the non-fixed line width mode, reading a fourth field of each line of data from the message body of the target file, and determining the length of each line of data in the target file according to the data content of the fourth field of each line of data.
That is, when the line data mode is the fixed line width mode, since each line of data has the same line width, the length of each line of data can be obtained by directly obtaining the data content of the corresponding field from the message header.
When the line data mode is the non-fixed line width mode, the length of each line of data may be different, so that the data content of the corresponding field of the message body of each line of data may be read to obtain the length of each line of data respectively.
The determining unit 111 determines a start index of each line of data according to the length of each line of data.
In this embodiment, the determining unit 111 determines the start index of each line of data according to the length of each line of data includes:
reading the first field from a message header of the target file;
determining the message header length of the target file according to the data content of the first field;
determining the initial position of the message body of the target file according to the length of the message header as the initial index of the first line data of the target file;
determining the length of the head line data according to the length of each line of data;
calculating the difference value between the length of the head line data and the length of the message header to obtain the length of the message body of the head line data;
determining the length of each line of data as the message body length of each line of data from the second line of data;
and splitting the message body according to the length of the message body of each line of data to obtain the initial index of each line of data.
For example: when the length of the message header is 50 bytes, starting from the 51 th byte of the first line data to be the initial index of the first line data of the target file, when the length of the first line data is determined to be 100 bytes, the length of the message body of the first line data is 100-50=50 bytes, at this time, the initial index of the second line data is 101 th byte, if the length of the second line data of the message body is determined to be 100, starting from the 101 st and 200 th bytes to be the message body of the second line data, the initial index of the third line data is 201 th byte, and so on, the initial index of each line of data is obtained.
The parsing unit 112 parses the target file according to the initial index of each line of data by using the old version program.
In this embodiment, the parsing unit 112 parsing the target file according to the start index of each line of data by using the old version program includes:
acquiring the length of an analyzable field of each line of data of the old version program;
for each line of data, when the analyzed field length of the old version program is detected to reach the corresponding analyzable field length, skipping the current line of data, and determining the next line of data of the current line of data according to the initial index of each line of data;
and continuing to analyze the target file from the next line of data.
It will be appreciated that the old version program will configure the parse-able field length for each row of data and parse the binary file according to the parse-able field length for each row of data.
For example: when the resolvable field length of each line of data of the old version program is 100 bytes, in the resolving process, if the current line of data has 200 bytes in total but the resolving field length of the current line of data reaches 100 bytes, the resolving of the current line of data is stopped, and the next line of data is directly jumped to continue resolving, so as to avoid invalid resolving, realize the compatibility of the old version program to the newly defined binary file, and avoid resolving errors.
Moreover, since fields which are not analyzed and skipped in each row of data are newly added fields, the fields cannot be processed by the old version program, so that even if the fields are not analyzed, the execution of the old version program is not affected, program errors are avoided, and the analysis efficiency is improved.
Moreover, the new version program has adaptability to the binary file newly defined after the gray scale is upgraded, so that the binary file format reconfigured by the embodiment can realize the up-down compatibility of the new version program and the old version program after the gray scale is upgraded, the flexibility and the adaptability of the gray scale upgrade are increased, and the new version program has a higher application prospect in the fields of stock exchange trade systems and the like.
It can be seen from the above technical solutions that, in performing gray scale upgrade, the present invention can configure a file format of a binary file as a target format to assist file parsing, when it is detected that an old version program receives any binary file, determine the any binary file as a target file, parse a message header of the target file according to the target format to obtain a line data pattern of the target file, determine a length of each line of data in the target file according to the line data pattern, so as to pointedly determine the length of each line of data according to different line data patterns, determine an initial index of each line of data according to the length of each line of data, parse the target file according to the initial index of each line of data by using the old version program, and further implement effective parsing of the new defined binary file after gray scale upgrade by the old version program, the problems that the old version program cannot analyze the binary file and the analysis is wrong after the gray scale is upgraded are solved.
Fig. 3 is a schematic structural diagram of a computer device according to a preferred embodiment of the present invention for implementing a binary file parsing method based on gray scale upgrading.
The computer device 1 may comprise a memory 12, a processor 13 and a bus, and may further comprise a computer program, such as a binary file parsing program based on grey scale upgrade, stored in the memory 12 and executable on the processor 13.
It will be appreciated by those skilled in the art that the schematic diagram is merely an example of the computer device 1, and does not constitute a limitation to the computer device 1, the computer device 1 may be in a bus structure or a star structure, the computer device 1 may include more or less hardware or software than those shown, or different component arrangements, for example, the computer device 1 may further include an input and output device, a network access device, and the like.
It should be noted that the computer device 1 is only an example, and other electronic products that are currently available or may come into existence in the future, such as electronic products that can be adapted to the present invention, should also be included in the scope of the present invention, and are included herein by reference.
The memory 12 includes at least one type of readable storage medium, including flash memory, removable hard disks, multimedia cards, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, magnetic disks, optical disks, and the like. The memory 12 may in some embodiments be an internal storage unit of the computer device 1, for example a removable hard disk of the computer device 1. The memory 12 may also be an external storage device of the computer device 1 in other embodiments, such as a plug-in removable hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), etc. provided on the computer device 1. Further, the memory 12 may also include both an internal storage unit and an external storage device of the computer device 1. The memory 12 may be used not only to store application software installed in the computer apparatus 1 and various types of data such as codes of a binary file parsing program based on gradation, etc., but also to temporarily store data that has been output or is to be output.
The processor 13 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same or different functions, including one or more Central Processing Units (CPUs), microprocessors, digital Processing chips, graphics processors, and combinations of various control chips. The processor 13 is a Control Unit (Control Unit) of the computer device 1, connects various components of the entire computer device 1 by using various interfaces and lines, and executes various functions and processes data of the computer device 1 by running or executing programs or modules (for example, executing a binary file parsing program based on gradation upgrade, and the like) stored in the memory 12 and calling data stored in the memory 12.
The processor 13 executes the operating system of the computer device 1 and various installed application programs. The processor 13 executes the application program to implement the steps in each embodiment of the binary file parsing method based on gray scale upgrading, such as the steps shown in fig. 1.
Illustratively, the computer program may be divided into one or more modules/units, which are stored in the memory 12 and executed by the processor 13 to accomplish the present invention. The one or more modules/units may be a series of computer readable instruction segments capable of performing certain functions, which are used to describe the execution of the computer program in the computer device 1. For example, the computer program may be divided into a configuration unit 110, a determination unit 111, a parsing unit 112.
The integrated unit implemented in the form of a software functional module may be stored in a computer-readable storage medium. The software functional module is stored in a storage medium and includes several instructions to enable a computer device (which may be a personal computer, a computer device, or a network device) or a processor (processor) to execute parts of the binary file parsing method based on gray scale upgrading according to the embodiments of the present invention.
The modules/units integrated by the computer device 1 may be stored in a computer-readable storage medium if they are implemented in the form of software functional units and sold or used as separate products. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented.
Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U-disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), random-access Memory, or the like.
Further, the computer-readable storage medium may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created according to the use of the blockchain node, and the like.
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a string of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, which is used for verifying the validity (anti-counterfeiting) of the information and generating a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
The bus may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one line is shown in FIG. 3, but this does not mean only one bus or one type of bus. The bus is arranged to enable connection communication between the memory 12 and at least one processor 13 or the like.
Although not shown, the computer device 1 may further include a power supply (such as a battery) for supplying power to each component, and preferably, the power supply may be logically connected to the at least one processor 13 through a power management device, so that functions of charge management, discharge management, power consumption management and the like are realized through the power management device. The power supply may also include any component of one or more dc or ac power sources, recharging devices, power failure detection circuitry, power converters or inverters, power status indicators, and the like. The computer device 1 may further include various sensors, a bluetooth module, a Wi-Fi module, and the like, which are not described herein again.
Further, the computer device 1 may further include a network interface, and optionally, the network interface may include a wired interface and/or a wireless interface (such as a WI-FI interface, a bluetooth interface, etc.), which are generally used for establishing a communication connection between the computer device 1 and other computer devices.
Optionally, the computer device 1 may further comprise a user interface, which may be a Display (Display), an input unit, such as a Keyboard (Keyboard), and optionally a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable, among other things, for displaying information processed in the computer device 1 and for displaying a visualized user interface.
It is to be understood that the embodiments described are illustrative only and are not to be construed as limiting the scope of the claims.
Fig. 3 shows only the computer device 1 with the components 12-13, and it will be understood by a person skilled in the art that the structure shown in fig. 3 does not constitute a limitation of the computer device 1, and may comprise fewer or more components than shown, or a combination of certain components, or a different arrangement of components.
Referring to fig. 1, the memory 12 in the computer device 1 stores a plurality of instructions to implement a binary file parsing method based on gray scale upgrading, and the processor 13 can execute the plurality of instructions to implement:
when gray scale upgrading is executed, configuring a file format of a binary file as a target format;
when detecting that an old version program receives any binary file, determining the any binary file as a target file;
analyzing the message header of the target file according to the target format to obtain a line data mode of the target file;
determining the length of each line of data in the target file according to the line data mode;
determining the initial index of each row of data according to the length of each row of data;
and analyzing the target file by using the old version program according to the initial index of each line of data.
Specifically, the specific implementation method of the instruction by the processor 13 may refer to the description of the relevant steps in the embodiment corresponding to fig. 1, which is not described herein again.
It should be noted that all the data involved in the present application are legally acquired.
In the embodiments provided in the present invention, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The invention is operational with numerous general purpose or special purpose computing system environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet-type devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like. The invention may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The invention may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the present invention may also be implemented by one unit or means through software or hardware. The terms first, second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions may be made on the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims (9)

1. A binary file analysis method based on gray scale upgrading is characterized by comprising the following steps:
when gray scale upgrading is executed, the file format of the binary file is configured as a target format, and the method comprises the following steps: configuring a first field for recording a message header size of the binary file;
when detecting that an old version program receives any binary file, determining the any binary file as a target file;
analyzing the message header of the target file according to the target format to obtain a line data mode of the target file;
determining the length of each line of data in the target file according to the line data mode;
determining a starting index of each line of data according to the length of each line of data, comprising: reading the first field from a message header of the target file; determining the message header length of the target file according to the data content of the first field; determining the initial position of the message body of the target file according to the length of the message header as the initial index of the first line data of the target file; determining the length of the head line data according to the length of each line of data; calculating the difference value between the length of the head line data and the length of the message header to obtain the length of the message body of the head line data; determining the length of each line of data as the message body length of each line of data from the second line of data; splitting the message body according to the length of the message body of each line of data to obtain an initial index of each line of data;
and analyzing the target file by utilizing the old version program according to the initial index of each line of data.
2. The method of claim 1, wherein configuring the file format of the binary file as the target format comprises:
configuring a second field for recording a row data pattern of the binary file;
when the line data mode is a fixed line width mode, configuring a third field for recording the fixed line width of each line of data of the binary file, and adding the first field, the second field and the third field in a message header of the binary file; or alternatively
And when the line width mode is a non-fixed line width mode, adding the first field and the second field in a message header of the binary file, respectively configuring each fourth field for recording the line width of each line of data of the binary file, and correspondingly adding each fourth field at the initial position of a message body of each line of data of the binary file.
3. The method for parsing binary file based on gray scale upgrading of claim 2, wherein the parsing the message header of the object file according to the object format to obtain the line data pattern of the object file comprises:
reading the second field from the message header of the target file according to the target format;
and determining the line data mode of the target file according to the data content of the second field.
4. The method of claim 2, wherein the determining the length of each line of data in the target file according to the line data pattern comprises:
when the line width mode is the fixed line width mode, reading the third field from the message header of the target file, and determining the length of each line of data in the target file according to the data content of the third field; or alternatively
And when the line data mode is the non-fixed line width mode, reading a fourth field of each line of data from a message body of the target file, and determining the length of each line of data in the target file according to the data content of the fourth field of each line of data.
5. The method of claim 2, wherein the parsing the target file according to the start index of each line of data by the old version program comprises:
acquiring the length of a resolvable field of each row of data of the old version program;
for each line of data, when detecting that the length of the field analyzed by the old version program reaches the length of the corresponding analyzable field, skipping the current line of data, and determining the next line of data of the current line of data according to the initial index of each line of data;
and continuing to analyze the target file from the next line of data.
6. A binary file parsing apparatus based on gray scale upgrading, comprising:
a configuration unit configured to configure a file format of a binary file as a target format when performing a gray scale upgrade, including: configuring a first field for recording a message header size of the binary file;
the system comprises a determining unit, a judging unit and a processing unit, wherein the determining unit is used for determining any binary file as a target file when detecting that the old version program receives the any binary file;
the analysis unit is used for analyzing the message header of the target file according to the target format to obtain a line data mode of the target file;
the determining unit is further configured to determine the length of each line of data in the target file according to the line data pattern;
the determining unit is further configured to determine a start index of each line of data according to the length of each line of data, and includes: reading the first field from a message header of the target file; determining the message header length of the target file according to the data content of the first field; determining the initial position of the message body of the target file according to the length of the message header as the initial index of the first line data of the target file; determining the length of the head line data according to the length of each line of data; calculating the difference value between the length of the head line data and the length of the message header to obtain the length of the message body of the head line data; determining the length of each line of data as the message body length of each line of data from the second line of data; splitting the message body according to the length of the message body of each line of data to obtain an initial index of each line of data;
and the analysis unit is also used for analyzing the target file by utilizing the old version program according to the initial index of each line of data.
7. The binary file parsing device according to claim 6, wherein the configuration unit is specifically configured to:
configuring a second field for recording a row data pattern of the binary file;
when the line data mode is a fixed line width mode, configuring a third field for recording the fixed line width of each line of data of the binary file, and adding the first field, the second field and the third field in a message header of the binary file; or
And when the line width mode is a non-fixed line width mode, adding the first field and the second field in a message header of the binary file, respectively configuring each fourth field for recording the line width of each line of data of the binary file, and correspondingly adding each fourth field at the initial position of a message body of each line of data of the binary file.
8. A computer device, characterized in that the computer device comprises:
a memory storing at least one instruction; and
a processor executing instructions stored in the memory to implement the method of binary file parsing based on grey scale as claimed in any one of claims 1 to 5.
9. A computer-readable storage medium characterized by: the computer-readable storage medium has stored therein at least one instruction that is executed by a processor in a computer device to implement the method for binary file parsing based on gray scale as recited in any one of claims 1 to 5.
CN202210756625.5A 2022-06-30 2022-06-30 Binary file analysis method, device, equipment and medium based on gray scale upgrading Active CN114818656B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210756625.5A CN114818656B (en) 2022-06-30 2022-06-30 Binary file analysis method, device, equipment and medium based on gray scale upgrading

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210756625.5A CN114818656B (en) 2022-06-30 2022-06-30 Binary file analysis method, device, equipment and medium based on gray scale upgrading

Publications (2)

Publication Number Publication Date
CN114818656A CN114818656A (en) 2022-07-29
CN114818656B true CN114818656B (en) 2022-09-23

Family

ID=82522810

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210756625.5A Active CN114818656B (en) 2022-06-30 2022-06-30 Binary file analysis method, device, equipment and medium based on gray scale upgrading

Country Status (1)

Country Link
CN (1) CN114818656B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110457526A (en) * 2019-07-31 2019-11-15 南京理工大学 Unitized data analytic method based on xml document
CN112559482A (en) * 2020-12-17 2021-03-26 中国电子科技集团公司第五十二研究所 Binary data classification processing method and system based on distribution
CN112711432A (en) * 2020-12-31 2021-04-27 北京安博通科技股份有限公司 Feature library upgrading method and device for network security equipment
CN114138325A (en) * 2021-11-24 2022-03-04 聚好看科技股份有限公司 Gray scale publishing method and device

Family Cites Families (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102413141B (en) * 2011-11-30 2014-10-08 华为技术有限公司 Network message parsing method and communication equipment
CN103888281B (en) * 2012-12-21 2018-05-18 腾讯科技(北京)有限公司 Server gray scale upgrade method, device and corresponding gray scale upgrade server
CN105487884B (en) * 2015-10-20 2019-02-01 华为技术有限公司 Upgrade processing method and relevant device
US10324706B1 (en) * 2017-05-09 2019-06-18 Amazon Technologies, Inc. Automated software deployment for electromechanical systems
CN110377563A (en) * 2019-07-23 2019-10-25 中国工商银行股份有限公司 Document handling method and device and electronic equipment and readable storage medium storing program for executing
CN110795393A (en) * 2019-10-31 2020-02-14 中孚安全技术有限公司 Method, system, equipment and readable storage medium for analyzing binary format of document
CN112433709A (en) * 2020-12-03 2021-03-02 深圳前海微众银行股份有限公司 JSON-based data processing method, device, equipment and medium
CN112565267B (en) * 2020-12-07 2023-05-02 贵阳语玩科技有限公司 Forward compatible element increment change data transmission method and system
CN112395251A (en) * 2020-12-21 2021-02-23 深圳赛安特技术服务有限公司 Intelligent analysis method and device for data file, electronic equipment and storage medium
CN112559013A (en) * 2020-12-24 2021-03-26 厦门亿联网络技术股份有限公司 Video conference service system and gray scale upgrading method and device thereof
CN113326052A (en) * 2021-05-11 2021-08-31 华锐分布式(北京)技术有限公司 Method and device for upgrading service component, computer equipment and storage medium
CN113934443A (en) * 2021-10-11 2022-01-14 西安万像电子科技有限公司 Software upgrading system
CN113742298B (en) * 2021-11-04 2022-03-08 南京芯传汇电子科技有限公司 Airborne binary file general parallel analysis method and device and electronic equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110457526A (en) * 2019-07-31 2019-11-15 南京理工大学 Unitized data analytic method based on xml document
CN112559482A (en) * 2020-12-17 2021-03-26 中国电子科技集团公司第五十二研究所 Binary data classification processing method and system based on distribution
CN112711432A (en) * 2020-12-31 2021-04-27 北京安博通科技股份有限公司 Feature library upgrading method and device for network security equipment
CN114138325A (en) * 2021-11-24 2022-03-04 聚好看科技股份有限公司 Gray scale publishing method and device

Also Published As

Publication number Publication date
CN114818656A (en) 2022-07-29

Similar Documents

Publication Publication Date Title
CN115048111B (en) Code generation method, device, equipment and medium based on metadata
CN113468049A (en) Test method, device, equipment and medium based on configurable interface
CN113806434A (en) Big data processing method, device, equipment and medium
CN114185776A (en) Big data point burying method, device, equipment and medium for application program
CN114491646A (en) Data desensitization method and device, electronic equipment and storage medium
CN112214256B (en) Machine learning operation control method and device, electronic equipment and storage medium
CN114816371B (en) Message processing method, device, equipment and medium
CN115314570B (en) Data issuing method, device, equipment and medium based on protocol development framework
CN114818656B (en) Binary file analysis method, device, equipment and medium based on gray scale upgrading
CN115174541A (en) H5 resource loading method and device, electronic equipment and storage medium
CN115033489A (en) Code resource detection method and device, electronic equipment and storage medium
CN114385497A (en) Test environment generation method and device, electronic equipment and storage medium
CN114398282A (en) Test script generation method, device, equipment and storage medium
CN114185522A (en) Page theme customizing method and device, electronic equipment and storage medium
CN112905470A (en) Interface calling method and device, computer equipment and medium
CN115964307B (en) Automatic test method, device, equipment and medium for transaction data
CN113672483B (en) Device log storage method and device, electronic device and medium
CN115328583A (en) Log printing method, device, equipment and medium based on preset C + + log library
CN114860314B (en) Deployment upgrading method, device, equipment and medium based on database compatibility
CN116225971B (en) Transaction interface compatibility detection method, device, equipment and medium
CN114860349B (en) Data loading method, device, equipment and medium
CN115202697A (en) FPGA (field programmable Gate array) upgrading method, device, equipment and medium
CN115357272A (en) Front-end public component publishing method, device, equipment and medium
CN114968415A (en) Configuration file modification method, device, equipment and storage medium
CN115934576A (en) Test case generation method, device, equipment and medium in transaction scene

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant