Method and device for modifying executable file and computer storage medium

By acquiring and analyzing assembly code in embedded software, generating machine code instructions and injecting executable files, the problem of flexibility and efficiency in modifying embedded software files in the existing technology is solved, and the ability to quickly modify and debug is achieved.

CN118535216APending Publication Date: 2024-08-23VITESCO AUTOMOTIVE ELECTRONICS (CHANGCHUN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310145548.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-02-21
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

The existing technology needs to rely on source code or reserved interfaces when modifying the executable file of embedded software, which is inflexible and time-consuming, especially in the case of multi-party cooperative development, and cannot quickly debug and check problems.

Method used

By obtaining the assembly code of the modified program fragment, analyze and process it into machine code instruction code and addressing information, combined with the executable file and target function information, determine the entry location, and inject the modified program into the executable file without using the source file. Fragment, change the function function, and realize the direct modification of the machine code file.

Benefits of technology

It realizes the rapid modification of executable files without relying on source code and reserved interfaces, saves debugging and testing time, improves the flexibility and efficiency of modification, and is suitable for updating executable files without source code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118535216A
    Figure CN118535216A
Patent Text Reader

Abstract

The invention relates to a method, a device and a computer storage medium for modifying executable files of embedded software. The method comprises the following steps: acquiring a modification fragment assembly code corresponding to at least one modification program fragment, wherein the modification fragment assembly code comprises an assembly instruction and addressing information thereof; analyzing and processing the modified fragment assembly code to obtain a machine code instruction code and addressing information for the modified program fragment; acquiring a file associated with the executable file; acquiring information of a target function related to modification of the program fragment; determining entry position information of the modification program fragment based on a file associated with the executable file and the information of the objective function; and modifying entry position information of the program fragment based on the machine code instruction code of the modified program fragment and the addressing information, and injecting at least one modified program fragment into the executable file without using the source file, so that at least part of function functions of the original executable file are changed.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] In the field of embedded software applications in motor vehicles, in particular in the field of D3 (Data-Driven Documents), microcontrollers, EPROMs or other types of programmable logic devices are usually programmed with executable files, such as S19 files.

[0003] In traditional technology, if you need to modify an executable file that has been generated, it is generally performed in two ways. The first way is to modify the source code file, and then regenerate the executable file through a compilation process. However, this method takes a lot of time to compile and other work, and is not suitable for quick debugging and problem checking. The second way is to provide fixed calibrable parameters to turn a function on or off, such as setting a corresponding flag bit. By changing the corresponding flag bit, related functions can be turned on or off, or different software branches can be selected. The second method can only predict the functions that need to be modified in advance, so it lacks flexibility and is time-consuming.

[0004] Moreover, when multiple organizations cooperate to develop the same software application, one of them may not open the source code. In this case, if modifications are needed, the only way is to rely on the party that does not open the source code to modify the source code or provide fixed calibratable parameters in advance.

[0005] Therefore, the solution for modifying the executable file of embedded software still needs to be improved. Summary of the invention

[0006] In order to solve the above-mentioned problems and defects, the present application proposes a method and a device for modifying an executable file of embedded software.

[0007] According to one aspect of the present application, a method for modifying an executable file of embedded software is provided, comprising:

[0008] Obtaining a modified fragment assembly code corresponding to at least one modified program fragment, the modified fragment assembly code including assembly instructions and addressing information thereof;

[0009] Analyzing and processing the modified segment assembly code to obtain machine code instruction code and addressing information for the modified program segment;

[0010] Obtaining files associated with the executable file;

[0011] Acquiring information of a target function related to the modified program fragment;

[0012] Determine entry location information of the modified program fragment based on information of a file associated with the executable file and a target function;

[0013] Based on the machine code instruction code and addressing information of the modified program fragment and the entry position information of the modified program fragment, at least one modified program fragment is injected into the executable file without using the source file, so that at least part of the function of the original executable file is changed.

[0014] According to another aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored. The computer program includes executable instructions. When the executable instructions are executed by a processor, the method described above is implemented.

[0015] According to another aspect of the present application, an electronic device is provided, which includes a processor and a memory for storing executable instructions of the processor, wherein the processor is configured to execute the executable instructions to implement the method as described above.

[0016] In the present application, at least one modification program fragment is injected into the executable file without using the source file, so that at least part of the function of the original executable file is changed. In other words, the modification or update of the executable file is achieved without relying on the source code or the reserved interface. Here, the final executable file, that is, the machine code file, such as the S19 file, is modified directly, eliminating the link of compiling, linking or recalibrating, and facilitating the debugger to quickly modify the code logic to complete the debugging work. Therefore, not only can the debugging and testing time be saved, but also the executable file can be updated without the source code. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The above-mentioned features and other features and advantages of the present application will be more intuitively presented through exemplary embodiments described in detail with reference to the accompanying drawings.

[0018] Figure 1 is a schematic flow chart of a method according to an embodiment of the present application.

[0019] Figure 2 is a schematic flow chart of a method according to another embodiment of the present application.

[0020] Figure 3 is a schematic structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0021] The exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, the exemplary embodiments can be implemented in a variety of forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided to make the content of this application comprehensive and complete and to fully convey the concepts of the exemplary embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar structures, and thus their repeated description will be omitted.

[0022] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, elements, etc. can be adopted. In other cases, known structures, methods or operations are not shown or described in detail to avoid blurring the various aspects of the application.

[0023] This application takes the injection modification of executable files, such as S19 files, as an example to introduce a method and device for modifying executable files of embedded software. The method and device can be used in embedded software applications, especially in the field of embedded software applications for motor vehicles. S19 files are a file format created by Motorola, which transmits binary information in the form of ASCII (American Standard Code for Information Interchange) hexadecimal text. It is usually used to program microcontrollers, EPROMs and other types of programmable logic devices. Files in S19 format are common data formats in the embedded software industry. The content is a text-based string. Each line of the file describes the address of the control chip and the content that will be burned into the address, that is, pure machine code. The content burned in is generally a hexadecimal expression of the machine code that can be recognized by the main control chip. Generally, to obtain a usable executable file, you must first use a programming tool to write the program source code. The program source code then undergoes compilation, linking, positioning and other processes to obtain the corresponding executable file.

[0024] For the generated executable file, it is usually accompanied by a corresponding ELF file. ELF file is a file format for binary files, executable files, object codes, shared libraries and core dump format files. The ELF file generally contains a hash table about function addresses.

[0025] In application, it is often necessary to readjust or modify the embedded software application. That is to say, when an executable file has been generated by the source code, the application needs to be adjusted or modified. For example, it is necessary to modify a specific software function, such as simply shielding a specific software function, modifying the parameters of a specific software function, adding or reducing control logic, adding or reducing functions, etc. In this case, if the modification is made on the basis of the program source code, on the one hand, the modification process is time-consuming and laborious because the program source code file needs to go through the processes of compilation, linking, positioning, etc. On the other hand, in the case where the program source code file cannot be obtained, for example, when the partner does not open the program source code file, it is impossible to modify. In the present application, at least one modification program fragment is injected into the executable file without using the source file.

[0026] Combine the following Figure 1 The method flow for modifying the executable file of embedded software is shown to introduce the principles and exemplary solutions of the present application.

[0027] like Figure 1 As shown, the method for modifying the executable file of embedded software of the present application includes step S101, wherein a modified fragment assembly code corresponding to at least one modified program fragment to be injected into the executable file is obtained, and the assembly code includes the assembly instructions and addressing information of the program fragment to be modified. In this step, based on the specific modification requirements, the assembly code of the corresponding modified program fragment is obtained, which is referred to as the modified fragment assembly code. The modified fragment assembly code can be written by personnel using any combination of one or more programming languages, and the programming language includes object-oriented programming languages ​​such as Java, C++, etc., and also includes conventional procedural programming languages ​​such as "C" language or similar programming languages. For example, if the modification requirement is to shield a specific function, a source program language can be written by personnel, in which the first instruction of the function corresponding to the function is directly changed to return. Then, the assembly code of the modified program fragment is generated by the programming language using an assembly tool.

[0028] Of course, the assembly code for modifying the program fragment can also be automatically generated by a software tool. The assembly instructions for modifying the program fragment include related function instructions and assembly instruction addresses.

[0029] After obtaining the modified fragment assembly code in step S101, the process proceeds to step S102, wherein the modified fragment assembly code is analyzed and processed to obtain the machine code instruction code and addressing information for the modified program fragment. In this embodiment, step S102 includes sub-steps S1021 and S1022 executed sequentially. Of course, a technical solution in which sub-steps S1021 and S1022 are executed in parallel can also be envisioned.

[0030] In sub-step S1021, the acquired modified fragment assembly code is subjected to instruction code analysis to determine the machine code instruction code corresponding to the assembly instruction in the modified fragment assembly code. Here, the association relationship between the assembly instruction and the machine code instruction code is analyzed, so as to determine the machine code instruction code of the modified program fragment based on the instruction code in the assembly code.

[0031] In sub-step S1022, the addressing mode of the machine code instruction code of the modified program fragment is parsed to determine the absolute address of the machine code instruction code of the modified program fragment. Here, the machine code instruction code is parsed to see whether it changes with the position in the ECU. For the machine code instruction code that changes with the position in the ECU, the target address and data offset of the modified program fragment are analyzed, and the address offset is changed again according to the target address and data offset to determine the new machine code instruction code address. Wherein, the absolute address of the machine code instruction code is determined based on the absolute address of the modified fragment assembly code and the relative address of the corresponding machine code instruction code.

[0032] like Figure 1 As shown, in parallel with step S101 to step S102, step S103 to step S105 are executed. In step S103, a file associated with the executable file is obtained, and the file associated with the executable file includes a hash table containing function names / data symbols and their entry locations. Here, for example, the executable file is an S19 file, and the file associated with the executable file is an ELF file associated with the S19 file.

[0033] After the hash table is obtained in step S103, the process proceeds to step S104, wherein information of a target function related to the modified program fragment to be injected into the executable file is obtained. Then the process proceeds to step S105, wherein entry position information of the modified program fragment related to the modified program fragment is determined. Here, for example, a search function is used to find entry position information of the modified program fragment. Similarly, step S103 and step S104 can be performed sequentially as shown in the figure, or can be performed in parallel.

[0034] Then, based on the determined machine code instruction code and absolute address of the modified program fragment and the entry location information of the associated function determined in step S105, in step S106, at least one modified program fragment is injected into the executable file without using the source file, so that at least part of the function function of the original executable file is changed.

[0035] As shown in the figure, step S106 includes sub-steps S1061-S1064. In sub-step S1061, based on the machine code instruction code and addressing information of the modified program fragment and the entry position information of the modified program fragment, the machine code language fragment of the modified program fragment is determined. Then go to sub-step S1062, in which the original executable file, that is, the original S19 file, is read in. In the next sub-step S1063, the file function position in the original executable file is analyzed to obtain the text position of the machine code language fragment to be modified in the executable file.

[0036] Finally, in sub-step S1064, the executable file is updated, so that the machine code language segment to be modified is injected into the executable file. Here, the machine code language segment of the modified program segment can be added to the original executable file, or the machine code language segment of the modified program segment can be used to replace the old machine code language segment in the original executable file.

[0037] This is a complete modification of the executable file. Then, the executable file, such as the S19 file, is burned into the programmable device and will be scheduled by the operating system as a host, or it can be executed from a specific location through offset means, so that the newly injected code can be executed by the CPU.

[0038] It should be understood that the order of the above method steps is only illustrative, and those skilled in the art can be aware of a variety of method solutions different from the above execution order based on their understanding of the prior art and common knowledge.

[0039] Figure 2 is a schematic flow chart of a method according to another embodiment of the present application. Figure 1 The only difference between the illustrated embodiments is that method steps S101 to S102 and method steps S103 to S105 are not executed in parallel but are executed sequentially.

[0040] In an exemplary embodiment of the present application, a computer-readable storage medium is further provided, on which a computer program is stored, the program including executable instructions, which can implement the steps of the method for modifying an executable file of embedded software described in any of the above embodiments when executed by, for example, a processor. In some possible implementations, various aspects of the present application can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to cause the terminal device to execute the steps described in the method for modifying an executable file of embedded software in this specification according to various exemplary embodiments of the present application.

[0041] The program product for implementing the above method according to the embodiment of the present application can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present application is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0042] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0043] The computer readable storage medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by an instruction execution system, an apparatus, or a device or used in combination with it. The program code contained on the readable storage medium may be transmitted with any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the above.

[0044] Program code for performing the operations of the present application may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).

[0045] In an exemplary embodiment of the present application, an electronic device is further provided, which may include a processor and a memory for storing executable instructions of the processor, wherein the processor is configured to execute the steps of the method for modifying an executable file of embedded software in any of the above embodiments by executing the executable instructions.

[0046] Those skilled in the art will appreciate that various aspects of the present application may be implemented as a system, method or program product. Therefore, various aspects of the present application may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to as "circuit", "module" or "system" herein.

[0047] Refer to the following Figure 3 The electronic device 300 according to this embodiment of the present application is described. Figure 3 The electronic device 300 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0048] like Figure 3 As shown, the electronic device 300 is in the form of a general computing device. The components of the electronic device 300 may include, but are not limited to: at least one processing unit 310, at least one storage unit 320, a bus 330 connecting different system components (including the storage unit 320 and the processing unit 310), a display unit 340, etc.

[0049] The storage unit stores a program code, which can be executed by the processing unit 310, so that the processing unit 310 performs the steps of various exemplary embodiments of the present application described in the method for modifying an executable file of embedded software in this specification. For example, the processing unit 310 can perform the following steps: Figure 1 or Figure 2 Steps shown.

[0050] The storage unit 320 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 3201 and / or a cache memory unit 3202 , and may further include a read-only memory unit (ROM) 3203 .

[0051] The storage unit 320 may also include a program / utility 3204 having a set (at least one) of program modules 3205, such program modules 3205 including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include the implementation of a network environment.

[0052] Bus 330 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.

[0053] The electronic device 300 may also communicate with one or more external devices 400 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 300, and / or communicate with any device that enables the electronic device 300 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 350. Furthermore, the electronic device 300 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 360. The network adapter 360 may communicate with other modules of the electronic device 300 via the bus 330. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 300, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0054] Through the description of the above implementation modes, it is easy for those skilled in the art to understand that the example implementation modes described here can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the implementation mode of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, or a network device, etc.) to execute the method for modifying the executable file of the embedded software according to the implementation mode of the present application.

[0055] Those skilled in the art will readily appreciate other embodiments of the present application after considering the description and practicing the contents disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The description and embodiments are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the appended claims.

Claims

1. A method for modifying an executable file of embedded software, the method comprising: Obtaining a modified fragment assembly code corresponding to at least one modified program fragment, the modified fragment assembly code including assembly instructions and addressing information thereof; Analyzing and processing the modified segment assembly code to obtain machine code instruction code and addressing information for the modified program segment; Obtaining files associated with the executable file; Acquiring information of a target function related to the modified program fragment; Determine entry location information of the modified program fragment based on information of a file associated with the executable file and a target function; Based on the machine code instruction code and addressing information of the modified program fragment and the entry position information of the modified program fragment, at least one modified program fragment is injected into the executable file without using the source file, so that at least part of the function of the original executable file is changed.

2. The method according to claim 1, characterized in that Analyzing and processing the modified segment assembly code includes at least one of the following steps: - performing instruction code analysis on the acquired modified segment assembly code to determine the machine code instruction code corresponding to the assembly instruction in the modified segment assembly code; - performing addressing analysis on the acquired modified fragment assembly code to determine addressing information of the machine code corresponding to the assembly instruction in the modified fragment assembly code.

3. The method according to claim 2, characterized in that The addressing analysis of the acquired modified fragment assembly code includes: - Based on the absolute address of the modified segment assembly code and the relative address of the corresponding machine code instruction code, determine the absolute address of the machine code instruction code.

4. The method according to claim 1, characterized in that The executable file is an S19 file, and the file associated with the executable file is an ELF file associated with the S19 file.

5. The method according to claim 1, characterized in that The file associated with the executable file includes a hash table containing function names / data symbols and their entry locations. Determining the entry location information of the modified program fragment based on the file associated with the executable file and the information of the target function includes: -Performing a search operation on the hash table based on the information of the target function, thereby determining the entry position information of the modified program fragment.

6. The method according to claim 1, characterized in that The step of injecting at least one modified program fragment into the executable file includes at least one of the following sub-steps: - based on the machine code instruction code and addressing information of the modified program fragment and the entry position information of the modified program fragment, determining the machine code language fragment of the modified program fragment, - read in the original executable file, - Analyze the text function position in the original executable file to obtain the text position of the machine code language fragment of the modified program fragment in the executable file, -Injects a machine code language fragment that modifies the program fragment into the executable file.

7. The method according to claim 1, characterized in that Injecting the machine code language fragment of the modified program fragment into the executable file includes at least one of the following operations: - Add the machine code language fragment of the modified program fragment to the original executable file, -Replace the old machine code language segment in the original executable file with the machine code language segment of the modified program segment.

8. The method according to claim 1, characterized in that Changing at least part of the functional functions of the original executable file includes at least one of the following operations: shielding a specific function, modifying a functional parameter, and adding or reducing control logic.

9. The method according to claim 1, characterized in that: The embedded software is used for vehicle control.

10. A computer-readable storage medium having a computer program stored thereon, the computer program comprising executable instructions, and when the executable instructions are executed by a processor, the method according to any one of claims 1 to 9 is implemented.

11. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to execute the executable instructions to implement the method according to any one of claims 1 to 9.