A symbol recovery method and apparatus

By generating and adding symbol description information, the inefficient update and maintenance problems caused by the missing symbol table are solved, and efficient symbol recovery and application code understanding are achieved.

CN114327567BActive Publication Date: 2025-07-22DOUYIN VISION CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210008413.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-05
Publication Date
2025-07-22
Estimated Expiration
2042-01-05

AI Technical Summary

Technical Problem

During the application packaging process, the symbol table is deleted, causing developers to be unable to understand the meaning of the application code. They need to compare the code with symbols one by one, which is extremely inefficient.

Method used

By obtaining the target application file and debugging information file, the symbol description information is generated, the symbol attribute information is determined, and the symbol attribute information is added to the executable file, the loading command information is updated, and the symbol table content is restored.

Benefits of technology

There is no need to analyze symbol information one by one, which improves the efficiency of symbol recovery and simplifies the update and maintenance process of the application.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114327567B_ABST
    Figure CN114327567B_ABST
Patent Text Reader

Abstract

The present disclosure provides a symbol recovery method and apparatus, which obtain a target application file and a debug information file corresponding to the target application file; generate description information of symbols to be recovered based on the debug information file; determine attribute information of the symbols to be recovered based on the description information of the symbols to be recovered; update the load command information in the target application file by using the attribute information of the symbols to be recovered, and add the description information of the symbols to be recovered to the executable file of the target application file to obtain a recovered target application file. The present disclosure generates description information of symbols to be recovered through a debug information file, then determines the attribute information of the symbols according to the description information of the symbols, so as to realize the recovery of the symbol table content, and then updates the recovered content to the load command information and the executable file, without the need for developers to analyze the information of each symbol one by one, and the efficiency is higher.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technologies, and more particularly, to a symbol recovery method and apparatus. Background Art

[0002] Symbols are variable names and function names in an application. Through the definition of symbols, the code can directly reference the symbols. During the process of developing source code, a symbol table is usually prepared to record information about various symbols in the source code, such as type, name, number of bytes, etc., to facilitate the compilation of the source code into an executable file.

[0003] Since the symbol table is not used during the normal operation of the application, during the packaging process of the application, the symbol table data is usually deleted to reduce the size of the application package. Due to the lack of the symbol table, developers must hold a backup file of the symbol table. Otherwise, they cannot know the information of each symbol in the application, and thus cannot understand the meaning of the application code, and cannot update and maintain the application. If the backed-up symbol table is lost due to an uncontrollable force, developers need to analyze the code symbol by symbol, which is extremely inefficient. Summary of the Invention

[0004] Embodiments of the present disclosure provide at least a symbol recovery method and apparatus.

[0005] In a first aspect, embodiments of the present disclosure provide a symbol recovery method, including:

[0006] Obtaining a target application file and a debug information file corresponding to the target application file;

[0007] Generating description information of symbols to be recovered based on the debug information file;

[0008] Determining attribute information of the symbols to be recovered based on the description information of the symbols to be recovered;

[0009] Updating the load command information in the target application file by using the attribute information of the symbols to be recovered, and adding the description information of the symbols to be recovered to the executable file of the target application file to obtain a recovered target application file.

[0010] In an optional implementation, the debug information file includes a first symbol table and a first string table; the symbols to be recovered include a first symbol in the first symbol table and a second symbol in the first string table;

[0011] The generating description information of symbols to be recovered based on the debug information file includes:

[0012] Generating description information of the first symbol based on the first symbol table in the debug information file;

[0013] Generate the description information of the second symbol based on the first string table in the debug information file.

[0014] In an alternative embodiment, the attribute information of the symbol to be restored includes at least one of the following:

[0015] The total number of symbols to be restored, the field size of the description information of the first symbol, the field size of the description information of the second symbol, the total field size of the description information of the first symbol and the second symbol.

[0016] In an alternative embodiment, the executable file includes a second symbol table and a second string table;

[0017] Adding the description information of the symbol to be restored to the executable file of the target application file includes:

[0018] Determine the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file;

[0019] Based on the offset position at the end of the second string table, insert the description information of the second symbol at the end of the second string table;

[0020] Based on the offset position at the end of the second symbol table, insert the description information of the second symbol at the end of the second string table.

[0021] In an alternative embodiment, before inserting the description information of the second symbol at the end of the second string table based on the offset position at the end of the second string table, the method further includes:

[0022] Determine the actual field size of the second string table based on the field size of the second string table and the number of padding characters in the second string table;

[0023] Determine the number of padding characters required for the second string table after insertion based on the field size of the description information of the second symbol and the actual field size of the second string table;

[0024] Determine the number of additional padding characters required based on the number of padding characters required for the second string table after insertion and the number of padding characters in the second string table before insertion;

[0025] Pad the description information of the second symbol based on the number of additional padding characters.

[0026] In an alternative embodiment, adding the description information of the symbol to be restored to the executable file of the target application file includes:

[0027] Create a continuous target memory area based on the total field size of the description information of the first symbol and the second symbol, and the total field size of the target application file;

[0028] Determine the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file;

[0029] Cut the target application file based on the offset position at the end of the second symbol table and the offset position at the end of the second string table to obtain a first sub-file, a second sub-file, and a third sub-file arranged in sequence;

[0030] Write the first sub-file, the description information of the first symbol, the second sub-file, the description information of the second symbol, and the third sub-file into the target memory area in sequence to obtain the executable file after adding the description information.

[0031] In an alternative embodiment, the method further includes:

[0032] Perform code analysis on the target application file based on the executable file in the restored target application file to obtain the attribute information of the executable file.

[0033] In a second aspect, an embodiment of the present disclosure further provides a symbol restoration device, including:

[0034] An acquisition module, configured to acquire a target application file and a debug information file corresponding to the target application file;

[0035] A generation module, configured to generate description information of a symbol to be restored based on the debug information file;

[0036] A determination module, configured to determine the attribute information of the symbol to be restored based on the description information of the symbol to be restored;

[0037] A restoration module, configured to update the load command information in the target application file by using the attribute information of the symbol to be restored, and add the description information of the symbol to be restored to the executable file of the target application file to obtain the restored target application file.

[0038] In an alternative embodiment, the debug information file includes a first symbol table and a first string table; the symbol to be restored includes a first symbol in the first symbol table and a second symbol in the first string table;

[0039] The generation module is specifically configured to:

[0040] Generate the description information of the first symbol based on the first symbol table in the debug information file;

[0041] Generate the description information of the second symbol based on the first string table in the debug information file.

[0042] In an alternative embodiment, the attribute information of the symbol to be restored includes at least one of the following:

[0043] The total number of symbols to be restored, the field size of the description information of the first symbol, the field size of the description information of the second symbol, the total field size of the description information of the first symbol and the second symbol.

[0044] In an alternative embodiment, the executable file includes a second symbol table and a second string table;

[0045] The recovery module is specifically configured to:

[0046] Determine the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file;

[0047] Based on the offset position at the end of the second string table, insert the description information of the second symbol to the end of the second string table;

[0048] Based on the offset position at the end of the second symbol table, insert the description information of the second symbol to the end of the second string table.

[0049] In an alternative embodiment, before inserting the description information of the second symbol to the end of the second string table based on the offset position at the end of the second string table, the recovery module is further configured to:

[0050] Determine the actual field size of the second string table based on the field size of the second string table and the number of padding characters of the second string table;

[0051] Determine the number of padding characters required for the second string table after insertion based on the field size of the description information of the second symbol and the actual field size of the second string table;

[0052] Determine the number of additional padding characters required based on the number of padding characters required for the second string table after insertion and the number of padding characters of the second string table before insertion;

[0053] Perform character padding on the description information of the second symbol based on the number of additional padding characters.

[0054] In an alternative embodiment, when adding the description information of the symbol to be restored to the executable file of the target application file, the restoration module is configured to:

[0055] Create a continuous target memory area based on the total field size of the description information of the first symbol and the second symbol, and the total field size of the target application file;

[0056] Determine the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file;

[0057] Cut the target application file based on the offset position at the end of the second symbol table and the offset position at the end of the second string table to obtain a first sub-file, a second sub-file, and a third sub-file arranged in sequence;

[0058] Write the first sub-file, the description information of the first symbol, the second sub-file, the description information of the second symbol, and the third sub-file into the target memory area in sequence to obtain an executable file with the description information added.

[0059] In an alternative embodiment, the apparatus further includes an analysis module, configured to:

[0060] Perform code analysis on the target application file based on the executable file in the restored target application file to obtain the attribute information of the executable file.

[0061] In a third aspect, an embodiment of the present disclosure further provides an electronic device, including: a processor, a memory, and a bus, where the memory stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the memory through the bus. When the machine-readable instructions are executed by the processor, the steps in the first aspect, or any possible implementation manner in the first aspect, are executed.

[0062] In a fourth aspect, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, the steps in the first aspect, or any possible implementation manner in the first aspect, are executed.

[0063] The symbol recovery method and device provided by the embodiments of the present disclosure obtain a target application file and a debug information file corresponding to the target application file; generate description information of symbols to be recovered based on the debug information file; determine attribute information of the symbols to be recovered based on the description information of the symbols to be recovered; update the load command information in the target application file by using the attribute information of the symbols to be recovered, and add the description information of the symbols to be recovered to the executable file of the target application file to obtain the recovered target application file. The present disclosure generates description information of symbols to be recovered through a debug information file, and then determines the attribute information of the symbols according to the description information of the symbols, so as to realize the recovery of the symbol table content, and then update the recovered content to the load command information and the executable file. It is not necessary for developers to analyze the information of symbols one by one, and the efficiency is higher.

[0064] To make the above objects, features and advantages of the present disclosure more obvious and understandable, the following specific embodiments are given in detail in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0065] To more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following briefly introduces the accompanying drawings required to be used in the embodiments. The accompanying drawings are incorporated into the specification and constitute a part of the specification. These drawings show the embodiments that conform to the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only show some embodiments of the present disclosure, and therefore should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.

[0066] Figure 1 Shows a flowchart of a symbol recovery method provided by an embodiment of the present disclosure;

[0067] Figure 2 Shows a flowchart of another symbol recovery method provided by an embodiment of the present disclosure;

[0068] Figure 3 Shows a schematic diagram of a symbol recovery device provided by an embodiment of the present disclosure;

[0069] Figure 4 Shows a schematic diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0070] To make the objectives, technical solutions, and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Apparently, the described embodiments are only some, rather than all, of the embodiments of the present disclosure. Components of the embodiments of the present disclosure described and illustrated in the drawings herein can be arranged and designed in a variety of different configurations. Therefore, the detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the claimed present disclosure, but merely represents selected embodiments of the present disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of the present disclosure without creative efforts shall fall within the scope of protection of the present disclosure.

[0071] It should be noted that like reference numerals and letters denote like items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0072] The term "and / or" in this document merely describes an association relationship and indicates that three relationships may exist. For example, A and / or B may represent three cases: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the term "at least one" in this document means any one of multiple items or any combination of at least two of multiple items. For example, including at least one of A, B, and C may represent selecting any one or more elements from the set composed of A, B, and C.

[0073] Since the symbol table is not used during the normal operation of the application, the symbol table data is usually deleted during the packaging process of the application to reduce the size of the application package. Due to the lack of the symbol table, developers must hold a backup file of the symbol table. Otherwise, they cannot know the information of each symbol in the application, and thus cannot understand the meaning of the application code, and cannot update and maintain the application. If the backed-up symbol table is lost due to uncontrollable forces, developers need to analyze the code symbol by symbol, which is extremely inefficient.

[0074] To solve the technical problem of the low efficiency of manually restoring symbol information by developers, the present disclosure provides a symbol restoration method. The description information of the symbols to be restored is generated from the debug information file, and then the attribute information of the symbols is determined according to the description information of the symbols, thereby realizing the restoration of the symbol table content. Then, the restored content is updated to the load command information and the executable file, eliminating the need for developers to analyze the symbol information one by one, resulting in higher efficiency.

[0075] For ease of understanding of this embodiment, first, a symbol recovery method disclosed in the embodiments of the present disclosure will be introduced in detail. The execution subject of the symbol recovery method provided in the embodiments of the present disclosure is generally a computer device with certain computing capabilities. In some possible implementation manners, the symbol recovery method can be implemented by a processor calling computer-readable instructions stored in a memory.

[0076] See Figure 1 As shown, it is a flowchart of the symbol recovery method provided in the embodiments of the present disclosure. The method includes steps S101 to S104, where:

[0077] S101. Obtain a target application file and a debug information file corresponding to the target application file.

[0078] In this step, the target application file can be an installation package file of an application, also known as an ipa file in the iOS system. The debug information file of the target application file can be a dSYM file, and the file name is usually xxx.app.dSYM. The debug information file usually contains the debug information of the application program and is a kind of object file (.o file), and its symbol type is MH_DSYM. The debug information will be in the installation package only after being packaged in some specific ways, such as the Xcode method, otherwise, developers need to back it up by themselves. The dSYM file is usually used to provide the function name and file name corresponding to the error function address for crash analysis.

[0079] Exemplarily, the symbol table symbol tabal and the string table Stringtable in the dSYM file can be extracted. The symbols in the symbols under the symbol table path can contain the offset information of each symbol, and the string table can contain the attribute information of each symbol. The symbols corresponding to the symbol table and the string table can be the same, and the information they contain can be different types of information of the same part of the symbols.

[0080] Here, the symbol table of the dSYM file can be called the first symbol table, and the corresponding symbol can be called the first symbol. The string table in the dSYM file can be called the first string table, and its corresponding symbol can be called the second symbol. Actually, the first symbol and the second symbol may refer to the same symbol.

[0081] S102. Generate description information of the symbols to be recovered based on the debug information file.

[0082] After obtaining the debug information file, the debug information file can be analyzed, the information in the first symbol table and the first string table can be extracted, and then the description information of the first symbol can be extracted from the first symbol table, and the description information of the second symbol can be extracted from the second symbol table.

[0083] Here, the generated description information can be in the NSData format. The file name of the description information of the first symbol can be symbol_table_append_data, which means appending data to the symbol table. The file name of the description information of the second symbol can be string_table_append_data, which means appending data to the string table. By adding the above two contents to the executable file, the restoration of the symbol can be completed.

[0084] S103. Determine the attribute information of the symbol to be restored based on the description information of the symbol to be restored.

[0085] When adding the description information to the executable file, some information related to the symbol in the executable file also needs to be modified, so that the added description information can be correctly used and prevent other codes of the application from becoming unusable due to the offset of new data.

[0086] Therefore, it is necessary to determine the attribute information of the symbol to be restored newly added and modify the data related to the symbol in the executable file using the attribute information.

[0087] Specifically, the attribute information of the symbol to be restored can include at least one of the following:

[0088] The total number of symbols to be restored, the field size of the description information of the first symbol, the field size of the description information of the second symbol, the total field size of the description information of the first symbol and the second symbol.

[0089] Here, the total number of symbols to be restored is the total number of symbols that need to be added to the executable file, and the field size of the description information is the size of the storage space occupied by this section of the description information.

[0090] Specifically, the description information of the first symbol can be added to the end of the symbol table of the executable file of the target application respectively, and the description information of the second symbol can be added to the end of the string table of the executable file of the target application. The symbol table of the above executable file is the second symbol table, and the string table of the executable file is the second string table.

[0091] Since adding the description information will cause the data after the description information to shift, and the offset is related to the field size of the description information, it is necessary to modify the offset of the subsequent data and the data related to the offset of the subsequent data based on the field size of the description information of the first symbol and the field size of the description information of the second symbol.

[0092] Exemplarily, first, based on the field size of the first symbol, the offset position after offset at the end of the second symbol table in the executable file can be determined. Then, the data after the second symbol table is offset to a position after the offset position at the end of the second symbol table. In the blank area generated by the offset, the description information of the first symbol is added. Correspondingly, based on the field sizes of the description information of the first symbol and the second symbol, the offset position at the end of the second string table needs to be determined, and then the description information of the second symbol is added to the blank area generated by the offset.

[0093] Here, the order of the second symbol table and the second string table in the executable file can be determined first, and the data with a later position can be processed first, so as to reduce the calculation amount of the offset.

[0094] For adding the description information implemented by the C language method, if the description information is directly added, the data subsequent to the addition position will be overwritten by the newly added data. Therefore, a memory area can be created, the executable file is split at two insertion positions, and then the split executable file and the description information are sequentially added to the created memory area according to the order after adding the description information, and the insertion of the description information can be completed.

[0095] Specifically, a continuous target memory area can be created based on the total field size of the description information of the first symbol and the second symbol, and the total field size of the target application file; then, the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file can be determined; then, based on the offset position at the end of the second symbol table and the offset position at the end of the second string table, the target application file is cut to obtain the first sub-file, the second sub-file, and the third sub-file arranged in sequence; finally, the first sub-file, the description information of the first symbol, the second sub-file, the description information of the second symbol, and the third sub-file are sequentially written into the target memory area to obtain the executable file after adding the description information.

[0096] When adding the description information, considering that the code needs to be filled and aligned, therefore, based on the field size of the second string table and the number of its padding characters, the actual field size of the second string table can be determined. Then, based on the field size of the description information of the second symbol and the actual field size of the second string table, the number of padding characters required for the second string table after insertion can be determined. Then, based on the number of existing padding characters in the second string table and the number of padding characters required after insertion, the number of padding characters that need to be newly added can be determined. Finally, according to the number of newly added padding characters, the description information of the first symbol is filled with characters, and then the filled description information of the second symbol is added to the executable file. Similar steps can be adopted for the second symbol table and the description information of the first symbol to achieve code filling and alignment.

[0097] S104. Update the load command information in the target application file by using the attribute information of the symbol to be restored, and add the description information of the symbol to be restored to the executable file of the target application file, so as to obtain the restored target application file.

[0098] In this step, after adding the description information, it is also necessary to update the load command information in the target application file, that is, the load command, modify the information of the load symbol table address LC_SYMTAB therein, modify the number of symbols indicated by its string, the offset stroff of the string, and the size strsize of the string; modify the information of the load dynamic symbol table address LC_DYSYMTAB, and modify the offset of its indirect symbol table; modify the information of the mapping to the process address space LC_SEGMENT_64(__LINKEDIT), and modify its file size filesize and virtual memory size Vmsize.

[0099] After obtaining the restored target application file, the executable file can be analyzed to obtain the attribute information of the executable file, which is used for operations such as maintenance and upgrade, and crash location.

[0100] See Figure 2 As shown, it is a flowchart of another symbol restoration device provided by an embodiment of the present disclosure. This method extracts the description information of the symbol from the dSYM file, extracts the executable file Mach-O from the installation package ipa, then inserts the extracted description information into the executable file, first collects the offset information offset and the size information of the added field, then uses the collected information to modify the load command information, and finally inserts the binary data of the description information at the corresponding offset position.

[0101] The symbol restoration method provided by the embodiment of the present disclosure includes: obtaining a target application file and a debug information file corresponding to the target application file; generating description information of a symbol to be restored based on the debug information file; determining attribute information of the symbol to be restored based on the description information of the symbol to be restored; updating the load command information in the target application file by using the attribute information of the symbol to be restored, and adding the description information of the symbol to be restored to the executable file of the target application file, so as to obtain the restored target application file. The present disclosure generates the description information of the symbol to be restored through the debug information file, then determines the attribute information of the symbol according to the description information of the symbol, thereby realizing the restoration of the symbol table content, and then updates the restored content to the load command information and the executable file, without the need for developers to analyze the symbol information one by one, and the efficiency is higher.

[0102] Those skilled in the art can understand that in the above methods of the specific embodiments, the writing order of each step does not mean a strict execution order and does not impose any limitation on the implementation process. The specific execution order of each step should be determined according to its function and possible internal logic.

[0103] Based on the same inventive concept, the embodiments of the present disclosure also provide a symbol recovery device corresponding to the symbol recovery method. Since the principle of solving problems by the device in the embodiments of the present disclosure is similar to the above symbol recovery method of the embodiments of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.

[0104] Refer to Figure 3 As shown, it is a schematic diagram of a symbol recovery device provided by an embodiment of the present disclosure. The device includes:

[0105] In a second aspect, the embodiments of the present disclosure also provide a symbol recovery device, including:

[0106] An acquisition module 310, configured to acquire a target application file and a debug information file corresponding to the target application file;

[0107] A generation module 320, configured to generate description information of symbols to be recovered based on the debug information file;

[0108] A determination module 330, configured to determine attribute information of the symbols to be recovered based on the description information of the symbols to be recovered;

[0109] A recovery module 340, configured to update the loading command information in the target application file by using the attribute information of the symbols to be recovered, and add the description information of the symbols to be recovered to the executable file of the target application file to obtain a recovered target application file.

[0110] In an optional implementation manner, the debug information file includes a first symbol table and a first string table; the symbols to be recovered include a first symbol in the first symbol table and a second symbol in the first string table;

[0111] The generation module 320 is specifically configured to:

[0112] Generate description information of the first symbol based on the first symbol table in the debug information file;

[0113] Generate description information of the second symbol based on the first string table in the debug information file.

[0114] In an optional implementation manner, the attribute information of the symbols to be recovered includes at least one of the following:

[0115] The total number of symbols to be restored, the field size of the description information of the first symbol, the field size of the description information of the second symbol, and the total field size of the description information of the first symbol and the second symbol.

[0116] In an alternative embodiment, the executable file includes a second symbol table and a second string table;

[0117] The restoration module 340 is specifically configured to:

[0118] Determine the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file;

[0119] Based on the offset position at the end of the second string table, insert the description information of the second symbol to the end of the second string table;

[0120] Based on the offset position at the end of the second symbol table, insert the description information of the second symbol to the end of the second string table.

[0121] In an alternative embodiment, before inserting the description information of the second symbol to the end of the second string table based on the offset position at the end of the second string table, the restoration module 340 is further configured to:

[0122] Based on the field size of the second string table and the number of padding characters in the second string table, determine the actual field size of the second string table;

[0123] Based on the field size of the description information of the second symbol and the actual field size of the second string table, determine the number of padding characters required for the second string table after insertion;

[0124] Based on the number of padding characters required for the second string table after insertion and the number of padding characters in the second string table before insertion, determine the number of additional padding characters required;

[0125] Based on the number of additional padding characters, perform character padding on the description information of the second symbol.

[0126] In an alternative embodiment, when adding the description information of the symbol to be restored to the executable file of the target application file, the restoration module 340 is configured to:

[0127] Based on the total field size of the description information of the first symbol and the second symbol and the total field size of the target application file, create a continuous target memory area;

[0128] Determine the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file;

[0129] Based on the offset position at the end of the second symbol table and the offset position at the end of the second string table, cut the target application file to obtain the first sub-file, the second sub-file, and the third sub-file arranged in sequence;

[0130] Write the first sub-file, the description information of the first symbol, the second sub-file, the description information of the second symbol, and the third sub-file into the target memory area in sequence to obtain an executable file with description information added.

[0131] In an optional implementation manner, the device further includes an analysis module, configured to:

[0132] Based on the executable file in the restored target application file, perform code analysis on the target application file to obtain the attribute information of the executable file.

[0133] The symbol recovery device provided by the embodiments of the present disclosure obtains a target application file and the corresponding debug information file of the target application file; generates description information of symbols to be recovered based on the debug information file; determines the attribute information of the symbols to be recovered based on the description information of the symbols to be recovered; updates the load command information in the target application file by using the attribute information of the symbols to be recovered, and adds the description information of the symbols to be recovered to the executable file of the target application file to obtain a restored target application file. The present disclosure generates description information of symbols to be recovered through a debug information file, and then determines the attribute information of the symbols according to the description information of the symbols, so as to realize the recovery of the content of the symbol table, and then update the recovered content to the load command information and the executable file. It does not require developers to analyze the information of symbols one by one, and the efficiency is higher.

[0134] Corresponding to Figure 1 the symbol recovery method in Figure 4 as shown, which is a schematic structural diagram of an electronic device 400 provided by the embodiments of the present disclosure, including:

[0135] A processor 41, a memory 42, and a bus 43; the memory 42 is used to store execution instructions, including an internal memory 421 and an external memory 422; the internal memory 421 here is also called the main memory, and is used to temporarily store the operation data in the processor 41 and the data exchanged with the external memory 422 such as a hard disk. The processor 41 exchanges data with the external memory 422 through the internal memory 421. When the electronic device 400 runs, the processor 41 communicates with the memory 42 through the bus 43, so that the processor 41 executes the following instructions:

[0136] Obtain the target application file and the corresponding debug information file for the target application file;

[0137] Generate description information of symbols to be restored based on the debug information file;

[0138] Determine the attribute information of the symbols to be restored based on the description information of the symbols to be restored;

[0139] Update the load command information in the target application file using the attribute information of the symbols to be restored, and add the description information of the symbols to be restored to the executable file of the target application file to obtain the restored target application file.

[0140] In an optional implementation, the debug information file includes a first symbol table and a first string table; the symbols to be restored include the first symbols in the first symbol table and the second symbols in the first string table;

[0141] The generating description information of symbols to be restored based on the debug information file includes:

[0142] Generate description information of the first symbols based on the first symbol table in the debug information file;

[0143] Generate description information of the second symbols based on the first string table in the debug information file.

[0144] In an optional implementation, the attribute information of the symbols to be restored includes at least one of the following:

[0145] The total number of symbols to be restored, the field size of the description information of the first symbols, the field size of the description information of the second symbols, the total field size of the description information of the first symbols and the second symbols.

[0146] In an optional implementation, the executable file includes a second symbol table and a second string table;

[0147] The adding the description information of the symbols to be restored to the executable file of the target application file includes:

[0148] Determine the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file;

[0149] Insert the description information of the second symbols at the end of the second string table based on the offset position at the end of the second string table;

[0150] Insert the description information of the second symbols at the end of the second string table based on the offset position at the end of the second symbol table.

[0151] In an alternative embodiment, before inserting the description information of the second symbol at the offset position at the end of the second string table, the method further includes:

[0152] Determine the actual field size of the second string table based on the field size of the second string table and the number of padding characters of the second string table;

[0153] Determine the number of padding characters required for the second string table after insertion based on the field size of the description information of the second symbol and the actual field size of the second string table;

[0154] Determine the number of additional padding characters required based on the number of padding characters required for the second string table after insertion and the number of padding characters of the second string table before insertion;

[0155] Perform character padding on the description information of the second symbol based on the number of additional padding characters.

[0156] In an alternative embodiment, adding the description information of the symbol to be restored to the executable file of the target application file includes:

[0157] Create a continuous target memory area based on the total field size of the description information of the first symbol and the second symbol and the total field size of the target application file;

[0158] Determine the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file;

[0159] Cut the target application file based on the offset position at the end of the second symbol table and the offset position at the end of the second string table to obtain a first sub-file, a second sub-file, and a third sub-file arranged in sequence;

[0160] Write the first sub-file, the description information of the first symbol, the second sub-file, the description information of the second symbol, and the third sub-file into the target memory area in sequence to obtain the executable file after adding the description information.

[0161] In an alternative embodiment, the method further includes:

[0162] Perform code analysis on the target application file based on the executable file in the restored target application file to obtain the attribute information of the executable file.

[0163] Embodiments of the present disclosure also provide a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, it executes the steps of the symbol recovery method described in the foregoing method embodiments. Wherein, the storage medium may be a volatile or non-volatile computer-readable storage medium.

[0164] Embodiments of the present disclosure also provide a computer program product, which carries program code. The instructions included in the program code can be used to execute the steps of the symbol recovery method described in the foregoing method embodiments. For details, reference can be made to the foregoing method embodiments and will not be elaborated herein.

[0165] Wherein, the above computer program product can be specifically implemented in a manner of hardware, software or a combination thereof. In an optional embodiment, the computer program product is specifically embodied as a computer storage medium. In another optional embodiment, the computer program product is specifically embodied as a software product, such as a Software Development Kit (SDK), etc.

[0166] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the above description and device can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated herein. In several embodiments provided by the present disclosure, it should be understood that the disclosed device and method can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For another example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection can be through some communication interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical, mechanical or other form.

[0167] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0168] In addition, in each embodiment of the present disclosure, the functional units can be integrated in one processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit.

[0169] When the above-mentioned functions are implemented in the form of software function units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium executable by a processor. Based on this understanding, the technical solution of the present disclosure, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present disclosure. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program codes.

[0170] Finally, it should be noted that the above-mentioned embodiments are only specific implementation manners of the present disclosure, used to illustrate the technical solutions of the present disclosure, rather than limiting them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: any person skilled in the art within the technical scope disclosed by the present disclosure can still modify the technical solutions recorded in the foregoing embodiments or can easily think of changes, or perform equivalent replacements on some of the technical features; and these modifications, changes, or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should all be covered within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.

Claims

1. A symbol recovery method, characterized in that, Including: Obtain a target application file and a debug information file corresponding to the target application file; Generate description information of symbols to be restored based on the debug information file; Determine attribute information of the symbols to be restored based on the description information of the symbols to be restored; Update the load command information in the target application file by using the attribute information of the symbols to be restored, and add the description information of the symbols to be restored to the executable file of the target application file to obtain a restored target application file; Wherein, the debug information file includes a first symbol table and a first string table; the symbols to be restored include a first symbol in the first symbol table and a second symbol in the first string table; Wherein, adding the description information of the symbols to be restored to the executable file of the target application file includes: Create a continuous target memory area based on the total field size of the description information of the first symbol and the second symbol and the total field size of the target application file; Determine the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file; Cut the target application file based on the offset position at the end of the second symbol table and the offset position at the end of the second string table to obtain a first sub-file, a second sub-file, and a third sub-file arranged in sequence; Write the first sub-file, the description information of the first symbol, the second sub-file, the description information of the second symbol, and the third sub-file into the target memory area in sequence to obtain an executable file with description information added.

2. The method according to claim 1, characterized in that Generating the description information of the symbols to be restored based on the debug information file includes: Generate the description information of the first symbol based on the first symbol table in the debug information file; Generate the description information of the second symbol based on the first string table in the debug information file.

3. The method according to claim 1, wherein The attribute information of the symbols to be restored includes at least one of the following: the total number of symbols to be restored, the field size of the description information of the first symbol, the field size of the description information of the second symbol, and the total field size of the description information of the first symbol and the second symbol.

4. The method according to claim 2, wherein The executable file includes a second symbol table and a second string table; Adding the description information of the symbols to be restored to the executable file of the target application file includes: Determine the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file; Insert the description information of the second symbol to the end of the second string table based on the offset position at the end of the second string table; Insert the description information of the first symbol to the end of the second string table based on the offset position at the end of the second symbol table.

5. The method according to claim 3, characterized in that, Before inserting the description information of the second symbol to the end of the second string table based on the offset position at the end of the second string table, the method further includes: Determine the actual field size of the second string table based on the field size of the second string table and the number of padding characters of the second string table; Determine the number of padding characters required for the second string table after insertion based on the field size of the description information of the second symbol and the actual field size of the second string table; Determine the number of additional padding characters required based on the number of padding characters required for the second string table after insertion and the number of padding characters in the second string table before insertion; Perform character padding on the description information of the second symbol based on the number of additional padding characters; 6. The method according to claim 1, wherein The method further includes: Perform code analysis on the target application file based on the executable file in the restored target application file to obtain the attribute information of the executable file.

7. A symbol recovery device, characterized in that, including: An acquisition module for acquiring a target application file and a debug information file corresponding to the target application file; A generation module for generating description information of symbols to be restored based on the debug information file; A determination module for determining the attribute information of the symbols to be restored based on the description information of the symbols to be restored; A restoration module for updating the load command information in the target application file using the attribute information of the symbols to be restored and adding the description information of the symbols to be restored to the executable file of the target application file to obtain a restored target application file; wherein the debug information file includes a first symbol table and a first string table; the symbols to be restored include a first symbol in the first symbol table and a second symbol in the first string table; wherein adding the description information of the symbols to be restored to the executable file of the target application file includes: Create a continuous target memory area based on the total field size of the description information of the first symbol and the second symbol and the total field size of the target application file; Determine the offset position at the end of the second symbol table and the offset position at the end of the second string table in the executable file; Cut the target application file based on the offset position at the end of the second symbol table and the offset position at the end of the second string table to obtain a first sub-file, a second sub-file, and a third sub-file arranged in sequence; Write the first sub-file, the description information of the first symbol, the second sub-file, the description information of the second symbol, and the third sub-file into the target memory area in sequence to obtain an executable file with description information added.

8. An electronic device, characterized in that, including: A processor, a memory, and a bus, where the memory stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the memory through the bus. When the machine-readable instructions are executed by the processor, the steps of the symbol restoration method according to any one of claims 1 to 6 are executed.

9. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium. When the computer program is run by the processor, the steps of the symbol restoration method according to any one of claims 1 to 6 are executed.

Citation Information

Patent Citations

  • Generating symbolic debug information by merging translation and compiler debug information

    US5560009A