Disassembling method and device, electronic equipment and readable medium

By matching machine instructions and conversion rules in the target code, intermediate representation instructions are generated, which solves the problem of being unable to analyze intermediate representation instructions in the existing technology and reduces the difficulty of disassembly analysis.

CN118778969APending Publication Date: 2024-10-15LOONGSON ZHONGKE (XIAN) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410814975.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-21
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

In the existing technology, the intermediate representation instructions of the target code cannot be directly viewed and analyzed during the disassembly process, resulting in high difficulty in analyzing the disassembly results.

Method used

By reading the machine instructions in the target code, matching the conversion rules of the target compiler with predefined candidates, generating corresponding intermediate representation instructions, and outputting the disassembly results, allowing technicians to analyze the intermediate representation instructions.

Benefits of technology

It reduces the difficulty of analyzing disassembly results, enables technicians to more intuitively understand and analyze the intermediate representation instructions of the target code, and improves analysis efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118778969A_ABST
    Figure CN118778969A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a disassembling method and device, electronic equipment and a readable medium, and relates to the technical field of computers, in the method, a target code generated by a target compiler is read, and an instruction object of a machine instruction in the target code is recognized. And based on a conversion rule corresponding to the target compiler, matching the instruction object with a predefined candidate object in the conversion rule to obtain a target rule corresponding to the instruction object. Generating an intermediate representation instruction corresponding to the target rule according to the target rule and the machine instruction; wherein the conversion rules are used for representing conditions met by instruction objects corresponding to various intermediate representation instructions; the instruction objects corresponding to the various intermediate representation instructions are obtained by converting the various intermediate representation instructions. And outputting a disassembling result based on the generated intermediate representation instruction. Therefore, the analysis difficulty of the disassembling result can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a disassembly method, device, electronic device and readable medium. Background Art

[0002] At present, when a compiler processes a source program, it converts the source program into an intermediate representation, and then assembles the intermediate representation into machine instructions to obtain the target code. Accordingly, a decompiler can be used to disassemble the program, so as to perform operations such as analyzing or debugging the program based on the disassembly result.

[0003] In the prior art, when disassembling, the machine instructions in the target code are converted into assembly code as the disassembly result, but the intermediate representation instructions of the target code cannot be found in the assembly code, and the technicians cannot analyze the intermediate representation instructions, resulting in high difficulty in analyzing the disassembly result. Summary of the invention

[0004] The embodiments of the present invention provide a disassembly method, device, electronic device and readable medium, which can reduce the difficulty of analyzing the disassembly result.

[0005] In order to solve the above problem, an embodiment of the present invention discloses a disassembly method, which includes:

[0006] Reading the target code generated by the target compiler and identifying the instruction object of the machine instruction in the target code;

[0007] Based on the conversion rules corresponding to the target compiler, the instruction objects are matched with the candidate objects predefined in the conversion rules respectively to obtain the target rules corresponding to the instruction objects; according to the target rules and the machine instructions, an intermediate representation instruction corresponding to the target rules is generated; wherein the conversion rules are used to characterize the conditions satisfied by the instruction objects corresponding to various intermediate representation instructions; the instruction objects corresponding to various intermediate representation instructions are obtained by converting various intermediate representation instructions;

[0008] Based on the generated intermediate representation instructions, a disassembly result is output.

[0009] On the other hand, an embodiment of the present invention discloses a disassembly device, the device comprising:

[0010] An identification module, used for reading the target code generated by the target compiler and identifying the instruction object of the machine instruction in the target code;

[0011] A matching module, for matching the instruction object with the candidate objects predefined in the conversion rule based on the conversion rule corresponding to the target compiler, to obtain the target rule corresponding to the instruction object;

[0012] A generation module, configured to generate an intermediate representation instruction corresponding to the target rule according to the target rule and the machine instruction; wherein the conversion rule is used to characterize the conditions satisfied by the instruction objects corresponding to each type of intermediate representation instruction; and the instruction objects corresponding to each type of intermediate representation instruction are obtained by converting the various types of intermediate representation instructions;

[0013] An output module is used to output a disassembly result based on the generated intermediate representation instruction.

[0014] On the other hand, an embodiment of the present invention discloses an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the aforementioned method.

[0015] The embodiment of the present invention further discloses a machine-readable medium on which instructions are stored. When executed by one or more processors, the processors are enabled to execute the method described above.

[0016] The embodiment of the present invention includes the following advantages: In the disassembly method provided in the embodiment of the present invention, the target code generated by the target compiler is read, and the instruction object of the machine instruction in the target code is identified. Based on the conversion rule corresponding to the target compiler, the instruction object is matched with the candidate objects predefined in the conversion rule respectively, and the target rule corresponding to the instruction object is obtained. According to the target rule and the machine instruction, an intermediate representation instruction corresponding to the target rule is generated; wherein the conversion rule is used to characterize the conditions satisfied by the instruction object corresponding to each intermediate representation instruction; the instruction object corresponding to each intermediate representation instruction is obtained by converting the intermediate representation instruction. Based on the generated intermediate representation instruction, the disassembly result is output. In this way, the instruction object of the machine instruction in the target code and the preset target compiler are matched, the intermediate representation instruction corresponding to the machine instruction is generated, and then the disassembly result is output, so that the technician can analyze the output intermediate representation instruction, thereby reducing the difficulty of analyzing the disassembly result. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0018] Figure 1It is a flowchart of the steps of a disassembly method provided by an embodiment of the present invention;

[0019] Figure 2 It is a schematic diagram of a processing flow provided by an embodiment of the present invention;

[0020] Figure 3 is a block diagram of a disassembly device provided by an embodiment of the present invention;

[0021] Figure 4 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0022] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0023] At present, the compilation process of software source program to executable file is composed of a series of steps, and each step has a corresponding tool. These tools can work together in a specific order, and the output of the previous tool is used as the input of the following tool during specific work. Since this compilation process is like a chain, this series of tools is called a compilation tool chain. Compilers, linkers, and disassemblers for processing binary files obtained after compilation, etc., all belong to tools in the compilation tool chain. An embodiment of the present invention can be a disassembly method provided for a disassembler therein.

[0024] The disassembly method provided in the embodiment of the present invention can also be implemented in the form of a separate disassembly program, or can also be added as a disassembly function to existing debuggers, disassemblers and other tools. In this way, the disassembly method can have wide applicability.

[0025] Reference Figure 1 , shows a flow chart of steps of a disassembly method provided by an embodiment of the present invention, such as Figure 1 As shown, the processing method may specifically include the following steps:

[0026] Step 101: read the target code generated by the target compiler, and identify the instruction object of the machine instruction in the target code.

[0027] Step 102: Based on the conversion rules corresponding to the target compiler, the instruction objects are matched with the candidate objects predefined in the conversion rules respectively to obtain the target rules corresponding to the instruction objects.

[0028] Step 103: Generate an intermediate representation instruction corresponding to the target rule according to the target rule and the machine instruction; wherein the conversion rule is used to characterize the conditions satisfied by the instruction objects corresponding to each type of intermediate representation instruction; the instruction objects corresponding to each type of intermediate representation instruction are obtained by converting the various types of intermediate representation instructions.

[0029] Step 104: output a disassembly result based on the generated intermediate representation instruction.

[0030] With respect to the above steps 101 to 104, in the embodiment of the present invention, the target code refers to the code in the executable file obtained by compiling the source program. The target code may be the target code that needs to be disassembled. Specifically, the target code for which the intermediate representation needs to be known may be selected for processing as needed. The disassembly method may be applied to debuggers, disassemblers, electronic devices, and the like.

[0031] The target code can be stored in a specific format. For example, when the operating system of the electronic device is a Linux system, the target code can be stored in an ELF format. When the operating system of the electronic device is a Windows system, the target code can be stored in a PE format. When reading the target code, the starting and ending positions of the machine instructions in the target code can be found according to the format rules of the target code. Based on the starting and ending positions, the file length of the entire file of the target code is determined, and then a byte array of the same size is created accordingly, and all the machine instructions read are stored in the byte array. The byte array stores all the machine instructions in the target code. It should be noted that for the convenience of processing, the machine instructions represented in binary can be represented in hexadecimal, that is, the hexadecimal instruction encoding of each machine instruction in the target code is stored in the byte array, and the machine instructions in the byte array are specifically machine instructions represented in hexadecimal.

[0032] Next, the byte array can be traversed, a machine instruction can be read from the byte array, and the machine instruction can be decoded to determine the specified object of the machine instruction. Among them, the instruction objects of different machine instructions can be different, and the instruction object can represent the constituent elements of the machine instruction. Specifically, the instruction object can include the operation code and operand of the machine instruction. Among them, the operation code is the part of the instruction used to specify what operation is performed. The operand is the source or target of the operation data specified in the instruction. The type of the operand (for example, an immediate value, a register or a memory address) and their specific value or position can be known through decoding. Specifically, since the assembly instruction corresponds to the machine instruction one by one, there is no one-to-many correspondence, and the operation code of the assembly instruction is usually a mnemonic, wherein the mnemonic can be a simplified form of an English word or abbreviation, used to represent a specific machine operation. The operation code of the machine instruction is a string of numbers in binary form, which are the parts directly interpreted and executed by the CPU. Therefore, for the convenience of processing, the operation code in the instruction object of the machine instruction can be the operation code in the assembly instruction obtained by decoding the machine instruction, that is, the operation code represented at the assembler level. Accordingly, the operands in the instruction object of the machine instruction may be operands in the assembly instruction obtained by decoding the machine instruction, that is, operands represented at the assembler level. It should be noted that the abstraction levels of codes at different levels and the degree of association with hardware are different. Therefore, codes at different levels have their own sets of opcodes. The assembly instruction converted from an intermediate representation instruction and the machine instruction converted from the assembly instruction have different representations. Accordingly, the opcode of the intermediate representation instruction, the opcode of the assembly instruction and the opcode of the machine instruction are different. Similarly, the representation of the operands is also different.

[0033] Optionally, the intermediate representation involved in the embodiment of the present invention may be an intermediate code representation (Intermediate Code Representation, IR) or a low-level intermediate code representation (Low-Level Intermediate Code Representation, LLIR). Among them, LLIR may be defined by a specific compiler. Correspondingly, the above intermediate representation instructions may be intermediate code representation instructions (IR instructions) or low-level intermediate code representation instructions (LLIR instructions). Among them, IR is a key concept in compiler design. It is an intermediate form used in the compiler and an intermediate form of code generated during the compilation process, between the source code and the target code. IR can provide an abstract level that is convenient for the compiler to perform optimization and code generation. LLIR is another intermediate form used in the compiler, which is closer to machine code than IR. LLIR can provide sufficient information for the back end of the compiler to perform effective code generation and optimization, and LLIR still maintains a certain degree of abstraction to facilitate porting and maintenance across architectures.

[0034] The process of modern compilers processing source programs can be roughly summarized into the following basic processes: source program parsing stage, intermediate code generation stage, target code generation stage, and the final linking stage. The intermediate code generation stage can generate IR based on the source program, and the main work in the target code generation stage is to convert IR into machine instructions. This conversion process may be completed in one pass or multiple passes, and the specific method is determined by the compiler. Different compilers may have different processing methods. In the process of assembling IR into machine instructions, some compilers directly assemble IR to generate machine instructions. Some compilers will first convert IR into LLIR related to the computer instruction set and architecture, and then assemble LLIR to generate machine instructions.

[0035] The intermediate representation instruction may be an instruction constituting the intermediate representation. For example, when the intermediate representation is IR, the intermediate representation instruction may be an IR instruction, and when the intermediate representation is LLIR, the intermediate representation instruction may be an LLIR instruction. When IR or LLIR generates machine instructions, there is a one-to-many situation, that is, in the compilation stage, an IR instruction or LLIR instruction may be assembled into multiple machine instructions. For example, in the process of LLIR assembly generating machine instructions, for LLIR instructions with relatively simple functions, they may be assembled into one machine instruction, while for LLIR instructions with relatively complex functions, they need to be assembled into multiple machine instructions to realize their semantics. Therefore, when disassembling, when generating the intermediate representation instruction corresponding to the machine instruction in the target code, there may be a situation where one intermediate representation instruction is generated for one machine instruction, and one intermediate representation instruction is generated for multiple machine instructions. Accordingly, the number of intermediate representation instructions finally generated may be less than or equal to the number of machine instructions included in the target code.

[0036] Furthermore, due to the differences in the compilation methods of different compilers, that is, different compilers have different ways of assembling the intermediate representation into machine instructions after converting the source program into the intermediate representation. Accordingly, after different compilers convert the same intermediate representation instructions into machine instructions, the characteristics of the instruction objects of the converted machine instructions may be different. Therefore, in the embodiment of the present invention, disassembly can be performed based on the conversion rules corresponding to the target compiler that generates the target code to ensure the accuracy of the disassembly result.

[0037] Among them, the conversion rules corresponding to the target compiler can be pre-configured. For example, the conversion rules input by the user can be received and stored in the electronic device, or the pre-configured conversion rules can be loaded from a specified location. There can be multiple conversion rules, and one conversion rule can correspond to a class of intermediate representation instructions. For any conversion rule, the candidate objects predefined in this type of conversion rule can be the characteristics possessed by the instruction object of the machine instruction converted by the intermediate representation instruction corresponding to this type of conversion rule. For the machine instruction, if the instruction object of the machine instruction matches the candidate object predefined in a certain conversion rule, that is, the instruction object of the machine instruction has the characteristics possessed by the instruction object corresponding to the intermediate representation instruction corresponding to this type of conversion rule, it means that the machine instruction is converted by the intermediate representation instruction. Therefore, the conversion rule can be determined as the target rule corresponding to the instruction object, so as to disassemble the machine instruction into the intermediate representation instruction corresponding to the matching target rule. Further, after obtaining the intermediate representation instructions corresponding to each machine instruction in the target code, these intermediate representation instructions can be output as disassembly results.

[0038] In summary, in the disassembly method provided in the embodiment of the present invention, the target code generated by the target compiler is read, and the instruction object of the machine instruction in the target code is identified. Based on the conversion rule corresponding to the target compiler, the instruction object is matched with the candidate object predefined in the conversion rule respectively to obtain the target rule corresponding to the instruction object. According to the target rule and the machine instruction, an intermediate representation instruction corresponding to the target rule is generated; wherein the conversion rule is used to characterize the conditions satisfied by the instruction object corresponding to each intermediate representation instruction; the instruction object corresponding to each intermediate representation instruction is obtained by converting each intermediate representation instruction. Based on the generated intermediate representation instruction, the disassembly result is output. In this way, based on the instruction object of the machine instruction in the target code and the preset target compiler, the intermediate representation instruction corresponding to the machine instruction is generated by matching, and based on the intermediate representation instruction generated for the target code, the disassembly result is output, so that the user can view the intermediate representation of the target code, so that the technician can analyze the intermediate representation, thereby reducing the difficulty of analyzing the disassembly result to a certain extent.

[0039] Among them, the conversion rules corresponding to the target compiler may include multiple conversion rules, and one conversion rule may correspond to one type of intermediate representation instruction. For any type of intermediate representation instruction, the characteristics of the instruction object of the machine instruction converted by the target compiler from the intermediate representation instruction of this type may be counted in advance. Among them, the characteristics may describe the conditions that the operation code and operand of the instruction object of the machine instruction converted from the intermediate representation instruction of this type meet. Accordingly, for a type of intermediate representation instruction, a corresponding conversion rule may be generated, and the conversion rule may characterize the characteristics of the instruction object corresponding to the intermediate representation instruction of this type. The instruction object corresponding to the intermediate representation instruction of this type is the instruction object of the machine instruction converted from the intermediate representation instruction of this type. Among them, the intermediate representation instructions of the same type share operational semantics, that is, they perform the same type of operation and have the same instruction opcode. And the operand representation method used by the intermediate representation instructions of the same type is the same. Specifically, the type of operands (for example, registers, virtual registers, immediate numbers or memory addresses, etc.) and the number of operands used by the intermediate representation instructions of the same type may be the same.

[0040] Specifically, each machine instruction can be traversed, and for the traversed machine instruction, the instruction object is matched with each conversion rule in the conversion rule. If the instruction object of the machine instruction matches the predefined candidate object in the conversion rule, the conversion rule can be determined as the target rule.

[0041] Optionally, the step of generating an intermediate representation instruction corresponding to the target rule according to the target rule and the machine instruction may specifically include:

[0042] Step 1031: If the instruction quantity parameter is not defined in the target rule, convert the machine instruction into an intermediate representation instruction corresponding to the target rule.

[0043] Step 1032: Otherwise, convert the machine instruction and the associated machine instructions into intermediate representation instructions corresponding to the target rule; the associated machine instructions include other machine instructions in the target code that are associated with the machine instruction.

[0044] In the embodiment of the present invention, the instruction quantity parameter may be set when at least two machine instructions are obtained after the intermediate representation instruction corresponding to the conversion rule is assembled. That is, if the intermediate representation instruction and the machine instruction are in a one-to-one relationship, then the instruction quantity parameter may not be included in the conversion rule corresponding to the intermediate representation instruction. In this way, the number of parameters set in the conversion rule can be minimized, thereby simplifying the conversion rule.

[0045] If the target rule does not define the instruction quantity parameter, it can be determined that the currently traversed machine instruction can be disassembled separately, so the operation of converting the machine instruction into the intermediate representation instruction corresponding to the target rule can be performed. If the intermediate representation instruction and the machine instruction are in a one-to-many relationship, the conversion rule corresponding to the intermediate representation instruction of this type can include the instruction quantity parameter. Among them, the number represented by the instruction quantity parameter can represent the specific number of multiple machine instructions converted by the intermediate representation instruction of this type. Correspondingly, if the instruction quantity parameter is defined in the target rule, it can be determined that the currently traversed machine instruction cannot be disassembled separately, and needs to be disassembled together with other machine instructions in the target code. Therefore, the operation of converting the machine instruction and the associated machine instruction into the intermediate representation instruction corresponding to the target rule can be performed. Among them, the associated machine instruction can be a machine instruction in the target code that is assembled from the same intermediate representation instruction as the currently traversed machine instruction. That is to say, if a machine instruction in the target code and the currently traversed machine instruction are assembled from the same intermediate representation instruction, then it can be considered that they have an associated relationship. It should be noted that converting the machine instruction into the intermediate representation instruction corresponding to the target rule can be based on the instruction object of the machine instruction to disassemble and generate the intermediate representation instruction corresponding to the machine instruction. Converting the machine instruction and the associated machine instruction into the intermediate representation instruction corresponding to the target rule may be based on disassembling the instruction object of the machine instruction and the instruction object of the associated machine instruction to generate the intermediate representation instruction corresponding to the machine instruction.

[0046] Of course, during specific implementation, when the intermediate representation instruction and the machine instruction are in a one-to-one relationship, an instruction quantity parameter may be set in the conversion rule corresponding to the intermediate representation instruction of this type. Accordingly, when the number represented by the instruction quantity parameter defined in the target rule is less than 2, the operation of converting the machine instruction into the intermediate representation instruction corresponding to the target rule may be performed. When the number represented by the instruction quantity parameter defined in the target rule is not less than 2, the operation of converting the machine instruction and the associated machine instruction into the intermediate representation instruction corresponding to the target rule may be performed. The embodiment of the present invention does not limit this.

[0047] In an embodiment of the present invention, when the instruction quantity parameter is not defined in the target rule, the machine instruction is converted into an intermediate representation instruction corresponding to the target rule. When the instruction quantity parameter is defined in the target rule, the machine instruction and the associated machine instruction are converted into an intermediate representation instruction corresponding to the target rule; the associated machine instruction includes other machine instructions associated with the machine instruction in the target code. In this way, the conversion is carried out in a targeted manner corresponding to different situations, which can ensure the accuracy of the intermediate representation instruction obtained by disassembly to a certain extent.

[0048] Optionally, in the embodiment of the present invention, the step of matching the instruction object with the candidate objects predefined in the conversion rule to obtain the target rule corresponding to the instruction object may specifically include:

[0049] Step 1021: Match the operation code in the instruction object with the operation code predefined in each of the conversion rules, and use the conversion rule consistent with the operation code in the instruction object as an alternative rule.

[0050] Step 1022: Match the operands in the instruction object with the operand conditions defined in each of the candidate rules, and determine the candidate rule corresponding to the operand condition that the operand in the instruction object meets as the target rule.

[0051] In an embodiment of the present invention, a conversion rule may characterize the characteristics possessed by an instruction object corresponding to the corresponding intermediate representation instruction of the corresponding type. Specifically, the characteristics may include the operation code, the type and number of operands corresponding to the machine instruction converted from the intermediate representation instruction of the corresponding type. Accordingly, the operation code defined in the conversion rule may be the operation code corresponding to the machine instruction converted from the intermediate representation instruction corresponding to the conversion rule. Among them, the machine instructions converted from the same type of intermediate representation instructions have the same operation code. The operand conditions defined in the conversion rule may include the number, type and conditions satisfied by the operands. For any conversion rule, the candidate objects predefined in the conversion rule are the operation codes and operand conditions predefined in the conversion rule. If the operation code of a machine instruction is the same as the operation code defined in a conversion rule, and the operands meet the operand conditions defined in the conversion rule, the instruction object of the machine instruction can be determined to meet the conditions satisfied by the instruction object corresponding to the intermediate representation instruction of the corresponding type of the conversion rule.

[0052] Specifically, the opcode in the instruction object of the machine instruction traversed this time can be matched with the opcode defined in each conversion rule. If the opcode in the instruction object of the machine instruction is consistent with the opcode defined in the conversion rule, the conversion rule can be determined as an alternative rule. Among them, the hit alternative rule can be one or more. Further, the operand in the instruction object can be matched with the operand condition defined in each conversion rule. If the operation data in the instruction object meets the operand condition defined in the alternative rule, it can be determined that the two match, and then the alternative rule can be determined as the target rule.

[0053] Exemplarily, in one example, for LLIR instructions, the conversion rules may include:

[0054] Conversion rule 1 corresponding to the intermediate representation instruction of the MOVM type: the operation code is sll.w, and the operand condition is: rk=r0.

[0055] Conversion rule 2 corresponding to the intermediate representation instruction of SLL XY type: the operation code is sll.w, and the operand conditions are: rk≠r0 and rd==rj. Among them, XY represents two operands respectively.

[0056] Conversion rule 3 corresponding to the intermediate representation instruction of SLL XYZ type: the operation code is sll.w, and the operand conditions are: rk≠r0 and rd≠rj. Among them, XYZ represent three operands respectively.

[0057] Conversion rule 4 corresponding to the intermediate representation instruction of MOVB type: the operation code is lu12i.w, the operand condition is: rd==r30, the instruction quantity parameter = 3. Alternatively, the conversion rule 4 corresponding to the intermediate representation instruction of MOVB type can also be expressed as: the operation code is lu12i.w, the operand condition is: rd==r30, the instruction quantity parameter = 3, and the associated instruction operation codes are: add.d, ld.b.

[0058] Among them, rk represents the source register, rd represents the destination register, and rj represents the jump register or the immediate value. r0 and r30 may be special registers in the general registers, that is, registers with special purposes. Exemplarily, in one architecture, there may be 32 general registers, recorded as r0 to r31.

[0059] Accordingly, assuming that the opcode in the instruction object of the currently traversed machine instruction is sll.w, then conversion rule 1, conversion rule 2, and conversion rule 3 can be determined as candidate rules. Assuming that the operands in the instruction object of the currently traversed machine instruction are: rd=r5, rj=r5, rk=r4. Since rd==rj, and the values ​​are both r5, rk≠r0. Therefore, conversion rule 2 can be determined as the target rule.

[0060] In an embodiment of the present invention, target rules are gradually matched from conversion rules based on the opcodes and operands in the instruction object of the machine instruction, which can ensure that the features represented by the target rules match the opcodes and operands in the instruction object of the machine instruction, thereby ensuring the accuracy of the acquired target rules to a certain extent.

[0061] Optionally, when the instruction quantity parameter is defined in the target rule, the following steps may also be performed in the embodiment of the present invention:

[0062] Step S21, storing the machine instructions into a first array.

[0063] Step S22, continue processing the next machine instruction in the target code, and when the target instruction quantity does not match the preset quantity, and the target rule hit by the next machine instruction is the same as the target rule hit by the machine instruction, add the next machine instruction to the first array until the last associated machine instruction is processed; the first array is used to store machine instructions with an associated relationship.

[0064] Accordingly, the step of converting the machine instruction and the associated machine instruction into an intermediate representation instruction corresponding to the target rule may specifically include:

[0065] Step 1032A: When the target instruction quantity matches the preset quantity, convert the next machine instruction and the machine instructions stored in the first array into intermediate representation instructions corresponding to the target rule to obtain the intermediate representation instructions corresponding to the machine instruction and the associated machine instructions; the target instruction quantity is the total quantity of the next machine instruction and the machine instructions stored in the first array.

[0066] After converting the machine instructions and the machine instructions in the first array into intermediate representation instructions corresponding to the target rule, the following may be performed: Step S31 , clearing the first array.

[0067] In the embodiment of the present invention, the first array may be a pre-created dynamic array. Specifically, a dynamic array may be created as the first array before step 102. When the machine instruction is stored in the first array, it may be stored in the form of an instruction object, that is, the instruction object of the machine instruction may be stored in the first array. Furthermore, during the compilation process, multiple machine instructions obtained by assembling an intermediate representation instruction will be stored continuously.

[0068] Therefore, in the embodiment of the present invention, when other machine instructions belong to the M machine instructions stored continuously with the machine instruction (the machine instruction processed in step S21), it can be determined that the target rule hit by the other machine instructions is the same as the target rule hit by the machine instruction, and the other machine instructions are determined as associated machine instructions. Wherein, M is equal to N-1, N represents the number represented by the instruction quantity parameter, that is, N represents the preset number. In other words, the M machine instructions stored continuously with the machine instruction are assembled from the same intermediate representation instruction as the machine instruction. Wherein, the machine instructions in the target code can be stored in sequence according to the order of generation, and the associated machine instructions can be the M machine instructions stored continuously after the machine instruction. Accordingly, when the next machine instruction to be processed belongs to these M machine instructions, it can be determined that the target rule hit by the next machine instruction to be processed is the same as the target rule hit by the machine instruction.

[0069] When traversing to these M machine instructions, if the number of machine instructions in the first array plus the number of the next machine instruction currently being processed (i.e., the machine instruction currently being processed) does not reach N, that is, the number of machine instructions in the first array + 1 is not N, then it can be determined that all associated machine instructions have not yet been searched. Therefore, the next machine instruction currently being processed can be added to the first array, and the next machine instruction can be processed. If the number of machine instructions in the first array this time + 1 is N, then it can be determined that the next machine instruction currently being processed (referring to the machine instruction participating in this traversal) is the last associated machine instruction among these M machine instructions, that is, the number of machine instructions in the first array and the total number of machine instructions currently being processed are equal to N, and the machine instructions stored in the first array and the machine instructions currently being processed can be combined to disassemble into an intermediate representation instruction. The machine instructions stored in the first array and the machine instructions currently being processed are the machine instructions in step S21 and their associated machine instructions. Then, the machine instruction currently being processed and all the machine instructions in the first array can be combined and converted into an intermediate representation instruction corresponding to the target rule. The target instruction number is the total number of the currently processed machine instructions and the machine instructions stored in the first array, that is, the target instruction number is the number of machine instructions stored in the first array + 1. Similarly, when adding the next machine instruction to the first array, it can be stored in the form of an instruction object, that is, the instruction objects of other instructions can be added to the first array.

[0070] In an embodiment of the present invention, before determining the target rule hit by the machine instruction, it is also possible to first determine whether the first array is empty. The first array is used to store machine instructions of other machine instructions assembled from the same intermediate representation instruction. If it is not empty, it means that the machine instruction cannot be directly disassembled into an intermediate representation instruction. Then, it can be determined whether the machine instruction currently being processed and the machine instructions in the first array can be combined and disassembled into an intermediate representation instruction. If they can be combined and disassembled into an intermediate representation instruction (that is, the number of machine instructions stored in the first array + 1 is equal to N), the machine instructions stored in the first array and the machine instruction are disassembled into an intermediate representation instruction, and the first array is cleared. Specifically, the clearing operation can be performed before or after the disassembly. If they cannot be combined and disassembled into an intermediate representation instruction (that is, the number of machine instructions stored in the first array + 1 is not equal to N), the machine instruction currently being processed is added to the first array, and the next machine instruction is traversed. If it is empty, it means that the machine instruction currently being processed may be directly disassembled into an intermediate representation instruction, or it may not be directly disassembled into an intermediate representation instruction. Therefore, when it is empty, the target rule hit by the currently processed machine instruction can be determined. When the instruction quantity parameter is not defined in the target rule, the currently processed machine instruction is converted into an intermediate representation instruction corresponding to the target rule. When the instruction quantity parameter is defined in the target rule, it is stored in the first array and the next machine instruction is processed.

[0071] It should be noted that, in the conversion rule defined with the instruction quantity parameter, the opcodes of all machine instructions obtained by assembling the intermediate representation instructions corresponding to the conversion rule may be defined. Accordingly, when the next machine instruction to be processed belongs to M machine instructions stored continuously, and the opcode of the next machine instruction to be processed is defined in the target rule hit by the machine instruction, it can be determined that the target rule hit by the machine instruction is the same as the target rule hit by the machine instruction.

[0072] In an embodiment of the present invention, by storing machine instructions into a first array and combining the number of machine instructions stored in the first array with the total number of machine instructions currently being processed, it is possible to quickly determine whether the machine instruction currently being processed is the last associated machine instruction, whether the machine instruction currently being processed and the machine instructions in the first array can be disassembled into an intermediate representation instruction, and when they can be disassembled into an intermediate representation instruction, the machine instruction currently being processed and the machine instructions in the first array are converted into intermediate representation instructions, thereby ensuring processing efficiency to a certain extent.

[0073] It should be noted that, in one implementation, the machine instructions may be stored in a first array, and then other machine instructions in the target code that hit the same target rule as the target rule hit by the machine instructions are added to the first array; accordingly, the converting of the machine instructions and associated machine instructions into intermediate representation instructions corresponding to the target rule includes: when the number of machine instructions stored in the first array matches the number represented by the instruction number parameter, converting all machine instructions in the first array into intermediate representation instructions corresponding to the target rule,

[0074] In this implementation, when the M machine instructions are traversed, the M machine instructions can be added to the first array in sequence. In this way, the associated machine instructions of the machine instructions can be obtained by directly reading the subsequent M machine instructions stored continuously, thereby ensuring the acquisition efficiency to a certain extent. Further, in the conversion rule defined with the instruction quantity parameter, the opcodes of all machine instructions assembled by the intermediate representation instructions corresponding to the conversion rule can be defined. Accordingly, for the M machine instructions stored continuously, the M machine instructions can be added to the first array when the opcodes in the instruction objects of these machine instructions exist in the target rule hit by the machine instruction, so as to ensure the accuracy of the associated machine instructions. Further, if the number of machine instructions stored in the first array is the same as the number represented by the instruction quantity parameter, it can be considered that the two match. Accordingly, it can be determined that the machine instructions stored in the first array can be combined to disassemble into an intermediate representation instruction, and the first array includes the machine instruction and all the associated machine instructions of the machine instruction, and then all the machine instructions in the first array can be converted into the intermediate representation instructions corresponding to the target rule, and the first array is cleared. On the contrary, in the process of adding machine instructions to the first array, if the number of machine instructions stored in the first array is different from the number represented by the instruction number parameter, it can be determined that the machine instructions stored in the first array cannot be combined to form an intermediate representation instruction. Therefore, the adding operation can continue to be performed. In this implementation, by creating a first array and storing machine instructions and associated machine instructions in the first array, it is possible to determine whether the timing of generating intermediate representation instructions for machine instructions and associated machine instructions has arrived by determining whether the number of machine instructions stored in the first array matches the number represented by the instruction number parameter, thereby simplifying the determination operation to a certain extent and improving the operation efficiency.

[0075] Accordingly, after converting the currently processed machine instruction and the machine instructions in the first array into intermediate representation instructions corresponding to the target rule, the first array can be cleared. Specifically, all the contents stored in the first array can be deleted. In this way, by clearing the first array, when new machine instructions with associated machine instructions appear in the future, the first array can continue to be used, avoiding the problem of residual data in the first array, thereby causing interference.

[0076] Optionally, the step of converting the machine instruction into an intermediate representation instruction corresponding to the target rule may specifically include:

[0077] Step 1031a: Use the intermediate representation opcode corresponding to the target rule as the first opcode, and generate a first operand that conforms to the operand format of the intermediate representation instruction based on the operand rule corresponding to the target rule and the operands in the instruction object.

[0078] Step 1031b: Generate a corresponding intermediate representation instruction for the machine instruction based on the first opcode and the first operand.

[0079] The intermediate representation opcode corresponding to the target rule refers to the opcode of the intermediate representation instruction corresponding to the target rule. The operand rule corresponding to the target rule can be preset according to the number, type and representation form of the operands included in the intermediate representation instruction corresponding to the target rule. The representation form can be used to represent the form in which the operand is expressed.

[0080] Specifically, for the case where the intermediate representation instruction and the machine instruction are one-to-one, the operand rule corresponding to the conversion rule can be used to indicate the operand type, arrangement method and representation form required to be extracted from the instruction object of the machine instruction. The operand rule corresponding to the conversion rule is determined according to the semantics of the machine instruction representation obtained by assembling the intermediate representation instruction corresponding to the conversion rule. The operand generated according to the operand rule is the first operand.

[0081] Exemplarily, for the above-mentioned conversion rule 2, the operand rule corresponding to the conversion rule 2 can be used to indicate the extraction of rk and rd in the instruction object, arranged in the order of rk, rd, and the operand is represented in the form of R*. Correspondingly, the generated first operand can be: R4, R5. For the above-mentioned conversion rule 3, the operand rule corresponding to the conversion rule 3 can be used to indicate the extraction of rk, rd and rj in the instruction object, arranged in the order of rk, rj, rd, and the operand is represented in the form of R*. Correspondingly, the generated first operand can be: R4, R5, R6.

[0082] Further, after obtaining the first operation code and the first operand, the first operation code and the first operand can be combined to obtain the intermediate representation instruction corresponding to the machine instruction. Exemplarily, assuming that the first operation code is: SLL, the corresponding target rule is a machine instruction of conversion rule two, which can be disassembled into the intermediate representation instruction: SLL R4, R5. The corresponding target rule is a machine instruction of conversion rule three, which can be disassembled into the intermediate representation instruction: SLL R4, R5, R6.

[0083] In the embodiment of the present invention, the intermediate representation operation code corresponding to the target rule is first used as the first operation code, and based on the operand rule corresponding to the target rule and the operand in the instruction object, a first operand conforming to the operand format of the intermediate representation instruction is generated. Then, based on the first operation code and the first operand, a corresponding intermediate representation instruction can be generated for the machine instruction. In this way, the generation efficiency of the intermediate representation instruction can be ensured to a certain extent.

[0084] Optionally, the step of converting the machine instruction and the associated machine instruction into an intermediate representation instruction corresponding to the target rule may specifically include:

[0085] Step 1032a, use the intermediate representation opcode corresponding to the target rule as the second opcode, and generate a second operand that conforms to the operand format of the intermediate representation instruction based on the operand rule corresponding to the target rule, the operands in the instruction object of the machine instruction, and the operands in the instruction object of the associated machine instruction.

[0086] Step 1032b: Generate corresponding intermediate representation instructions for the machine instruction and the associated machine instruction based on the second opcode and the second operand.

[0087] The explanation of the related concepts in the embodiments of the present invention can refer to the above related description, which will not be repeated here.

[0088] For the case where the intermediate representation instructions and machine instructions are one-to-many, the operand rule corresponding to the conversion rule can be used to indicate the operand type, arrangement and representation required to be extracted from the machine instruction and the instruction object associated with the machine instruction. The operand rule corresponding to the conversion rule is determined based on the semantics of the multiple machine instructions represented by the intermediate representation instructions corresponding to the conversion rule. The operand generated according to the operand rule is the second operand.

[0089] Exemplarily, for the above conversion rule four, the operand rule corresponding to conversion rule four can be used to indicate extracting rd from the machine instruction: lu12i.w, extracting rd from the associated machine instruction: ld.b, and extracting rk from the associated machine instruction: add.d, arranging in the order of rk+rd (rd in lu12i.w), rd (rd in ldb), and representing the operand in the form of R*. Assume that the machine instruction is: lu12i.w r30 16, and the associated machine instruction is: add.d r30 r30 r5; ld.b r4r30 0×0. rd in lu12i.w is the value of r30, and the value of r30 is obtained by the (16<<12) operation, and the value of r30 is 65536. rk=r4 is extracted in add.d, and rd=r4 in ldb. Accordingly, the generated second operand can be: 65536(R5), R4. Among them, 65536(R5) is the representation of R5+65536.

[0090] Further, after obtaining the second operation code and the second operand, the second operation code and the second operand can be combined to obtain the intermediate representation instruction corresponding to the machine instruction and its associated machine instruction. Exemplarily, assuming that the second operation code is: MOVB, the machine instruction corresponding to the target rule is conversion rule four and its associated machine instruction, which can be disassembled into the intermediate representation instruction: MOVB 65536 (R5), R4.

[0091] It should be noted that the above-mentioned conversion of the next machine instruction and the machine instructions in the first array into the intermediate representation instruction corresponding to the target rule may specifically be: using the intermediate representation opcode corresponding to the target rule as the second opcode, and generating a second operand that conforms to the operand format of the intermediate representation instruction based on the operand rule corresponding to the target rule, the operands in the currently processed machine instruction, and the operands in the instruction object of the machine instruction in the first array. Based on the second opcode and the second operand, a corresponding intermediate representation instruction is generated. The operand set consisting of the operands in the next machine instruction and the operands in the instruction object of the machine instruction in the first array is the same as the operand set consisting of the operands in the instruction object of the machine instruction and the operands in the instruction object of the associated machine instruction in step 1032a.

[0092] Further, in the case where the first array stores machine instructions and all associated machine instructions, the implementation method of converting all machine instructions in the first array into intermediate representation instructions corresponding to the target rule can refer to step 1032a-step 1032b. Exemplarily, the operation may include: using the intermediate representation opcode corresponding to the target rule as the second opcode, and converting the operands in the instruction objects of all machine instructions in the first array into second operands that conform to the operand format of the intermediate representation instruction according to the operand rule corresponding to the target rule; and generating corresponding intermediate representation instructions for the machine instruction and the associated machine instruction based on the second opcode and the second operand.

[0093] In an embodiment of the present invention, the intermediate representation opcode corresponding to the target rule is first used as the second opcode, and the operands in the instruction objects of the machine instruction and the associated machine instruction are converted into second operands that conform to the operand format of the intermediate representation instruction according to the operand rule corresponding to the target rule. Then, based on the second opcode and the second operand, the corresponding intermediate representation instruction is generated for the machine instruction and the associated machine instruction. In this way, the generation efficiency of the intermediate representation instruction can be ensured to a certain extent. At the same time, the machine instruction and its associated machine instruction are disassembled into an intermediate representation instruction, which can ensure the accuracy of the final disassembly result, and can reduce the number of times the disassembly operation is performed, thereby reducing the consumption of processing resources.

[0094] Optionally, the step of identifying the instruction object of the machine instruction in the target code specifically includes: for any of the machine instructions, comparing the machine instruction with a preset instruction encoding format to determine an operation code and an operand corresponding to the machine instruction, and determining the operation code and the operand as the instruction object of the machine instruction.

[0095] Specifically, the length of a machine instruction can be either variable or fixed, and different architectures use different methods. When the length of a machine instruction is fixed, an array of equal length can be directly read from a byte array according to the fixed length followed by the machine instruction to obtain the encoding of a machine instruction, that is, a complete machine instruction. The machine instruction is then compared one by one with each instruction encoding format in the architecture followed. Among them, the preset instruction encoding format includes all instruction encoding formats in the architecture followed, and the instruction encoding format can be obtained from the architecture manual file.

[0096] Specifically, for any instruction encoding format, the content in the corresponding bit of the machine instruction can be extracted according to the bit range occupied by the opcode and the bit range occupied by various operands defined in the instruction encoding format. Specifically, the opcode can be extracted according to the bit range occupied by the opcode. The operand can be extracted according to the bit range occupied by the operand. The bit operation & (bitwise AND) can be performed on the encoding representation of the machine instruction using a mask for masking the bit range occupied by all operands to obtain the value corresponding to the bit range occupied by the opcode. Similarly, for any operand, the bit operation & (bitwise AND) can be performed on the encoding representation of the machine instruction using a mask for masking the bit range occupied by the opcode and the bit range occupied by other operands to obtain the value corresponding to the bit range occupied by the operand. It should be noted that when the length of the machine instruction is variable, an array of equal length can be directly read from the byte array according to the length defined in the instruction encoding format compared this time to obtain the encoding of a machine instruction, that is, to obtain a complete machine instruction. After obtaining the operation code and the operand, the operation code and the operand can be assigned to the corresponding instruction object. The instruction object is composed of the operation code and the operand of the machine instruction.

[0097] Optionally, in an embodiment of the present invention, after the step of generating intermediate representation instructions corresponding to the target rules according to the target rules and the machine instructions, it may also include: step S41, storing each generated intermediate representation instruction into a second array; the second array is used to cache the intermediate representation instructions obtained by disassembly.

[0098] Accordingly, the step of outputting the disassembly result based on the generated intermediate representation instruction may specifically include:

[0099] Step 1041: Determine the content in the second array as the intermediate representation instruction corresponding to the target code, and output it as a disassembly result.

[0100] Among them, the second array can be a pre-created dynamic array. Specifically, before step 102, a dynamic array can be created as the second array. That is, in the embodiment of the present invention, two dynamic arrays can be pre-created, respectively as the first array and the second array. The intermediate representation instruction corresponding to the machine instruction can be in the form of a string, and the string object can be stored in the second array, that is, each generated intermediate representation instruction is stored. Exemplarily, when an intermediate representation instruction is generated, the intermediate representation instruction is stored in the second array. Correspondingly, after completing the traversal of the machine instructions in the byte array, that is, after the machine instructions in the target code are converted into intermediate representation instructions, the second array caches the final result of the disassembly. These intermediate representation instructions in the second array can constitute the intermediate representation corresponding to the target code. Finally, the content in the second array can be printed out as the disassembly result.

[0101] It should be noted that, in the case where the intermediate representation in the embodiment of the present invention is LLIR, the step of outputting the disassembly result based on the intermediate representation instructions corresponding to the machine instructions in the target code may include: converting the intermediate representation instructions corresponding to the machine instructions in the target code into IR instructions according to the second conversion rule corresponding to the target compiler. Among them, the second conversion rule can be used to characterize the characteristics of the instruction objects corresponding to various types of IR instructions, and the instruction objects corresponding to the IR instructions are the instruction objects of the LLIR instructions obtained by converting such IR instructions. Then, all the IR instructions obtained by conversion are used as the disassembly result and output. Among them, the implementation method of each step can refer to the description of the aforementioned related steps, which will not be repeated here. In this way, it is convenient for users to know the IR representation corresponding to the target code, providing technicians with more diverse choices.

[0102] The following is an explanation with reference to a specific example. For example, taking hexadecimal representation as an example, assuming that the machine instructions in the target code include:

[0103] 001710a5

[0104] 001710a6 00170085

[0106] 1400021e

[0107] 001097de

[0108] 280003c4

[0109] The instruction code can be read first and stored in a byte array. Create two dynamic arrays array_inst and array_dis, as the first array and the second array respectively. The content in the byte array can be: byte[...]{00,17,10,a5,00,...,28,00,03,c4}. Accordingly, the byte array can be traversed for decoding. For example, taking the machine instruction as a fixed length of 32 bits, a byte is 8 bits, and a machine instruction can be obtained by intercepting 4 bytes each time. Accordingly, the content obtained for the first time can be {00,17,10,a5}. Assume that the opcode defined in the instruction encoding format of the sll.w instruction occupies a bit range of [31,15] bits, and the bit ranges occupied by various operands are: rd is [4,0] bits, rj is [9,5] bits, and rk is [14,10] bits. Set all the bits occupied by the operands in the first machine instruction to 0, and the value corresponding to the [31,15] bit can be obtained. For example, the bitwise operation & (bitwise AND) can be performed on the encoding of the machine instruction 001710a5 using the mask 0xffff80000 to obtain the value corresponding to the [31,15] bit. Specifically, the processing process can be expressed as:

[0110] (0x001710a5&0xffff8000)=0x00170000. 0xffff8000 masks the lower 15 bits of 0x001710a5 and retains the upper 17 bits.

[0111] Based on the above, we can know that the value of the [31,15] bit of 001710a5 is 00170000. When the hexadecimal representation of the opcode defined in the instruction encoding format of the sll.w instruction is also 00170000, it can be determined that the opcode of the machine instruction is sll.w. Correspondingly, the value of operand rd can be expressed as 0x001710a5&((1<<5)-1)=5. Correspondingly, rd=r5. Similarly, it can be determined that the value of rj is r5 and the value of rk is r4. Among them, (1<<5)-1 is a bit operation expression used to generate a mask (0x10) that masks the upper 27 bits. The assembly code representation of the first machine instruction can be sll.w$r5,$r5,$r4.

[0112] Further, through rule matching, it can be determined that the target rule hit by the first machine instruction is the aforementioned conversion rule 2. The first machine instruction can be directly disassembled into an LLIR instruction without being put into the first array. Specifically, the first machine instruction can be disassembled into SLL R4, R5. Accordingly, the SLL R4, R5 obtained after disassembly can be added to the second array array_dis.

[0113] Next, the second machine instruction can be processed. Through rule matching, it can be determined that the target rule hit by the second machine instruction is the aforementioned conversion rule three. The second machine instruction can be directly disassembled into an LLIR instruction without being placed in the first array. Specifically, the second machine instruction can be disassembled into SLL R4, R5, R6. Accordingly, the SLL R4, R5, R6 obtained after disassembly can be added to the second array array_dis. Next, the third machine instruction is processed. Through rule matching, it can be determined that the target rule hit by the third machine instruction is the aforementioned conversion rule one. The third machine instruction can be directly disassembled into an LLIR instruction without being placed in the first array. Specifically, the third machine instruction can be disassembled into MOVW R4, R5. Accordingly, the MOVW R4, R5 obtained after disassembly can be added to the second array array_dis.

[0114] For the fourth machine instruction, decoding can obtain the opcode op=lu12i.w, operand rd=r30, and operand si20=16. Among them, si20 represents a 20-bit immediate value. Through rule matching, it can be determined that the target rule hit by the fourth machine instruction is the aforementioned conversion rule four. The fourth machine instruction cannot be directly disassembled into an LLIR instruction and needs to be placed in the first array array_inst. At this time, the array_inst element is empty, and the machine instruction can be placed in array_inst. Then, the next machine instruction, that is, the fifth machine instruction, can be processed. For the fifth machine instruction and the sixth machine instruction stored continuously, the fifth machine instruction decoding can obtain the opcode op=add.d, operand rd=r30, operand rj=r30, and operand rk=r5. At this time, array_inst stores "lu12i.w r30,16. The fifth machine instruction is the associated machine instruction of the fourth machine instruction. The fifth machine instruction and the fourth machine instruction cannot be deassembled into one LLIR. The instruction object of the fifth machine instruction can be stored in the first array. Then, the next machine instruction, that is, the sixth machine instruction, can be processed.

[0115] The sixth machine instruction can be decoded to obtain the opcode op=ld.b, operand rd=r4, operand rj=r30, and operand offs=0. Among them, offs represents the offset. At this time, array_inst stores "lu12i.w r30,16" and "add.d r30 r30 r5". The sixth machine instruction is also the associated machine instruction of the fourth machine instruction. These three machine instructions can be disassembled into one LLIR instruction. Accordingly, the first array can be cleared. And these three machine instructions are disassembled into MOVB 65536(R5), R4, and stored in the second array array_dis.

[0116] Finally, the disassembly result can be obtained from the second array array_dis. The disassembly result can be an LLIR composed of 4 LLIR instructions. The disassembly result can be expressed as:

[0117]

[0118] Among them, op represents the operation code, src represents the source register, and dest represents the destination register.

[0119] Further, the following is an explanation in conjunction with an application scenario of an embodiment of the present invention. At present, LLIR is an important dependent method for reading and studying target files, executable files, and dynamic libraries. A compiler that generates machine instructions from LLIR assembly requires a disassembly system to disassemble the machine instructions into assembly code, but at the same time requires a disassembly system to disassemble the machine instructions into LLIR IR. Disassembling machine instructions into assembly code can be achieved using an existing tool chain. For example, the objdump of the GNU tool chain implements the disassembly function, but it disassembles the machine instructions in the target code into assembly code. If the compiler converts IR into LLIR related to the computer architecture, and then assembles LLIR to generate machine instructions. During disassembly, the compiler will have the need to disassemble machine instructions to generate LLIR, but objdump does not have the function of directly disassembling machine instructions into LLIR. For compilers with the process of IR->LLIR->machine instructions, the lack of this function will make it impossible to view the disassembly represented by the low-level intermediate code of the target file, which will have a relatively large obstacle to the analysis and research of the target file.

[0120] A new disassembly system in an embodiment of the present invention, Figure 2 is a schematic diagram of a processing flow provided by an embodiment of the present invention, such as Figure 2As shown, the disassembly system can be started first, and the target code file to be disassembled (i.e., the aforementioned target code) can be passed to the disassembler as a startup parameter. Then, the disassembly system can read the encoded text of the machine instructions in the target code file, and store all the read content in the byte array ba. Next, a dynamic array arr1 can be created, that is, the aforementioned first array is created. A dynamic array arr2 is created, that is, the aforementioned second array is created. Then the traversal phase, byte array, is entered. The machine instruction is read from ba and decoded to obtain the instruction object inst. In this way, by disassembling the compiled and coded instruction object, the LLIR corresponding to the machine instruction can be generated.

[0121] Next, based on the inst, determine whether it can be directly disassembled. If yes, disassemble the machine instruction into an LLIR instruction and add the result to arr2. If no, add the inst of the machine instruction to arr1.

[0122] Next, determine whether the byte array ba is completely traversed, and if so, end the disassembly. Otherwise, traverse the next machine instruction in the byte array ba, and use the next machine instruction as the current machine instruction. If the current machine instruction can be directly disassembled, that is, arr1 is empty, then disassemble the current machine instruction into an LLIR instruction. If the current machine instruction cannot be directly disassembled, then if arr1 is empty, add it to arr1. If arr1 is not empty, perform the operation of determining whether inst and arr1 can be combined for disassembly, that is, determine whether the current machine instruction and the machine instruction of the instruction object in arr1 can be combined for disassembly. If not, add the inst of the current machine instruction to arr1. If so, disassemble based on the current inst and arr1, add the result to arr2, and clear arr1. Among them, disassembly based on the current inst and arr1 specifically refers to: converting the currently processed machine instruction and the machine instruction in the first array into the operation of the intermediate representation instruction corresponding to the target rule. When assembling LLIR into machine instructions, the semantically complex LLIR is assembled into multiple machine instructions. Therefore, during disassembly, the machine instruction can be contextually analyzed according to the conversion rules to determine whether the machine instruction being disassembled can be disassembled into an LLIR alone or needs to be disassembled into an LLIR together with other instructions. The instruction object and its context are analyzed to determine whether the machine instruction can be directly disassembled into an LLIR, or whether the machine instruction and the next several machine instructions are combined to disassemble into an LLIR to ensure the accuracy of the disassembly operation.

[0123] Finally, after all the byte arrays are traversed, the content stored in arr2 is used as the disassembly result and output. In this way, it is convenient for users to view the intermediate representation and enrich the functions of the compilation tool chain. In addition, the algorithm design in the embodiment of the present invention is simple and efficient, and the implementation cost is low, so that relevant personnel can obtain greater convenience at a relatively low cost.

[0124] Reference Figure 3 , shows a block diagram of a disassembly device provided by an embodiment of the present invention, which can be applied to electronic devices such as Figure 3 As shown, the device may specifically include:

[0125] The identification module 201 is used to read the target code to be processed and identify the instruction object of the machine instruction in the target code;

[0126] A matching module 202, configured to match the instruction object with candidate objects predefined in the conversion rule based on the conversion rule corresponding to the target compiler, to obtain a target rule corresponding to the instruction object;

[0127] A generation module 203 is used to generate an intermediate representation instruction corresponding to the target rule according to the target rule and the machine instruction; wherein the conversion rule is used to characterize the conditions satisfied by the instruction objects corresponding to each type of intermediate representation instruction; the instruction objects corresponding to each type of intermediate representation instruction are obtained by converting the various types of intermediate representation instructions;

[0128] The output module 204 is used to output the disassembly result based on the generated intermediate representation instruction.

[0129] Optionally, the generating module 203 is further configured to:

[0130] In the case where the instruction quantity parameter is not defined in the target rule, converting the machine instruction into an intermediate representation instruction corresponding to the target rule;

[0131] Otherwise, the machine instruction and associated machine instructions are converted into intermediate representation instructions corresponding to the target rule; the associated machine instructions include other machine instructions in the target code that are associated with the machine instruction.

[0132] Optionally, the matching module 202 is further configured to:

[0133] Matching the operation code in the instruction object with the operation code predefined in each of the conversion rules, and taking the conversion rule consistent with the operation code in the instruction object as an alternative rule;

[0134] The operands in the instruction object are matched with the operand conditions defined in each of the candidate rules, and the candidate rule corresponding to the operand condition that the operand in the instruction object meets is determined as the target rule.

[0135] Optionally, when the instruction quantity parameter is defined in the target rule, the device further comprises: a storage module, used to store the machine instruction in a first array; an adding module, used to continue processing the next machine instruction in the target code, and when the target instruction quantity does not match the preset quantity and the target rule hit by the next machine instruction is the same as the target rule hit by the machine instruction, add the next machine instruction to the first array until the last associated machine instruction is processed; the first array is used to store machine instructions with an associated relationship;

[0136] The generating module 203 is further specifically used for:

[0137] When the target instruction quantity matches the preset quantity, the next machine instruction and the machine instructions stored in the first array are converted into intermediate representation instructions corresponding to the target rule to obtain intermediate representation instructions corresponding to the machine instruction and associated machine instructions; the target instruction quantity is the total quantity of the next machine instruction and the machine instructions stored in the first array.

[0138] Optionally, the generating module 203 is further configured to:

[0139] Using the intermediate representation operation code corresponding to the target rule as the first operation code, and generating a first operand that conforms to the operand format of the intermediate representation instruction based on the operand rule corresponding to the target rule and the operand in the instruction object;

[0140] Based on the first opcode and the first operand, a corresponding intermediate representation instruction is generated for the machine instruction.

[0141] Optionally, the generating module 203 is further configured to:

[0142] Using the intermediate representation operation code corresponding to the target rule as a second operation code, and generating a second operand that conforms to the operand format of the intermediate representation instruction based on the operand rule corresponding to the target rule, the operand in the instruction object of the machine instruction, and the operand in the instruction object of the associated machine instruction;

[0143] Based on the second opcode and the second operand, a corresponding intermediate representation instruction is generated for the machine instruction and the associated machine instruction.

[0144] Optionally, the device further comprises: a storage module, used to store each of the generated intermediate representation instructions into a second array; the second array is used to cache the intermediate representation instructions obtained by disassembly;

[0145] The output module 204 is specifically used for:

[0146] The content in the second array is determined as the intermediate representation instruction corresponding to the target code, and is output as the disassembly result.

[0147] Optionally, the intermediate representation instruction is an intermediate code representation instruction or a low-level intermediate code representation instruction.

[0148] In summary, the disassembly device provided by the embodiment of the present invention reads the target code generated by the target compiler and identifies the instruction object of the machine instruction in the target code. Based on the conversion rule corresponding to the target compiler, the instruction object is matched with the candidate object predefined in the conversion rule respectively to obtain the target rule corresponding to the instruction object. According to the target rule and the machine instruction, an intermediate representation instruction corresponding to the target rule is generated; wherein the conversion rule is used to characterize the conditions satisfied by the instruction object corresponding to each intermediate representation instruction; the instruction object corresponding to each intermediate representation instruction is obtained by converting the intermediate representation instruction. Based on the generated intermediate representation instruction, the disassembly result is output. In this way, based on the instruction object of the machine instruction in the target code and the preset target compiler, the intermediate representation instruction corresponding to the machine instruction is generated by matching, and based on the intermediate representation instruction generated for the target code, the disassembly result is output, so that the user can view the intermediate representation of the target code, so that the technician can analyze the intermediate representation, thereby reducing the difficulty of analyzing the disassembly result to a certain extent.

[0149] Reference Figure 4 , is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Figure 4 As shown, the electronic device includes: a processor, a memory, a communication interface and a communication bus, and the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the disassembly method of the aforementioned embodiment.

[0150] An embodiment of the present invention provides a machine-readable medium having instructions stored thereon, which, when executed by one or more processors, enables the processors to execute the disassembly method of the aforementioned embodiment.

[0151] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0152] It should be understood by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes. It should be pointed out that all actions of obtaining signals, information or data in this application are carried out in compliance with the corresponding data protection laws and policies of the country of residence and with the authorization given by the owner of the corresponding device.

[0153] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0154] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a predictable manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0155] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0156] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0157] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0158] The above describes in detail a disassembly method, a disassembly device, an electronic device and one or more machine-readable media provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A disassembly method, characterized in that: The method comprises: Reading the target code generated by the target compiler and identifying the instruction object of the machine instruction in the target code; Based on the conversion rules corresponding to the target compiler, the instruction objects are matched with the candidate objects predefined in the conversion rules respectively to obtain the target rules corresponding to the instruction objects; According to the target rule and the machine instruction, an intermediate representation instruction corresponding to the target rule is generated; wherein the conversion rule is used to characterize the conditions satisfied by the instruction objects corresponding to each type of intermediate representation instruction; the instruction objects corresponding to each type of intermediate representation instruction are obtained by converting the various types of intermediate representation instructions; Based on the generated intermediate representation instructions, a disassembly result is output.

2. The method according to claim 1, characterized in that The step of generating an intermediate representation instruction corresponding to the target rule according to the target rule and the machine instruction includes: In the case where the instruction quantity parameter is not defined in the target rule, converting the machine instruction into an intermediate representation instruction corresponding to the target rule; Otherwise, the machine instruction and the associated machine instructions are converted into intermediate representation instructions corresponding to the target rule; the associated machine instructions include other machine instructions in the target code that are associated with the machine instruction.

3. The method according to claim 1, characterized in that The matching of the instruction object of the machine instruction with the candidate object predefined in the conversion rule includes: Matching the operation code in the instruction object with the operation code predefined in each of the conversion rules, and taking the conversion rule consistent with the operation code in the instruction object as an alternative rule; The operands in the instruction object are matched with the operand conditions defined in each of the candidate rules, and the candidate rule corresponding to the operand condition that the operand in the instruction object meets is determined as the target rule.

4. The method according to claim 2, characterized in that: In the case where the instruction quantity parameter is defined in the target rule, the method further includes: Storing the machine instructions in a first array; Continue to process the next machine instruction in the target code, and if the number of target instructions does not match the preset number, and the target rule hit by the next machine instruction is the same as the target rule hit by the machine instruction, add the next machine instruction to the first array until the last associated machine instruction is processed; the first array is used to store machine instructions with an associated relationship; The converting the machine instruction and the associated machine instruction into an intermediate representation instruction corresponding to the target rule comprises: When the target instruction quantity matches the preset quantity, the next machine instruction and the machine instructions stored in the first array are converted into intermediate representation instructions corresponding to the target rule to obtain intermediate representation instructions corresponding to the machine instruction and associated machine instructions; the target instruction quantity is the total quantity of the next machine instruction and the machine instructions stored in the first array.

5. The method according to claim 2, characterized in that: The converting the machine instruction into an intermediate representation instruction corresponding to the target rule comprises: Using the intermediate representation operation code corresponding to the target rule as the first operation code, and generating a first operand that conforms to the operand format of the intermediate representation instruction based on the operand rule corresponding to the target rule and the operand in the instruction object; Based on the first opcode and the first operand, a corresponding intermediate representation instruction is generated for the machine instruction.

6. The method according to claim 2, characterized in that The converting the machine instruction and the associated machine instruction into an intermediate representation instruction corresponding to the target rule comprises: Using the intermediate representation operation code corresponding to the target rule as a second operation code, and generating a second operand that conforms to the operand format of the intermediate representation instruction based on the operand rule corresponding to the target rule, the operand in the instruction object of the machine instruction, and the operand in the instruction object of the associated machine instruction; Based on the second opcode and the second operand, a corresponding intermediate representation instruction is generated for the machine instruction and the associated machine instruction.

7. The method according to claim 1, characterized in that The method further comprises: storing each of the generated intermediate representation instructions into a second array; the second array is used to cache the intermediate representation instructions obtained by disassembly; Outputting a disassembly result based on the generated intermediate representation instruction includes: The content in the second array is determined as the intermediate representation instruction corresponding to the target code, and is output as the disassembly result.

8. A disassembly device, characterized in that: The device comprises: An identification module, used for reading the target code generated by the target compiler and identifying the instruction object of the machine instruction in the target code; A matching module, for matching the instruction object with the candidate objects predefined in the conversion rule based on the conversion rule corresponding to the target compiler, to obtain the target rule corresponding to the instruction object; A generation module, configured to generate an intermediate representation instruction corresponding to the target rule according to the target rule and the machine instruction; wherein the conversion rule is used to characterize the conditions satisfied by the instruction objects corresponding to each type of intermediate representation instruction; and the instruction objects corresponding to each type of intermediate representation instruction are obtained by converting the various types of intermediate representation instructions; An output module is used to output a disassembly result based on the generated intermediate representation instruction.

9. An electronic device, characterized in that: include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store executable instructions, and the executable instructions enable the processor to execute the method according to any one of claims 1 to 7.

10. One or more machine-readable media, characterized in that Instructions are stored thereon, which, when executed by one or more processors, cause the processors to perform the method according to any one of claims 1 to 7.