Function identification method and device
By obtaining function features and simulated execution test cases in RTOS firmware, identifying functions in unsigned table information, solving the problem of not being able to identify RTOS firmware functions in the prior art, and improving the recognition efficiency and accuracy.
Patent Information
- Application Number
- CN202111624133.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2041-12-28
AI Technical Summary
The prior art cannot effectively identify functions in RTOS firmware with unsigned table information, resulting in the inappropriate method of function recognition in most RTOS firmware.
By obtaining the function characteristics of each function to be identified in the RTOS firmware, we judge whether there is a target preset function object in the preset function object collection, and use the test cases included in the target preset function object to simulate the recognition function and execute it according to the simulation. The result determines the function symbol of the function to be identified.
It realizes effective identification of functions in RTOS firmware without sign table information, improving the efficiency and accuracy of function recognition.
Smart Images

Figure CN114462042B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network security technology, and in particular to a function identification method and device. Background Art
[0002] Real-time operating systems (RTOS) are widely used in industrial control, aerospace, and power systems. In order to resist malicious attacks, security researchers have improved the security of a large number of RTOS-based software products by performing RTOS firmware reverse engineering and vulnerability analysis. Currently, the main method is to identify functions in RTOS firmware and then perform reverse engineering and vulnerability analysis on RTOS firmware.
[0003] In the related art, the symbol table information in the RTOS firmware is used to recover the functions in the firmware, so as to realize the recognition of the unsigned functions in the RTOS firmware.
[0004] However, since the above-mentioned related technologies need to use symbol table information to realize function recognition, considering that most RTOS firmwares have removed symbol table information, the function recognition method in the related technology is not applicable to most RTOS firmwares without symbol table information. Summary of the invention
[0005] The invention provides a function identification method and device, which are used to solve the defect that the prior art is not suitable for RTOS firmware without symbol table information, and realize the identification of functions in RTOS firmware without symbol table information.
[0006] The present invention provides a function identification method, comprising:
[0007] Obtain the function characteristics of each function to be identified in the RTOS firmware;
[0008] For any to-be-identified function in the RTOS firmware, determine whether there is a target preset function object in the preset function object set; wherein the target preset function object satisfies the function characteristics of the target preset function and matches the function characteristics of the to-be-identified function; and the target preset function has a function symbol;
[0009] When the target preset function object exists in the preset function object set, use N groups of test cases included in the target preset function object to perform function simulation execution on the to-be-identified function; wherein N is a positive integer greater than or equal to 1;
[0010] When the simulation execution results corresponding to each group of test cases successfully match the corresponding expected results, the function symbol of the function to be identified is determined according to the function symbol of the target preset function, and the function to be identified is identified based on the function symbol of the function to be identified.
[0011] According to a function identification method provided by the present invention, the preset function object set includes at least one preset function object;
[0012] Each preset function object corresponds to a preset function, and the preset function object includes: function characteristics of the preset function, at least one set of test cases and corresponding expected results.
[0013] According to a function identification method provided by the present invention, when the target preset function object exists in the preset function object set, using N groups of test cases included in the target preset function object to perform function simulation execution on the to-be-identified function, comprising:
[0014] When the target preset function object exists in the preset function object set, for any one of the N groups of test cases included in the target preset function object, the following function simulation execution process is performed: the parameters of the test case are set to the context of the function simulation execution environment, and the function to be identified is executed by function simulation, and the simulation execution result corresponding to the test case is obtained; if the simulation execution result does not match the expected result corresponding to the test case, it is determined that the test case fails to match; if the simulation execution result matches the expected result corresponding to the test case, it is determined that the test case matches successfully, and the above-mentioned function simulation execution is performed for the next group of test cases in the N groups of test cases, until the function simulation execution of the N groups of test cases is completed.
[0015] According to a function identification method provided by the present invention, the parameters of the test case are set in the context of a function simulation execution environment, and the function simulation executes the function to be identified, and obtains the simulation execution result corresponding to the test case, including:
[0016] Obtaining the architecture and bit information of the RTOS firmware;
[0017] Determine the parameter register and the return value register according to the architecture and bit information of the RTOS firmware;
[0018] According to the preset conditions in the test case, set the values of the parameters of the parameter registers to be used and the values in the memory;
[0019] Perform instruction-by-instruction simulation on the function to be identified; during the instruction-by-instruction simulation process, if the simulation execution of any instruction of the function to be identified fails, end the simulation execution of the function to be identified; if the simulation execution of all instructions of the function to be identified is successful, obtain the simulation execution result corresponding to the test case.
[0020] According to a function identification method provided by the present invention, the function features include: parameter features and return value features;
[0021] Among them, the parameter characteristics include: the number of parameters; the return value characteristics include: whether the function has a return value.
[0022] According to a function identification method provided by the present invention, the simulation execution result includes: a memory context result, and / or a function return value.
[0023] The present invention also provides a function recognition device, comprising:
[0024] An acquisition module is used to acquire the function characteristics of each function to be identified in the RTOS firmware;
[0025] A judgment module, for judging whether there is a target preset function object in the preset function object set for any to-be-identified function in the RTOS firmware; wherein the target preset function object satisfies the function characteristics of the target preset function and matches the function characteristics of the to-be-identified function; and the target preset function has a function symbol;
[0026] A processing module, configured to, when the target preset function object exists in the preset function object set, use N groups of test cases included in the target preset function object to perform function simulation execution on the to-be-identified function; wherein N is a positive integer greater than or equal to 1;
[0027] A determination module is used to determine the function symbol of the function to be identified according to the function symbol of the target preset function when the simulation execution results corresponding to each group of test cases successfully match the corresponding expected results, and identify the function to be identified based on the function symbol of the function to be identified.
[0028] According to a function identification device provided by the present invention, the preset function object set includes at least one preset function object;
[0029] Each preset function object corresponds to a preset function, and the preset function object includes: function characteristics of the preset function, at least one set of test cases and corresponding expected results.
[0030] According to a function recognition device provided by the present invention, the processing module is specifically used for:
[0031] When the target preset function object exists in the preset function object set, for any one of the N groups of test cases included in the target preset function object, the following function simulation execution process is performed: the parameters of the test case are set to the context of the function simulation execution environment, and the function to be identified is executed by function simulation, and the simulation execution result corresponding to the test case is obtained; if the simulation execution result does not match the expected result corresponding to the test case, it is determined that the test case fails to match; if the simulation execution result matches the expected result corresponding to the test case, it is determined that the test case matches successfully, and the above-mentioned function simulation execution is performed for the next group of test cases in the N groups of test cases, until the function simulation execution of the N groups of test cases is completed.
[0032] According to a function recognition device provided by the present invention, the processing module is specifically used for:
[0033] Obtaining the architecture and bit information of the RTOS firmware;
[0034] Determine the parameter register and the return value register according to the architecture and bit information of the RTOS firmware;
[0035] According to the preset conditions in the test case, set the values of the parameters of the parameter registers to be used and the values in the memory;
[0036] Perform instruction-by-instruction simulation on the function to be identified; during the instruction-by-instruction simulation process, if the simulation execution of any instruction of the function to be identified fails, end the simulation execution of the function to be identified; if the simulation execution of all instructions of the function to be identified is successful, obtain the simulation execution result corresponding to the test case.
[0037] According to a function identification device provided by the present invention, the function characteristics include: parameter characteristics and return value characteristics;
[0038] Among them, the parameter characteristics include: the number of parameters; the return value characteristics include: whether the function has a return value.
[0039] According to a function identification device provided by the present invention, the simulation execution result includes: a memory context result, and / or a function return value.
[0040] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any of the above-mentioned function identification methods are implemented.
[0041] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned function identification methods are implemented.
[0042] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the steps of any one of the function identification methods described above are implemented.
[0043] The function identification method and device provided by the present invention obtain the function characteristics of each function to be identified in the RTOS firmware. For any function to be identified, the preset function object corresponding to the preset function that matches the function characteristics in the preset function object set is used to determine the corresponding target preset function object for the function to be identified. Next, the function to be identified simulates and executes N groups of test cases corresponding to the target preset function, and determines the function identification result of the function to be identified based on the simulation execution results of the N groups of test cases. Function identification is achieved by matching the function characteristics of the function to be identified and simulating the execution of test cases, which effectively identifies the functions in the RTOS firmware while also improving the efficiency and accuracy of function identification. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0045] Figure 1 One of the flow charts of the function identification method provided by the present invention;
[0046] Figure 2 The second flowchart of the function identification method provided by the present invention;
[0047] Figure 3 The third flowchart of the function identification method provided by the present invention;
[0048] Figure 4 The fourth flowchart of the function identification method provided by the present invention;
[0049] Figure 5 The fifth flowchart of the function identification method provided by the present invention;
[0050] Figure 6 A schematic diagram of the structure of the function recognition device provided by the present invention;
[0051] Figure 7 This is a schematic structural diagram of an electronic device provided by the present invention. DETAILED DESCRIPTION
[0052] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0053] Combine the following Figure 1-Figure 5 The function identification method of the present invention is described.
[0054] Figure 1 One of the flow charts of the function identification method provided by the present invention is as follows: Figure 1 As shown, the function identification method includes:
[0055] Step 110, obtaining the function characteristics of each function to be identified in the RTOS firmware.
[0056] The execution subject of the present invention may be a processor, or a processing module disposed in the processor, wherein the processing module may be implemented by a combination of software and / or hardware.
[0057] A real-time operating system (RTOS) is an operating system that can accept and process external events or data at a fast enough speed when they occur, and its processing results can control the production process or respond quickly to the processing system within a specified time, schedule all available resources to complete real-time tasks, and control the coordinated operation of all real-time tasks.
[0058] RTOS firmware is a piece of code in the non-volatile memory of the real-time operating system. RTOS firmware consists of binary, and there is no symbol table information in most RTOS firmware.
[0059] Optionally, load the RTOS firmware into Ghidra to obtain the function list corresponding to the RTOS firmware and the function features of each function to be identified in the function list. Among them, the function list includes multiple functions to be identified and the function features corresponding to each function to be identified. It should be noted that Ghidra is a software reverse engineering framework. The framework includes a set of fully functional high-end software analysis tools that enable users to analyze compiled code on various platforms including Windows, MacOS and Linux. Ghidra's functions include disassembly, assembly, decompilation, drawing and scripting.
[0060] Optionally, the parameter feature of each function to be identified includes the number of parameters; and the return value feature of each function to be identified includes: whether the function to be identified has a return value.
[0061] Step 120, for any function to be identified in the RTOS firmware, determine whether there is a target preset function object in the preset function object set. The target preset function object satisfies the function characteristics of the target preset function and matches the function characteristics of the function to be identified; the target preset function has a function symbol.
[0062] Optionally, the preset function object set includes at least one preset function object. The preset function may be a commonly used library function, and all preset functions have function symbols. For example, the preset functions include functions such as memcpy and strcpy. The function symbol of the function memcpy is memcpy.
[0063] Optionally, the preset function object includes function characteristics of the preset function, at least one set of test cases and corresponding expected results.
[0064] Among them, for any function to be identified in the RTOS firmware, the target preset function object corresponding to the function to be identified is the preset function object corresponding to the preset function that matches the function feature of the function to be identified in the preset function object set. In other words, the preset function having the same function feature as the function to be identified is called the target preset function corresponding to the function to be identified, and the preset function object of the target preset function is called the target preset function object of the function to be identified.
[0065] Optionally, for any function to be identified in the RTOS firmware, by matching the function features of the preset functions corresponding to the multiple preset function objects in the preset function object set with the function features of the function to be identified one by one, it is determined whether there is a target preset function object corresponding to the function to be identified in the preset function object set. Specifically, if there is a preset function having the same function features as the function to be identified in the preset functions corresponding to the multiple preset function objects, then there is a target preset function object corresponding to the function to be identified in the preset function object set, and the preset function object corresponding to the preset function is called the target preset function object corresponding to the function to be identified; if there is no preset function having the same function features as the function to be identified in the preset functions corresponding to the multiple preset function objects, then there is no target preset function object corresponding to the function to be identified in the preset function object set.
[0066] Step 130: When there is a target preset function object in the preset function object set, use N groups of test cases included in the target preset function object to perform function simulation execution on the function to be identified, where N is a positive integer greater than or equal to 1.
[0067] Optionally, for any function to be identified in the RTOS firmware, when there is a target preset function object corresponding to the function to be identified in the preset function object set, the N groups of test cases included in the target preset function object are used to simulate the execution of the function to be identified to determine whether the function to be identified is the target preset function based on the result of the simulation execution, thereby realizing the identification of the function to be identified.
[0068] A possible implementation of simulating the execution of the function to be identified is described below as an example.
[0069] In one possible implementation, for any test case in the N groups of test cases, the number of parameters in the test case and the specific values of each parameter are used as parameters of the function to be identified and the function to be identified with the parameters is run (simulated execution). After running, the simulated execution result of the function to be identified for the test case is obtained.
[0070] Step 140, when the simulation execution results corresponding to each group of test cases successfully match the corresponding expected results, the function symbol of the function to be identified is determined according to the function symbol of the target preset function, and the function to be identified is identified based on the function symbol of the function to be identified.
[0071] Optionally, for any function to be identified in the RTOS firmware, on the basis that there is a target preset function object corresponding to the function to be identified in the preset function object set, the function to be identified is simulated and executed using N groups of test cases included in the target preset function object, and if the simulation execution results corresponding to each group of test cases successfully match the corresponding expected results, it is determined that the function to be identified has been identified, and the function to be identified is the target preset function corresponding to the target preset function object. In other words, the function to be identified is the target preset function.
[0072] A possible implementation method of determining the function symbol of the to-be-recognized function according to the function symbol of the target preset function is exemplarily described below.
[0073] In a possible implementation, the function symbol of the target preset function is used to determine the function symbol of the function to be identified. For example, if the function symbol of the target preset function is memcpy, the function symbol of the function to be identified is memcpy.
[0074] Optionally, after determining the function symbol of the function to be identified, an identification result corresponding to the function to be identified is output, the identification result including the function name (funcName), offset address (offset) and function signature (funcSign) of the target preset function;
[0075] For example, when the function symbol of the function to be identified is memcpy, the following content will be output:
[0076] {
[0077] "funcName":"strncmp",
[0078] "funcSign":"int strncmp(const char*s1,const char*s2,s ize_t n)",
[0079] "offset":"0x624ba4"
[0080] }
[0081] After determining the function symbol of the function to be identified, the function to be identified is then identified according to the function symbol. For details, reference may be made to the function identification method used for functions with function symbols in the prior art, and no limitation is made thereto.
[0082] The function identification method provided by the present invention obtains the function features of each function to be identified in the RTOS firmware. For any function to be identified, the preset function object corresponding to the preset function matching the function features in the preset function object set is used to determine the corresponding target preset function object for the function to be identified. Next, the function to be identified simulates and executes N groups of test cases corresponding to the target preset function, and determines the function identification result of the function to be identified based on the simulation execution results of the N groups of test cases. Function identification is achieved by matching the function features of the function to be identified and simulating the execution of test cases, which effectively identifies the functions in the RTOS firmware while also improving the efficiency and accuracy of function identification.
[0083] Optionally, Figure 2 The second flow chart of the function identification method provided by the present invention, in step 130, when there is a target preset function object in the preset function object set, for any group of test cases in the N groups of test cases included in the target preset function object, the following function simulation execution process is performed, which may include steps 210-230, wherein:
[0084] Step 210, setting the parameters of the test case into the context of the function simulation execution environment, and simulating the execution of the function to be identified, and obtaining the simulation execution result corresponding to the test case.
[0085] In this embodiment, the simulation execution environment may be Ghidra.
[0086] Optionally, in Ghidra, the parameters in the test case are set to the context of the function simulation execution environment. Specifically, according to the parameters of the test case, the same parameters are set in the corresponding multiple registers in Ghidra; and the parameters of the test case are input into the function to be identified and the function simulation execution of the function to be identified is performed to obtain the simulation execution result of the function to be identified for the test case.
[0087] Optionally, the simulation execution result includes: a memory context result, and / or a function return value.
[0088] Step 220 , determine whether the simulation execution result matches the expected result corresponding to the test case. If yes, execute step 230 , if not, execute step 240 .
[0089] Optionally, whether the test case is successfully matched is determined by judging whether the simulation execution result matches the expected result corresponding to the test case. That is, whether the simulation execution result is the same as the expected result corresponding to the test case is determined to be successfully matched. Specifically, if the simulation execution result is the same as the expected result corresponding to the test case, it is determined that the test case is successfully matched; if the simulation execution result is different from the expected result corresponding to the test case, it is determined that the test case is not matched.
[0090] Below, with examples, taking the target preset function as memcpy as an example, a possible implementation method for determining that the simulation execution result does not match the expected result corresponding to the test case is described.
[0091] First, let's briefly explain the memcpy function. The function signature format of memcpy is as follows: void*memcpy(void*destin,void*source,uint n). Among them, void* is used to indicate an untyped pointer, uint is used to indicate an unsigned integer, pointer destin is the destination pointer, and pointer source is the source pointer. The expected result of running the memcpy function is: copy the n bytes pointed to by the source pointer source to the memory location pointed to by the destination pointer dest in.
[0092] Next, we take a set of test cases corresponding to the target preset function memcpy as an example. The three parameters of the memcpy function are in order: a destination pointer pointing to 0x8000, a source pointer pointing to 0x4000, and 6. Assuming that the memory value corresponding to the memory address 0x8000 pointed to by the destination pointer is set to \00\00\00\00abc, and the memory value corresponding to the memory address 0x4000 pointed to by the source pointer is set to abcd\00a, the expected result corresponding to the test case is that the memory value corresponding to the memory address 0x8000 pointed to by the destination pointer is abcd\00ac. By taking the parameters in the test case as the parameters of the function to be identified and running this parameter, the simulation execution result of the function to be identified under the test case is obtained. Whether the test case is matched successfully is determined by whether the simulation execution result is the same as the expected result corresponding to the test case.
[0093] Step 230, determine whether the test case is matched successfully, and perform the above simulation execution for the next group of test cases in the N groups of test cases until the function simulation execution of the N groups of test cases is completed.
[0094] When the simulation execution result matches or is the same as the expected result corresponding to the test case, the test case is matched successfully, and the above function simulation execution is performed for the next group of test cases in the N groups of test cases until the function simulation execution of the N groups of test cases is completed.
[0095] Based on the example in step 220, when the simulation execution result corresponding to the function to be identified under the test case is abcd\00ac, that is, the simulation execution result is the same as the expected result, then it is determined that the test case is matched successfully. Further, the function to be identified performs the above simulation execution process for the next group of test cases in the N groups of test cases.
[0096] Step 240, determining that the test case matching fails.
[0097] In the case where the simulation execution result does not match or is not identical to the expected result corresponding to the test case, the test case matching fails.
[0098] Based on the example in step 220, when the simulation execution result corresponding to the to-be-identified function under the test case is not abcd\00ac, that is, the simulation execution result is different from the expected result, it is determined that the test case matching fails.
[0099] The function identification method provided by the present invention uses N groups of test cases included in the target preset function object to perform function simulation execution on the function to be identified. Once the simulation execution result does not match the expected result corresponding to the test case, it can be determined that the test case matching fails. This ensures the accuracy of function identification while reducing the probability of determining that the function to be identified fails.
[0100] Optionally, Figure 3 The third flow chart of the function recognition method provided by the present invention is as follows: Figure 3 As shown, the implementation of step 210 may include steps 310 to 340, wherein:
[0101] Step 310, obtaining the architecture and bit number information of the RTOS firmware.
[0102] Optionally, the RTOS firmware architecture information is the type of general processor used by the RTOS firmware, and the bit number information is the bit number of the general processor used by the RTOS firmware. For example, the architecture information and location information in the RTOS firmware are ARM32. The architecture information of the RTOS firmware is ARM, and the bit number information is 32. That is, the RTOS firmware needs to use a 32-bit ARM processor for simulation execution.
[0103] Step 320, determining the parameter register and the return value register according to the architecture and bit information of the RTOS firmware.
[0104] It should be noted that the architecture and location information in the RTOS firmware determines the number of parameter registers and which of the parameter registers the return value register is. In other words, if any of the architecture and location information in the RTOS firmware changes, the corresponding parameter register and return value register information will also change.
[0105] Below, taking the architecture and bit information of the RTOS firmware as ARM32 as an example, the implementation method of determining the parameter register and the return value register is explained.
[0106] It should be noted that ARM32 includes 15 registers, namely: R0-R12, SP (the Stack SP), LR (Link Register). Among them, ARM32 clearly stipulates that R0, R1, R2, and R3 among the 15 registers are used as function call parameters.
[0107] In a possible implementation, when the architecture and bit information of the RTOS firmware is ARM32, R0 is used as the return value register, and R0, R1, R2, and R3 are used as parameter registers. In other words, the function parameter values are set through registers R0, R1, R2, and R3, and the return value after the function simulation execution is stored through R0.
[0108] Step 330, according to the preset conditions in the test case, set the values of the parameters of the parameter registers to be used and the values in the memory.
[0109] Optionally, the preset conditions in the test case include parameter values in each parameter register and memory values corresponding to the parameter values.
[0110] In the following, taking the target preset function as the memcpy function as an example, an exemplary description is given of setting the parameter values of the parameter register to be used and the values in the memory.
[0111] The memcpy function has been briefly described in step 220, so it will not be repeated here.
[0112] Next, a set of test cases corresponding to the memcpy function is used as an example for explanation. A set of test cases is: the three parameters of the memcpy function are in order: a destination pointer pointing to 0x8000, a source pointer pointing to 0x4000, and 6. Assume that the memory value corresponding to the memory address 0x8000 pointed to by the destination pointer is set to \00\00\00\00abc, and the memory value corresponding to the memory address 0x4000 pointed to by the source pointer is set to abcd\00a, then the parameter values of the parameter registers to be used are set to: 0x8000, 0x4000, 6, and the memory value corresponding to the memory address 0x8000 pointed to by the destination pointer is set to \00\00\00\00abc, and the memory value corresponding to the memory address 0x4000 pointed to by the source pointer is set to abcd\00a.
[0113] Step 340 , perform instruction-by-instruction simulation for the function to be identified. During the instruction-by-instruction simulation process, determine whether the simulation execution of any instruction of the function to be identified fails. If so, execute step 350 ; if not, execute step 360 .
[0114] It should be noted that in the process of testing the function to be identified for the test case, a series of instructions need to be executed to complete the test for the test case. For example, the function of the function to be tested for the target preset function is to implement the addition operation of parameter a and parameter b, then the addition function of this target preset function may require dozens of instructions to implement, and this instruction can be a Pcode instruction in Ghidra.
[0115] Optionally, any function to be identified is executed instruction by instruction during the simulation execution of any group of test cases in the target preset function object. During the instruction-by-instruction simulation process, it is determined whether the simulation execution of any instruction of the function to be identified fails to determine subsequent operations.
[0116] Optionally, when the simulated execution output of any instruction reports an error, it can be determined that the simulated execution of the instruction has failed.
[0117] Step 350, ending the simulation execution of the function to be identified.
[0118] In this embodiment, when it is determined that the simulation execution of any instruction of the function to be identified fails, the simulation execution of the function to be identified is terminated.
[0119] Step 360, when the simulation execution of all instructions of the function to be identified is successful, the simulation execution result corresponding to the test case is obtained.
[0120] Optionally, the simulation execution result includes a memory context result and / or a function return value.
[0121] Optionally, when it is determined that the simulation execution of any instruction of the function to be identified is successful, the simulation execution result corresponding to the test case is obtained.
[0122] The function identification method provided by the present invention, in the process of simulating the execution of the function to be identified, sets the parameters of the test case to the context of the simulated execution environment according to the architecture and bit information of the RTOS firmware, simulates the execution of the function to be identified, and obtains the simulated execution result corresponding to the test case, which effectively simulates the context environment of the RTOS firmware for function execution, thereby effectively improving the recognition accuracy of the function identification method.
[0123] Next, through Figure 4-Figure 5 The process of the function identification method provided by the present invention is further described. Figure 4 The fourth flowchart of the function identification method provided by the present invention is as follows: Figure 5 This is the fifth flow chart of the function identification method provided by the present invention.
[0124] like Figure 4 As shown, the process of realizing function recognition of any function to be recognized in the function recognition method provided by the present invention includes the following steps:
[0125] Step 401, for any function to be identified in the RTOS firmware.
[0126] Step 402: determine whether there is a target preset function object corresponding to the function to be identified in the preset function object set.
[0127] Step 403, determining N groups of test cases corresponding to the target preset function object.
[0128] Step 404: perform function simulation execution on a group of test cases among the N groups of test cases corresponding to the target preset function object.
[0129] Step 405 , determining whether the function simulation execution of the test case for the function to be identified fails; if so, executing step 406 ; if not, executing step 407 .
[0130] Step 406, ending the function simulation execution for the function to be identified.
[0131] Step 407, determine whether the function simulation execution of N test cases has been completed for the function to be identified. If yes, execute steps 408-409; if no, execute step 404;
[0132] Step 408: successfully complete the identification of the function to be identified.
[0133] Step 409, determining the function symbol of the function to be identified.
[0134] Next, combine Figure 5 The specific implementation steps of simulating and executing any group of test cases corresponding to the target preset function object in step 403 are introduced, which specifically include the following steps:
[0135] Step 501, obtaining the architecture and bit number information of the RTOS firmware.
[0136] Step 502: Determine at least one register according to the architecture and bit number information of the RTOS firmware.
[0137] Step 503: Determine at least one input parameter register and return value register according to the architecture and bit number information of the RTOS firmware.
[0138] Step 504: according to the test case, access the parameter value to the input parameter register and write the memory value to the memory corresponding to the parameter value.
[0139] Step 505 , determine whether any instruction of the function to be identified fails during simulation execution. If yes, execute step 506 , if no, execute step 507 .
[0140] Step 506, ending the function simulation execution for the function to be identified.
[0141] Step 507, obtaining the simulation execution result corresponding to the test case.
[0142] The function recognition device provided by the present invention is described below. The function recognition device described below and the function recognition method described above can be referenced to each other.
[0143] The present invention provides a function recognition device. Figure 6 A schematic diagram of the structure of the function recognition device provided by the present invention is shown in FIG. Figure 6 As shown, the function recognition device 600 includes: an acquisition module 601, a judgment module 602, a processing module 603 and a determination module 604; wherein,
[0144] An acquisition module 601 is used to acquire function characteristics of each to-be-identified function in the RTOS firmware;
[0145] The judgment module 602 is used to judge whether there is a target preset function object in the preset function object set for any to-be-identified function in the RTOS firmware; wherein the target preset function object satisfies the function characteristics of the target preset function and matches the function characteristics of the to-be-identified function; and the target preset function has a function symbol;
[0146] The processing module 603 is used to perform function simulation execution on the to-be-identified function using N groups of test cases included in the target preset function object when the target preset function object exists in the preset function object set; wherein N is a positive integer greater than or equal to 1;
[0147] Determination module 604 is used to determine the function symbol of the function to be identified according to the function symbol of the target preset function when the simulation execution results corresponding to each group of test cases successfully match the corresponding expected results, and identify the function to be identified based on the function symbol of the function to be identified.
[0148] According to a function identification device provided by the present invention, the preset function object set includes at least one preset function object;
[0149] Each preset function object corresponds to a preset function, and the preset function object includes: function characteristics of the preset function, at least one set of test cases and corresponding expected results.
[0150] According to a function recognition device provided by the present invention, the processing module 603 is specifically used for:
[0151] When the target preset function object exists in the preset function object set, for any one of the N groups of test cases included in the target preset function object, the following function simulation execution process is performed: the parameters of the test case are set to the context of the function simulation execution environment, and the function to be identified is executed by function simulation, and the simulation execution result corresponding to the test case is obtained; if the simulation execution result does not match the expected result corresponding to the test case, it is determined that the test case fails to match; if the simulation execution result matches the expected result corresponding to the test case, it is determined that the test case matches successfully, and the above-mentioned function simulation execution is performed for the next group of test cases in the N groups of test cases, until the function simulation execution of the N groups of test cases is completed.
[0152] According to a function recognition device provided by the present invention, the processing module 603 is specifically used for:
[0153] Obtaining the architecture and bit information of the RTOS firmware;
[0154] Determine the parameter register and the return value register according to the architecture and bit information of the RTOS firmware;
[0155] According to the preset conditions in the test case, set the values of the parameters of the parameter registers to be used and the values in the memory;
[0156] Perform test case simulation one by one for the function to be identified; during the test case simulation process, if the simulation execution of any test case for the function to be identified fails, then end the simulation execution of the function to be identified; if the simulation execution of the test case for the function to be identified is successful, then obtain the simulation execution result corresponding to the test case.
[0157] According to a function identification device provided by the present invention, the function characteristics include: parameter characteristics and return value characteristics;
[0158] Among them, the parameter characteristics include: the number of parameters; the return value characteristics include: whether the function has a return value.
[0159] According to a function identification device provided by the present invention, the simulation execution result includes: a memory context result, and / or a function return value.
[0160] The function recognition device provided by the present invention obtains the function features of each function to be recognized in the RTOS firmware. For any function to be recognized, the preset function object corresponding to the preset function matching the function features in the preset function object set is used to determine the corresponding target preset function object for the function to be recognized. Next, the function to be recognized simulates and executes N groups of test cases corresponding to the target preset function, and determines the function recognition result of the function to be recognized based on the simulation execution results of the N groups of test cases. Function recognition is achieved by matching the function features of the function to be recognized and simulating the execution of test cases, which effectively recognizes the functions in the RTOS firmware while also improving the efficiency and accuracy of function recognition.
[0161] The function recognition device provided by the present invention can realize Figures 1 to 5 The various processes implemented by the method embodiment and achieving the same technical effect are not described here to avoid repetition.
[0162] Optionally, the present invention provides an electronic device, including a processor, a memory, and a program or instruction stored in the memory and executable on the processor. When the program or instruction is executed by the processor, each process of the above-mentioned function recognition method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0163] Figure 7 A schematic diagram of the physical structure of the electronic device provided by the present invention, such as Figure 7As shown, the electronic device 700 may include: a processor (processor) 710, a communication interface (Communications Interface) 720, a memory (memory) 730 and a communication bus 740, wherein the processor 710, the communication interface 720, and the memory 730 communicate with each other through the communication bus 740. The processor 710 can call the logic in the memory 730 to execute the function identification method, which includes: obtaining the function characteristics of each function in the RTOS firmware; for any function to be identified in the RTOS firmware, judging whether there is a target preset function object in the preset function object set; wherein the target preset function object satisfies the function characteristics of the target preset function and matches the function characteristics of the function to be identified; the target preset function has a function symbol; when there is a target preset function object in the preset function object set, the N groups of test cases included in the target preset function object are used to perform function simulation execution on the function to be identified; when the simulation execution results corresponding to each group of test cases are successfully matched with the corresponding expected results, the function symbol of the function to be identified is determined according to the function symbol of the target preset function, and the function to be identified is identified based on the function symbol of the function to be identified. In addition, the logic instructions in the above-mentioned memory 730 can be implemented in the form of software function units and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several test cases to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., various media that can store program codes.
[0164] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the function identification method provided by the above methods, and the function identification method includes: obtaining the function characteristics of each function in the RTOS firmware; for any function to be identified in the RTOS firmware, judging whether there is a target preset function object in the preset function object set; wherein the target preset function object satisfies the function characteristics of the target preset function and matches the function characteristics of the function to be identified; the target preset function has a function symbol; when the target preset function object exists in the preset function object set, using N groups of test cases included in the target preset function object to perform function simulation execution on the function to be identified; when the simulation execution results corresponding to each group of test cases successfully match the corresponding expected results, determining the function symbol of the function to be identified according to the function symbol of the target preset function, and identifying the function to be identified based on the function symbol of the function to be identified.
[0165] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the function identification method provided by the above-mentioned methods, the function identification method comprising: obtaining function characteristics of each function in the RTOS firmware; for any function to be identified in the RTOS firmware, determining whether there is a target preset function object in the preset function object set; wherein the target preset function object satisfies the function characteristics of the target preset function and matches the function characteristics of the function to be identified; the target preset function has a function symbol; when there is a target preset function object in the preset function object set, using N groups of test cases included in the target preset function object to perform function simulation execution on the function to be identified; when the simulation execution results corresponding to each group of test cases successfully match the corresponding expected results, determining the function symbol of the function to be identified according to the function symbol of the target preset function, and identifying the function to be identified based on the function symbol of the function to be identified.
[0166] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0167] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0168] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A function identification method, It is characterized in that include: Obtain the function characteristics of each function to be identified in the RTOS firmware; For any to-be-identified function in the RTOS firmware, determine whether there is a target preset function object in the preset function object set; wherein the target preset function object satisfies the function characteristics of the target preset function and matches the function characteristics of the to-be-identified function; and the target preset function has a function symbol; When the target preset function object exists in the preset function object set, use N groups of test cases included in the target preset function object to perform function simulation execution on the to-be-identified function; wherein N is a positive integer greater than or equal to 1; When the simulation execution results corresponding to each group of test cases successfully match the corresponding expected results, the function symbol of the to-be-identified function is determined according to the function symbol of the target preset function, and the to-be-identified function is identified based on the function symbol of the to-be-identified function; When the target preset function object exists in the preset function object set, using the N groups of test cases included in the target preset function object to perform function simulation execution on the to-be-identified function, comprising: When the target preset function object exists in the preset function object set, the following function simulation execution process is performed for any group of test cases in the N groups of test cases included in the target preset function object: the parameters of the test case are set to the context of the function simulation execution environment, and the function to be identified is executed by function simulation, and the simulation execution result corresponding to the test case is obtained.
2. The function identification method according to claim 1, It is characterized in that The preset function object set includes at least one preset function object; Each preset function object corresponds to a preset function, and the preset function object includes: function characteristics of the preset function, at least one set of test cases and corresponding expected results.
3. The function identification method according to claim 1, It is characterized in that The method further comprises: If the simulation execution result does not match the expected result corresponding to the test case, it is determined that the test case matches failed; if the simulation execution result matches the expected result corresponding to the test case, it is determined that the test case matches successfully, and the function simulation execution is performed for the next group of test cases in the N groups of test cases until the function simulation execution of the N groups of test cases is completed.
4. The function identification method according to claim 3, It is characterized in that The step of setting the parameters of the test case into the context of the function simulation execution environment, and performing function simulation execution of the function to be identified, and obtaining the simulation execution result corresponding to the test case, includes: Obtaining the architecture and bit information of the RTOS firmware; Determine the parameter register and the return value register according to the architecture and bit information of the RTOS firmware; According to the preset conditions in the test case, set the values of the parameters of the parameter registers to be used and the values in the memory; Perform instruction-by-instruction simulation on the function to be identified; during the instruction-by-instruction simulation process, if the simulation execution of any instruction of the function to be identified fails, end the simulation execution of the function to be identified; if the simulation execution of all instructions of the function to be identified is successful, obtain the simulation execution result corresponding to the test case.
5. The function identification method according to claim 1, It is characterized in that The function features include: parameter features and return value features; Among them, the parameter characteristics include: the number of parameters; the return value characteristics include: whether the function has a return value.
6. The function identification method according to claim 1, It is characterized in that The simulation execution result includes: memory context result, and / or function return value.
7. A function recognition device, It is characterized in that include: An acquisition module is used to acquire the function characteristics of each function to be identified in the RTOS firmware; A judgment module, for judging whether there is a target preset function object in the preset function object set for any to-be-identified function in the RTOS firmware; wherein the target preset function object satisfies the function characteristics of the target preset function and matches the function characteristics of the to-be-identified function; and the target preset function has a function symbol; A processing module, configured to, when the target preset function object exists in the preset function object set, use N groups of test cases included in the target preset function object to perform function simulation execution on the to-be-identified function; wherein N is a positive integer greater than or equal to 1; A determination module, used for determining the function symbol of the to-be-identified function according to the function symbol of the target preset function when the simulation execution results corresponding to each group of test cases all successfully match the corresponding expected results, and identifying the to-be-identified function based on the function symbol of the to-be-identified function; The processing module is specifically used for: When the target preset function object exists in the preset function object set, the following function simulation execution process is performed for any group of test cases in the N groups of test cases included in the target preset function object: the parameters of the test case are set to the context of the function simulation execution environment, and the function to be identified is executed by function simulation, and the simulation execution result corresponding to the test case is obtained.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the steps of the function identification method according to any one of claims 1 to 6 are implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the function identification method according to any one of claims 1 to 6 are implemented.
10. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the function identification method according to any one of claims 1 to 6 are implemented.
