Patch file generation method, patching method and related equipment

By generating patch files with the same structural characteristics, and using the difference information between the old and new versions of the files to perform multi-level difference comparisons, the problems of large storage space and low update efficiency in terminal device upgrades and security vulnerability repairs are solved, and smaller patch files are realized. size and faster updates.

CN118567660APending Publication Date: 2024-08-30HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310233641.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-02-28
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

In the system upgrade and security vulnerability repair of terminal equipment, the existing technology delivers a complete image file through the server, which results in large storage space usage and low update efficiency. It cannot adapt to frequent system iterations and emergency security vulnerability repair needs, which brings problems to users. Bad experience.

Method used

By obtaining the difference classes, difference member variables and difference member methods of the old and new version files, a patch file with the same structural characteristics is generated, including the difference data generated by the multi-level difference comparison process and its index information, thereby reducing the size of the patch file and running it on the terminal. Stable updates are available on the device.

Benefits of technology

Effectively reduce the size of patch files, save user download time, speed up updates, and improve update success rate and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567660A
    Figure CN118567660A
Patent Text Reader

Abstract

The invention discloses a patch file generation method, a patching method and related equipment, and a server can perform multi-level difference comparison on new and old version files based on the structural features of the new and old version files to generate patch files with the same structural features as the new and old version files. The patch file comprises the difference data generated in the multi-level difference comparison process and the index information of the difference data, the terminal equipment can obtain the difference data on the server and obtain the difference data by analyzing the index information in the patch file, and further update operation can be carried out on the old version file based on the difference data to generate the new version file, so that the user experience is improved. Therefore, the volume of the patch file can be effectively reduced, redundant information issued to the terminal equipment by the server is less, and meanwhile, the stability of the patch during operation on the terminal equipment can be ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a patch file generation method, a patching method and related equipment. Background Art

[0002] When users use terminal devices, the operating system or application may need to upgrade functions or fix security vulnerabilities. As the performance and configuration of the terminal device's system operating platform improve, the data volume of the image file corresponding to the operating system or application is also increasing. Sending complete image files to the terminal device through the server for function upgrades or security vulnerability repairs not only takes up a large storage space of the terminal device and has low update efficiency, but also cannot adapt to the needs of frequent system iterations and emergency security vulnerability repairs, giving users a very poor experience. Summary of the invention

[0003] The embodiments of the present application provide a patch file generation method, a patching method and related devices, which can effectively reduce the size of the patch file, so that the redundant information sent by the server to the terminal device is less, and at the same time can ensure the stability of the patch when running on the terminal device.

[0004] In a first aspect, an embodiment of the present application provides a patch file generation method, the method comprising: obtaining a first file in a first version installation package and a second file in a second version installation package, the first version being a higher version of the second version, the first file being used to indicate the classes used in the first version installation package and the member variables and member methods included in the classes, and the second file being used to indicate the classes used in the second version installation package and the member variables and member methods included in the classes; determining the difference classes, the difference member variables and the difference member methods included in the difference classes between the first version installation package and the second version installation package based on the first file and the second file; and generating a patch file based on the difference classes, the difference member variables and the difference member methods included in the difference classes.

[0005] By implementing the method provided in the first aspect, the new and old version files can be compared at multiple levels based on the structural features of the new and old version files, and a patch file with the same structural features as the new and old version files can be generated, and the patch file includes the difference data and index information generated by the multi-level difference comparison process. In this way, the size of the patch file can be effectively reduced.

[0006] In one possible implementation, the difference class includes one or more of a deleted class, a newly added class, and a replaced class, wherein the deleted class is a class that is not included in the first file but included in the second file, the newly added class is a class that is included in the first file but not included in the second file, and the replaced class is a class that is included in both the first file and the second file but has different member variables and / or member methods.

[0007] In this way, the specific difference type of the difference class (such as deletion, addition, replacement) can be recorded.

[0008] In one possible implementation, the difference member variables include one or more of deleted member variables, newly added member variables, and replaced member variables, wherein the deleted member variables are member variables that are not included in the first file but included in the second file, the newly added member variables are member variables that are included in the first file but not included in the second file, and the replaced member variables are member variables that are included in both the first file and the second file but have different contents.

[0009] In this way, the specific difference type (such as deletion, addition, replacement) of the difference member variables can be recorded.

[0010] In one possible implementation, the difference member method includes one or more of a deletion member method, a new member method, and a replacement member method, wherein the deletion member method is a member method that is not included in the first file but included in the second file, the new member method is a member method that is included in the first file but not included in the second file, and the replacement member method is a member method that is included in both the first file and the second file but has different contents.

[0011] In this way, the specific difference type (such as deletion, addition, replacement) of the difference member method can be recorded.

[0012] In one possible implementation, the patch file includes a first section header, the first section header includes first indication information, and the first indication information is used to indicate the first position of the deleted class in the second version installation package; or, the first section header includes second indication information, and the second indication information is used to indicate the second position of the newly added class in the patch file; or, the first section header includes third indication information, and the third indication information is used to indicate the third position of the replaced class in the patch file and the fourth position in the second version installation package.

[0013] In this way, the patch file can record the indication information of each difference class, the amount of data recording the difference information will be reduced, and the size of the patch file will also be reduced. When patching, the specific location of the difference class can be found based on the indication information of the difference class.

[0014] In a possible implementation, the patch file also includes a file header, the file header includes indication information of the difference class, and the indication information of the difference class points to the first section header.

[0015] In this way, when patching, the indication information of each difference class can be found based on the indication information of the difference class.

[0016] In one possible implementation, the patch file also includes a second section header, the second section header includes fourth indication information, the fourth indication information is used to indicate the deletion of the member variable at the fifth position in the second version installation package; or, the second section header includes fifth indication information, the fifth indication information is used to indicate the addition of the member variable at the sixth position in the patch file; or, the second section header includes sixth indication information, the sixth indication information is used to indicate the replacement of the member variable at the seventh position in the patch file and the eighth position in the second version installation package; and / or, the second section header includes seventh indication information, the seventh indication information is used to indicate the deletion of the member method at the ninth position in the second version installation package; or, the second section header includes eighth indication information, the eighth indication information is used to indicate the addition of the member method at the tenth position in the patch file; or, the second section header includes ninth indication information, the ninth indication information is used to indicate the replacement of the member method at the eleventh position in the patch file and the twelfth position in the second version installation package.

[0017] In this way, the patch file can record the indication information of each difference member variable and / or member method, the amount of data recording the difference information can be further reduced, and the size of the patch file will also be further reduced. When patching, the specific location of the difference member variables and / or member methods can be found based on the indication information of the difference member variables and / or member methods.

[0018] In one possible implementation, the first file and the second file both include a file header, the file header includes class indication information, the class indication information points to a first independent data section, the first independent data section includes class information and member variable indication information and member method indication information included in the class, the member variable indication information points to a second independent data section, the member method indication information points to a third independent data section, the second independent data section includes member variable information, and the third independent data section includes member method information.

[0019] In this way, objects such as classes, member variables, and member methods all exist in independent data sections, which can reduce the impact of second-order differences caused by differential modifications.

[0020] In a possible implementation, the patch file generation method is executed by a server.

[0021] In this way, the redundant information sent from the server to the terminal device will be reduced.

[0022] In the first aspect, the first version may be a new version, the second version may be an old version, the first file and the second file may be files having the same structural features (eg, files having the structural features of the abc file), and the first section header may be Figure 5AIn the exemplary header of the difference class, the first indication information may be the index value of the deleted class, the first position may be the position of the deleted class in the second version installation package, the second indication information may be the index value of the newly added class, the second position may be the position of the deleted class in the patch file, the third indication information may be the index value of the replacement class, the third position may be the position of the replacement class in the patch file, the fourth position may be the position of the replacement class in the second version installation package, and the second section header may be Figure 5B In the exemplary header of the internal change information of the difference class shown, the fourth indication information may be the index value of the deleted member variable, the fifth position may be the position of the deleted member variable in the second version installation package, the fifth indication information may be the index value of the newly added member variable, the sixth position may be the position of the newly added member variable in the patch file, the sixth indication information may be the index value of the replaced member variable, the seventh position may be the position of the replaced member variable in the patch file, the eighth position may be the position of the replaced member variable in the second version installation package, the seventh indication information may be the index value of the deleted member method, the ninth position may be the position of the deleted member method in the second version installation package, the eighth indication information may be the index value of the newly added member method, the tenth position may be the position of the newly added member method in the patch file, the ninth indication information may be the index value of the replaced member method, the eleventh position may be the position of the replaced member method in the patch file, the twelfth position may be the position of the replaced member method in the second version installation package, the first independent data section may be an independent data section of the class, the second independent data section may be an independent data section of the member variable, and the third independent data section may be an independent data section of the member method.

[0023] In a second aspect, an embodiment of the present application provides a patching method, the method comprising: a terminal device obtains a patch file, the patch file is generated based on a difference class between a first version installation package and a second version installation package, and a difference member variable and a difference member method included in the difference class, the difference class and the difference member variable and the difference member method included in the difference class are determined based on a first file and a second file, the first file is a file in the first version installation package, the second file is a file in the second version installation package, the first version is a higher version of the second version, the first file is used to indicate the class used in the first version installation package and the member variable and member method included in the class, and the second file is used to indicate the class used in the second version installation package and the member variable and member method included in the class; the terminal device performs an update operation on the second version installation package based on the difference class and the difference member variable and the difference member method included in the difference class to generate a first version installation package.

[0024] By implementing the method provided in the second aspect above, the terminal device can locate the difference data based on the index information corresponding to the difference object in the patch file, which can save the user's time in downloading the patch file, speed up the update speed, and help ensure the stability of the patch during operation, improve the success rate of the update, and improve the user experience.

[0025] In one possible implementation, the difference class includes one or more of a deleted class, a newly added class, and a replaced class, wherein the deleted class is a class that is not included in the first file but included in the second file, the newly added class is a class that is included in the first file but not included in the second file, and the replaced class is a class that is included in both the first file and the second file but has different member variables and / or member methods.

[0026] In this way, the specific difference type of the difference class (such as deletion, addition, replacement) can be recorded.

[0027] In one possible implementation, the difference member variables include one or more of deleted member variables, newly added member variables, and replaced member variables, wherein the deleted member variables are member variables that are not included in the first file but included in the second file, the newly added member variables are member variables that are included in the first file but not included in the second file, and the replaced member variables are member variables that are included in both the first file and the second file but have different contents.

[0028] In this way, the specific difference type (such as deletion, addition, replacement) of the difference member variables can be recorded.

[0029] In one possible implementation, the difference member method includes one or more of a deletion member method, a new member method, and a replacement member method, wherein the deletion member method is a member method that is not included in the first file but included in the second file, the new member method is a member method that is included in the first file but not included in the second file, and the replacement member method is a member method that is included in both the first file and the second file but has different contents.

[0030] In this way, the specific difference type (such as deletion, addition, replacement) of the difference member method can be recorded.

[0031] In one possible implementation, the patch file includes a first section header, the first section header includes first indication information, the first indication information is used to indicate the first position of the deleted class in the second version installation package, and the terminal device updates the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class, specifically including: the terminal device deletes the deleted class at the first position; or, the first section header includes second indication information, the second indication information is used to indicate the second position of the newly added class in the patch file, and the terminal device updates the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class, specifically including: the terminal device obtains the newly added class at the second position and adds the newly added class to the second version installation package; or, the first section header includes third indication information, the third indication information is used to indicate the third position of the replacement class in the patch file and the fourth position in the second version installation package, and the terminal device updates the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class, specifically including: the terminal device restores the replacement class in the second version installation package based on the third position and the fourth position.

[0032] In this way, when patching, the specific location of the difference class can be found based on the indication information of the difference class.

[0033] In a possible implementation, the patch file also includes a file header, the file header includes indication information of the difference class, and the indication information of the difference class points to the first section header.

[0034] In this way, when patching, the indication information of each difference class can be found based on the indication information of the difference class.

[0035] In one possible implementation, the patch file also includes a second section header, the second section header includes fourth indication information, the fourth indication information is used to indicate the deletion of the member variable at the fifth position in the second version installation package, and the terminal device updates the second version installation package based on the difference class, the difference member variables included in the difference class, and the difference member method, specifically including: the terminal device deletes the member variable at the fifth position; or, the second section header includes fifth indication information, the fifth indication information is used to indicate the addition of the member variable at the sixth position in the patch file, and the terminal device updates the second version installation package based on the difference class, the difference member variables included in the difference class, and the difference member method, specifically including: the terminal device obtains the member variable at the sixth position and adds the new member variable to the second version installation package; or, the second section header includes sixth indication information, the sixth indication information is used to indicate the replacement of the member variable at the seventh position in the patch file and the eighth position in the second version installation package, and the terminal device updates the second version installation package based on the difference class, the difference member variables included in the difference class, and the difference member method, specifically including: the terminal device restores the member variable in the second version installation package based on the seventh position and the eighth position out a replacement member variable; and / or, the second section header includes seventh indication information, the seventh indication information is used to indicate the ninth position of the member deletion method in the second version installation package, and the terminal device updates the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class, specifically including: the terminal device deletes the member deletion method at the ninth position; or, the second section header includes eighth indication information, the eighth indication information is used to indicate the tenth position of the newly added member method in the patch file, and the terminal device updates the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class, specifically including: the terminal device obtains the newly added member method at the tenth position and adds the newly added member method to the second version installation package; or, the second section header includes ninth indication information, the ninth indication information is used to indicate the eleventh position of the replacement member method in the patch file and the twelfth position in the second version installation package, and the terminal device updates the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class, specifically including: the terminal device restores the replacement member method in the second version installation package based on the eleventh position and the twelfth position.

[0036] In this way, when patching, the specific locations of the different member variables and / or member methods can be found based on the indication information of the different member variables and / or member methods.

[0037] In one possible implementation, the first file and the second file both include a file header, the file header includes class indication information, the class indication information points to a first independent data section, the first independent data section includes class information and member variable indication information and member method indication information included in the class, the member variable indication information points to a second independent data section, the member method indication information points to a third independent data section, the second independent data section includes member variable information, and the third independent data section includes member method information.

[0038] In this way, objects such as classes, member variables, and member methods all exist in independent data sections, which can reduce the impact of second-order differences caused by difference modifications.

[0039] In the above second aspect, the first version may be a new version, the second version may be an old version, the first file and the second file may be files having the same structural features (eg, files having the structural features of the abc file), and the first section header may be Figure 5A In the exemplary header of the difference class, the first indication information may be the index value of the deleted class, the first position may be the position of the deleted class in the second version installation package, the second indication information may be the index value of the newly added class, the second position may be the position of the deleted class in the patch file, the third indication information may be the index value of the replacement class, the third position may be the position of the replacement class in the patch file, the fourth position may be the position of the replacement class in the second version installation package, and the second section header may be Figure 5B In the exemplary header of the internal change information of the difference class shown, the fourth indication information may be the index value of the deleted member variable, the fifth position may be the position of the deleted member variable in the second version installation package, the fifth indication information may be the index value of the newly added member variable, the sixth position may be the position of the newly added member variable in the patch file, the sixth indication information may be the index value of the replaced member variable, the seventh position may be the position of the replaced member variable in the patch file, the eighth position may be the position of the replaced member variable in the second version installation package, the seventh indication information may be the index value of the deleted member method, the ninth position may be the position of the deleted member method in the second version installation package, the eighth indication information may be the index value of the newly added member method, the tenth position may be the position of the newly added member method in the patch file, the ninth indication information may be the index value of the replaced member method, the eleventh position may be the position of the replaced member method in the patch file, the twelfth position may be the position of the replaced member method in the second version installation package, the first independent data section may be an independent data section of the class, the second independent data section may be an independent data section of the member variable, and the third independent data section may be an independent data section of the member method.

[0040] In a third aspect, an embodiment of the present application provides an electronic device, comprising one or more processors and one or more memories; wherein the one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program code, and the computer program code comprises computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes the method described in any one of the first aspect or the second aspect.

[0041] In a fourth aspect, an embodiment of the present application provides a computer storage medium, which stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed on an electronic device, the electronic device executes any one of the methods described in the first or second aspect above.

[0042] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a computer, enables the computer to execute any of the methods in the first or second aspects above. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 is a schematic diagram of using the Bsdiff algorithm to describe difference information provided by an embodiment of the present application;

[0044] Figure 2 is a schematic diagram of a communication system provided in an embodiment of the present application;

[0045] Figure 3A is a schematic diagram of a file header of an abc file provided in an embodiment of the present application;

[0046] Figure 3B It is a schematic diagram of a section header corresponding to a section area of ​​a class in an abc file provided in an embodiment of the present application;

[0047] Figure 3C It is a schematic diagram of a section header corresponding to a section area of ​​a field in an abc file provided in an embodiment of the present application;

[0048] Figure 3D It is a schematic diagram of a section header corresponding to a section area of ​​a method in an abc file provided in an embodiment of the present application;

[0049] Figure 4 It is a flowchart of a patch file generation method provided in an embodiment of the present application;

[0050] Figure 5A is a schematic diagram of a different type of header provided in an embodiment of the present application;

[0051] Figure 5Bis a schematic diagram of a header of internal change information of a difference class provided in an embodiment of the present application;

[0052] Figure 6 It is a flowchart of a patching method provided in an embodiment of the present application;

[0053] Figure 7 is a structural diagram of a server 100 provided in an embodiment of the present application;

[0054] Figure 8 It is a structural diagram of a terminal device 200 provided in an embodiment of the present application. DETAILED DESCRIPTION

[0055] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in the text is only a description of the association relationship of the associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0056] It should be understood that the terms "first", "second", etc. in the specification, claims and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.

[0057] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments.

[0058] At present, with the continuous development of terminal devices, the data volume of the image files (also called installation packages) corresponding to the operating system or application of the terminal device is getting larger and larger, and the demand for functional upgrades or security vulnerability repairs is becoming more and more frequent. The differential update technology (also called incremental update technology) has important applications. Taking the application as an example, the differential update technology refers to comparing the different parts of the new version image file and the old version image file through a certain differential update algorithm (this process can be called a differential process), and then extracting the different parts (i.e., the differential parts) to generate a patch file (also called a differential package or differential update package). The terminal device can merge the information of the differential part in the patch file with the old version image file to generate a new version of the image file. Further, the functional upgrade or security vulnerability repair process can be completed based on the new version of the image file.

[0059] It can be seen that, using the above difference update technology, since the patch file only records the information of the difference part, the patch file is smaller than the complete image file of the new version, and the update process is faster and more stable. The current mainstream difference algorithms include the Binary Software Difference (Bsdiff) algorithm, the Xdelta3 algorithm, the Vcdiff algorithm, etc. However, the size of the patch file generated by the current mainstream difference algorithm accounts for an average of 30%-50% of the size of the original image file (i.e., the complete image file of the new version), and the update process is still relatively long. Therefore, the current mainstream difference algorithm still has a lot of room for improvement in the form of describing the difference information.

[0060] Take the Bsdiff algorithm as an example. This algorithm does not distinguish between file formats and only performs differences based on binary blocks. For binary differences, even if only one line is modified at the code level, a large number of binary differences may be generated after the executable file is compiled. These binary differences can be divided into the following three categories:

[0061] 1. Zero-order variation

[0062] Zero-order changes refer to the inherent changes that occur during the compilation process, that is, two identical source code segments may also change after compilation.

[0063] 2. First-order changes

[0064] First-order changes refer to changes caused by directly modifying the source code, that is, differences generated during the compilation process that are directly related to the content of the modified source code.

[0065] 3. Second-order changes

[0066] Second-order changes refer to changes indirectly caused by first-order changes, that is, each insertion or modification of code will cause the pointer address or register address of other unmodified code parts to change, but most other binary field contents within the change remain the same as the old version file.

[0067] Second-order changes have the following two main characteristics: 1) For code segments that are not affected by the updated code, after compiling to generate an executable file, the changes in the binary content of this area are extremely sparse, that is, the differences in the second-order changes affected by the first-order changes are sparse, and only the addresses of some pointers or registers will change, usually not more than one or two bytes, and the intervals between the differences are large. 2) The updated code and data will have large position changes, but most of these changes are moves of the entire block, that is, the pointer address changes in the code at a certain position will have the same displacement value. The above two characteristics will result in most of the byte differences being 0 in the code blocks affected by the second-order changes, while a small number of displacement data that need to be updated have a large number of identical displacement values.

[0068] Based on the above two characteristics, the Bsdiff algorithm uses difference files (differencefile) and additional files (extrafile) to describe binary differences. The above difference files can be used to describe the difference data of code blocks with the same source code in the new and old version files, and the above additional files can be used to describe the new data in the new version file, which does not exist in the old version file.

[0069] The Bsdiff algorithm usually generates a patch file through the following steps:

[0070] Step 1: Generate a string index by sorting the content of the old version file through suffixes or using a hash algorithm.

[0071] Step 2: Use the above string index to compare the new version file and generate difference files and new files.

[0072] Specifically, after generating the string index, the index can be used to sequentially search for the longest binary segment that fully matches the old and new version files, and then expand forward and backward from the binary segment to generate a larger "approximate match", where the requirement for "approximate match" can be that at least 50% of the bytes of each suffix extended forward and each prefix extended backward can match the string of the old version file. These approximately matched fields can be considered as new codes caused by second-order changes, and non-approximately matched fields can be considered as newly generated fields of first-order changes. The difference file contains the byte differences of the approximately matched fields, and the newly added file contains the non-approximately matched fields.

[0073] Step 3: Compress the difference file, the newly added file, and the control file (ie, the file used to describe the necessary index control information) into a patch file.

[0074] See also Figure 1 , Figure 1 This is a schematic diagram of using the Bsdiff algorithm to describe the difference information. It can be seen that the difference file generated based on the new and old version files contains a large number of characters with the same offset of 2, so the difference file can be compressed efficiently.

[0075] Since the Bsdiff algorithm relies on the above two features, it has the following two disadvantages:

[0076] 1. Currently, most files have format information, but the Bsdiff algorithm only focuses on binary differences and does not fully utilize the structural characteristics of the file format. Therefore, the compression ratio of the patch files generated by the Bsdiff algorithm often has a large room for improvement.

[0077] 2. The Bsdiff algorithm requires that the differences in binary content are sparse and the offsets of the entire block are the same. However, when there are more modified contents and the differences are denser, the offset characteristics of the entire block will be less obvious, and the compression ratio of the patch file generated by the Bsdiff algorithm will be worse. Therefore, when the characteristics of the operating system or application are significantly different before and after the update (i.e., when a major version is updated), the compression ratio of the patch file generated by the Bsdiff algorithm will also be poor.

[0078] In order to solve the problem that the current mainstream difference update technology does not pay attention to the structural features of the file format during the patch file generation process, and the patch file compression ratio is seriously deteriorated in the scenario where the old version file has a large amount of modification and the second-order difference is dense, the embodiment of the present application provides a patch file generation method, and the server can perform a multi-level difference comparison between the new and old version files based on the structural features of the new and old version files to generate a patch file with the same structural features as the new and old version files, and the patch file includes multi-level difference data records. In this way, the size of the patch file can be effectively reduced, so that the redundant information sent by the server to the terminal device is less, and the stability of the patch when running on the terminal device can also be ensured.

[0079] Below, a communication system provided by an embodiment of the present application is first introduced.

[0080] Figure 2 A communication system provided by an embodiment of the present application is exemplified.

[0081] like Figure 2 As shown, the communication system may include a server 100 and a terminal device 200 .

[0082] The server 100 can be used to generate one or more patch files required by the terminal device 200. The one or more patch files can be used to repair one or more vulnerabilities of the operating system or application, or can also be used to add one or more product features and / or functions, which is not limited in the present embodiment. In addition, patches can be of various types, such as Taking the system as an example, corresponding types of patches may exist in the application (APP) layer, application framework layer, kernel layer or hardware driver layer, etc., and the embodiments of the present application are not limited to this.

[0083] The server 100 can also be used to add key information such as protocol and security verification to the patch file, thereby generating a transmittable patch package, and can send the generated transmittable patch package to the terminal device 200 through far-field communication. The patch package can be actively pushed by the server 100 to the terminal device 200, or the terminal device 200 can actively request the server 100 to obtain it, which is not limited in the embodiment of the present application.

[0084] The terminal device 200 can be used to receive the patch package sent by the server 100; it can also be used to verify, load, activate, etc. the patch package, thereby completing the update task of the operating system or application.

[0085] The terminal device 200 may be any type of electronic device, which is not limited in the present application. For example, the terminal device 200 may be a mobile phone, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, a smart screen, a wearable device, an augmented reality (AR) device, a virtual reality (VR) device, an artificial intelligence (AI) device, a car computer, a smart headset, a game console, or an Internet of Things (IOT) device, a smart home device such as a smart water heater, a smart lamp, a smart air conditioner, or a smart sports equipment, a smart medical device such as a blood pressure machine, etc.

[0086] In an embodiment of the present application, the server 100 side may include a patch tool, and the server 100 may provide the patch tool with an object for difference analysis (i.e., the old and new version files), and carry the operation of the patch tool (i.e., providing the environment configuration and system resources that the patch tool relies on in the process of generating patch files, such as tool chains and baseline codes). The patch tool may be responsible for processing the old and new version files, and performing multi-level difference comparison (also referred to as multi-level structured difference comparison) based on the structural information of the old and new version files to generate a structured patch file. Among them, the above-mentioned old and new version files may be a set of files before and after the version update, and the file set may include: a set of files before the version update (i.e., a set of files of the old version, such as a set of files with problems compiled before the source code is modified), and a set of files after the version update (i.e., a set of files of the new version, such as a set of files with problems that have been fixed after the source code is modified and compiled again). It is easy to understand that the above-mentioned old and new version files may be obtained by decompressing the complete installation package corresponding to the operating system or application.

[0087] In an embodiment of the present application, the terminal device 200 may include a patch engine, and the terminal device 200 receives the patch package sent by the server 100, and completes enabling actions such as verification, loading, and activation of the patch package, all of which can be completed through the patch engine.

[0088] It is understandable that the above Figure 2 The exemplary communication system does not constitute a specific limitation on the embodiments of the present application. In some other examples of the present application, the above communication system may also include a larger number of servers or terminal devices, which is not limited in the embodiments of the present application.

[0089] In an embodiment of the present application, the files before and after the above-mentioned version update are a structured file with a multi-level pointing relationship. The patch file generation method provided in the embodiment of the present application is to perform a multi-level difference comparison on the files before and after the version update based on the structural features of the files before and after the version update, and generate a patch file with the same structural features as the files before and after the above-mentioned version update.

[0090] In an embodiment of the present application, the patch file generation method provided in an embodiment of the present application is illustrated by taking the files before and after the above-mentioned version update as Harmony Ark Compiler Bytecode files as an example.

[0091] Among them, the Ark Compiler is a unified compilation and runtime platform designed to support the joint compilation and operation of multiple programming languages ​​and multiple chip platforms. It can support multiple programming languages ​​including dynamic type and static type languages, such as JavaScript (JS), TypeScript (TS), ArkTypeScript (ArkTS), etc. It is the compilation and runtime base that supports the Hongmeng system to become the operating system of various electronic devices such as mobile phones, tablets, personal computers, car computers, smart screens, smart wearable devices, etc.

[0092] Among them, the Ark compiler bytecode file is generated by compiling the input ArkTS or TS or JS source code (sourcecode) through the Ark compiler's compilation tool chain. It is a binary file that can be recognized and run by a virtual machine. The Ark compiler's compilation tool chain may include a parser (Parser), an abstract syntax tree (Abstract Syntax Tree, AST) transformer (Transformer), a bytecode generator (Bytecode Generator), a register allocator (RegisterAllocator), and a native emitter. Specifically, the parser can first parse the input ArkTS or TS or JS source code into AST, and then after the AST transformer, bytecode generator, and register allocator, the native emitter generates the Ark compiler bytecode file. The Ark compiler bytecode file usually exists in the form of a file with a .abc suffix (for example, *.abc), which can also be called an abc file.

[0093] For ease of understanding, the specific structure of the abc file is introduced below.

[0094] The abc file can be composed of a file header (abcHeader), a section (Section), and a section header (SectionHeader).

[0095] The file header is located at the beginning of the current abc file, that is, the position where the offset is 0. The file header can be used to locate other parts of the abc file. Figure 3A As shown in the example, the file header may include but is not limited to the following parts: magic, checksum, file_size, foreign_off, foreign_size, num_class, class_idx_off, num_lnps, lnp_idx_off. Among them:

[0096] Magic, called magic number, is used to determine the type of the file and can be represented by a string. For example, the magic number corresponding to the current abc file can be 'P"A"N"D"A"\0"\0"\0'.

[0097] Checksum, file verification code, is used to check file errors. The alder32 algorithm is usually used to verify all areas of the file except the magic and checksum areas.

[0098] file_size, used to describe the size of the file.

[0099] foreign_off, used to describe the offset of the external area.

[0100] The file may include classes, fields, and methods. Classes are templates used to create user-defined objects. They are the most basic concept in object-oriented programming technology and an abstract data type. The definition of a class usually includes the definition of methods for operating instances of the class. A field is a member of a class and is essentially a variable. Therefore, a field can also be called a member variable. A method (or member method) is a function that is connected to an object and allows the object data to be operated.

[0101] Normally, all classes, fields, and methods can be divided into two groups, one in the external (Foreign) area and the other in the internal (Local) area. The classes, fields, and methods in the external area are declared in other files and reference the current abc file, while the classes, fields, and methods in the internal area are declared in the current abc file.

[0102] foreign_size, used to describe the size of the external area.

[0103] num_classes is used to describe the number of classes defined in the current abc file.

[0104] class_idx_off is used to describe the offset of the class index structure ClassIndex, where ClassIndex is an offset array. The elements in the offset array are used to describe the offset of each class defined in the current abc file. All elements are sorted by class name. It is easy to understand that the number of elements contained in the offset array is the number of classes defined in the current abc file (num_class).

[0105] num_lnps is used to describe the number of line number programs (LineNumberProgram) in the current abc file.

[0106] lnp_idx_off is used to describe the offset of the LineNumberProgramIndex structure, where LineNumberProgramIndex is an offset array, and the elements in the offset array are used to describe the offset of each line number program in the current abc file. It is easy to understand that the number of elements in the offset array is the number of line number programs in the current abc file.

[0107] The section (also called section) is used to store all the data in the current abc file. In the abc file, each class, field, and method corresponds to an independent data section.

[0108] The section header is used to describe the information contained in the section. Each section can correspond to a section header.

[0109] like Figure 3B As shown in the example, the section header corresponding to a class section in the abc file may include but is not limited to the following parts: name, super_class_off, access_flags, num_fields, num_methods, class_data, padding, fields, methods. Among them:

[0110] name, used to describe the name of the class (i.e. class name), its format (Format) can be a string (String).

[0111] super_class_off, used to describe the offset of the name of the parent class, and its format can be uint8_t[4], where uint8_t is an 8-bit unsigned integer value.

[0112] access_flags is used to describe the access flags of the current class (such as public, abstract, etc.), and its format can be uleb128, where uleb128 is an unsigned integer value in LEB128 (LittleEndian Base128) encoding.

[0113] num_fields is used to describe the number of fields declared in the current class, and its format can be uleb128.

[0114] num_methods is used to describe the number of methods declared in the current class, and its format can be uleb128.

[0115] class_data, used to describe the tagged value of the current class, is a variable-length list of tagged values, and its format can be Taggedvalue[]. Each element in the list has the format corresponding to Taggedvalue. Taggedvalue can include the following parts: tag_value, data, where tag_value is used to describe the tag that determines the meaning of the data, and the format of tag_value can be uint8_t. Depending on the tag, there may be optional data; data is used to describe the optional payload, and the format of data can be uint8_t[]. Tag is a corresponding tag in ClassTag. ClassTag can include the following parts: interfaces, source_lang, runtime_annotation, annotation, source_file, runtime_type_annotation, type_annotation, where interfaces is used to describe the interface list implemented by the current class, and its corresponding tag can be 0x01; source_lang is used to describe the source language, and its corresponding tag can be 0x02; runtime_annotation is used to describe the runtime of the current class. me) visible annotation, the corresponding label can be 0x03; annotation is used to describe the offset of the runtime invisible annotation of the current class, and the corresponding label can be 0x04; source_file is used to describe the offset of the file name string containing the source code of the current class, and the corresponding label can be 0x05; runtime_type_annotation is used to describe the offset of the runtime visible type annotation of the current class, and the corresponding label can be 0x06; type_annotation is used to describe the offset of the runtime invisible type annotation of the current class, and the corresponding label can be 0x07.

[0116] Padding is used to fill data to ensure that the fields contained in the current class are aligned on 4-byte boundaries. Its format can be uint8_t[].

[0117] fields is used to describe the fields declared in the current class. Its format can be Field[], which is an array. Each element in the array has the format of a field. The format of the field will be described below. Figure 3CIt is easy to understand that the number of elements contained in the array is the number of fields declared in the current class (num_fields).

[0118] methods is used to describe the methods declared in the current class. Its format can be Method[], which is an array. Each element in the array has the format of a method. The format of the method will be described below. Figure 3D It is easy to understand that the number of elements contained in this array is the number of methods declared in the current class (num_methods).

[0119] like Figure 3C As shown in the example, the section header corresponding to a field in the abc file may include but is not limited to the following parts: class_idx, type_idx, name_off, access_flags, field_data. Among them:

[0120] class_idx is used to describe the index value of the class to which the current field belongs. Its format can be uint16_t, where uint16_t is a 16-bit unsigned integer value.

[0121] type_idx: an index value used to describe the type of the current field. Its format can be uint16_t.

[0122] name_off, used to describe the offset of the name of the current field, and its format can be uint32_t, where uint32_t is a 32-bit little endian unsigned integer value.

[0123] access_flags is used to describe the access flags of the current field (such as public, private, static, etc.), and its format can be uleb128.

[0124] field_data is used to describe the tagged value of the current field. It is a variable-length list of tagged values. Its format can be Taggedvalue[]. Each element in the list has the format corresponding to Taggedvalue. For the introduction of Taggedvalue, please refer to the above content and will not be repeated here. The label is a corresponding label in FieldTag. FieldTag can include the following parts: int_value, value, runtime_annotation, annotation, runtime_type_annotation, type_annotation, among which int_value is used to describe the integer value of the current field, and its corresponding label can be 0x01; value is used to describe the offset of the value of the current field, and its corresponding label can be 0x02; runtime_annotation is used to describe the offset of the runtime (runtime) visible annotation (annotation) of the current field, and its corresponding label can be 0x03; annotation is used to describe the offset of the runtime invisible annotation of the current field, and its corresponding label can be 0x04; runtime_type_annotation is used to describe the offset of the runtime visible type annotation of the current field, and its corresponding label can be 0x05; type_annotation is used to describe the offset of the runtime invisible type annotation of the current field, and its corresponding label can be 0x06.

[0125] like Figure 3D As shown in the example, the section header corresponding to a method section in the abc file may include but is not limited to the following parts: class_idx, proto_idx, name_off, access_flags, method_data. Among them:

[0126] class_idx is used to describe the index value of the class to which the current method belongs. Its format can be uint16_t.

[0127] proto_idx is used to describe the index value of the prototype of the current method, and its format can be uint16_t.

[0128] name_off, used to describe the offset of the name of the current method, and its format can be uint32_t.

[0129] access_flags is used to describe the access flags of the current method (such as public, private, static, etc.), and its format can be uleb128.

[0130] method_data, used to describe the tagged value of the current method, is a variable-length list of tagged values, and its format can be Taggedvalue[]. Each element in the list has the format corresponding to Taggedvalue. For the introduction of Taggedvalue, please refer to the above content and will not be repeated here. Tag is a corresponding tag in MethodTag. MethodTag can include the following parts: code, source_lang, runtime_annotation, runtime_param_annotation, debug_info, annotation, param_annotation, type_annotation, runtime_type_annotation, among which code is used to describe the offset of the code of the current method, and its corresponding tag can be 0x01; source_lang is used to describe the source language (sourcelanguage), and its corresponding tag can be 0x02; runtime_annotation is used to describe the offset of the runtime (runtime) visible annotation (annotation) of the current method, and its corresponding The label can be 0x03; runtime_param_annotation is used to describe the offset of the runtime visible annotations of the parameters of the current method, and its corresponding label can be 0x04; debug_info is used to describe the offset of the debug information related to the current method, and its corresponding label can be 0x05; annotation is used to describe the offset of the runtime invisible annotations of the current method, and its corresponding label can be 0x06; param_annotation is used to describe the offset of the runtime invisible annotations of the parameters of the current method, and its corresponding label can be 0x07; type_annotation is used to describe the offset of the runtime invisible type annotations of the current method, and its corresponding label can be 0x08; runtime_type_annotation is used to describe the offset of the runtime visible type annotations of the current method, and its corresponding label can be 0x09.

[0131] Since the abc file is a highly structured file with a hierarchical pointing relationship, in the embodiment of the present application, the file header (eg Figure 3AThe two parts num_classes and class_idx_off (also called class indication information) in the file header (shown as an example) point to each specific class included in the abc file in turn, so that the section header of each class (for example Figure 3B Furthermore, based on the two parts num_fields and fields in the section header of each class (also called the indication information of member variables), each specific field included in the corresponding class can be pointed to in sequence, so that the section header of each field can be located in sequence (for example Figure 3C Similarly, the two parts of num_methods and methods (also called member method indication information) in the section header of each class can be used to point to each specific method included in the corresponding class in turn, so that the section header of each method can be located in turn (for example Figure 3D Furthermore, the specific data of the fields and methods can be located based on the information included in the section header of each field and the section header of each method. In this way, based on the hierarchical pointing relationship of the abc file, the specific data corresponding to each class, field, and method included in the abc file can be obtained.

[0132] It is understandable that the above Figure 3A-3D It is only a set of schematic diagrams of the structure of the abc file, and should not constitute a limitation on the abc file. In some examples, the abc file may also include more or less information, which is not limited in the embodiments of the present application.

[0133] In the embodiment of the present application, both the new version file and the old version file are abc files, and the patch file generated therefrom is also an abc file (ie, the file format of the patch file has the structural features of the abc file).

[0134] Figure 4 The specific process of a patch file generation method provided in an embodiment of the present application is exemplified.

[0135] like Figure 4 As shown, the method can be applied to the server 100. It should be noted that the method is not limited to the server 100, and can also be applied to other devices, such as terminal devices, developer's development devices, etc., which are not limited in the present embodiment of the application. The specific steps of the method are described in detail below:

[0136] S401. The server 100 obtains a new version file and an old version file, wherein both the new version file and the old version file are files with structural feature 1.

[0137] The new version file may be a file after the version is updated (e.g., a file that has fixed problems in the previous version), and the old version file may be a file before the version is updated (e.g., a file with problems). It is easy to understand that the new version file and the old version file may be obtained by decompressing a complete installation package corresponding to a certain operating system or a certain application.

[0138] Among them, the above-mentioned new version file can be uploaded to the server 100 by the developer through the development device, and the above-mentioned old version file can be stored on the server 100, or, the developer can upload the old version file to the server 100 simultaneously when uploading the new version file through the development device. The embodiment of the present application does not limit the way in which the server 100 obtains the new version file and the old version file.

[0139] In the embodiment of the present application, the structural feature 1 may refer to the structural feature of the abc file, and both the new version file and the old version file may be abc files. For the introduction of the specific structure of the abc file, please refer to the above-mentioned related content, which will not be repeated here.

[0140] S402. The server 100 performs a multi-level difference comparison on the data of the new version file and the old version file based on the structural feature 1, and generates a patch file having the structural feature 1. The patch file includes the difference data and index information generated by the multi-level difference comparison process.

[0141] In the embodiment of the present application, "multi-level difference comparison" may refer to performing a first-level difference comparison, a second-level difference comparison, ..., an N-level difference comparison (where N is a positive integer) on the new version file and the old version file, respectively. Among them, the first-level difference comparison may refer to performing a difference comparison based on the data pointed to by the file header information of the new version file and the file header information of the old version file (i.e., the data pointed to once); the second-level difference comparison may refer to performing a difference comparison based on the data pointed to by the header information corresponding to the data used in the first-level difference comparison process (i.e., the data pointed to twice); and so on.

[0142] The first-level difference comparison and the second-level difference comparison processes are introduced below.

[0143] First level difference comparison:

[0144] Taking the above-mentioned new version file and old version file as an example, both are abc files, the first-level difference comparison is to compare the differences between the classes in the new version file and the old version file.

[0145] The file headers of the new version file and the old version file can be Figure 3A The file header is shown as an example in .

[0146] First, the server 100 can locate the specific section header of each class included in the new version file and the old version file based on the num_classes and class_idx_off parts in the file headers of the new version file and the old version file respectively (for example Figure 3B Further, the specific content of each class can be located based on the information in the section header of each class.

[0147] Then, the server 100 can compare the differences of the classes based on the new version file and the old version file, so as to determine the classes that differ between the new version file and the old version file (i.e., the difference classes). The difference classes may include: deleted classes, newly added classes, and replaced classes. The deleted classes may refer to classes that are not included in the new version file but included in the old version file; the newly added classes may refer to classes that are included in the new version file but not included in the old version file; and the replaced classes may refer to classes that are included in both the new version file and the old version file but have different specific contents.

[0148] Exemplarily, during the class difference comparison process, if the new version file does not include class A (ClassA) but the old version file includes class A, then the server 100 can determine that class A is a deleted class; if the new version file includes class A but the old version file does not include class A, then the server 100 can determine that class A is a newly added class; if both the new version file and the old version file include class A but the specific contents of class A in the new version file and the old version file are different, then the server 100 can determine that class A is a replacement class.

[0149] Finally, the server 100 may generate a header of the difference class based on the difference class.

[0150] like Figure 5A As shown in the example, the header of the difference class may include but is not limited to the following parts: class_idx_off, class_del[], class_add[], class_rep[]. Among them:

[0151] class_idx_off, used to describe the offset of the difference class index.

[0152] class_del[] is used to describe the index value of the current difference class when the current difference class is a deletion class. It is easy to understand that the index value points to the location of the old class that needs to be deleted (i.e., the deletion class). In an embodiment of the present application, the data section of the old class that needs to be deleted in the old version file can be located based on the index value, and the data section can be used to store the specific data of the old class that needs to be deleted. It is easy to understand that the location of the above-mentioned deletion class can be the location of the deletion class in the old version file (i.e., the location of the data section of the deletion class in the old version file), so that the terminal device can delete the deletion class at the location in the old version file where the deletion class is located.

[0153] class_add[] is used to describe the index value of the current difference class when the current difference class is a newly added class. It is easy to understand that the index value points to the location of the class that needs to be added (i.e., the newly added class). In an embodiment of the present application, the data section of the class that needs to be added in the patch file can be located based on the index value, and the data section can be used to store the specific data of the class that needs to be added. It is easy to understand that the position of the above-mentioned newly added class can be the position of the newly added class in the patch file (i.e., the position of the data section of the newly added class in the patch file). In this way, the terminal device can obtain the newly added class at the position in the patch file where the newly added class is located, and add the newly added class to the old version file.

[0154] class_rep[] is used to describe the index value of the current difference class when the current difference class is a replacement class. It is easy to understand that the index value points to the position of the old class that needs to be replaced (i.e., the replacement class). In an embodiment of the present application, the data section of the old class that needs to be replaced in the patch file can be located based on the index value, and the data section can be used to store the specific data of the old class that needs to be replaced. It is easy to understand that the position of the above-mentioned replacement class may include the position of the replacement class in the patch file (i.e., the position of the data section of the replacement class in the patch file) and the position of the replacement class in the old version file. In this way, the terminal device can obtain the specific data to be replaced at the position in the patch file where the replacement class is located, and update the specific data to the position in the old version file where the replacement class is located.

[0155] It is easy to understand that each difference class can correspond to one of the above Figure 5A The head is shown as an example.

[0156] It is easy to understand that the data section of the patch file generated after the above-mentioned first-level difference comparison may include specific data of the newly added class and the replaced class, which data are obtained from the new version file.

[0157] It can be seen that the patch file generated based on the first-level difference comparison (such as the difference comparison of the above class) is smaller in size, reduces traffic consumption, saves download time, and improves user experience compared with the current common patch file generated by overall comparison of new and old version files.

[0158] Secondary difference comparison:

[0159] The second-level difference comparison is taken as an example to compare the fields and methods declared in the classes in the new version file and the old version file.

[0160] In the embodiment of the present application, the first-level difference comparison process records the difference information of the class between the new version file and the old version file, and the second-level difference comparison process records the difference information of the fields and methods declared in the class between the new version file and the old version file. It is easy to understand that since the dimension of the first-level difference comparison process is the class, if only the first-level difference comparison process is performed, the difference information recorded in the patch file not only includes the content that has changed in the class between the new and old version files (such as the fields and methods that have changed), but also includes the content that has not changed in the class between the new and old version files (such as the fields and methods that have not changed). The fine-grainedness of the difference recorded in the second-level difference comparison process is improved compared to the first-level difference comparison process. The second-level difference comparison process can only record the content that has changed in the class between the new and old version files (such as the fields and methods that have changed), and the amount of data of the difference information that needs to be recorded will be reduced. Therefore, the patch file generated after the second-level difference comparison will be smaller.

[0161] During the secondary difference comparison process, the server 100 can perform a difference comparison of fields and methods based on the new version file and the old version file, so as to determine the fields (i.e., difference fields) and methods (i.e., difference methods) that differ between the new version file and the old version file. Among them, the difference fields may include: deleted fields, newly added fields, and replaced fields. The deleted fields may refer to fields that are not included in the new version file but included in the old version file; the newly added fields may refer to fields that are included in the new version file but not included in the old version file; the replaced fields may be fields that are included in both the new version file and the old version file but have different specific contents. Among them, the difference methods may include: deleted methods, newly added methods, and replaced methods. The deleted methods may refer to methods that are not included in the new version file but included in the old version file; the newly added methods may refer to methods that are included in the new version file but not included in the old version file; the replaced methods may be methods that are included in both the new version file and the old version file but have different specific contents.

[0162] After the secondary difference comparison, the server 100 may generate a header of the internal change information of the difference class.

[0163] like Figure 5B As shown in the example, the header of the difference class internal change information may include but is not limited to the following parts: name, super_class_off, access_flags, fields, fields_del[], fields_add[], fields_rep[], methods, methods_del[], methods_add[], methods_rep[], class_data_offset, where:

[0164] name, used to describe the name of the current difference class.

[0165] super_class_off is the offset used to describe the name of the parent class.

[0166] access_flags: used to describe the access flags of the current difference class (such as public, abstract, etc.).

[0167] fields, used to describe the fields declared in the current difference class.

[0168] fields_del[] is used to describe the index value of the current difference field when the current difference field is a deletion field. It is easy to understand that the index value points to the location of the old field that needs to be deleted (i.e., the deletion field). In an embodiment of the present application, the data section of the old field that needs to be deleted in the old version file can be located based on the index value, and the data section can be used to store the specific data of the old field that needs to be deleted. It is easy to understand that the position of the above-mentioned deletion field can be the position of the deletion field in the old version file (i.e., the position of the data section of the deletion field in the old version file), so that the terminal device can delete the deletion field at the position in the old version file where the deletion field is located.

[0169] fields_add[] is used to describe the index value of the current difference field when the current difference field is a newly added field. It is easy to understand that the index value points to the position of the field that needs to be added (i.e., the newly added field). In an embodiment of the present application, the data section of the field that needs to be added in the patch file can be located based on the index value, and the data section can be used to store the specific data of the field that needs to be added. It is easy to understand that the position of the above-mentioned newly added field can be the position of the newly added field in the patch file (i.e., the position of the data section of the newly added field in the patch file). In this way, the terminal device can obtain the newly added field at the position in the patch file where the newly added field is located, and add the newly added field to the old version file.

[0170] fields_rep[] is used to describe the index value of the current difference field when the current difference field is a replacement field. It is easy to understand that the index value points to the position of the old field that needs to be replaced (i.e., the replacement field). In an embodiment of the present application, the data section of the old field that needs to be replaced in the patch file can be located based on the index value, and the data section can be used to store the specific data of the old field that needs to be replaced. It is easy to understand that the position of the above-mentioned replacement field may include the position of the replacement field in the patch file (i.e., the position of the data section of the replacement field in the patch file) and the position of the replacement field in the old version file. In this way, the terminal device can obtain the specific data to be replaced at the position in the patch file where the replacement field is located, and update the specific data to the position in the old version file where the replacement field is located.

[0171] methods, which is used to describe the methods declared in the current difference class.

[0172] methods_del[] is used to describe the index value of the current difference method when the current difference method is the deletion method. It is easy to understand that the index value points to the location of the old method (i.e., the deletion method) that needs to be deleted. In an embodiment of the present application, the data section of the old method that needs to be deleted in the old version file can be located based on the index value, and the data section can be used to store the specific data of the old method that needs to be deleted. It is easy to understand that the position of the above-mentioned deletion method can be the position of the deletion method in the old version file (i.e., the position of the data section of the deletion method in the old version file), so that the terminal device can delete the deletion method at the position in the old version file where the deletion method is located.

[0173] methods_add[] is used to describe the index value of the current difference method when the current difference method is a newly added method. It is easy to understand that the index value points to the location of the method that needs to be added (i.e., the newly added method). In an embodiment of the present application, the data section of the method that needs to be added in the patch file can be located based on the index value, and the data section can be used to store the specific data of the method that needs to be added. It is easy to understand that the position of the above-mentioned newly added method can be the position of the newly added method in the patch file (i.e., the position of the data section of the newly added method in the patch file). In this way, the terminal device can obtain the newly added method at the location in the patch file where the newly added method is located, and add the newly added method to the old version file.

[0174] methods_rep[] is used to describe the index value of the current difference method when the current difference method is a replacement method. It is easy to understand that the index value points to the location of the old method that needs to be replaced (i.e., the replacement method). In an embodiment of the present application, the data section of the old method that needs to be replaced in the patch file can be located based on the index value, and the data section can be used to store the specific data of the old method that needs to be replaced. It is easy to understand that the position of the above-mentioned replacement method may include the position of the replacement method in the patch file (i.e., the position of the data section of the replacement method in the patch file) and the position of the replacement method in the old version file. In this way, the terminal device can obtain the specific data to be replaced at the position in the patch file where the replacement method is located, and update the specific data to the position in the old version file where the replacement method is located.

[0175] class_data_offset is used to describe the offset of the difference class data in the patch file.

[0176] It is easy to understand that when the difference class is a new class or a replacement class, the difference class can correspond to one of the above Figure 5B The head is shown as an example.

[0177] It is easy to understand that the data section of the patch file generated after the above-mentioned secondary difference comparison may include specific data of newly added fields, replaced fields, newly added methods, and replaced methods, which are obtained from the new version file.

[0178] It can be seen that after performing a first-level difference comparison (such as the difference comparison of the above type), performing a second-level difference comparison can improve the granularity of the difference description and reduce the difference record information of the patch file, thereby further compressing the size of the patch file, making the redundant information sent to the user terminal device less, and further improving the user experience.

[0179] In the embodiment of the present application, the generated patch file has the same structural features as the new version file and the old version file, so the patch file also has a hierarchical pointing relationship. Figure 5A , class_del[] can point to the deleted class, class_add[] can point to the added class, and class_rep[] can point to the replaced class. Figure 5B , fields_del[] can point to deleted fields, fields_add[] can point to newly added fields, fields_rep[] can point to replaced fields, methods_del[] can point to deleted methods, methods_add[] can point to newly added methods, and methods_rep[] can point to replaced methods.

[0180] It is easy to understand that, taking the abc file as an example, the patch file generated by the patch file generation method provided by the embodiment of the present application is also an abc file. Therefore, the patch file can also be composed of a file header, a section area, and a section header. For the introduction of the file header, the section area, and the section header, please refer to the relevant content of the specific structure of the aforementioned abc file, which will not be repeated here.

[0181] In the embodiment of the present application, the file header of the patch file and the file header of the new and old version files (for example Figure 3A It is easy to understand that in the file header of the patch file, num_classes can be used to describe the number of difference classes, and class_idx_off can be used to describe the offset of the difference class index structure. Specifically, based on the two parts num_classes and class_idx_off in the file header of the patch file (which can also be called the indication information of the difference class), each specific difference class included in the patch file can be pointed to in turn, so that the header of each difference class (for example Figure 5A The header of the difference class shown in the exemplary embodiment) can further be located based on the index information included in the header of the difference class (such as the index value of the deleted class, the index value of the added class, and the index value of the replaced class) to locate the header of the internal change information of the difference class (such as Figure 5B The header of the internal change information of the difference class shown in the example), further, the specific data of the difference fields and difference methods stored in the data section of the patch file can be located based on the index information included in the header of the internal change information of the difference class (for example, the index value of the deleted field, the index value of the newly added field, the index value of the replaced field, the index value of the deleted method, the index value of the newly added method, and the index value of the replaced method).

[0182] It is understandable that the above Figure 5A-Figure 5B It is only a set of schematic diagrams of the structure of the patch file, and should not constitute a limitation on the patch file. In some examples, the patch file may also include more or less information, which is not limited in the embodiments of the present application.

[0183] It should be noted that in the embodiments of the present application, only the first-level difference comparison and the second-level difference comparison are used as examples to illustrate the patch file generation method, which should not constitute a limitation on the present application. Not limited to the first-level difference comparison and the second-level difference comparison, in some examples of the present application, third-level and above difference comparisons can also be performed, and the difference comparison process is similar, which will not be repeated here.

[0184] It should be noted that in the embodiments of the present application, only the first-level difference comparison is the class (Class) as an example, and the second-level difference comparison is the field (Field) and method (Method) declared in the class as an example, which should not constitute a limitation on the present application. Not limited to the difference comparison of classes, fields, and methods, in some examples of the present application, other data in the new and old version files can also be compared for differences, and the difference comparison process is similar, which will not be repeated here.

[0185] S403: The server 100 generates a transmittable patch package based on the patch file.

[0186] Specifically, after generating the patch file, the server 100 may add some key information to the current patch file and package it to generate a transmittable patch package. The key information may include but is not limited to: version information and verification information, wherein the version information may be the version of the current patch file, including the version number, version name, generation time, etc., and the verification information may be information used to distinguish the identity of the current patch file, such as a cyclic redundancy check (CRC) code.

[0187] S404: The server 100 sends the patch package to the terminal device.

[0188] Specifically, after generating the patch package, the server 100 can actively send the patch package to the terminal device to be updated, or the server 100 can send the patch package to the terminal device to be updated after receiving the acquisition request for the patch package sent by the terminal device to be updated. The embodiment of the present application does not limit the triggering method for the server 100 to send the patch package to the terminal device.

[0189] In actual applications, for an operating system or application, there may be many versions, and it is impossible to guarantee that the operating system or application installed on each terminal device is the latest version. For example, the latest version is 1.2, but the versions that need to be updated include 1.0 and 1.1. In this case, the server 100 needs to generate a patch package that updates version 1.0 (i.e., the old version) to version 1.2 (i.e., the new version) and a patch package that updates version 1.1 (i.e., the old version) to version 1.2 (i.e., the new version). In this way, it can be guaranteed that the update requirements of all terminal devices can be met. It is easy to understand that when updating the operating system or application of a terminal device, the server 100 needs to first obtain the version installed on the terminal device (e.g., version 1.1), and then determine the corresponding patch package based on the version (e.g., the patch package that updates version 1.1 to version 1.2). Further, the server 100 can send the corresponding patch package determined above to the terminal device.

[0190] By implementing the above Figure 4 In the patch file generation method of the illustrated embodiment, taking the case where both the new and old version files are abc files as an example, the server 100 can make full use of the format information of the abc file to realize multi-level difference information recording, and the patch file generated based on the abc file and having the structural characteristics of the abc file is conducive to ensuring the stability of the patch operation. At the same time, since the objects such as classes, fields, methods, etc. pointed to by the structural information of the abc file exist in independent data sections, the second-order difference effect caused by the difference modification can be reduced, and the size of the patch file can be reduced. Compared with the patch file generated by the Bsdiff algorithm, the patch file generated by the patch file generation method provided by the embodiment of the present application will also have a greater compression rate benefit (approximately between 20% and 70%), and the more the modification amount, the greater the compression rate benefit.

[0191] It should be noted that the above Figure 4 The illustrated embodiment merely takes the patch file generation process being executed on the server 100 side as an example. In some examples, the patch file generation process may also be executed on the terminal device side (eg, the terminal device 200 side), which is not limited in the embodiments of the present application.

[0192] Figure 6 The specific process of a patching method provided in an embodiment of the present application is exemplified.

[0193] like Figure 6 As shown, the method can be applied to the terminal device 200. The specific steps of the method are described in detail below:

[0194] S601. The terminal device 200 obtains a patch package.

[0195] The patch package can be Figure 4 The patch package generated by the server 100 shown in the example.

[0196] Specifically, the terminal device 200 has installed a version of the operating system or application, which may be referred to as the old version (or current version). When one or more vulnerabilities appear in the old version, or one or more product features and / or functions need to be added, the aforementioned Figure 4 The exemplary method generates a patch package and publishes it on the server 100. The terminal device 200 can obtain the patch package from the server 100 to subsequently repair one or more of the above-mentioned vulnerabilities based on the patch package, or add one or more product features and / or functions.

[0197] The terminal device 200 obtains the patch package, which may specifically be the terminal device 200 receiving the patch package actively sent by the server 100, or the terminal device 200 triggers the download of the patch package on the server 100 after receiving a user operation (such as an operation to download the patch package), or the terminal device 200 automatically triggers the download of the patch package on the server 100 based on preset rules. The embodiments of the present application do not limit the manner in which the terminal device 200 obtains the patch package.

[0198] In the embodiment of the present application, since the patch file in the patch package is an example of an abc file, the terminal device 200 is a terminal device with the ability to execute the abc file.

[0199] S602: The terminal device 200 obtains difference data by parsing index information in the patch package, and updates the old version of the installation package based on the difference data to generate a new version of the installation package.

[0200] After obtaining the patch package, the terminal device 200 can parse the patch package, and by parsing the patch package, the difference data recorded in the patch package (i.e., the data corresponding to the difference objects between the new version file and the old version file) can be read. Specifically, the terminal device 200 parses the index information (e.g., the index values ​​recorded in the fields of deletion, addition, and replacement) corresponding to the difference objects (e.g., difference classes, difference fields, and difference methods) in the patch package, and locates the difference data based on the index information, wherein the difference data can be obtained through the aforementioned Figure 4 The exemplary multi-level difference alignment (eg, generated by a primary difference alignment and a secondary difference alignment) process is shown.

[0201] The above difference objects may be, for example, difference classes, difference fields, and difference methods. For example, the terminal device 200 may be based on the file header of the patch file (eg Figure 3A The two parts num_classes and class_idx_off in the file header shown in the example are located at the header of the difference class (for example Figure 5A If the difference class is a deleted class, the terminal device 200 can locate the class in the old version of the installation package based on the index value of the class_del[] record in the header of the difference class; if the difference class is a newly added class or a replaced class, the terminal device 200 can locate the header of the internal change information of the difference class based on the index value of the class_add[] or class_rep[] record in the header of the difference class (for example, Figure 5BThe header of the internal change information of the difference class shown in the example), further, the terminal device 200 can also locate the specific data of the difference fields and difference methods stored in the data section of the patch file based on the index values ​​of the fields_del[], fields_add[], fields_rep[], methods_del[], methods_add[], and methods_rep[] records in the header of the internal change information of the difference class.

[0202] The above difference data may include three types: deletion type, addition type, and replacement type.

[0203] The terminal device 200 performs an update operation on the old version of the installation package based on the difference data to generate a new version of the installation package, which may specifically include: when it is determined that the type of the difference data is a deletion type, the terminal device 200 may delete the difference data (such as the difference class, difference field, difference method, etc. corresponding to the data that needs to be deleted) from the old version of the installation package; when it is determined that the type of the difference data is a new addition type, the terminal device 200 may add the difference data in the patch file (such as the difference class, difference field, difference method, etc. corresponding to the data that needs to be added) to the old version of the installation package; when it is determined that the type of the difference data is a replacement type, the terminal device 200 may replace the corresponding data in the old version of the installation package with the difference data in the patch file (such as the difference class, difference field, difference method, etc. corresponding to the data that needs to be replaced). It is easy to understand that after the terminal device 200 performs an update operation on the old version of the installation package based on all the difference data in the patch package, a new version of the installation package can be generated.

[0204] After generating the new version of the installation package, the terminal device 200 can repair vulnerabilities in the operating system or application programs, increase product features and / or functions, etc. based on the installation package.

[0205] In some examples, before the terminal device 200 performs an update operation on the old version of the installation package based on the difference data, the terminal device 200 may further include: the terminal device 200 verifies the patch package to determine whether the patch package matches the operating system or application to be updated. Specifically, when the terminal device 200 verifies the patch package, it can read the version information and verification information in the patch package, and verify the patch package through the version information and verification information, that is, the verification data in the patch package, such as the version number, generation time, and CRC check code, is compared with the verification data in the operating system or application to be updated to ensure that the patch package matches the operating system or application to be updated, and avoid using the wrong patch package. If the verification is successful, it means that the patch package matches the operating system or application to be updated on the terminal device 200; if the verification fails, it means that the patch package does not match the operating system or application to be updated on the terminal device 200. In the case of successful verification, the terminal device 200 can then perform an update operation on the old version of the installation package based on the difference data to implement functions such as vulnerability repair.

[0206] By implementing the above Figure 6 In the patching method of the illustrated embodiment, taking the patch file as an abc file as an example, the terminal device 200 can locate the difference data based on the index information corresponding to the difference objects (such as difference classes, difference fields, and difference methods) in the patch file. Since the difference objects are independent, the terminal device 200 can independently modify different objects (such as classes, fields, and methods) in the old version file to generate a new version file. Compared with the traditional method of patching binary differences throughout the image, it is more conducive to ensuring the stability of the patch during operation. In addition, the above-mentioned patch file is a structured file generated by multi-level structured difference comparison based on the structural characteristics of the abc file, which can effectively reduce the size of the patch file, thereby saving the user's time in downloading the patch file, speeding up the update speed, improving the success rate of the update, and improving the user experience.

[0207] It should be noted that the above Figure 6 The patching method shown can be executed by the terminal device 200 triggered by the user, or it can be automatically executed silently in the background by the terminal device 200, which is not limited in the embodiments of the present application.

[0208] It should be noted that the embodiment of the present application only takes the abc file as an example to introduce the patch file generation method and the patching method. It is not limited to the abc file. Other files with similar structural features to the abc file can also be applied to the patch file generation method and the patching method provided in the embodiment of the present application. The embodiment of the present application does not limit this.

[0209] The structure of a server 100 provided in an embodiment of the present application is introduced below.

[0210] Figure 7 The structure of a server 100 provided in an embodiment of the present application is exemplified.

[0211] like Figure 7 As shown, the server 100 may include: one or more processors 701, a memory 702, a communication interface 703, a transmitter 705, a receiver 706, a coupler 707, and an antenna 708. These components may be connected via a bus 704 or other means. Figure 7 Take bus connection as an example.

[0212] The communication interface 703 can be used for the server 100 to communicate with other devices, such as the terminal device 200, etc., for communication. Specifically, the communication interface 703 can be a 3G communication interface, a 4G communication interface, a 5G communication interface, or a communication interface of a future new air interface. Not limited to a wireless communication interface, the server 100 can also be configured with a wired communication interface 703, such as a local access network (LAN) interface. The transmitter 705 can be used to transmit and process the signal output by the processor 701. The receiver 706 can be used to receive and process the mobile communication signal received by the antenna 708.

[0213] In some examples of the present application, the transmitter 705 and the receiver 706 can be regarded as a wireless modem. In the server 100, the number of the transmitter 705 and the receiver 706 can be one or more. The antenna 708 can be used to convert the electromagnetic energy in the transmission line into electromagnetic waves in the free space, or convert the electromagnetic waves in the free space into electromagnetic energy in the transmission line. The coupler 707 is used to divide the mobile communication signal received by the antenna 708 into multiple paths and distribute them to multiple receivers 706.

[0214] The memory 702 is coupled to the processor 701 and is used to store various software programs and / or multiple sets of instructions. Specifically, the memory 702 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more disk storage devices, flash memory devices or other non-volatile solid-state storage devices. The memory 702 may store a network communication program, which may be used to communicate with one or more additional devices, one or more terminal devices, or one or more network devices.

[0215] In some examples of the present application, the memory 702 may be used to store an implementation program of the patch file generation method provided by one or more embodiments of the present application on the server 100 side.

[0216] The processor 701 can be used to read and execute computer-readable instructions. Specifically, the processor 701 can be used to call a program stored in the memory 702, such as an implementation program of the patch file generation method provided in one or more embodiments of the present application on the server 100 side, and execute the instructions contained in the program.

[0217] It should be noted that Figure 7 The server 100 shown is only one implementation of the embodiment of the present application. In actual applications, the server 100 may also include more or fewer components, which is not limited here.

[0218] For more details about the functions and working principles of the server 100, please refer to the relevant contents in the above embodiments, which will not be repeated here.

[0219] The structure of a terminal device 200 provided in an embodiment of the present application is introduced below.

[0220] Figure 8 The structure of a terminal device 200 provided in an embodiment of the present application is exemplified.

[0221] like Figure 8 As shown, the terminal device 200 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0222] It is understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the terminal device 200. In other examples of the present application, the terminal device 200 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0223] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0224] The controller may be the nerve center and command center of the terminal device 200. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0225] The processor 110 may also be provided with a memory for storing instructions and data. In some examples, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0226] In some examples, processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0227] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some examples, the processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces. For example: the processor 110 may be coupled to the touch sensor 180K through the I2C interface, so that the processor 110 communicates with the touch sensor 180K through the I2C bus interface to realize the touch function of the terminal device 200.

[0228] The I2S interface can be used for audio communication. In some examples, the processor 110 can include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to achieve communication between the processor 110 and the audio module 170. In some examples, the audio module 170 can transmit an audio signal to the wireless communication module 160 via the I2S interface to achieve the function of answering a call through a Bluetooth headset.

[0229] The PCM interface can also be used for audio communication, sampling, quantizing and encoding analog signals. In some examples, the audio module 170 and the wireless communication module 160 can be coupled via a PCM bus interface. In some examples, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface to implement the function of answering calls via a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.

[0230] The UART interface is a universal serial data bus for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some examples, the UART interface is generally used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 through the UART interface to implement the Bluetooth function. In some examples, the audio module 170 can transmit an audio signal to the wireless communication module 160 through the UART interface to implement the function of playing music through a Bluetooth headset.

[0231] The MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some examples, the processor 110 and the camera 193 communicate via the CSI interface to implement the shooting function of the terminal device 200. The processor 110 and the display screen 194 communicate via the DSI interface to implement the display function of the terminal device 200.

[0232] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. In some examples, the GPIO interface can be used to connect the processor 110 with the camera 193, the display 194, the wireless communication module 160, the audio module 170, the sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.

[0233] The USB interface 130 is an interface that complies with the USB standard specification, and specifically can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the terminal device 200, and can also be used to transmit data between the terminal device 200 and peripheral devices. It can also be used to connect headphones to play audio through the headphones. The interface can also be used to connect other terminal devices, such as AR devices, etc.

[0234] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the terminal device 200. In other examples of the present application, the terminal device 200 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0235] The charging management module 140 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive wireless charging input through a wireless charging coil of the terminal device 200. While the charging management module 140 is charging the battery 142, it may also power the terminal device 200 through the power management module 141.

[0236] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and supplies power to the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle number, battery health status (leakage, impedance), etc. In some other examples, the power management module 141 can also be set in the processor 110. In some other examples, the power management module 141 and the charging management module 140 can also be set in the same device.

[0237] The wireless communication function of the terminal device 200 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.

[0238] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in terminal device 200 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In other examples, the antenna can be used in combination with a tuning switch.

[0239] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G applied to the terminal device 200. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some examples, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some examples, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.

[0240] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays an image or video through a display screen 194. In some examples, the modem processor may be an independent device. In other examples, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.

[0241] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the terminal device 200. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0242] In some examples, the terminal device 200 can access the Internet through a mobile network (such as 2G / 3G / 4G / 5G networks), a wireless network (such as Wi-Fi), or a wired network (such as broadband), and communicate with other devices through the network. The WLAN wireless communication solution provided by the wireless communication module 160 can also enable the terminal device 200 to communicate with a server (such as the server 100). For example, the terminal device 200 can receive a patch package sent by the server 200 through the network.

[0243] In some examples, the antenna 1 of the terminal device 200 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the terminal device 200 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology, etc. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite based augmentation system (SBAS).

[0244] The terminal device 200 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0245] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some examples, the terminal device 200 may include 1 or N display screens 194, where N is a positive integer greater than 1.

[0246] The terminal device 200 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.

[0247] ISP is used to process the data fed back by camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise, brightness, etc. of the image. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some examples, ISP can be set in camera 193.

[0248] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP for conversion into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some examples, the terminal device 200 may include 1 or N cameras 193, where N is a positive integer greater than 1.

[0249] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the terminal device 200 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.

[0250] Video codecs are used to compress or decompress digital videos. The terminal device 200 may support one or more video codecs. Thus, the terminal device 200 may play or record videos in multiple coding formats, such as moving picture experts group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.

[0251] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of the terminal device 200 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.

[0252] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the terminal device 200. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0253] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the terminal device 200 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the terminal device 200 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0254] In some examples of the present application, the internal memory 121 may be used to store the implementation program of the patch file generation method and the patching method provided in one or more embodiments of the present application on the terminal device 200 side. The processor 110 may be used to read and execute computer-readable instructions. Specifically, the processor 100 may be used to call a program stored in the internal memory 121, such as the implementation program of the patch file generation method and the patching method provided in one or more embodiments of the present application on the terminal device 200 side, and execute the instructions contained in the program.

[0255] The terminal device 200 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.

[0256] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some examples, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.

[0257] The speaker 170A, also called a "speaker", is used to convert an audio electrical signal into a sound signal. The terminal device 200 can listen to music or listen to a hands-free call through the speaker 170A.

[0258] The receiver 170B, also called a "handset", is used to convert audio electrical signals into sound signals. When the terminal device 200 receives a call or voice message, the voice can be received by placing the receiver 170B close to the ear.

[0259] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can speak by putting their mouth close to microphone 170C to input the sound signal into microphone 170C. The terminal device 200 can be provided with at least one microphone 170C. In other examples, the terminal device 200 can be provided with two microphones 170C, which can not only collect sound signals but also realize noise reduction function. In other examples, the terminal device 200 can also be provided with three, four or more microphones 170C to collect sound signals, reduce noise, identify the source of sound, realize directional recording function, etc.

[0260] The earphone interface 170D is used to connect a wired earphone and can be a USB interface 130 or a 3.5 mm open mobile terminal platform (OMTP) standard interface or a cellular telecommunications industry association of the USA (CTIA) standard interface.

[0261] The touch sensor 180K is also called a "touch panel". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other examples, the touch sensor 180K can also be set on the surface of the terminal device 200, which is different from the position of the display screen 194.

[0262] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The terminal device 200 may receive key input and generate key signal input related to user settings and function control of the terminal device 200.

[0263] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (for example: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.

[0264] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, messages, missed calls, notifications, etc.

[0265] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to and separated from the terminal device 200 by inserting the SIM card interface 195 or pulling it out from the SIM card interface 195. The terminal device 200 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, and the like. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The terminal device 200 interacts with the network through the SIM card to implement functions such as calls and data communications. In some examples, the terminal device 200 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the terminal device 200 and cannot be separated from the terminal device 200.

[0266] It should be understood that Figure 8 The terminal device 200 shown is only an example, and the terminal device 200 may have more Figure 8 More or fewer components may be shown, two or more components may be combined, or there may be a different configuration of components. Figure 8 The various components shown in the EMBODIMENTS 2000 may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.

[0267] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can 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. When the computer program instructions are loaded and executed on a computer, the process or function described in the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state disk (SSD)), etc.

[0268] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.

[0269] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A patch file generation method, characterized in that: The method comprises: Obtain a first file in a first version installation package and a second file in a second version installation package, wherein the first version is a higher version of the second version, the first file is used to indicate a class used in the first version installation package and member variables and member methods included in the class, and the second file is used to indicate a class used in the second version installation package and member variables and member methods included in the class; Determine, based on the first file and the second file, a difference class between the first version installation package and the second version installation package, and a difference member variable and a difference member method included in the difference class; A patch file is generated based on the difference class, the difference member variables and the difference member methods included in the difference class.

2. The method according to claim 1, characterized in that The difference class includes one or more of a deleted class, a newly added class, and a replaced class, wherein the deleted class is a class that is not included in the first file but included in the second file, the newly added class is a class that is included in the first file but not included in the second file, and the replaced class is a class that is included in both the first file and the second file but has different member variables and / or member methods.

3. The method according to claim 1 or 2, characterized in that: The difference member variables include one or more of deleted member variables, newly added member variables, and replaced member variables, wherein the deleted member variables are member variables not included in the first file but included in the second file, the newly added member variables are member variables included in the first file but not included in the second file, and the replaced member variables are member variables included in both the first file and the second file but with different contents.

4. The method according to any one of claims 1 to 3, characterized in that The difference member method includes one or more of a member deletion method, a member addition method, and a member replacement method, wherein the member deletion method is a member method not included in the first file but included in the second file, the member addition method is a member method included in the first file but not included in the second file, and the member replacement method is a member method included in both the first file and the second file but with different contents.

5. The method according to any one of claims 2 to 4, characterized in that: The patch file includes a first section header, the first section header includes first indication information, and the first indication information is used to indicate a first position of the deleted class in the second version installation package; or, The first section header includes second indication information, where the second indication information is used to indicate a second position of the newly added class in the patch file; or, The first section header includes third indication information, and the third indication information is used to indicate the third position of the replacement class in the patch file and the fourth position in the second version installation package.

6. The method according to claim 5, characterized in that The patch file also includes a file header, and the file header includes indication information of the difference class, and the indication information of the difference class points to the first section header.

7. The method according to claim 5 or 6, characterized in that: The patch file also includes a second section header, the second section header includes fourth indication information, and the fourth indication information is used to indicate the fifth position of the deleted member variable in the second version installation package; or, the second section header includes fifth indication information, and the fifth indication information is used to indicate the sixth position of the newly added member variable in the patch file; or, the second section header includes sixth indication information, and the sixth indication information is used to indicate the seventh position of the replaced member variable in the patch file and the eighth position in the second version installation package; and / or, The second node header includes seventh indication information, and the seventh indication information is used to indicate the ninth position of the member deletion method in the second version installation package; or, the second node header includes eighth indication information, and the eighth indication information is used to indicate the tenth position of the new member addition method in the patch file; or, the second node header includes ninth indication information, and the ninth indication information is used to indicate the member replacement method is at the eleventh position in the patch file and at the twelfth position in the second version installation package.

8. The method according to any one of claims 1 to 7, characterized in that Both the first file and the second file include a file header, the file header includes class indication information, the class indication information points to a first independent data section, the first independent data section includes class information and member variable indication information and member method indication information included in the class, the member variable indication information points to a second independent data section, the member method indication information points to a third independent data section, the second independent data section includes member variable information, and the third independent data section includes member method information.

9. The method according to any one of claims 1 to 8, characterized in that: The patch file generation method is executed by a server.

10. A patching method, characterized in that: The method comprises: The terminal device obtains a patch file, where the patch file is generated based on a difference class between a first version installation package and a second version installation package, and a difference member variable and a difference member method included in the difference class, where the difference class, and the difference member variable and the difference member method included in the difference class are determined based on a first file and a second file, where the first file is a file in the first version installation package, and the second file is a file in the second version installation package, where the first version is a higher version of the second version, where the first file is used to indicate a class used in the first version installation package and the member variables and member methods included in the class, and where the second file is used to indicate a class used in the second version installation package and the member variables and member methods included in the class; The terminal device performs an update operation on the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class to generate the first version installation package.

11. The method according to claim 10, characterized in that The difference class includes one or more of a deleted class, a newly added class, and a replaced class, wherein the deleted class is a class that is not included in the first file but included in the second file, the newly added class is a class that is included in the first file but not included in the second file, and the replaced class is a class that is included in both the first file and the second file but has different member variables and / or member methods.

12. The method according to claim 10 or 11, characterized in that: The difference member variables include one or more of deleted member variables, newly added member variables, and replaced member variables, wherein the deleted member variables are member variables not included in the first file but included in the second file, the newly added member variables are member variables included in the first file but not included in the second file, and the replaced member variables are member variables included in both the first file and the second file but with different contents.

13. The method according to any one of claims 10 to 12, characterized in that: The difference member method includes one or more of a member deletion method, a member addition method, and a member replacement method, wherein the member deletion method is a member method not included in the first file but included in the second file, the member addition method is a member method included in the first file but not included in the second file, and the member replacement method is a member method included in both the first file and the second file but with different contents.

14. The method according to any one of claims 11 to 13, characterized in that The patch file includes a first section header, the first section header includes first indication information, the first indication information is used to indicate a first position of the deletion class in the second version installation package, and the terminal device performs an update operation on the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class, specifically including: the terminal device deletes the deletion class at the first position; or, The first section header includes second indication information, and the second indication information is used to indicate a second position of the newly added class in the patch file. The terminal device performs an update operation on the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class, specifically including: the terminal device obtains the newly added class at the second position and adds the newly added class to the second version installation package; or, The first section header includes third indication information, and the third indication information is used to indicate the third position of the replacement class in the patch file and the fourth position in the second version installation package. The terminal device updates the second version installation package based on the difference class and the difference member variables and difference member methods included in the difference class, which specifically includes: the terminal device restores the replacement class in the second version installation package based on the third position and the fourth position.

15. The method according to claim 14, characterized in that The patch file also includes a file header, and the file header includes indication information of the difference class, and the indication information of the difference class points to the first section header.

16. The method according to claim 14 or 15, characterized in that The patch file also includes a second section header, the second section header includes fourth indication information, the fourth indication information is used to indicate the fifth position of the deleted member variable in the second version installation package, and the terminal device updates the second version installation package based on the difference class, the difference member variables included in the difference class, and the difference member method, specifically including: the terminal device deletes the deleted member variable at the fifth position; or the second section header includes fifth indication information, the fifth indication information is used to indicate the sixth position of the newly added member variable in the patch file, and the terminal device updates the second version installation package based on the difference class, the difference member variables included in the difference class, and the difference member method The method performs an update operation on the second version installation package, specifically including: the terminal device obtains the member variable at the sixth position and adds the newly added member variable in the second version installation package; or, the second section header includes sixth indication information, and the sixth indication information is used to indicate the seventh position of the replacement member variable in the patch file and the eighth position in the second version installation package, and the terminal device performs an update operation on the second version installation package based on the difference class, the difference member variables included in the difference class, and the difference member method, specifically including: the terminal device restores the replacement member variable in the second version installation package based on the seventh position and the eighth position; and / or, The second section header includes seventh indication information, and the seventh indication information is used to indicate the ninth position of the member deletion method in the second version installation package. The terminal device updates the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class, specifically including: the terminal device deletes the member deletion method at the ninth position; or the second section header includes eighth indication information, and the eighth indication information is used to indicate the tenth position of the new member method in the patch file, and the terminal device updates the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class. An update operation is performed, specifically including: the terminal device obtains the new member method at the tenth position and adds the new member method to the second version installation package; or, the second section header includes ninth indication information, and the ninth indication information is used to indicate that the replacement member method is at the eleventh position in the patch file and at the twelfth position in the second version installation package. The terminal device performs an update operation on the second version installation package based on the difference class, the difference member variables and the difference member methods included in the difference class, specifically including: the terminal device restores the replacement member method in the second version installation package based on the eleventh position and the twelfth position.

17. The method according to any one of claims 10 to 16, characterized in that Both the first file and the second file include a file header, the file header includes class indication information, the class indication information points to a first independent data section, the first independent data section includes class information and member variable indication information and member method indication information included in the class, the member variable indication information points to a second independent data section, the member method indication information points to a third independent data section, the second independent data section includes member variable information, and the third independent data section includes member method information.

18. An electronic device, characterized in that: The electronic device includes one or more processors and one or more memories; wherein the one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program code, and the computer program code includes computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes the method described in any one of claims 1-9 or 10-17.

19. A computer storage medium, characterized in that: The computer storage medium stores a computer program, which includes program instructions. When the program instructions are executed on an electronic device, the electronic device executes the method as claimed in any one of claims 1 to 9 or 10 to 17.