Interface class file acquisition method and device, computer device, and storage medium
Patent Information
- Application Number
- CN202210510457.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-11
- Publication Date
- 2026-08-18
- Estimated Expiration
- 2042-05-11
AI Technical Summary
但是,在编译过程中直接使用扩展功能的插件程序的程序文件,会导致实现扩展功能的源代码泄露,源代码隐私安全性差
[0035] The aforementioned method, apparatus, computer device, and storage medium for obtaining interface class files involve: obtaining a program file that implements at least one business function; determining the target content associated with class dependencies within the classes of the program file; adjusting the content of the classes in the program file based on the target content to obtain an interface class with the same name; and deleting the interface classes with the same name corresponding to useless classes in the program file to obtain the corresponding interface class file. By adjusting the target content associated with class dependencies, the classes in the program file are converted into interface classes with the same name, thus decoupling the dependencies between classes within the program file or between classes within the program file and external classes. Then, by deleting useless classes from the interface classes with the same name in the program file, the decoupled classes in the program file are further optimized and compressed to obtain the interface class file. The interface class file only exposes specific classes and their methods, hiding the content related to class dependencies in the program file, thereby achieving the goal of hiding the source code and ensuring source code security.
Smart Images

Figure CN117093998B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, specifically to a method, apparatus, computer device, and computer-readable storage medium (hereinafter referred to as storage medium) for obtaining interface class files. Background Technology
[0002] In application development, plugin projects are often used to extend application functionality. This involves loading and installing the corresponding plugin program after the host application is running to implement the extended functionality. Since plugin programs do not run independently, their program files need to be loaded into the host application's project for compilation to generate the final application. However, directly using the plugin program files during compilation can lead to the leakage of the source code implementing the extended functionality, resulting in poor source code privacy and security. Summary of the Invention
[0003] Therefore, it is necessary to provide a method, apparatus, computer device, and storage medium for obtaining interface class files to address the aforementioned technical problems, thereby avoiding the exposure of the source code of extended functions and improving the privacy and security of the source code.
[0004] Firstly, this application provides a method for obtaining an interface class file, the method comprising:
[0005] Obtain the program file that implements at least one business function;
[0006] Determine the target content in the program file that is associated with class dependencies;
[0007] Based on the target content in the class, the content of the class in the program file is adjusted to obtain the interface class with the same name as the class.
[0008] Delete the interface class with the same name as the unused class in the program file to obtain the interface class file corresponding to the program file.
[0009] In some embodiments of this application, the content of a class in a program file is adjusted based on the target content of the class to obtain an interface class with the same name as the class, including:
[0010] Obtain the bytecode file of the class;
[0011] Convert the method source code in the bytecode file into empty implementation code to obtain an interface class with the same name as the class; the empty implementation code includes the same method signature as the method source code.
[0012] In some embodiments of this application, an interface class with the same name as a useless class in the program file is deleted to obtain an interface class file corresponding to the program file, including:
[0013] Obtain pre-configured obfuscation rules and identify useless classes based on these rules;
[0014] The target interface class is determined from the interface classes with the same name based on the class name of the useless class;
[0015] Remove the target interface class to obtain the interface class file corresponding to the program file.
[0016] In some embodiments of this application, after removing the target interface class, the method further includes:
[0017] Naming rules are determined based on obfuscation code rules;
[0018] Replace class names, method names, and variable names in the program file according to the naming rules.
[0019] In some embodiments of this application, after deleting the interface class with the same name as the unused class in the program file to obtain the interface class file corresponding to the program file, the method further includes:
[0020] Save the interface class files to the project management repository.
[0021] In some embodiments of this application, after deleting the interface class with the same name as the unused class in the program file to obtain the interface class file corresponding to the program file, the method further includes:
[0022] Get the target path of the interface class file in the project management repository;
[0023] The host application is compiled based on the target path of the interface class file, generating an executable code file.
[0024] Secondly, this application provides an apparatus for obtaining interface class files, the apparatus comprising:
[0025] The program file acquisition module is used to acquire program files that implement at least one business function.
[0026] The target content acquisition module is used to determine the target content in the program file that is associated with the class dependency relationship;
[0027] The target content processing module is used to adjust the content of classes in the program file based on the target content in the class, and obtain the interface class with the same name as the class.
[0028] The interface class file generation module is used to delete interface classes with the same name as unused classes in the program file and obtain the interface class file corresponding to the program file.
[0029] Thirdly, this application also provides a computer device, which includes:
[0030] One or more processors;
[0031] Memory; and
[0032] One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the method for obtaining interface class files.
[0033] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, the computer program being loaded by a processor to execute the steps in the method for obtaining interface class files.
[0034] Fifthly, embodiments of this application provide a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the steps in the method for obtaining an interface class file.
[0035] The aforementioned method, apparatus, computer device, and storage medium for obtaining interface class files involve: obtaining a program file that implements at least one business function; determining the target content associated with class dependencies within the classes of the program file; adjusting the content of the classes in the program file based on the target content to obtain an interface class with the same name; and deleting the interface classes with the same name corresponding to useless classes in the program file to obtain the corresponding interface class file. By adjusting the target content associated with class dependencies, the classes in the program file are converted into interface classes with the same name, thus decoupling the dependencies between classes within the program file or between classes within the program file and external classes. Then, by deleting useless classes from the interface classes with the same name in the program file, the decoupled classes in the program file are further optimized and compressed to obtain the interface class file. The interface class file only exposes specific classes and their methods, hiding the content related to class dependencies in the program file, thereby achieving the goal of hiding the source code and ensuring source code security. Attached Figure Description
[0036] 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.
[0037] Figure 1 This is a schematic diagram illustrating a scenario of how the interface class file is obtained in an embodiment of this application.
[0038] Figure 2This is a flowchart illustrating the method for obtaining interface class files in an embodiment of this application;
[0039] Figure 3 This is a flowchart illustrating the steps of adjusting the content of classes in a program file based on the target content in the class in this embodiment of the application.
[0040] Figure 4 This is a flowchart illustrating the steps for adjusting the content of classes in a program file in an embodiment of this application.
[0041] Figure 5 This is a flowchart illustrating the steps of code obfuscation processing for the processed program file in an embodiment of this application;
[0042] Figure 6 This is a schematic diagram of the structure of the interface class file acquisition device in the embodiments of this application;
[0043] Figure 7 This is a schematic diagram of the structure of the computer device in the embodiments of this application. Detailed Implementation
[0044] 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 only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0045] In the description of this application, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the stated features. In the description of this application, "multiple" means two or more, unless otherwise explicitly specified.
[0046] In the description of this application, the word "for example" is used to mean "used as an example, illustration, or description." Any embodiment described as "for example" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is provided to enable any person skilled in the art to make and use the invention. Details are set forth in the following description for purposes of explanation. It should be understood that those skilled in the art will recognize that the invention can be made without using these specific details. In other instances, well-known structures and processes will not be described in detail to avoid obscuring the description of the invention with unnecessary detail. Therefore, the invention is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed in this application.
[0047] Figure 1 This diagram illustrates the application environment of a method for obtaining interface class files in one embodiment. This method can be applied to a computer device, which may be a server or a terminal. Figure 1 As shown, taking server 100 as an example, the server 100 obtains a program file that implements at least one business function and determines the target content associated with the class dependency relationship in the class of the program file; based on the target content in the class, the class in the program file is adjusted to obtain an interface class with the same name as the class; the interface class with the same name corresponding to the useless class in the program file is deleted to obtain the interface class file corresponding to the program file.
[0048] It is understood that the method for obtaining interface class files in this application embodiment can be specifically applied to plugin projects. Plugin projects refer to program files that reference other business functions to extend the functionality of the host application. Specifically, these business function program files are built into the host application as plugins. After the mobile device (such as a mobile phone) installs the host application, the program file corresponding to the business function will be loaded and installed after the host application runs to implement the corresponding business function. The program file corresponding to the business function refers to the program file compiled after the developer completes the coding. This program file cannot run independently but needs to rely on its host application to run. Therefore, this program file needs to be loaded into the compilation path of the host application and compiled in conjunction with the program file of the host application to generate an application that can implement the corresponding business function. However, in the prior art, directly using the program file that implements the corresponding business function during the compilation process will lead to source code leakage and poor source code privacy and security. In addition, since the program file of the business function often includes a large number of class dependencies, dependency resolution slows down during the compilation process, resulting in a long compilation time.
[0049] Those skilled in the art will understand that Figure 1 The application environment shown is merely one application scenario of the solution in this application and does not constitute a limitation on the application scenario of the solution in this application. Other application environments may include those that are more specific to this application. Figure 1 The number of computer devices shown is more or less, for example Figure 1 Only one server is shown here. It is understood that the system for obtaining this interface class file may include one or more other servers; this is not specifically limited here. Additionally, as... Figure 1 As shown, the system for obtaining the interface class file may also include a storage device for storing data, such as program files.
[0050] It should also be noted that, Figure 1The application scenario diagram shown is merely an example. The application scenarios described in the embodiments of the present invention are intended to more clearly illustrate the technical solutions of the embodiments of the present invention and do not constitute a limitation on the technical solutions provided by the embodiments of the present invention. As those skilled in the art will know, with the evolution of technology and the emergence of new business scenarios, the technical solutions provided by the embodiments of the present invention are also applicable to similar technical problems.
[0051] See Figure 2 This application provides a method for obtaining interface class files, which is mainly applied to the above-mentioned... Figure 1 Taking server 100 as an example, the method includes steps S210 to S240, as follows:
[0052] S210, Obtain a program file that implements at least one business function.
[0053] In this context, a program file refers to a software package or program package that implements a certain business function and is written in a programming language. It can be a JAR file generated by compiling the program code that implements the business function, such as a JAR package. Specifically, a program file includes class bytecode files and resource files, etc.
[0054] In practical applications, there can be multiple program files. For example, in plugin development, business functions can be plugin functionalities provided by the application. The application often includes multiple plugin functionalities, and different program files can be used to implement different plugin functionalities.
[0055] S220, Determine the target content in the class of the program file that is associated with the class dependency relationship.
[0056] In programming, a class is the basic unit of code; one class corresponds to one bytecode file. Class dependency refers to a class depending on other classes in some way. When two classes are in a dependency relationship, a change in one class may affect the other. In program code, class dependency manifests as one class (e.g., class A) being used as a parameter by another class (e.g., class B). For example, class B might use class A or an instance of class A in a method.
[0057] Among them, the target content associated with class dependency refers to the code that introduces the dependency in the code corresponding to the class; as above, class dependency is manifested as one class using another class in a certain method. Therefore, the target content can include, but is not limited to, at least one of the following: the method defined by the class, and the import function statement used to import another class (such as the import function statement).
[0058] Specifically, after obtaining the program file, the program file can be parsed to extract the classes contained in the program file, as well as the constant information, class information, interface information, field information, method information, etc. of each class, and the target content associated with the class dependency relationship can be filtered out from it.
[0059] S230: Based on the target content in the class, adjust the content of the class in the program file to obtain the interface class with the same name.
[0060] In a typical program file, multiple classes are often included. For each class, the target source code corresponding to the target content is first determined in the bytecode file of that class. Then, the target source code is modified to obtain an interface class with the same name as the class. Specifically, the modification process includes code deletion and code transformation. After modification, the program file contains hidden content related to class dependencies, preventing the exposure of class dependencies and decoupling different classes within the program file, thus accelerating subsequent compilation.
[0061] Furthermore, as described above, the target content may include the methods defined by the class and the import function statements used to import another class; based on the target content in the class, the class in the program file is subjected to content adjustment processing. Specifically, the bytecode file of the class is obtained from the program file, and the source code of the methods defined by the class and the source code of the function statements used to import another class are determined from the bytecode file. The source code of the methods and the source code of the functions are adjusted respectively to obtain the interface class with the same name as the class.
[0062] Taking an import function statement used to import another class as an example, after identifying the corresponding function source code in the class's bytecode file, the function source code can be adjusted, specifically by deleting code. By deleting the import function statement used to import another class, the dependency on the external class can be hidden, and by reducing class dependencies, the compilation of the subsequent program file can be accelerated.
[0063] Furthermore, taking the target content including the methods defined by the class as an example, in one embodiment, such as Figure 3 As shown, step S230 adjusts the content of the class in the program file based on the target content in the class to obtain an interface class with the same name as the class, including:
[0064] S310, retrieve the bytecode file of the class.
[0065] Bytecode files, in this context, refer to class files. Each class in a program file has a corresponding bytecode file. Bytecode files are binary files composed of a specific format of byte streams, which can be directly executed by the Java Virtual Machine.
[0066] S320 converts the method source code in the bytecode file into empty implementation code, resulting in an interface class with the same name as the class; the empty implementation code includes the same method signature as the method source code.
[0067] The method source code includes the method signature and method body, among other code information. The method signature is information used to uniquely identify a method's source code, including the method type, data type, method name, and method variables. The method body refers to the specific code in each method's source code that implements its functionality. It's understandable that a bytecode file can contain one or more method source codes.
[0068] Empty implementation code refers to code that removes the method body and retains only the method signature.
[0069] After obtaining the bytecode file of the class, the source code of the methods defined in the bytecode file is determined. Then, based on line-by-line bytecode operations, the content of the method source code in the class's bytecode file is adjusted. Specifically, the method body in the method source code can be deleted, empty implementation code corresponding to the method source code can be constructed based on the method signature, and an interface class with the same name can be generated by replacing the method source code in the bytecode file with the empty implementation code. This converts the implementation class in the program file into an interface class, hides the implementation information of the class, and exposes only the class name and method signature, thus avoiding the leakage of the source code of the implemented functions.
[0070] After converting all classes in the program file to interface classes with the same name, the method bodies involving class dependencies in the source code are deleted, which can hide the dependencies between different classes inside the program file as well as the dependencies on external classes. Furthermore, by reducing class dependencies, the compilation time of the processed program file is reduced.
[0071] For example, the bytecode file of a class in the program file is shown below:
[0072]
[0073] Taking a target content that includes method bodies defined in a class and import function statements used to import another class as an example, after obtaining the class's bytecode file, the function code for the import function statements used to import another class is identified in the bytecode file. Specifically, the function code includes the code "importcom.shili.demo.exported" and the code "importcom.shili.demo.Param". Simultaneously, the method code (i.e., method source code) corresponding to the methods defined in the class is identified in the bytecode file. Specifically, the method code includes the code "Funmethod(param:param):Int{}" (the code within the curly braces is not shown). Then, the function code is deleted, and the method source code in the class's bytecode file is converted into empty implementation code to obtain a program file with adjusted content.
[0074] Taking the bytecode file of the above class as an example, after adjusting the content of the target function code and method source code, the following processed program file is obtained:
[0075]
[0076] S240, delete the interface class with the same name as the useless class in the program file, and obtain the interface class file corresponding to the program file.
[0077] In this context, "useless classes" refer to classes that are not loaded or referenced in the program file. For example, if a portion of a program file contains classes with only inner class dependencies, and after adjusting the content related to these dependencies, effectively hiding those dependencies, then this portion of the class is not referenced anywhere in the program file. Such classes can be identified as useless classes. For instance, if a program file includes classes A and B, with class A used as a parameter by class B, and after adjusting the content related to class dependencies in class B, class A and class B are decoupled. Since class A has no other class dependencies in the program file, class A can be identified as a useless class.
[0078] After adjusting the target content of classes in the program file, all corresponding interface classes with the same name are still retained. This means that debugging information such as line numbers, field names, method names, parameter names, variable names, etc., of each class is preserved. By obtaining the interface classes with the same name as the useless classes in the program file and deleting the interface classes with the same name as the useless classes, the program file can be trimmed of useless code, the class structure of the program file can be optimized, and the program file can be compressed. At the same time, it further avoids the reverse derivation of source code information through decompilation or reverse engineering based on the debugging information in the interface classes with the same name.
[0079] After content adjustment to obtain the corresponding interface class and the interface class file obtained after deleting the corresponding interface class of useless classes, the external plugin project can only see the method declaration of specific classes, and cannot see the content related to class dependencies and the method bodies of all classes in the program file, thus achieving the purpose of hiding the internal implementation.
[0080] It is understandable that this interface class file is specifically used for compiling the host application, and will not be used for packaging the host application's APK (Android application package). In other words, this interface class file will not be packaged into the host application's APK.
[0081] Specifically, obfuscation techniques can be used to delete interface classes with the same name as useless classes. In one embodiment, deleting interface classes with the same name as useless classes in the program file to obtain the interface class file corresponding to the program file includes: obtaining pre-configured obfuscation code rules, determining useless classes based on the obfuscation code rules, determining the target interface class from the interface classes with the same name according to the class name of the useless class, and removing the target interface class to obtain the interface class file corresponding to the program file.
[0082] The obfuscation rules can be set according to the actual situation. After obtaining the obfuscation rules, the processed program file can be analyzed based on the obfuscation rules to identify useless classes. Then, the corresponding target interface classes can be selected from the classes in the program file according to the class names of the useless classes. Through obfuscation technology, useless classes in the program file can be accurately removed, thereby simplifying the classes in the program file and avoiding the exposure of all classes in the program file.
[0083] Furthermore, in one embodiment, determining the target interface class from interface classes with the same name based on the class name of the useless class specifically includes: obtaining the entry class in the processed program file, and determining the target class from classes other than the entry class based on the class name of the useless class. Here, the entry class refers to the class containing the entry method, such as the main method. Since the entry class serves as the entry point for the program file, it is retained when simplifying the classes in the program file to ensure that the resulting interface class file can be called and that business functions can be used.
[0084] Furthermore, in one embodiment, after removing the target interface class, the method further includes: determining naming rules based on obfuscation rules; and replacing class names, method names, and variable names in the program file according to the naming rules.
[0085] Specifically, meaningless character sequences can be used to replace class names, method names, and variable names in the processed program file, further hiding class information, method information, and variable information in the processed program file, thereby achieving the goal of hiding the source code and ensuring source code security.
[0086] The method for obtaining the interface class file described above involves: acquiring a program file that implements at least one business function; determining the target content associated with class dependencies in the classes of the program file; adjusting the content of the classes in the program file based on the target content to obtain an interface class with the same name; and deleting the interface classes with the same name corresponding to useless classes in the program file to obtain the corresponding interface class file. By adjusting the target content associated with class dependencies, the classes in the program file are converted into interface classes with the same name, thus decoupling the dependencies between classes within the program file or between classes within the program file and external classes. Then, by deleting useless classes in the interface classes with the same name in the program file, the decoupled classes in the program file are further optimized and compressed to obtain the interface class file. The interface class file only exposes specific classes and their methods, hiding the content related to class dependencies in the program file, thereby achieving the goal of hiding the source code and ensuring source code security.
[0087] Furthermore, in one embodiment, after deleting the interface class with the same name as the useless class in the program file to obtain the interface class file corresponding to the program file, the method further includes: saving the interface class file to the project management library.
[0088] The project management repository refers to the Maven repository corresponding to the host application, which specifically includes local Maven repositories and remote Maven repositories.
[0089] Specifically, after obtaining the interface class file corresponding to the program file, the interface class file is published to the project management library of the host application so that the host application can download and use the interface class file during local debugging or version release.
[0090] Furthermore, after deleting the interface class with the same name as the useless class in the program file and obtaining the interface class file corresponding to the program file, the process also includes: obtaining the target path of the interface class file in the project management library; compiling the host application based on the target path of the interface class file to generate an executable code file.
[0091] During the compilation of the host application, the target path of the interface class file is loaded into the compilation path as a dependency of the host application, enabling the host application to access the interface class file during compilation. The resulting executable code file is the executable code file corresponding to the host application, which can implement the functions of the host application itself, as well as the business functions in the program file corresponding to the interface class file.
[0092] It is understandable that during the packaging process of the host application, the host application is packaged based on the program files, so that the host application can provide the actual method dependencies through the program files during runtime to achieve the corresponding business functions.
[0093] It should be understood that, although Figure 2 to Figure 3 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 2 to Figure 3 At least some of the steps in the process may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but may be executed at different times. The execution order of these steps or stages is not necessarily sequential, but may be executed in turn or alternately with other steps or at least some of the steps or stages in other steps.
[0094] The following example further illustrates the method for obtaining the aforementioned interface class files. Specifically, taking plugin development as an example, and the program file being a JAR file providing business functionality, the method for obtaining the interface class files includes the following steps:
[0095] Step 1: Obtain the JAR package. Among all classes in the JAR package, determine the target content associated with the class dependencies. Based on the target content in the class, adjust the content of the classes in the JAR package to obtain the interface class with the same name as the class.
[0096] Specifically, after obtaining the JAR package, it iterates through all classes and methods in each JAR package. By manipulating the bytecode files of the classes, the source code of each method is replaced with empty implementation code, thus removing the class implementation and keeping only the class name and the method signature of each class. This generates an interface class with the same name as the class, thereby reducing class dependencies and avoiding useless or implicit class imports, such as class dependencies imported through import function statements, and accelerating the subsequent obfuscation process.
[0097] More specifically, the Gradle Transform tool can be used to adjust the content of JAR files. The Gradle Transform tool is a set of APIs for modifying bytecode files. For example... Figure 4As shown, the Gradle Transform tool processes the JAR file, specifically by sequentially using the Transforminput, createMockableJar, and rewriteClass functions to process the classes (i.e., the bytecode files corresponding to the classes) within the JAR file. In the output JAR file, all classes from the original JAR file are converted into interface classes with the same name. Specifically, the Transforminput function transforms the input class files into target bytecode files; the createMockableJar function converts the method source code in the bytecode file into empty implementation code; and the rewriteClass function rewrites the bytecode files corresponding to the classes based on the empty implementation code, resulting in interface classes with the same name.
[0098] Step 2: Obfuscate the program file to obtain the interface class file corresponding to the program file.
[0099] Code obfuscation can be achieved using the ProGuard tool. Specifically, obfuscation rules can be configured in the configuration file (e.g., build.gradle) of the host application's project, and the configuration parameter "minifyEnabled" can be set to "true" to enable code obfuscation. This will obfuscate the processed program files and remove unused classes, variables, and methods from them.
[0100] Specifically, ProGuard includes four functions: a shrinker, an optimizer, an obfuscator, and a preverifier. Among them:
[0101] The compression feature is specifically used to detect and remove unused classes, variables, methods, and properties;
[0102] The optimization features are specifically used to optimize code, such as adding private, static, or final declarations to non-entry point classes, removing unused parameters, and turning certain methods into inline code.
[0103] The obfuscation feature is used to rename non-entry class names, variable names, and method names with short, semantically meaningless names, while the name of the entry class remains unchanged;
[0104] The pre-validation function is used to check whether the code conforms to specifications, such as Java 1.6 or other specifications.
[0105] likeFigure 5 As shown, after obtaining the JAR file output in step 1, the JAR file is sequentially subjected to shrink, optimize, obfuscate, and preverify operations. The final output JAR file is the interface class file. It is understandable that after the shrink, optimize, obfuscate, and preverify operations, the interface classes with the same names corresponding to unused classes are pruned from the output JAR file.
[0106] Step 3: Publish the interface class file to the Maven repository.
[0107] During the local compilation, debugging, and release of the official version of the host application, the JAR files (i.e., interface class files) are published to different Maven repositories.
[0108] In this plugin project, the `compileOnly` technique is used to add the interface class file as a dependency to the host application's compilation path, but it is not packaged into the host application's APK. This means the interface class file can only be accessed at compile time, and dependencies modified by `compileOnly` are not transitive. At runtime, the actual method dependencies are provided to the plugin APK via an AAR file. External plugin projects can only view the method declarations of specified classes after clipping and hiding, thus achieving the goal of hiding the internal implementation.
[0109] To better implement the interface class file acquisition method provided in the embodiments of this application, based on the interface class file acquisition method proposed in the embodiments of this application, the embodiments of this application also provide an interface class file acquisition device, such as... Figure 6 As shown, the interface class file acquisition device 600 includes:
[0110] The program file acquisition module 610 is used to acquire program files that implement at least one business function.
[0111] The target content acquisition module 620 is used to determine the target content in the program file that is associated with the class dependency relationship;
[0112] The target content processing module 630 is used to adjust the content of classes in the program file based on the target content in the class, and obtain the interface class with the same name as the class.
[0113] The interface class file generation module 640 is used to delete interface classes with the same name as unused classes in the program file and obtain the interface class file corresponding to the program file.
[0114] In some embodiments of this application, the target content processing module 630 is specifically used to obtain the bytecode file of the class; convert the method source code in the bytecode file into empty implementation code to obtain the interface class with the same name as the class; wherein, the empty implementation code includes the same method signature as the method source code.
[0115] In some embodiments of this application, the interface class file generation module 640 is specifically used to obtain pre-configured obfuscation code rules, determine useless classes based on the obfuscation code rules, determine the target interface class from interface classes with the same name according to the class name of the useless class, remove the target interface class, and obtain the interface class file corresponding to the program file.
[0116] In some embodiments of this application, the interface class file generation module 640 is specifically used to determine naming rules based on obfuscation code rules; and to replace class names, method names, and variable names in the program file according to the naming rules.
[0117] In some embodiments of this application, the interface class file acquisition device 600 further includes a compilation module, which is specifically used to save the interface class file to the project management library.
[0118] In some embodiments of this application, the compilation module is further configured to obtain the target path of the interface class file in the project management library; and to compile the host application based on the target path of the interface class file to generate an executable code file.
[0119] The aforementioned interface class file acquisition device adjusts the target content associated with class dependencies to convert classes in the program file into interface classes with the same name. This decouples the dependencies between classes within the program file, or between classes within the program file and external classes. Then, by deleting useless classes from the interface classes with the same name in the program file, the decoupled classes in the program file are further optimized and compressed to obtain the interface class file. The interface class file only exposes specific classes and their methods, hiding the content related to class dependencies in the program file, thus achieving the goal of hiding the source code and ensuring source code security.
[0120] In some embodiments of this application, the interface class file acquisition device 600 can be implemented as a computer program, and the computer program can be implemented in the form of, for example, Figure 7 It runs on the computer device shown. The computer device's memory can store the various program modules that make up the interface class file acquisition device 600, for example, Figure 6 The diagram shows a program file acquisition module 610, a target content acquisition module 620, a target content processing module 630, and an interface class file generation module 640. The computer program comprised of these modules causes the processor to execute the steps in the interface class file acquisition methods of the various embodiments of this application described in this specification.
[0121] For example, Figure 7 The computer device shown can be used as follows Figure 6 The program file acquisition module 610 in the interface class file acquisition device 600 shown executes step S210. The computer device can execute step S220 through the target content acquisition module 620. The computer device can execute step S230 through the target content processing module 630. The computer device can execute step S240 through the interface class file generation module 640. The computer device includes a processor, memory, and a network interface connected via a system bus. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used to communicate with external computer devices via a network connection. When the computer program is executed by the processor, it implements a method for acquiring interface class files.
[0122] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0123] In some embodiments of this application, a computer device is provided, including one or more processors; a memory; and one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the processors in the following steps:
[0124] Obtain the program file that implements at least one business function;
[0125] Determine the target content in the program file that is associated with class dependencies;
[0126] Based on the target content in the class, the content of the class in the program file is adjusted to obtain the interface class with the same name as the class.
[0127] Delete the interface class with the same name as the unused class in the program file to obtain the interface class file corresponding to the program file.
[0128] In some embodiments of this application, when the processor executes the computer program, it further performs the following steps: obtaining the bytecode file of the class; converting the method source code in the bytecode file into empty implementation code to obtain an interface class with the same name as the class; wherein the empty implementation code includes the same method signature as the method source code.
[0129] In some embodiments of this application, when the processor executes the computer program, it also performs the following steps: obtaining pre-configured obfuscation code rules, determining useless classes based on the obfuscation code rules; determining the target interface class from interface classes with the same name according to the class name of the useless class; removing the target interface class to obtain the interface class file corresponding to the program file.
[0130] In some embodiments of this application, when the processor executes the computer program, it also performs the following steps: determining naming rules based on obfuscation code rules; and replacing class names, method names, and variable names in the program file according to the naming rules.
[0131] In some embodiments of this application, when the processor executes the computer program, it also performs the following step: saving the interface class file to the project management library.
[0132] In some embodiments of this application, when the processor executes the computer program, it also performs the following steps: obtaining the target path of the interface class file in the project management library; compiling the host application based on the target path of the interface class file to generate an executable code file.
[0133] The aforementioned computer device executes a computer program through a processor to implement the steps of obtaining interface class files. This involves adjusting the content of the target content associated with class dependencies, decoupling the dependencies between classes within the program file, or between classes within the program file and external classes. Then, by obfuscating the program file, the decoupled classes in the program file are further optimized and compressed to obtain interface class files. Only specific classes and their methods are exposed to the outside world, while hiding the content related to class dependencies in the program file, thus achieving the goal of hiding the source code and ensuring source code security.
[0134] In some embodiments of this application, a computer-readable storage medium is provided, storing a computer program that is loaded by a processor, causing the processor to perform the following steps:
[0135] Obtain the program file that implements at least one business function;
[0136] Determine the target content in the program file that is associated with class dependencies;
[0137] Based on the target content in the class, the content of the class in the program file is adjusted to obtain the interface class with the same name as the class.
[0138] Delete the interface class with the same name as the unused class in the program file to obtain the interface class file corresponding to the program file.
[0139] In some embodiments of this application, when a computer program is executed by a processor, it further performs the following steps: obtaining the bytecode file of the class; converting the method source code in the bytecode file into empty implementation code to obtain an interface class with the same name as the class; wherein the empty implementation code includes the same method signature as the method source code.
[0140] In some embodiments of this application, when the computer program is executed by the processor, it further performs the following steps: obtaining pre-configured obfuscation code rules, determining useless classes based on the obfuscation code rules; determining the target interface class from interface classes with the same name according to the class name of the useless class; removing the target interface class to obtain the interface class file corresponding to the program file.
[0141] In some embodiments of this application, when a computer program is executed by a processor, it further performs the following steps: determining naming rules based on obfuscation code rules; and replacing class names, method names, and variable names in the program file according to the naming rules.
[0142] In some embodiments of this application, when the computer program is executed by the processor, it also performs the following steps: saving the interface class file to the project management library.
[0143] In some embodiments of this application, when the computer program is executed by the processor, it further performs the following steps: obtaining the target path of the interface class file in the project management library; compiling the host application based on the target path of the interface class file to generate an executable code file.
[0144] The aforementioned computer program is loaded by the processor, causing the processor to execute the steps of obtaining the interface class file. This process adjusts the target content associated with class dependencies, decoupling the dependencies between classes within the program file or between classes within the program file and external classes. Then, by obfuscating the program file, the decoupled classes are further optimized and compressed to obtain the interface class file. Only specific classes and their methods are exposed, while the content related to class dependencies in the program file is hidden, thus achieving the goal of hiding the source code and ensuring source code security.
[0145] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0146] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0147] The foregoing has provided a detailed description of a method, apparatus, computer device, and storage medium for obtaining interface class files according to embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for obtaining an interface class file, characterized in that, include: Obtain the program file that implements at least one business function; Determine the target content associated with class dependencies in the class of the program file. The class is the basic unit of program code, and one class can correspond to one bytecode file. Based on the target content in the class, the class in the program file is adjusted to obtain an interface class with the same name as the class. Delete the interface class with the same name as the unused class in the program file; Obtain pre-configured obfuscation rules and determine naming rules based on the obfuscation rules; Replace the class names, method names, and variable names in the program file according to the naming rules to obtain the interface class file corresponding to the program file.
2. The method according to claim 1, characterized in that, The step of adjusting the content of the class in the program file based on the target content in the class to obtain an interface class with the same name as the class includes: Obtain the bytecode file of the class; The method source code in the bytecode file is converted into empty implementation code to obtain an interface class with the same name as the class; wherein the empty implementation code includes the same method signature as the method source code.
3. The method according to claim 1, characterized in that, The step of deleting the interface class with the same name as the useless class in the program file to obtain the interface class file corresponding to the program file includes: Obtain pre-configured obfuscation rules, and determine useless classes based on the obfuscation rules; The target interface class is determined from the interface classes with the same name based on the class name of the useless class; Remove the target interface class to obtain the interface class file corresponding to the program file.
4. The method according to claim 1, characterized in that, After deleting the interface class with the same name as the useless class in the program file to obtain the interface class file corresponding to the program file, the process further includes: Save the interface class file to the project management library.
5. The method according to claim 4, characterized in that, After deleting the interface class with the same name as the useless class in the program file to obtain the interface class file corresponding to the program file, the process further includes: Obtain the target path of the interface class file in the project management library; The host application is compiled based on the target path of the interface class file to generate an executable code file.
6. A device for obtaining interface class files, characterized in that, The device includes: The program file acquisition module is used to acquire program files that implement at least one business function. The target content acquisition module is used to determine the target content associated with the class dependency relationship in the class of the program file. The class is the basic unit of program code, and one class can correspond to one bytecode file. The target content processing module is used to perform content adjustment processing on the class in the program file based on the target content in the class, so as to obtain the interface class with the same name as the class; An interface class file generation module is used to delete interface classes with the same name as unused classes in the program file; obtain pre-configured obfuscation code rules and determine naming rules based on the obfuscation code rules; replace class names, method names and variable names in the program file according to the naming rules to obtain the interface class file corresponding to the program file.
7. A computer device, characterized in that, The computer device includes: One or more processors; Memory; and One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the method for obtaining the interface class file according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, It stores a computer program, which is loaded by a processor to execute the steps in the method for obtaining the interface class file as described in any one of claims 1 to 5.
9. A computer program product, comprising a computer program or instructions, characterized in that, When the computer program or instructions are executed by the processor, they implement the steps of the method for obtaining the interface class file as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Java program security processing method and device, computer equipment and storage medium
CN113656765A
Method and system for optimizing source code
US20070094650A1