A JAR package anti-decompilation method
By encrypting the JAR package and using the verification and decryption of the decryption lib file and class loading component, the problem of the single dimension of consideration in the existing anti-decompilation scheme is solved, and the practicality of anti-decompilation of JAR packages is improved.
Patent Information
- Application Number
- CN202311698021.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-12
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2043-12-12
AI Technical Summary
Existing anti-decompilation solutions for JAR packages consider only one dimension, resulting in poor practicality.
By configuring an encryption program to encrypt the JAR package, an encrypted JAR package is generated. The key is verified and decrypted using the decryption lib file and class loading component. The key is then transferred using the startup package, thereby improving the encryption security level.
It achieves multi-dimensional anti-decompilation effects for JAR packages, improves the encryption security level, and makes it more difficult to prevent decompilation.
Smart Images

Figure CN117874721B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to the fields of network technology and security technology, and in particular to a JAR package anti-decompilation method. BACKGROUND
[0002] Just-in-time compilation can load bytecode generated by JAVA language compilation according to needs during JVM runtime, and re-interpret and compile the bytecode to generate machine code of a target machine, which is beneficial to realize cross-platform business. The disadvantage is that the bytecode contains a large number of JAVA high-level language features, which is easy to be read by reverse decryption, resulting in core technology being stolen.
[0003] At present, various technical solutions have been proposed to prevent bytecode from being stolen by reverse decryption, such as CN202111389699.1, CN202011202910.X and CN202211036548.2, which all propose a scheme to prevent bytecode from being stolen. The summary idea is that there are mainly three solutions: the first is to perform non-semantic processing on variables, class names and other information in the bytecode through an obfuscation method. The disadvantage is that the non-semantic processing has low decryption complexity and limited anti-theft effect. The second is to encrypt the information in the bytecode through a certain encryption algorithm, and then decrypt it during runtime. The disadvantage is that the security of key delivery is not considered. The third is to introduce hardware media, CS authentication and other methods for encryption and decryption. The disadvantage is that the hardware deployment is difficult and has poor practicability.
[0004] In summary, the existing technology has the technical problem of poor practicability due to the single consideration dimension of the JAR package anti-decompilation scheme. SUMMARY
[0005] The application provides a JAR package anti-decompilation method, which is used to solve the technical problem of poor practicability due to the single consideration dimension of the JAR package anti-decompilation scheme in the prior art.
[0006] In view of the above problems, the application provides a JAR package anti-decompilation method.
[0007] The first aspect of the application provides a JAR package anti-decompilation method, comprising: calling an encryption program to encrypt an original JAR package to generate an encrypted JAR package; generating decryption information and configuring a decryption lib file, wherein the decryption lib file is associated with an encrypted file of the encrypted JAR package; when a start command parameter is received, activating a start program package to perform loading verification to generate a loading verification result; when the loading verification result is passed, activating a class loading component embedded in the encrypted JAR package to perform decryption verification to generate a decryption verification result; when the decryption verification result is passed, calling the decryption lib file to perform decryption of the encrypted file to obtain decrypted class information; loading the decrypted class information and deleting the start program package.
[0008] The second aspect of the application provides a JAR package anti-decompilation system, comprising: a first encryption unit configured to call an encryption program to encrypt an original JAR package to generate an encrypted JAR package; a first configuration unit configured to generate decryption information and configure a decryption lib file, wherein the decryption lib file is associated with an encrypted file of the encrypted JAR package; a first verification unit configured to, when a start command parameter is received, activate a start program package to perform loading verification to generate a loading verification result; a second verification unit configured to, when the loading verification result is passed, activate a class loading component embedded in the encrypted JAR package to perform decryption verification to generate a decryption verification result; a first decryption unit configured to, when the decryption verification result is passed, call the decryption lib file to perform decryption of the encrypted file to obtain decrypted class information; and a first loading unit configured to load the decrypted class information and delete the start program package. The one or more technical solutions provided in the application have at least the following technical effects or advantages:
[0009] The application calls an encryption program to encrypt an original JAR package to generate an encrypted JAR package; generates decryption information and configures a decryption lib file, wherein the decryption lib file is associated with an encrypted file of the encrypted JAR package; when a start command parameter is received, activates a start program package to perform loading verification to generate a loading verification result; when the loading verification result is passed, activates a class loading component embedded in the encrypted JAR package to perform decryption verification to generate a decryption verification result; when the decryption verification result is passed, calls the decryption lib file to perform decryption of the encrypted file to obtain decrypted class information; and loads the decrypted class information and deletes the start program package. By configuring an encryption program for encryption and using a start program package to implement key transmission, and by using a decryption lib file and a class loading component to implement key verification and decryption, no hardware configuration is required, the key transmission process is considered, the encryption security level is high, and the technical effect of improving the JAR package anti-decompilation effect in multiple dimensions is achieved. BRIEF DESCRIPTION OF DRAWINGS
[0010] Figure 1 A JAR package anti-decompilation method flowchart provided by the present application;
[0011] Figure 2 A functional module diagram of a JAR package anti-decompilation system provided by the present application;
[0012] Figure 3 A working principle diagram of encryption of a JAR package in a JAR package anti-decompilation method provided by the present application;
[0013] Figure 4 A working principle diagram of obtaining a startup program package in a JAR package anti-decompilation method provided by the present application;
[0014] Figure 5 A working principle diagram of a class loading component in a JAR package anti-decompilation method provided by the present application;
[0015] Figure 6 A structure diagram of a JAR package anti-decompilation system provided by the present application.
[0016] Legend: first encryption unit 100, first configuration unit 200, first verification unit 300, second verification unit 400, first decryption unit 500, first loading unit 600. DETAILED DESCRIPTION
[0017] The embodiments of the present application provide a JAR package anti-decompilation method, which is used to solve the technical problem of poor practicability caused by the single consideration dimension of the JAR package anti-decompilation scheme in the prior art. By configuring an encryption program for encryption, and using a startup program package to realize the transmission of a key, and using a decryption lib file and a class loading component to realize the verification and decryption of the key, without hardware configuration, the transmission process of the key is considered, the encryption security level is high, and the technical effect of improving the JAR package anti-decompilation effect in multiple dimensions is achieved.
[0018] Embodiment one
[0019] As shown in the Figure 1 The present application provides a JAR package anti-decompilation method, which includes the following steps:
[0020] S10: calling an encryption program to encrypt an original JAR package to generate an encrypted JAR package;
[0021] In one preferred embodiment, the JAR package anti-decompilation method of the embodiments of the present application is implemented through a JAR package anti-decompilation system, which at least has a memory and a processor. The computer instructions or codes of any step of the JAR package anti-decompilation method of the embodiments of the present application are stored in the memory, and the computer instructions or codes are called from the memory when any step of the JAR package anti-decompilation method of the embodiments of the present application is executed by the processor.
[0022] As shown in Figure 2 , the JAR package anti-decompilation system provided by the embodiments of the present application is preferably based on a JAR package that needs to be anti-decompiled, and is configured with an encryption program, a decryption lib of JNA call, a startup program package and a custom classLoader. The custom classLoader is not used for loading class information and verifying the class loading component, and is a virtual component commonly used in the java language. The custom classLoader is deployed in the encrypted JAR package. The encryption program is used for encrypting the JAR package that needs to be anti-decompiled. The decryption lib is a file information that stores a decryption method, which is associated with the encrypted class file of the encrypted JAR package, and can be called by the custom classLoader to realize the decryption of the encrypted class file. The startup program package is used for performing initial verification on the target JAR package when receiving the JAR package startup parameter, and performing operations such as encrypted key transmission.
[0023] Preferably, the JAR package, the custom classLoader and the encryption program are written in JAVA language, and the decryption lib and the startup program package are written in golang language. The golang language is a machine compiled language, which is used for writing ciphertext data and the startup program package, and can improve the decryption difficulty.
[0024] In summary, in order to implement the JAR package anti-decompilation method of the embodiments of the present application, the encryption program needs to be configured in advance to encrypt the original JAR package, so as to obtain an encrypted JAR package. Then, the decryption lib of JNA call is configured. Then, the startup program package and the custom classLoader (hereinafter referred to as the class loading component) are configured.
[0025] The first step is that the encryption program performs an algorithm process on the original JAR package, which is preferably as follows:
[0026] Further, as shown in Figure 3 , the encryption program is called to encrypt the original JAR package to generate an encrypted JAR package, including the following steps:
[0027] S11: traversing the original JAR package to select a file to be encrypted;
[0028] S12: calling the encryption program, generating a first universally unique identifier, encrypting the to-be-encrypted file to generate an encrypted file, replacing the to-be-encrypted file with the original JAR package to generate the encrypted JAR package.
[0029] Further, when receiving the start command parameter, the start program package is activated for loading verification, and a loading verification result is generated. The previous steps further include steps of:
[0030] S121: obtaining the MD5 value, SHA-1 value and encryption password of the encrypted JAR package, generating a machine code compiled language file through machine code compilation;
[0031] S122: constructing the start program package according to the machine code compiled language file.
[0032] In a preferred embodiment, the original JAR package, that is, the JAR package that needs to be encrypted, and the to-be-encrypted file refer to the preset class file that needs to be encrypted in the JAR package.
[0033] After the JAVA program is compiled, the generated file directory mainly includes BOOT-INF, MATE-INF and org. The BOOT-INF includes classes and lib subdirectories. The classes folder contains engineering business code, and the core class information to be encrypted is contained in the directory; the lib directory contains third-party library files dependent on the business. The MATE-INF directory mainly stores the MAVEN packaging information. The maven directory stores the engineering POM file, engineering name, version information and the like. The resource directory stores resource files, such as static page resources, springboot configuration, log configuration and the like. The MANIFEST.MF file is usually used to define extension or packaging related data, and it is a metadata file with name / value pairs. The main class of the JAR package is defined in the file. The org directory stores springboot related class files.
[0034] Preferably, since the core class information to be encrypted is under BOOT-INF, the classes subdirectory under the BOOT-INF directory is traversed to extract any class file that needs to be encrypted. The encryption program is called to generate a first universally unique identifier, encrypt the file to be encrypted by a preset encryption method, generate an encrypted file, replace the file to be encrypted in the original JAR package, and generate an encrypted JAR package. The preset encryption method includes but is not limited to existing mature encryption methods such as asymmetric encryption, symmetric encryption, and chaos encryption. When the encrypted JAR package is generated, a decryption file is also generated, which is stored in the decryption lib file using machine code compilation language for easy calling in the next step. The first universally unique identifier is abbreviated as UUID in English. It is a standard 128-bit identifier used to uniquely identify information in a computing system. By using UUID as the encryption key, the encryption key is called in the next step, and its randomness and extremely low probability of repetition are used to ensure that the encryption key is different each time, thereby preventing theft.
[0035] Further, each encrypted JAR package has a corresponding startup program package of machine code compilation language. Preferably, after the encryption of all encrypted files in the encrypted JAR package is completed, the MD5 value, SHA-1 value and encryption key of the encrypted JAR package are extracted. The MD5 value and SHA-1 value are fingerprint data of the file, and when the encrypted JAR package changes, the MD5 value and SHA-1 value must also change. Therefore, the MD5 value, SHA-1 value and encryption key of the encrypted JAR package can be compiled by machine code compilation language to obtain a machine code compilation language file, and then the MD5 value and SHA-1 value can be configured to obtain a startup program package.
[0036] Further, the encryption program is called to generate a first universally unique identifier, encrypt the file to be encrypted, generate an encrypted file, replace the file to be encrypted in the original JAR package, and generate the encrypted JAR package. The steps further include:
[0037] S13: Directory configuration is performed on the encrypted JAR package to generate a directory configuration result, including:
[0038] S14: In the lib directory of the BOOT-INF directory, a preset version of the jna.jar library file is generated, and the JAR file directory of the encrypted JAR package is stored in the jna.jar library file.
[0039] S15: In the root directory of the encrypted JAR package, the first class file information of the com.sun.jna interface is copied.
[0040] S16: copying second class file information generated after compiling the class loading component under the root directory of the encrypted JAR package, and adding jna dependency information in the POM file in the META-INF / maven directory;
[0041] S17: modifying the class value of the encrypted JAR package in the MANIFEST.MF file in the META-INF directory to a preset class name, and constructing the class loading component embedded in the encrypted JAR package.
[0042] In a preferred embodiment, in order to realize the start of the Java package, the class loading component can be used for verification, preferably, the class file value of the self-compiled encrypted JAR package, i.e. the self-compiled classLoader class, is updated to the value of Main-Class in MANIFEST.MF, so that the class loading component becomes the entrance of the JAR package business class.
[0043] Preferably, the configuration process is as follows: the jna.jar library file is configured as a Java library, a preset version of the jna.jar library file is generated in the lib directory of the BOOT-INF directory, BOOT-INF / classpath.idx and BOOT-INF / layers.idx are rewritten, and the JAR file directory of the encrypted JAR package is embedded into the jna.jar library file; first class file information of the com.sun.jna interface is copied under the root directory of the encrypted JAR package; then second class file information generated after compiling the class loading component is copied under the root directory of the encrypted JAR package, and jna dependency information is added in the POM file in the maven directory of the META-INF directory; the class value of the encrypted JAR package in the MANIFEST.MF file in the META-INF directory is modified to a preset class name, the class loading component is constructed embedded in the encrypted JAR package, and the configuration of the class loading component is completed. The preset class name is the self-compiled classLoader class. The first class file information refers to the interface class file information with com.sun.jna as the directory path, which facilitates the decryption of the encrypted JAR package by the class loading component for fast calling of the decrypted lib file. The second class file information refers to the class file information of the self-compiled class loading component, which is used to determine whether verification is needed when the encrypted JAR package is called.
[0044] S20: generating decryption information and configuring a decrypted lib file, wherein the decrypted lib file is associated with the encrypted file of the encrypted JAR package;
[0045] Further, the decryption information is generated and the decrypted lib file is configured, wherein the decrypted lib file is associated with the encrypted file of the encrypted JAR package, comprising the steps of:
[0046] S21: configuring the decryption information according to the encrypted JAR package, storing into a lib folder, and generating the decryption lib file;
[0047] S22: creating a preset folder of JAN calling under the directory of the encrypted JAR package, wherein the preset folder is associated with the decryption lib file, and used for calling the decryption information to decrypt the encrypted file during decryption.
[0048] In a preferred embodiment, the decryption information refers to the key information for decryption determined after encryption using the encryption key, and the decryption information is one-to-one associated with the encrypted file of the encrypted JAR package. The key information for decryption and the information of one-to-one association of the decryption information and the encrypted file of the encrypted JAR package are compiled by using machine code language, and based on the compilation result, are stored into the lib folder to obtain the decryption lib file. Under the directory of the encrypted JAR package, a preset folder of JAN calling, i.e., the lib folder, is created, for example, win32-x86-64, and during decryption, the header file libfun.h and the dynamic link library libfun.dll of the lib are copied to the lib folder, so that the encrypted JAR package can be decrypted by calling. The decryption lib file is compiled by using machine code language, so that the cracking difficulty of the decryption lib file is improved, and the security is improved.
[0049] S30: when receiving the start command parameter, activating the start program package to perform loading verification, and generating a loading verification result;
[0050] In a preferred embodiment, when receiving the start command of the JAR package, the start program package receives the start command parameter to perform loading verification, and if the loading verification result is passed, the key is transmitted. The start command parameter is exemplarily: when starting the JAR package, the JAR package to be started and the start program package are placed in the same directory, assuming that the name of the start program package is start and the name of the JAR package is test.jar, and the start program package is activated and run by the command starttest.jar.
[0051] Further, as shown in Figure 4 when receiving the start command parameter, activating the start program package to perform loading verification, and generating a loading verification result, including:
[0052] performing system clock function verification to generate a first loading verification result;
[0053] performing fingerprint verification on the start command parameter to generate a second loading verification result;
[0054] When the first loading check result is failed or / and the second loading check result is failed, the loading check result is marked as failed.
[0055] When the first loading check result is passed and the second loading check result is passed, the loading check result is marked as passed.
[0056] In a preferred embodiment, the loading check at least includes system clock function check and fingerprint check, but does not add restrictions to other conventional check methods.
[0057] The system clock function check process is as follows:
[0058] Further, the system clock function check is performed to generate the first loading check result, including:
[0059] A preset numerical variable and a preset cycle number are configured, wherein the initial value of the preset numerical variable is 0, and the preset numerical variable is an integer;
[0060] A second current timestamp is obtained;
[0061] The system is cyclically run according to the preset cycle number, a third current timestamp is obtained, a deviation from the second current timestamp is calculated, and a first time deviation is obtained;
[0062] When the first time deviation is within a preset time deviation range, the first loading check result is marked as passed, otherwise, it is marked as failed.
[0063] In a preferred embodiment, a preset numerical variable and a preset cycle number are configured, the initial value of the preset numerical variable is 0, and the preset numerical variable is an integer. The second current timestamp refers to the time identifier when the system clock function check is started. The system is cyclically run according to the preset cycle number, and when the running number of the preset cycle number is met, the time identifier of the running completion is recorded, which is the third current timestamp. The time interval between the third current timestamp and the second current timestamp is calculated, which is the first time deviation. When the first time deviation is within a preset time deviation range, the first loading check result is marked as passed, otherwise, it is marked as failed. The preset time deviation range is a preset time deviation for evaluating whether the system clock function is normal. The decryption process of the method involves the timestamp, and the purpose of checking the clock during running is to prevent the system time from being fixed by a cracker for cracking attempt.
[0064] The fingerprint check process is as follows:
[0065] Further, the fingerprint check is performed on the start command parameter to generate the second loading check result, including:
[0066] According to the second start command parameter, a JAR package retrieval result is obtained;
[0067] When the number of the JAR package retrieval result is zero, the second loading verification result is identified as failed.
[0068] Further, the method further comprises:
[0069] When the number of the JAR package retrieval result is not zero, a retrieval JAR package MD5 value and a retrieval JAR package SHA-1 value are extracted;
[0070] According to the start program package, an encrypted JAR package MD5 value and an encrypted JAR package SHA-1 value are called;
[0071] When the encrypted JAR package MD5 value is the same as the retrieval JAR package MD5 value, and the retrieval JAR package SHA-1 value is the same as the encrypted JAR package SHA-1 value, the second loading verification result is identified as passed;
[0072] Otherwise, the second loading verification result is identified as failed.
[0073] In a preferred embodiment, the second parameter of the start command parameter, i.e., the name of the java package to be started, is extracted. For example, when the start command parameter is start test.jar, the second parameter is test.jar. The JAR package retrieval result is obtained by searching in the root directory of the java package. When the number of JAR packages in the JAR package retrieval result is 0, the second loading verification result is identified as failed. When the number of the JAR package retrieval result is not zero, the JAR package retrieval result MD5 value and the retrieval JAR package SHA-1 value of the retrieval JAR package of the JAR package retrieval result are extracted. Then, the encrypted java package MD5 value and the SHA-1 value stored in the start program package are compared. When the encrypted JAR package MD5 value is the same as the retrieval JAR package MD5 value, and the retrieval JAR package SHA-1 value is the same as the encrypted JAR package SHA-1 value, the second loading verification result is identified as passed. Otherwise, the second loading verification result is identified as failed. The start program package generates MD5 and SHA-1 values of the retrieval JAR package, and compares the newly generated values with the encrypted JAR package MD5 and SHA-1 values recorded in the start program package. If the values are the same, it is considered that the JAR package is the target JAR package. Otherwise, it is considered that the JAR package has been tampered with, and the program package exits the running and refuses to load. The security of the encrypted JAR package is ensured.
[0074] S40: When the loading verification result is passed, a class loading component embedded in the encrypted JAR package is activated to perform decryption verification, and a decryption verification result is generated.
[0075] Further, when the loading verification result is passed, a class loading component embedded in the encrypted JAR package is activated to perform decryption verification, and a decryption verification result is generated, including:
[0076] When the loading verification result is passed, ciphertext data is encrypted based on a preset encryption method to obtain encrypted ciphertext information, which is transmitted to the class loading component, wherein the decryption lib file has a decryption private key of the encrypted ciphertext information;
[0077] System clock function verification is performed to generate a first decryption verification result;
[0078] The encrypted ciphertext information is verified to generate a second decryption verification result;
[0079] When the first decryption verification result is not passed or / and the second decryption verification result is not passed, the decryption verification result is marked as not passed;
[0080] When the first decryption verification result is passed and the second decryption verification result is passed, the decryption verification result is marked as passed.
[0081] In a preferred embodiment, when the loading verification result is passed, ciphertext data such as a key needs to be encrypted and transmitted in a startup package to avoid the risk of hijacking during transmission. When the ciphertext data is transmitted to the class loading component, decryption verification is performed using the class loading component, wherein the decryption verification includes system clock function verification and encrypted ciphertext information verification. The system clock function verification corresponds to the first decryption verification result, and the encrypted ciphertext information verification corresponds to the second decryption verification result. When the first decryption verification result is not passed and any one of the second decryption verification results is not passed, the decryption verification result is marked as not passed. When the first decryption verification result is passed and the second decryption verification result is marked as passed, the decryption verification result is marked as passed. The system clock function verification process is exactly the same as the system clock function verification process of the startup package, and will not be described in detail.
[0082] The encrypted ciphertext information verification is described in detail as follows:
[0083] Preferably, the ciphertext encryption transmission process is as follows:
[0084] Further, when the loading verification result is passed, ciphertext data is encrypted based on a preset encryption method to obtain encrypted ciphertext information, which is transmitted to the class loading component, including:
[0085] According to the startup package, a second universally unique identifier is generated, and the preset encryption method is called to perform encryption to obtain first encrypted ciphertext information;
[0086] According to the startup package, a first current timestamp is obtained, the preset encryption method is called for encryption, and second encrypted ciphertext information is obtained;
[0087] According to the startup package, an encrypted file is obtained, the preset encryption method is called for encryption, and third encrypted ciphertext information is obtained;
[0088] The first encrypted ciphertext information, the second encrypted ciphertext information, and the third encrypted ciphertext information are added to the encrypted ciphertext information, wherein the encrypted ciphertext information is a machine code compilation language;
[0089] According to the startup package, the second universally unique identifier is stored to a verification passed JAR package, JAR package startup parameters are generated, and the encrypted ciphertext information and the JAR package startup parameters are transmitted to the class loading component.
[0090] In a preferred embodiment, when the loading verification result is passed, the ciphertext information that needs to be encrypted is called. Preferably, the encrypted ciphertext includes at least the second universally unique identifier, the encrypted file, that is, the encrypted key, and the first current timestamp, that is, the time identifier when the encrypted ciphertext is generated. The second universally unique identifier is different each time the startup is started, and is generated for the startup package to prevent malicious behavior of repeated attempts to decompile. The preset encryption method refers to an encryption method that is preconfigured with a decryption lib file. The decryption key of the preset encryption method is stored in the decryption lib file. According to the startup package, the second universally unique identifier is generated, the preset encryption method is called for encryption, and first encrypted ciphertext information is obtained. According to the startup package, a first current timestamp is obtained, the preset encryption method is called for encryption, and second encrypted ciphertext information is obtained. According to the startup package, an encrypted file is obtained, the preset encryption method is called for encryption, and third encrypted ciphertext information is obtained. The first encrypted ciphertext information, the second encrypted ciphertext information, and the third encrypted ciphertext information are added to the encrypted ciphertext information, wherein the encrypted ciphertext information is a machine code compilation language. Preferably, the three encrypted ciphertext information of the encrypted ciphertext information is stored in three files in the same directory of the startup package, and is named in a non-semantic manner to prevent crackers from understanding the file purpose through the file name.
[0091] Further, the second universally unique identifier code is stored to the passed JAR package, the passed JAR package refers to the JAR package to be started which has passed the loading check, a JAR package starting parameter is generated, preferably, the JAR package starting parameter is a cmd command, and a command provided by JVM to prevent DEBUG is added to prevent crackers from debugging, the second universally unique identifier code is passed to the passed JAR package through the cmd parameter, and an exemplary cmd parameter is: java–jar-DisableAttachMechanism test.jar token. Then the encrypted ciphertext information and the JAR package starting parameter are passed to the class loading component.
[0092] Further, as shown in Figure 5 After receiving the encrypted ciphertext information and the JAR package starting parameter, the encrypted ciphertext information checking process is as follows:
[0093] Further, the encrypted ciphertext information is checked to generate a second decryption check result, including:
[0094] The encrypted ciphertext information is decrypted to obtain a second universally unique identifier code original value;
[0095] When the second universally unique identifier code original value is different from the second universally unique identifier code transmission value of the JAR package starting parameter, the second decryption check result is identified as not passed.
[0096] In a preferred embodiment, the ciphertext information of the second universally unique identifier code of the encrypted ciphertext information is decrypted through the decryption of the lib file to obtain the second universally unique identifier code original value, that is, the encrypted second universally unique identifier code, which is compared with the second universally unique identifier code transmission value of the JAR package starting parameter, if they are different, the second decryption check result is identified as not passed. If they are not the same, it is considered that this time of starting is abnormal, and the loading is refused. The second universally unique identifier code transmission value refers to the uuid code of the passed JAR package to which the second universally unique identifier code is passed through the cmd parameter.
[0097] Further, it further includes:
[0098] When the second universally unique identifier code original value is the same as the second universally unique identifier code transmission value of the JAR package starting parameter, the encrypted ciphertext information is decrypted to obtain a first current timestamp, the time difference with a fourth current timestamp is calculated to obtain a second time deviation;
[0099] A time deviation modulus value range is configured;
[0100] When the second time deviation is not within the time deviation modulus value range, the second decryption check result is identified as not passed;
[0101] Otherwise, the second decryption check result is identified as passing.
[0102] In a preferred embodiment, when the second universally unique identification code original value is the same as the second universally unique identification code passing value of the JAR package startup parameter, the ciphertext information of the first current timestamp of the encrypted ciphertext information is decrypted to obtain the first current timestamp; the time interval between the fourth current timestamp and the current time identifier is calculated, and is set as the second time deviation. Based on the time deviation modulus range pre-configured by the user, such as 1 second. When the second time deviation is less than the time deviation modulus range, for example, less than or equal to 1 second, the second decryption check result is identified as passing; if greater than 1 second, the second decryption check result is identified as not passing, and the loading is refused.
[0103] The embodiment of the application determines a unique startup call through the second universally unique identification code plus timestamp in each startup change, so as to prevent a cracker from repeatedly debugging and attempting to crack by using the three files (the second universally unique identification code after asymmetric encryption, the timestamp and the encrypted key) generated by the program package.
[0104] S50: When the decryption check result is passing, the decryption lib file is called to execute decryption of the encrypted file to obtain decryption class information;
[0105] Further, when the decryption check result is passing, the decryption lib file is called to execute decryption of the encrypted file to obtain decryption class information, including:
[0106] Obtaining the file class of the JAR package to be started;
[0107] When the class header information of the file class conforms to the preset format, the file class is directly loaded;
[0108] When the class header information of the file class does not conform to the preset format, the decryption lib file is called to execute decryption of the file class to obtain decryption class information.
[0109] In a preferred embodiment, when the decryption check result is passing, the decryption lib file is called to execute decryption of the encrypted file to obtain decryption class information representing class data to be called. The method for determining the encrypted file is as follows:
[0110] The file class of the JAR package to be started is determined, when the class header information of the file class conforms to the preset format, the file class is directly loaded; when the class header information of the file class does not conform to the preset format, the decryption lib file is called to execute decryption of the file class to obtain decryption class information. This is because the unencrypted class header information conforms to the standard format, and is random code after encryption.
[0111] S60: loading the decrypted class information, and deleting the startup program package.
[0112] In a preferred embodiment, the JAR package is deleted after decryption. When the program needs to be restarted or deployed again, the startup program package can be deployed again. This releases space and reduces system load pressure.
[0113] To sum up, the embodiments of the present application have at least the following technical effects:
[0114] 1. The embodiments of the present application provide a JAR package anti-decompilation method, which is used to solve the poor practicability caused by the single consideration dimension of the JAR package anti-decompilation scheme in the prior art. An encryption program is configured to be used for encryption, a startup program package is used to implement key transmission, and a decryption lib file and a class loading component are used to implement key verification and decryption, without hardware configuration. The transmission process of the key is considered, the encryption security level is high, and the technical effect of multi-dimensional improvement of the JAR package anti-decompilation effect is achieved.
[0115] 2. The embodiments of the present application determine the unique startup call in the mode of the second universally unique identifier plus a timestamp each time the startup is changed, to prevent a cracker from repeatedly debugging and attempting to crack by using the three files (the asymmetrically encrypted second universally unique identifier, the timestamp, and the encrypted key) generated by the program package.
[0116] Embodiment Two
[0117] Based on the same inventive concept as the JAR package anti-decompilation method in the foregoing embodiments, as shown in Figure 6 The present application provides a JAR package anti-decompilation system, which comprises:
[0118] A first encryption unit 100 is configured to call an encryption program to encrypt an original JAR package and generate an encrypted JAR package;
[0119] A first configuration unit 200 is configured to generate decryption information and configure a decryption lib file, wherein the decryption lib file is associated with the encrypted file of the encrypted JAR package.
[0120] A first verification unit 300 is configured to activate a startup program package to perform loading verification when a startup command parameter is received, and generate a loading verification result.
[0121] A second verification unit 400 is configured to activate a class loading component embedded in the encrypted JAR package to perform decryption verification when the loading verification result is passed, and generate a decryption verification result.
[0122] The first decryption unit 500 is configured to call the decryption lib file to perform decryption of the encrypted file when the decryption check result is passed, and obtain decryption class information.
[0123] The first loading unit 600 is configured to load the decryption class information and delete the start program package.
[0124] Further, the first encryption unit 100 performs the steps comprising:
[0125] Traverse the original JAR package, and select a file to be encrypted;
[0126] Call the encryption program, generate a first universally unique identifier, encrypt the file to be encrypted to generate an encrypted file, replace the file to be encrypted in the original JAR package, and generate the encrypted JAR package.
[0127] Further, the first encryption unit 100 performs the steps comprising:
[0128] Directory configuration is performed on the encrypted JAR package to generate a directory configuration result, comprising:
[0129] In the lib directory of the BOOT-INF directory, a preset version of a jna.jar library file is generated, and a JAR file directory of the encrypted JAR package is stored in the jna.jar library file;
[0130] Under the root directory of the encrypted JAR package, first class file information of a com.sun.jna interface is copied;
[0131] Under the root directory of the encrypted JAR package, second class file information of the class loading component after compilation is copied, and jna dependency information is added in a POM file in the META-INF / maven directory;
[0132] The class value of the encrypted JAR package in a MANIFEST.MF file in the META-INF directory is modified to a preset class name, and the class loading component is embedded in the encrypted JAR package.
[0133] Further, the first configuration unit 200 performs the steps comprising:
[0134] According to the encrypted JAR package, the decryption information is configured and stored in a lib folder to generate a decryption lib file;
[0135] A preset folder for JAN calling is created under the directory of the encrypted JAR package, wherein the preset folder is associated with the decryption lib file, and is used to call the decryption information to decrypt the encrypted file.
[0136] Further, the first checking unit 300 performs the steps of:
[0137] Obtaining the MD5 value, SHA-1 value and encryption password of the encrypted JAR package, compiling through machine code to generate a machine code compiled language file;
[0138] According to the machine code compiled language file, the startup program package is constructed.
[0139] Further, the first checking unit 300 performs the steps of:
[0140] Performing system clock function checking to generate a first loading checking result;
[0141] Performing fingerprint checking on the startup command parameter to generate a second loading checking result;
[0142] When the first loading checking result is failed or / and the second loading checking result is failed, the loading checking result is marked as failed;
[0143] When the first loading checking result is passed and the second loading checking result is passed, the loading checking result is marked as passed.
[0144] Further, the second checking unit 400 performs the steps of:
[0145] When the loading checking result is passed, the ciphertext data is encrypted based on a preset encryption method to obtain encrypted ciphertext information, which is transmitted to the class loading component, wherein the decryption lib file has a decryption private key of the encrypted ciphertext information;
[0146] Performing system clock function checking to generate a first decryption checking result;
[0147] Performing the encrypted ciphertext information checking to generate a second decryption checking result;
[0148] When the first decryption checking result is failed or / and the second decryption checking result is failed, the decryption checking result is failed;
[0149] When the first decryption checking result is passed and the second decryption checking result is passed, the decryption checking result is passed.
[0150] Further, the second checking unit 400 performs the steps of:
[0151] According to the startup program package, a second universally unique identifier is generated, the preset encryption method is called for encryption to obtain first encrypted ciphertext information;
[0152] According to the startup package, a first current timestamp is obtained, the preset encryption method is called for encryption, and second encrypted ciphertext information is obtained;
[0153] According to the startup package, an encrypted file is obtained, the preset encryption method is called for encryption, and third encrypted ciphertext information is obtained;
[0154] The first encrypted ciphertext information, the second encrypted ciphertext information, and the third encrypted ciphertext information are added to the encrypted ciphertext information, wherein the encrypted ciphertext information is a machine code compilation language;
[0155] According to the startup package, the second universally unique identifier code is stored to a verification passed JAR package, a JAR package startup parameter is generated, and the encrypted ciphertext information and the JAR package startup parameter are transmitted to the class loading component.
[0156] Further, the first verification unit 300 performs the following steps:
[0157] A preset numerical variable and a preset number of cycles are configured, wherein the initial value of the preset numerical variable is 0, and the preset numerical variable is an integer;
[0158] A second current timestamp is obtained;
[0159] According to the preset number of cycles, system cycle operation is performed, a third current timestamp is obtained, a deviation from the second current timestamp is calculated, and a first time deviation is obtained;
[0160] When the first time deviation is within a preset time deviation range, the first loading verification result is identified as passed, otherwise, it is identified as not passed.
[0161] Further, the first verification unit 300 performs the following steps:
[0162] According to the second startup parameter of the startup command parameter, a JAR package retrieval result is obtained;
[0163] When the number of JAR package retrieval results is zero, the second loading verification result is identified as not passed.
[0164] Further, the first verification unit 300 performs the following steps:
[0165] When the number of JAR package retrieval results is not zero, a retrieval JAR package MD5 value and a retrieval JAR package SHA-1 value are extracted;
[0166] According to the startup package, an encrypted JAR package MD5 value and an encrypted JAR package SHA-1 value are called;
[0167] When the encrypted JAR package MD5 value and the retrieved JAR package MD5 value are the same, and the retrieved JAR package SHA-1 value and the encrypted JAR package SHA-1 value are the same, the second loading verification result is identified as passed;
[0168] Otherwise, the second loading verification result is identified as failed.
[0169] Further, the second verification unit 400 performs steps including:
[0170] Decrypting the encrypted ciphertext information to obtain a second universally unique identification code original value;
[0171] When the second universally unique identification code original value and the second universally unique identification code transmission value of the JAR package startup parameter are different, the second decryption verification result is identified as failed.
[0172] Further, the second verification unit 400 performs steps including:
[0173] When the second universally unique identification code original value and the second universally unique identification code transmission value of the JAR package startup parameter are the same, decrypting the encrypted ciphertext information to obtain a first current timestamp, calculating a time difference with a fourth current timestamp to obtain a second time deviation;
[0174] Configuring a time deviation modulus value range;
[0175] When the second time deviation is not within the time deviation modulus value range, the second decryption verification result is identified as failed.
[0176] Otherwise, the second decryption verification result is identified as passed.
[0177] Further, the first decryption unit 500 performs steps including:
[0178] Obtaining a file class of a JAR package to be started;
[0179] When the class header information of the file class conforms to a preset format, directly loading the file class;
[0180] When the class header information of the file class does not conform to the preset format, calling the decryption lib file to perform decryption of the file class to obtain decrypted class information.
[0181] The specification and drawings are, of course, to be regarded in an illustrative rather than a restrictive sense. It is to be understood that any such modifications, variations, combinations or equivalents that fall within the scope of the application are intended to be embraced herein.
Claims
1. A method for preventing JAR packages from being decompiled, characterized in that, include: The encryption program is invoked to encrypt the original JAR file and generate an encrypted JAR file. Generate decryption information and configure the decryption lib file, wherein the decryption lib file is associated with the encrypted file of the encrypted JAR package; When the startup command parameters are received, the startup package is activated to perform loading verification and generate loading verification results. When the loading verification result is passed, the class loading component embedded in the encrypted JAR package is activated to perform decryption verification and generate a decryption verification result; When the decryption verification result is successful, the decryption lib file is invoked to decrypt the encrypted file and obtain the decryption class information. The decryption information is loaded, and the startup package is deleted.
2. The method as described in claim 1, characterized in that, The encryption program is invoked to encrypt the original JAR file, generating an encrypted JAR file, which includes: Iterate through the original JAR files and select the file to be encrypted; The encryption program is invoked to generate a first universally unique identifier, which is then used to encrypt the file to be encrypted, generating an encrypted file. The file to be encrypted is then replaced in the original JAR package to generate the encrypted JAR package.
3. The method as described in claim 2, characterized in that, The encryption program is invoked to generate a first universally unique identifier, encrypt the file to be encrypted to generate an encrypted file, replace the file to be encrypted in the original JAR file to generate the encrypted JAR file, and then the process further includes: Configure the directory for the encrypted JAR package and generate the directory configuration result, including: In the lib directory of the BOOT-INF directory, a preset version of the jna.jar library file is generated, and the JAR file directory of the encrypted JAR package is stored in the jna.jar file; In the root directory of the encrypted JAR package, copy the first type of file information that generates the com.sun.jna interface; In the root directory of the encrypted JAR package, copy the second type of file information after the class loading component is compiled, and at the same time modify the POM file in the META-INF / maven directory to add JNA dependency information; Modify the class value of the encrypted JAR package in the MANIFEST.MF file of the META-INF directory to a preset class name, and construct the class loading component embedded in the encrypted JAR package.
4. The method as described in claim 1, characterized in that, Generate decryption information and configure the decryption lib file, wherein the decryption lib file is associated with the encrypted file of the encrypted JAR package, including: Based on the encrypted JAR package, configure the decryption information, store it in the lib folder, and generate the decrypted lib file; In the directory of the encrypted JAR package, a preset folder for JAN calls is created. The preset folder is associated with the decryption lib file and is used to call the decryption information to decrypt the encrypted file during decryption.
5. The method as described in claim 4, characterized in that, Upon receiving the startup command parameters, the startup package is activated for loading verification, and a loading verification result is generated, which includes: Obtain the MD5 value, SHA-1 value, and encryption password of the encrypted JAR package, and compile it using machine code to generate a machine code compiled language file; The startup package is constructed by compiling the language file based on the machine code.
6. The method as described in claim 1, characterized in that, Upon receiving the startup command parameters, the startup package is activated for loading verification, and a loading verification result is generated, including: Perform system clock function verification and generate the first load verification result; The startup command parameters are fingerprinted to generate a second loading verification result; When the first loading verification result is failed and / or the second loading verification result is failed, the loading verification result is marked as failed; If both the first and second loading verification results are passed, the loading verification results are marked as passed.
7. The method as described in claim 6, characterized in that, When the loading verification result is successful, the class loading component embedded in the encrypted JAR package is activated to perform decryption verification and generate a decryption verification result, including: When the loading verification result is passed, the ciphertext data is encrypted based on a preset encryption method to obtain encrypted ciphertext information, which is then transmitted to the class loading component. The decryption lib file contains the decryption private key of the encrypted ciphertext information. Perform system clock function verification and generate the first decryption verification result; The encrypted ciphertext information is verified to generate a second decryption verification result; When the first decryption verification result is failed and / or the second decryption verification result is failed, the decryption verification result is marked as failed; When both the first and second decryption verification results are passed, the decryption verification results are marked as passed.
8. The method as described in claim 7, characterized in that, When the loading verification result is successful, the ciphertext data is encrypted using a preset encryption method to obtain encrypted ciphertext information, which is then transmitted to the class loading component, including: Based on the startup package, a second universal unique identifier is generated, and the preset encryption method is called to encrypt the first encrypted ciphertext information. Based on the startup package, a first current timestamp is obtained, and the preset encryption method is called to encrypt the second encrypted ciphertext information. According to the startup package, an encrypted file is obtained, and the preset encryption method is called to encrypt it to obtain the third encrypted ciphertext information; The first encrypted ciphertext, the second encrypted ciphertext, and the third encrypted ciphertext are added to the encrypted ciphertext, wherein the encrypted ciphertext is machine code compiled language; According to the startup package, the second universal unique identifier is stored in the verified JAR package, JAR package startup parameters are generated, and the encrypted ciphertext information and the JAR package startup parameters are passed to the class loading component.
9. The method as described in claim 6, characterized in that, Perform system clock function verification and generate the first load verification result, including: Configure a preset numerical variable and a preset number of loops, wherein the initial value of the preset numerical variable is 0, and the preset numerical variable is an integer; Get the second current timestamp; The system runs in a loop according to the preset number of loops to obtain a third current timestamp, and the deviation from the second current timestamp is calculated to obtain a first time deviation; If the first time deviation is within the preset time deviation range, the first loading verification result is marked as passed; otherwise, it is marked as failed.
10. The method as described in claim 6, characterized in that, The startup command parameters are fingerprinted to generate a second loading verification result, including: The search is performed based on the second startup parameter of the startup command parameters to obtain the JAR package search results; If the number of JAR package retrieval results is zero, the second loading verification result is marked as failed.
Citation Information
Patent Citations
A method, system, and storage medium for parsing and decrypting encryption based on a JAR program.
CN112329035B
Java code obfuscation method and system, computer equipment and storage medium
CN114090965A
Method and system for operating Java encrypted jar packet based on JNI
CN115114595A
Java code encasing method and system
CN111552931A
Method for preventing Java program from being decompiled
CN112131536A