Jump table search method, device, electronic device and storage medium
By identifying and searching target instructions in the order of function instructions in the target file in reverse order, and determining the position of the jump table with relocation information, the problem of finding the jump table in dynamic jump commands is solved, and the search efficiency is improved.
Patent Information
- Application Number
- CN202210109460.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-28
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2042-01-28
AI Technical Summary
During the process of program development, it is difficult to find the jump table for dynamic jump instructions in the target file, which makes it difficult to quickly locate and obtain the jump table during the debugging process.
By identifying instructions in sequence in the execution order of instructions in the function, and looking in reverse order along the recognition order when dynamic jump instructions are identified, the target instruction corresponding to the first register read by the dynamic jump instructions is determined, thereby obtaining the jump table The base address of the target instruction determines the storage area of the jump table.
It realizes the jump table for fast positioning and obtaining dynamic jump instructions, simplifies the search process in the target file and improves the debugging efficiency.
Smart Images

Figure CN114546481B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of electronic technology, and in particular to a jump table search method, device, electronic equipment and storage medium. Background Art
[0002] In the process of program development, after the source file of the program is obtained by using a high-level programming language, it is necessary to convert the source file into a relocatable target file through compilation and assembly operations. The target file includes the machine code of the program and the data required for program execution. The program usually includes multiple functions. When the function includes a dynamic jump instruction, the target file will include a jump table of the dynamic jump instruction. The jump table includes the jump address required when the dynamic jump instruction jumps.
[0003] Usually, after obtaining the relocatable target file, the relocatable target file needs to be debugged. At this time, it is necessary to find and determine the jump table of the dynamic jump instruction from the target file. Since the target file includes more content, it is difficult to find and determine the jump table from the target file. Summary of the invention
[0004] In view of the above problems, an embodiment of the present invention is proposed to provide a jump table search method that overcomes the above problems or at least partially solves the above problems, so as to solve the problem that it is difficult to search and determine the jump table from the target file.
[0005] Correspondingly, an embodiment of the present invention further provides a jump table search device, an electronic device and a storage medium to ensure the implementation and application of the above method.
[0006] An embodiment of the present invention discloses a jump table search method, comprising:
[0007] Determine the functions included in the target file;
[0008] Identify the instructions in the function in sequence according to the execution order of the instructions in the function, and record the identification order;
[0009] In the case where a dynamic jump instruction is identified, searching in reverse order along the identification order to determine a target instruction corresponding to the first register read by the dynamic jump instruction; the target instruction is used to write a base address of a jump table into the operated second register, so that other instructions between the target instruction and the dynamic jump instruction write a destination address in the jump table into the first register based on the base address in the second register for the jump instruction to read;
[0010] Obtaining relocation information of the target instruction from the target file, and obtaining relocation information of other instructions included in the function;
[0011] Based on the relocation information of the target instruction and the relocation information of the other instructions, a storage area of the jump table is determined from the target file to obtain the jump table from the storage area.
[0012] Optionally, searching in reverse order along the recognition sequence to determine the target instruction corresponding to the first register read by the dynamic jump instruction includes:
[0013] Accessing the identified instructions recorded in the identification sequence in reverse order along the identification sequence to determine the register operated by the identified instructions;
[0014] In the case where the identified instruction passes data to the first register through the register operated by the identified instruction, continue to access other identified instructions that pass data to the register operated by the identified instruction in reverse order along the identification order until the identified instruction of the target category is accessed, and the identified instruction of the target category is used as the target instruction.
[0015] Optionally, the target instruction is an assignment instruction;
[0016] In the case where the identified instruction transfers data to the first register through the operated register, continuing to access other identified instructions that transfer data to the register operated by the identified instruction in reverse order along the identification sequence until an identified instruction of the target category is accessed, and taking the identified instruction of the target category as the target instruction, comprises:
[0017] In the case where the accessed identified instruction is a load instruction that writes data to the first register, accessing in reverse order along the identification sequence to determine a shift instruction that writes data to a third register read by the load instruction;
[0018] The assignment instruction that determines to write data to the second register read by the shift instruction is accessed in reverse order along the identification sequence.
[0019] Optionally, the step of sequentially identifying the instructions in the function according to the execution order of the instructions in the function and recording the identification order includes:
[0020] Accessing the instructions in the function in sequence according to the execution order, identifying and marking the instructions when the accessed instructions are not marked, and recording the instructions in the recognition order;
[0021] When the accessed instruction is marked or a preset instruction is accessed, stopping the step of accessing the instruction in the function at the instruction;
[0022] In the case of accessing a branch instruction, the step of accessing instructions in the function is continued in each execution direction indicated by the branch instruction.
[0023] Optionally, the determining the storage area of the jump table from the target file based on the relocation information of the target instruction and the relocation information of the other instructions includes:
[0024] In a case where the relocation information of the other instructions includes the relocation information of the target class, determining the target relocation information from the relocation information of the target class;
[0025] Using the area between the address indicated by the relocation information of the target instruction and the address indicated by the target relocation information as the storage area;
[0026] The position indicated by the relocation information of the target category is located after the address indicated by the relocation information of the target instruction, and the target relocation information is the relocation information of the target category that is closest to the address indicated by the relocation information of the target instruction.
[0027] Optionally, after determining the storage area of the jump table from the target file, the method further includes:
[0028] Acquire at least one entry in the jump table from the storage area; the entry includes a jump address;
[0029] In the case where the jump address points to the location of the function in the target file, it is determined that the storage area is correct.
[0030] The embodiment of the present invention also discloses a jump table search device, comprising:
[0031] A first determining module, used for determining functions included in a target file;
[0032] An identification module, used to identify the instructions in the function in sequence according to the execution order of the instructions in the function, and record the identification order;
[0033] A search module, configured to, when a dynamic jump instruction is identified, search in reverse order along the identification sequence to determine a target instruction corresponding to the first register read by the dynamic jump instruction; the target instruction is used to write a base address of a jump table into the operated second register, so that other instructions between the target instruction and the dynamic jump instruction write a destination address in the jump table into the first register based on the base address in the second register for reading by the jump instruction;
[0034] An acquisition module, used for acquiring the relocation information of the target instruction from the target file, and acquiring the relocation information of other instructions included in the function;
[0035] The second determining module is used to determine the storage area of the jump table from the target file based on the relocation information of the target instruction and the relocation information of the other instructions, so as to obtain the jump table from the storage area.
[0036] Optionally, the search module includes:
[0037] A determination unit, configured to access the identified instructions recorded in the identification sequence in reverse order along the identification sequence, and determine the register operated by the identified instruction;
[0038] An access unit is used to, when the identified instruction passes data to the first register through the register operated by the identified instruction, continue to access other identified instructions that pass data to the register operated by the identified instruction in reverse order along the identification order, until an identified instruction of the target category is accessed, and use the identified instruction of the target category as the target instruction.
[0039] Optionally, the target instruction is an assignment instruction;
[0040] The access unit is specifically used to, when the identified instruction accessed is a load instruction that writes data to the first register, access in reverse order along the identification sequence to determine the shift instruction that writes data to the third register read by the load instruction; and access in reverse order along the identification sequence to determine the assignment instruction that writes data to the second register read by the shift instruction.
[0041] Optionally, the identification module is specifically used to access the instructions in the function in sequence according to the execution order, and when the accessed instruction is not marked, identify and mark the instruction, and record the instruction in the identification order; when the accessed instruction is marked or when a preset instruction is accessed, stop executing the step of accessing the instruction in the function at the instruction; when a branch instruction is accessed, continue executing the step of accessing the instruction in the function in each execution direction indicated by the branch instruction.
[0042] Optionally, the second determination module is specifically used to determine the target relocation information from the relocation information of the target category when the relocation information of the other instructions includes the relocation information of the target category; and use the area between the address indicated by the relocation information of the target instruction and the address indicated by the target relocation information as the storage area; wherein the position indicated by the relocation information of the target category is located after the address indicated by the relocation information of the target instruction, and the target relocation information is the relocation information of the target category that is closest to the address indicated by the relocation information of the target instruction.
[0043] Optionally, it also includes: a detection module, used to obtain at least one table entry in the jump table from the storage area; the table entry includes a jump address; when the jump address points to the position of the function in the target file, determine that the storage area is correct.
[0044] The embodiment of the present invention further discloses an electronic device including a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors. The one or more programs include instructions for performing the following operations:
[0045] Determine the functions included in the target file;
[0046] Identify the instructions in the function in sequence according to the execution order of the instructions in the function, and record the identification order;
[0047] In the case where a dynamic jump instruction is identified, searching in reverse order along the identification order to determine a target instruction corresponding to the first register read by the dynamic jump instruction; the target instruction is used to write a base address of a jump table into the operated second register, so that other instructions between the target instruction and the dynamic jump instruction write a destination address in the jump table into the first register based on the base address in the second register for the jump instruction to read;
[0048] Obtaining relocation information of the target instruction from the target file, and obtaining relocation information of other instructions included in the function;
[0049] Based on the relocation information of the target instruction and the relocation information of the other instructions, a storage area of the jump table is determined from the target file to obtain the jump table from the storage area.
[0050] An embodiment of the present invention further discloses a readable storage medium. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute one or more jump table search methods described in the embodiment of the present invention.
[0051] In an embodiment of the present invention, the electronic device determines the function included in the target file, identifies the instructions in the function in sequence according to the execution order of the instructions in the function, and records the identification order. When a dynamic jump instruction is identified, the electronic device searches in reverse order along the identification order to determine the target instruction corresponding to the first register read by the dynamic jump instruction, obtains the relocation information of the target instruction from the target file, and obtains the relocation information of other instructions included in the function. Based on the relocation information of the target instruction and the relocation information of other instructions, the electronic device determines the storage area of the jump table from the target file. When searching for the jump table of the dynamic jump instruction, the electronic device determines the target instruction for obtaining the base address in combination with the register used when the dynamic jump instruction reads the jump table and the execution order of the instructions, and determines the position of the jump table in the target file according to the relocation information of the target instruction, so that the storage area of the jump table of the dynamic jump instruction in the target file can be quickly determined. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 is a flowchart of a jump table search method according to an exemplary embodiment;
[0053] Figure 2 is a schematic flow chart of a jump table search method according to an exemplary embodiment;
[0054] Figure 3 is a structural block diagram of a jump table search device according to an exemplary embodiment;
[0055] Figure 4 The present invention is a structural block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0056] In order to facilitate the understanding of the present invention, the technical background of the present invention is briefly introduced first.
[0057] In the process of program development, a high-level programming language is first used to develop the source file of the program, and then the source file is converted into a relocatable target file through compilation and assembly. Finally, the relocatable target file can be combined with some necessary system files through linking to create an executable target file, which can be loaded and executed by the central processing unit (CPU). The jump table search method provided in this embodiment operates on the relocatable target file, which is convenient for simplifying the description. The target files appearing in other positions in this embodiment all refer to the relocatable target files obtained through assembly.
[0058] In one embodiment, the relocatable target file is, for example, an ELF target file, and the target file is composed of a set of sections described by a section header table. For example, the target file includes a code section (.text section), a read-only data section (.rodata section), a code section relocation information section (.rel(a).text section), and a read-only data section relocation information section (.rel(a).rodata section). The code section stores the code segments of each function included in the compiled program, and the program consists of multiple functions, each of which is used to implement a specific function. Each function includes multiple instructions, such as call instructions, shift instructions, assignment instructions, memory access instructions, and jump instructions. Multiple instructions are executed in the logical order of the function to implement the function. It should be noted that the instructions in this embodiment refer to the broader definition of assembly instructions, and each instruction can be composed of one or more assembly instructions. The corresponding character strings and constants are stored in the read-only data section, and the relocation information of the code section is stored in the code section relocation information section, and the relocation information is used to re-modify the address information in the instructions of the code segment in the link stage. The target file also includes other sections, which are not introduced in detail in this embodiment. The target file can also be in other formats, and the specific content included in the target file can be set according to the requirements, which is not limited in this embodiment.
[0059] Among them, the dynamic jump instruction is a jump instruction in the jump instruction, and the jump address of the dynamic jump instruction is not fixed during the program running process. When a function in the program includes a dynamic jump instruction, the read-only data section includes a jump table of the dynamic jump instruction, and the jump table includes multiple table entries, and each table entry stores a jump address. The jump address points to a certain instruction in the function. During the execution of the dynamic jump instruction, the instruction can be jumped to according to the read jump address. During the function running process, a jump address can be determined from multiple jump addresses in the table entry. The destination address of the jump address in the jump table can be written into a register by other instructions before the dynamic jump instruction for the dynamic jump instruction to read. For the convenience of distinction, the register is named the first register. The destination address is composed of the base address of the jump table and the offset corresponding to a table entry in the jump table. The base address is the first address of the jump table, and the offset corresponds to the position of the table entry in the jump table. The base address plus the offset is the storage address of the table entry. When a dynamic jump instruction is executed, the destination address can be first read from the first register, and then the jump address included in the corresponding table entry can be obtained from the jump table according to the destination address, and the jump to the corresponding instruction based on the jump address can be performed. During the running of the program, the jump address of the dynamic jump instruction changes. In the process of writing the destination address to the first register, the base address of the jump table and different offsets can be used to obtain different destination addresses. The base address of the jump table remains unchanged. When the destination address written to the first register changes, the destination address read from the first register by the jump instruction is different, and the jump addresses in different table entries can be obtained from the jump table.
[0060] During the program development phase, after assembling to obtain a relocatable target file, debugging is required. At this time, if a function includes a dynamic jump instruction, it is necessary to first determine the dynamic jump instruction in the target file, then determine the storage area of the jump table of the dynamic jump instruction in the target file, and then obtain the jump table of the dynamic jump instruction from the target file. Since the target file is composed of a series of sections and contains a lot of content, it is difficult to find and determine the jump table from the target file.
[0061] One of the core concepts of the embodiment of the present invention is to identify the instructions in the function in sequence according to the execution order of the instructions in the function, taking the function in the program as a unit, and record the identification order; when a dynamic jump instruction is identified, the first register used by the jump table is read in combination with the dynamic jump instruction, and the target instruction for obtaining the base address of the jump table is searched in reverse order along the identification order. Since the relocation information of the target instruction points to the base address of the jump table, the position of the jump table in the target file can be determined based on the relocation information of the target instruction.
[0062] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0063] Reference Figure 1 , Figure 1 FIG. 1 is a flowchart of a jump table search method according to an exemplary embodiment. The method may include the following steps:
[0064] Step 101: Determine the functions included in the target file.
[0065] Step 102: Identify the instructions in the function in sequence according to the execution order of the instructions in the function, and record the identification order.
[0066] The jump table search method can be executed by an electronic device such as a computer or a server. The electronic device can first obtain a relocatable target file, then identify a dynamic jump instruction from the target file, and determine the storage area of the jump table of the dynamic jump instruction in the target file. The target file can be pre-stored in a preset location in the electronic device, and the electronic device can obtain the target file from the preset location; or the target file can also be obtained by the electronic device from other electronic devices connected to it.
[0067] In this embodiment, after obtaining the target file, the electronic device can identify the instructions in each function in the program as a unit, determine the dynamic jump instruction in the function, and then determine the storage area of the jump table of the dynamic jump instruction in the target file. In combination with the above content, in the process of searching the jump table, the electronic device can first determine each function included in the code section from the code section, and then identify the instructions in the function. In the instruction identification process, each instruction in the function can be identified in turn according to the execution order of the instructions in the function, the functional type of the instruction can be determined, and the recognition order of the instructions can be recorded. For example, if function X includes instructions A, instruction B, instruction C and instruction D, as well as other instructions, during the program running process, when function X is run, instruction A is executed first, then instruction B is executed, then instruction C is executed, and finally instruction D is executed. The electronic device can first identify instruction A in the execution order, determine the functional type of instruction A, then identify instruction B located after instruction A, then identify instruction C located after instruction B, and then identify instruction D. At the same time, the recognition order can be recorded, and the recognition order is from instruction A to instruction D. The instructions in a function have different functions, such as call instructions for calling other instructions, load instructions for loading data into registers, and dynamic jump instructions for jumping. The functional types of instructions in a function can be pre-divided according to the specific functions of the instructions.
[0068] Optionally, step 102 may include:
[0069] Accessing instructions in the function in order of execution, identifying and marking the instructions if the accessed instructions are not marked, and recording the instructions in the order of recognition;
[0070] When the accessed instruction is marked or a preset instruction is accessed, stopping the execution of the step of accessing the instruction in the function at the instruction;
[0071] When a branch instruction is accessed, the steps of executing the instructions in the access function are continued in each execution direction indicated by the branch instruction.
[0072] Among them, multiple instructions in the function can be executed sequentially, in parallel, in a loop, or in a jump execution. For example, instructions A, instruction B, instruction C, and instruction D can be sequentially executed from instruction A to instruction D. Or, instructions C and instruction D can be executed in parallel, first executing instruction A, then executing instruction B, instruction B is a branch instruction, pointing to the first execution direction where instruction C is located and the second execution direction where instruction D is located, respectively. After instruction B is executed, instruction C is executed along the first execution direction, and instruction D is executed along the second execution direction at the same time, and instruction C and instruction D are executed in parallel.
[0073] For another example, instruction B and instruction C are executed cyclically, instruction A is executed first, and then instruction B and instruction C are executed in sequence. When the execution result of instruction C does not meet the preset condition, instruction B is returned, and instruction B and instruction C are repeatedly executed until the execution result of instruction C meets the preset condition, and instruction D is executed. In the process of returning from instruction C to instruction B, instruction E can be executed. At this time, instruction C constitutes a branch instruction, pointing to the first execution direction from instruction C to instruction E, and pointing to the second execution direction from instruction C to instruction D.
[0074] For another example, instruction A, instruction B, instruction C, and instruction D are executed in sequence, instruction B is a call instruction, and during the execution of instruction B, instruction F needs to be called. At this time, instruction B constitutes a branch instruction, pointing to a first execution direction from instruction B to instruction F, and a second execution direction from instruction B to instruction C. The execution order of instructions in a function includes but is not limited to the above examples, and this embodiment does not impose any limitation on this.
[0075] In this embodiment, when each instruction is identified in sequence according to the execution order of the instructions in the function, the electronic device can access each instruction in sequence according to the execution order, and when the accessed instruction is not marked, the instruction is identified and marked, and the identified instruction is recorded in the recognition order; when the accessed instruction is marked, the access is stopped at the instruction. Marking the instruction can avoid repeated identification of the instruction and can avoid repeated recording of the instruction in the recognition order. Combined with the above example, in the process of accessing instruction A, instruction B, instruction C and instruction D in sequence according to the execution order, each time the electronic device accesses an instruction, it first determines whether the instruction is marked. If the instruction is not marked, it can be determined that the instruction has not been recognized by the electronic device and has not been recorded in the recognition order. The instruction can be identified and the identified instruction can be recorded in the recognition order, and the instruction can be marked at the same time. On the contrary, if the instruction has been marked, it can be determined that the instruction has been recognized, and the instruction can be ignored and not recorded in the recognition order.
[0076] In some cases, the function includes a branch instruction as described above. At this time, the instructions in the function can continue to be accessed in the execution order of the instructions in each execution direction indicated by the branch instruction. Combined with the above example, instruction B is a branch instruction, and instructions C and D are executed in parallel. When instruction B is accessed, if instruction B is not marked, instruction B is identified and recorded in the recognition order. When instruction B is identified as a branch instruction, instruction C can be continued to be accessed in the first execution direction according to the execution order of the instructions, and instruction D can be continued to be accessed in the second execution direction according to the execution order of the instructions. In the process of accessing the instructions in the first execution direction and the second execution direction, if the accessed instruction is not marked, the instruction is identified and marked, and the instruction is recorded in the recognition order; in a certain execution direction, if the accessed instruction is marked, the access in the execution direction is stopped. At this time, the recorded access order includes two paths, the first path is from instruction A to instruction B, then from instruction B to instruction C, and extends to other instructions after instruction C; the second path is from instruction A to instruction B, then from instruction B to instruction D, and extends to other instructions after instruction D. The electronic device may continue to access the instructions in the function until each instruction in the function has been marked and recorded in the access order.
[0077] In this embodiment, when the electronic device is accessing the instructions in the function in the execution order, if the accessed instruction is marked, the step of accessing the instruction can be stopped at the instruction. In combination with the above example, instruction B and instruction C are executed in a loop. After accessing instruction A, instruction B, and instruction C in sequence, instruction E can be accessed along the first execution direction, and instruction D can be accessed along the second instruction direction. During the access process, if the accessed instruction is not marked, the instruction is identified and marked, and the instruction is recorded in the identification order; if the accessed instruction is marked, the access is stopped. After accessing instruction B along the first execution direction, instruction B has been marked during the first access, and the electronic device can stop accessing at instruction B. In the second execution direction, the electronic device can continue to access in the execution order of the instructions until the marked instruction is accessed, or the last instruction in the second execution direction is accessed. At this time, the recorded access sequence includes two paths. The first path is from instruction A to instruction B, then from instruction B to instruction C, and finally from instruction C to instruction E; the second path is from instruction A to instruction B, then from instruction B to instruction C, and finally from instruction C to instruction D, and extends to other instructions after instruction D.
[0078] Similarly, when instruction B is a call instruction, the electronic device can access instruction F along the first execution direction and access instruction C along the second instruction direction when it recognizes that instruction B is a branch instruction. When instruction F is executed and returns to instruction B, since instruction B has been marked, further access is stopped. When instruction F does not return, since there are no other instructions in the first execution direction, access to instructions in the first execution direction can be stopped. At this time, the recorded access order also includes two paths. The first path is from instruction A to instruction B, and then from instruction B to instruction F; the second path is from instruction A to instruction B, then from instruction B to instruction C, and finally from instruction C to instruction D, and extends to other instructions after instruction D.
[0079] In one embodiment, the electronic device can stop executing the step of accessing the instruction in the function at the instruction when the accessed instruction is a preset instruction. When accessing the instruction in the function in the execution order, if the access step is continued at the preset instruction, the recorded access order may be inaccurate and the target instruction cannot be determined. Therefore, when the accessed instruction is a preset instruction, the step of accessing the instruction in the function can be stopped at the instruction to avoid the occurrence of such a situation. For example, the preset instruction is a function return instruction, function Y is the parent function, function X is the child function of function Y, function Y includes a call instruction for calling function X, and function X includes a corresponding function return instruction. During the program running process, when function Y executes the call instruction during the running process, after calling function X, function X returns function Y when executing the function return instruction. For another example, the preset instruction is a call instruction of a preset type, the calling object of the call instruction of this type is a function, and the called function does not return. In combination with the above example, when function X does not include a corresponding function return instruction, the call instruction in function Y is a call instruction of a preset type. During the program running process, when function Y executes the call instruction during the running process, after calling function X, function X is executed and does not return to function Y. The preset instruction may include but is not limited to the above examples, and the preset instruction may be specifically set according to the instructions included in the function.
[0080] Optionally, when marking instructions, the instructions may be marked in the order of access. For example, when instructions A, B, C, and D are executed sequentially, instruction A may be marked with number 1, instruction B may be marked with number 2, instruction C may be marked with number 3, and instruction D may be marked with number 4. For another example, when instructions B and C are executed in a loop, instruction A may be marked with number 1, instruction B may be marked with number 2, instruction C may be marked with number 3, and instruction E in the first execution direction may be marked with number 4A, and instruction D in the second execution direction may be marked with number 4B. During the marking process, different marks may be set for each instruction to distinguish different instructions. Specific methods for marking instructions may include, but are not limited to, the above examples.
[0081] In an embodiment of the present invention, when instructions are accessed and identified in sequence according to the execution order of the instructions in a function, the instructions can be marked, and access can be stopped when the accessed instruction is marked, and access can be continued when the instruction is not marked, thereby avoiding repeated identification of the instructions and avoiding repeated recording of the instructions in the identification order, so as to improve the recognition efficiency of the instructions.
[0082] Step 103: When a dynamic jump instruction is identified, search in reverse order along the identification sequence to determine the target instruction corresponding to the first register read by the dynamic jump instruction.
[0083] Wherein, the target instruction is used to write the base address of the jump table to the second register being operated, so that other instructions between the target instruction and the dynamic jump instruction write the destination address in the jump table to the first register based on the base address in the second register for the jump instruction to read. In combination with the above example, the base address of the jump table remains unchanged during the program running process. In the execution order of each instruction in the function, the instruction before the dynamic jump instruction needs to obtain the base address of the jump table from the second register, determine the destination address based on the base address, and then write the destination address to the first register. Since the target instruction is used to write the base address of the jump table to the second register being operated, the relocation information of the target instruction points to the position of the jump table in the target file, which is the position of the base address of the jump table in the read-only data section.
[0084] In this embodiment, when the electronic device recognizes a dynamic jump instruction, it can start from the dynamic jump instruction and search in reverse order along the recognition order, and determine the target instruction corresponding to the first register read by the dynamic jump instruction from the recognized instructions that are located before the dynamic jump instruction in the recognition order to obtain the relocation information of the target instruction, and determine the position of the jump table in the read-only data section according to the relocation information of the target instruction.
[0085] Optionally, step 103 may include:
[0086] Access the identified instructions recorded in the identification sequence in reverse order along the identification sequence to determine the register operated by the identified instructions;
[0087] When the identified instruction passes data to the first register through the operated register, continue to access other identified instructions that pass data to the register operated by the identified instruction in reverse order along the identification order until the identified instruction of the target category is accessed, and the identified instruction of the target category is used as the target instruction.
[0088] Among them, the first register is used to store the destination address for the dynamic jump instruction to read when it is executed. Among the multiple instructions located before the dynamic jump instruction, generally only one specific instruction (the specific instruction is the target instruction) writes the base address of the jump table to the second register operated. One or more instructions located between the target instruction and the dynamic jump instruction can obtain the destination address by operating the base address in the second register, and write the destination address to the first register. The electronic device can access each identified instruction in reverse order along the recognition order, determine the register operated by the accessed identified instruction, and determine whether the register operated by the identified instruction participates in the process of writing data to the first register. If it participates, it means that the identified instruction is an instruction located between the dynamic jump instruction and the target instruction, or is a target instruction. When the identified instruction is an instruction of the target category, it means that the instruction is a target instruction that writes the base address of the jump table to the operated register (i.e., the second register).
[0089] In combination with the above example, if instruction A, instruction B, instruction C and instruction D are executed in sequence, when the electronic device identifies them in sequence according to the execution order, the recorded identification order is from instruction A to instruction D. When instruction D is identified as a dynamic jump instruction, instruction D can be used as the starting point, and the identified instructions in the identification order can be accessed in reverse order along the direction from instruction D to instruction A. The identified instructions are the instructions that have been recorded in the identification order. In the process of accessing each identified instruction, the register operated by the identified instruction can be determined. For example, the register operated by instruction C can be determined to determine whether instruction C transfers data to the first register through the operated register. If instruction C transfers data to the first register through the operated register, it means that instruction C and the operated register participate in the process of writing data to the first register. The electronic device can continue to access each identified instruction along the identification order from instruction D to instruction A. If a certain identified instruction and the operated register participate in the process of writing data to the first register and are instructions of the target category, the identified instruction is determined to be the target instruction.
[0090] The target class instruction is, for example, the assignment instruction described above, which is used to write the base address of the jump table into the second register. The target class instruction may also be other types of instructions for writing the base address of the jump table into the register, which is not limited in this embodiment.
[0091] Optionally, in the case where the identified instruction transfers data to the first register through the register operated by the identified instruction, continuing to access other identified instructions that transfer data to the register operated by the identified instruction in reverse order along the identification order until the identified instruction of the target category is accessed, the step of taking the identified instruction of the target category as the target instruction includes:
[0092] In the case where the accessed identified instruction is a load instruction that writes data to the first register, accessing in reverse order along the identification sequence to determine a shift instruction that writes data to the third register read by the load instruction;
[0093] The assignment instruction that writes data to the second register read by the shift instruction is determined by accessing it in reverse order along the identification sequence.
[0094] In one embodiment, the target instruction may be an assignment instruction. When the electronic device writes the destination address to the first register, it first obtains the base address of the jump table through the assignment instruction and writes the base address to the second register; then obtains the offset through the shift instruction, reads the base address from the second register, adds the base address and the offset to obtain the destination address, and writes the destination address to the third register; then, the load instruction reads the destination address from the third register and writes the destination address to the first register. Finally, the dynamic jump instruction can read the destination address from the first register and read the jump address from the jump table according to the destination address. Therefore, when the electronic device accesses the dynamic jump instruction, it can access it in reverse order along the recognition order to find and determine the assignment instruction related to the first register. In combination with the above example, instruction A, instruction B, instruction C and instruction D are executed sequentially, and the identification order recorded by the electronic device is from instruction D to instruction A. When the electronic device identifies instruction D as a dynamic jump instruction, it first accesses in reverse order along the identification order, determines at least one load instruction before the dynamic jump instruction in the identification order, determines the target load instruction that writes data to the first register from the at least one load instruction, and determines the third register read by the target load instruction. After accessing the target load instruction, continue to access in reverse order along the identification order, determine at least one shift instruction before the target load instruction, and determine the target shift instruction that writes data to the third register from the at least one shift instruction, and determine the second register read by the target shift instruction. After determining the target shift instruction and the second register, you can continue to access in reverse order along the identification order, determine at least one assignment instruction before the target shift instruction, determine the target assignment instruction that writes data to the second register from the at least one assignment instruction, and use the target assignment instruction as the target instruction.
[0095] Among them, all the instructions located before the dynamic jump instruction may include multiple assignment instructions, multiple shift instructions and multiple loading instructions. Among the multiple assignment instructions, multiple shift instructions and multiple loading instructions, only one of them participates in the process of writing the destination address to the first register. Therefore, in the process of determining the target assignment instruction, it is necessary to determine the target assignment instruction in combination with the register operated by each instruction.
[0096] In the embodiment of the present invention, the assignment instruction is determined by searching in reverse order along the recognition order of the instructions in combination with the registers operated by the instructions, so that the assignment instruction corresponding to the first register can be accurately found, thereby improving the accuracy of the search.
[0097] In practical applications, the specific process of writing the destination address to the first register can be set according to requirements, so the method of searching for the target instruction in reverse order along the recognition sequence can be adaptively adjusted according to the writing process of the destination address.
[0098] Step 104: Obtain relocation information of the target instruction from the target file, and obtain relocation information of other instructions included in the function, so as to obtain a jump table from the storage area.
[0099] In this embodiment, after determining the target instruction, the electronic device can obtain the relocation information of the target instruction from the target file. In combination with the above example, the relocation information of the instruction in the function is stored in the code section relocation information section of the target file. When the target instruction is an assignment instruction, the electronic device can obtain the relocation information of the assignment instruction from the code section relocation information section. The relocation information is the base address of the jump table in the target file. The specific method of obtaining the relocation information of the assignment instruction from the code section relocation information section can be set according to the needs, and this embodiment does not limit this.
[0100] At the same time, the electronic device can obtain the relocation information of other instructions included in the function. Optionally, the electronic device can traverse each instruction in the function, determine the instructions with relocation information, and then obtain the relocation information of the dynamic jump instruction and the relocation information of other instructions from the code section relocation information section. Part or all of the instructions in the function have relocation information, and the relocation information of each instruction points to a position in the read-only data section.
[0101] It should be noted that the step of obtaining the relocation information of other instructions in the function can be performed at any time point in the process of executing the jump table search method, for example, before step 104, and this embodiment does not limit this.
[0102] Step 105: Based on the relocation information of the target instruction and the relocation information of other instructions, determine the storage area of the jump table from the target file.
[0103] In one embodiment, the electronic device can determine the storage area of the jump table in the target file based on the relocation information of the target instruction and the relocation information of other instructions in the function. When the program includes multiple functions, steps 101 to 105 can be performed for each function respectively to determine the storage area of the jump table of the dynamic jump instruction included in each function.
[0104] Optionally, step 105 may include:
[0105] In the case where the relocation information of the other instructions includes the relocation information of the target class, determining the target relocation information from the relocation information of the target class;
[0106] Using the area between the address indicated by the relocation information of the target instruction and the address indicated by the target relocation information as a storage area;
[0107] The position indicated by the target category relocation information is located after the address indicated by the target instruction relocation information, and the target relocation information is the relocation information of the target category that is closest to the address indicated by the target instruction relocation information.
[0108] The relocation information points to a location in the read-only data section. When multiple instructions in a function have relocation information, the multiple relocation information points to an area in the read-only data section. For example, if the relocation information of instruction A points to the 6th byte in the read-only data section, the relocation information of instruction B points to the 14th byte in the read-only data section, and the relocation information of instruction C points to the 20th byte in the read-only data section, then the multiple relocation information points to an area from the 6th byte to the 20th byte in the read-only data section.
[0109] After determining the relocation information of the dynamic jump instruction and the relocation information of other instructions in the function, the electronic device can combine multiple relocation information to first determine the relocation information of the target category whose indicated position is located after the position indicated by the relocation information of the target instruction. For example, if the relocation information of the target instruction in the above example points to the 10th byte in the read-only data section, the relocation information of the target category is the relocation information of instruction B and instruction C. At this time, the electronic device can determine that the relocation information of instruction B is the target relocation information, and the address indicated by the relocation information of instruction B is closest to the address indicated by the relocation information of the target instruction. At this time, the electronic device can determine that the area from the 10th byte to the 13th byte in the read-only data section is the storage area of the jump table. Further, after determining the storage area of the jump table, the electronic device can read the storage area between the 10th byte and the 13th address in the read-only data section to obtain the content in the jump table of instruction D.
[0110] It should be noted that, when the address indicated by the relocation information of other instructions does not include the relocation information of the target category, the address indicated by the relocation information of the target instruction can be directly used as the storage area of the jump table. In combination with the above example, if the address indicated by the relocation information of the target instruction D is the 16th byte in the read-only data section, the storage area of the 16th byte can be directly used as the storage area of the jump table.
[0111] Optionally, after step 105, the method may further include:
[0112] Acquire at least one entry in the jump table from the storage area; the entry includes a jump address;
[0113] In the case where the jump address points to the location of the function in the object file, determine that the storage area is correct.
[0114] In one embodiment, after determining the storage area of the jump table in the target file, the electronic device can verify the determined storage area. In combination with the above example, after determining the storage area of the jump table in the read-only data section, the electronic device can obtain one byte of data from the storage area, and the byte of data includes a table entry in the jump table. If the jump address included in the table entry points to the position of the function in the target file, it is determined that the storage area of the jump table is correctly determined. Since the jump address of the dynamic jump instruction is located in the function, the jump address stored in each table entry in the jump table of the dynamic jump instruction is located in the function where the dynamic jump instruction is located. For example, after obtaining the jump table of instruction D, the electronic device can read one byte of content from the storage area from the 10th byte to the 13th byte in the read-only data section, and store one table entry in one byte of content. After reading the content in the table entry, it can be determined whether the jump address in the table entry is located at the position of the function in the target file. If so, it is determined that the storage area is the storage area corresponding to the jump table of instruction D. On the contrary, if the read jump address does not point to the location of the function in the target file, it means that the storage area is wrong, and the electronic device can output a notification message to inform the user that the storage area is determined incorrectly and does not correspond to the dynamic jump instruction.
[0115] In the embodiment of the present invention, after determining the storage area of the jump table of the dynamic jump instruction in the target file, the electronic device can verify the storage area, thereby avoiding obtaining an erroneous jump table.
[0116] Reference Figure 2 , Figure 2The present invention is a flow chart of a jump table search method according to an exemplary embodiment. In the method, the electronic device first executes the step of obtaining the relocation information of the instruction in the function, and obtains the relocation information of all the instructions with relocation information in the function, including the relocation information of the dynamic jump instruction and the relocation information of other instructions. Then, the electronic device can execute the step of identifying the instructions in the function and recording the identification order, and sequentially identify each instruction along the execution order of the instructions in the function, and record the identification order until the dynamic jump instruction is identified. After the dynamic jump instruction is identified, the step of determining the target load instruction can be executed, and the target load instruction for loading data to the first register can be determined by searching in reverse order along the identification order. After the target load instruction is found, the step of determining the target shift instruction can be executed, and the target load instruction for writing data to the third register can be determined by continuing to search in reverse order along the identification order according to the third register read by the target load instruction. After the target shift instruction is found, if the register read by the target shift instruction is not written by the stack instruction, the register read by the target shift instruction is determined to be the second register, and the target assignment instruction is determined according to the second register. On the contrary, if the register read by the target shift instruction is written by the stack instruction, the register read by the target shift instruction is determined to be the fourth register, and the reverse search is continued along the identification path to determine the stack instruction that performs the write operation on the fourth register, and then the second register read by the stack instruction is determined according to the reading order of the stack instruction, and the target assignment instruction corresponding to the second register is further determined. After determining the target assignment instruction, the storage area of the jump table in the target file is determined based on the relocation information of the target assignment instruction and the relocation information of other instructions.
[0117] In some cases, there may be a stack instruction after the target assignment instruction. After the target assignment instruction writes the base address to the second register, the stack instruction will store the base address in the second register into the stack, and during the execution of the target shift instruction, the base address is taken out from the stack, and the base address taken out from the stack is stored in the fourth register, and the target shift instruction reads the base address from the fourth register. At this time, after the target shift instruction is determined by reverse search, it is determined whether the data in the register read by the target shift instruction is written by the stack instruction. If it is not written by the stack instruction, it can be determined that the target shift instruction directly reads the base address from the second register, and the target assignment instruction is determined according to the second register. On the contrary, it is determined that the target shift instruction reads the base address from the fourth register, the stack instruction corresponding to the fourth register is determined, the corresponding second register is determined according to the stack instruction, and then the target assignment instruction is determined according to the second register. Further, the storage area of the jump table can be determined according to the relocation information of the target assignment instruction and the relocation information of other instructions.
[0118] In an embodiment of the present invention, the electronic device determines the function included in the target file, identifies the instructions in the function in sequence according to the execution order of the instructions in the function, and records the identification order. When a dynamic jump instruction is identified, the electronic device searches in reverse order along the identification order to determine the target instruction corresponding to the first register read by the dynamic jump instruction, obtains the relocation information of the target instruction from the target file, and obtains the relocation information of other instructions included in the function. Based on the relocation information of the target instruction and the relocation information of other instructions, the electronic device determines the storage area of the jump table from the target file. When searching for the jump table of the dynamic jump instruction, the electronic device determines the target instruction for obtaining the base address in combination with the register used when the dynamic jump instruction reads the jump table and the execution order of the instructions, and determines the position of the jump table in the target file according to the relocation information of the target instruction, so that the storage area of the jump table of the dynamic jump instruction in the target file can be quickly determined.
[0119] Reference Figure 3 , Figure 3 3 is a structural block diagram of a jump table search device according to an exemplary embodiment. The device 300 may include the following modules:
[0120] A first determining module 301 is used to determine the functions included in the target file;
[0121] The identification module 302 is used to identify the instructions in the function in sequence according to the execution order of the instructions in the function, and record the identification order;
[0122] The search module 303 is used to search in reverse order along the recognition sequence when a dynamic jump instruction is identified, and determine the target instruction corresponding to the first register read by the dynamic jump instruction; the target instruction is used to write the base address of the jump table to the operated second register, so that other instructions between the target instruction and the dynamic jump instruction write the destination address in the jump table to the first register based on the base address in the second register for the jump instruction to read;
[0123] An acquisition module 304 is used to acquire the relocation information of the target instruction from the target file, and acquire the relocation information of other instructions included in the function;
[0124] The second determination module 305 is used to determine the storage area of the jump table from the target file based on the relocation information of the target instruction and the relocation information of other instructions, so as to obtain the jump table from the storage area.
[0125] Optionally, the search module 303 includes:
[0126] A determination unit, used to access the identified instructions recorded in the identification sequence in reverse order along the identification sequence, and determine the register operated by the identified instruction;
[0127] An access unit is used to, when an identified instruction transfers data to a first register through the register operated by the identified instruction, continue to access other identified instructions that transfer data to the register operated by the identified instruction in reverse order along the identification order until an identified instruction of the target category is accessed, and use the identified instruction of the target category as the target instruction.
[0128] Optionally, the target instruction is an assignment instruction;
[0129] The access unit is specifically used to, when the identified instruction accessed is a load instruction that writes data to a first register, access in reverse order along the identification sequence to determine the shift instruction that writes data to a third register read by the load instruction; and access in reverse order along the identification sequence to determine the assignment instruction that writes data to a second register read by the shift instruction.
[0130] Optionally, the identification module 302 is specifically used to access the instructions in the function in sequence in the execution order, identify and mark the instructions when the accessed instructions are not marked, and record the instructions in the identification order; when the accessed instructions are marked or when a preset instruction is accessed, stop executing the steps of accessing the instructions in the function at the instruction; when a branch instruction is accessed, continue executing the steps of accessing the instructions in the function in each execution direction indicated by the branch instruction.
[0131] Optionally, the second determination module 305 is specifically used to determine the target relocation information from the relocation information of the target category when the relocation information of other instructions includes the relocation information of the target category; the area between the address indicated by the relocation information of the target instruction and the address indicated by the target relocation information is used as the storage area; wherein the position indicated by the relocation information of the target category is located after the address indicated by the relocation information of the target instruction, and the target relocation information is the relocation information in the relocation information of the target category that is closest to the address indicated by the relocation information of the target instruction.
[0132] Optionally, it also includes: a detection module, used to obtain at least one table entry in the jump table from the storage area; the table entry includes a jump address; when the jump address points to the position of the function in the target file, determine that the storage area is correct.
[0133] Figure 4 4 is a block diagram of an electronic device according to an exemplary embodiment. For example, the electronic device 400 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0134] Reference Figure 4, the electronic device 400 may include one or more of the following components: a processing component 402 , a memory 404 , a power component 406 , a multimedia component 408 , an audio component 410 , an input / output (I / O) interface 412 , a sensor component 414 , and a communication component 416 .
[0135] The processing component 402 generally controls the overall operation of the electronic device 400, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 402 may include one or more processors 420 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 402 may include one or more modules to facilitate the interaction between the processing component 402 and other components. For example, the processing component 402 may include a multimedia module to facilitate the interaction between the multimedia component 408 and the processing component 402.
[0136] The memory 404 is configured to store various types of data to support operations on the electronic device 400. Examples of such data include instructions for any application or method operating on the electronic device 400, contact data, phone book data, messages, pictures, videos, etc. The memory 404 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0137] The power supply component 406 provides power to the various components of the electronic device 400. The power supply component 406 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 400.
[0138] The multimedia component 408 includes a screen that provides an output interface between the electronic device 400 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 408 includes a front camera and / or a rear camera. When the electronic device 400 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and the rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0139] The audio component 410 is configured to output and / or input audio signals. For example, the audio component 410 includes a microphone (MIC), and when the electronic device 400 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 404 or sent via the communication component 416. In some embodiments, the audio component 410 also includes a speaker for outputting audio signals.
[0140] I / O interface 412 provides an interface between processing component 402 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0141] The sensor assembly 414 includes one or more sensors for providing various aspects of status assessment for the electronic device 400. For example, the sensor assembly 414 can detect the open / closed state of the electronic device 400, the relative positioning of the components, such as the display and keypad of the electronic device 400, and the sensor assembly 414 can also detect the position change of the electronic device 400 or a component of the electronic device 400, the presence or absence of contact between the user and the electronic device 400, the orientation or acceleration / deceleration of the electronic device 400, and the temperature change of the electronic device 400. The sensor assembly 414 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 414 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 414 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0142] The communication component 416 is configured to facilitate wired or wireless communication between the electronic device 400 and other devices. The electronic device 400 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 416 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 416 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0143] In an exemplary embodiment, the electronic device 400 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.
[0144] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 404 including instructions, and the instructions can be executed by a processor 420 of an electronic device 400 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0145] A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to perform a jump table search method, the method comprising:
[0146] Determine the functions included in the target file;
[0147] According to the execution order of the instructions in the function, identify the instructions in the function one by one and record the identification order;
[0148] In the case where a dynamic jump instruction is identified, searching in reverse order along the identification sequence to determine a target instruction corresponding to the first register read by the dynamic jump instruction; the target instruction is used to write a base address of the jump table to the operated second register, so that other instructions between the target instruction and the dynamic jump instruction write a destination address in the jump table to the first register based on the base address in the second register for the jump instruction to read;
[0149] Obtain relocation information of the target instruction from the target file, and obtain relocation information of other instructions included in the function;
[0150] Based on the relocation information of the target instruction and the relocation information of other instructions, a storage area of the jump table is determined from the target file to obtain the jump table from the storage area.
[0151] Optionally, when a dynamic jump instruction is identified, searching in reverse order along the identification order to determine a target instruction corresponding to the first register read by the dynamic jump instruction includes:
[0152] Access the identified instructions recorded in the identification sequence in reverse order along the identification sequence to determine the register operated by the identified instructions;
[0153] When the identified instruction passes data to the first register through the operated register, continue to access other identified instructions that pass data to the register operated by the identified instruction in reverse order along the identification order until the identified instruction of the target category is accessed, and the identified instruction of the target category is used as the target instruction.
[0154] Optionally, the target instruction is an assignment instruction; when the identified instruction transfers data to the first register through the operated register, continue to access other identified instructions that transfer data to the register operated by the identified instruction in reverse order along the identification order until the identified instruction of the target category is accessed, and take the identified instruction of the target category as the target instruction, including when the accessed identified instruction is a load instruction that writes data to the first register, access in reverse order along the identification order to determine the shift instruction that writes data to the third register read by the load instruction; access in reverse order along the identification order to determine the assignment instruction that writes data to the second register read by the shift instruction.
[0155] Optionally, the instructions in the function are identified in sequence according to the execution order of the instructions in the function, and the identification order is recorded, including: accessing the instructions in the function in sequence according to the execution order, identifying and marking the instructions when the accessed instructions are not marked, and recording the instructions in the identification order; when the accessed instructions are marked or when a preset instruction is accessed, stopping the step of accessing the instructions in the function at the instruction; when a branch instruction is accessed, continuing the step of accessing the instructions in the function in each execution direction indicated by the branch instruction.
[0156] Optionally, based on the relocation information of the target instruction and the relocation information of other instructions, the storage area of the jump table is determined from the target file, including: when the relocation information of other instructions includes the relocation information of the target category, the target relocation information is determined from the relocation information of the target category; the area between the address indicated by the relocation information of the target instruction and the address indicated by the target relocation information is used as the storage area; wherein the position indicated by the relocation information of the target category is located after the address indicated by the relocation information of the target instruction, and the target relocation information is the relocation information in the relocation information of the target category that is closest to the address indicated by the relocation information of the target instruction.
[0157] Optionally, the method further includes: acquiring at least one entry in a jump table from a storage area; the entry includes a jump address; and when the jump address points to a position of a function in a target file, determining that the storage area is correct.
[0158] 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.
[0159] It will be appreciated 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.
[0160] 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.
[0161] 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.
[0162] 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.
[0163] 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.
[0164] 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.
[0165] The jump table search method and device, an electronic device and a storage medium provided by the present invention are introduced in detail above. Specific examples are used in this article 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 method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A jump table search method, characterized in that: include: Determine the functions included in the target file; Identify the instructions in the function in sequence according to the execution order of the instructions in the function, and record the identification order; In the case of identifying a dynamic jump instruction, searching in reverse order along the identification order to determine a target instruction corresponding to the first register read by the dynamic jump instruction; the target instruction is used to write a base address of a jump table to the operated second register, so that other instructions between the target instruction and the dynamic jump instruction obtain the base address of the jump table from the second register, determine a destination address according to the base address, and then write the destination address to the first register for reading by the dynamic jump instruction; Obtaining relocation information of the target instruction from the target file, and obtaining relocation information of other instructions included in the function; Based on the relocation information of the target instruction and the relocation information of the other instructions, a storage area of the jump table is determined from the target file to obtain the jump table from the storage area.
2. The method according to claim 1, characterized in that The step of searching in reverse order along the recognition sequence to determine a target instruction corresponding to the first register read by the dynamic jump instruction comprises: Accessing the identified instructions recorded in the identification sequence in reverse order along the identification sequence to determine the register operated by the identified instructions; In the case where the identified instruction passes data to the first register through the register operated by the identified instruction, continue to access other identified instructions that pass data to the register operated by the identified instruction in reverse order along the identification order until the identified instruction of the target category is accessed, and the identified instruction of the target category is used as the target instruction.
3. The method according to claim 2, characterized in that The target instruction is an assignment instruction; In the case where the identified instruction transfers data to the first register through the operated register, continuing to access other identified instructions that transfer data to the register operated by the identified instruction in reverse order along the identification sequence until an identified instruction of the target category is accessed, and taking the identified instruction of the target category as the target instruction, comprises: In the case where the accessed identified instruction is a load instruction that writes data to the first register, accessing in reverse order along the identification sequence to determine a shift instruction that writes data to a third register read by the load instruction; The assignment instruction that determines to write data to the second register read by the shift instruction is accessed in reverse order along the identification sequence.
4. The method according to claim 1, characterized in that: The step of sequentially identifying the instructions in the function according to the execution order of the instructions in the function and recording the identification order includes: Accessing the instructions in the function in sequence according to the execution order, identifying and marking the instructions when the accessed instructions are not marked, and recording the instructions in the recognition order; When the accessed instruction is marked or a preset instruction is accessed, stopping the step of accessing the instruction in the function at the instruction; In the case of accessing a branch instruction, the step of accessing instructions in the function is continued in each execution direction indicated by the branch instruction.
5. The method according to claim 1, characterized in that The step of determining the storage area of the jump table from the target file based on the relocation information of the target instruction and the relocation information of the other instructions comprises: In a case where the relocation information of the other instructions includes the relocation information of the target class, determining the target relocation information from the relocation information of the target class; Using the area between the address indicated by the relocation information of the target instruction and the address indicated by the target relocation information as the storage area; The position indicated by the relocation information of the target category is located after the address indicated by the relocation information of the target instruction, and the target relocation information is the relocation information of the target category that is closest to the address indicated by the relocation information of the target instruction.
6. The method according to any one of claims 1 to 5, characterized in that After determining the storage area of the jump table from the target file, the method further includes: Acquire at least one entry in the jump table from the storage area; the entry includes a jump address; In the case where the jump address points to the location of the function in the target file, it is determined that the storage area is correct.
7. A jump table search device, characterized in that: include: A first determining module, used for determining functions included in a target file; An identification module, used to identify the instructions in the function in sequence according to the execution order of the instructions in the function, and record the identification order; A search module, for, when a dynamic jump instruction is identified, searching in reverse order along the identification sequence to determine a target instruction corresponding to the first register read by the dynamic jump instruction; the target instruction is used to write a base address of a jump table to the operated second register, so that other instructions between the target instruction and the dynamic jump instruction obtain the base address of the jump table from the second register, determine a destination address according to the base address, and then write the destination address to the first register for reading by the dynamic jump instruction; An acquisition module, used for acquiring the relocation information of the target instruction from the target file, and acquiring the relocation information of other instructions included in the function; The second determining module is used to determine the storage area of the jump table from the target file based on the relocation information of the target instruction and the relocation information of the other instructions, so as to obtain the jump table from the storage area.
8. The device according to claim 7, characterized in that The search module comprises: A determination unit, configured to access the identified instructions recorded in the identification sequence in reverse order along the identification sequence, and determine the register operated by the identified instruction; An access unit is used to, when the identified instruction passes data to the first register through the register operated by the identified instruction, continue to access other identified instructions that pass data to the register operated by the identified instruction in reverse order along the identification order, until an identified instruction of the target category is accessed, and use the identified instruction of the target category as the target instruction.
9. The device according to claim 8, characterized in that The target instruction is an assignment instruction; The access unit is specifically configured to, when the accessed identified instruction is a load instruction that writes data to the first register, access in reverse order along the identification sequence to determine a shift instruction that writes data to a third register read by the load instruction; The assignment instruction that determines to write data to the second register read by the shift instruction is accessed in reverse order along the identification sequence.
10. The device according to claim 7, characterized in that The identification module is specifically used to sequentially access the instructions in the function according to the execution order, identify and mark the instructions when the accessed instructions are not marked, and record the instructions into the identification order; When the accessed instruction is marked or a preset instruction is accessed, stopping the step of accessing the instruction in the function at the instruction; In the case of accessing a branch instruction, the step of accessing instructions in the function is continued in each execution direction indicated by the branch instruction.
11. The device according to claim 7, characterized in that The second determination module is specifically used to determine the target relocation information from the relocation information of the target category when the relocation information of the other instructions includes the relocation information of the target category; use the area between the address indicated by the relocation information of the target instruction and the address indicated by the target relocation information as the storage area; wherein the position indicated by the relocation information of the target category is located after the address indicated by the relocation information of the target instruction, and the target relocation information is the relocation information of the target category that is closest to the address indicated by the relocation information of the target instruction.
12. The device according to any one of claims 7 to 11, characterized in that Also includes: A detection module, configured to obtain at least one entry in the jump table from the storage area; The table entry includes a jump address; In the case where the jump address points to the location of the function in the target file, it is determined that the storage area is correct.
13. An electronic device, characterized in that: The system comprises a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors, wherein the one or more programs include instructions for performing the following operations: Determine the functions included in the target file; Identify the instructions in the function in sequence according to the execution order of the instructions in the function, and record the identification order; In the case of identifying a dynamic jump instruction, searching in reverse order along the identification order to determine a target instruction corresponding to the first register read by the dynamic jump instruction; the target instruction is used to write a base address of a jump table to the operated second register, so that other instructions between the target instruction and the dynamic jump instruction obtain the base address of the jump table from the second register, determine a destination address according to the base address, and then write the destination address to the first register for reading by the dynamic jump instruction; Obtaining relocation information of the target instruction from the target file, and obtaining relocation information of other instructions included in the function; Based on the relocation information of the target instruction and the relocation information of the other instructions, a storage area of the jump table is determined from the target file to obtain the jump table from the storage area.
14. A readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the jump table search method as described in one or more of method claims 1-6.
