Method, device, electronic device and storage medium for dynamically modifying instructions
By dynamically modifying the execution instructions of the target program in the VxWorks operating system, the cumbersome process of modifying the instruction in the prior art is solved, and the modification efficiency is improved.
Patent Information
- Application Number
- CN202011325988.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-23
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2040-11-23
AI Technical Summary
The prior art is cumbersome when modifying the execution instructions of programs in the VxWorks operating system, resulting in inefficiency.
By receiving commands, find the target function entry address of the target program, disassemble the target function, determine the target address of the instruction to be modified, and dynamically modify the instructions to achieve the execution instruction modification of the target program.
The steps of modifying program execution instructions are simplified, modification efficiency is improved, and space occupancy is reduced.
Smart Images

Figure CN114528200B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a method for dynamically modifying instructions, a device for dynamically modifying instructions, an electronic device and a storage medium. Background Art
[0002] VxWorks operating system is an embedded real-time operating system. It is widely used in high-tech fields with extremely high real-time requirements due to its good operability and real-time performance.
[0003] Generally speaking, for an application program running in a VxWorks operating system, it may be necessary to perform a test task on a program to test the stability and functional coverage of the program during operation. Usually, a tester is required to test the operation of the program by modifying the execution instructions of the program.
[0004] However, it is usually necessary to modify, compile, reload and execute the source code of a program or compile multiple redundant programs in order to complete the process of modifying the execution instructions of the program, thereby changing the execution behavior of the program to test the operation of the program. It can be seen that the current process of modifying the execution instructions of a program is relatively cumbersome, resulting in low modification efficiency. Summary of the invention
[0005] In view of the above problems, an embodiment of the present invention is proposed to provide a method for dynamically modifying instructions that overcomes the above problems or at least partially solves the above problems, so as to improve the efficiency of modifying the execution instructions of a program.
[0006] Correspondingly, an embodiment of the present invention further provides a device for dynamically modifying instructions, an electronic device and a storage medium to ensure the implementation and application of the above method.
[0007] In order to solve the above problem, an embodiment of the present invention discloses a method for dynamically modifying instructions, characterized in that it is applied to an electronic device running a VxWorks operating system, and the method includes:
[0008] receiving a first command, wherein the first command carries a program identifier of a target program, wherein the target program is a program running in the electronic device and including instructions to be modified;
[0009] In response to the first command, searching, according to the program identifier, in the memory of the VxWorks operating system for an entry address of a target function corresponding to the target program, wherein the target function includes an execution instruction of the target program;
[0010] According to the entry address of the target function, the target function is disassembled to obtain an assembly instruction set corresponding to the target function;
[0011] Determine, according to the assembly instruction set, a target address of the instruction to be modified in the memory;
[0012] The instruction to be modified stored at the target address is modified into a target instruction, so that the target program executes the target instruction.
[0013] The embodiment of the present invention further discloses a device for dynamically modifying instructions, which is applied to an electronic device running a VxWorks operating system, and the device includes:
[0014] A receiving module, configured to receive a first command, wherein the first command carries a program identifier of a target program, wherein the target program is a program running in the electronic device and including the instruction to be modified;
[0015] A search module, configured to search, in response to the first command, for an entry address of a target function corresponding to the target program in the memory of the VxWorks operating system according to the program identifier, wherein the target function includes an execution instruction of the target program;
[0016] A disassembly module, used for disassembling the target function according to the entry address of the target function to obtain an assembly instruction set corresponding to the target function;
[0017] A determination module, used to determine a target address of the instruction to be modified in the memory according to the assembly instruction set;
[0018] The modification module is used to modify the instruction to be modified stored at the target address into a target instruction, so that the target program executes the target instruction.
[0019] The embodiment of the present invention further discloses an electronic device, the electronic device comprising 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:
[0020] receiving a first command, wherein the first command carries a program identifier of a target program, wherein the target program is a program running in the electronic device and including instructions to be modified;
[0021] In response to the first command, searching, according to the program identifier, in the memory of the VxWorks operating system for an entry address of a target function corresponding to the target program, wherein the target function includes an execution instruction of the target program;
[0022] According to the entry address of the target function, the target function is disassembled to obtain an assembly instruction set corresponding to the target function;
[0023] Determine, according to the assembly instruction set, a target address of the instruction to be modified in the memory;
[0024] The instruction to be modified stored at the target address is modified into a target instruction, so that the target program executes the target instruction.
[0025] 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 methods for dynamically modifying instructions described in the embodiment of the present invention.
[0026] The embodiments of the present invention include the following advantages:
[0027] The embodiment of the present invention can respond to the first command, and according to the program identifier of the target program carried in the first command, search the entry address of the target function corresponding to the target program in the memory of the VxWorks operating system, and then disassemble the target function according to the entry address to obtain the assembly instruction set corresponding to the target function, and locate the target address of the instruction to be modified in the memory in the assembly instruction set, so as to modify the instruction to be modified stored at the target address to the target instruction. The target program is a program running in the electronic device and containing the instruction to be modified. Through the embodiment of the present invention, the instructions of the target program can be dynamically modified without modifying, compiling, reloading, etc. the source code of the target program, simplifying the steps of modifying the instruction to be modified to the target instruction, thereby improving the efficiency of the execution instruction of the modification program and reducing the space occupancy rate in the process of modifying the instruction. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 is a flowchart of a method for dynamically modifying instructions according to an embodiment of the present invention;
[0029] Figure 2 is a structural block diagram of an embodiment of a dynamic modification instruction device of the present invention;
[0030] Figure 3 The present invention is a structural block diagram of an electronic device for dynamically modifying instructions according to an exemplary embodiment. DETAILED DESCRIPTION
[0031] 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.
[0032] Method Embodiment
[0033] Reference Figure 1 , shows a flowchart of a method for dynamically modifying instructions according to an embodiment of the present invention, which is applied to an electronic device running a VxWorks operating system. The method may specifically include the following steps:
[0034] Step 101: receiving a first command, wherein the first command carries a program identifier of a target program, and the target program is a program running in the electronic device and including instructions to be modified.
[0035] The embodiments of the present invention can be applied to electronic devices running the VxWorks operating system. The electronic devices include, but are not limited to, servers, smart phones, voice recorders, tablet computers, e-book readers, MP3 (Moving Picture Experts Group Audio Layer III) players, MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, car computers, desktop computers, set-top boxes, smart TVs, wearable devices, and the like.
[0036] In an example of an embodiment of the present invention, the electronic device may be a Loongson platform equipped with a Loongson processor. Preferably, the processor may be a Loongson series processor, such as Loongson 1, Loongson 2 or Loongson 3, etc. The embodiment of the present invention does not limit the type of the processor.
[0037] In the VxWorks operating system, if a technician needs to modify the execution instructions of a program, it is usually necessary to recompile, modify, reload and execute the source code of the program and then compile multiple redundant programs. Obviously, the existing technology for modifying the execution instructions of the program has technical problems such as high difficulty, long time consumption, inflexibility, and waste of memory space. Especially when the technicians in this field perform test tasks on the program, such as testing the stability and functional coverage of the program by modifying the execution instructions of the program, the above-mentioned technical problems will greatly reduce the test efficiency, reduce the accuracy of the test results and consume a lot of manpower and material costs. Therefore, the present invention provides a method for dynamically modifying instructions to overcome the above-mentioned technical problems.
[0038] In the embodiment of the present invention, the program whose execution instructions need to be modified is called a target program, that is, the target program is a program running in the electronic device and containing instructions to be modified.
[0039] When a person skilled in the art needs to modify the instructions of the target program, a first command may be inputted at the electronic device running the VxWorks operating system, wherein the first command may be a system command in the VxWorks operating system, such as an lkAddr command, and the program identifier of the target program may be used as a parameter of the lkAddr command. The receiving of the first command may be receiving the lkAddr command carrying the program identifier of the target program.
[0040] Step 102, in response to the first command, according to the program identifier, searching the memory of the VxWorks operating system for an entry address of a target function corresponding to the target program, wherein the target function includes an execution instruction of the target program.
[0041] Optionally, the execution instructions include: operand logic calculation, conditional transfer, sequential execution and calling any one or more instructions of a non-target program.
[0042] The target program refers to a program that runs in an electronic device and contains instructions to be modified. The target program can be a set of a series of ordered instructions written to allow the electronic device to perform certain operations or solve a certain problem. A certain execution behavior can be achieved through one or more instructions. When designing the target program, writing a small program containing several instructions can perform a simple behavior, such as program a for performing operand logic calculations, program b for sequential execution, and program c for calling program A (the program A is a non-target program). Assembling multiple small programs can perform complex behaviors. For example, the target program can be a set of ordered instructions obtained by assembling the above-mentioned abc programs. The target program first performs the operand logic calculation behavior, then sequential execution, and finally executes the call to program A. The multiple small programs are collectively referred to as the target function. The target function contains the execution instructions of the target program and can control the execution behavior of the target program.
[0043] In response to the first command carrying the program identifier of the target program, the VxWorks operating system can display the symbol table of the target function in the memory, and search for the entry address of the target function in the symbol table in the memory. The symbol table is a data structure used in a language translator (such as a compiler and an interpreter). In the symbol table, each identifier of a function is bound to its declaration or usage information, such as its data type, scope, and memory address. The entry address of the target function can be obtained by searching the symbol table, and the entry address is the starting address of the function in the memory.
[0044] For example, the program identifier of the target program is addrTest, and in response to the first command: lkAddr addrTest, the symbol table of the target function corresponding to the target program in the memory is displayed:
[0045]
[0046]
[0047] Therefore, by querying the symbol table, it can be obtained that the entry address of the target function is 0xc0243370.
[0048] Step 103: disassemble the target function according to the entry address of the target function to obtain an assembly instruction set corresponding to the target function.
[0049] Since the instructions in the target function are stored in the memory in the form of binary code, in order to be able to find the target address corresponding to the instruction to be modified in the target function in the memory, the embodiment of the present invention disassembles the target function to obtain the assembly instruction set corresponding to the target function, and then the target address corresponding to the instruction to be modified can be found in the assembly instruction set.
[0050] Optionally, step 103 includes:
[0051] The entry address of the target function is input into the EJTAG (Enhanced Joint Test Action Group) tool, and the binary code of the target function is disassembled by the EJTAG tool to obtain the assembly instruction set corresponding to the target function. The EJTAG tool is a hardware / software subsystem that implements a set of hardware-based debugging features inside the processor to support on-chip debugging.
[0052] The disassembly refers to the process of converting the binary code of a function into assembly code, or the process of converting machine language code into assembly language code. By disassembling the target function, the binary code of the target function stored in the memory can be converted into an assembly instruction set in the form of assembly language code, that is, the executable target program is converted into a readable assembly language. By converting the binary code into assembly instructions, the target address corresponding to the instruction to be modified can be determined.
[0053] It should be noted that the disassembly tool used in the present invention generally refers to the ejtag tool, and may also be other disassembly tools, such as IDAPro, w32Dasm, etc. Through the disas command in the ejtag tool, the disassembly operation is performed starting from the entry address of the target function.
[0054] Step 104: Determine the target address of the instruction to be modified in the memory according to the assembly instruction set.
[0055] Optionally, step 104 includes:
[0056] Step 1041: Determine characteristic parameters in the instruction to be modified according to the keywords contained in the instruction to be modified.
[0057] In an example of the present invention, assuming that the instruction to be modified is "if(data<0xF000)" and the target instruction is "if(data>0x10)", that is, the instruction "if(data<0xF000)" in the target function needs to be dynamically modified to "if(data>0x10)". It should be noted that the embodiment of the present invention does not limit the type of programming language of the target program. In this example, taking C++ language as an example, the instruction to be modified "if(data<0xF000)" and the target instruction "if(data>0x10)" are both instructions written in C++ language.
[0058] In order to find the assembly instruction corresponding to the instruction to be modified in the assembly instruction set corresponding to the target function, the embodiment of the present invention determines a characteristic parameter in the instruction to be modified, and finds the assembly instruction corresponding to the instruction to be modified by matching the characteristic parameter in the assembly instruction set.
[0059] In an embodiment of the present invention, a characteristic parameter can be determined based on a keyword contained in the instruction to be modified, and the keyword includes but is not limited to an immediate number, an operator, an operand, etc. At least one keyword contained in the instruction to be modified can be used as a characteristic parameter. For example, for the instruction to be modified "if(data<0xF000)", the instruction contains an operator "if", an operand "data", an operator "<", and an immediate number "0xF000". In one example, it can be determined that the characteristic parameter of the instruction is "data<0xF000", and the characteristic parameter "data<0xF000" indicates that the value of the operand data is less than 0xF000. It can be understood that "<0xF000" can also be used as a characteristic parameter, or "if(data<0xF000)" can be used as a characteristic parameter, etc.
[0060] Step 1042: Match the characteristic parameter in the assembly instruction set to obtain a first assembly instruction containing the characteristic parameter.
[0061] By matching the characteristic parameters in the assembly instruction set, the first assembly instruction containing the characteristic parameters can be located. For example, for the C++ instruction "if(data<0xF000)" to be modified, the first assembly instruction matching the characteristic parameters can be located in the assembly instruction set according to the characteristic parameters "data<0xF000".
[0062] For example, the assembly instructions obtained after the binary code corresponding to the instruction to be modified "if (data < 0xF000)" is disassembled are as follows:
[0063] 0xffffffffc0243388:3402efff li v0,0xefff
[0064] 0xffffffffc024338c:0043102b sltu v0,v0,v1
[0065] 0xffffffffc0243390:1440003b bnez v0,c04ce010
[0066] The characteristic parameter "data<0xF000" is matched in the assembly instruction set corresponding to the target function. Since 0xefff is the value of 0xF000 minus 1, 0xefff is less than 0xF000. It can be determined that 0xefff matches the characteristic parameter "data<0xF000". Furthermore, the first assembly instruction containing the characteristic parameter "data<0xF000" can be determined in the assembly instruction set as: 0xffffffffc0243388:3402efff li v0, 0xefff.
[0067] Step 1043, obtaining a first address of the first assembly instruction in the memory.
[0068] The first address of the first assembly instruction in the memory can be obtained from the located first assembly instruction. For example, the first assembly instruction obtained in the above example is: 0xffffffffc0243388:3402efff li v0, 0xefff, and the first address of the instruction in the memory is 0xc0243388.
[0069] Step 1044: Determine the target address of the instruction to be modified in the memory according to the entry address of the target function and the first address.
[0070] In specific applications, a C++ instruction usually corresponds to multiple assembly instructions. For example, in the above example, the instruction to be modified "if (data < 0xF000)" corresponds to three assembly instructions. Therefore, after determining the first assembly instruction containing the characteristic parameter, all assembly instructions corresponding to the instruction to be modified can be determined based on the first address of the first assembly instruction and the number of the assembly instructions corresponding to the instruction to be modified.
[0071] Because all assembly instructions corresponding to the instruction to be modified are usually located before or after the first assembly instruction, the target addresses in the memory of all assembly instructions corresponding to the instruction to be modified can be determined based on the entry address of the target function and the first address.
[0072] Optionally, the step 1044 includes:
[0073] Step A1, determining the number of assembly instructions corresponding to the instruction to be modified.
[0074] For example, in the above example, after disassembling the binary code corresponding to the instruction to be modified "if (data < 0xF000)", the above three assembly instructions can be obtained, and it can be determined that the number of assembly instructions corresponding to the instruction to be modified "if (data < 0xF000)" is 3.
[0075] Step A2: determining a second assembly instruction in the assembly instruction set according to the first assembly instruction and the number of assembly instructions.
[0076] For example, the assembly instructions obtained after the binary code corresponding to the instruction to be modified "if (data < 0xF000)" is disassembled are as follows:
[0077] 0xffffffffc0243388:3402efff li v0,0xefff
[0078] 0xffffffffc024338c:0043102b sltu v0,v0,v1
[0079] 0xffffffffc0243390:1440003b bnez v0,c04ce010
[0080] The above three assembly instructions can be obtained by disassembling the binary code corresponding to the instruction to be modified "if(data<0xF000)". The first assembly instruction refers to the assembly instruction containing the characteristic parameter in all the assembly instructions corresponding to the instruction to be modified, and the second assembly instruction refers to the other assembly instructions except the first assembly instruction in all the assembly instructions corresponding to the instruction to be modified. In the above example, the first assembly instruction is: 0xffffffffc0243388:3402efff li v0, 0xefff. According to the number of assembly instructions corresponding to the first assembly instruction and the instruction to be modified "if(data<0xF000)", the second assembly instruction can be determined in the assembly instruction set of the target function. Since the number of assembly instructions corresponding to the instruction to be modified "if (data < 0xF000)" is 3, and the first assembly instruction is the first of the above three assembly instructions, it can be determined that the second assembly instruction is the other two of the above three assembly instructions, that is, the second assembly instruction includes: 0xffffffffc024338c: 0043102b sltu v0, v0, v1 and 0xffffffffc0243390: 1440003b bnezv0, c04ce010.
[0081] Step A3, obtaining a second address of the second assembly instruction in the memory.
[0082] As shown in the above example, the second assembly instruction includes: 0xffffffffc024338c:0043102b sltu v0, v0, v1 and 0xffffffffc0243390:1440003b bnez v0, c04ce010, then the second address of the second assembly instruction in the memory is 0xc024338c and 0xc0243390.
[0083] Step A4: determining the starting address and the ending address of the instruction to be modified in the memory according to the first address and the second address.
[0084] As shown in the above example, the first address of the assembly instruction corresponding to the instruction to be modified "if (data <0xF000)" is 0xc0243388, and the second address includes 0xc024338c and 0xc0243390. It can be determined that the starting address of the instruction to be modified in the memory is 0xc0243388, and the ending address is 0xc0243390.
[0085] Step A5: determining the target address of the instruction to be modified in the memory according to the starting address and the ending address.
[0086] According to the starting address and the ending address, it can be known that the assembly instruction corresponding to the instruction to be modified is:
[0087] 0xffffffffc0243388:3402efff li v0,0xefff
[0088] 0xffffffffc024338c:0043102b sltu v0,v0,v1
[0089] 0xffffffffc0243390:1440003b bnez v0,c04ce010
[0090] The target addresses of the instructions to be modified in the memory include: 0xc0243388, 0xc024338c, and 0xc0243390.
[0091] Step 105: modify the instruction to be modified stored at the target address into a target instruction, so that the target program executes the target instruction.
[0092] According to the format and size information in the instruction to be modified and the assembly instruction manual, the binary code corresponding to the instruction to be modified stored at the target address is modified to the binary code corresponding to the target instruction. Optionally, when there are multiple instructions to be modified, all the instructions to be modified are modified one by one.
[0093] For the instruction to be modified "if(data<0xF000)" in the above example, the corresponding target instruction is "if(data>0x10)", and the assembly instructions corresponding to the target instruction are as follows:
[0094] 0xffffffffc0243388:34020011li v0,0x11
[0095] 0xffffffffc024338c:0062102b sltu v0, v1, v0
[0096] 0xffffffffc0243390:1440003b bnez v0,c04ce010
[0097] Optionally, step 105 includes:
[0098] Step 1051, determine the binary code corresponding to the target instruction.
[0099] Step 1052: In response to the second command, modify the binary code of the instruction to be modified stored at the target address to the binary code corresponding to the target instruction.
[0100] In a specific application, the instructions of the program are stored in the form of binary codes. Therefore, the process of modifying the instruction to be modified into the target instruction may be: modifying the binary code of the instruction to be modified stored at the target address into the binary code corresponding to the target instruction.
[0101] In an embodiment of the present invention, the binary code corresponding to the target instruction can be pre-stored in a specified location in the memory. When it is necessary to modify the binary code of the instruction to be modified stored at the target address to the binary code corresponding to the target instruction, the binary code corresponding to the target instruction can be read from the specified location in the memory and written to the target address to achieve the modification of the binary code of the instruction to be modified stored at the target address to the binary code corresponding to the target instruction.
[0102] Of course, in a specific implementation, the binary code corresponding to the target instruction can also be directly written to the target address through a second command, and the second command is a command for writing content to a specified address in the memory. For example, the second command can be a copy command, an m command, etc. in the VxWorks operating system. Taking the m command as an example, the m command is as follows: m addr, [width]. This command indicates that the content of the addr address is modified according to the width. Using the m command provided in the VxWork system, 0x34020011, 0x62102b, and 1440003b can be written to addresses 0xc0243388, 0xc024338c, and 0xc0243390, respectively, to achieve the modification of the instruction to be modified "if (data <0xF000)" in the target program to the target instruction "if (data> 0x10)".
[0103] Optionally, since the third assembly instruction in the assembly instructions corresponding to the instruction to be modified and the target instruction in the above example is the same, that is, the assembly instructions corresponding to the addresses 1440003b and 0xc0243390 are the same, only the first two assembly instructions can be modified, that is, use the m command provided in the VxWorks operating system to write 0x34020011 and 0x62102b to addresses 0xc0243388 and 0xc024338c respectively.
[0104] Optionally, before modifying the instruction to be modified stored at the target address into the target instruction, the method further includes:
[0105] Step B1, detecting whether the target program is in a running state.
[0106] Step B2, when the target program is in a running state, suspending the running of the target program so that the target program is in a non-running state.
[0107] Optionally, modifying the instruction to be modified stored at the target address into a target instruction includes:
[0108] When the target program is not in a running state, the instruction to be modified stored at the target address is modified into a target instruction.
[0109] Optionally, after modifying the instruction to be modified stored at the target address into a target instruction, the method may further include: running the modified target program.
[0110] The method of the present invention can flexibly and dynamically modify the instruction to be modified into the target instruction, and after the modification is completed, the execution behavior of the target program can be changed by running the target program. Therefore, the present invention can quickly and dynamically change the execution behavior of the target program without recompiling, modifying, reloading and executing the source code of the target program.
[0111] It should be noted that during the modification process implemented in the present invention, the target program is in a stopped state. Therefore, before the modification, it is necessary to detect whether the target program is in a running state. When the target program is in a running state, the running of the target program can be suspended, and after the instructions to be modified in the target program are modified into target instructions, the target program can continue to be executed so that the target program executes the target instruction.
[0112] In summary, the embodiment of the present invention can respond to the first command, and according to the program identifier of the target program carried in the first command, search the entry address of the target function corresponding to the target program in the memory of the VxWorks operating system, and then disassemble the target function according to the entry address to obtain the assembly instruction set corresponding to the target function, and locate the target address of the instruction to be modified in the memory in the assembly instruction set, so as to modify the instruction to be modified stored at the target address to the target instruction. The target program is a program running in the electronic device and containing the instruction to be modified. Through the embodiment of the present invention, the instructions of the target program can be dynamically modified without modifying, compiling, reloading, etc. the source code of the target program, simplifying the steps of modifying the instruction to be modified to the target instruction, thereby improving the efficiency of the execution instruction of the modification program and reducing the space occupancy rate in the process of modifying the instruction.
[0113] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0114] Device Embodiment
[0115] Reference Figure 2 , shows a structural block diagram of an embodiment of a dynamic modification instruction device of the present invention, which is applied to an electronic device running a VxWorks operating system. The device may specifically include the following modules:
[0116] The receiving module 201 is used to receive a first command, wherein the first command carries a program identifier of a target program, and the target program is a program running in the electronic device and including an instruction to be modified;
[0117] A search module 202, configured to search, in response to the first command, for an entry address of a target function corresponding to the target program in the memory of the VxWorks operating system according to the program identifier, wherein the target function includes an execution instruction of the target program;
[0118] A disassembly module 203 is used to disassemble the target function according to the entry address of the target function to obtain an assembly instruction set corresponding to the target function;
[0119] A determination module 204, configured to determine a target address of the instruction to be modified in the memory according to the assembly instruction set;
[0120] The modification module 205 is used to modify the instruction to be modified stored at the target address into a target instruction, so that the target program executes the target instruction.
[0121] Optionally, the determining module 204 includes:
[0122] A first determination submodule, configured to determine characteristic parameters in the instruction to be modified according to keywords contained in the instruction to be modified;
[0123] A matching submodule, used for matching the characteristic parameter in the assembly instruction set to obtain a first assembly instruction containing the characteristic parameter;
[0124] An acquisition submodule, used for acquiring a first address of the first assembly instruction in the memory;
[0125] The second determining submodule is used to determine the target address of the instruction to be modified in the memory according to the entry address of the target function and the first address.
[0126] Optionally, the second determining submodule includes:
[0127] A first determining unit, used to determine the number of assembly instructions corresponding to the instruction to be modified;
[0128] A second determining unit, configured to determine a second assembly instruction in the assembly instruction set according to the first assembly instruction and the number of assembly instructions;
[0129] an acquiring unit, configured to acquire a second address of the second assembly instruction in the memory;
[0130] A third determining unit, configured to determine a starting address and an ending address of the instruction to be modified in the memory according to the first address and the second address;
[0131] A fourth determining unit is used to determine a target address of the instruction to be modified in the memory according to the starting address and the ending address.
[0132] Optionally, the modification module 205 includes:
[0133] A third determination submodule is used to determine the binary code corresponding to the target instruction;
[0134] The binary code modification submodule is used to modify the binary code of the instruction to be modified stored at the target address into the binary code corresponding to the target instruction in response to the second command.
[0135] Optionally, the device further comprises:
[0136] A detection module, used to detect whether the target program is in a running state;
[0137] A pause module, used for pausing the operation of the target program when the target program is in a running state, so that the target program is in a non-running state;
[0138] Optionally, the modification module 205 includes:
[0139] The modification submodule is used to modify the to-be-modified instruction stored at the target address into a target instruction when the target program is not in a running state.
[0140] Optionally, the disassembly module 203 includes:
[0141] The disassembly submodule is used to input the entry address of the target function into the ejtag tool, disassemble the target function through the ejtag tool, and obtain the assembly instruction set corresponding to the target function.
[0142] Optionally, the execution instructions include: operand logic calculation, conditional transfer, sequential execution and calling any one or more instructions of a non-target program.
[0143] In summary, the embodiment of the present invention can respond to the first command, and according to the program identifier of the target program carried in the first command, search the entry address of the target function corresponding to the target program in the memory of the VxWorks operating system, and then disassemble the target function according to the entry address to obtain the assembly instruction set corresponding to the target function, and locate the target address of the instruction to be modified in the memory in the assembly instruction set, so as to modify the instruction to be modified stored at the target address to the target instruction. The target program is a program running in the electronic device and containing the instruction to be modified. Through the embodiment of the present invention, the instructions of the target program can be dynamically modified without modifying, compiling, reloading, etc. the source code of the target program, simplifying the steps of modifying the instruction to be modified to the target instruction, thereby improving the efficiency of the execution instruction of the modification program and reducing the space occupancy rate in the process of modifying the instruction.
[0144] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0145] An embodiment of the present invention provides an electronic device, comprising 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: receiving a first command, wherein the first command carries a program identifier of a target program, wherein the target program is a program running in the electronic device and includes instructions to be modified; in response to the first command, searching, according to the program identifier, in the memory of the VxWorks operating system for an entry address of a target function corresponding to the target program, wherein the target function includes execution instructions of the target program; disassembling the target function according to the entry address of the target function to obtain an assembly instruction set corresponding to the target function; determining, according to the assembly instruction set, a target address of the instruction to be modified in the memory; and modifying the instruction to be modified stored at the target address into a target instruction, so that the target program executes the target instruction.
[0146] Figure 31 is a block diagram of an electronic device 300 for dynamically modifying instructions according to an exemplary embodiment. For example, the electronic device 300 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.
[0147] Reference Figure 3 , the electronic device 300 may include one or more of the following components: a processing component 302 , a memory 304 , a power component 306 , a multimedia component 308 , an audio component 310 , an input / output (I / O) interface 312 , a sensor component 314 , and a communication component 316 .
[0148] The processing component 302 generally controls the overall operation of the electronic device 300, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 302 may include one or more processors 320 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 302 may include one or more modules to facilitate the interaction between the processing component 302 and other components. For example, the processing component 302 may include a multimedia module to facilitate the interaction between the multimedia component 308 and the processing component 302.
[0149] The memory 304 is configured to store various types of data to support operations on the device 300. Examples of such data include instructions for any application or method operating on the electronic device 300, contact data, phone book data, messages, pictures, videos, etc. The memory 304 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.
[0150] The power component 304 provides power to the various components of the electronic device 300. The power component 304 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 300.
[0151] The multimedia component 308 includes a screen that provides an output interface between the electronic device 300 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 308 includes a front camera and / or a rear camera. When the electronic device 300 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 rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0152] The audio component 310 is configured to output and / or input audio signals. For example, the audio component 310 includes a microphone (MIC), and when the electronic device 300 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 304 or sent via the communication component 316. In some embodiments, the audio component 310 also includes a speaker for outputting audio signals.
[0153] I / O interface 312 provides an interface between processing component 302 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.
[0154] The sensor assembly 314 includes one or more sensors for providing various aspects of status assessment for the electronic device 300. For example, the sensor assembly 314 can detect the open / closed state of the device 300, the relative positioning of components, such as the display and keypad of the electronic device 300, and the sensor assembly 314 can also detect the position change of the electronic device 300 or a component of the electronic device 300, the presence or absence of user contact with the electronic device 300, the orientation or acceleration / deceleration of the electronic device 300, and the temperature change of the electronic device 300. The sensor assembly 314 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 314 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 314 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0155] The communication component 316 is configured to facilitate wired or wireless communication between the electronic device 300 and other devices. The electronic device 300 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 314 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 314 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.
[0156] In an exemplary embodiment, the electronic device 300 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.
[0157] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 304 including instructions, and the instructions can be executed by a processor 320 of an electronic device 300 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.
[0158] 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 method for dynamically modifying instructions, the method comprising:
[0159] receiving a first command, wherein the first command carries a program identifier of a target program, wherein the target program is a program running in the electronic device and including instructions to be modified;
[0160] In response to the first command, searching, according to the program identifier, in the memory of the VxWorks operating system for an entry address of a target function corresponding to the target program, wherein the target function includes an execution instruction of the target program;
[0161] According to the entry address of the target function, the target function is disassembled to obtain an assembly instruction set corresponding to the target function;
[0162] Determine, according to the assembly instruction set, a target address of the instruction to be modified in the memory;
[0163] The instruction to be modified stored at the target address is modified into a target instruction, so that the target program executes the target instruction.
[0164] 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.
[0165] 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.
[0166] 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.
[0167] 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.
[0168] 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.
[0169] 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.
[0170] 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.
[0171] The above is a detailed introduction to a method and device for dynamically modifying instructions, an electronic device and a storage medium provided by the present invention. 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 a person 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 method for dynamically modifying instructions, characterized in that: Applied to an electronic device running a VxWorks operating system, the method comprises: receiving a first command, wherein the first command carries a program identifier of a target program, wherein the target program is a program running in the electronic device and including instructions to be modified; In response to the first command, searching, according to the program identifier, in the memory of the VxWorks operating system for an entry address of a target function corresponding to the target program, wherein the target function includes an execution instruction of the target program; According to the entry address of the target function, the target function is disassembled to obtain an assembly instruction set corresponding to the target function; Determine, according to the assembly instruction set, a target address of the instruction to be modified in the memory; The instruction to be modified stored at the target address is modified into a target instruction, so that the target program executes the target instruction.
2. The method according to claim 1, characterized in that: Determining, according to the assembly instruction set, a target address of the instruction to be modified in the memory includes: Determining characteristic parameters in the instruction to be modified according to the keywords contained in the instruction to be modified; Matching the characteristic parameter in the assembly instruction set to obtain a first assembly instruction containing the characteristic parameter; Obtaining a first address of the first assembly instruction in the memory; A target address of the instruction to be modified in the memory is determined according to the entry address of the target function and the first address.
3. The method according to claim 2, characterized in that The step of determining the target address of the instruction to be modified in the memory according to the entry address of the target function and the first address includes: Determine the number of assembly instructions corresponding to the instruction to be modified; Determine a second assembly instruction in the assembly instruction set according to the first assembly instruction and the number of assembly instructions; Obtaining a second address of the second assembly instruction in the memory; Determine the starting address and the ending address of the instruction to be modified in the memory according to the first address and the second address; A target address of the instruction to be modified in the memory is determined according to the start address and the end address.
4. The method according to claim 1, characterized in that: The step of modifying the instruction to be modified stored at the target address into a target instruction comprises: Determine the binary code corresponding to the target instruction; In response to the second command, the binary code of the instruction to be modified stored at the target address is modified to the binary code corresponding to the target instruction.
5. The method according to any one of claims 1 to 4, characterized in that: Before modifying the instruction to be modified stored at the target address into the target instruction, the method further includes: Detecting whether the target program is in a running state; When the target program is in a running state, pausing the running of the target program so that the target program is in a non-running state; The step of modifying the instruction to be modified stored at the target address into a target instruction comprises: When the target program is not in a running state, the instruction to be modified stored at the target address is modified into a target instruction.
6. The method according to any one of claims 1 to 5, characterized in that: The execution instructions include: operand logic calculation, conditional transfer, sequential execution and calling any one or more instructions of a non-target program.
7. A device for dynamically modifying instructions, characterized in that: Applicable to an electronic device running a VxWorks operating system, the device comprising: A receiving module, configured to receive a first command, wherein the first command carries a program identifier of a target program, wherein the target program is a program running in the electronic device and including the instruction to be modified; A search module, configured to search, in response to the first command, for an entry address of a target function corresponding to the target program in the memory of the VxWorks operating system according to the program identifier, wherein the target function includes an execution instruction of the target program; A disassembly module, used for disassembling the target function according to the entry address of the target function to obtain an assembly instruction set corresponding to the target function; A determination module, used to determine a target address of the instruction to be modified in the memory according to the assembly instruction set; The modification module is used to modify the instruction to be modified stored at the target address into a target instruction, so that the target program executes the target instruction.
8. The device according to claim 7, characterized in that The determining module comprises: A first determination submodule, configured to determine characteristic parameters in the instruction to be modified according to keywords contained in the instruction to be modified; A matching submodule, used for matching the characteristic parameter in the assembly instruction set to obtain a first assembly instruction containing the characteristic parameter; An acquisition submodule, used for acquiring a first address of the first assembly instruction in the memory; The second determining submodule is used to determine the target address of the instruction to be modified in the memory according to the entry address of the target function and the first address.
9. The device according to claim 8, characterized in that The second determining submodule includes: A first determining unit, used to determine the number of assembly instructions corresponding to the instruction to be modified; A second determining unit, configured to determine a second assembly instruction in the assembly instruction set according to the first assembly instruction and the number of assembly instructions; an acquiring unit, configured to acquire a second address of the second assembly instruction in the memory; A third determining unit, configured to determine a starting address and an ending address of the instruction to be modified in the memory according to the first address and the second address; A fourth determining unit is used to determine a target address of the instruction to be modified in the memory according to the starting address and the ending address.
10. The device according to claim 7, characterized in that The modification module comprises: A third determination submodule is used to determine the binary code corresponding to the target instruction; The binary code modification submodule is used to modify the binary code of the instruction to be modified stored at the target address into the binary code corresponding to the target instruction in response to the second command.
11. The device according to any one of claims 7 to 10, characterized in that: The device also includes: A detection module, used to detect whether the target program is in a running state; A pause module, used for pausing the operation of the target program when the target program is in a running state, so that the target program is in a non-running state; The modification module comprises: The modification submodule is used to modify the to-be-modified instruction stored at the target address into a target instruction when the target program is not in a running state.
12. The device according to any one of claims 7 to 10, characterized in that: The execution instructions include: operand logic calculation, conditional transfer, sequential execution and calling any one or more instructions of a non-target program.
13. An electronic device, characterized in that: The electronic device includes 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, and the one or more programs include instructions for performing the following operations: receiving a first command, wherein the first command carries a program identifier of a target program, wherein the target program is a program running in the electronic device and including instructions to be modified; In response to the first command, searching, according to the program identifier, in the memory of the VxWorks operating system for an entry address of a target function corresponding to the target program, wherein the target function includes an execution instruction of the target program; According to the entry address of the target function, the target function is disassembled to obtain an assembly instruction set corresponding to the target function; Determine, according to the assembly instruction set, a target address of the instruction to be modified in the memory; The instruction to be modified stored at the target address is modified into a target instruction, so that the target program executes the target instruction.
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 method for dynamically modifying instructions as described in one or more of method claims 1-6.
Citation Information
Patent Citations
VxWorks operation system as well as method and device for configuring start waiting time thereof
CN102681858A
Computer program protection method and device, electronic equipment and computer readable storage medium
CN109740313A