XML-based protocol dynamic packaging and analyzing method

文档序号:486952 发布日期:2022-01-04 浏览:6次 中文

阅读说明:本技术 一种基于xml的协议动态组包和解析方法 (XML-based protocol dynamic packaging and analyzing method ) 是由 何舒 辜彬 葛泽文 江红 于 2021-10-20 设计创作,主要内容包括:本发明提供一种基于XML的协议动态组包和解析方法,包括:在协议模板的XML文件中定义关键字来表示协议动态组包和解析的交互流程;再通过解析协议模板的XML文件中的关键字来模拟协议动态组包和解析。本发明的有益效果是:1、对于各种自定义协议,只要在协议模板的XML文件中通过关键字对协议格式及业务动作进行定义,即可通过解析XML的关键字实现协议流程交互,即协议动态组包和解析;2、关键字和运算调用的基础函数和业务函数等可根据业务需要进行扩展,兼容性和可扩展性好;3、使用本发明进行实时动态组包和解析,被测设备无需做出任何改动。(The invention provides a protocol dynamic packaging and analyzing method based on XML, which comprises the following steps: defining keywords in an XML file of a protocol template to represent an interactive flow of protocol dynamic packaging and analysis; and simulating the dynamic package and analysis of the protocol by analyzing the keywords in the XML file of the protocol template. The invention has the beneficial effects that: 1. for various self-defined protocols, as long as the protocol format and the service action are defined in the XML file of the protocol template through keywords, the protocol flow interaction, namely the protocol dynamic packaging and analysis, can be realized by analyzing the keywords of the XML; 2. keywords, basic functions called by operation, service functions and the like can be expanded according to service requirements, and compatibility and expandability are good; 3. the invention is used for real-time dynamic packaging and analysis, and the tested equipment does not need to be changed.)

1. A dynamic protocol packaging and parsing method based on XML is characterized by comprising the following steps:

defining keywords in an XML file of a protocol template to represent an interactive flow of protocol dynamic packaging and analysis;

and simulating the dynamic package and analysis of the protocol by analyzing the keywords in the XML file of the protocol template.

2. An XML-based protocol dynamic packaging and parsing method according to claim 1, wherein the method for emulating protocol dynamic packaging by parsing keywords in an XML file of a protocol template comprises the steps of:

(1) according to the transmitted protocol template name and the data packet name, finding out a node with the same name as the transmitted data packet name from the loaded protocol template data in the memory by matching a < Package > tag;

(2) sequentially circularly analyzing the child nodes of the data packet node < Package >, carrying out different operation steps according to different defined keywords, and outputting the packaging results of the child nodes;

(3) and after the processing of all the sub-nodes under the node < Package > of the data packet is finished, splicing the packaging results of each sub-node according to the packaging mode defined by the protocol template to obtain the packaging results of the data packet.

3. The dynamic packing and parsing method of XML-based protocol according to claim 2, wherein in the dynamic packing method of protocol, the child nodes of the data packet node < Package > are sequentially parsed in a loop, different operation steps are performed according to different defined keywords, and the method for outputting the packing result of the child nodes includes the following sub-steps:

(2.1) if the node name of the child node of the data packet node < Package > is Field < Field >, entering a Field processing flow: according to field attributes defined in the protocol template, adopting different data generation modes to obtain corresponding package results;

(2.2) if the node name of the child node of the packet node < Package > is the preparation area < PreArea >, entering a preparation area processing flow: reading data defined by all child nodes of the preparation area < PreArea > into an intermediate variable list in sequence for subsequent use;

(2.3) if the node name of the child node of the packet node < Package > is the private area < PriArea >, entering a private area processing flow: processing all child nodes of the private area < PriArea > in sequence, wherein the child nodes of the private area < PriArea > are single fields needing to be operated to obtain results, the operation results are stored in an intermediate variable list and only used for intermediate data operation, and the packaged results are not included;

(2.4) if the node name of the child node of the data packet node < Package > is the identification area < FlagArea >, entering an identification area processing flow: sequentially processing all sub-nodes of the identification area < FlagArea >, writing the obtained sub-node data into a temporary list, sequentially splicing the sub-node data in the temporary list according to a specified data splicing mode after all the sub-nodes of the identification area < FlagArea > are processed, obtaining a packaged character string, and storing the packaged character string into a packaged result;

(2.5) if the node name of the child node of the data packet node < Package > is the protection area < ProArea >, entering a protection area processing flow: processing all sub-nodes of a protection area (ProArea) in sequence, writing the obtained sub-node data into a temporary list, splicing the sub-node data in the temporary list in sequence according to a specified data splicing mode after all the sub-nodes of the protection area (ProArea) are processed to obtain a group string, operating the group string according to the protection area operation definition of a protocol template after all the sub-nodes are processed in sequence to obtain the group string, and taking the operation result as the final group package result;

(2.6) if the node name of the child node of the data packet node < Package > is the circulation area < CycArea >, entering a circulation area processing flow: the loop region processing flow comprises a nested loop, the outer loop times are determined according to the loop times defined by a protocol template, the inner loop times are determined according to the number of sub-nodes in the loop region, the results of the sub-nodes are sequentially calculated in the inner loop, and the result of each sub-node can calculate a fixed result according to the protocol template definition; and when the two layers of circulation processing are finished, the fixed results of all the child nodes are spliced to obtain a group packaging result of the circulation area.

4. The dynamic XML-based protocol packaging and parsing method as claimed in claim 3, wherein when the node name of the packet node < Package > is the identification area < FlagArea >, if the identification area < FlagArea > participates in the operation at other places, the packaged result of the identification area < FlagArea > is written into the intermediate variable list through the reference attribute defined by the protocol template, and the packaged result of the identification area < FlagArea > stored in the intermediate variable list can be referred to subsequently, so that a plurality of continuous data of the identification area < FlagArea > are referred to as a whole.

5. The XML-based protocol dynamic packaging and parsing method of claim 3, wherein when the node name of the packet node < Package > is the loop region < CycArea >, the inside and outside loop times are added as the file name suffixes of the result of the child node according to the protocol template definition to ensure the uniqueness of the data; and dynamically reading external file data with continuous file names as a packaging result according to the definition of the protocol template.

6. An XML-based protocol dynamic packaging and parsing method according to claim 1, wherein the method for simulating protocol dynamic parsing by parsing keywords in an XML file of a protocol template comprises the steps of:

(1) according to the transmitted protocol template name and the data packet name, finding out a node with the same name as the transmitted data packet name from the loaded protocol template data in the memory by matching a < Package > tag;

(2) sequentially and circularly traversing child nodes of the data packet node < Package >, and preprocessing the protocol template;

(3) after the protocol preprocessing is finished, sequentially analyzing the sub-nodes of the data packet node < Package >, performing different operation steps according to different keywords, outputting the analysis results of the sub-nodes, and recording the analysis results into an analysis result list;

(4) and after all child nodes under the data packet node < Package > are processed, sequentially outputting the analysis results in the analysis result list to a result file for a user to check.

7. The dynamic XML-based protocol packaging and parsing method of claim 6, wherein the method for preprocessing the protocol templates comprises the steps of:

(2.1) if the node name of the child node of the data packet node < Package > is the referred area < RefArea >, entering the referred area processing flow: the referenced area processing flow writes the whole referenced area into a referenced data intermediate variable list for direct reference of a calling area < CallArea >;

(2.2) if the node name of the child node of the data packet node < Package > is calling area < CallArea >, entering a calling area processing flow: the calling area processing flow acquires the name of the quoted area according to the node value of the calling area < CallArea >, acquires the prefix information of the child node id from the id attribute of the calling area < CallArea >, and then updates the id of all the child nodes of the quoted area and the prefix information and replaces the calling area content of the protocol template.

8. The dynamic Package and parsing method for XML-based protocol according to claim 1, wherein in the dynamic parsing method for protocol, the child nodes of the data packet node < Package > are sequentially parsed in a loop, different operation steps are performed according to different keywords, and the method for outputting the parsing result of the child nodes includes the following sub-steps:

(3.1) if the node name of the child node of the data packet node < Package > is Field < Field >, entering a Field processing flow: acquiring a field actual value according to the field length and the calculated field offset, or acquiring the field actual value according to a field separator; if the field expected value is defined, acquiring the field expected value according to a field operation mode of the expected value; then comparing the actual field value with the expected field value, if the actual field value is consistent with the expected field value, continuing the process, and if the actual field value is inconsistent with the expected field value, outputting error information and terminating the analysis process;

(3.2) if the node name of the child node of the packet node < Package > is the preparation area < PreArea >, entering a preparation area processing flow: reading data defined by all child nodes of a preparation area < PreArea > into an intermediate variable list in sequence for subsequent use;

(3.3) if the node name of the child node of the packet node < Package > is the private area < PriArea >, entering a private area processing flow: processing all child nodes of the private area < PriArea > in sequence, wherein the child nodes of the private area < PriArea > are single fields needing to be operated to obtain results, the operation results are stored in an intermediate variable list and only used for intermediate data operation, and the packaged results are not included;

(3.4) if the node name of the child node of the data packet node < Package > is the identification area < FlagArea >, entering an identification area processing flow: firstly, acquiring data of the identification area < FlagArea > according to the definition of a protocol template, then sequentially processing all sub-nodes of the identification area < FlagArea >, writing the obtained sub-node data into a temporary list, and outputting an analysis character string to an XML file of a result file according to the sequence of the sub-node data in the temporary list after all the sub-nodes of the identification area < FlagArea > are processed, so that a user can conveniently check the analysis character string;

(3.5) if the node name of the child node of the data packet node < Package > is the protection area < ProArea >, entering a protection area processing flow: firstly, acquiring data before analysis of a protection area according to the data length of the protection area, then taking the data before analysis of the protection area as an input parameter of an operation function according to operation information defined in an operation information child node < CalcInfo > of the protection area, and obtaining the data after the protection is removed after operation; then, sequentially analyzing the data after the protection is removed according to the specific field definition of the protection area to obtain the final analysis result of the data of the protection area;

(3.6) if the node name of the child node of the data packet node < Package > is the circulation area < CycArea >, entering a circulation area processing flow: firstly, dynamically generating a protocol template of the cycle in real time according to the cycle times defined by the protocol template, then acquiring data of a cycle area < CycArea >, sequentially analyzing each sub-node of the cycle area < CycArea > according to the dynamically generated protocol template of the cycle in real time, and outputting an analysis result;

(3.7) if the node name of the child node of the data packet node < Package > is the child template area < SubArea >, entering a child template area processing flow: the sub-template area processing flow matches a corresponding sub-template from a loaded protocol template file in a memory in real time according to the name of the sub-template defined by the protocol template, and then adds the matched sub-template into a sub-template temporary list for subsequent direct reference;

(3.8) if the node name of the child node of the packet node < Package > is the selected area < SelArea >, entering a selected area processing flow: the method comprises the steps of defining selection conditions in a protocol template and names of sub-templates needing to be jumped under the selection conditions, achieving branch judgment and processing of a protocol processing flow, and directly matching corresponding sub-templates from a sub-template temporary list for analysis if the selection conditions are met.

9. The dynamic XML-based protocol packaging and parsing method according to claim 8, wherein there are two types of data in the entire identification area < FlagArea > and the child node in the identification area < FlagArea >:

one is to obtain data according to the data length of the identification area < FlagArea > and the calculated data offset of the identification area < FlagArea >, and the type is suitable for the condition that the data is directly spliced by numerical values;

and the other is to acquire data according to the delimiters defined by the protocol template, and the type is suitable for the condition that the splicing mode of the data is a format.

10. The XML-based protocol dynamic packaging and parsing method of claim 8, wherein the selection condition has two defining ways:

if one is the child node which is analyzed before, the condition is selected to be designated as the node name;

and the other is a child node which is not analyzed, and data is acquired according to the data length and the relative offset of the child node.

Technical Field

The invention relates to the technical field of protocol analysis, in particular to a protocol dynamic packaging and analyzing method based on XML.

Background

At present, there are mature testing methods and testing tools for various general protocols. However, if the protocol format is customized, there are few existing testing methods for testing the protocol. For a custom protocol, the correctness of the data format of the protocol is generally verified by adopting a static analysis mode, but an abnormal use case of protocol interaction is difficult to construct. If the simulation package is performed on the tested protocol, the test tool is generally customized, and the protocol flow is implemented again. The method has no universality and low input-output. How to dynamically package according to real-time data in a protocol interaction process, simulate real protocol data to the maximum extent, reduce the change of tested equipment and become an important problem to be solved for successfully carrying out protocol dynamic testing.

Disclosure of Invention

The invention aims to provide a protocol dynamic packaging and analyzing method based on XML (extensive makeup language) to solve the problems of how to dynamically package real-time data in a protocol interaction process, simulating real protocol data to the maximum extent and reducing the change of equipment to be tested.

The invention provides a protocol dynamic packaging and analyzing method based on XML, which comprises the following steps:

defining keywords in an XML file of a protocol template to represent an interactive flow of protocol dynamic packaging and analysis;

and simulating the dynamic package and analysis of the protocol by analyzing the keywords in the XML file of the protocol template.

Further, the method for simulating the protocol dynamic package by analyzing the keywords in the XML file of the protocol template comprises the following steps:

(1) according to the transmitted protocol template name and the data packet name, finding out a node with the same name as the transmitted data packet name from the loaded protocol template data in the memory by matching a < Package > tag;

(2) sequentially circularly analyzing the child nodes of the data packet node < Package >, carrying out different operation steps according to different defined keywords, and outputting the packaging results of the child nodes;

(3) and after the processing of all the sub-nodes under the node < Package > of the data packet is finished, splicing the packaging results of each sub-node according to the packaging mode defined by the protocol template to obtain the packaging results of the data packet.

Further, in the method for dynamically packaging the protocol, the child nodes of the data packet node < Package > are sequentially analyzed in a circulating manner, different operation steps are performed according to different defined keywords, and the method for outputting the packaging result of the child nodes comprises the following substeps:

(2.1) if the node name of the child node of the data packet node < Package > is Field < Field >, entering a Field processing flow: according to field attributes defined in the protocol template, adopting different data generation modes to obtain corresponding package results;

(2.2) if the node name of the child node of the packet node < Package > is the preparation area < PreArea >, entering a preparation area processing flow: reading data defined by all child nodes of the preparation area < PreArea > into an intermediate variable list in sequence for subsequent use;

(2.3) if the node name of the child node of the packet node < Package > is the private area < PriArea >, entering a private area processing flow: processing all child nodes of the private area < PriArea > in sequence, wherein the child nodes of the private area < PriArea > are single fields needing to be operated to obtain results, the operation results are stored in an intermediate variable list and only used for intermediate data operation, and the packaged results are not included;

(2.4) if the node name of the child node of the data packet node < Package > is the identification area < FlagArea >, entering an identification area processing flow: sequentially processing all sub-nodes of the identification area < FlagArea >, writing the obtained sub-node data into a temporary list, sequentially splicing the sub-node data in the temporary list according to a specified data splicing mode after all the sub-nodes of the identification area < FlagArea > are processed, obtaining a packaged character string, and storing the packaged character string into a packaged result;

(2.5) if the node name of the child node of the data packet node < Package > is the protection area < ProArea >, entering a protection area processing flow: processing all sub-nodes of a protection area (ProArea) in sequence, writing the obtained sub-node data into a temporary list, splicing the sub-node data in the temporary list in sequence according to a specified data splicing mode after all the sub-nodes of the protection area (ProArea) are processed to obtain a group string, operating the group string according to the protection area operation definition of a protocol template after all the sub-nodes are processed in sequence to obtain the group string, and taking the operation result as the final group package result;

(2.6) if the node name of the child node of the data packet node < Package > is the circulation area < CycArea >, entering a circulation area processing flow: the loop region processing flow comprises a nested loop, the outer loop times are determined according to the loop times defined by a protocol template, the inner loop times are determined according to the number of sub-nodes in the loop region, the results of the sub-nodes are sequentially calculated in the inner loop, and the result of each sub-node can calculate a fixed result according to the protocol template definition; and when the two layers of circulation processing are finished, the fixed results of all the child nodes are spliced to obtain a group packaging result of the circulation area.

Further, when the node name of the packet node < Package > is the identification area < FlagArea >, if the identification area < FlagArea > participates in operation at other places in the following, the Package result of the identification area < FlagArea > is written into the intermediate variable list through the reference attribute defined by the protocol template, and the Package result of the identification area < FlagArea > stored in the intermediate variable list can be referred in the following, so that a plurality of continuous data of the identification area < FlagArea > are referred as a whole.

Furthermore, when the node name of the data packet node < Package > is a cyclic region < CycArea >, according to the definition of a protocol template, adding internal and external cyclic times as a file name suffix of a result of a child node to ensure the uniqueness of data; and dynamically reading external file data with continuous file names as a packaging result according to the definition of the protocol template.

Further, the method for simulating the dynamic analysis of the protocol by analyzing the keywords in the XML file of the protocol template comprises the following steps:

(1) according to the transmitted protocol template name and the data packet name, finding out a node with the same name as the transmitted data packet name from the loaded protocol template data in the memory by matching a < Package > tag;

(2) sequentially and circularly traversing child nodes of the data packet node < Package >, and preprocessing the protocol template;

(3) after the protocol preprocessing is finished, sequentially analyzing the sub-nodes of the data packet node < Package >, performing different operation steps according to different keywords, outputting the analysis results of the sub-nodes, and recording the analysis results into an analysis result list;

(4) and after all child nodes under the data packet node < Package > are processed, sequentially outputting the analysis results in the analysis result list to a result file for a user to check.

Further, the method for preprocessing the protocol template comprises the following steps:

(2.1) if the node name of the child node of the data packet node < Package > is the referred area < RefArea >, entering the referred area processing flow: the referenced area processing flow writes the whole referenced area into a referenced data intermediate variable list for direct reference of a calling area < CallArea >;

(2.2) if the node name of the child node of the data packet node < Package > is calling area < CallArea >, entering a calling area processing flow: the calling area processing flow acquires the name of the quoted area according to the node value of the calling area < CallArea >, acquires the prefix information of the child node id from the id attribute of the calling area < CallArea >, and then updates the id of all the child nodes of the quoted area and the prefix information and replaces the calling area content of the protocol template.

Further, in the protocol dynamic analysis method, the child nodes of the data packet node < Package > are circularly analyzed in sequence, different operation steps are performed according to different keywords, and the method for outputting the analysis result of the child nodes comprises the following substeps:

(3.1) if the node name of the child node of the data packet node < Package > is Field < Field >, entering a Field processing flow: acquiring a field actual value according to the field length and the calculated field offset, or acquiring the field actual value according to a field separator; if the field expected value is defined, acquiring the field expected value according to a field operation mode of the expected value; then comparing the actual field value with the expected field value, if the actual field value is consistent with the expected field value, continuing the process, and if the actual field value is inconsistent with the expected field value, outputting error information and terminating the analysis process;

(3.2) if the node name of the child node of the packet node < Package > is the preparation area < PreArea >, entering a preparation area processing flow: reading data defined by all child nodes of a preparation area < PreArea > into an intermediate variable list in sequence for subsequent use;

(3.3) if the node name of the child node of the packet node < Package > is the private area < PriArea >, entering a private area processing flow: processing all child nodes of the private area < PriArea > in sequence, wherein the child nodes of the private area < PriArea > are single fields needing to be operated to obtain results, the operation results are stored in an intermediate variable list and only used for intermediate data operation, and the packaged results are not included;

(3.4) if the node name of the child node of the data packet node < Package > is the identification area < FlagArea >, entering an identification area processing flow: firstly, acquiring data of the identification area < FlagArea > according to the definition of a protocol template, then sequentially processing all sub-nodes of the identification area < FlagArea >, writing the obtained sub-node data into a temporary list, and outputting an analysis character string to an XML file of a result file according to the sequence of the sub-node data in the temporary list after all the sub-nodes of the identification area < FlagArea > are processed, so that a user can conveniently check the analysis character string;

(3.5) if the node name of the child node of the data packet node < Package > is the protection area < ProArea >, entering a protection area processing flow: firstly, acquiring data before analysis of a protection area according to the data length of the protection area, then taking the data before analysis of the protection area as an input parameter of an operation function according to operation information defined in an operation information child node < CalcInfo > of the protection area, and obtaining the data after the protection is removed after operation; then, sequentially analyzing the data after the protection is removed according to the specific field definition of the protection area to obtain the final analysis result of the data of the protection area;

(3.6) if the node name of the child node of the data packet node < Package > is the circulation area < CycArea >, entering a circulation area processing flow: firstly, dynamically generating a protocol template of the cycle in real time according to the cycle times defined by the protocol template, then acquiring data of a cycle area < CycArea >, sequentially analyzing each sub-node of the cycle area < CycArea > according to the dynamically generated protocol template of the cycle in real time, and outputting an analysis result;

(3.7) if the node name of the child node of the data packet node < Package > is the child template area < SubArea >, entering a child template area processing flow: the sub-template area processing flow matches a corresponding sub-template from a loaded protocol template file in a memory in real time according to the name of the sub-template defined by the protocol template, and then adds the matched sub-template into a sub-template temporary list for subsequent direct reference;

(3.8) if the node name of the child node of the packet node < Package > is the selected area < SelArea >, entering a selected area processing flow: the method comprises the steps of defining selection conditions in a protocol template and names of sub-templates needing to be jumped under the selection conditions, achieving branch judgment and processing of a protocol processing flow, and directly matching corresponding sub-templates from a sub-template temporary list for analysis if the selection conditions are met.

Further, the data of the entire identification area < FlagArea > and the acquisition modes of the child nodes in the identification area < FlagArea > are totally two:

one is to obtain data according to the data length of the identification area < FlagArea > and the calculated data offset of the identification area < FlagArea >, and the type is suitable for the condition that the data is directly spliced by numerical values;

and the other is to acquire data according to the delimiters defined by the protocol template, and the type is suitable for the condition that the splicing mode of the data is a format.

Further, there are two defining ways for the selection condition:

if one is the child node which is analyzed before, the condition is selected to be designated as the node name;

and the other is a child node which is not analyzed, and data is acquired according to the data length and the relative offset of the child node.

In summary, due to the adoption of the technical scheme, the invention has the beneficial effects that:

1. for various self-defined protocols, as long as the protocol format and the service action are defined in the XML file of the protocol template through keywords, the protocol flow interaction, namely the protocol dynamic packaging and analysis, can be realized by analyzing the keywords of the XML;

2. keywords, basic functions called by operation, service functions and the like can be expanded according to service requirements, and compatibility and expandability are good;

3. the traditional method for simulating the transmitting and receiving packets to carry out protocol test needs some changes of the tested equipment such as: and (4) inserting piles to output data, shielding certain identity authentication operation, closing an anti-replay function and the like. The invention is used for real-time dynamic packaging and analysis, and the tested equipment does not need to be changed.

Drawings

In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention, and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.

Fig. 1 is a flowchart of a dynamic package and parsing method for XML-based protocols according to an embodiment of the present invention.

Fig. 2 is a flowchart of simulating dynamic grouping of protocols according to an embodiment of the present invention.

Fig. 3 is a flowchart of a field processing flow of an emulation protocol dynamic group package according to an embodiment of the present invention.

Fig. 4 is a flowchart of simulation protocol dynamic parsing according to an embodiment of the present invention.

Detailed Description

In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.

Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.

Examples

As shown in fig. 1, the present embodiment provides a method for dynamically packaging and parsing a protocol based on XML, which includes:

defining keywords in an XML file of a protocol template to represent an interactive flow of protocol dynamic packaging and analysis;

and simulating the dynamic package and analysis of the protocol by analyzing the keywords in the XML file of the protocol template.

Specifically, the method comprises the following steps:

as shown in fig. 2, the method for simulating the protocol dynamic package by parsing the keywords in the XML file of the protocol template includes the following steps:

(1) and according to the transmitted protocol template name and the data packet name, finding out the node with the same name as the transmitted data packet name from the loaded protocol template data in the memory by matching the < Package > tag.

(2) Sequentially and circularly analyzing the child nodes of the data packet node < Package >, carrying out different operation steps according to different defined keywords, and outputting the packaging results of the child nodes:

(2.1) if the node name of the child node of the data packet node < Package > is Field < Field >, entering a Field processing flow: and obtaining a corresponding package result by adopting different data generation modes according to the field attribute defined in the protocol template. As shown in fig. 3, wherein:

(2.1.1) if the data generation mode is 'numerical value', reading the value of the XML node of the field as the data result, and before outputting the data result, performing necessary data filling and data type conversion according to the defined data type and data length. If the data result is defined in the protocol template to be referenced subsequently, the data result is written into the intermediate variable list in the form of key-value, so that the data result can be acquired from the intermediate variable list subsequently.

(2.1.2) if the data generation mode is 'file', acquiring a file name from the value of the XML node of the field, reading the file with the specified file name from the data file path specified in the configuration file, and using the file content as a packaging result. If the file defines the incremental suffix attribute, suffixes can be dynamically added after fixed file names, so that the requirement of reading a plurality of files circularly in sequence is met.

(2.1.3) if the data generation method is "operation", the operation related information (mainly the external function name and the definition of the input/output parameter) is acquired according to the definition of the operation child node < CalcInfo >, the operation is performed, the value of the output parameter or the function return value is used as the package result, and the two methods are specified by the output data attribute of the operation child node.

(2.1.4) if the data generation mode is 'reference data', acquiring the name of the referenced field from the value of the XML node of the field, matching the field with the same name in the intermediate variable list, and taking the field value as a packaging result;

(2.1.5) if the data generation mode is 'reference length', acquiring the name of the referenced field from the value of the XML node of the field, then matching the field with the same name in the intermediate variable list, and taking the field length as a packaging result;

(2.1.6) if the data generation mode is random number, calling a random function, and generating a random number with a specified length as a packaging result;

(2.1.7) if the data generation mode is 'increment number', calculating an increment result of the data generation mode according to two attributes of 'increment initial value' and 'increment step length' of the field, and taking the increment result as a packaging result;

(2.1.8) if the data generation mode is 'system time', the current system time is obtained as the packaging result.

(2.2) if the node name of the child node of the packet node < Package > is the preparation area < PreArea >, entering a preparation area processing flow: sequentially reading data (mainly file data and a small amount of constant data) defined by all child nodes of the preparation area < PreArea > into an intermediate variable list for subsequent use;

(2.3) if the node name of the child node of the packet node < Package > is the private area < PriArea >, entering a private area processing flow: processing all child nodes of the private area < PriArea > in sequence, wherein the child nodes of the private area < PriArea > are single fields needing to be operated to obtain results, the operation results are stored in an intermediate variable list and only used for intermediate data operation, and the packaged results are not included;

(2.4) if the node name of the child node of the data packet node < Package > is the identification area < FlagArea >, entering an identification area processing flow: sequentially processing all sub-nodes of the identification area < FlagArea >, writing the obtained sub-node data into a temporary list, sequentially splicing the sub-node data in the temporary list according to a specified data splicing mode after all the sub-nodes of the identification area < FlagArea > are processed, obtaining a packaged character string, and storing the packaged character string into a packaged result; in some examples, if the identification area < FlagArea > participates in the operation at other places in the following, the package result of the identification area < FlagArea > is written into an intermediate variable list through a reference attribute defined by the protocol template, and the package result of the identification area < FlagArea > stored in the intermediate variable list can be referred in the following, so that a plurality of continuous data of the identification area < FlagArea > are referred as a whole.

(2.5) if the node name of the child node of the data packet node < Package > is the protection area < ProArea >, entering a protection area processing flow: the processing flow of the protection area is similar to that of the identification area, but after all the child nodes are sequentially processed to obtain the group package character string, the group package character string is operated according to the protection area operation definition of the protocol template, and the operation result is used as the final group package result; sequentially processing all sub-nodes of a protection area < ProArea >, writing the obtained sub-node data into a temporary list, sequentially splicing the sub-node data in the temporary list according to a specified data splicing mode after all the sub-nodes of the protection area < ProArea > are processed to obtain a packaged character string, and after all the sub-nodes are sequentially processed to obtain the packaged character string, operating the packaged character string according to the protection area operation definition of a protocol template, and taking the operation result as the final packaged result;

(2.6) if the node name of the child node of the data packet node < Package > is the circulation area < CycArea >, entering a circulation area processing flow: the loop region processing flow comprises a nested loop, the outer loop times are determined according to the loop times defined by a protocol template, the inner loop times are determined according to the number of sub-nodes in the loop region, the results of the sub-nodes are sequentially calculated in the inner loop, and the result of each sub-node can calculate a fixed result according to the protocol template definition; and when the two layers of circulation processing are finished, the fixed results of all the child nodes are spliced to obtain a group packaging result of the circulation area. In some embodiments, when the node name of the data packet node < Package > is the cycle region < cyca rea >, the internal and external cycle times are added as the file name suffixes of the results of the child nodes according to the protocol template definition to ensure the uniqueness of the data; and dynamically reading external file data with continuous file names as a packaging result according to the definition of the protocol template.

(3) And after the processing of all the sub-nodes under the node < Package > of the data packet is finished, splicing the packaging results of each sub-node according to the packaging mode defined by the protocol template to obtain the packaging results of the data packet.

As shown in fig. 4, the method for simulating dynamic parsing of a protocol by parsing keywords in an XML file of a protocol template includes the following steps:

(1) according to the transmitted protocol template name and the data packet name, finding out a node with the same name as the transmitted data packet name from the loaded protocol template data in the memory by matching a < Package > tag;

(2) sequentially and circularly traversing child nodes of the data packet node < Package >, and preprocessing the protocol template; the main content of the preprocessing is to replace the definition of the calling area with the content of the referred area so as to ensure that the same protocol sub-template is defined once in the referred area of the protocol template and then is referred for many times through the calling area; the method specifically comprises the following substeps:

(2.1) if the node name of the child node of the data packet node < Package > is the referred area < RefArea >, entering the referred area processing flow: the referenced area processing flow writes the whole referenced area into a referenced data intermediate variable list for direct reference of a calling area < CallArea >;

(2.2) if the node name of the child node of the data packet node < Package > is calling area < CallArea >, entering a calling area processing flow: the calling area processing flow acquires the name of the quoted area according to the node value of the calling area < CallArea >, acquires the prefix information of the child node id from the id attribute of the calling area < CallArea >, updates the id of all the child nodes of the quoted area and the prefix information and then replaces the calling area content of the protocol template, and the id of all the child nodes of the quoted area and the prefix information are used for avoiding the problem that the id of the quoted area is not unique after being quoted at multiple positions.

(3) After the protocol preprocessing is finished, sequentially analyzing the sub-nodes of the data packet node < Package >, performing different operation steps according to different keywords, outputting the analysis results of the sub-nodes, and recording the analysis results into an analysis result list; the contents of the referenced area and the calling area are not processed and are directly skipped. The method comprises the following specific steps:

(3.1) if the node name of the child node of the data packet node < Package > is Field < Field >, entering a Field processing flow: acquiring a field actual value according to the field length and the calculated field offset, or acquiring the field actual value according to a field separator; if the field expected value is defined, acquiring the field expected value according to a field operation mode of the expected value (similar to the data generation mode definition and processing in the packaging process); then comparing the actual field value with the expected field value, if the actual field value is consistent with the expected field value, continuing the process, and if the actual field value is inconsistent with the expected field value, outputting error information and terminating the analysis process;

(3.2) if the node name of the child node of the packet node < Package > is the preparation area < PreArea >, entering a preparation area processing flow: sequentially reading data (mainly file data and a small amount of constant data) defined by all child nodes of the preparation area < PreArea > into an intermediate variable list for subsequent use;

(3.3) if the node name of the child node of the packet node < Package > is the private area < PriArea >, entering a private area processing flow: processing all child nodes of the private area < PriArea > in sequence, wherein the child nodes of the private area < PriArea > are single fields needing to be operated to obtain results, the operation results are stored in an intermediate variable list and only used for intermediate data operation, and the packaged results are not included;

(3.4) if the node name of the child node of the data packet node < Package > is the identification area < FlagArea >, entering an identification area processing flow: firstly, acquiring data of the identification area < FlagArea > according to the definition of a protocol template, then sequentially processing all sub-nodes of the identification area < FlagArea >, writing the obtained sub-node data into a temporary list, and outputting an analysis character string to an XML file of a result file according to the sequence of the sub-node data in the temporary list after all the sub-nodes of the identification area < FlagArea > are processed, so that a user can conveniently check the analysis character string; if the identification area < FlagArea > participates in operation at other places in the follow-up process, the output analysis character string can be written into the intermediate variable list through the reference attribute definition of the protocol template, and the analysis character string can be directly referred in the follow-up process. The data of the entire identification area < FlagArea > and the acquisition modes of the child nodes in the identification area < FlagArea > are totally two:

one is to obtain data according to the data length of the identification area < FlagArea > and the calculated data offset of the identification area < FlagArea >, and the type is suitable for the condition that the data is directly spliced by numerical values;

and the other is to acquire data according to the delimiters defined by the protocol template, and the type is suitable for the condition that the splicing mode of the data is a format.

(3.5) if the node name of the child node of the data packet node < Package > is the protection area < ProArea >, entering a protection area processing flow: firstly, acquiring data before analysis of a protection area according to the data length of the protection area, then, according to operation information defined in an operation information child node < CalcInfo > of the protection area, taking the data before analysis of the protection area as an input parameter of an operation function, and obtaining data after protection removal after operation (the data before analysis of the protection area can be understood as ciphertext data after protocol opposite-end encryption, and the data after protection removal is plaintext data after local-end decryption); then, sequentially analyzing the data after the protection is removed according to the specific field definition of the protection area to obtain the final analysis result of the data of the protection area;

(3.6) if the node name of the child node of the data packet node < Package > is the circulation area < CycArea >, entering a circulation area processing flow: firstly, dynamically generating a protocol template of the loop in real time according to the loop times defined by the protocol template, for example: and circulating for 5 times, sequentially copying the child nodes of the circulating area < CycArea > in the protocol template to 5 times, and dynamically updating the field ID according to the circulating times to ensure the uniqueness of the field in the template. Then acquiring the data of the circulation region < CycArea >, sequentially analyzing each sub-node of the circulation region < CycArea > according to a protocol template of the circulation dynamically generated in real time, and outputting an analysis result;

(3.7) if the node name of the child node of the data packet node < Package > is the child template area < SubArea >, entering a child template area processing flow: the sub-template area processing flow matches a corresponding sub-template from a loaded protocol template file in a memory in real time according to the name of the sub-template defined by the protocol template, and then adds the matched sub-template into a sub-template temporary list for subsequent direct reference;

(3.8) if the node name of the child node of the packet node < Package > is the selected area < SelArea >, entering a selected area processing flow: the processing flow of the selected area is similar to an if … else … statement in a programming language, the branch judgment and processing of the protocol processing flow are realized by defining a selection condition in a protocol template and the name of a sub-template needing to be jumped under the selection condition, and if the selection condition is met, the corresponding sub-template is directly matched from a sub-template temporary list for analysis; the selection condition has two definition modes:

one is the node (stored in the intermediate variable list) which is analyzed before, the condition is selected and designated as the node name;

and the other is a node which is not resolved, and data is acquired according to the data length and the relative offset of the node.

(4) And after all child nodes under the data packet node < Package > are processed, sequentially outputting the analysis results in the analysis result list to a result file for a user to check.

The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

16页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种快速修改ELF格式文件的方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!