CN114528200A - Method and device for dynamically modifying instruction, electronic equipment and storage medium - Google Patents

Method and device for dynamically modifying instruction, electronic equipment and storage medium Download PDF

Info

Publication number
CN114528200A
CN114528200A CN202011325988.0A CN202011325988A CN114528200A CN 114528200 A CN114528200 A CN 114528200A CN 202011325988 A CN202011325988 A CN 202011325988A CN 114528200 A CN114528200 A CN 114528200A
Authority
CN
China
Prior art keywords
instruction
target
address
program
modified
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011325988.0A
Other languages
Chinese (zh)
Inventor
袁俊卿
刘立超
丁克华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Loongson Technology Corp Ltd
Original Assignee
Loongson Technology Corp Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Loongson Technology Corp Ltd filed Critical Loongson Technology Corp Ltd
Priority to CN202011325988.0A priority Critical patent/CN114528200A/en
Publication of CN114528200A publication Critical patent/CN114528200A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3624Software debugging by performing operations on the source code, e.g. via a compiler
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/53Decompilation; Disassembly

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention provides a method, a device, electronic equipment and a storage medium for dynamically modifying an instruction, wherein the method comprises the following steps: receiving a first command, wherein the first command carries a program identifier of a target program, and the target program is a program which runs in the electronic equipment and contains an instruction to be modified; responding to the first command, and searching an entry address of a target function corresponding to the target program in a memory of the VxWorks operating system according to the program identifier, wherein the target function comprises an execution instruction 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 a target address of the instruction to be modified in the memory according to the assembly instruction set; and modifying the instruction to be modified stored in the target address into a target instruction so as to enable the target program to execute the target instruction. The embodiment of the invention can dynamically modify the instruction of the target program and improve the efficiency of modifying the execution instruction of the program.

Description

Method and device for dynamically modifying instruction, electronic equipment and storage medium
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method for dynamically modifying an instruction, an apparatus for dynamically modifying an instruction, an electronic device, and a storage medium.
Background
The VxWorks operating system is an embedded real-time operating system, and is widely applied to the technical field with high precision and extremely high real-time requirement due to good operability and real-time performance.
Generally, for an application program running in a VxWorks operating system, a test task may need to be performed on a program to test the stability and functional coverage of the program when running. Generally, a tester is required to test the operation condition of the program by modifying the execution instruction of the program.
However, it is usually necessary to modify, compile, reload and execute the source code of a program or compile redundant programs, etc. to complete the process of modifying the execution instructions of the program, and further change the execution behavior of the program, so as to test the running condition of the program. It can be seen that the current process of modifying the execution instruction of the program is cumbersome, resulting in low modification efficiency.
Disclosure of Invention
In view of the above, embodiments of the present invention are proposed to provide a method for dynamically modifying instructions that overcomes or at least partially solves the above mentioned problems, so as to improve the efficiency of modifying the execution instructions of a program.
Correspondingly, the embodiment of the invention also provides a device for dynamically modifying the instruction, electronic equipment and a storage medium, which are used for ensuring the realization and the application of the method.
In order to solve the above problem, the embodiment of the present invention discloses a method for dynamically modifying an instruction, which is characterized in that the method is applied to an electronic device running a VxWorks operating system, and the method includes:
receiving a first command, wherein the first command carries a program identifier of a target program, and the target program is a program which runs in the electronic equipment and contains an instruction to be modified;
responding to the first command, and searching an entry address of a target function corresponding to the target program in a memory of the VxWorks operating system according to the program identifier, wherein the target function comprises an execution instruction 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 a target address of the instruction to be modified in the memory according to the assembly instruction set;
and modifying the instruction to be modified stored in the target address into a target instruction so as to enable the target program to execute the target instruction.
The embodiment of the invention also discloses a device for dynamically modifying the instruction, which is applied to the electronic equipment for running the VxWorks operating system, and the device comprises:
a receiving module, configured to receive a first command, where the first command carries a program identifier of a target program, and the target program is a program that runs in the electronic device and includes an instruction to be modified;
the searching module is used for responding to the first command and searching an entry address of a target function corresponding to the target program in a memory of the VxWorks operating system according to the program identifier, wherein the target function comprises an execution instruction of the target program;
the disassembling module is used for disassembling the target function according to the entry address of the target function to obtain an assembling instruction set corresponding to the target function;
the determining module is used for determining the target address of the instruction to be modified in the memory according to the assembly instruction set;
and the modification module is used for modifying the instruction to be modified stored in the target address into a target instruction so as to enable the target program to execute the target instruction.
An embodiment of the present invention also discloses an electronic device, which includes a memory, and one or more programs, where the one or more programs are stored in the memory, and configured to be executed by one or more processors, and the one or more programs include instructions for:
receiving a first command, wherein the first command carries a program identifier of a target program, and the target program is a program which runs in the electronic equipment and contains an instruction to be modified;
responding to the first command, and searching an entry address of a target function corresponding to the target program in a memory of the VxWorks operating system according to the program identifier, wherein the target function comprises an execution instruction 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 a target address of the instruction to be modified in the memory according to the assembly instruction set;
and modifying the instruction to be modified stored in the target address into a target instruction so as to enable the target program to execute the target instruction.
The embodiment of the invention also discloses a readable storage medium, and when the instructions in the storage medium are executed by a processor of the electronic equipment, the electronic equipment can execute one or more methods for dynamically modifying the instructions in the embodiment of the invention.
The embodiment of the invention has the following advantages:
according to the embodiment of the invention, in response to the first command, according to the program identifier of the target program carried in the first command, the entry address of the target function corresponding to the target program is searched in the internal memory of the VxWorks operating system, then the target function can be disassembled according to the entry address, the assembly instruction set corresponding to the target function is obtained, and the target address of the instruction to be modified in the internal memory is positioned in the assembly instruction set, so that the instruction to be modified stored in the target address is modified into the target instruction. The target program is a program which runs in the electronic equipment and contains a command to be modified, and the command of the target program can be dynamically modified by the embodiment of the invention without modifying, compiling, reloading and other operations on a source code of the target program, so that the step of modifying the command to be modified into the target command is simplified, the efficiency of executing the command of the modified program can be improved, and the space occupancy rate in the command modifying process is reduced.
Drawings
FIG. 1 is a flow chart of the steps of a method embodiment of the present invention for dynamically modifying instructions;
FIG. 2 is a block diagram of an embodiment of an apparatus for dynamically modifying instructions according to the present invention;
FIG. 3 is a block diagram illustrating an electronic device for dynamically modifying instructions, according to an example embodiment.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below.
Method embodiment
Referring to fig. 1, a flowchart illustrating steps of an embodiment of a method for dynamically modifying an instruction according to the present invention is shown, and the method is applied to an electronic device running a VxWorks operating system, and specifically may include the following steps:
step 101, receiving a first command, where the first command carries a program identifier of a target program, and the target program is a program that runs in the electronic device and includes an instruction to be modified.
The embodiment of the invention can be applied to electronic equipment for running the VxWorks operating system. The electronic devices include, but are not limited to: a server, a smart phone, a recording pen, a tablet computer, an e-book reader, an MP3 (Moving Picture Experts Group Audio Layer III) player, an MP4 (Moving Picture Experts Group Audio Layer IV) player, a laptop, a car computer, a desktop computer, a set-top box, a smart tv, a wearable device, and the like.
In an example of the embodiment of the present invention, the electronic device may be a Loongson platform configured with a Loongson processor, and preferably, the processor may be a Loongson series processor, such as: no. 1, No. 2, or No. 3, and the like, and the embodiment of the present invention does not limit the type of the processor.
In a VxWorks operating system, if a technician needs to modify an execution instruction of a program, steps of recompiling, modifying, reloading and executing a source code of the program, then compiling redundant multiple programs and the like are generally needed, and obviously, the technical problems of high difficulty, long time consumption, inflexibility, waste of memory space and the like exist in the scheme for modifying the program execution instruction in the prior art. Especially when the skilled person performs test tasks on the program, such as: when the stability and the functional coverage of the program operation are tested by modifying the execution instruction of the program, the above technical problems can greatly reduce the testing efficiency, reduce the accuracy of the testing result and consume a large amount of manpower and material resources. Accordingly, the present invention provides a method for dynamically modifying instructions to overcome the above-mentioned problems.
In the embodiment of the present invention, a program that needs to modify an execution instruction is referred to as an object program, that is, the object program is a program that runs in the electronic device and includes an instruction to be modified.
When a person skilled in the art needs to modify an instruction of an object program, a first command may be input at the electronic device side running the VxWorks operating system, where the first command may be a system command in the VxWorks operating system, such as an lkAddr command, and a program identifier of the object program is used as a parameter of the lkAddr command. The receiving the first command may be receiving an lkAddr command carrying a program identifier of the target program.
And step 102, responding to the first command, and searching an entry address of a target function corresponding to the target program in a memory of the VxWorks operating system according to the program identifier, wherein the target function comprises an execution instruction of the target program.
Optionally, the executing the instruction includes: operand logic computation, conditional branching, sequential execution, and invocation of any one or more instructions in a non-target program.
The target program refers to a program which runs in the electronic device and contains instructions to be modified, the target program may be a set of a series of ordered instructions written for the electronic device to perform certain operations or solve a certain problem, a certain execution behavior may be realized through one or more instructions, when the design of the target program is carried out, a small program comprising a plurality of instructions can be written to execute a simple action, such as a program for performing operand logic calculations, b program for sequential execution, and c program for calling an a program (the a program is a non-target program), assembling a plurality of applets can perform complex behaviors, such as the target program can be a set of ordered instructions obtained by assembling the abc program, the target program performs the operand logic calculation first, then sequentially, and finally performs the call a procedure. The small programs are collectively called an objective function, and the objective function comprises an execution instruction of the objective program and can control the execution behavior of the objective program.
The VxWorks operating system can display the symbol table of the target function in the memory in response to the first command carrying the program identifier of the target program, and look up 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 (e.g., a compiler and an interpreter), in which each identifier of a function is bound with its declaration or usage information, such as its data type, scope, and memory address, and an entry address of a target function, which is a starting address of the function in the memory, can be obtained by looking up the symbol table.
For example, the program identification of the target program is addrTest, and in response to the first command: the lkAddr addrTest displays a symbol table of an object function corresponding to the object program in the memory:
Figure BDA0002794288580000051
Figure BDA0002794288580000061
therefore, the entry address of the target function is 0xc0243370 by querying the symbol table.
And 103, disassembling the target function according to the entry address of the target function to obtain an assembly instruction set corresponding to the target function.
Because the instructions in the target function are stored in the memory in the form of binary codes, in order 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 further can find the target address corresponding to the instruction to be modified in the assembly instruction set.
Optionally, the step 103 includes:
inputting the entry address of the target function into an ejtag (enhanced Joint Test Action group) tool, and disassembling the binary code of the target function through the ejtag tool to obtain an assembly instruction set corresponding to the target function. The ejtag tool is a hardware/software subsystem that implements a set of hardware-based debug features within the processor to support on-chip debugging.
The disassembling refers to a process of converting a binary code of a function into an assembly code, or a process of converting a machine language code into an assembly language code, and by disassembling a target function, the binary code of a target function stored in a memory can be converted into an assembly instruction set in the form of the assembly language code, that is, an executable target program is converted into a readable assembly language, and a target address corresponding to an instruction to be modified can be determined by converting the binary code into the assembly instruction.
It should be noted that the disassembling tool used in the present invention is generally referred to as ejtag tool, and may also be other disassembling tools, such as IDAPro, w32 darm, etc. And executing disassembling operation from the entry address of the target function through a disas command in the ejtag tool.
And 104, determining the target address of the instruction to be modified in the memory according to the assembly instruction set.
Optionally, the step 104 includes:
step 1041, determining a characteristic parameter in the instruction to be modified according to the keyword included in the instruction to be modified.
In one example of the present invention, it is assumed that the instruction to be modified is "if (data <0xF 000)", and the target instruction is "if (data >0x 10)", that is, the instruction "if (data <0xF 000)" in the target function needs to be dynamically modified into "if (data >0x 10)". It should be noted that the embodiment of the present invention does not limit the type of the programming language of the target program. In this example, taking the c + + language as an example, the instruction "if (data <0xF 000)" to be modified and the target instruction "if (data >0x 10)" are both instructions written in the c + + language.
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 invention determines the 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.
In the embodiment of the present invention, the characteristic parameter may be determined according to a key included in the instruction to be modified, where the key includes, but is not limited to, an immediate, an operator, an operand, and the like, and at least one key included in the instruction to be modified may be used as the characteristic parameter. For example, an instruction to be modified "if (data <0xF 000)" includes an operator "if", an operand "data", an operator "<", and an immediate "0 xF 000". In one example, a characteristic parameter of the instruction may be determined to be "data <0xF 000", the characteristic parameter "data <0xF 000" indicating that the value of the operand data is less than 0xF 000. It is to be understood that "< 0xF 000" may be used as the characteristic parameter, or "if (data <0xF 000)" may be used as the characteristic parameter, or the like.
Step 1042, matching the characteristic parameters in the assembly instruction set to obtain a first assembly instruction containing the characteristic parameters.
By matching the characteristic parameters in the assembly instruction set, a first assembly instruction including the characteristic parameters can be located, for example, for a c + + instruction "if (data <0xF 000)" to be modified, according to which the characteristic parameter "data <0xF 000" can be located in the assembly instruction set, a first assembly instruction matching the characteristic parameters can be located.
For example, an assembly instruction obtained after disassembling the binary code corresponding to the instruction "if (data <0xF 000)" to be modified is as follows:
0xffffffffc0243388:3402efff li v0,0xefff
0xffffffffc024338c:0043102b sltu v0,v0,v1
0xffffffffc0243390:1440003b bnez v0,c04ce010
matching a characteristic parameter "data <0xF 000" in an assembly instruction set corresponding to the objective function, where 0xefff is smaller than 0xF000 because 0xefff is a value of 0xF000 minus 1, and thus it can be determined that 0xefff matches the characteristic parameter "data <0xF 000", and further it can be determined that a first assembly instruction including the characteristic parameter "data <0xF 000" in the assembly instruction set is: 0xffffffffc 0243388: 3402 effli v0, 0 xefff.
In step 1043, a first address of the first assembly instruction in the memory is obtained.
The first address of the first assembler instruction in the memory can be obtained from the first assembler instruction obtained by positioning, where the first assembler instruction obtained in the above example is: 0xffffffffc 0243388: 3402 effli v0, 0xefff, the first address of the instruction in memory is 0xc 0243388.
Step 1044 is to determine a target address of the instruction to be modified in the memory according to the entry address of the target function and the first address.
In a particular application, a c + + instruction typically corresponds to a plurality of assembler instructions. For example, in the above example, the instruction to be modified "if (data <0xF 000)" corresponds to three assembly instructions. Therefore, after the first assembly instruction containing the characteristic parameters is determined, all assembly instructions corresponding to the instructions to be modified can be determined according to the first address of the first assembly instruction and the instruction number of the assembly instructions corresponding to the instructions to be modified.
Because all the assembler instructions corresponding to the instructions to be modified are usually in the front and back positions of the first assembler instruction, the target addresses of all the assembler instructions corresponding to the instructions to be modified in the memory can be determined according to the entry address of the target function and the first address.
Optionally, step 1044 includes:
step A1, determining the number of assembly instructions corresponding to the instruction to be modified.
For example, in the above example, after disassembling the binary code corresponding to the instruction "if (data <0xF 000)" to be modified, the above 3 assembly instructions can be obtained, and then the number of the assembly instructions corresponding to the instruction "if (data <0xF 000)" to be modified is determined to be 3.
Step a2, determining a second assembler instruction in the assembler instruction set according to the first assembler instruction and the assembler instruction number.
For example, an assembly instruction obtained after disassembling the binary code corresponding to the instruction "if (data <0xF 000)" to be modified is as follows:
0xffffffffc0243388:3402efff li v0,0xefff
0xffffffffc024338c:0043102b sltu v0,v0,v1
0xffffffffc0243390:1440003b bnez v0,c04ce010
the three assembly instructions can be obtained by disassembling the binary codes corresponding to the instructions to be modified, namely 'if (data <0xF 000)', where the first assembly instruction refers to the assembly instruction including the characteristic parameters in all the assembly instructions corresponding to the instructions to be modified, and the second assembly instruction refers to the assembly instructions except for the first assembly instruction in all the assembly instructions corresponding to the instructions to be modified. In the above example, the first assembler instruction is: 0xffffffffc 0243388: 3402 effli v0, 0 xefff. According to the number of assembly instructions corresponding to the first assembly instruction and the to-be-modified instruction "if (data <0xF 000)", a second assembly instruction can be determined in the assembly instruction set of the objective function. Since the number of assembly instructions corresponding to the instruction "if (data <0xF 000)" to be modified is 3, and the first assembly instruction is the first assembly instruction of the 3 assembly instructions, it may be determined that the second assembly instruction is the remaining two of the 3 assembly instructions, that is, the second assembly instruction includes: 0xffffffffc024338 c: 0043102b sltu v0, v0, v1 and 0 xffffffffffc 0243390: 1440003b bnez v0, c04ce 010.
Step a3, obtaining a second address of the second assembly instruction in the memory.
As shown in the above example, the second assembler instruction includes: 0xffffffffc024338 c: 0043102b sltu v0, v0, v1 and 0 xffffffffffc 0243390: 1440003b bnez v0, c04ce010, the second address of the second assembly instruction in the memory is 0xc024338c and 0xc 0243390.
Step a4, determining a start address and an end address of the instruction to be modified in the memory according to the first address and the second address.
As shown in the above example, the first address of the assembler instruction corresponding to the instruction "if (data <0xF 000)" to be modified is 0xc0243388, the second address includes 0xc024338c and 0xc0243390, and it can be determined that the start address of the instruction to be modified in the memory is 0xc0243388, and the end address is 0xc 0243390.
Step a5, determining a target address of the instruction to be modified in the memory according to the start address and the end address.
According to the starting address and the ending address, the assembly instruction corresponding to the instruction to be modified is known as follows:
0xffffffffc0243388:3402efff li v0,0xefff
0xffffffffc024338c:0043102b sltu v0,v0,v1
0xffffffffc0243390:1440003b bnez v0,c04ce010
the target address of the instruction to be modified in the memory comprises: 0xc0243388, 0xc024338c, 0xc 0243390.
Step 105, modifying the instruction to be modified stored in the target address into a target instruction, so that the target program executes the target instruction.
And modifying the binary codes corresponding to the instructions to be modified stored in the target address into the binary codes corresponding to the target instructions according to the format and size information in the instructions to be modified and the assembly instruction manual. Optionally, when the number of the instructions to be modified is multiple, all the instructions to be modified are modified one by one.
For the to-be-modified instruction "if (data <0xF 000)" in the above example, the target instruction corresponding to the target instruction is "if (data >0x 10)", and the target instruction corresponds to the assembler instruction as follows:
0xffffffffc0243388:34020011li v0,0x11
0xffffffffc024338c:0062102b sltu v0,v1,v0
0xffffffffc0243390:1440003b bnez v0,c04ce010
optionally, step 105 includes:
step 1051, determine the binary code corresponding to the target instruction.
Step 1052, in response to the second command, modifying the binary code of the instruction to be modified stored in the target address into the binary code corresponding to the target instruction.
In a specific application, the instructions of the program are stored in a binary code form, and therefore, the process of modifying the instructions to be modified into the target instructions may be: and modifying the binary code of the instruction to be modified stored in the target address into the binary code corresponding to the target instruction.
In the embodiment of the present invention, the binary code corresponding to the target instruction may be pre-stored in a designated location in the memory, and when the binary code of the instruction to be modified, which is stored in the target address, needs to be modified into the binary code corresponding to the target instruction, the binary code corresponding to the target instruction may be read from the designated location in the memory, and the target address is written into the binary code, so as to modify the binary code of the instruction to be modified, which is stored in the target address, into the binary code corresponding to the target instruction.
Of course, in a specific implementation, the binary code corresponding to the target instruction may also be directly written into the target address through a second command, where the second command is a command for writing content into a specified address in the memory. For example, the second command may be a copy command, an m command, etc. in a VxWorks operating system. Taking the m command as an example, the m command is specifically as follows: m addr, [ width ]. The command indicates to modify the contents of the addr address by width. 0x34020011, 0x62102b, and 1440003b can be written into addresses 0xc0243388, 0xc024338c, and 0xc0243390, respectively, using an m command provided in the vxword system to achieve modification of an instruction to be modified "if (data <0xF 000)" in the target program to a target instruction "if (data >0x 10)".
Alternatively, 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, 1440003b is the same as the assembly instruction corresponding to the address 0xc0243390, only the first two assembly instructions may be modified, that is, 0x34020011 and 0x62102b may be written into the addresses 0xc0243388 and 0xc024338c, respectively, using the m command provided in the VxWorks operating system.
Optionally, before modifying the instruction to be modified stored in the target address into the target instruction, the method further includes:
and step B1, detecting whether the target program is in a running state.
And step B2, in the case that the target program is in the running state, suspending the running of the target program so that the target program is in the non-running state.
Optionally, the modifying the instruction to be modified stored in the target address into the target instruction includes:
and under the condition that the target program is in a non-running state, modifying the instruction to be modified stored in the target address into a target instruction.
Optionally, after modifying the instruction to be modified stored in the target address to the target instruction, the method may further include: and running the modified target program.
The method of the invention can flexibly modify the instruction to be modified into the target instruction dynamically, and the execution behavior of the target program can be changed by operating the target program after the modification is completed. Therefore, the invention can rapidly and dynamically change the execution behavior of the target program under the condition of not needing steps of recompiling, modifying, reloading, executing and the like on the source code of the target program.
It should be noted that, in the modification process of the present invention, the target program is in a state of stopping running, and therefore, it is necessary to detect whether the target program is in a running state before modification, and in the case that the target program is in the running state, the running of the target program may be suspended, and after an instruction to be modified in the target program is modified into a target instruction, the target program continues to be executed, so that the target program executes the target instruction.
To sum up, in the embodiment of the present invention, in response to the first command, according to a program identifier of an object program carried in the first command, an entry address of an object function corresponding to the object program is searched in a memory of the VxWorks operating system, so that the object function can be disassembled according to the entry address to obtain an assembly instruction set corresponding to the object function, and a target address of an instruction to be modified in the memory is located in the assembly instruction set, so that the instruction to be modified, which is stored in the target address, is modified into the object instruction. The target program is a program which runs in the electronic equipment and contains a command to be modified, and the command of the target program can be dynamically modified by the embodiment of the invention without modifying, compiling, reloading and other operations on a source code of the target program, so that the step of modifying the command to be modified into the target command is simplified, the efficiency of executing the command of the modified program can be improved, and the space occupancy rate in the command modifying process is reduced.
It should be noted that, for simplicity of description, the method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present invention is not limited by the illustrated order of acts, as some steps may occur in other orders or concurrently in accordance with the embodiments of the present invention. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no particular act is required to implement the invention.
Apparatus embodiment
Referring to fig. 2, a block diagram of an embodiment of a dynamic modification instruction device according to the present invention is shown, and is applied to an electronic device running a VxWorks operating system, where the device may specifically include the following modules:
a receiving module 201, configured to receive a first command, where the first command carries a program identifier of a target program, and the target program is a program that runs in the electronic device and includes an instruction to be modified;
a searching module 202, configured to search, in response to the first command and according to the program identifier, an entry address of an object function corresponding to the object program in a memory of the VxWorks operating system, where the object function includes an execution instruction of the object program;
the disassembling module 203 is configured to disassemble the target function according to the entry address of the target function to obtain an assembling instruction set corresponding to the target function;
a determining module 204, configured to determine, according to the assembly instruction set, a target address of the instruction to be modified in the memory;
and a modifying module 205, configured to modify the instruction to be modified stored in the target address into a target instruction, so that the target program executes the target instruction.
Optionally, the determining module 204 includes:
the first determining submodule is used for determining the characteristic parameters in the instruction to be modified according to the keywords contained in the instruction to be modified;
the matching submodule is used for matching the characteristic parameters in the assembly instruction set to obtain a first assembly instruction containing the characteristic parameters;
the obtaining submodule is used for obtaining a first address of the first assembly instruction in the memory;
and the second determining submodule is used for 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.
Optionally, the second determining sub-module includes:
the first determining unit is used for determining the number of the assembly instructions corresponding to the instructions 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;
the obtaining unit is used for obtaining a second address of the second assembly instruction in the memory;
a third determining unit, configured to determine, according to the first address and the second address, a starting address and an ending address of the instruction to be modified in the memory;
and a fourth determining unit, configured to determine, according to the start address and the end address, a target address of the instruction to be modified in the memory.
Optionally, the modifying module 205 includes:
the third determining submodule is used for determining the binary code corresponding to the target instruction;
and the modified binary code submodule is used for responding to a second command and modifying the binary code of the instruction to be modified stored in the target address into the binary code corresponding to the target instruction.
Optionally, the apparatus further comprises:
the detection module is used for detecting whether the target program is in a running state;
the suspension module is used for suspending the operation of the target program under the condition that the target program is in the operation state, so that the target program is in the non-operation state;
optionally, the modifying module 205 includes:
and the modification submodule is used for modifying the instruction to be modified stored in the target address into the target instruction under the condition that the target program is in the non-running state.
Optionally, the disassembling module 203 includes:
and the disassembling sub-module is used for inputting the entry address of the target function into an ejtag tool, and disassembling the target function through the ejtag tool to obtain an assembling instruction set corresponding to the target function.
Optionally, the executing the instruction includes: operand logic computation, conditional branching, sequential execution, and invocation of any one or more instructions in a non-target program.
To sum up, in the embodiment of the present invention, in response to the first command, according to a program identifier of a target program carried in the first command, an entry address of the target function corresponding to the target program is searched in a memory of the VxWorks operating system, and then the target function may be disassembled according to the entry address to obtain an assembly instruction set corresponding to the target function, and a target address of an instruction to be modified in the memory is located in the assembly instruction set, so that the instruction to be modified, which is stored in the target address, is modified into the target instruction. The target program is a program which runs in the electronic equipment and contains a command to be modified, and the command of the target program can be dynamically modified by the embodiment of the invention without modifying, compiling, reloading and other operations on a source code of the target program, so that the step of modifying the command to be modified into the target command is simplified, the efficiency of executing the command of the modified program can be improved, and the space occupancy rate in the command modifying process is reduced.
For the device embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
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 the one or more programs configured to be executed by the one or more processors include instructions for: receiving a first command, wherein the first command carries a program identifier of a target program, and the target program is a program which runs in the electronic equipment and contains an instruction to be modified; responding to the first command, and searching an entry address of a target function corresponding to the target program in a memory of the VxWorks operating system according to the program identifier, wherein the target function comprises an execution instruction 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 a target address of the instruction to be modified in the memory according to the assembly instruction set; and modifying the instruction to be modified stored in the target address into a target instruction so as to enable the target program to execute the target instruction.
FIG. 3 is a block diagram illustrating an architecture of an electronic device 300 for dynamically modifying instructions, according to an example 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, an exercise device, a personal digital assistant, and the like.
Referring to fig. 3, electronic device 300 may include one or more of the following components: processing component 302, memory 304, power component 306, multimedia component 308, audio component 310, input/output (I/O) interface 312, sensor component 314, and communication component 316.
The processing component 302 generally controls overall operation of the electronic device 300, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing elements 302 may include one or more processors 320 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 302 can include one or more modules that facilitate interaction between the processing component 302 and other components. For example, the processing component 302 can include a multimedia module to facilitate interaction between the multimedia component 308 and the processing component 302.
The memory 304 is configured to store various types of data to support operations at the device 300. Examples of such data include instructions for any application or method operating on the electronic device 300, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 304 may be implemented by any type or combination of volatile or non-volatile memory devices, 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 or optical disks.
The power components 304 provide power to the various components of the electronic device 300. Power components 304 may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for electronic device 300.
The multimedia component 308 comprises a screen providing an output interface between the electronic device 300 and a 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 an input signal from a 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 boundary of a 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 facing camera and/or a rear facing camera. The front camera and/or the rear camera may receive external multimedia data when the electronic device 300 is in an operation mode, such as a photographing mode or a video mode. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
The audio component 310 is configured to output and/or input audio signals. For example, the audio component 310 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 300 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may further be stored in the memory 304 or transmitted via the communication component 316. In some embodiments, audio component 310 also includes a speaker for outputting audio signals.
The I/O interface 312 provides an interface between the processing component 302 and peripheral interface modules, which may be 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.
Sensor assembly 314 includes one or more sensors for providing various aspects of status assessment for electronic device 300. For example, sensor assembly 314 may detect an open/closed state of device 300, the relative positioning of components, such as a display and keypad of electronic device 300, sensor assembly 314 may also detect a change in the position of electronic device 300 or a component of electronic device 300, the presence or absence of user contact with electronic device 300, the orientation or acceleration/deceleration of electronic device 300, and a change in the temperature of electronic device 300. Sensor assembly 314 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 314 may also include a light 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.
The communication component 316 is configured to facilitate wired or wireless communication between the electronic device 300 and other devices. The electronic device 300 may 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 associated information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communications component 314 further includes a Near Field Communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
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, micro-controllers, microprocessors or other electronic components for performing the above-described methods.
In an exemplary embodiment, a non-transitory computer-readable storage medium comprising instructions, such as the memory 304, that are executable by the processor 320 of the electronic device 300 to perform the above-described method is also provided. For example, the non-transitory computer readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
A non-transitory computer readable storage medium in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform a method of dynamically modifying instructions, the method comprising:
receiving a first command, wherein the first command carries a program identifier of a target program, and the target program is a program which runs in the electronic equipment and contains an instruction to be modified;
responding to the first command, and searching an entry address of a target function corresponding to the target program in a memory of the VxWorks operating system according to the program identifier, wherein the target function comprises an execution instruction 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 a target address of the instruction to be modified in the memory according to the assembly instruction set;
and modifying the instruction to be modified stored in the target address into a target instruction so as to enable the target program to execute the target instruction.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
Embodiments of the present invention are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal to function in a predictive manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing terminal to cause a series of operational steps to be performed on the computer or other programmable terminal to produce a computer implemented process such that the instructions which execute on the computer or other programmable terminal provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the embodiments of the invention.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or terminal that comprises the element.
The present invention provides a method and apparatus for dynamically modifying instructions, an electronic device, and a storage medium, which are described in detail above, and the principles and embodiments of the present invention are explained herein by using specific examples, and the descriptions of the above examples are only used to help understand the method and the core ideas of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (14)

1. A method for dynamically modifying instructions is applied to an electronic device running a VxWorks operating system, and comprises the following steps:
receiving a first command, wherein the first command carries a program identifier of a target program, and the target program is a program which runs in the electronic equipment and contains an instruction to be modified;
responding to the first command, and searching an entry address of a target function corresponding to the target program in a memory of the VxWorks operating system according to the program identifier, wherein the target function comprises an execution instruction 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 a target address of the instruction to be modified in the memory according to the assembly instruction set;
and modifying the instruction to be modified stored in the target address into a target instruction so as to enable the target program to execute the target instruction.
2. The method of claim 1, wherein determining a target address in the memory of an instruction to be modified from the set of assembly instructions comprises:
determining characteristic parameters in the instruction to be modified according to keywords contained in the instruction to be modified;
matching the characteristic parameters in the assembly instruction set to obtain a first assembly instruction containing the characteristic parameters;
acquiring a first address of the first assembly instruction in the memory;
and 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.
3. The method of claim 2, wherein 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 comprises:
determining the number of assembly instructions corresponding to the to-be-modified instruction;
determining a second assembly instruction in the assembly instruction set according to the first assembly instruction and the assembly instruction number;
acquiring a second address of the second assembly instruction in the memory;
determining 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;
and determining the target address of the instruction to be modified in the memory according to the starting address and the ending address.
4. The method of claim 1, wherein modifying the instruction to be modified stored at the target address into a target instruction comprises:
determining a binary code corresponding to the target instruction;
and responding to a second command, and modifying the binary code of the instruction to be modified stored in the target address into the binary code corresponding to the target instruction.
5. The method according to any one of claims 1 to 4, wherein before modifying the instruction to be modified stored in the target address into a target instruction, the method further comprises:
detecting whether the target program is in a running state;
under the condition that the target program is in a running state, the running of the target program is suspended, so that the target program is in a non-running state;
the modifying the instruction to be modified stored in the target address into the target instruction comprises:
and under the condition that the target program is in a non-running state, modifying the instruction to be modified stored in the target address into a target instruction.
6. The method of any of claims 1 to 5, wherein executing the instruction comprises: operand logic computation, conditional branching, sequential execution, and invocation of any one or more instructions in a non-target program.
7. An apparatus for dynamically modifying an instruction, applied to an electronic device running a VxWorks operating system, the apparatus comprising:
a receiving module, configured to receive a first command, where the first command carries a program identifier of a target program, and the target program is a program that runs in the electronic device and includes an instruction to be modified;
the searching module is used for responding to the first command and searching an entry address of a target function corresponding to the target program in a memory of the VxWorks operating system according to the program identifier, wherein the target function comprises an execution instruction of the target program;
the disassembling module is used for disassembling the target function according to the entry address of the target function to obtain an assembling instruction set corresponding to the target function;
the determining module is used for determining the target address of the instruction to be modified in the memory according to the assembly instruction set;
and the modification module is used for modifying the instruction to be modified stored in the target address into a target instruction so as to enable the target program to execute the target instruction.
8. The apparatus of claim 7, wherein the determining module comprises:
the first determining submodule is used for determining the characteristic parameters in the instruction to be modified according to the keywords contained in the instruction to be modified;
the matching submodule is used for matching the characteristic parameters in the assembly instruction set to obtain a first assembly instruction containing the characteristic parameters;
the obtaining submodule is used for obtaining a first address of the first assembly instruction in the memory;
and the second determining submodule is used for 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.
9. The apparatus of claim 8, wherein the second determining submodule comprises:
the first determining unit is used for determining the number of the assembly instructions corresponding to the instructions 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;
the obtaining unit is used for obtaining a second address of the second assembly instruction in the memory;
a third determining unit, configured to determine, according to the first address and the second address, a starting address and an ending address of the instruction to be modified in the memory;
and a fourth determining unit, configured to determine, according to the start address and the end address, a target address of the instruction to be modified in the memory.
10. The apparatus of claim 7, wherein the modification module comprises:
the third determining submodule is used for determining the binary code corresponding to the target instruction;
and the modified binary code submodule is used for responding to a second command and modifying the binary code of the instruction to be modified stored in the target address into the binary code corresponding to the target instruction.
11. The apparatus of any one of claims 7 to 10, further comprising:
the detection module is used for detecting whether the target program is in a running state;
the suspension module is used for suspending the operation of the target program under the condition that the target program is in the operation state, so that the target program is in the non-operation state;
the modification module includes:
and the modification submodule is used for modifying the instruction to be modified stored in the target address into the target instruction under the condition that the target program is in the non-running state.
12. The apparatus of any of claims 7 to 10, wherein the instructions to execute comprise: operand logic computation, conditional branching, sequential execution, and invocation of any one or more instructions in a non-target program.
13. An electronic device comprising a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by one or more processors, the one or more programs comprising instructions for:
receiving a first command, wherein the first command carries a program identifier of a target program, and the target program is a program which runs in the electronic equipment and contains an instruction to be modified;
responding to the first command, and searching an entry address of a target function corresponding to the target program in a memory of the VxWorks operating system according to the program identifier, wherein the target function comprises an execution instruction 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 a target address of the instruction to be modified in the memory according to the assembly instruction set;
and modifying the instruction to be modified stored in the target address into a target instruction so as to enable the target program to execute the target instruction.
14. A readable storage medium, characterized in that instructions in the storage medium, when executed by a processor of an electronic device, enable the electronic device to perform a method of dynamically modifying instructions as recited in one or more of method claims 1-6.
CN202011325988.0A 2020-11-23 2020-11-23 Method and device for dynamically modifying instruction, electronic equipment and storage medium Pending CN114528200A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011325988.0A CN114528200A (en) 2020-11-23 2020-11-23 Method and device for dynamically modifying instruction, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011325988.0A CN114528200A (en) 2020-11-23 2020-11-23 Method and device for dynamically modifying instruction, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114528200A true CN114528200A (en) 2022-05-24

Family

ID=81618889

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011325988.0A Pending CN114528200A (en) 2020-11-23 2020-11-23 Method and device for dynamically modifying instruction, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114528200A (en)

Similar Documents

Publication Publication Date Title
EP2945058B1 (en) Processing method and device for application program
JP7315796B2 (en) Circuit principle diagram check method, device and system
CN111736916A (en) Dynamic expansion method and device based on Java language, electronic equipment and storage medium
CN109426504B (en) Program processing method, program processing device, electronic device and storage medium
CN113377370A (en) File processing method and device, electronic equipment and storage medium
CN111767058A (en) Program compiling method and device, electronic equipment and storage medium
CN111061452A (en) Voice control method and device of user interface
CN107450912A (en) Layout method, device and the terminal of the page
CN116069612A (en) Abnormality positioning method and device and electronic equipment
CN113010157A (en) Code generation method and device
CN104991857A (en) Method and apparatus for trace debugging
CN110874259A (en) Program execution method, device, equipment and storage medium
CN112631695B (en) Data verification method and device, electronic equipment and storage medium
CN111240927B (en) Method, device and storage medium for detecting time consumption of method in program
CN114528200A (en) Method and device for dynamically modifying instruction, electronic equipment and storage medium
CN112445484B (en) Register processing method and device, electronic equipment and storage medium
CN113420531A (en) Code text conversion method and device and storage medium
CN111459494A (en) Code processing method and device
CN111596949B (en) Method and device for developing application program
CN111273910B (en) Method, device and storage medium for acquiring resource number identifier
CN114020504B (en) Data processing method and device, electronic equipment and storage medium
CN112445483B (en) Instruction generation method and device, electronic equipment and storage medium
CN115658135A (en) Code analysis processing method and device and readable storage medium
CN113885938A (en) Code modification method and device, electronic equipment and storage medium
CN114546481A (en) Jump table lookup method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination