A communication protocol format and interaction mode extraction method based on binary reverse
By constructing a data flow graph and a deterministic constraint table, combined with a neural network semantic inference model, the problem of low efficiency in binary protocol reverse analysis in existing technologies is solved, and fully automatic and accurate protocol extraction is achieved in offline environments, which is suitable for isolated network environments.
Patent Information
- Application Number
- CN202611447652.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-17
- Publication Date
- 2026-11-27
Smart Images

Figure CN123185286A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method for extracting communication protocol formats and interaction methods based on binary reverse engineering, belonging to the field of communication protocol analysis and extraction technology. Background Technology
[0002] In fields such as industrial control, the Internet of Things (IoT), and the Internet of Vehicles (IoV), a large number of devices communicate using undisclosed proprietary binary protocols. A primary prerequisite for security analysis of these protocols (such as vulnerability discovery, fuzzing, and intrusion detection) is obtaining their format specifications and interaction logic. However, protocol specifications are core trade secrets of manufacturers and are typically not disclosed.
[0003] Traditional protocol reverse engineering methods rely heavily on manual analysis, which is inefficient. Some automated methods that have emerged in recent years can be divided into two categories: one is passive analysis based on network traffic statistics (such as PI and Netzob), which infers field boundaries through sequence comparison, but is almost ineffective for encrypted / obfuscated traffic and cannot restore the interactive state machine; the other is state machine inference based on active probing (such as the L* algorithm), which requires real-time interaction with online devices and cannot be applied to offline firmware security analysis scenarios.
[0004] Interpreting protocol definitions directly from the code of communication binary programs (firmware, dynamic libraries, executables) is the fundamental way to completely solve the above-mentioned pain points. However, existing general-purpose binary analysis tools (such as IDA Pro and Ghidra) lack domain knowledge of "protocol construction and parsing logic" and cannot automatically extract field formats and state machines, still relying heavily on manual reverse engineering. In recent years, although there have been attempts to directly analyze binary code using neural network semantic inference models (such as large language models), such models lack precise awareness of the underlying memory layout, register states, and data flow relationships. Directly reading disassembled code is prone to serious illusions, namely, the inferred field offsets, lengths, and byte order often seriously contradict the binary implementation.
[0005] Existing technologies include protocol reverse engineering based on network traffic, state machine inference based on active probing, and attempts to reverse binary protocols directly using neural network semantic inference models. Firstly, network traffic-based protocol reverse engineering techniques, such as Protocol Informatics (PI) and Netzob, perform multi-sequence alignment on captured network packets and delineate field boundaries based on byte change patterns. However, this method relies solely on statistical features, cannot handle encrypted or obfuscated traffic, struggles to infer field semantics (such as checksum algorithms), and completely fails to reconstruct the protocol interaction state machine logic. Secondly, active probing-based state machine inference techniques typically employ active probing methods, utilizing active learning algorithms such as L* to iteratively build the protocol state machine model by sending constructed probe packets to the target device and observing the response. The limitations of this approach are that it requires real-time interaction with online devices, making it unsuitable for offline firmware analysis scenarios; furthermore, it often requires a predefined input symbol set and lacks automatic processing for complex binary protocol field structures. Finally, attempts have been made to directly utilize neural network semantic inference models for binary protocol reverse engineering. Existing research has attempted to directly apply neural network semantic inference models (such as large language models) to binary code analysis. The basic approach is to use disassembled instruction sequences or pseudocode as text input models, and the models output natural language descriptions of code functions and field structures. However, such models lack the ability to accurately model the underlying binary memory layout, data flow, and instruction side effects. The field offsets, lengths, and byte order information they output often contradict the actual memory access instructions in the binary code, resulting in serious factual illusions. Existing solutions lack effective mechanisms to verify and correct the numerical technical details output by the models, leading to unreliable extraction results that cannot be directly used for subsequent security testing or protocol implementation. Summary of the Invention
[0006] The technical problem to be solved by this invention is to provide a method for extracting communication protocol formats and interaction methods based on binary reverse engineering. This method deeply integrates the deterministic constraints extracted by static program analysis with neural network semantic inference, and uses cross-validation mechanism to suppress model illusions, thereby accurately and completely extracting protocol field templates and protocol state machines.
[0007] To solve the above-mentioned technical problems, the present invention adopts the following technical solution: The present invention designs a method for extracting communication protocol format and interaction mode based on binary reverse engineering, and performs the following steps A to E to obtain the field template and protocol state machine of the target communication program, thereby realizing the extraction of the target communication program format and interaction mode; Step A. Load the target binary file of the target communication program, parse and convert it to obtain the corresponding intermediate analysis representation results; Step B. Based on the intermediate analysis results and the location of each network communication transmission function, generate the corresponding deterministic constraint table through the construction of the data flow graph (DFG). Step C. Based on the data flow graph (DFG) and deterministic constraint table of each network communication sending function, perform field-level local boundary verification, infer the semantic labels and encoding logic of the fields through a neural network semantic inference model, and obtain the field template of the target communication program through cross-validation algorithm and conflict backtracking correction. Step D. Based on the intermediate analysis results, and based on the location of each network communication receiving function, the message parsing function is determined by reverse tracing, and the corresponding single function complete state transition table is obtained. Then, by merging, the protocol state machine of the target communication program is constructed. Step E. For the field template and protocol state machine corresponding to the target communication program, perform a global semantic and structural consistency check, extract the field information in the state transition conditions and check the matching of the corresponding field definitions in the field template, mark the inconsistencies, and check the data flow graph and control flow graph respectively to determine the source of the error. Eliminate the inconsistencies by correcting the state transition conditions or by backtracking and supplementing the field template, and update the field template and protocol state machine corresponding to the target communication program.
[0008] As a preferred technical solution of the present invention: step A includes the following steps A1 to A6; Step A1. Load the target binary file of the target communication program, parse the header data structure of the target binary file, identify the file encapsulation format of the target binary file, and determine the compilation type of the target binary file based on the header structure defined by the file encapsulation format. If the compilation type of the target binary file is native code, proceed to step A2; if the compilation type of the target binary file is managed code, proceed to step A6. Step A2. First, based on the file encapsulation format of the target binary file, locate and extract the code segment in the target binary file to obtain the native machine code in the code segment, and at the same time obtain the target CPU architecture corresponding to the target binary file; then, based on the target CPU architecture, perform disassembly on the native machine code to obtain the corresponding assembly instruction sequence, and then convert the assembly instruction sequence into an intermediate representation IR structure diagram that uses a unified intermediate language format and is independent of the CPU architecture. In the intermediate representation IR structure diagram, a single instruction constitutes a single IR node, and the order or jump relationship between instructions is the edge between IR nodes; then proceed to step A3; Step A3. Based on the dependency generation relationship between each IR node in the intermediate representation IR structure diagram, generate the function call graph corresponding to the intermediate representation IR structure diagram, analyze the jump relationship between each IR node, generate the control flow graph corresponding to each function in the intermediate representation IR structure diagram, and then proceed to step A4. Step A4. Based on the native machine code, parse the underlying hardware metadata corresponding to each instruction and attach it to the corresponding IR node as an auxiliary attribute. Update the intermediate representation IR structure diagram to form the intermediate representation IR of the native code, and then proceed to step A5. Step A5. First, based on the function call graph, using network communication send and receive functions as anchor points, select all functions on the function call chain related to communication data send and receive from the function call graph to form each key function; then, obtain the instruction sequence of each IR node and its edge corresponding to each key function from the intermediate representation IR structure graph, and convert it into structured pseudocode text. Combine the intermediate representation IR, function call graph, and each control flow graph to encapsulate the intermediate analysis representation result. Step A6. Based on the file encapsulation format of the target binary file, locate and extract the IL bytecode and metadata in the target binary file. The IL bytecode forms the intermediate representation (IR) of the managed code. The IL bytecode is then parsed to generate a function call graph of the instructions and a control flow graph corresponding to each function. The intermediate representation (IR) and metadata are then combined to encapsulate the intermediate analysis representation result.
[0009] As a preferred technical solution of the present invention: step B includes the following steps B1 to B3; Step B1. Extract the function call graph from the intermediate analysis representation results. Using each network communication sending function as the retrieval anchor point, perform backward slicing across functions and procedures in the intermediate representation IR. That is, starting from the target sending buffer pointed to by the buffer pointer parameter of the retrieval anchor point, trace the data flow of each byte in the buffer backward along the data dependency relationship until it is determined that the source of each byte of data can be traced back to one of the three types of endpoints: function parameters, global variables, and return values. This constitutes the complete data dependency path corresponding to the network communication sending function. Step B2. Based on all data dependency paths corresponding to each network communication sending function, construct a data flow graph (DFG) for each network communication sending function. Each node in the DFG corresponds to a data operation point, and each node records the program location identifier, operation type, memory offset, and data width. Step B3. Based on the data flow graph (DFG) corresponding to each network communication sending function, generate a deterministic constraint table for each node in the DFG, thereby obtaining the deterministic constraint table corresponding to each network communication sending function.
[0010] As a preferred technical solution of the present invention: In step B1, if the intermediate representation IR is an intermediate representation IR structure graph, the IR node corresponding to the retrieval anchor point is used as the operation unit, and the data dependency edge of the IR node is traversed in reverse. When a function call instruction is encountered, the function call graph is reversed to enter the IR node subgraph of the called function to continue tracing, thereby realizing reverse tracing. If the intermediate representation IR is IL bytecode, the IL instruction corresponding to the retrieval anchor point in the IL bytecode is used as the operation unit. The data dependency edge of the IL instruction is traversed in reverse. When a method call instruction is encountered, the IL instruction sequence of the called function is entered in reverse along the function call graph to continue tracing, thus realizing reverse tracing.
[0011] As a preferred technical solution of the present invention: step C includes the following steps C1 to C3; Step C1. Based on the data flow graph (DFG) and deterministic constraint table of each network communication sending function, construct structured prompt words, and infer the semantic labels and encoding logic of the fields through a neural network semantic inference model, and output a list of field definitions; Step C2. For each field definition list, perform cross-validation and conflict backtracking correction, update the field definition list, and obtain a list of conflict-free field definitions. Step C3. If the target binary file is compiled as native code, then the list of conflict-free field definitions is merged according to the position of the corresponding target send buffer in the actual protocol to form the field template of the target communication program; if the target binary file is compiled as managed code, then the list of conflict-free field definitions directly forms the field template of the target communication program.
[0012] As a preferred technical solution of the present invention: step C1 includes the following steps C1a to C1c; Step C1a. If the target binary file is compiled as native code, proceed to step C1b; if the target binary file is compiled as managed code, proceed to step C1c. Step C1b. Based on the function call diagram of each network communication sending function in the intermediate analysis representation results, perform the following steps for each network communication sending function to obtain the field definition list corresponding to the network communication sending function; Based on the data flow graph (DFG) corresponding to the network communication sending function, instruction fragments corresponding to the IR nodes traversed by the DFG are extracted from the intermediate representation IR structure diagram to form code slices related to the construction of the communication buffer, and corresponding structured pseudocode text is obtained. At the same time, according to the deterministic constraint table corresponding to the network communication sending function, each constraint record in the deterministic constraint table is converted into a hard constraint array. The structured pseudocode text, the hard constraint array, and the candidate semantic list provided by the preset domain knowledge dictionary are jointly encapsulated into structured prompt words. The structured prompt words are input into the neural network semantic inference model to infer the semantic labels and encoding logic of the fields and output a list of field definitions. Step C1c. Using reflection or metadata parsing techniques, extract the field skeletons of protocol-related structures from the metadata representing the intermediate analysis results, construct explicit structure layout constraints, encapsulate the explicit structure layout constraints into structured prompts, and input them into a neural network semantic inference model. Within the boundaries of the explicit structure layout constraints, infer the semantic labels and encoding logic of the fields, and output a list of field definitions.
[0013] As a preferred embodiment of the present invention: step C2 includes steps C2a to C2c; Step C2a. If the target binary file is compiled as native code, proceed to step C2b; if the target binary file is compiled as managed code, proceed to step C2c. Step C2b. For each field definition list, perform cross-validation and conflict backtracking correction as follows to obtain a conflict-free field definition list; Iterate through each field in the field definition list, extracting the offset and data width of the field from the field definition list. In the data flow graph (DFG) of the corresponding network communication sending function, query the memory access instruction sequence corresponding to the offset range. Obtain the actual data width and address range operated by the memory access instruction sequence, forming a memory access instruction range. Determine if the offset and data width of the field from the field definition list are consistent with the memory access instruction range. If they are, the field passes verification; otherwise, a field conflict is identified. This process is repeated for each field in the field definition list. Then, it is determined whether there are conflicting fields in the field definition list. If so, conflict backtracking correction is performed for each conflicting field to obtain a conflict-free field definition list; otherwise, the current field definition list is considered conflict-free. Step C2c. Execute the cross-validation algorithm and conflict backtracking correction. Iterate through each field in the field definition list and determine whether the offset and data width of the field from the field definition list are consistent with the field skeleton in the explicit structure layout constraints. If they are, the field is considered to have passed the validation; otherwise, the field is considered to be in conflict. Then, complete the validation of each field in the field definition list, and then determine whether there are conflicting fields in the field definition list. If there are, perform conflict backtracking correction for each conflicting field to obtain a conflict-free field definition list; otherwise, it is a conflict-free field definition list.
[0014] As a preferred technical solution of the present invention: in steps C2b and C2c, for each conflicting field, the following conflict backtracking correction is performed to update the field definition list, thereby obtaining a conflict-free field definition list; First, the conflict information of the field is written into the structured prompt words for updating. The input is the neural network semantic inference model, which outputs the semantic label and encoding logic of the field. Then, the cross-validation algorithm is executed again for the field. If the field is found to be valid, the semantic label and encoding logic of the field are updated to the field definition list. If the field is found to be conflicting, the inference result of the neural network semantic inference model is discarded, and the static rule matching result of the corresponding data flow graph (DFG) is used instead, and the field definition list is updated.
[0015] As a preferred embodiment of the present invention, step D includes the following steps D1 to D3; Step D1. Based on the function call graph in the intermediate analysis results, for each network communication receiving function, using the network communication receiving function as the retrieval target, search the function call graph for all function call points pointing to the retrieval target, and mark them as anchor points of each receiving function, thus obtaining the anchor points of each receiving function corresponding to the network communication receiving function; further, for each receiving function anchor point, based on the function call graph, start from the function node corresponding to the receiving function anchor point and trace upwards along the reverse edge of the call, marking all functions that call the retrieval target network communication receiving function and contain data parsing logic as message parsing functions, and then proceed to step D2; Step D2. Based on the fact that each network communication receiving function corresponds to a receiving function anchor point, and each receiving function anchor point corresponds to a message parsing function, execute steps D2-1 to D2-3 for each message parsing function to obtain the complete state transition table of the single function corresponding to the message parsing function, and then proceed to step D3. Step D2-1. For the control flow graph corresponding to the message parsing function, a depth-first search is used to traverse each basic block in the control flow graph. First, the instruction sequence within the basic block is converted into pseudo-code statements in natural language to form the pseudo-code block corresponding to the basic block. Then, if the exit edge of the basic block is a conditional jump edge, the jump condition is converted into a conditional expression with logical operators, and the target basic block it points to is recorded. If the exit edge of the basic block is a cross-function call edge, the cross-function call edge is converted into a text description form, and the entry basic block of the called function it points to is recorded. Finally, the corresponding indentation level is added according to the current nesting depth. After traversing each basic block in the control flow graph, the structured execution trajectory text of the tree structure corresponding to the message parsing function is obtained. Step D2-2. Input the structured execution trajectory text corresponding to the message parsing function into the neural network semantic inference model. Based on the causal relationship of the code logic, the neural network semantic inference model identifies the message type field values that trigger different processing branches and maps them to protocol state nodes; and maps the branch conditions to labeled state transition edges. The transition edge labels contain the condition expression and the corresponding message field name, and then outputs the corresponding state transition table. Step D2-3. Use a neural network semantic inference model to perform semantic reasoning on the abnormal handling branches or specific magic number verification branches in the structured execution trajectory text that are not triggered by regular traffic, complete the hidden states or backdoor maintenance paths not exposed in the protocol specification, and merge the completed hidden state transition edges into the state transition table to form a single-function complete state transition table corresponding to the message parsing function. Step D3. Based on the fact that each network communication receiving function corresponds to a receiving function anchor point, firstly, for each receiving function anchor point, merge the single-function complete state transition tables of each message parsing function corresponding to the receiving function anchor point to form the anchor point complete state transition table corresponding to the receiving function anchor point. Then, for each network communication receiving function, the complete state transition tables of the anchor points of each receiving function corresponding to the network communication receiving function are merged to form the protocol state transition table corresponding to the network communication receiving function. Then, the protocol state transition tables corresponding to each network communication receiving function are merged to obtain the protocol state machine of the target communication program; During the merging process, if there are shared state nodes between the two state transition tables, the shared nodes are merged; if the two state transition tables are completely independent, they are retained as parallel branches.
[0016] As a preferred embodiment of the present invention: step E includes the following steps E1 to E3; Step E1. Input the field template and protocol state machine of the target communication program into the neural network semantic inference model and perform cross-consistency verification. This includes extracting the conditional expression of each state transition edge in the protocol state machine, parsing out the field names and expected values involved, and searching for the field definition corresponding to the field name in the field template. If the field name does not exist in the field template, or the offset, data width, or data type of the field name is inconsistent with the implicit constraints in the state transition edge, then the verification item is marked as an inconsistency item. The neural network semantic inference model then outputs the marked field template and protocol state machine, as well as the list of marked inconsistencies. If the list of inconsistencies is not empty, proceed to step E2; if the list of inconsistencies is empty, keep the field template and protocol state machine corresponding to the target communication program unchanged. Step E2. For each inconsistency in the inconsistency list, first check the data flow graph (DFG) and control flow graph corresponding to each network communication sending function, and then proceed to step E3. If the inconsistency stems from a semantic reasoning error in step D, then the corresponding state transition condition in the protocol state machine must be corrected to be consistent with the static data flow conclusion in the corresponding data flow graph. If the inconsistency stems from a missing field in step C, then backtrack to step C and add the missing field to the field template. Step E3. Input the field template and protocol state machine corrected in step E2 back into the neural network semantic inference model, and repeat the verification and correction process from step E1 to E2 until the list of inconsistencies output by the neural network semantic inference model is empty. Then output the corrected field template and protocol state machine and update it to the field template and protocol state machine corresponding to the target communication program.
[0017] The method for extracting communication protocol formats and interaction methods based on binary reverse engineering described in this invention has the following technical advantages compared with existing technologies: This invention designs a method for extracting communication protocol formats and interaction methods based on binary reverse engineering. First, the target binary file of the target communication program is parsed to obtain intermediate analysis representation results. Then, based on the intermediate analysis representation results, data flow backtracking is performed using each network communication sending function as an anchor point to construct a data flow graph and generate a deterministic constraint table. Next, based on the data flow graph and the deterministic constraint table, field semantic labels and encoding logic are inferred using a neural network semantic inference model, and field templates are obtained through cross-validation and conflict backtracking correction. Then, based on the intermediate analysis representation results, message parsing functions are determined by reverse tracing using each network communication receiving function as an anchor point. A state transition table is generated through control flow graph semantic processing and model inference, and the protocol state machine is constructed. Finally, cross-consistency verification is performed on the field templates and the protocol state machine to obtain a fully self-consistent protocol specification document. This invention achieves fully automatic protocol reverse engineering in off-network, non-interactive environments. Through the synergy of static constraints and neural network semantic inference models, it effectively suppresses model illusions and takes into account both native and managed code adaptive analysis, resulting in accurate and reliable extraction results. This invention designs a method for extracting communication protocol formats and interaction methods based on binary reverse engineering. It can automatically extract protocols using only the target binary file without capturing network traffic or interacting with online devices, making it suitable for security research in isolated network environments. At the same time, it adopts an adaptive dual-path strategy for managed code (reflection + semantic annotation) and native code (DFG slicing + instruction-level semantic inference), taking into account both zero false positives and deep parsing, covering the analysis needs of different language runtimes. This invention designs a method for extracting communication protocol formats and interaction methods based on binary reverse engineering. It can accurately extract the byte order, checksum algorithm, and lightweight encryption / obfuscation logic of fields, and obtain deep coding information that cannot be obtained by traffic analysis. Based on control flow semantic reasoning, it can restore hidden protocol states or backdoor paths that have not appeared in network traffic. The state machine integrity is far superior to passive analysis methods based on statistics. This invention designs a method for extracting communication protocol formats and interaction methods based on binary inversion. It uses the memory access instruction facts in the data flow graph to strictly constrain the output of the neural network semantic inference model, and effectively filters model illusions through quantitative cross-validation to ensure that the extracted offset, data width and type are completely consistent with the binary implementation. The results can be directly used to generate fuzz test cases or configure network security devices. Attached Figure Description
[0018] Figure 1 This is a flowchart of the method for extracting communication protocol formats and interaction methods based on binary reverse engineering, as designed in this invention. Figure 2 This is a flowchart of step C in the binary reverse-engineered communication protocol format and interaction method extraction method designed in this invention; Figure 3 This is a flowchart of step D in the binary reverse-engineered communication protocol format and interaction method extraction method designed in this invention. Detailed Implementation
[0019] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.
[0020] This invention designs a method for extracting communication protocol format and interaction mode based on binary reverse engineering. It directly analyzes the binary code of the communication program and constructs an automated closed loop consisting of intermediate representation conversion, data flow backtracking and delimitation, neural network semantic inference, and static constraint cross-validation to automatically reconstruct the protocol specification. In practical applications, as shown in Figure 1, the following steps A to E are executed to obtain the field template and protocol state machine of the target communication program, thereby realizing the extraction of the target communication program format and interaction mode.
[0021] Step A. Load the target binary file of the target communication program and execute steps A1 to A6 below to parse and convert it to obtain the corresponding intermediate analysis representation results.
[0022] Step A1. Load the target binary file (firmware, dynamic library, executable file) of the target communication program, parse the header data structure of the target binary file, identify the file encapsulation format of the target binary file, and determine the compilation type of the target binary file based on the header structure defined by the file encapsulation format. If the compilation type of the target binary file is native code, proceed to step A2; if the compilation type of the target binary file is managed code (.NET / Java), proceed to step A6.
[0023] Step A2. First, based on the target binary file's file encapsulation format, locate and extract the code segment from the target binary file to obtain the native machine code (ARM / Thumb / x86 / MIPS, etc.) within the code segment, and simultaneously obtain the target CPU architecture corresponding to the target binary file. Then, based on the target CPU architecture, disassemble the native machine code to obtain the corresponding assembly instruction sequence. Next, convert the assembly instruction sequence into an intermediate representation (IR) structure diagram using a unified intermediate language format, independent of the CPU architecture. In the intermediate representation IR structure diagram, a single instruction constitutes a single IR node, and the edges between IR nodes are defined by the order or jump relationship between instructions. Then proceed to step A3. In practical applications, the intermediate representation IR structure diagram may use VEX IR or LLVM IR.
[0024] Step A3. Based on the dependency generation relationship between each IR node in the intermediate representation IR structure diagram, generate the function call graph corresponding to the intermediate representation IR structure diagram, analyze the jump relationship between each IR node, generate the control flow graph corresponding to each function in the intermediate representation IR structure diagram, and then proceed to step A4.
[0025] Step A4. Based on the native machine code, parse the underlying hardware metadata corresponding to each instruction and attach it to the corresponding IR node as an auxiliary attribute. Update the intermediate representation IR structure diagram to form the intermediate representation IR of the native code, and then proceed to step A5. The underlying hardware metadata includes memory address, register operands and data width.
[0026] Step A5. First, based on the function call graph, using network communication send / receive functions as anchors, select all functions on the function call chain related to communication data transmission and reception from the function call graph to form each key function; then, obtain the instruction sequence of each IR node and its edges corresponding to each key function from the intermediate representation IR structure graph, and convert it into structured pseudocode text, in which the virtual address, operand register and immediate offset of the instruction are explicitly preserved, as input material for subsequent neural network semantic inference model (preferably Large Language Model (LLM) or Transformer-based model) for semantic understanding; the structured pseudocode text, combined with the intermediate representation IR, function call graph and each control flow graph, are encapsulated together as the intermediate analysis representation result.
[0027] Step A6. Based on the file encapsulation format of the target binary file, locate and extract the IL bytecode and metadata in the target binary file. The IL bytecode forms the intermediate representation (IR) of the managed code. The IL bytecode is then parsed to generate a function call graph of the instructions and a control flow graph corresponding to each function. The intermediate representation (IR) and metadata are then combined to encapsulate the intermediate analysis representation result.
[0028] Step B. Based on the intermediate analysis results, perform steps B1 to B3 as follows: based on the location of each network communication transmission function, generate the corresponding deterministic constraint table through the construction of the data flow graph (DFG).
[0029] Step B1. Extract the function call graph from the intermediate analysis representation results. Using each network communication sending function (such as send, recv, write) as the retrieval anchor point, perform backward slicing across functions and procedures in the intermediate representation IR. That is, starting from the target sending buffer pointed to by the buffer pointer parameter of the retrieval anchor point, trace the data flow of each byte in the buffer backward along the data dependency relationship until it is determined that the source of each byte of data can be traced back to one of the three types of endpoints: function parameters, global variables, and return values. This constitutes the complete data dependency path corresponding to the network communication sending function.
[0030] The above-described tracing design, implemented from the starting point, involves the following steps: If the intermediate representation IR is an intermediate representation IR structure graph, the IR node corresponding to the retrieval anchor point is used as the operation unit. The traversal proceeds backward along the data dependency edges of the IR nodes. When a function call instruction is encountered, the traversal proceeds backward along the function call graph to enter the IR node subgraph of the called function and continue tracing, thus achieving reverse tracing. If the intermediate representation IR is IL bytecode, the IL instruction corresponding to the retrieval anchor point in the IL bytecode is used as the operation unit. The traversal proceeds backward along the data dependency edges of the IL instructions. When a method call instruction is encountered, the traversal proceeds backward along the function call graph to enter the IL instruction sequence of the called function and continue tracing, thus achieving reverse tracing.
[0031] Step B2. Based on all data dependency paths corresponding to each network communication sending function, construct a Data Flow Graph (DFG) for each network communication sending function. Completely depict the mapping path of source data, intermediate processing, and sending buffer in sequence. Each node in the DFG corresponds to a data operation point, and each node records the program location identifier, operation type (read / write), memory offset, and data width.
[0032] Step B3. Based on the data flow graph (DFG) corresponding to each network communication sending function, generate a deterministic constraint table for each node in the DFG, thereby obtaining the deterministic constraint table corresponding to each network communication sending function.
[0033] Step C. The design employs a collaborative strategy of static data flow delimitation, model semantic assignment, and cross-validation to prevent illusions, specifically based on the data flow graph (DFG) and deterministic constraint table of each network communication sending function, such as... Figure 2 As shown, following steps C1 to C3, field-level local boundary verification is performed. The semantic label and encoding logic of the field are inferred through the neural network semantic inference model. The field template of the target communication program is obtained through cross-validation algorithm and conflict backtracking correction.
[0034] Step C1. Based on the data flow graph (DFG) and deterministic constraint table of each network communication sending function, perform steps C1a to C1c to construct structured prompt words, and use a neural network semantic inference model to infer the semantic labels and encoding logic of the fields, and output a list of field definitions.
[0035] Step C1a. If the target binary file is compiled as native code, proceed to step C1b; if the target binary file is compiled as managed code, proceed to step C1c.
[0036] Step C1b. Based on the function call diagram of each network communication sending function in the intermediate analysis representation results, perform the following steps for each network communication sending function to obtain the field definition list corresponding to the network communication sending function.
[0037] Based on the data flow graph (DFG) corresponding to the network communication sending function, instruction fragments corresponding to the IR nodes traversed by the DFG are extracted from the intermediate representation IR structure diagram to form code slices related to the construction of the communication buffer, and corresponding structured pseudocode text is obtained. Simultaneously, according to the deterministic constraint table corresponding to the network communication sending function, each constraint record in the deterministic constraint table is converted into a hard constraint array. The structured pseudocode text, the hard constraint array, and the candidate semantic list provided by the preset domain knowledge dictionary are jointly encapsulated into structured prompt words. The structured prompt words are input into a neural network semantic inference model (such as a large language model based on the Transformer architecture) to infer the semantic labels and encoding logic of the fields and output a list of field definitions.
[0038] In practical applications, the hard constraint field "hard_constraints" is set as a priori conditions that cannot be covered by the model, forcing the neural network semantic inference model to reason within the given memory offset boundary. Within the constraint boundary, the neural network semantic inference model infers the semantic labels of the fields (such as "synchronization header" and "CRC check") and possible encoding logic, and outputs a structured list of field definitions. Each field contains "field_name", "offset", "size", "type", "semantic_label" and "encoding_algorithm".
[0039] Step C1c. Using reflection or metadata parsing techniques, extract the field skeletons of protocol-related structures from the metadata representing the intermediate analysis results to form explicit structure layout constraints. Encapsulate the explicit structure layout constraints into structured prompts and input them into a neural network semantic inference model (such as a large language model based on the Transformer architecture). Infer the semantic labels and encoding logic of the fields within the boundaries of the explicit structure layout constraints and output a list of field definitions.
[0040] In practical applications, the prompts are organized in a structured JSON format and contain the following fields: "code_slice": The pseudocode text to be analyzed; "hard_constraints": An array of deterministic constraints extracted from DFG, each constraint containing "offset" (memory offset), "size" (byte width), "instruction_type" (such as LDRB, STRH, REV16), and "operand_values" (critical immediate values). "domain_hints": A list of candidate field semantics from the domain knowledge dictionary.
[0041] For example: Source code slice (ARM assembly): LDRB R0, [R1,#0]; CMP R0, #0xAA LDRH R0, [R1,#1]; REV16 R0, R0 The hard_constraints (JSON array) constructed by S2 actually behave as follows: [ {"offset":0, "size":1, "insn":"LDRB", "imm":["0xAA"]}, {"offset":1, "size":2, "insn":"LDRH+REV16", "endian":"big"} ] The final prompt words (simplified version) for the input model are: "Given that there is a 1-byte read instruction at offset 0 and a comparison immediate value of 0xAA, and a half-word read + invert instruction at offset 1, please assign semantic labels to the fields within these boundaries." The validation logic after model output is as follows: If the model output offset=1 and size=1, then DFG will find the LDRH instruction that is actually size=2 at that point, determine the conflict, and trigger backtracking and regeneration.
[0042] Step C2. Perform steps C2a to C2c as follows: for each field definition list, perform cross-validation and conflict backtracking correction, update the field definition list, and obtain a list of conflict-free field definitions.
[0043] Step C2a. If the target binary file is compiled as native code, proceed to step C2b; if the target binary file is compiled as managed code, proceed to step C2c.
[0044] Step C2b. For each field definition list, perform cross-validation and conflict backtracking correction as follows to obtain a conflict-free field definition list.
[0045] Iterate through each field in the field definition list, extracting the offset "offset" and data width "size" from the field definition list. In the data flow graph (DFG) of the corresponding network communication sending function, query the memory access instruction sequence corresponding to the offset range. Obtain the actual data width and address range operated by the memory access instruction sequence, forming a memory access instruction interval. Determine if the offset and data width of the field from the field definition list match the memory access instruction interval. If they match, the field passes verification; otherwise, a field conflict is identified. For example, the neural network semantic inference model outputs offset=1, size=2, but the DFG shows only LDRB (1 byte) access at offset 1. Then, complete the verification of each field in the field definition list. Next, determine if there are conflicting fields in the field definition list. If so, perform conflict backtracking correction for each conflicting field to obtain a conflict-free field definition list; otherwise, it is a conflict-free field definition list.
[0046] Step C2c. Execute the cross-validation algorithm and conflict backtracking correction. Iterate through each field in the field definition list and determine whether the offset and data width of the field from the field definition list are consistent with the field skeleton in the explicit structure layout constraints. If they are, the field is considered to have passed the validation; otherwise, the field is considered to be in conflict. Then, complete the validation of each field in the field definition list, and then determine whether there are conflicting fields in the field definition list. If there are, perform conflict backtracking correction for each conflicting field to obtain a conflict-free field definition list; otherwise, it is a conflict-free field definition list.
[0047] In practical applications, in steps C2b and C2c above, the following conflict backtracking correction is performed for each conflicting field to update the field definition list and thus obtain a conflict-free field definition list.
[0048] First, the conflict information of the field is written into the structured prompt words for updating. The input is the neural network semantic inference model, which outputs the semantic label and encoding logic of the field. Then, the cross-validation algorithm is executed again for the field. If the field is found to be valid, the semantic label and encoding logic of the field are updated to the field definition list. If the field is found to be conflicting, the inference result of the neural network semantic inference model is abandoned, and the static rule matching result of the corresponding data flow graph (DFG) is used instead. The field definition list is then updated. For example, the field can be directly inferred to be a 2-byte big-endian field based on the half-word load instruction LDRH + byte inversion instruction REV16.
[0049] Step C3. If the target binary file is compiled as native code, then the list of conflict-free field definitions is merged according to the position of the corresponding target send buffer in the actual protocol to form the field template of the target communication program; if the target binary file is compiled as managed code, then the list of conflict-free field definitions directly forms the field template of the target communication program.
[0050] according to Figure 2 The application is shown in Table 1, which compares the managed path with the native instructions.
[0051] Table 1. Comparison of Dual Paths
[0052] Step D. For the control flow of the received message processing function, a method combining graph structure textualization and model state reasoning is adopted, such as... Figure 3 As shown, based on the intermediate analysis results, the following steps D1 to D3 are executed: based on the location of each network communication receiving function, the message parsing function is determined by reverse tracing, and the corresponding single function complete state transition table is obtained. Then, by merging, the protocol state machine of the target communication program is constructed.
[0053] Step D1. Based on the function call graph in the intermediate analysis results, for each network communication receiving function, using the network communication receiving function as the retrieval target, search the function call graph for all function call points pointing to the retrieval target, and mark them as anchor points of each receiving function, thus obtaining the anchor points of each receiving function corresponding to the network communication receiving function; further, for each receiving function anchor point, based on the function call graph, start from the function node corresponding to the receiving function anchor point, trace upwards along the reverse edge of the call (the direction from the callee to the caller), and mark all functions that call the retrieval target network communication receiving function and contain data parsing logic as message parsing functions, and then proceed to step D2.
[0054] Step D2. Based on the fact that each network communication receiving function corresponds to a receiving function anchor point, and each receiving function anchor point corresponds to a message parsing function, execute steps D2-1 to D2-3 for each message parsing function to obtain the complete state transition table of the single function corresponding to the message parsing function, and then proceed to step D3.
[0055] Step D2-1. For the control flow graph corresponding to the message parsing function, use depth-first search (DFS) to traverse each basic block in the control flow graph. First, convert the instruction sequence within the basic block into natural language pseudocode statements to form the pseudocode block corresponding to the basic block. Then, if the exit edge of the basic block is a conditional jump edge, convert the jump condition (such as CMP+Bcc) into a conditional expression with logical operators (AND / OR / NOT) and record the target basic block it points to. If the exit edge of the basic block is a cross-function call edge, convert the cross-function call edge into a text description such as "calling subfunction FuncX with parameter R0=..." and record the entry basic block of the called function it points to. Finally, add the corresponding indentation level according to the current nesting depth. After completing the traversal of each basic block in the control flow graph, the structured execution trajectory text of the tree structure corresponding to the message parsing function is obtained.
[0056] Step D2-2. Input the structured execution trajectory text corresponding to the message parsing function into the neural network semantic inference model. Based on the causal relationship of the code logic, the neural network semantic inference model identifies the message type field values that trigger different processing branches and maps them to protocol state nodes; and maps the branch conditions to labeled state transition edges. The transition edge labels contain the condition expression and the corresponding message field name, and then output the corresponding state transition table.
[0057] Step D2-3. Utilize a neural network semantic inference model to perform semantic reasoning on anomaly handling branches or specific magic number verification branches in the structured execution trajectory text that are not triggered by regular traffic, complete the hidden states or backdoor maintenance paths not exposed in the protocol specification, and merge the completed hidden state transition edges into the state transition table to form a single-function complete state transition table corresponding to the message parsing function.
[0058] Step D3. Based on the anchor points corresponding to each network communication receiving function, firstly, for each receiving function anchor point, merge the complete state transition tables of the single function for each message parsing function to form the complete anchor point state transition table corresponding to the receiving function anchor point; then, for each network communication receiving function, merge the complete anchor point state transition tables of each receiving function anchor point to form the protocol state transition table corresponding to the network communication receiving function; finally, merge the protocol state transition tables corresponding to each network communication receiving function to obtain the protocol state machine of the target communication program; during merging, if there are shared state nodes between the two state transition tables, merge the shared nodes; if the two state transition tables are completely independent, they are retained as parallel branches.
[0059] In practical applications, for example, as follows.
[0060] CFG branch conditions before transformation: CMP R0, #1 and CMP R0, #2 The transformed semantic execution trajectory text (the specific string of the input model): If (buf[0] == 0xAA), then execute: Analyze the serial number; If (serial number == 0xFFFF), then execute: Entering maintenance mode (hidden path); otherwise: Entering data receiving mode.
[0061] The state transition table output by the neural network semantic inference model is shown in Table 2.
[0062] Table 2 shows the state transition representation of the model output.
[0063] Step E. For the field template and protocol state machine corresponding to the target communication program, perform global semantic and structural consistency checks according to steps E1 to E3 below, extract field information in the state transition conditions and check the matching of the corresponding field definitions in the field template, mark inconsistencies, and check the data flow graph and control flow graph respectively to determine the source of errors. Eliminate inconsistencies by correcting the state transition conditions or by backtracking and supplementing the field template, and update the field template and protocol state machine corresponding to the target communication program.
[0064] Step E1. Input the field template and protocol state machine of the target communication program into the neural network semantic inference model and perform cross-consistency verification. This includes extracting the conditional expression of each state transition edge in the protocol state machine, parsing out the field names and expected values involved, and searching for the field definition corresponding to the field name in the field template. If the field name does not exist in the field template, or the offset, data width, or data type of the field name is inconsistent with the implicit constraints in the state transition edge, then the verification item is marked as an inconsistency item. The neural network semantic inference model then outputs the marked field template and protocol state machine, as well as the list of marked inconsistencies. If the list of inconsistencies is not empty, proceed to step E2; if the list of inconsistencies is empty, keep the field template and protocol state machine corresponding to the target communication program unchanged.
[0065] Step E2. For each inconsistency in the inconsistency list, first check the data flow graph (DFG) and control flow graph corresponding to each network communication sending function, and then proceed to step E3.
[0066] If the inconsistency stems from a semantic reasoning error in step D, then the corresponding state transition condition in the protocol state machine must be corrected to be consistent with the static data flow conclusion in the corresponding data flow graph. If the inconsistency stems from a missing field in step C, then backtrack to step C and add the missing field to the field template.
[0067] Step E3. Input the field template and protocol state machine corrected in step E2 back into the neural network semantic inference model, and repeat the verification and correction process from step E1 to E2 until the list of inconsistencies output by the neural network semantic inference model is empty. Then output the corrected field template and protocol state machine and update it to the field template and protocol state machine corresponding to the target communication program.
[0068] The above design scheme is applied in practice, including the following Embodiment 1 and Embodiment 2.
[0069] Case 1: Structure Extraction and Model Semantic Enhancement Based on .NET Managed Code. An industrial control host computer software is developed using the .NET framework, and the communication module is a managed DLL. After the system loads, reflection is used to automatically filter protocol-related structures, extracting field names, types, offsets, and Marshal attributes to construct a field skeleton. For example, the following was extracted: Field 1: Header, uint8, constant value = 0xAA Field 2: SequenceID, uint16, big-endian Field 3: DataLength, uint8 Field 4: Data, byte[], length determined by DataLength. Field 5: Checksum, uint8, Algorithm = XOR Subsequently, the structure definition and field context are encapsulated into a structured prompt input model. Under the static offset constraints determined by reflection, the model infers that "Header is the frame synchronization header," "SequenceID is the sequence number," "DataLength is the payload length," and "Checksum is the XOR checksum." The statically extracted XOR operation logic automatically verifies the model's inference of the checksum field, ultimately generating a highly readable zero-false alarm protocol template.
[0070] Case 2: Joint Intelligent Extraction of Static Constraints and Models Based on Native Binary Programs. An embedded device's communication service uses ARM native binary. The system locates the `tcp_data_handler` function, identifies the byte-by-byte parsing mode, and extracts the instruction sequence: LDRB R0, [R1,#0]; CMP R0, #0xAA; B.NE error LDRH R0, [R1,#1]; REV16 R0, R0 LDRB R3, [R1,#3]; ... The structured prompt words are automatically constructed, where the "hard_constraints" array contains three constraints: {"offset":0, "size":1, "instruction_type":"LDRB", "operand_values":[0xAA]}, {"offset":1, "size":2, "instruction_type":"LDRH+REV16"}, and {"offset":3, "size":1, "instruction_type":"LDRB"}. The model outputs under the constraints: "buf[0] is the synchronization header, with a fixed value of 0xAA; buf[1:2] is a 2-byte big-endian sequence number; buf[3] is the payload length". This output is adopted after being verified by the DFG memory write mode and forms the field definition. At the same time, the main loop control flow is input into the model after passing through the semantic text representation, and the state machine containing the hidden management state is inferred. The fields referenced by the state transition conditions are completely consistent with the template, achieving high-precision restoration.
[0071] This invention achieves fully automated protocol reverse engineering in off-network, non-interactive environments. Through the synergy of static constraints and neural network semantic inference models, it effectively suppresses model illusions and takes into account both native and managed code adaptive analysis, resulting in accurate and reliable extraction results. In practical applications, only the target binary file is needed for fully automated protocol extraction without capturing network traffic or interacting with online devices, making it suitable for security research in isolated network environments. Furthermore, it employs an adaptive dual-path strategy for managed code (reflection + semantic annotation) and native code (DFG slicing + instruction-level semantic inference), balancing zero false positives and deep parsing to cover the analysis needs of different language runtimes.
[0072] In practical applications, it can accurately extract the byte order, checksum algorithm, and lightweight encryption / obfuscation logic of fields, obtaining deep encoded information that cannot be obtained through traffic analysis. Based on control flow semantic reasoning, it can restore hidden protocol states or backdoor paths that have not appeared in network traffic, and the state machine integrity far exceeds that of passive analysis methods based on statistics. Moreover, it uses the memory access instruction facts in the data flow graph to strictly constrain the output of the neural network semantic inference model, and effectively filters model illusions through quantitative cross-validation, ensuring that the extracted offset, data width, and type are completely consistent with the binary implementation. The results can be directly used to generate fuzz test cases or configure network security devices.
[0073] The embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the present invention is not limited to the above embodiments. Within the scope of knowledge possessed by those skilled in the art, various changes can be made without departing from the spirit of the present invention.
Claims
1. A method for extracting communication protocol formats and interaction methods based on binary reverse engineering, characterized in that, Perform steps A through E to obtain the field template and protocol state machine of the target communication program, thereby extracting the format and interaction method of the target communication program. Step A. Load the target binary file of the target communication program, parse and convert it to obtain the corresponding intermediate analysis representation results; Step B. Based on the intermediate analysis results and the location of each network communication transmission function, generate the corresponding deterministic constraint table through the construction of the data flow graph (DFG). Step C. Based on the data flow graph (DFG) and deterministic constraint table of each network communication sending function, perform field-level local boundary verification, infer the semantic labels and encoding logic of the fields through a neural network semantic inference model, and obtain the field template of the target communication program through cross-validation algorithm and conflict backtracking correction. Step D. Based on the intermediate analysis results, and based on the location of each network communication receiving function, the message parsing function is determined by reverse tracing, and the corresponding single function complete state transition table is obtained. Then, by merging, the protocol state machine of the target communication program is constructed. Step E. For the field template and protocol state machine corresponding to the target communication program, perform a global semantic and structural consistency check, extract the field information in the state transition conditions and check the matching of the corresponding field definitions in the field template, mark the inconsistencies, and check the data flow graph and control flow graph respectively to determine the source of the error. Eliminate the inconsistencies by correcting the state transition conditions or by backtracking and supplementing the field template, and update the field template and protocol state machine corresponding to the target communication program.
2. The method for extracting communication protocol format and interaction mode based on binary reverse engineering according to claim 1, characterized in that: Step A includes the following steps A1 to A6; Step A1. Load the target binary file of the target communication program, parse the header data structure of the target binary file, identify the file encapsulation format of the target binary file, and determine whether the compilation type of the target binary file is raw code based on the header structure defined by the file encapsulation format, then proceed to step A2. If the target binary file is compiled as managed code, proceed to step A6; Step A2. First, based on the file encapsulation format of the target binary file, locate and extract the code segment in the target binary file to obtain the native machine code in the code segment, and at the same time obtain the target CPU architecture corresponding to the target binary file; then, based on the target CPU architecture, perform disassembly on the native machine code to obtain the corresponding assembly instruction sequence, and then convert the assembly instruction sequence into an intermediate representation IR structure diagram that uses a unified intermediate language format and is independent of the CPU architecture. In the intermediate representation IR structure diagram, a single instruction constitutes a single IR node, and the order or jump relationship between instructions is the edge between IR nodes; then proceed to step A3; Step A3. Based on the dependency generation relationship between each IR node in the intermediate representation IR structure diagram, generate the function call graph corresponding to the intermediate representation IR structure diagram, analyze the jump relationship between each IR node, generate the control flow graph corresponding to each function in the intermediate representation IR structure diagram, and then proceed to step A4. Step A4. Based on the native machine code, parse the underlying hardware metadata corresponding to each instruction and attach it to the corresponding IR node as an auxiliary attribute. Update the intermediate representation IR structure diagram to form the intermediate representation IR of the native code, and then proceed to step A5. Step A5. First, based on the function call graph, using network communication send and receive functions as anchor points, select all functions on the function call chain related to communication data send and receive from the function call graph to form each key function; then, obtain the instruction sequence of each IR node and its edge corresponding to each key function from the intermediate representation IR structure graph, and convert it into structured pseudocode text. Combine the intermediate representation IR, function call graph, and each control flow graph to encapsulate the intermediate analysis representation result. Step A6. Based on the file encapsulation format of the target binary file, locate and extract the IL bytecode and metadata in the target binary file. The IL bytecode forms the intermediate representation (IR) of the managed code. The IL bytecode is then parsed to generate a function call graph of the instructions and a control flow graph corresponding to each function. The intermediate representation (IR) and metadata are then combined to encapsulate the intermediate analysis representation result.
3. The method for extracting communication protocol format and interaction mode based on binary reverse engineering according to claim 1, characterized in that: Step B includes the following steps B1 to B3; Step B1. Extract the function call graph from the intermediate analysis representation results. Using each network communication sending function as the retrieval anchor point, perform backward slicing across functions and procedures in the intermediate representation IR. That is, starting from the target sending buffer pointed to by the buffer pointer parameter of the retrieval anchor point, trace the data flow of each byte in the buffer backward along the data dependency relationship until it is determined that the source of each byte of data can be traced back to one of the three types of endpoints: function parameters, global variables, and return values. This constitutes the complete data dependency path corresponding to the network communication sending function. Step B2. Based on all data dependency paths corresponding to each network communication sending function, construct a data flow graph (DFG) for each network communication sending function. Each node in the DFG corresponds to a data operation point, and each node records the program location identifier, operation type, memory offset, and data width. Step B3. Based on the data flow graph (DFG) corresponding to each network communication sending function, generate a deterministic constraint table for each node in the DFG, thereby obtaining the deterministic constraint table corresponding to each network communication sending function.
4. The method for extracting communication protocol format and interaction mode based on binary reverse engineering according to claim 3, characterized in that: In step B1, if the intermediate representation IR is an intermediate representation IR structure graph, the IR node corresponding to the retrieval anchor point is used as the operation unit. The data dependency edge of the IR node is traversed in reverse. When a function call instruction is encountered, the function call graph is reversed to enter the IR node subgraph of the called function to continue tracing, thereby realizing reverse tracing. If the intermediate representation IR is IL bytecode, the IL instruction corresponding to the retrieval anchor point in the IL bytecode is used as the operation unit. The data dependency edge of the IL instruction is traversed in reverse. When a method call instruction is encountered, the IL instruction sequence of the called function is entered in reverse along the function call graph to continue tracing, thus realizing reverse tracing.
5. The method for extracting communication protocol format and interaction mode based on binary reverse engineering according to claim 1, characterized in that: Step C includes the following steps C1 to C3; Step C1. Based on the data flow graph (DFG) and deterministic constraint table of each network communication sending function, construct structured prompt words, and infer the semantic labels and encoding logic of the fields through a neural network semantic inference model, and output a list of field definitions; Step C2. For each field definition list, perform cross-validation and conflict backtracking correction, update the field definition list, and obtain a list of conflict-free field definitions. Step C3. If the target binary file is compiled as native code, then the list of non-conflicting field definitions is merged according to the positional relationship of their corresponding target send buffers in the actual protocol to form the field template of the target communication program; If the target binary file is compiled as managed code, then the list of conflict-free field definitions directly constitutes the field template of the target communication program.
6. The method for extracting communication protocol format and interaction mode based on binary reverse engineering according to claim 5, characterized in that: Step C1 includes the following steps C1a to C1c; Step C1a. If the target binary file is compiled as native code, proceed to step C1b; if the target binary file is compiled as managed code, proceed to step C1c. Step C1b. Based on the function call diagram of each network communication sending function in the intermediate analysis representation results, perform the following steps for each network communication sending function to obtain the field definition list corresponding to the network communication sending function; Based on the data flow graph (DFG) corresponding to the network communication sending function, instruction fragments corresponding to the IR nodes traversed by the DFG are extracted from the intermediate representation IR structure diagram to form code slices related to the construction of the communication buffer, and corresponding structured pseudocode text is obtained. At the same time, according to the deterministic constraint table corresponding to the network communication sending function, each constraint record in the deterministic constraint table is converted into a hard constraint array. The structured pseudocode text, the hard constraint array, and the candidate semantic list provided by the preset domain knowledge dictionary are jointly encapsulated into structured prompt words. The structured prompt words are input into the neural network semantic inference model to infer the semantic labels and encoding logic of the fields and output a list of field definitions. Step C1c. Using reflection or metadata parsing techniques, extract the field skeletons of protocol-related structures from the metadata representing the intermediate analysis results, construct explicit structure layout constraints, encapsulate the explicit structure layout constraints into structured prompts, and input them into a neural network semantic inference model. Within the boundaries of the explicit structure layout constraints, infer the semantic labels and encoding logic of the fields, and output a list of field definitions.
7. The method for extracting communication protocol format and interaction mode based on binary reverse engineering according to claim 5, characterized in that: Step C2 includes steps C2a to C2c; Step C2a. If the target binary file is compiled as native code, proceed to step C2b; if the target binary file is compiled as managed code, proceed to step C2c. Step C2b. For each field definition list, perform cross-validation and conflict backtracking correction as follows to obtain a conflict-free field definition list; Iterate through each field in the field definition list, extracting the offset and data width of the field from the field definition list. In the data flow graph (DFG) of the corresponding network communication sending function, query the memory access instruction sequence corresponding to the offset range. Obtain the actual data width and address range operated by the memory access instruction sequence, forming a memory access instruction range. Determine if the offset and data width of the field from the field definition list are consistent with the memory access instruction range. If they are, the field passes verification; otherwise, a field conflict is identified. This process is repeated for each field in the field definition list. Then, it is determined whether there are conflicting fields in the field definition list. If so, conflict backtracking correction is performed for each conflicting field to obtain a conflict-free field definition list; otherwise, the current field definition list is considered conflict-free. Step C2c. Execute the cross-validation algorithm and conflict backtracking correction. Iterate through each field in the field definition list and determine whether the offset and data width of the field from the field definition list are consistent with the field skeleton in the explicit structure layout constraints. If they are, the field is considered to have passed the validation; otherwise, the field is considered to be in conflict. Then, complete the validation of each field in the field definition list, and then determine whether there are conflicting fields in the field definition list. If there are, perform conflict backtracking correction for each conflicting field to obtain a conflict-free field definition list; otherwise, it is a conflict-free field definition list.
8. The method for extracting communication protocol format and interaction mode based on binary reverse engineering according to claim 7, characterized in that: In steps C2b and C2c, for each conflicting field, the following conflict backtracking correction is performed to update the field definition list, thereby obtaining a conflict-free field definition list. First, the conflict information of the field is written into the structured prompt words for updating. The input is the neural network semantic inference model, which outputs the semantic label and encoding logic of the field. Then, the cross-validation algorithm is executed again for the field. If the field is found to be valid, the semantic label and encoding logic of the field are updated to the field definition list. If the field is found to be conflicting, the inference result of the neural network semantic inference model is discarded, and the static rule matching result of the corresponding data flow graph (DFG) is used instead, and the field definition list is updated.
9. The method for extracting communication protocol format and interaction mode based on binary reverse engineering according to claim 1, characterized in that: Step D includes the following steps D1 to D3; Step D1. Based on the function call graph in the intermediate analysis results, for each network communication receiving function, using the network communication receiving function as the retrieval target, search the function call graph for all function call points pointing to the retrieval target, and mark them as anchor points of each receiving function, thus obtaining the anchor points of each receiving function corresponding to the network communication receiving function; further, for each receiving function anchor point, based on the function call graph, start from the function node corresponding to the receiving function anchor point and trace upwards along the reverse edge of the call, marking all functions that call the retrieval target network communication receiving function and contain data parsing logic as message parsing functions, and then proceed to step D2; Step D2. Based on the fact that each network communication receiving function corresponds to a receiving function anchor point, and each receiving function anchor point corresponds to a message parsing function, execute steps D2-1 to D2-3 for each message parsing function to obtain the complete state transition table of the single function corresponding to the message parsing function, and then proceed to step D3. Step D2-1. For the control flow graph corresponding to the message parsing function, a depth-first search is used to traverse each basic block in the control flow graph. First, the instruction sequence within the basic block is converted into pseudo-code statements in natural language to form the pseudo-code block corresponding to the basic block. Then, if the exit edge of the basic block is a conditional jump edge, the jump condition is converted into a conditional expression with logical operators, and the target basic block it points to is recorded. If the exit edge of the basic block is a cross-function call edge, the cross-function call edge is converted into a text description form, and the entry basic block of the called function it points to is recorded. Finally, the corresponding indentation level is added according to the current nesting depth. After traversing each basic block in the control flow graph, the structured execution trajectory text corresponding to the tree structure of the message parsing function is obtained; Step D2-2. Input the structured execution trajectory text corresponding to the message parsing function into the neural network semantic inference model. The neural network semantic inference model identifies the values of the message type fields that trigger different processing branches based on the causal relationship of the code logic, and maps them to protocol state nodes. And map the branch conditions to labeled state transition edges, where the transition edge label contains the condition expression and the corresponding message field name, and then output the corresponding state transition table. Step D2-3. Use a neural network semantic inference model to perform semantic reasoning on the abnormal handling branches or specific magic number verification branches in the structured execution trajectory text that are not triggered by regular traffic, complete the hidden states or backdoor maintenance paths not exposed in the protocol specification, and merge the completed hidden state transition edges into the state transition table to form a single-function complete state transition table corresponding to the message parsing function. Step D3. Based on the fact that each network communication receiving function corresponds to a receiving function anchor point, firstly, for each receiving function anchor point, merge the single-function complete state transition tables of each message parsing function corresponding to the receiving function anchor point to form the anchor point complete state transition table corresponding to the receiving function anchor point. Then, for each network communication receiving function, the complete state transition tables of the anchor points of each receiving function corresponding to the network communication receiving function are merged to form the protocol state transition table corresponding to the network communication receiving function. Then, the protocol state transition tables corresponding to each network communication receiving function are merged to obtain the protocol state machine of the target communication program; During the merging process, if there are shared state nodes between the two state transition tables, then the shared nodes are merged. If the two state transition tables are completely independent, they are retained as parallel branches.
10. The method for extracting communication protocol format and interaction mode based on binary reverse engineering according to claim 1, characterized in that: Step E includes the following steps E1 to E3; Step E1. Input the field template and protocol state machine of the target communication program into the neural network semantic inference model and perform cross-consistency verification. This includes extracting the conditional expression of each state transition edge in the protocol state machine, parsing out the field names and expected values involved, and searching for the field definition corresponding to the field name in the field template. If the field name does not exist in the field template, or the offset, data width, or data type of the field name is inconsistent with the implicit constraints in the state transition edge, then the verification item is marked as an inconsistency item. Then, the neural network semantic inference model outputs the marked field template and protocol state machine, as well as the list of marked inconsistencies. If the list of inconsistencies is not empty, proceed to step E2. If the list of inconsistencies is empty, then the field template and protocol state machine corresponding to the target communication program remain unchanged; Step E2. For each inconsistency in the inconsistency list, first check the data flow graph (DFG) and control flow graph corresponding to each network communication sending function, and then proceed to step E3. If the inconsistency stems from a semantic reasoning error in step D, then the corresponding state transition condition in the protocol state machine must be corrected to be consistent with the static data flow conclusion in the corresponding data flow graph. If the inconsistency stems from a missing field in step C, then backtrack to step C and add the missing field to the field template. Step E3. Input the field template and protocol state machine corrected in step E2 back into the neural network semantic inference model, and repeat the verification and correction process from step E1 to E2 until the list of inconsistencies output by the neural network semantic inference model is empty. Then output the corrected field template and protocol state machine and update it to the field template and protocol state machine corresponding to the target communication program.
