CN113590138A - Executable file processing method and device - Google Patents

Executable file processing method and device Download PDF

Info

Publication number
CN113590138A
CN113590138A CN202010366846.2A CN202010366846A CN113590138A CN 113590138 A CN113590138 A CN 113590138A CN 202010366846 A CN202010366846 A CN 202010366846A CN 113590138 A CN113590138 A CN 113590138A
Authority
CN
China
Prior art keywords
offset
instruction
instance
executable file
relocation table
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
CN202010366846.2A
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.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co 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 Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN202010366846.2A priority Critical patent/CN113590138A/en
Priority to PCT/CN2021/088873 priority patent/WO2021218756A1/en
Publication of CN113590138A publication Critical patent/CN113590138A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/61Installation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating

Abstract

The application provides an executable file processing method and device, wherein the method comprises the following steps: acquiring a relocation table corresponding to the executable file, wherein the relocation table is used for indicating at least one instruction of offset to be corrected; determining the position of the instruction of the offset to be corrected in the executable file according to the relocation table, and determining an instance member corresponding to the instruction of the offset to be corrected; the offset of the instance member is corrected. The instructions for compiling the instance members are modified, so that the code overhead is reduced, and the memory space and the storage space occupied by the application program are also reduced.

Description

Executable file processing method and device
Technical Field
The present application relates to terminal technologies, and in particular, to a method and a device for processing an executable file.
Background
A system and various applications may be arranged in the electronic device. The code of an application arranged in an electronic device, often comprising a plurality of classes; the code of the system generally includes a plurality of classes.
A device providing a system or an application program, which adjusts a class in a code of the application program or adjusts a class in a code of the system; when a class is adjusted, the layout of the instance members associated with the class is affected. Thus, when installing a system or application, the offsets of instance members in the class need to be modified.
However, how to quickly and accurately correct the offset of the instance member is a problem to be solved.
Disclosure of Invention
The application provides an executable file processing method and device, which aim to solve the problem of quickly and accurately correcting the offset of an instance member.
In a first aspect, the present application provides an executable file processing method applied to an electronic device, where the method includes:
acquiring a relocation table corresponding to an executable file, wherein the relocation table is used for indicating at least one instruction of offset to be corrected;
according to the relocation table, determining the position of the instruction of the offset to be corrected in the executable file, and determining an instance member corresponding to the instruction of the offset to be corrected;
the offset of the instance member is modified.
In an optional manner, the obtaining a relocation table corresponding to an executable file includes:
when the system is determined to be updated, sending the information of the executable file to network equipment; receiving a relocation table corresponding to the information of the executable file sent by the network equipment;
or sending software version information to the network equipment; and receiving a relocation table and an executable file which are sent by the network equipment and correspond to the software version information.
In an optional mode, the relocation table includes an instruction offset, an instruction type, and an instance member of an instruction;
the instruction offset is the offset of an instruction of the offset to be corrected in an executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction of the offset to be corrected is encoded.
In an optional manner, before correcting the offset of the instance member, the method further includes:
calculating the current actual offset of the instance member, wherein the actual offset is the offset obtained by correcting the original member offset of the instance member;
correcting the offset of the instance member, including: and correcting the original member offset of the example member into the actual offset.
In an alternative manner, when the instance member is an instance member variable, calculating an actual offset of the instance member includes:
traversing each class inherited by the member variable of the current instance from the class of the highest layer in the classes inherited by the member variable of the current instance, and aligning and arranging the member variable of the instance in each class to obtain the offset of the member variable of the instance in each class;
determining the offset of a previous instance member variable positioned before a current instance member variable, the size of the previous instance member variable, and the space filling size between the current instance member variable and the previous instance member variable, wherein the sum of the offset and the size is the actual offset of the current instance member variable;
when the instance member is a dummy function, calculating an actual offset of the instance member, including:
traversing each class inherited by the current virtual function from the class of the highest layer in the classes inherited by the current virtual function, and calculating the offset of a pointer of the virtual function in each class to obtain a virtual function table;
and determining the sum of the offset of the pointer of the previous virtual function positioned before the current virtual function and the length of the pointer of the current virtual function in the virtual function table as the actual offset of the current virtual function.
In an optional mode, the relocation table includes an instruction type; the instruction type is used for indicating a coding mode when an immediate number in an instruction of an offset to be corrected is coded, and the coding mode comprises a coding position;
correcting the original member offset of the instance member to the actual offset, including:
and writing the actual offset into a specific bit in the instruction of the offset to be corrected according to the coding mode indicated by the instruction type, wherein the specific bit is a bit indicated by a coding position in the coding mode.
In an optional mode, the instruction includes an operation code and an operand, the operation code is used to indicate an instruction type, and the operand is used to indicate data to be operated and a unit address where the data is located.
In an alternative manner, after correcting the offset of the instance member, the method further includes:
and loading and running the modified executable file, wherein the modified executable file runs according to the modified instruction.
In an alternative manner, the loading and running the modified executable file includes:
and accessing the instance member according to the modified instruction.
In a first aspect, the present application provides an executable file processing method, applied to a network device, the method including:
generating a relocation table corresponding to an executable file according to at least one instruction of the offset to be corrected, wherein the relocation table is used for indicating the position of the instruction of the offset to be corrected in the executable file;
and sending the relocation table to the electronic equipment, wherein the relocation table is used for correcting the offset of the instance member corresponding to the instruction of the offset to be corrected.
In an alternative manner, sending the relocation table to an electronic device includes:
receiving information of the executable file sent by the electronic equipment when the system is updated; sending a relocation table corresponding to the information of the executable file to the electronic device;
or receiving software version information sent by the electronic equipment; and sending the relocation table and the executable file corresponding to the software version information to the electronic equipment.
In an optional mode, the relocation table includes an instruction offset, an instruction type, and an instance member of an instruction;
the instruction offset is the offset of an instruction of the offset to be corrected in an executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction of the offset to be corrected is encoded.
In an optional manner, the relocation table is specifically configured to correct the offset of the instance member corresponding to the offset-to-be-corrected instruction according to the current actual offset of the instance member;
and the actual offset is the offset obtained by correcting the original member offset of the example member.
In an optional mode, the instruction includes an operation code and an operand, the operation code is used to indicate an instruction type, and the operand is used to indicate data to be operated and a unit address where the data is located.
In a third aspect, the present application provides a processor, where the processor is applied to a terminal device, and the processor is configured to:
acquiring a relocation table corresponding to an executable file, wherein the relocation table is used for indicating at least one instruction of offset to be corrected;
according to the relocation table, determining the position of the instruction of the offset to be corrected in the executable file, and determining an instance member corresponding to the instruction of the offset to be corrected;
the offset of the instance member is modified.
In an optional manner, when the processor acquires the relocation table corresponding to the executable file, the processor is specifically configured to:
when the system is determined to be updated, sending the information of the executable file to network equipment; receiving a relocation table corresponding to the information of the executable file sent by the network equipment;
or sending software version information to the network equipment; and receiving a relocation table and an executable file which are sent by the network equipment and correspond to the software version information.
In an optional mode, the relocation table includes an instruction offset, an instruction type, and an instance member of an instruction;
the instruction offset is the offset of an instruction of the offset to be corrected in an executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction of the offset to be corrected is encoded.
In an alternative manner, the processor, before correcting the instantiation offset, is further configured to:
calculating the current actual offset of the instance member, wherein the actual offset is the offset obtained by correcting the original member offset of the instance member;
when the processor corrects the offset of the instance member, it is specifically configured to: and correcting the original member offset of the example member into the actual offset.
In an alternative manner, when the instance member is an instance member variable, the processor is specifically configured to:
traversing each class inherited by the member variable of the current instance from the class of the highest layer in the classes inherited by the member variable of the current instance, and aligning and arranging the member variable of the instance in each class to obtain the offset of the member variable of the instance in each class;
determining the offset of a previous instance member variable positioned before a current instance member variable, the size of the previous instance member variable, and the space filling size between the current instance member variable and the previous instance member variable, wherein the sum of the offset and the size is the actual offset of the current instance member variable;
when the instance member is a virtual function, and the processor calculates the actual offset of the instance member, the processor is specifically configured to:
traversing each class inherited by the current virtual function from the class of the highest layer in the classes inherited by the current virtual function, and calculating the offset of a pointer of the virtual function in each class to obtain a virtual function table;
and determining the sum of the offset of the pointer of the previous virtual function positioned before the current virtual function and the length of the pointer of the current virtual function in the virtual function table as the actual offset of the current virtual function.
In an optional mode, the relocation table includes an instruction type; the instruction type is used for indicating a coding mode when an immediate number in an instruction of an offset to be corrected is coded, and the coding mode comprises a coding position;
when the processor corrects the original member offset of the instance member to the actual offset, the processor is specifically configured to:
and writing the actual offset into a specific bit in the instruction of the offset to be corrected according to the coding mode indicated by the instruction type, wherein the specific bit is a bit indicated by a coding position in the coding mode.
In an optional mode, the instruction includes an operation code and an operand, the operation code is used to indicate an instruction type, and the operand is used to indicate data to be operated and a unit address where the data is located.
In an alternative manner, the processor, after correcting the offset of the instance member, is further configured to:
and loading and running the modified executable file, wherein the modified executable file runs according to the modified instruction.
In an optional manner, when the processor loads and runs the modified executable file, the method is specifically configured to:
and accessing the instance member according to the modified instruction.
In a fourth aspect, the present application provides a processor, which is applied to a network device, and is configured to:
generating a relocation table corresponding to an executable file according to at least one instruction of the offset to be corrected, wherein the relocation table is used for indicating the position of the instruction of the offset to be corrected in the executable file;
and sending the relocation table to the electronic equipment, wherein the relocation table is used for correcting the offset of the instance member corresponding to the instruction of the offset to be corrected.
In a selectable mode, when the processor sends the relocation table to the electronic device, the processor is specifically configured to:
receiving information of the executable file sent by the electronic equipment when the system is updated; sending a relocation table corresponding to the information of the executable file to the electronic device;
or receiving software version information sent by the electronic equipment; and sending the relocation table and the executable file corresponding to the software version information to the electronic equipment.
In an optional mode, the relocation table includes an instruction offset, an instruction type, and an instance member of an instruction;
the instruction offset is the offset of an instruction of the offset to be corrected in an executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction of the offset to be corrected is encoded.
In an optional manner, the relocation table is specifically configured to correct the offset of the instance member corresponding to the offset-to-be-corrected instruction according to the current actual offset of the instance member;
and the actual offset is the offset obtained by correcting the original member offset of the example member.
In an optional mode, the instruction includes an operation code and an operand, the operation code is used to indicate an instruction type, and the operand is used to indicate data to be operated and a unit address where the data is located.
In a fifth aspect, the present application provides an electronic device, comprising: a processor;
the processor to execute instructions in computer-executable program code; when executed by the processor, the instructions cause the electronic device to perform the method provided by the first aspect.
In one possible implementation, the electronic device further includes a receiver; the receiver is used for receiving the relocation table sent by the network equipment.
In a sixth aspect, the present application provides a network device, comprising: a processor and a transmitter;
the processor to execute instructions in computer-executable program code; when the processor executes the instructions, the instructions cause the electronic device to perform the method provided by the second aspect;
the transmitter is used for transmitting the relocation table to the electronic equipment.
In a seventh aspect, the present application provides a communication system, including the terminal device according to any one of the third aspect, the electronic device according to any one of the fourth aspect, and the network device. The network equipment is used for receiving the software control program and the relocation table provided by the electronic equipment; the network device may send the software control program and the relocation table to the terminal device.
In an eighth aspect, the present application provides a terminal device comprising at least one processing element or chip configured to perform any of the implementations of the first aspect above.
In a ninth aspect, the present application provides a program which, when executed by a processor, is adapted to perform any of the implementations of the first aspect above.
In a tenth aspect, the present application provides a computer-readable storage medium containing the program of the ninth aspect.
In an eleventh aspect, the present application provides an electronic device comprising at least one processing element or chip for performing any of the implementations of the first aspect above.
In a twelfth aspect, the present application provides a program which, when executed by a processor, is adapted to perform any of the implementations of the second aspect above.
In a thirteenth aspect, the present application provides a computer-readable storage medium containing the program of the twelfth aspect.
Acquiring a relocation table corresponding to an executable file, wherein the relocation table is used for indicating at least one instruction of offset to be corrected; determining the position of the instruction of the offset to be corrected in the executable file according to the relocation table, and determining an instance member corresponding to the instruction of the offset to be corrected; the offset of the instance member is corrected. When a system or an application program is installed for the first time or a system or an application program is updated for the first time, the electronic equipment needs to correct the offset of the instance member in the instruction of the executable file, the electronic equipment firstly acquires a relocation table corresponding to the executable file, and then finds out the instruction of the offset to be corrected according to the relocation table, so that the offset of the instance member in the instruction can be corrected. According to the scheme provided by the embodiment, a global variable does not need to be added to each instance member; only one relocation table is provided for each instance member of the application program, and the offset of the instance member can be corrected according to the information in the relocation table, namely, the instruction for compiling the instance member is corrected, so that the code overhead is reduced, and the memory space and the storage space occupied by the application program are also reduced; in addition, only the instruction of the instance member needing to be corrected needs to be corrected, and the instruction overhead can be reduced because no additional instruction needs to be added by accessing the instance member. In addition, according to the scheme provided by this embodiment, since the relocation table may be independent of the application program, the code of the execution process of the scheme provided by this embodiment does not need to be arranged in the application program, and further, if the scheme provided by this embodiment occurs in the upgrade or update process of the application program, the overhead of the application program during running is not increased. Further, since the relocation table can be independent of the application program, the implementation process of the scheme provided by the embodiment does not need to be implemented during the operation process of the application program.
Drawings
Fig. 1 is a schematic view of an application scenario a according to an embodiment of the present application;
FIG. 2 is a first schematic diagram illustrating compilation of classes provided in this embodiment;
FIG. 3 is a second schematic diagram illustrating compilation of classes provided in this embodiment;
FIG. 4 is a first diagram illustrating an offset of an example member according to the present embodiment;
FIG. 5 is a third schematic diagram illustrating compilation of classes provided in this embodiment;
FIG. 6 is a second diagram illustrating an offset of an example member according to the present embodiment;
FIG. 7 is a fourth schematic diagram illustrating compilation of classes provided in this embodiment;
FIG. 8 is a fifth diagram illustrating compilation of classes provided in the present embodiment;
FIG. 9 is a second diagram illustrating an offset of an example member according to the present embodiment;
FIG. 10 is a sixth schematic diagram illustrating compilation of classes provided in this embodiment;
FIG. 11 is a fourth example member offset diagram provided in this embodiment;
FIG. 12 is a seventh schematic diagram illustrating compilation of classes provided in the present embodiment;
fig. 13 is a schematic flowchart of an executable file processing method according to an embodiment of the present application;
fig. 14 is a schematic diagram of a decoupling class according to an embodiment of the present application;
fig. 15 is a schematic diagram of an application scenario according to an embodiment of the present application;
fig. 16 is a schematic diagram of an application scenario three provided in the embodiment of the present application;
FIG. 17 is a flowchart illustrating another executable file processing method according to an embodiment of the present application;
FIG. 18 is a flowchart illustrating another executable file processing method according to an embodiment of the present application;
fig. 19 is a schematic structural diagram of a processor according to an embodiment of the present application;
FIG. 20 is a block diagram of another processor according to an embodiment of the present disclosure;
fig. 21 is a schematic structural diagram of an electronic device according to an embodiment of the present application;
fig. 22 is a schematic structural diagram of a network device according to an embodiment of the present application.
Detailed Description
The embodiment of the application is applied to the electronic equipment. Electronic devices include, but are not limited to: terminal equipment, network equipment, server. The terminal device may be a terminal device in the prior art or a terminal device appearing in the future; the network device may be a terminal device in the prior art or a network device appearing in the future.
Moreover, the electronic device may adopt a communication system in the prior art, or a fifth-generation mobile communication network (5G) communication system, or another system that may appear in the future, or another communication system. For example: wireless Local Area Network (WLAN) system, global system for mobile communication (GSM) system, Code Division Multiple Access (CDMA) system, Wideband Code Division Multiple Access (WCDMA) system, General Packet Radio Service (GPRS), Long Term Evolution (LTE) system, LTE Frequency Division Duplex (FDD) system, LTE Time Division Duplex (TDD), universal mobile telecommunications system (universal mobile telecommunications system, UMTS), universal internet microwave access (worldwide interoperability for mobile, wireless access, max), new radio access (NR), and so on.
Some terms in the present application are explained below to facilitate understanding by those skilled in the art. It should be noted that, when the scheme of the embodiment of the present application is applied to an electronic device, the name of the electronic device may be changed, but this does not affect the implementation of the scheme of the embodiment of the present application.
1) Electronic devices, including but not limited to: terminal devices, network devices, servers, smart devices, and the like. The electronic device may be various types of electronic devices in the related art, and may also be an electronic device appearing in the future.
2) A terminal device is a device that provides voice and/or data connectivity to a user. In the present application, a terminal device mainly refers to, but is not limited to, a mobile terminal, a vehicle-mounted terminal, a vehicle device, a public terminal, a handheld device with a wireless communication function, a wearable device, a computing device, and the like, wherein the vehicle-mounted terminal includes, but is not limited to, a vehicle-mounted navigator and the like, and the mobile terminal includes, but is not limited to, a mobile phone, a wearable device, a tablet computer, and the like. Illustratively, the terminal device may also be a Virtual Reality (VR) terminal device, an Augmented Reality (AR) terminal device, a wireless terminal in industrial control, a wireless terminal in unmanned driving, a wireless terminal in telemedicine, a wireless terminal in smart grid, a wireless terminal in smart city (smart city), a wireless terminal in smart home (smart home), and so on.
3) A network device, also called Radio Access Network (RAN) device, is a device for accessing a terminal device to a wireless network, and includes devices in various communication systems; the network equipment may have various forms, such as macro base station, micro base station, relay station, access point, etc.; the network device includes, but is not limited to, a network device in a new air interface network, and a network device in a long term evolution network. Illustratively, network devices include, but are not limited to: a transmission point (TRP), a next generation Node B (gNB), a Base Transceiver Station (BTS) in a global system for mobile communication (GSM) or Code Division Multiple Access (CDMA), a Node B (nodeB, NB) in a Wideband Code Division Multiple Access (WCDMA) system, an evolved Node B (eNB or eNodeB) in a long term evolution system, a radio network controller (radio network controller, RNC), a Base Station Controller (BSC), a nodeB (nodeB), (bbd), or an hnb (Node B), a baseband unit (baseband base), and the like.
4) "plurality" means two or more, and other terms are analogous. "and/or" describes the association relationship of the associated objects, meaning that there may be three relationships, e.g., a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship.
5) "correspond" may refer to an association or binding relationship, and a corresponds to B refers to an association or binding relationship between a and B.
It should be noted that the terms or terms referred to in the embodiments of the present application may be mutually referred and are not described in detail.
Fig. 1 is a schematic view of an application scenario a according to an embodiment of the present application. As shown in fig. 1, according to the solution of the embodiment of the present application, an electronic device 01 is, for example, an intelligent terminal or a handheld terminal. The network device 02 is, for example, a server. The network device 02 may generate an application program and send the application program to the electronic device 01; the electronic apparatus 01 installs an application program. And a system (control system) is installed in the electronic apparatus 01.
It is known that various applications may be arranged in an electronic device, wherein an application may also be referred to as a software program, or a software control program. The code of an application program usually has a plurality of classes; classes have instance members. Instance members can be instance member variables or instance members can be instance member methods. For example, the example member method is a dummy function.
In addition, a system (control system) is also provided in the electronic device in order to run the application program.
In one example, the network device for generating the application program may employ a compiler to compile the application program; during compilation, the compiler may calculate the layout of each class in the application, and thus the offset of the instance members. The offset of the instance member is stored in an executable file by adopting a compiler; wherein the executable file is stored with the application program.
The electronic device is installed with a system and an application program, and in a scenario of updating the system of the electronic device, the following description is provided. If the instance member in the application program depends on the parent class in the system with the specific version, at this time, the parent class of the application program or the parent class of the parent class is defined in the system with the specific version; the system is updated to obtain a new version of the system, and the parent class depended by the instance member in the application program or the parent class depended on by the instance member in the application program is defined in the system with the specific version, so that the application program cannot normally run in the system with the new version.
For example, the application includes class b, which includes instance member c; the application may run in a version a system; where the parent of class b is class a, but class a is defined in version a systems. And updating the system of the version A to obtain the system of the version B. At this time, when the application program is operated in the system of the version B, since the instance member c of the class B of the application program depends on the class a, but the class a is defined in the system of the version A, the instance member c of the application program also depends on the system of the version A. However, at this time, the system is updated, so that the application cannot normally operate in the system of version B.
A system (system) and an Application (APP) are installed in an electronic device, and in a scenario in which an application of the electronic device is updated, the following description is provided. The electronic equipment is provided with an application program, and the network equipment updates the application program; and, the electronic device selects to update the application. At this time, the class and instance members in the updated application code have been modified; the network device sends the updated application program to the electronic device, the electronic device runs the updated application program, but the executable file corresponding to the application program in the electronic device is not modified, and therefore when the instance member of the application program is accessed according to the executable file, an access error occurs.
When the system is initially installed according to the application program or initially, because the class and the instance member of the application are changed, when the instance member of the application program is accessed according to the executable file, an access error occurs.
Furthermore, when a system is initially installed, an application is initially installed, a system is updated, or an application is updated, it is often necessary to adjust the class in the system or the application. Further, the layout of instance members associated with a class may be affected, i.e., the layout is adjusted; after the layout is adjusted, the problem of access errors of instance members is caused.
For example, fig. 2 is a schematic diagram of compiling classes provided in the present embodiment, and as shown in fig. 2, the application includes class a (class a); as shown in FIG. 3, the parent class of class A is class S (class S). As shown in fig. 2, i in class a is defined, and objects m and n of a type of two nt in a schematic diagram of compiling the class provided by fig. 3 for this embodiment are Public int m and Public int n, respectively; objects m and n are instance member variables in class A; and an instance member variable m is defined in class a as obj.m ═ 1. As shown in FIG. 3, instance member variables a and b are defined in class S, public int a and public int b, respectively. And compiling the application program, thereby compiling the class A and the class S to obtain an executable file corresponding to the application program. As shown in FIG. 2, the executable file includes an instruction "str w0, [ x20, #16 ]" for accessing instance member variable m; the immediate #16 of the instruction "str w0, [ x20, #16 ]" is the offset of the instance member variable m from the object base address, i.e., the immediate #16 is the offset of the instance member variable m. Fig. 4 is a first schematic diagram illustrating an offset of an instance member provided in this embodiment, as shown in fig. 4, an object base address base is shown in fig. 4, which shows an offset of an instance member variable m. Fig. 5 is a third schematic diagram of compiling the class provided in this embodiment, and as shown in fig. 5, the class S is modified, and an example member variable c is added to the class S, which is public int c. When the instance member variable in the class S changes, the layout of the instance member changes; fig. 6 is a second schematic diagram of the offset of the instance member provided in this embodiment, as shown in fig. 6, fig. 6 shows the base address base of the object, and shows the offset of the instance member variable c after the class S is modified. At this time, the offset #16 in the instruction "str w0, [ x20, #16 ]" indicating the instance member variable m is unchanged; thus, when the instance member variable m is accessed using the instruction "str w0, [ x20, #16 ]" in the executable file, the instance member variable c is accessed and the instance member variable m cannot be accessed correctly.
The instruction may also be referred to as a machine instruction.
For another example, fig. 7 is a schematic diagram illustrating compilation of classes provided in this embodiment, as shown in fig. 7, an application includes a virtual function, and the virtual function is defined as Public void testVtable; fig. 8 is a fifth schematic diagram illustrating compilation of classes provided in this embodiment, and as shown in fig. 8, the parent class of the virtual function is class s (class s). As shown in fig. 7, an example member method obj.f () is defined in the dotted function. As shown in FIG. 8, two instance member methods are defined in class S, Public void f (), Public void g (). And compiling the application program, thereby compiling the virtual function and the class S and obtaining an executable file corresponding to the application program. As shown in FIG. 7, the executable file includes instructions "ldr x1, [ x0, #112 ]" for accessing instance member method f; the immediate #112 of the instruction "ldr x1, [ x0, #112 ]" is the offset of the instance member method f from the object base address, i.e., the immediate #112 is the offset of the instance member method f. Fig. 9 is a second schematic diagram of the offset of the example member provided in this embodiment, as shown in fig. 9, fig. 9 shows the base address base of the object, and shows the offset of the example member method f. Fig. 10 is a sixth schematic diagram illustrating compilation of a class provided in this embodiment, and as shown in fig. 10, a class S is modified, and an example member method e is added to the class S, and is a Public void e (). When the instance member variable in the class S changes, the layout of the instance member changes; fig. 11 is a fourth schematic diagram illustrating an offset of an example member provided in this embodiment, as shown in fig. 11, fig. 11 shows an object base address base, which shows an offset of an example member method e after the class S is modified. At this time, the offset #112 in the instruction "ldr x1, [ x0, #112 ]" indicating the instance member method f is unchanged; thus, when the instance member method f is accessed using the instructions "ldr x1, [ x0, #112 ]" in the executable file, the instance member method e is accessed and the instance member method f cannot be accessed correctly.
From the above analysis, it is necessary to adjust the offset of the instance member when the system is initially installed, the application is initially installed, the system is updated, or the application is updated.
In one example, a Global Offset Table (GOT) method or a functional link table (PLT) method may be used to resolve symbol references between shared libs. However, both methods are not suitable for processing object-oriented code, i.e. for processing applications resulting from an object-oriented approach; further, offset handling of instance members cannot be supported, nor does polymorphic behavior.
In one example, during the running process of the application program, a global variable may be configured for each instance member, and the global variable is used for storing an offset value of the instance member; storing global variables of instance members into code of an application; further, the global variable for each instance member may be modified, thereby offsetting the modified instance member. However, in the above manner of setting the global variable, one global variable needs to be added to each instance member, thereby increasing the code overhead and increasing the memory space and storage space occupied by the application program. And the global variable of each instance member needs to be corrected, and obtaining the global offset can increase one time of memory access operation and addition operation, thereby increasing the instruction overhead.
For example, fig. 12 is a schematic diagram seven illustrating the compilation of classes provided by this embodiment, and as shown in fig. 12, an Objective-C compiler llvm (low level virtual machine) allocates a global variable to each instance member in each class of an application program; the global variable is used for storing an offset value of an instance member; when compiling a class, the underlying virtual machine calculates the size of the base class to be 40 bytes, and records the base class size (instanceSize) at this time in the derivative class MyClass. An adjustment is made at the instance member of the application's class to increase the size of the base class to 48 bytes. Then, running an application program, and when loading the Myclass, determining the real size of the base class and the size of the base class recorded in the derivative Myclass, wherein the real size of the base class and the size of the base class recorded in the derivative Myclass are different; it can be determined that the size of the base class has changed and that the size of the base class has increased by 8 bytes. Then, all instance members in the MyClass are traversed by runtime, the value of all variables of each instance member is increased by 8, and the base class size (instanceSize) recorded in the MyClass class is also increased by 8.
According to the example, since each instance member needs to add one global variable, when the offset of the instance member is corrected, the values of all the variables of each instance member need to be increased by 8, so that the memory space and the storage space occupied by the application program are increased; moreover, the global variable of each instance member needs to be corrected, and 8 is added to the value of all the variables of each instance member, thereby increasing the instruction overhead. In addition, the above process needs to modify the global variable of the instance member during the running process of the application program, so that the modification process occupies a Central Processing Unit (CPU), thereby reducing the starting performance of the application program.
The application provides an executable file processing method and device, which can solve the problems.
Fig. 13 is a flowchart illustrating an executable file processing method according to an embodiment of the present application. As shown in fig. 13, the method includes:
101. and acquiring a relocation table corresponding to the executable file, wherein the relocation table is used for indicating at least one instruction of the offset to be corrected.
In one example, step 101 includes the following several implementations.
In a first implementation manner, when the system is determined to be updated, information of an executable file is sent to network equipment; and receiving a relocation table which is sent by the network equipment and corresponds to the information of the executable file.
In a second implementation manner, software version information is sent to network equipment; and receiving a relocation table and an executable file which are sent by the network equipment and correspond to the software version information.
In one example, the instruction includes an operation code and an operand, the operation code is used for indicating the type of the instruction, and the operand is used for indicating the data to be operated on and the address of the unit where the data is located.
Illustratively, the execution subject of the present embodiment may be an electronic device.
The electronic device is used to install the system and at least one application. The system and the application program are both formed by codes; at least one class is included in the code of the system and at least one class is included in the code of the application. Each class has instance members. Instance members can be instance member variables or instance members can be instance member methods.
From the foregoing description, it is necessary to correct the offset of the instance member when the system is initially installed, or the application is initially installed, or the system is updated, or the application is updated.
Because the classes in the system do not need to be decoupled, the system does not need to be compiled in a decoupling mode; but does not exclude the case where a class in the system appears in the future, being a decoupled class. Classes in applications may be compiled in a decoupled manner, and classes in applications may be classified into decoupled classes and non-decoupled classes. The scheme provided by the embodiment is suitable for decoupling class.
Decoupling class, which refers to a class in an application that needs to inherit a class in the system (excluding Object in the system); i.e. classes in the application, need to inherit and depend on classes in the system (excluding objects in the system).
Non-decoupled classes refer to classes in the application that do not need to inherit (remove Object in the system); i.e. classes in the application, do not need to inherit and depend on classes in the system (except Object in the system).
Fig. 14 is a schematic diagram of a decoupling class according to an embodiment of the present application. As shown in fig. 14, the system has an Object therein, and the system also has class a and class B; the application program comprises a class C, a class D, a class E and a class F. Both class A and class B of the system inherit the Object of the system. Class C of the application program inherits the Object of the system, and class E of the application program inherits class C of the application program; class D of the application inherits class A of the system, and class F of the application inherits class D of the application. Since the parent class of class D of the application is class a of the system and the parent class of class F of the application is class a of the system, class D and class F are decoupled classes. However, class C and class E do not inherit the class of the system, and class C and class E are non-decoupled classes. It can be seen that class D and class F, which are decoupling classes, change with class a of the system; class C, E, which is a non-decoupled class, does not change with the change of class a, class B in the system.
In one example, since the decoupling class changes with the change of the system, the offset (offset) of the decoupling class needs to be recalculated and read in to avoid the situation that the software control program cannot operate normally.
The application program has at least one corresponding executable file; one executable corresponds to one table of relocation tables, i.e. each executable has a corresponding table of relocation. The executable file comprises at least one instruction, and the instruction comprises an operation code and an operand; the operation code is used for indicating the instruction type of the instruction; the operand is used for indicating data to be operated on and the address of the unit where the data is located. As can be seen, the operand includes an immediate, which is the offset of the corresponding instance member of the instruction.
For example, instruction "str w0, [ x20, #16 ]"; instruction "str w0, [ x20, #16 ]" is an assembly instruction. str is an operation code; w0, x20, #16 are operands. w0 represents a general register, w0 is a 32-bit register; x0 represents another general register, and x0 is a 64-bit register. x20 is the base address; #16 is an immediate number and #16 characterizes the instruction's corresponding instance member as having an offset of 16, i.e., the instance member has an offset of 16 relative to the object base address.
The instruction "str w0, [ x20, #16 ]" refers to saving the data in the register w0 to the memory cell indicated by the address "x 20+ 16". It can be seen that the data in the register w0 is the data to be operated on, and "x 20+ 16" indicates the address of the cell where the data is located.
In the embodiment of the present application, in order to correct the offset of the instance member accurately and quickly, a relocation table may be used to correct the offset of the instance member, where the relocation table is used to indicate at least one instruction of the offset to be corrected.
First, for an executable file that needs to be modified, a relocation table corresponding to the executable file needs to be obtained. The following methods may be used to obtain the relocation table corresponding to the executable file.
First, an application scenario for acquiring a relocation table corresponding to an executable file is described. Fig. 15 is a schematic view of an application scenario two provided in the embodiment of the present application. As shown in fig. 15, the control device 11 generates an application program; the control device 11 uploads the generated application program or the updated application program to the network device 12; the network device 14 provides an application service, which is equivalent to an application store; the network device 14 provides the application service to the electronic device 13. Fig. 16 is a schematic view of an application scenario three provided in the embodiment of the present application. As shown in fig. 16, a display interface of the application service may be displayed in the electronic device 13, and display information of a plurality of application programs is displayed on the display interface; the display information is, for example, an icon of the application program or a profile of the application program. For example, the application a, the application B, and the application C are displayed on the display interface of the electronic device 13.
The electronic device 13 may automatically determine whether the application provided in the application service needs to be downloaded, and when the electronic device 13 automatically determines that the application provided in the application service needs to be downloaded, the electronic device 13 obtains the application provided in the application service provided by the control device 11 from the network device 12. For example, the control device 11 uploads the generated installation package of the application program a to the network device 12; when the electronic device 13 automatically determines that the application program a provided in the application service needs to be downloaded, the electronic device 13 sends an acquisition instruction to the network device 12; the network device 12 transmits the installation package of the application a to the electronic device 13 according to the acquisition instruction.
Or, the user sends a trigger instruction to the electronic device 13; the electronic device 13 determines that the application program provided in the application service needs to be downloaded according to the trigger instruction; the electronic device 13 acquires an application program provided in the application service provided by the control device 11 from the network device 12. For example, the control device 11 uploads the generated installation package of the application program a to the network device 12; the electronic equipment 13 acquires a trigger instruction sent by a user, wherein the trigger instruction is used for instructing the electronic equipment 13 to download the application program A; the electronic device 13 sends an acquisition instruction to the network device 12; the network device 12 transmits the installation package of the application a to the electronic device 13 according to the acquisition instruction.
In a first way of obtaining the relocation table corresponding to the executable file, when determining to update the system, the electronic device determines that the offset of the instance member of the executable file needs to be corrected, and then needs to obtain the relocation table corresponding to the executable file. At this time, the electronic device may transmit information of the executable file to the network device; information of the executable file, such as an identification of the executable file; the network device has previously generated or acquired a relocation table corresponding to the executable file, so that the relocation table corresponding to the information of the executable file can be sent to the electronic device.
Based on the scenarios shown in fig. 15 to 16, the control device 11 for generating an application generates an application, an executable file, and a relocation table, for example. The control device 11 uploads the software installation package to the network device 12. The electronic device 13 automatically or according to the instruction of the user, sends the information of the executable file to the network device 12; the network device 12 sends the stored relocation table corresponding to the executable file to the electronic device 13.
A second way of obtaining a relocation table corresponding to an executable file is as follows. When the electronic device installs the application program for the first time or updates the application program, the electronic device may determine which version of the application program needs to be installed, and then the electronic device sends software version information of the application program to the network device. The network device generates an application program corresponding to the software version information in advance, and the network device can adopt a compiler to compile the application program to obtain an executable file corresponding to the software version information; and, the network device generates a relocation table corresponding to the software version information, wherein the executable file corresponds to the relocation table.
Based on the scenarios shown in fig. 15 to 16, the control device 11 for generating an application generates an application, an executable file, and a relocation table, for example. To mark that the relocation table is configured for the application, the application may be assigned an indicator (also referred to as "id") that indicates that the relocation table is configured for the application. It can be known that, when the control device 11 for generating the application program generates the relocation table, an indication identifier is generated at the same time, and the indication identifier is used for indicating that the relocation table is configured for the application program; in one example, the indication may also indicate a storage location of the relocation table. As shown in fig. 15, the control device 11 generates a software installation package, where the software installation package includes an application program, a relocation table, and an indication flag, where the indication flag is used to indicate that the relocation table is configured for the application program; the control device 11 uploads the software installation package to the network device 12. Also, the control device 11 may notify the network device 14 that the application is updated; as shown in fig. 16, the network device 14 is configured to provide an application service to the electronic device 13, and the application service corresponds to an application store; thus, the network device 14 can display the application program provided by the control device 11 in the application service, so that the electronic device 13 selects whether to acquire the software installation package from the network device 12 according to the content in the application service displayed by the network device 14. The electronic device 13 obtains the software installation package from the network device 12 automatically or according to the instruction of the user. Further, the electronic device 13 obtains a software installation package, which includes the application program, the relocation table, and the indication identifier. The electronic device 13 may determine that the application is configured with the relocation table based on the indication.
Alternatively, based on the scenarios shown in fig. 15 to 16, as another example, as shown in fig. 15, the control device 11 generates a software installation package, where the software installation package includes an application program, a relocation table, and an indication identifier, where the indication identifier is used to indicate that the relocation table is configured for the application program; the control device 11 uploads the software installation package to the network device 12. Also, the control device 11 may notify the network device 14 that the application is updated; as shown in fig. 16, the network device 14 is configured to provide an application service to the electronic device 13, and the application service corresponds to an application store; thus, the network device 14 can display the application program provided by the control device 11 in the application service, so that the electronic device 13 selects whether to acquire the application program from the network device 12 according to the content in the application service displayed by the network device 14. The electronic device 13 obtains the application program from the network device 12 automatically or according to the instruction of the user. At this time, the network device 12 puts the indication identifier into the application program, and the network device 12 sends the application program carrying the indication identifier to the electronic device 13. Further, the electronic device 13 may determine that the application is configured with the relocation table according to the indication identifier. The electronic device 13 determines whether to acquire the relocation table corresponding to the application program from the network device 12 according to the current state of the terminal device. For example, the electronic device 13 determines whether to retrieve a relocation table based on the current version of the system. When the electronic device 13 determines that the relocation table corresponding to the application needs to be acquired, the electronic device 13 sends an acquisition request to the network device 12, and the network device 12 sends the relocation table to the electronic device 13.
The indication mark can be invisibly stored in the network equipment and the terminal equipment, and after the electronic equipment acquires the application program, the relocation table and the indication mark, a background of the electronic equipment can determine that the relocation table is acquired according to the indication mark.
A third way of obtaining a relocation table corresponding to an executable file is as follows. After the electronic device is initially configured, in the same manner as the second manner, the electronic device may determine which version of the application needs to be installed, and then the electronic device sends software version information of the application to the network device. The network device generates an application program corresponding to the software version information in advance, and the network device can adopt a compiler to compile the application program to obtain an executable file corresponding to the software version information; and, the network device generates a relocation table corresponding to the software version information, wherein the executable file corresponds to the relocation table.
In a fourth way of obtaining the relocation table corresponding to the executable file, when the system, the application program, the update system, or the update application program is installed for the first time, the electronic device may obtain the relocation table corresponding to the executable file from another storage medium. For example, a single child device copies the relocation table from a removable hard disk.
102. And according to the relocation table, determining the position of the instruction of the offset to be corrected in the executable file, and determining an instance member corresponding to the instruction of the offset to be corrected.
For example, the relocation table may indicate a location in the executable file of at least one instruction to be corrected for an offset, and the electronic device may determine which instructions need to be corrected and determine the location of the instructions in the executable file directly from the relocation table.
According to the above description, the executable file includes at least one instruction, the instruction includes an opcode and an operand; the operation code is used for indicating the instruction type of the instruction; the operand is used for indicating data to be operated on and the address of the unit where the data is located. The operand includes an immediate, which is an offset of the instance member corresponding to the instruction.
As can be seen, an instruction is used to access an instance member, the instruction corresponding to the instance member; after the electronic device finds the instruction of the offset to be corrected in the executable file, the instance member corresponding to the instruction can be determined.
103. The offset of the instance member is corrected.
For example, after finding the instruction requiring the offset to be corrected and the instance member corresponding to the instruction, the electronic device may correct the offset of the instance member in the instruction.
For example, executable file A includes the instruction "str w0, [ x20, #16 ]". The relocation table indicates the location of the instruction in executable file a. The electronic device may find instruction "str w0, [ x20, #16 ]", where #16 characterizes the instruction's corresponding instance member as having an offset of 16; the electronic device may then correct the offset 16.
In this embodiment, a relocation table corresponding to an executable file is obtained, where the relocation table is used to indicate at least one instruction of an offset to be corrected; determining the position of the instruction of the offset to be corrected in the executable file according to the relocation table, and determining an instance member corresponding to the instruction of the offset to be corrected; the offset of the instance member is corrected. When a system or an application program is installed for the first time or a system or an application program is updated for the first time, the electronic equipment needs to correct the offset of the instance member in the instruction of the executable file, the electronic equipment firstly acquires a relocation table corresponding to the executable file, and then finds out the instruction of the offset to be corrected according to the relocation table, so that the offset of the instance member in the instruction can be corrected. According to the scheme provided by the embodiment, a global variable does not need to be added to each instance member; only one relocation table is provided for each instance member of the application program, and the offset of the instance member can be corrected according to the information in the relocation table, namely, the instruction for compiling the instance member is corrected, so that the code overhead is reduced, and the memory space and the storage space occupied by the application program are also reduced; in addition, only the instruction of the instance member needing to be corrected needs to be corrected, and the instruction overhead can be reduced because no additional instruction needs to be added by accessing the instance member. In addition, according to the scheme provided by this embodiment, since the relocation table may be independent of the application program, the code of the execution process of the scheme provided by this embodiment does not need to be arranged in the application program, and further, if the scheme provided by this embodiment occurs in the upgrade or update process of the application program, the overhead of the application program during running is not increased. Further, since the relocation table can be independent of the application program, the implementation process of the scheme provided by the embodiment does not need to be implemented during the operation process of the application program.
Fig. 17 is a flowchart illustrating another executable file processing method according to an embodiment of the present application. As shown in fig. 17, the method includes:
201. and acquiring a relocation table corresponding to the executable file, wherein the relocation table is used for indicating at least one instruction of the offset to be corrected.
In one example, the relocation table includes instruction offset, instruction type, instance member of the instruction; the instruction offset is the offset of the instruction with the offset to be corrected in the executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction with the offset to be corrected is encoded.
This step may be referred to as step 101 shown in fig. 13, for example. Also, the following is introduced.
In this embodiment, when the control device for generating the application program generates the application program and the executable file, the relocation table corresponding to the executable file is also generated. First, a control device for generating an application compiles the application using a compiler to obtain an instruction offset, an instruction type, and an instance member corresponding to an instruction for each instruction (i.e., a machine instruction). Where "instruction offset" refers to the offset of an instruction in an executable file (i.e., the offset of the instruction in the executable file for which the offset is to be corrected). The instruction type is used for indicating a coding mode when the immediate number in the instruction of the offset to be corrected is coded, wherein the coding mode comprises a coding position. "an instance member corresponding to an instruction" may be information of the instance member; example member information, including, for example, a first identifier and a second identifier; a first identity, referring to an identity of an instance member; the second identity refers to the identity of the class to which the instance member belongs, i.e., to the class that the instance member inherits. The instruction offset, instruction type, and instruction corresponding instance member for each instruction constitute relocation information for each instruction. Furthermore, the control device for generating the application program may put the relocation information of each instruction into a relocation table. Table 1 shows one structure of the relocation table.
Table 1 relocation table
offset classid fieldID/methodID Type of instruction
As shown in table 1, the relocation table is composed of at least four parts, which are an instruction offset (offset in table 1), a second flag (class in table 1), a first flag (fieldID/methodID in table 1), and an instruction type. When the instance member is an instance member variable, the first identification of the instance member is represented by a fieldID; when the instance member is an instance member method, the first identification of the instance member is represented by methodID.
Table 2 shows another structure of the relocation table.
Table 2 relocation table
offset fieldID/methodID Type of instruction
As shown in table 1, the relocation table is composed of at least three parts, which are an instruction offset (offset in table 2), a first flag (fieldID/methodID in table 2), and an instruction type. When the instance member is an instance member variable, the first identification of the instance member is represented by a fieldID; when the instance member is an instance member method, the first identification of the instance member is represented by methodID.
Then, the control device for generating the application program uploads the application program and the relocation table to the network device after obtaining the relocation table. Further, the network device waits for the terminal device that needs to install the application program to acquire the relocation table.
And the control equipment for generating the application program adopts the compiler to compile the application program when the application program is generated, so as to obtain a relocation table corresponding to the executable file. Because the application program comprises at least one instance member, the executable file comprises instructions corresponding to each instance member; the instruction includes an offset of the instance member; the offset of an instance member refers to the offset of the instance member relative to the base address of the object. When the control device initially generates the application, the offset of the instance member in the instruction refers to the original offset of the instance member.
Because the query instruction comprises the offset of the instance member and the application program and the executable file are published together, the electronic equipment can determine the offset of the instance member in the instruction according to the instruction after the application program is installed on the terminal equipment; the electronic device accesses the instance member in the application based on the offset of the instance member. As can be seen, the instruction is used to access instance members.
Since the offset of the instance member is recorded in the instruction, when the instance member needs to be corrected, the offset recorded in the instruction corresponding to the instance member needs to be corrected (patch), that is, the instruction corresponding to the instance member needs to be corrected.
202. And according to the relocation table, determining the position of the instruction of the offset to be corrected in the executable file, and determining an instance member corresponding to the instruction of the offset to be corrected.
For example, this step can be referred to as step 102 shown in fig. 13, and is not described again. Also, the following is introduced.
In one example, after acquiring the relocation table, the electronic device may detect whether a modification (patch) to an instruction of the executable file is needed.
In one example, the electronic device determines whether modification (patch) of an instruction of an executable file corresponding to the application program is required based on the hash value. Illustratively, each system library (system library of systems) has a hash value of the MetaData (MetaData). For example, the metadata includes class metadata (classmata), instance member variable metadata (FieldMetaData), instance member method metadata (MethodMetaData); for example, the class metadata (classmadata) includes the size (size) of the class (class), the variable type (FieldType), the variable name (FieldName), the variable size (FieldSize), the method name (MethodName), the method signature (MethodSignature), the virtual function table (vtable) pointer, and the like, but the implementation code of the instance member method is not included in the class metadata (classmadata). Moreover, when the instruction of the executable file is modified, the name and the hash value of the system library of the system depended on by the instance member of the application program need to be recorded. Therefore, after the system is upgraded and the electronic device acquires the relocation table, the electronic device compares the hash value of the system library recorded in the application program with the hash value of the upgraded system (the hash value of the system library of the upgraded system); when the electronic equipment determines that the two are consistent, determining that the instruction of the executable file corresponding to the application program does not need to be modified; when the electronic equipment determines that the two are inconsistent, the electronic equipment determines that the instruction of the executable file corresponding to the application program needs to be modified. 203. And determining the instruction in the executable file according to the instruction offset corresponding to the instance member, wherein the instruction comprises a second offset of the instance member, and the second offset is the original offset of the instance member.
The electronic device may read each instance member in the application. Each instance member has a first identifier, and the relocation table has the first identifier of the instance member, and the relocation table includes an instruction offset, the first identifier and an instruction type with a corresponding relationship; thus, the electronic device can read the instruction offset and the instruction type corresponding to the first identification of each instance member from the relocation table according to the first identification of each instance member.
For example, table 3 shows an example of a relocation table. As shown in Table 3, relocation information for two instance members is provided in the relocation table; the first identifier fieldID of the instance member variable M is B, the second identifier class of the class inherited by the instance member variable M is a, the offset of the instruction of the instance member variable M is 12, and the instruction type of the instruction of the instance member variable M is 1; the first identification methodID of the instance member method N is D, the second identification classid of the class inherited by the instance member method N is C, the offset of the instruction of the instance member method N is 24, and the instruction type of the instruction of the instance member method N is 2.
Table 3 relocation table
offset classid fieldID/methodID Type of instruction
12 A B 1
24 C D 2
For each instance member indicated by the first identification in the relocation table, the electronic device has read from the relocation table an instruction offset to the instance member; the instruction offset is the offset in the executable file of the instruction corresponding to the instance member. Therefore, the electronic equipment can determine the instruction corresponding to the instance member from the executable file according to the instruction offset of the instance member.
For each instance member indicated by the first identifier in the relocation table, after the electronic device determines the instruction corresponding to the instance member from the executable file, the electronic device can read the original offset of the instance member from the instruction because the original offset of the instance member is included in the instruction.
203. And calculating the current actual offset of the example member, wherein the actual offset is the offset obtained by correcting the original member offset of the example member.
In one example, step 203 includes the following several implementations.
In the first implementation manner of step 203, when the instance member is an instance member variable, each class inherited by the current instance member variable is traversed from the highest class in the classes inherited by the current instance member variable, and the instance member variables in each class are aligned to obtain an offset of the instance member variable in each class; and determining the offset of the previous instance member variable before the current instance member variable, the size of the previous instance member variable, and the space filling size between the current instance member variable and the previous instance member variable, wherein the sum of the offset of the previous instance member variable and the size of the space filling between the current instance member variable and the previous instance member variable is the actual offset of the current instance member variable.
In the second implementation manner of step 203, when the instance member is a virtual function, each class inherited by the current virtual function is traversed from the class at the highest level in the classes inherited by the current virtual function, and the offset of the pointer of the virtual function in each class is calculated to obtain a virtual function table; and determining the sum of the offset of the pointer of the previous virtual function positioned before the current virtual function and the length of the pointer of the current virtual function in the virtual function table as the actual offset of the current virtual function.
Illustratively, the electronic device also needs to calculate the actual offset of the individual instance members.
In one example, the electronic device determines, according to the obtained relocation table, a first identifier and a second identifier of each instance member, where the first identifier is an identifier of the instance member, and the second identifier is an identifier of a class to which the instance member belongs. And the electronic equipment determines the actual offset of the instance member according to the first identification and the second identification. In one example, since the first identifier indicates instance member information of the instance member and the second identifier indicates class information of the class inherited by the instance member, the terminal device can calculate the actual offset of the instance member according to the instance member information of the instance member and the class information of the class inherited by the instance member.
In one example, when the instance member is the instance member variable, the instance member variable has a parent class, the parent class also has its own parent class, and the instance member variable further corresponds to an inheritance chain, which includes the parent class inherited by the instance member variable and the parent class inherited by the parent class itself. Therefore, when calculating the actual offset of the instance member variable, it is necessary to traverse each class inherited by the instance member variable from the highest-level class of the classes inherited by the instance member variable, arrange the instance member variables in each class (at this time, the instance member variables have been aligned), and when arranging, determine the space filling size (i.e., the size of the hole) between adjacent instance member variables. Then, the offset of each instance member variable is obtained. And summing the offset of the previous instance member variable before the current instance member variable, the size of the previous instance member variable and the space filling size between the current instance member variable and the previous instance member variable to obtain the actual offset of the instance member variable.
It should be noted that: a previous instance member variable preceding the current instance member variable, the size of the previous instance member variable being the size of itself if of the original type (e.g., int); : and if the current instance member variable is positioned in front of the previous instance member variable, the size of the previous instance member variable is the size of the pointer corresponding to the previous instance member variable.
In another example, when the instance member is a virtual function, the virtual function has a parent class, the parent class also has its own parent class, and the virtual function corresponds to an inheritance chain, which includes the parent class inherited by the virtual function and the parent class inherited by the parent class itself. Therefore, when calculating the actual offset of the virtual function, it is necessary to traverse all classes inherited by the virtual function to access the original data of the classes, and further access the original data of the function (the original data of the function includes the function name and the function type); and traversing the original function data, and calculating the offset of the pointer of the virtual function in each class for the virtual function in the original function data to obtain a virtual function table. At this time, the offset of each imaginary function is included in the imaginary function table, wherein the offset of each imaginary function is calculated according to the pointer of each imaginary function located before the imaginary function. At this time, the sum of the offset of the pointer of the previous imaginary function located before the current imaginary function in the imaginary function table and the length of the pointer of the current imaginary function is used as the actual offset of the current imaginary function.
For example, since the virtual function table stores addresses of virtual functions (such addresses may be referred to as "pointers"); at this time, the actual offset of the current imaginary function is N +4, N is the offset of the pointer of the previous imaginary function located before the current imaginary function in the imaginary function table, and 4 is the length of the pointer of the current imaginary function. It should be noted that: each class has a corresponding virtual function table.
204. The original member offset of the instance member is modified to the actual offset.
In one example, the relocation table includes an instruction type; the instruction type is used for indicating a coding mode when the immediate number in the instruction of the offset to be corrected is coded, and the coding mode comprises a coding position.
Step 204 specifically includes: and writing the actual offset into a specific bit in the instruction of the offset to be corrected according to the encoding mode indicated by the instruction type, wherein the specific bit is a bit indicated by the encoding position in the encoding mode.
Illustratively, for each instance member indicated by the first identifier in the relocation table, the electronic device reads the instruction type of the instruction corresponding to the instance member from the relocation table; since the instruction type indicates the encoding mode, the terminal device can correct the offset of the instance member in the instruction according to the instruction type, that is, correct the original offset of the instance member. In this case, the relocation table includes an instruction type (instruction type in the relocation table, focusing on the encoding method of the immediate). For example, the instruction type indicates that the instruction is an instruction type such as str or ldr, and different instruction types correspond to different encoding modes for the immediate. The encoding mode includes an encoding position. The encoding method may be influenced by, for example, the byte width (left shift, right shift); the byte width affects the encoding mode and thus the encoding position.
As can be appreciated, the encoding position indicates a particular bit, which is the bit used to deposit the offset of the instance member. The electronic device may write the actual offset to a particular bit in the command based on the encoding indicated by the command type. Thereby obtaining a modified instruction and further obtaining a modified executable file.
For example, for the example shown in table 2, the first identification fieldID of the instance member variable M is B, the second identification classid of the class inherited by the instance member variable M is a, the offset of the instruction of the instance member variable M is 16, and the instruction type of the instruction of the instance member variable M is 1. The terminal equipment can read a first identifier, fieldID, of an instance member variable M in the software control program as B; the electronic equipment acquires that the instruction offset of the instance member variable M is 12 from the relocation table according to the first identifier fieldID being B; the terminal apparatus can find an instruction "str w0, [ x20, #16 ]", which is an instruction that needs to be corrected, and which is an instruction for indicating an instance member variable M, according to the instruction offset 12. After finding the command "str w0, [ x20, #16 ]", the electronic device may read the immediate 16 in the finding command "str w0, [ x20, #16 ]", the immediate 16 being the original offset of the instance member variable M. The terminal equipment needs to correct the immediate value 16; the electronic device corrects (patch) the immediate number 16 according to the encoding method indicated by the instruction type 1 of the instruction of the instance member variable M, and the terminal device corrects (patch) the instruction "str w0, [ x20, #16 ]".
205. And loading and running the modified executable file, wherein the modified executable file runs according to the modified instruction.
In one example, step 205 specifically includes: according to the modified instruction, the instance member is accessed.
For example, after the instructions of the executable file are modified according to the relocation table, the modified executable file may be loaded and then executed.
At this time, since the offset of the instance member in the instruction of the executable file is corrected, the corrected offset in the instruction is the actual offset of the instance member, and the actual offset indicates the actual position of the instance member. When the corrected executable file is operated, accessing the corresponding instance member according to the corrected instruction in the executable file; in turn, the correct access is made to the instance members.
For example, after correcting the instruction "str w0, [ x20, #16 ]", the immediate number 16 is corrected to, for example, an immediate number of 20; the immediate 20 indicates the true offset of the instance member variable M so that a true device can access the instance member variable M based on the immediate 20.
In this embodiment, on the basis of the above embodiments, the control device or the network device may provide a relocation table, where the relocation table includes an instruction offset, an instruction type, and information of instance members, where the instruction offset is an offset of an instruction in an executable file, and the instruction type indicates an encoding manner. After the electronic equipment can acquire the relocation table, reading an instruction used in an executable file according to the instruction offset in the relocation table; the instruction includes the original offset of the instance member; the electronic device also needs to calculate the real offset of the instance member; then, according to the encoding mode indicated by the instruction type in the relocation table, replacing the offset in the access instruction with the real offset of the instance member, and further correcting the instruction; the electronic device can correctly access the instance member according to the corrected instruction. The instructions for compiling the instance members are modified, so that the code overhead is reduced, and the memory space and the storage space occupied by the application program are also reduced; in addition, only the instruction of the instance member needing to be corrected needs to be corrected, and the instruction overhead can be reduced because no additional instruction needs to be added by accessing the instance member. In one example, the offset is corrected for a decoupling class in the application, where the decoupling class is a class affected by the system layout, that is, the decoupling class is a class that needs to inherit a class in the system (excluding Object in the system).
Fig. 18 is a flowchart illustrating a further executable file processing method according to an embodiment of the present application. As shown in fig. 18, the method includes:
301. and generating a relocation table corresponding to the executable file according to at least one instruction of the offset to be corrected, wherein the relocation table is used for indicating the position of the instruction of the offset to be corrected in the executable file.
302. And sending a relocation table to the electronic equipment, wherein the relocation table is used for correcting the offset of the instance member corresponding to the instruction of the offset to be corrected.
In one example, step 302 specifically includes:
receiving information of an executable file sent by electronic equipment when updating a system; sending a relocation table corresponding to the information of the executable file to the electronic equipment; or receiving software version information sent by the electronic equipment; and sending the relocation table and the executable file corresponding to the software version information to the electronic equipment.
In one example, the relocation table includes instruction offset, instruction type, instance member of the instruction; the instruction offset is the offset of the instruction with the offset to be corrected in the executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction with the offset to be corrected is encoded.
In one example, the relocation table is specifically used for correcting the offset of the instance member corresponding to the offset-to-be-corrected instruction according to the current actual offset of the instance member; the actual offset is the offset obtained by correcting the original member offset of the example member.
In one example, the instruction includes an operation code and an operand, the operation code is used for indicating the type of the instruction, and the operand is used for indicating the data to be operated on and the address of the unit where the data is located.
For this embodiment, reference may be made to the description of the above embodiments, which is not described again.
In this embodiment, a relocation table corresponding to an executable file is obtained, where the relocation table is used to indicate at least one instruction of an offset to be corrected; determining the position of the instruction of the offset to be corrected in the executable file according to the relocation table, and determining an instance member corresponding to the instruction of the offset to be corrected; the offset of the instance member is corrected. When a system or an application program is installed for the first time or a system or an application program is updated for the first time, the electronic equipment needs to correct the offset of the instance member in the instruction of the executable file, the electronic equipment firstly acquires a relocation table corresponding to the executable file, and then finds out the instruction of the offset to be corrected according to the relocation table, so that the offset of the instance member in the instruction can be corrected. According to the scheme provided by the embodiment, a global variable does not need to be added to each instance member; only one relocation table is provided for each instance member of the application program, and the offset of the instance member can be corrected according to the information in the relocation table, namely, the instruction for compiling the instance member is corrected, so that the code overhead is reduced, and the memory space and the storage space occupied by the application program are also reduced; in addition, only the instruction of the instance member needing to be corrected needs to be corrected, and the instruction overhead can be reduced because no additional instruction needs to be added by accessing the instance member. In addition, according to the scheme provided by this embodiment, since the relocation table may be independent of the application program, the code of the execution process of the scheme provided by this embodiment does not need to be arranged in the application program, and further, if the scheme provided by this embodiment occurs in the upgrade or update process of the application program, the overhead of the application program during running is not increased. Further, since the relocation table can be independent of the application program, the implementation process of the scheme provided by the embodiment does not need to be implemented during the operation process of the application program.
Fig. 19 is a schematic structural diagram of a processor according to an embodiment of the present application. As shown in fig. 19, the processor 191 is applied to an electronic device, and the processor 191 is configured to:
acquiring a relocation table corresponding to the executable file, wherein the relocation table is used for indicating at least one instruction of offset to be corrected;
determining the position of the instruction of the offset to be corrected in the executable file according to the relocation table, and determining an instance member corresponding to the instruction of the offset to be corrected;
the offset of the instance member is corrected.
In an example, when the processor 191 acquires the relocation table corresponding to the executable file, it is specifically configured to:
when the system is determined to be updated, sending information of the executable file to the network equipment; receiving a relocation table which is sent by network equipment and corresponds to the information of the executable file; or sending software version information to the network equipment; and receiving a relocation table and an executable file which are sent by the network equipment and correspond to the software version information.
In one example, the relocation table includes instruction offset, instruction type, instance member of the instruction; the instruction offset is the offset of the instruction with the offset to be corrected in the executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction with the offset to be corrected is encoded.
In one example, the processor 191, before correcting the employee offset, is further configured to:
calculating the current actual offset of the example member, wherein the actual offset is the offset obtained by correcting the original member offset of the example member;
when the processor corrects the offset of the instance member, it is specifically configured to: the original member offset of the instance member is modified to the actual offset.
In one example, when the instance member is an instance member variable, the processor 191 is specifically configured to:
traversing each class inherited by the member variable of the current instance from the class of the highest layer in the classes inherited by the member variable of the current instance, and aligning and arranging the member variable of the instance in each class to obtain the offset of the member variable of the instance in each class; and determining the offset of the previous instance member variable before the current instance member variable, the size of the previous instance member variable, and the space filling size between the current instance member variable and the previous instance member variable, wherein the sum of the offset of the previous instance member variable and the size of the space filling between the current instance member variable and the previous instance member variable is the actual offset of the current instance member variable.
In one example, when the instance member is a dummy function, and the processor 191 is specifically configured to:
traversing each class inherited by the current virtual function from the class of the highest layer in the classes inherited by the current virtual function, and calculating the offset of a pointer of the virtual function in each class to obtain a virtual function table; and determining the sum of the offset of the pointer of the previous virtual function positioned before the current virtual function and the length of the pointer of the current virtual function in the virtual function table as the actual offset of the current virtual function.
In one example, the relocation table includes an instruction type; the instruction type is used for indicating a coding mode when the immediate data in the instruction of the offset to be corrected is coded, and the coding mode comprises a coding position;
when the processor 191 corrects the original member offset of the instance member to the actual offset, it is specifically configured to: and writing the actual offset into a specific bit in the instruction of the offset to be corrected according to the encoding mode indicated by the instruction type, wherein the specific bit is a bit indicated by the encoding position in the encoding mode.
In one example, the instruction includes an operation code and an operand, the operation code is used for indicating the type of the instruction, and the operand is used for indicating the data to be operated on and the address of the unit where the data is located.
In one example, the processor, after correcting the offset of the instance member, is further configured to:
and loading and running the modified executable file, wherein the modified executable file runs according to the modified instruction.
In an example, when the processor loads and runs the modified executable file, the following steps are specifically performed: according to the modified instruction, the instance member is accessed.
In this embodiment, the processor of this embodiment may be configured to execute the technical solution of the method, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 20 is a schematic structural diagram of another processor according to an embodiment of the present application. As shown in fig. 20, the processor 201 is applied to a network device, and the processor 201 is configured to: generating a repositioning table corresponding to the executable file according to at least one instruction of the offset to be corrected, wherein the repositioning table is used for indicating the position of the instruction of the offset to be corrected in the executable file; and sending a relocation table to the electronic equipment, wherein the relocation table is used for correcting the offset of the instance member corresponding to the instruction of the offset to be corrected.
In an example, when the processor 201 sends the relocation table to the electronic device, the relocation table is specifically used for:
receiving information of an executable file sent by electronic equipment when updating a system; sending a relocation table corresponding to the information of the executable file to the electronic equipment; or receiving software version information sent by the electronic equipment; and sending the relocation table and the executable file corresponding to the software version information to the electronic equipment.
In one example, the relocation table includes instruction offset, instruction type, instance member of the instruction; the instruction offset is the offset of the instruction with the offset to be corrected in the executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction with the offset to be corrected is encoded.
In one example, the relocation table is specifically used for correcting the offset of the instance member corresponding to the offset-to-be-corrected instruction according to the current actual offset of the instance member; the actual offset is the offset obtained by correcting the original member offset of the example member.
In one example, the instruction includes an operation code and an operand, the operation code is used for indicating the type of the instruction, and the operand is used for indicating the data to be operated on and the address of the unit where the data is located.
In this embodiment, the processor of this embodiment may be configured to execute the technical solution of the method, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 21 is a schematic structural diagram of an electronic device according to an embodiment of the present application. As shown in fig. 21, the electronic apparatus includes: a transmitter 211, a receiver 212, and a processor 213.
A transmitter 211 for performing a transmitting action of the electronic device. A receiver 212 for performing a receiving action of the electronic device.
A processor 213 for executing instructions in computer-executable program code; the instructions, when executed by the processor, cause the electronic device to perform the above-described method embodiments.
In one example, the terminal device may further include a memory 214, the memory 214 for storing program codes and data for the terminal device.
In one example, the end device may also include a bus 215. Wherein the transmitter 211, the receiver 212, the processor 213, and the memory 214 may be connected to each other through a bus 215; the bus 215 may be a PCI bus or an EISA bus, etc. The bus 215 may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. For ease of illustration, only one thick line is shown in FIG. 21, but this does not mean only one bus or one type of bus.
In the embodiments of the present application, the above embodiments may be referred to and referred to by each other, and the same or similar steps and terms are not repeated.
Alternatively, part or all of the above modules may be implemented by being embedded in a chip of the device in the form of an integrated circuit. And they may be implemented separately or integrated together. That is, the above modules may be configured as one or more integrated circuits implementing the above methods, for example: one or more Application Specific Integrated Circuits (ASICs), or one or more microprocessors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs), among others.
In this embodiment, the electronic device may be configured to perform the actions of the electronic device in the method provided in the foregoing embodiment, and the implementation principle and the technical effect are similar and will not be described herein again.
Fig. 22 is a schematic structural diagram of a network device according to an embodiment of the present application. As shown in fig. 22, the network device includes: a transmitter 221, a receiver 222, and a processor 223. The network device may be a control device.
A transmitter 222 for performing a transmitting action of the network device. A receiver 222, configured to perform a receiving action of the network device.
A processor 223 for executing instructions in computer-executable program code; the instructions, when executed by the processor, cause the network device to perform the above-described method embodiments.
In one example, the terminal device may also include a memory 224, the memory 224 for storing program codes and data for the terminal device.
In one example, the end device may also include a bus 225. Wherein the transmitter 222, the receiver 222, the processor 223, and the memory 224 may be connected to each other through a bus 225; the bus 225 may be a PCI bus or an EISA bus, etc. The bus 225 may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. For ease of illustration, only one thick line is shown in FIG. 22, but this does not indicate only one bus or one type of bus.
In the embodiments of the present application, the above embodiments may be referred to and referred to by each other, and the same or similar steps and terms are not repeated.
Alternatively, part or all of the above modules may be implemented by being embedded in a chip of the device in the form of an integrated circuit. And they may be implemented separately or integrated together. That is, the above modules may be configured as one or more integrated circuits implementing the above methods, for example: one or more Application Specific Integrated Circuits (ASICs), or one or more microprocessors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs), among others.
In this embodiment, the network device may be configured to perform the actions of the network device in the method provided in the foregoing embodiment, and the implementation principle and the technical effect are similar, which are not described herein again.
An embodiment of the present application provides a communication system, which includes the electronic device and the claimed network device. The network equipment is used for receiving the software control program and the relocation table provided by the electronic equipment; the network device may send the relocation table to the electronic device.
The present application provides a computer-readable storage medium, which includes instructions or a program, when the instructions or the program is executed on a computer, the computer executes the steps of the electronic device in the method provided by the above embodiments.
The present application provides another computer-readable storage medium, which includes instructions or a program, when the instructions or the program is executed on a computer, the computer executes the steps of the network device in the method provided by the foregoing embodiment.
The embodiment of the present application provides another computer program product, which includes program code for executing the steps of the electronic device in the method provided by the above embodiment when the computer runs the program code.
The embodiment of the present application provides another computer program product, which includes program code for performing the steps of the network device in the method provided by the foregoing embodiment when the computer runs the program code.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. The procedures or functions according to the embodiments of the present application are all or partially generated when the computer program instructions are loaded and executed on a computer. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored on a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website, computer, server, or data center to another website, computer, server, or data center via wire (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a Solid State Disk (SSD)), among others.
Those skilled in the art will recognize that, in one or more of the examples described above, the functions described in the embodiments of the present application may be implemented in hardware, software, firmware, or any combination thereof. When implemented in software, the functions may be stored on or transmitted over as one or more instructions or code on a computer-readable medium. Computer-readable media includes both computer storage media and communication media including any medium that facilitates transfer of a computer program from one place to another. A storage media may be any available media that can be accessed by a general purpose or special purpose computer.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (32)

1. An executable file processing method applied to electronic equipment is characterized by comprising the following steps:
acquiring a relocation table corresponding to an executable file, wherein the relocation table is used for indicating at least one instruction of offset to be corrected;
according to the relocation table, determining the position of the instruction of the offset to be corrected in the executable file, and determining an instance member corresponding to the instruction of the offset to be corrected;
the offset of the instance member is modified.
2. The method of claim 1, wherein obtaining a relocation table corresponding to an executable file comprises:
when the system is determined to be updated, sending the information of the executable file to network equipment; receiving a relocation table corresponding to the information of the executable file sent by the network equipment;
or sending software version information to the network equipment; and receiving a relocation table and an executable file which are sent by the network equipment and correspond to the software version information.
3. The method according to claim 1 or 2, wherein the relocation table comprises instruction offset, instruction type, instance member of instruction;
the instruction offset is the offset of an instruction of the offset to be corrected in an executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction of the offset to be corrected is encoded.
4. The method according to any of claims 1-3, further comprising, prior to correcting the offset of the instance member:
calculating the current actual offset of the instance member, wherein the actual offset is the offset obtained by correcting the original member offset of the instance member;
correcting the offset of the instance member, including: and correcting the original member offset of the example member into the actual offset.
5. The method of claim 4, wherein calculating the actual offset of the instance member when the instance member is an instance member variable comprises:
traversing each class inherited by the member variable of the current instance from the class of the highest layer in the classes inherited by the member variable of the current instance, and aligning and arranging the member variable of the instance in each class to obtain the offset of the member variable of the instance in each class;
determining the offset of a previous instance member variable positioned before a current instance member variable, the size of the previous instance member variable, and the space filling size between the current instance member variable and the previous instance member variable, wherein the sum of the offset and the size is the actual offset of the current instance member variable;
when the instance member is a dummy function, calculating an actual offset of the instance member, including:
traversing each class inherited by the current virtual function from the class of the highest layer in the classes inherited by the current virtual function, and calculating the offset of a pointer of the virtual function in each class to obtain a virtual function table;
and determining the sum of the offset of the pointer of the previous virtual function positioned before the current virtual function and the length of the pointer of the current virtual function in the virtual function table as the actual offset of the current virtual function.
6. The method of claim 4, wherein the relocation table includes an instruction type; the instruction type is used for indicating a coding mode when an immediate number in an instruction of an offset to be corrected is coded, and the coding mode comprises a coding position;
correcting the original member offset of the instance member to the actual offset, including:
and writing the actual offset into a specific bit in the instruction of the offset to be corrected according to the coding mode indicated by the instruction type, wherein the specific bit is a bit indicated by a coding position in the coding mode.
7. The method according to any one of claims 1 to 6, wherein the instruction comprises an operation code and an operand, the operation code indicating the type of the instruction, and the operand indicating the data to be operated on and the address of the location where the data is located.
8. The method according to any of claims 1-7, further comprising, after correcting the offset of the instance member:
and loading and running the modified executable file, wherein the modified executable file runs according to the modified instruction.
9. The method of claim 8, wherein loading and running the modified executable file comprises:
and accessing the instance member according to the modified instruction.
10. An executable file processing method applied to a network device is characterized by comprising the following steps:
generating a relocation table corresponding to an executable file according to at least one instruction of the offset to be corrected, wherein the relocation table is used for indicating the position of the instruction of the offset to be corrected in the executable file;
and sending the relocation table to the electronic equipment, wherein the relocation table is used for correcting the offset of the instance member corresponding to the instruction of the offset to be corrected.
11. The method of claim 10, wherein sending the relocation table to an electronic device comprises:
receiving information of the executable file sent by the electronic equipment when the system is updated; sending a relocation table corresponding to the information of the executable file to the electronic device;
or receiving software version information sent by the electronic equipment; and sending the relocation table and the executable file corresponding to the software version information to the electronic equipment.
12. The method according to claim 10 or 11, wherein the relocation table comprises instruction offset, instruction type, instance member of instruction;
the instruction offset is the offset of an instruction of the offset to be corrected in an executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction of the offset to be corrected is encoded.
13. The method according to any one of claims 10 to 12, wherein the relocation table is specifically configured to correct the offset of the instance member corresponding to the instruction of the offset to be corrected according to the current actual offset of the instance member;
and the actual offset is the offset obtained by correcting the original member offset of the example member.
14. The method of any one of claims 10-13, wherein the instruction includes an opcode and an operand, the opcode indicating an instruction type and the operand indicating data to be operated on and an address of a location where the data is located.
15. A processor, wherein the processor is applied to a terminal device, and wherein the processor is configured to:
acquiring a relocation table corresponding to an executable file, wherein the relocation table is used for indicating at least one instruction of offset to be corrected;
according to the relocation table, determining the position of the instruction of the offset to be corrected in the executable file, and determining an instance member corresponding to the instruction of the offset to be corrected;
the offset of the instance member is modified.
16. The processor of claim 15, wherein when the processor obtains the relocation table corresponding to the executable file, the processor is specifically configured to:
when the system is determined to be updated, sending the information of the executable file to network equipment; receiving a relocation table corresponding to the information of the executable file sent by the network equipment;
or sending software version information to the network equipment; and receiving a relocation table and an executable file which are sent by the network equipment and correspond to the software version information.
17. The processor according to claim 15 or 16, wherein the relocation table comprises instruction offset, instruction type, instance member of an instruction;
the instruction offset is the offset of an instruction of the offset to be corrected in an executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction of the offset to be corrected is encoded.
18. The processor of any one of claims 15 to 17, wherein the processor, prior to correcting the instantiation offset, is further configured to:
calculating the current actual offset of the instance member, wherein the actual offset is the offset obtained by correcting the original member offset of the instance member;
when the processor corrects the offset of the instance member, it is specifically configured to: and correcting the original member offset of the example member into the actual offset.
19. The processor of claim 18, wherein when the instance member is an instance member variable, the processor is specifically configured to, when calculating the actual offset of the instance member:
traversing each class inherited by the member variable of the current instance from the class of the highest layer in the classes inherited by the member variable of the current instance, and aligning and arranging the member variable of the instance in each class to obtain the offset of the member variable of the instance in each class;
determining the offset of a previous instance member variable positioned before a current instance member variable, the size of the previous instance member variable, and the space filling size between the current instance member variable and the previous instance member variable, wherein the sum of the offset and the size is the actual offset of the current instance member variable;
when the instance member is a virtual function, and the processor calculates the actual offset of the instance member, the processor is specifically configured to:
traversing each class inherited by the current virtual function from the class of the highest layer in the classes inherited by the current virtual function, and calculating the offset of a pointer of the virtual function in each class to obtain a virtual function table;
and determining the sum of the offset of the pointer of the previous virtual function positioned before the current virtual function and the length of the pointer of the current virtual function in the virtual function table as the actual offset of the current virtual function.
20. The processor of claim 18, wherein the relocation table includes an instruction type; the instruction type is used for indicating a coding mode when an immediate number in an instruction of an offset to be corrected is coded, and the coding mode comprises a coding position;
when the processor corrects the original member offset of the instance member to the actual offset, the processor is specifically configured to:
and writing the actual offset into a specific bit in the instruction of the offset to be corrected according to the coding mode indicated by the instruction type, wherein the specific bit is a bit indicated by a coding position in the coding mode.
21. The processor according to any one of claims 16 to 20, wherein the instruction comprises an operation code and an operand, the operation code indicating an instruction type, and the operand indicating data to be operated on and an address of a unit where the data is located.
22. The processor according to any of claims 16-21, wherein the processor, after correcting the offset of the instance member, is further configured to:
and loading and running the modified executable file, wherein the modified executable file runs according to the modified instruction.
23. The processor of claim 22, wherein the processor, when loading and running the modified executable file, is specifically configured to:
and accessing the instance member according to the modified instruction.
24. A processor, applied to a network device, the processor configured to:
generating a relocation table corresponding to an executable file according to at least one instruction of the offset to be corrected, wherein the relocation table is used for indicating the position of the instruction of the offset to be corrected in the executable file;
and sending the relocation table to the electronic equipment, wherein the relocation table is used for correcting the offset of the instance member corresponding to the instruction of the offset to be corrected.
25. The processor of claim 24, wherein when the processor sends the relocation table to the electronic device, the processor is specifically configured to:
receiving information of the executable file sent by the electronic equipment when the system is updated; sending a relocation table corresponding to the information of the executable file to the electronic device;
or receiving software version information sent by the electronic equipment; and sending the relocation table and the executable file corresponding to the software version information to the electronic equipment.
26. The processor according to claim 24 or 25, wherein the relocation table comprises instruction offset, instruction type, instance member of an instruction;
the instruction offset is the offset of an instruction of the offset to be corrected in an executable file, and the instruction type is used for indicating the encoding mode when the immediate in the instruction of the offset to be corrected is encoded.
27. The processor according to any one of claims 24 to 26, wherein the relocation table is specifically configured to correct the offset of the instance member corresponding to the instruction to correct the offset amount according to the current actual offset of the instance member;
and the actual offset is the offset obtained by correcting the original member offset of the example member.
28. A processor according to any one of claims 24 to 27, wherein the instruction includes an opcode to indicate the type of instruction and an operand to indicate the data to be operated on and the address of the location where the data is located.
29. An electronic device, characterized in that the electronic device comprises: a processor;
the processor to execute instructions in computer-executable program code; the instructions, when executed by the processor, cause the electronic device to perform the method of any of claims 1-9.
30. The electronic device of claim 29, further comprising a receiver;
the receiver is used for receiving the relocation table sent by the network equipment.
31. A network device, wherein the electronic device comprises: a processor and a transmitter;
the processor to execute instructions in computer-executable program code; the instructions, when executed by the processor, cause the electronic device to perform the method of any of claims 10 to 14;
the transmitter is used for transmitting the relocation table to the electronic equipment.
32. A computer-readable storage medium comprising instructions which, when executed on a computer, cause the computer to perform the method of any one of claims 1-9, or cause the computer to perform the method of any one of claims 10-14.
CN202010366846.2A 2020-04-30 2020-04-30 Executable file processing method and device Pending CN113590138A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202010366846.2A CN113590138A (en) 2020-04-30 2020-04-30 Executable file processing method and device
PCT/CN2021/088873 WO2021218756A1 (en) 2020-04-30 2021-04-22 Executable file processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010366846.2A CN113590138A (en) 2020-04-30 2020-04-30 Executable file processing method and device

Publications (1)

Publication Number Publication Date
CN113590138A true CN113590138A (en) 2021-11-02

Family

ID=78237572

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010366846.2A Pending CN113590138A (en) 2020-04-30 2020-04-30 Executable file processing method and device

Country Status (2)

Country Link
CN (1) CN113590138A (en)
WO (1) WO2021218756A1 (en)

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070192761A1 (en) * 2006-02-15 2007-08-16 Ravi Sahita Method for adding integrity information to portable executable (PE) object files after compile and link steps
CN105224370B (en) * 2015-10-21 2019-03-08 安一恒通(北京)科技有限公司 A kind of method and apparatus of loading ELF document
CN106598674A (en) * 2016-12-16 2017-04-26 中南大学 Relocatable ELF file-based software quick loading method
US10657068B2 (en) * 2018-03-22 2020-05-19 Intel Corporation Techniques for an all persistent memory file system

Also Published As

Publication number Publication date
WO2021218756A1 (en) 2021-11-04

Similar Documents

Publication Publication Date Title
EP3128421B1 (en) Method, device, and system for achieving java application installation by cloud compilation
EP1872215B1 (en) Implementing data-compatibility-based version scheme
US7587612B2 (en) Generating and communicating information on locations of program sections in memory
CN109240730B (en) Singlechip online upgrading method and system
US20100242033A1 (en) Method and System for Controlling Software Version Updates
US9092293B2 (en) Method and system for selecting a program for download
US20150040112A1 (en) Enabling Interoperability Between Software Applications By Utilizing Partial Binaries
CN110543327B (en) Service component multiplexing method, device, computer equipment and storage medium
JP2005523516A (en) Apparatus and method for modifying kernel modules that run on multiple kernel versions
US20190095187A1 (en) Incremental updates in static libraries
US20150317233A1 (en) Software system debugging device and method thereof
US8959502B2 (en) Processing table of content access overflow in an application
CN110851151B (en) Method, device, terminal, server and storage medium for pre-installing application
CN106657361A (en) Android installation package OTA upgrade method with mixed codes
CN111722857A (en) Updating method and device of software development kit, electronic equipment and storage medium
CN113590138A (en) Executable file processing method and device
CN116909659A (en) Execution method, device, equipment and storage medium of blockchain intelligent contract
CN115167862A (en) Patch method and related equipment
US8141055B2 (en) Method for dynamic discovery of code segments in instrumented binary modules
CN112328288A (en) Method, system, equipment and storage medium for updating server component
US7568197B1 (en) Method and apparatus for interposing kernel symbols
CN115309408A (en) Data processing method, device, equipment, readable storage medium and program product
CN116795419A (en) Version package grouping method, device, equipment and storage medium
Kiyohara et al. New method for software updating in mobile phones
CN116820554A (en) Upgrading method and device of functional component, 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