Application program reinforcing method and device, storage medium and electronic equipment
By generating code relationship diagrams and retrieval rules to determine the application's code set to be processed and then performing hardening, the problem of low hardening efficiency in existing technologies is solved, achieving efficient and secure application hardening.
Patent Information
- Application Number
- CN202411052268.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-01
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2044-08-01
AI Technical Summary
Existing application hardening methods are inefficient, cannot accurately locate the code that needs hardening, and the decryption process during runtime cannot guarantee the stability of the application.
By generating a code relationship graph, retrieval rules are generated based on the reference relationships between classes. The code set to be processed is determined from the bytecode assembly file and then hardened. This includes determining the class code with SDK package, inheritance relationship, call relationship and overloading relationship, merging them and then compiling and hardening them.
It improves the efficiency of application hardening, accurately locates and hardens critical code, enhances the security and stability of program code, and reduces runtime overhead.
Smart Images

Figure CN119004414A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and more specifically, to a method and device for reinforcing an application program, a storage medium, and an electronic device. Background Art
[0002] With the rapid development of the Android platform, it has occupied the mainstream market of current mobile smart terminals. Due to the open source nature of the Android system, and the fact that Android applications are basically developed using the Java language, Java is compiled to generate a .dex file. After decompilation, the program code can be easily displayed to users intuitively. If a slight modification is made, a new mobile application can be generated. Therefore, in order to prevent applications from being maliciously attacked, it is particularly important to harden the application.
[0003] In the related art, there are two main methods for reinforcing applications: one is to encrypt the entire code, and the other is to extract the target function's instructions from the dex file and encrypt them, and then decrypt and fill them as needed during runtime. However, the overall code encryption method consumes a large operating overhead, and the latter reinforcement method cannot accurately locate the code that needs to be reinforced, and the decryption process during operation cannot guarantee the stability of the application. In other words, the technical problem of low efficiency in the reinforcement process of the application in the related art.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present application provide a method and device for reinforcing an application, a storage medium, and an electronic device, so as to at least solve the technical problem of low efficiency that occurs during the reinforcement process of the application.
[0006] According to one aspect of an embodiment of the present application, a method for reinforcing an application is provided, comprising: obtaining a code relationship graph of a target application, wherein the code relationship graph includes reference relationships between classes in a bytecode assembly file corresponding to the target application; generating a code retrieval strategy based on class codes of each class, wherein the code retrieval strategy includes a set of retrieval rules generated using reference relationships between classes; determining a code set to be processed from the bytecode assembly file based on a set of retrieval rules; and reinforcing the code in the code set to be processed to obtain a reinforced target application.
[0007] Optionally, the above-mentioned set of retrieval rules includes at least one of the following: determining at least part of the SDK packages from a set of SDK packages of the target application, and determining the code in at least part of the SDK packages as the first subset of code to be processed to be reinforced; determining the class code with an inheritance relationship as the second subset of code to be processed to be reinforced, wherein the relationship between the parent class and the child class with the same properties and methods is determined as an inheritance relationship; determining the method code in the class code with a calling relationship as the third subset of code to be processed to be reinforced, wherein in the case of calling a method code from the first class code to the second class code through a method signature, the first class code and the second class code have a calling relationship; determining the method code in the class code with an overloading relationship as the fourth subset of code to be processed to be reinforced, wherein in the case where the third class code inherits from the fourth class code and modifies the specified method in the fourth class code, the third class code and the fourth class code have an overloading relationship.
[0008] Optionally, the method further includes: merging the first code subset to be processed, the second code subset to be processed, the third code subset to be processed and the fourth code subset to be processed to obtain a code set to be processed.
[0009] Optionally, the above-mentioned reinforcement processing of the code in the code set to be processed to obtain a reinforced target application includes: compiling a group of bytecode assembly files corresponding to the code set to be processed into M bytecode files, where M is a positive integer greater than or equal to 1, and the bytecode assembly files corresponding to the target application include a group of bytecode assembly files; reinforcement processing is performed on the M bytecode files to obtain M reinforced bytecode files; based on the reinforced M bytecode files, a reinforced target application is obtained.
[0010] Optionally, the above-mentioned obtaining a reinforced target application based on the reinforced M bytecode files includes: removing class codes in N bytecode files that have the same attributes as those in M bytecode files to obtain N processed bytecode files, wherein the N bytecode files are obtained by compiling bytecode assembly files corresponding to the target application, and N is a positive integer greater than or equal to M; obtaining a reinforced target application based on the processed N bytecode files and the reinforced M bytecode files.
[0011] Optionally, before obtaining the code relationship diagram of the target application, the above method also includes: obtaining an APK application package of the target application, wherein the APK application package includes a group of bytecode files; decompiling the group of bytecode files to obtain a bytecode assembly file corresponding to the target application.
[0012] Optionally, after decompiling a group of bytecode files to obtain the bytecode assembly file corresponding to the target application, the above method also includes: parsing the data structure of each class in the bytecode assembly file corresponding to the target application to obtain the index relationship between each class; based on the index relationship between each class, generating a code relationship diagram.
[0013] According to another aspect of the embodiment of the present application, a reinforcement device for an application is also provided, including: a first acquisition unit, used to obtain a code relationship graph of a target application, wherein the code relationship graph includes reference relationships between classes in a bytecode assembly file corresponding to the target application; a first processing unit, used to generate a code retrieval strategy based on class codes of each class, wherein the code retrieval strategy includes a set of retrieval rules generated using reference relationships between classes; a second processing unit, used to determine a code set to be processed from the bytecode assembly file based on a set of retrieval rules; and a reinforcement unit, used to perform reinforcement processing on the code in the code set to be processed to obtain a reinforced target application.
[0014] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is used to execute the reinforcement method of the above-mentioned application when being run by an electronic device.
[0015] According to another aspect of an embodiment of the present application, there is also provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute a reinforcement method for the application program through the computer program.
[0016] Through the above-mentioned embodiments provided by the present application, a set of retrieval rules are generated according to the index relationship between each class in the bytecode assembly file corresponding to the application, and combined with the reinforcement requirements; a small amount of code that needs to be reinforced is determined from the bytecode assembly file according to the retrieval rules, so as to reinforce the key code of the application, thereby solving the problem of low reinforcement efficiency of program code in related technologies, achieving the technical effect of improving the reinforcement efficiency of the application, and improving the security of the program code. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings described herein are used to provide further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute improper limitations on the present application.
[0018] Figure 1 is a schematic diagram of an application scenario of an optional application reinforcement method according to an embodiment of the present application;
[0019] Figure 2is a flow chart of an optional application reinforcement method according to an embodiment of the present application;
[0020] Figure 3 is a schematic diagram of an optional code relationship diagram according to an embodiment of the present application;
[0021] Figure 4 It is a specific example of determining the code to be reinforced according to a search rule according to an optional embodiment of the present application;
[0022] Figure 5 is an overall flow chart of an optional application reinforcement method according to an embodiment of the present application;
[0023] Figure 6 is a schematic structural diagram of a reinforcement device for an optional application program according to an embodiment of the present application;
[0024] Figure 7 It is a schematic diagram of the structure of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0027] The technical solutions in the embodiments of the present application will comply with legal provisions during implementation. When performing operations according to the technical solutions in the embodiments, the data used will not involve user privacy. While ensuring that the operation process is compliant and legal, the security of the data is guaranteed.
[0028] In addition, when the above embodiments of the present application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant regulations and standards of the relevant country or region.
[0029] According to one aspect of the embodiments of the present application, a method for reinforcing an application is provided. As an optional implementation, the method for reinforcing an application can be applied to, but is not limited to, Figure 1 The application scenario shown in Figure 1 In the application scenario shown, the target terminal 102 may, but is not limited to, communicate with the server 106 via the network 104, and the server 106 may, but is not limited to, perform operations on the database 108, such as write data operations or read data operations. The above-mentioned target terminal 102 may, but is not limited to, include a human-computer interaction screen, a processor, and a memory. The above-mentioned human-computer interaction screen may, but is not limited to, be used to display a startup screen and a process screen of the target application on the target terminal 102. The above-mentioned processor may, but is not limited to, be used to respond to the above-mentioned human-computer interaction operation, perform corresponding operations, or generate corresponding instructions, and send the generated instructions to the server 106. The above-mentioned memory is used to store relevant processing data, such as code relationship diagrams, code retrieval strategies, and reinforced target applications.
[0030] Optionally, in this embodiment, the target terminal may be a terminal configured with a target client, which may include but is not limited to at least one of the following: a mobile phone (such as an Android phone, an iOS phone, etc.), a laptop, a tablet computer, a PDA, a MID (Mobile Internet Devices), a PAD, a desktop computer, a smart TV, etc. The target client may be a video client, an instant messaging client, a browser client, an education client, etc. The network may include but is not limited to: a wired network, a wireless network, wherein the wired network includes: a local area network, a metropolitan area network and a wide area network, and the wireless network includes: Bluetooth, WIFI and other networks that realize wireless communication. The server may be a single server, or a server cluster consisting of multiple servers, or a cloud server.
[0031] In order to solve the problem of low reinforcement efficiency of the above-mentioned application, an application reinforcement method is proposed in an embodiment of the present application. Figure 2 It is a flow chart of a method for reinforcing an application according to an embodiment of the present application, and the flow includes the following steps S202 to S208.
[0032] It should be noted that the application reinforcement method shown in step S202 to step S208 can be, but is not limited to, executed by an electronic device, wherein the electronic device can be, but is not limited to, Figure 1The target terminal or server is shown.
[0033] Step S202, obtaining a code relationship graph of the target application, wherein the code relationship graph includes reference relationships between classes in a bytecode assembly file corresponding to the target application;
[0034] Step S204, generating a code search strategy based on the class code of each class, wherein the code search strategy includes a set of search rules generated by using the reference relationship between each class;
[0035] Step S206, based on a set of search rules, determining a code set to be processed from the bytecode assembly file;
[0036] Step S208, strengthening the codes in the code set to be processed to obtain a strengthened target application.
[0037] The technical solution in the embodiments of the present application can be applied to, but is not limited to, code reinforcement of applications developed for the Android system (Android system), wherein developers develop different applications (referred to as APP) using the Java language, and the compilation tool compiles the Java source file into a Dalvik executable file (.dex).
[0038] Code hardening refers to the use of a series of technical means and methods to encrypt, obfuscate and modify key parts of the source code to enhance its ability to resist reverse engineering and malicious exploitation, thereby protecting core business logic, improving code security, and meeting compliance requirements.
[0039] By decompiling the above executable file (.dex), a bytecode assembly file (.smali file) corresponding to the target application is obtained, wherein the smali file is composed of multiple different classes, and each class corresponds to its own class code.
[0040] Each class includes different properties, methods and reference relationships between the class and other classes. The reference relationships in the embodiments of the present application include but are not limited to calling, inheritance, overloading, etc. The method is the smallest execution unit in a Java program. The function of a method is to improve the reusability and maintainability of the code.
[0041] In actual application scenarios, if a specific class belongs to a type of another large class, then when creating this specific class, it can be made to inherit the large class. In inheritance, the inherited class is called the parent class, and the inheritor is called the child class. After the child class inherits from the parent class, it contains all the properties and methods of the parent class. This reference relationship is called an inheritance relationship.
[0042] If a specific class belongs to a type of another large class, then when creating this specific class, it can be allowed to inherit the large class. In inheritance, the inherited class is called the parent class, and the inheritor is called the child class. After the child class inherits from the parent class, it contains all the properties and methods of the parent class. This reference relationship is called an inheritance relationship. The following will describe other reference relationships between classes in conjunction with specific embodiments.
[0043] Based on the class codes of the above-mentioned classes and in combination with the reinforcement requirements, a set of retrieval rules are generated, wherein the retrieval rules are used to determine a small amount of code that needs to be reinforced from the class codes of each class according to specified requirements.
[0044] The relationship between the classes can be obtained directly from the code relationship diagram, but is not limited to: Figure 3 As shown, the specific process of generating the code relationship diagram is described below in conjunction with a specific embodiment.
[0045] Before generating a code relationship diagram, you may, but are not limited to, perform the following process:
[0046] Obtaining an APK application package of a target application, wherein the APK application package includes a set of bytecode files;
[0047] Decompile a set of bytecode files to obtain the bytecode assembly file corresponding to the target application.
[0048] Among them, the APK application package contains a compressed package of multiple .dex files (which can also be understood as bytecode files). The above multiple .dex files are decompiled using tools to obtain the bytecode assembly files (.smali files) corresponding to the target application, and then the above code relationship diagram is generated based on the bytecode assembly files corresponding to the target application.
[0049] As an optional implementation method, the specific process of generating the above code relationship diagram is as follows:
[0050] Parse the data structure of each class in the bytecode assembly file corresponding to the target application to obtain the index relationship between each class;
[0051] Generate a code relationship diagram based on the index relationship between each class.
[0052] By parsing the class structures in the bytecode assembly file corresponding to the target application and the constants and calling method instructions in the bytecode, the class index and dependency relationship are established and mapped into Figure 3 The code relationship diagram shown.
[0053] It should be noted that the code relationship diagram includes but is not limited to the following information:
[0054] (1) A dictionary table of signature characters to class (Class), attribute (Field) and method (method) structures;
[0055] (2) The Class structure contains a list of declared member structures, where the members are Field and method;
[0056] (3) The Class structure contains a list of all inherited and implemented negative Class structures;
[0057] (4) The Class structure contains all references to the Type structure list, where Type is PrimitiveType and Class;
[0058] (5) The Class structure contains a list of all referenced String constants;
[0059] (6) The Class structure contains a list of all referenced methods;
[0060] (7) The Method structure contains a list of all other methods called;
[0061] (8) The Method structure contains a list of all Methods that are called by other Methods.
[0062] By using the apktool open source tool for decompilation and parsing the decompiled smali file according to the Dalvik bytecode protocol, we can obtain the reference relationship between each class structure, establish indexes and dependencies, and finally map it into a code relationship diagram.
[0063] The above code relationship diagram is the basis for implementing the technical solution of the present application. The relationship between each class can be directly determined from the code relationship diagram. For example, a subclass inherits from a parent class, method 1 (method1) in one class calls method 2 (method2) in the mehod list of another class, etc.
[0064] In combination with the above code relationship diagram and a set of pre-established retrieval rules, the code set to be processed is determined from the above bytecode assembly file, wherein a set of retrieval rules can be, but is not limited to, extracting a small amount of key code from the bytecode assembly file of the target application for reinforcement based on reinforcement requirements, thereby achieving the protection of key code and avoiding the problem of low efficiency caused by indiscriminate reinforcement of all codes.
[0065] As an optional implementation, the above set of search rules includes at least one of the following:
[0066] Determine at least some of the SDK packages from a group of SDK packages of the target application, and determine the codes in at least some of the SDK packages as the first subset of codes to be processed to be reinforced;
[0067] Determine the class codes with inheritance relationship as the second code subset to be processed to be reinforced, wherein the relationship between the parent class and the child class with the same attributes and methods is determined as the inheritance relationship;
[0068] Determine method codes in class codes having a calling relationship as a third to-be-processed code subset to be reinforced, wherein in the case where a method code is called from a first class code to a second class code through a method signature, the first class code and the second class code have a calling relationship;
[0069] The method codes in the class codes having an overloading relationship are determined as the fourth subset of codes to be processed to be reinforced, wherein the third class code and the fourth class code have an overloading relationship when the third class code inherits from the fourth class code and the designated method in the fourth class code is modified.
[0070] Among them, the above-mentioned way of modifying the specified method in the fourth category code includes but is not limited to modifying the number, order and type of parameters included in the specified method.
[0071] In the related art, the simplest and most accurate way to describe the reinforcement requirements is to enumerate the signatures of the basic elements (Class, Field, and Method) that need to be reinforced one by one. Therefore, in the embodiment of the present application, the retrieval rules for enumerated signatures are still used, and regular expression extensions are added to the signature characters. This rule can be referred to as R1. Example: "R1": ["Lcom / demo1 / ClassA;.*", "Lcom / demo2 / ClassB;.*"], indicating that the codes in ClassA and ClassB will be reinforced.
[0072] However, when the engineering code of the application increases to a certain scale, the above enumeration method becomes difficult to implement and maintain. Therefore, in the embodiment of the present application, the reinforcement requirements are further classified, and the reinforcement scope is determined according to the classification results.
[0073] The determination of the scope of reinforcement mainly depends on how to filter out a small amount of code that needs to be reinforced from the code files of the target application according to certain search rules. The search rules include but are not limited to the following:
[0074] (1) All code in the specified SDK package or class needs to be hardened;
[0075] It should be noted that an APK compressed package corresponding to an application includes multiple SDK packages (software development kits), where the SDK package is a collection of development tools used by software engineers to create application software for specific software packages, software frameworks, hardware platforms, operating systems, etc.
[0076] Since the Class signature must be prefixed with the package name of the SDK package, R1 based on the signature character regularization can actually be applied here.
[0077] For example, “R1”:[“Lcom / demo1 / .*”, “Lcom / demo2 / .*”] means that the codes in both demo1 and demo2 packages will be hardened.
[0078] (2) All class codes that inherit or implement the specified class need to be reinforced;
[0079] Combination Figure 3 The code relationship diagram shown can reverse index the parent class list corresponding to the class structure, so as to easily realize the search. Therefore, it is sufficient to directly list the class signature list in the search rule, which is referred to as R2.
[0080] like Figure 3 As shown, ClassB is a subclass of ClassA. ClassB inherits from the parent class ClassA and contains all the properties and methods of the parent class ClassA. ClassA and ClassB have an inheritance relationship.
[0081] For example, “R2”:[“Landroid / app / Activity;”, “Landroid / app / Service;”] means that all codes that inherit the Activity class and all codes that inherit the Service class will be reinforced.
[0082] (3) All method codes that overload the specified method need to be reinforced;
[0083] Similar to the retrieval rule R2 corresponding to the above-mentioned class code with inheritance relationship, the class signature can be replaced with the Method signature. The retrieval rule is recorded as R3.
[0084] For example, “R3”:[“Landroid / app / Activity;->onResume()V”, “Landroid / app / Service;->onDestroy()V”], this search rule indicates that all Activity onResume’s overridden method codes and all Service onDestroy’s overridden method codes will be hardened.
[0085] It should be noted that method overloading refers to calling different methods with the same method name based on different parameters provided. Differences in the number, order, and type of parameters can constitute overloading.
[0086] For example, Figure 4 As shown, assuming that the program code of an application includes class codes corresponding to three classes, namely ClassA, ClassB and ClassC, method2 in ClassA is based on method1 in ClassB, and method1 is modified to obtain the modified method1. Then ClassA contains the method code corresponding to the modified method1, which means that method2 in ClassA overloads method1 in ClassB.
[0087] At this time, in addition to determining the code in the modified method1 contained in ClassA that overloads method1 as the code to be reinforced, it is also necessary to determine the code in the modified method1 contained in ClassC that also overloads method1, and the code in method1 in ClassB as the code to be reinforced.
[0088] In other words, according to the above retrieval rule 3, all method codes that overload method1 in all classes are method codes that need to be reinforced.
[0089] (4) All method codes that call the specified method need to be hardened.
[0090] Combination Figure 3 The Method list corresponding to the Method structure in the code relationship diagram shown can be easily retrieved. The Method signature list can be listed in the rule, and the regular expression extension of the signature can be added to further adapt to the polymorphism of the Method. This retrieval rule is denoted as R4.
[0091] For example, "R4":["L.*;->encrypt1\(Ljava / lang / String;\)V","L.*;->encrypt2\(Ljava / lang / String;\)V"] means that all method codes that call encrypt1 and all method codes that call encrypt2 will be hardened.
[0092] For example, Figure 4 As shown, assuming that the program code of an application includes class codes corresponding to three classes, namely ClassA, ClassB and ClassC, and method2 in ClassA calls method1 in ClassB, then the code in method1 contained in ClassA, the code in method2 contained in ClassA and the code in method1 in ClassB are the retrieved codes that need to be reinforced.
[0093] In addition, if method3 in ClassC also calls method1 in ClassB, then the code in method1 contained in ClassC, the code in method3 contained in ClassC, and the code in method1 in ClassB are also retrieved codes that need to be reinforced.
[0094] According to the above four search rules, matching codes for reinforcement can almost meet all the needs of scope or special reinforcement. If the corresponding blacklist rules with similar definitions are added (referred to as B1, B2, B3, B4), the codes that do not need to be reinforced can be further filtered out, thus achieving the purpose of "determining the minimum set of codes that need to be reinforced".
[0095] Through the above method, the code that needs to be reinforced can be accurately located, the accuracy of the key code to be reinforced is improved, and the reinforcement efficiency of the program code is improved.
[0096] As an optional implementation, after retrieving a portion of the code to be reinforced according to the above set of retrieval rules, the above method further includes:
[0097] The first to-be-processed code subset, the second to-be-processed code subset, the third to-be-processed code subset and the fourth to-be-processed code subset are merged to obtain a to-be-processed code set.
[0098] After each code subset to be processed is determined according to the above set of search rules, each code subset to be processed is merged, and the merged code set is determined as the code set to be processed.
[0099] Obviously, in the embodiment of the present application, the above set of search rules is only an example and is not intended to be limiting.
[0100] For example, some of the rules in R1 to R4 are combined into another set of search rules, the codes to be reinforced are determined by using the other set of search rules, and the retrieved codes are merged to obtain the final code set to be reinforced.
[0101] As an optional example, the codes in the code set to be processed are reinforced to obtain a reinforced target application, including:
[0102] Compile a group of bytecode assembly files corresponding to the code set to be processed into M bytecode files, where M is a positive integer greater than or equal to 1, and the bytecode assembly files corresponding to the target application include a group of bytecode assembly files;
[0103] Perform reinforcement processing on the M bytecode files to obtain the reinforced M bytecode files;
[0104] Based on the hardened M bytecode files, a hardened target application is obtained.
[0105] The code set to be processed determined by a set of search rules corresponds to a set of bytecode assembly files (.smali files). The apktool tool in the above embodiment can also recompile the smali file list into a .dex file. Therefore, it is only necessary to map the code set to be processed after the above merge processing into a smali file list, move these files to a centralized directory, and use apktool to perform compilation to generate a new dex.
[0106] The elements in the code set are Class, Field, and Method. Replace Field and Method with the Class where the declaration is located, merge them with the existing Class in the code set, remove duplicates, and then convert the package name paths of the Class into smali file paths one by one, which can be mapped into a smali file list.
[0107] Move these smali files to a new summary directory so that the code can be removed from the original dex and a new .dex file (bytecode file) can be generated.
[0108] Since the maximum number of constant symbol references in dex is 64K, it is necessary to calculate the total number of all Class references (including String, Type, and Method) in the new directory after deduplication. Once it exceeds 64K, a new directory must be created to store the Class's smali files. Each summary directory will compile a new dex.
[0109] It should be noted that in the embodiment of the present application, the object of reinforcement is the new .dex file (bytecode file) compiled above, and the original dex file does not need to be unpacked and decrypted when running the application, which reduces the operation process and improves the operating efficiency of the reinforced target application.
[0110] Based on the hardened M bytecode files, the hardened target application is obtained, including:
[0111] Removing class codes having the same attributes in N bytecode files as those in M bytecode files, to obtain processed N bytecode files, wherein the N bytecode files are obtained by compiling bytecode assembly files corresponding to the target application, and N is a positive integer greater than or equal to M;
[0112] Based on the processed N bytecode files and the hardened M bytecode files, a hardened target application is obtained.
[0113] The N bytecode files obtained after compiling the bytecode assembly files corresponding to the target application contain complete program codes. However, since a small amount of key codes are retrieved through the above-mentioned set of retrieval rules and these key codes are reinforced, when using the reinforced M bytecode files and N bytecode files to obtain the reinforced application, it is necessary to remove the codes involved in the reinforcement processing in the original N bytecode files.
[0114] Specifically, class codes with the same attributes as those in the M bytecode files to be reinforced are found from the N bytecode files, and the found class codes are removed from the N bytecode files. Then, based on the processed N bytecode files and the reinforced M bytecode files, the reinforced target application is obtained.
[0115] Through the above method, it is possible to effectively avoid the class codes in the M bytecode files involved in the hardening process from being repeated in the N bytecode files.
[0116] As an optional implementation, the hardened target application is obtained based on the processed N bytecode files and the hardened M bytecode files, including:
[0117] The M bytecode files are encrypted and then dumped into a data area, and the hardened M bytecode files and the processed N bytecode files are merged, and the code in the merged bytecode file is determined as the hardened target application code.
[0118] Practical results show that when an APK with a size of 100M+ is reinforced using the technical solution of this application, while meeting all core code protection and security compliance requirements, only a dex file with a size of less than 8M needs to be reinforced, and the running time increases by an average of less than 150 milliseconds.
[0119] In order to more clearly understand the reinforcement method of the above application, the following Figure 5 The overall flow chart shown further describes it.
[0120] S502, decompile the bytecode file in the apk package to obtain a bytecode assembly file corresponding to the target application;
[0121] The bytecode file may be, but is not limited to, a .dex file, and the bytecode assembly file may be, but is not limited to, a .smai file.
[0122] S504, using a compilation tool to compile the bytecode assembly file into a corresponding bytecode file;
[0123] S506, generating a code relationship graph by parsing the class structure in the bytecode assembly file decompiled in step S502;
[0124] Among them, by parsing the class structure and the constants and calling method instructions in the bytecode file, the indexes and dependencies between the classes are established and mapped into Figure 3 The code relationship diagram shown.
[0125] S508, formulating a set of search rules according to the reinforcement requirements;
[0126] Among them, a set of retrieval rules can be but is not limited to determining the coverage of the code to be reinforced based on the reinforcement requirements. For example, all codes in the specified SDK package or Class need to be reinforced, and all class codes that inherit or implement the specified class need to be reinforced, etc. For details, please refer to the description in the above embodiment, which will not be repeated here.
[0127] It should be noted that, in addition to the above-mentioned search rules, the embodiment of the present application also proposes a set of blacklist rules B1, B2, B3, and B4 corresponding to the above-mentioned set of rules, and the blacklist rules are used to define codes that do not need to be reinforced.
[0128] After using the above set of retrieval rules to filter out the code that needs to be reinforced, a set of blacklist rules is used to eliminate the code that does not need to be reinforced from the initially screened code to be reinforced, so as to obtain the "minimum amount" of code to be reinforced, thereby improving the accuracy of locating the code that needs to be reinforced and improving the reinforcement efficiency.
[0129] S510, using the above search rules, obtaining a code set that needs to be reinforced;
[0130] The code set that needs to be reinforced corresponds to the .smai file, where: Figure 5 The codes in smai_classes 1 to smai_classes 3 are shown to include the codes in smai_classes 4 and smai_classes 5.
[0131] S512, compile the code set to be hardened to obtain compiled new bytecode files .dex4 and .dex5;
[0132] The codes in the above bytecode files .dex1 to .dex3 include all codes in the new bytecode files .dex4 and .dex5.
[0133] S514, encrypting the new bytecode files .dex4 and .dex5 to obtain encrypted data;
[0134] S516, obtaining the encrypted bytecode file;
[0135] S518, obtaining an encrypted application program according to the encrypted bytecode file and the original bytecode file.
[0136] In combination with the description in the above embodiment, it can be seen that since the code to be reinforced determined according to the above retrieval rules is part of the code from the original bytecode file, after the extracted part of the code is reinforced, it is necessary to first remove the code in the original bytecode file that is repeated with the part of the code involved in the reinforcement process to obtain the processed bytecode file.
[0137] The processed bytecode file and the encrypted bytecode file are then merged to obtain a code set in the hardened application.
[0138] Through the above-mentioned embodiments provided in the present application, the effect of encrypting the key code of the application can be achieved, avoiding the defect of low reinforcement efficiency caused by indiscriminate reinforcement of all codes in the related technology; at the same time, there is no need to shut down the virtual machine optimization as a whole or perform inefficient instruction translation.
[0139] In terms of product experience, it can enhance application security while maximizing application performance and stability.
[0140] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0141] According to another aspect of the embodiment of the present application, there is also provided Figure 6 A reinforcement device for an application as shown, the device comprising:
[0142] A first acquisition unit 602 is used to acquire a code relationship graph of a target application, wherein the code relationship graph includes reference relationships between classes in a bytecode assembly file corresponding to the target application;
[0143] A first processing unit 604 is used to generate a code search strategy based on the class code of each class, wherein the code search strategy includes a set of search rules generated by using the reference relationship between each class;
[0144] A second processing unit 606, configured to determine a code set to be processed from the bytecode assembly file based on a set of search rules;
[0145] The reinforcement unit 608 is used to reinforce the codes in the code set to be processed to obtain a reinforced target application.
[0146] Optionally, the first processing unit 604 includes:
[0147] A first processing module is used to determine at least part of the SDK packages from a group of SDK packages of the target application, and determine the codes in at least part of the SDK packages as a first subset of codes to be processed to be reinforced;
[0148] A second processing module is used to determine the class codes with inheritance relationship as the second to-be-processed code subset to be reinforced, wherein the relationship between the parent class and the child class with the same attributes and methods is determined as the inheritance relationship;
[0149] A third processing module is used to determine method codes in class codes having a calling relationship as a third to-be-processed code subset to be reinforced, wherein in the case where a method code is called from a first class code to a second class code through a method signature, the first class code and the second class code have a calling relationship;
[0150] The fourth processing module is used to determine the method code in the class code with an overloading relationship as a fourth subset of code to be processed to be reinforced, wherein the third class code and the fourth class code have an overloading relationship when the third class code inherits from the fourth class code and the designated method in the fourth class code is modified.
[0151] Optionally, the above device further includes:
[0152] The merging unit is used to merge the first code subset to be processed, the second code subset to be processed, the third code subset to be processed and the fourth code subset to be processed to obtain a code set to be processed.
[0153] Optionally, the reinforcement unit 608 includes:
[0154] A compiling module, used for compiling a group of bytecode assembly files corresponding to the code set to be processed into M bytecode files, wherein M is a positive integer greater than or equal to 1, and the bytecode assembly files corresponding to the target application program include a group of bytecode assembly files;
[0155] A reinforcement module, used for performing reinforcement processing on the M bytecode files to obtain the reinforced M bytecode files;
[0156] The fifth processing module is used to obtain a reinforced target application based on the M reinforced bytecode files.
[0157] Optionally, the fifth processing module includes:
[0158] The first processing submodule is used to remove class codes having the same attributes in the N bytecode files as those in the M bytecode files, and obtain N processed bytecode files, wherein the N bytecode files are obtained by compiling the bytecode assembly files corresponding to the target application, and N is a positive integer greater than or equal to M;
[0159] The second processing submodule is used to obtain a reinforced target application based on the processed N bytecode files and the reinforced M bytecode files.
[0160] Optionally, the above method further includes:
[0161] A second acquisition unit is used to acquire an APK application package of a target application, wherein the APK application package includes a group of bytecode files;
[0162] The third processing unit is used to decompile a group of bytecode files to obtain a bytecode assembly file corresponding to the target application.
[0163] Optionally, the third processing unit includes:
[0164] A parsing module is used to parse the data structure of each class in the bytecode assembly file corresponding to the target application and obtain the index relationship between each class;
[0165] The sixth processing module is used to generate a code relationship diagram based on the index relationship between each class.
[0166] By applying the above-mentioned device to the index relationship between each class in the bytecode assembly file corresponding to the application, and combining it with the reinforcement requirements, a set of retrieval rules are generated; a small amount of code that needs to be reinforced is determined from the bytecode assembly file according to the retrieval rules, thereby reinforcing the key code of the application, solving the problem of low reinforcement efficiency of program code in related technologies, achieving the technical effect of improving the reinforcement efficiency of the application, and improving the security of the program code.
[0167] It should be noted that the embodiments of the application reinforcement device here can refer to the embodiments of the application reinforcement method mentioned above, which will not be repeated here.
[0168] According to another aspect of the embodiment of the present application, an electronic device for implementing the reinforcement method of the above application is also provided. The electronic device may be Figure 1 The target terminal or server shown in FIG. This embodiment is described by taking the electronic device as the target terminal as an example. Figure 7 As shown, the electronic device includes a memory 702 and a processor 704. The memory 702 stores a computer program, and the processor 704 is configured to execute the steps in any of the above method embodiments through the computer program.
[0169] Optionally, in this embodiment, the electronic device may be located in at least one network device among a plurality of network devices of a computer network.
[0170] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0171] S1, obtaining a code relationship graph of a target application, wherein the code relationship graph includes reference relationships between classes in a bytecode assembly file corresponding to the target application;
[0172] S2, generating a code retrieval strategy based on the class code of each class, wherein the code retrieval strategy includes a set of retrieval rules generated by using the reference relationship between each class;
[0173] S3, based on a set of retrieval rules, determines the code set to be processed from the bytecode assembly file;
[0174] S4, strengthening the codes in the code set to be processed to obtain a strengthened target application.
[0175] Alternatively, a person skilled in the art may understand that: Figure 7 The structure shown is for illustration only. Figure 7 The electronic device and the electronic equipment described above are not limited in structure. Figure 7 More or fewer components (such as network interfaces, etc.) as shown in, or with Figure 7 Different configurations shown.
[0176] Among them, the memory 702 can be used to store software programs and modules, such as the program instructions / modules corresponding to the method and device for reinforcing the application in the embodiment of the present application. The processor 704 executes various functional applications and data processing by running the software programs and modules stored in the memory 702, that is, to implement the above-mentioned method for reinforcing the application. The memory 702 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 702 may further include a memory remotely located relative to the processor 704, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. Among them, the memory 702 may specifically be used, but is not limited to, for storing code relationship diagrams, a set of retrieval rules, and bytecode assembly files, etc. As an example, such as Figure 7 As shown, the memory 702 may include, but is not limited to, the first acquisition unit 602, the first processing unit 604, the second processing unit 606, and the reinforcement unit 608 in the reinforcement device of the application. In addition, other module units in the reinforcement device of the application may also be included but are not limited to, which will not be repeated in this example.
[0177] Optionally, the transmission device 706 is used to receive or send data via a network. Specific examples of the network may include a wired network and a wireless network. In one example, the transmission device 706 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers via a network cable so as to communicate with the Internet or a local area network. In one example, the transmission device 706 is a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0178] In addition, the electronic device further includes: a display 708 for displaying the screen after the hardened target application is run; and a connection bus 710 for connecting various module components in the electronic device.
[0179] In other embodiments, the target terminal or server may be a node in a distributed system, wherein the distributed system may be a blockchain system, and the blockchain system may be a distributed system formed by connecting the multiple nodes through network communication. The nodes may form a point-to-point network, and any form of computing device, such as a server, a target terminal or other electronic device, may become a node in the blockchain system by joining the point-to-point network.
[0180] According to another aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the application reinforcement method provided in various optional implementations of the above-mentioned server verification processing and other aspects, wherein the computer program is configured to execute the steps of any of the above-mentioned method embodiments when running.
[0181] Optionally, in this embodiment, the computer-readable storage medium may be configured to store a computer program for performing the following steps:
[0182] S1, obtaining a code relationship graph of a target application, wherein the code relationship graph includes reference relationships between classes in a bytecode assembly file corresponding to the target application;
[0183] S2, generating a code retrieval strategy based on the class code of each class, wherein the code retrieval strategy includes a set of retrieval rules generated by using the reference relationship between each class;
[0184] S3, based on a set of retrieval rules, determines the code set to be processed from the bytecode assembly file;
[0185] S4, strengthening the codes in the code set to be processed to obtain a strengthened target application.
[0186] Optionally, in the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0187] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing the hardware related to the target terminal through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.
[0188] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0189] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which can be personal computers, servers or network devices, etc.) to execute all or part of the steps of the methods of each embodiment of the present application.
[0190] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0191] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0192] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0193] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0194] The above are only preferred implementations of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for reinforcing an application, characterized in that: include: Obtaining a code relationship graph of a target application, wherein the code relationship graph includes reference relationships between classes in a bytecode assembly file corresponding to the target application; Based on the class codes of the various classes, a code search strategy is generated, wherein the code search strategy includes a set of search rules generated by using reference relationships between the various classes; Based on the set of search rules, determining a code set to be processed from the bytecode assembly file; The codes in the code set to be processed are reinforced to obtain a reinforced target application program.
2. The method according to claim 1, characterized in that The set of search rules includes at least one of the following: Determine at least part of the SDK packages from a group of SDK packages of the target application, and determine the codes in the at least part of the SDK packages as the first to-be-processed code subset to be reinforced; Determine the class code with inheritance relationship as the second to-be-processed code subset to be reinforced, wherein the relationship between the parent class and the child class with the same attributes and methods is determined as the inheritance relationship; Determine method codes in class codes having a calling relationship as a third subset of codes to be processed to be reinforced, wherein in the case where a method code is called from a first class code to a second class code through a method signature, the first class code and the second class code have the calling relationship; The method codes in the class codes having an overloading relationship are determined as a fourth subset of codes to be processed to be reinforced, wherein, when the third class code inherits from the fourth class code and the designated method in the fourth class code is modified, the third class code and the fourth class code have the overloading relationship.
3. The method according to claim 2, characterized in that The method further comprises: The first to-be-processed code subset, the second to-be-processed code subset, the third to-be-processed code subset and the fourth to-be-processed code subset are merged to obtain the to-be-processed code set.
4. The method according to claim 1, characterized in that: The step of performing reinforcement processing on the code in the code set to be processed to obtain a reinforced target application program includes: Compile a group of bytecode assembly files corresponding to the code set to be processed into M bytecode files, where M is a positive integer greater than or equal to 1, and the bytecode assembly files corresponding to the target application include the group of bytecode assembly files; Performing reinforcement processing on the M bytecode files to obtain reinforced M bytecode files; Based on the reinforced M bytecode files, the reinforced target application is obtained.
5. The method according to claim 4, characterized in that The step of obtaining the reinforced target application based on the reinforced M bytecode files comprises: Removing class codes having the same attributes as those in the M bytecode files from the N bytecode files to obtain processed N bytecode files, wherein the N bytecode files are obtained by compiling the bytecode assembly files corresponding to the target application, and N is a positive integer greater than or equal to M; Based on the processed N bytecode files and the reinforced M bytecode files, the reinforced target application is obtained.
6. The method according to any one of claims 1 to 5, characterized in that Before obtaining the code relationship graph of the target application, the method further includes: Obtaining an APK application package of the target application, wherein the APK application package includes a group of bytecode files; Decompile the set of bytecode files to obtain a bytecode assembly file corresponding to the target application.
7. The method according to claim 6, characterized in that After decompiling the set of bytecode files to obtain the bytecode assembly file corresponding to the target application, the method further includes: Parsing the data structure of each class in the bytecode assembly file corresponding to the target application to obtain the index relationship between the classes; The code relationship graph is generated based on the index relationship between the various classes.
8. A reinforcement device for an application, characterized in that: include: A first acquisition unit, configured to acquire a code relationship graph of a target application, wherein the code relationship graph includes reference relationships between classes in a bytecode assembly file corresponding to the target application; A first processing unit, configured to generate a code retrieval strategy based on the class codes of the various classes, wherein the code retrieval strategy includes a set of retrieval rules generated by using reference relationships between the various classes; A second processing unit, configured to determine a code set to be processed from the bytecode assembly file based on the set of search rules; The reinforcement unit is used to reinforce the codes in the code set to be processed to obtain a reinforced target application.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program can be executed by a terminal device or a computer to execute the method as claimed in any one of claims 1 to 7.
10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 7 through the computer program.
Citation Information
Patent Citations
Reinforcement method and device for executable file
CN106295327A
Method and device for security reinforcement of mobile application program
CN107977553A
Method, device and equipment for generating target function calling relation and medium
CN117806736A
JAVA code packing method and system
WO2021217980A1
Program protection device, program protection method, and program protection program
WO2022107295A1
