Third-party reference package decompilation method, system, electronic device and storage medium
By establishing a mapping table and sorting rules, the difficulty of decompiling third-party reference packages in the Java Card CAP package was solved, ensuring the consistency of token values, achieving a smooth decompilation process, and improving development efficiency.
Patent Information
- Application Number
- CN202211457457.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-21
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2042-11-21
AI Technical Summary
Existing technologies cannot effectively decompile Java Card CAP packages that have third-party references, leading to decompilation failures and causing inconvenience to programmers.
By establishing a mapping table between class names and token values, and sorting classes and methods based on the size of the token values, an exp file is generated to ensure that the token values are consistent with the corresponding values in the original package.
It enables successful decompilation of third-party reference packages, avoids exceptions caused by inconsistent token values, and improves the development efficiency of programmers.
Smart Images

Figure CN115794124B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically to a method for decompiling third-party reference packages, a system for decompiling third-party reference packages, an electronic device, and a storage medium. Background Technology
[0002] Currently, in the process of decompiling Java (an object-oriented programming language) packages, it is usually only possible to decompile Java Card CAP packages that do not contain third-party reference packages. If the target Java Card CAP package contains references to other Java Card CAP packages, then the referenced third-party packages may not be able to be decompiled correctly.
[0003] For example, if a third-party Java Card CAP package A exists, and Java Card CAP package B references Java Card CAP package A, due to the reference relationship between Java Card CAP package A and Java Card CAP package B, during decompilation, Java Card CAP package A must first be decompiled into a corresponding class file structure (a binary file that can run on any hardware platform and operating system that supports the Java Virtual Machine). Then, based on the class file structure, an exp file (a binary file in which information from the export file is included in the CAP file of Java Card CAP package B, used to link the contents of Java Card CAP package B with the items imported from Java Card CAP package A) is generated and provided to Java Card CAP package B for reference. However, when generating the reference exp file from Java Card CAP package A, since the original Java Card CAP package does not store class name information, the decompilation tool can only generate the corresponding class names according to certain specific rules, such as class AAA and class BBB. When generating exp files from decompiled classes AAA and BBB, the default rule generates token values according to the ASCII order of the class names. This causes a mismatch between the tokens in the generated exp and the tokens of the classes in the original packages. Existing conversion rules result in the corresponding class tokens and method tokens in the generated exp file not matching the tokens in the original Java Card CAP package A. If Java Card CAP package B references the exp file in Java Card CAP package A, the conversion tool will report a type mismatch error when decompiling Java Card CAP package B because the token values do not match. Therefore, Java Card CAP package B cannot be decompiled successfully when a third-party package is referenced.
[0004] Meanwhile, third-party reference packages are used frequently and extensively. The inability to properly decompile third-party reference packages in current technology will cause many inconveniences to programmers' daily work. Summary of the Invention
[0005] In view of the deficiencies in the existing technology, the purpose of this invention is to provide a method for decompiling third-party reference packages, a system for decompiling third-party reference packages, an electronic device and a storage medium, which can effectively ensure the sequential progress of programmers' development work.
[0006] To achieve the above objectives, this invention provides a method for decompiling a third-party reference package, specifically including the following steps:
[0007] Parse the Java Card CAP package to be decompiled and establish a mapping table to record the mapping relationship between class names and token values in the Java Card CAP package to be decompiled;
[0008] The classes in the Java Card CAP package to be decompiled are sorted according to a preset sorting rule, and the names of the sorted classes are output.
[0009] Based on the name of the output class, the corresponding token value is obtained by combining it with the relationship mapping table, and the exp file corresponding to the Java Card CAP package to be decompiled is generated.
[0010] Based on the exp file of the Java Card CAP package to be decompiled, the Java Card CAP package that references the Java Card CAP package to be decompiled is decompiled.
[0011] Based on the above technical solution, the specific steps for establishing a mapping table to record the mapping relationship between class names and token values in the Java Card CAP package to be decompiled include:
[0012] Iterate through the description information of each class in the Java Card CAP package to be decompiled, extract the token value of the current class, and extract the class name from the reference index of the current class;
[0013] The extracted token value of the current class is associated with the class name, and the association information is stored in the established relational mapping table.
[0014] Based on the above technical solution, the preset sorting rule is to sort the methods contained in the class according to the size of the token value.
[0015] Based on the above technical solution, the specific steps for sorting the classes in the Java Card CAP package to be decompiled according to a preset sorting rule include:
[0016] Based on the description information of the classes in the Java Card CAP package to be decompiled, obtain the number of fields and methods contained in the class;
[0017] Sort the fields contained in the class according to the ascending order of their token values;
[0018] Sort the methods contained in the class according to the ascending order of their token values.
[0019] Based on the above technical solution, the specific steps of sorting the methods contained in the class according to the ascending order of the method token values include:
[0020] Iterate through all the methods in the class and record the token value corresponding to each method in the created cache.
[0021] The token values recorded in the cache are sorted in ascending order, thereby sorting the methods contained in the class.
[0022] Based on the above technical solution, after the sorting of the fields and methods contained in the class is completed, the following is also included:
[0023] Generate a field table corresponding to the current class, so as to record the fields contained in the current class in sorted order;
[0024] Generate a method table corresponding to the current class, so as to record the methods contained in the current class in sorted order.
[0025] This invention provides a decompilation system for third-party reference packages, comprising:
[0026] The parsing module is used to parse the Java Card CAP package to be decompiled and to establish a relationship mapping table to record the mapping relationship between the class names and token values in the Java Card CAP package to be decompiled;
[0027] The sorting module is used to sort the classes in the Java Card CAP package to be decompiled based on a preset sorting rule, and output the names of the sorted classes.
[0028] The generation module is used to sequentially obtain the corresponding token value based on the name of the output class and the relational mapping table, and generate the exp file corresponding to the Java Card CAP package to be decompiled;
[0029] The decompilation module is used to decompile Java Card CAP packages that reference the Java Card CAP package to be decompiled, based on the exp file of the Java Card CAP package to be decompiled.
[0030] Based on the above technical solution, the preset sorting rule is to sort the methods contained in the class according to the size of the token value.
[0031] The present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the steps of the decompilation method for the third-party reference package described above.
[0032] The present invention provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the above-described decompilation method for third-party reference packages.
[0033] Compared with the prior art, the advantages of the present invention are as follows: The present invention records the mapping relationship between class names and token values in the original Java CardCAP package through a relational mapping table, so that the original token value can be found quickly based on the class name. Moreover, before decompiling, the methods contained in the class are sorted according to a preset sorting rule, so that there is no need to worry about the problem of same-level conflicts when generating the exp file, effectively ensuring the order of programmers' development work and providing convenience for programmers' development. Attached Figure Description
[0034] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0035] Figure 1 This is a flowchart illustrating a method for decompiling a third-party reference package according to an embodiment of the present invention;
[0036] Figure 2 This is a schematic diagram of the structure of a decompilation system for a third-party reference package according to an embodiment of the present invention. Detailed Implementation
[0037] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are some embodiments of this application, but not all embodiments.
[0038] See Figure 1 As shown in the figure, the decompilation method for a third-party reference package provided by this embodiment of the invention specifically includes the following steps:
[0039] S1: Parse the Java Card CAP package to be decompiled and establish a relational mapping table to record the mapping relationship between class names and token values in the Java Card CAP package to be decompiled; by establishing the relational mapping table, the mapping relationship between class names and token values is recorded in the relational mapping table, so that the corresponding token value can be quickly found by using the class name in the subsequent search process.
[0040] In this invention, the class name and token value can be extracted from the class description information when parsing the Java Card CAP package to be decompiled.
[0041] Specifically, a mapping table is established to record the mapping relationship between class names and token values in the Java Card CAP package to be decompiled. The specific steps include:
[0042] S101: Iterate through the description information of each class in the Java Card CAP package to be decompiled, extract the token value of the current class, and extract the class name from the reference index of the current class;
[0043] S102: Associate the extracted token value of the current class with the class name, and store the association information in the established relational mapping table.
[0044] That is, extract the token value of the current class from the description information, extract the class name from the reference index of the current class, associate the two pieces of information, and then store the association information in a pre-established relational mapping table.
[0045] S2: Sort the classes in the Java Card CAP package to be decompiled according to the preset sorting rules, and output the names of the sorted classes; that is, before decompilation, sort the classes according to the preset sorting rules so as to output the sorted class files.
[0046] In this invention, the preset sorting rule is to sort the methods contained in a class based on the size of the token value. Of course, in actual applications, the sorting of methods contained in a class is not limited to this sorting method.
[0047] The following section details how the present invention sorts the classes in the JavaCard CAP package to be decompiled based on a preset sorting rule, using a token value-based sorting rule:
[0048] S201: Based on the description information of the classes in the Java Card CAP package to be decompiled, obtain the number of fields and methods contained in the class; that is, first obtain the number of fields and methods contained in the class from the description information corresponding to the class, and then sort the fields and methods respectively.
[0049] S202: Sort the fields contained in the class according to the ascending order of the token values of the fields; that is, for the current class, sort the fields contained in the current class according to the size of the token values of the fields contained in the current class.
[0050] S203: Sort the methods contained in the class according to their token values in ascending order. That is, for the current class, sort the methods contained in the current class according to the size of their token values. In specific applications, the sorting method of field token values and method token values is not limited to the ascending order method described in this invention.
[0051] In this embodiment of the invention, the methods contained in the class are sorted according to their token values from smallest to largest. Specific steps include:
[0052] S2031: Iterate through all the methods in the class and record the token value corresponding to each method in the created cache area;
[0053] S2032: Sort the token values recorded in the cache in ascending order, thereby sorting the methods contained in the class.
[0054] Furthermore, after the sorting of the fields and methods contained in the class is completed, the process also includes: generating a field table corresponding to the current class to record the fields contained in the current class according to the sorting order, generating a method table corresponding to the current class to record the methods contained in the current class according to the sorting order, and then outputting the class file.
[0055] S3: Based on the name of the output class, obtain the corresponding token value according to the relationship mapping table, and generate the exp file corresponding to the Java Card CAP package to be decompiled;
[0056] That is, by looking up the relational mapping table, the corresponding token value is obtained according to the class name, thereby determining the token value corresponding to the class, and generating the exp file corresponding to the Java Card CAP package to be decompiled normally.
[0057] When generating the exp file corresponding to the Java Card CAP package to be decompiled, the order of the methods contained in the class has been determined beforehand. This avoids the problem of disordered method names in the generated classes for non-static public methods, thus preventing discrepancies between the token values in the generated exp file and those in the original Java Card CAP package to be decompiled. Similarly, for fields within the class, the problem of inconsistent token values between the exp file and the original Java Card CAP package to be decompiled is also avoided.
[0058] S4: Based on the exp file of the Java Card CAP package to be decompiled, perform decompilation operations on the Java Card CAP package that references the Java Card CAP package to be decompiled. Specifically, when decompiling the Java Card CAP package that references the Java Card CAP package to be decompiled, the exp file of the Java Card CAP package to be decompiled is included to implement the decompilation operation on the Java Card CAP package that references the Java Card CAP package to be decompiled.
[0059] The decompilation method for third-party reference packages in this invention records the mapping relationship between class names and token values in the original JavaCard CAP package through a relational mapping table. This allows the original token value to be quickly found based on the class name. Furthermore, before decompilation, the methods contained in the class are sorted according to a preset sorting rule. This eliminates concerns about conflicts at the same level when generating the exp file (e.g., issues where token values differ from the original CAP package due to the ASCII order of method names even though they are all public methods). This effectively ensures the sequential progress of programmers' development work and provides convenience for programmers.
[0060] See Figure 2 As shown, this embodiment of the invention also provides a decompilation system for third-party reference packages, including a parsing module, a sorting module, a generation module, and a decompilation module.
[0061] The parsing module parses the Java Card CAP package to be decompiled and establishes a mapping table to record the relationship between class names and token values in the package. This mapping table allows for quick retrieval of the corresponding token value using the class name during subsequent searches. The sorting module sorts the classes in the Java Card CAP package according to a preset sorting rule and outputs the names of the sorted classes. The generation module uses the output class names and the mapping table to retrieve the corresponding token values and generate the corresponding exp file for the Java Card CAP package. The decompilation module uses the exp file to decompile the Java Card CAP package that references it.
[0062] In this invention, the preset sorting rule is to sort the methods contained in the class based on the size of the token value.
[0063] The third-party reference package decompilation system of this invention records the mapping relationship between class names and token values in the original JavaCard CAP package through a relational mapping table, so that the original token value can be found quickly based on the class name. Before decompilation, the methods contained in the class are sorted according to a preset sorting rule, so that there is no need to worry about the problem of sibling conflicts when generating exp files, effectively ensuring the order of programmers' development work.
[0064] In one possible real-time mode, embodiments of the present invention also provide an electronic device, the electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the decompilation method for the third-party reference package described above.
[0065] In one possible real-time mode, embodiments of the present invention also provide a non-transitory computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the decompilation method for the third-party reference package described above.
[0066] The above description is merely a specific embodiment of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
[0067] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
Claims
1. A method for decompiling a third-party reference package, characterized in that, Specifically, the following steps are included: Parse the Java Card CAP package to be decompiled and establish a mapping table to record the mapping relationship between class names and token values in the Java Card CAP package to be decompiled; The classes in the Java Card CAP package to be decompiled are sorted according to a preset sorting rule, and the names of the sorted classes are output. Based on the name of the output class, the corresponding token value is obtained by combining it with the relationship mapping table, and the exp file corresponding to the JavaCard CAP package to be decompiled is generated. Based on the exp file of the Java Card CAP package to be decompiled, perform decompilation operations on the JavaCard CAP package that references the Java Card CAP package to be decompiled; The steps for establishing a mapping table to record the mapping relationship between class names and token values in the Java Card CAP package to be decompiled include: Iterate through the description information of each class in the Java Card CAP package to be decompiled, extract the token value of the current class, and extract the class name from the reference index of the current class; The extracted token value of the current class is associated with the class name, and the association information is stored in the established relational mapping table.
2. The method for decompiling a third-party reference package as described in claim 1, characterized in that: The preset sorting rule is to sort the methods contained in the class based on the size of the token value.
3. The method for decompiling a third-party reference package as described in claim 2, characterized in that, The sorting of classes in the Java Card CAP package to be decompiled based on a preset sorting rule includes the following steps: Based on the description information of the classes in the Java Card CAP package to be decompiled, obtain the number of fields and methods contained in the class; Sort the fields contained in the class according to the ascending order of their token values; Sort the methods contained in the class according to the ascending order of their token values.
4. The method for decompiling a third-party reference package as described in claim 3, characterized in that, The specific steps of sorting the methods contained in a class according to their token values from smallest to largest include: Iterate through all the methods in the class and record the token value corresponding to each method in the created cache. The token values recorded in the cache are sorted in ascending order, thereby sorting the methods contained in the class.
5. The method for decompiling a third-party reference package as described in claim 3, characterized in that, After the fields and methods contained in the class have been sorted, the following is also included: Generate a field table corresponding to the current class, so as to record the fields contained in the current class in sorted order; Generate a method table corresponding to the current class, so as to record the methods contained in the current class in sorted order.
6. A decompilation system for third-party reference packages, characterized in that, include: The parsing module is used to parse the Java Card CAP package to be decompiled and to establish a relationship mapping table to record the mapping relationship between the class names and token values in the Java Card CAP package to be decompiled; The sorting module is used to sort the classes in the Java Card CAP package to be decompiled based on a preset sorting rule, and output the names of the sorted classes. The generation module is used to sequentially obtain the corresponding token value based on the name of the output class and the relational mapping table, and generate the exp file corresponding to the Java Card CAP package to be decompiled; The decompilation module is used to decompile Java Card CAP packages that reference the Java Card CAP package to be decompiled, based on the exp file of the Java Card CAP package to be decompiled. The steps for establishing a mapping table to record the mapping relationship between class names and token values in the Java Card CAP package to be decompiled include: Iterate through the description information of each class in the Java Card CAP package to be decompiled, extract the token value of the current class, and extract the class name from the reference index of the current class; The extracted token value of the current class is associated with the class name, and the association information is stored in the established relational mapping table.
7. The decompilation system for a third-party reference package as described in claim 6, characterized in that, The preset sorting rule is to sort the methods contained in the class based on the size of the token value.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the decompilation method for the third-party reference package as described in any one of claims 1 to 5.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the decompilation method for a third-party reference package as described in any one of claims 1 to 5.
Citation Information
Patent Citations
JAVA card application package used as a library package
EP3291084A1
File language verification
US20020093856A1