Code obfuscation configuration method and device, equipment and medium

By obtaining the target naming rule file and the configuration code obfuscation rule file, the obfuscation file is generated, which solves the problem of easy identification of code obfuscation in the existing technology and improves the security and difficulty of the program.

CN118779850APending Publication Date: 2024-10-15GUANGZHOU SANQIJICAI NETWORK TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410801718.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-20
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

Existing code obfuscation methods are easily recognized by decompilers, which weakens the security of the code. How to obfuscate and replace the object names in the code more covertly to improve the security of the program.

Method used

By obtaining the target naming rule file, including keywords of the target programming language, configure the code obfuscation rule file of the code obfuscation tool, and when receiving a packaging request, use these rules to generate an obfuscation file to reduce the ease of recognition of the object name.

Benefits of technology

It improves the security of the code, reduces the risk of decompilation, and makes the obfuscated code more difficult to identify and crack.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118779850A_ABST
    Figure CN118779850A_ABST
Patent Text Reader

Abstract

The invention discloses a code obfuscation configuration method and device, equipment and a medium, and belongs to the technical field of Internet. The method comprises the steps of obtaining a target naming rule file of a current project; wherein the target naming rule file comprises a keyword corresponding to target programming language information; configuring a code obfuscation rule file of a code obfuscation tool according to the target naming rule file; starting a code obfuscation function of the current project according to the code obfuscation rule file; and under the condition that a packaging request is received, executing a packaging command on a current project so as to control the code obfuscation tool to generate an obfuscation file according to the code obfuscation rule file. According to the technical scheme, the keywords corresponding to the programming language used by the current project are determined as the obfuscation replacement names which can be selected by the code obfuscation tool, so that the identifiability of the object names in the current project can be reduced, and the security of the program is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of Internet technology, and specifically relates to a code obfuscation configuration method, device, equipment and medium. Background Art

[0002] Code obfuscation is a software protection technology that can effectively hide the internal implementation details of a program by converting and modifying the program source code or bytecode, reducing the risk of code reverse engineering and plagiarism, thereby improving the security of the program. This is very important for protecting the intellectual property or trade secrets of software developers.

[0003] The currently commonly used code obfuscation method, such as simply replacing the object names in the code with letters a, b, c, etc., can increase the difficulty of understanding the code to a certain extent, but due to the obviousness and identifiability of these names, the obfuscated code is easier for decompilers to identify as obfuscated, thereby weakening the security of the code. Therefore, how to more covertly obfuscate and replace the object names in the code is a problem that people in this field need to solve urgently. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a code obfuscation configuration method, device, equipment and medium, the purpose of which is to reduce the recognizability of the names of objects in the current project and improve the security of the program.

[0005] In a first aspect, an embodiment of the present application provides a code obfuscation configuration method, the method comprising:

[0006] Obtain a target naming rule file for the current project; wherein the target naming rule file includes keywords corresponding to target programming language information;

[0007] Configuring the code obfuscation rule file of the code obfuscation tool according to the target naming rule file;

[0008] According to the code obfuscation rule file, enable the code obfuscation function of the current project;

[0009] When a packaging request is received, a packaging command is executed on the current project to control the code obfuscation tool to generate an obfuscated file according to the code obfuscation rule file.

[0010] In a second aspect, an embodiment of the present application provides a code obfuscation configuration device, the device comprising:

[0011] A naming rule acquisition module, used to acquire a target naming rule file of the current project; wherein the target naming rule file includes keywords corresponding to target programming language information;

[0012] An obfuscation rule configuration module, used to configure a code obfuscation rule file of a code obfuscation tool according to the target naming rule file;

[0013] An obfuscation function activation module is used to activate the code obfuscation function of the current project according to the code obfuscation rule file;

[0014] The obfuscation file generation module is used to execute a packaging command on the current project when a packaging request is received, so as to control the code obfuscation tool to generate an obfuscation file according to the code obfuscation rule file.

[0015] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the method described in the first aspect.

[0016] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0017] In a fifth aspect, an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the method described in the first aspect.

[0018] In an embodiment of the present application, a target naming rule file of the current project is obtained; wherein the target naming rule file includes keywords corresponding to the target programming language information; the code obfuscation rule file of the code obfuscation tool is configured according to the target naming rule file; according to the code obfuscation rule file, the code obfuscation function of the current project is enabled; upon receiving a packaging request, a packaging command is executed on the current project to control the code obfuscation tool to generate an obfuscated file according to the code obfuscation rule file. The above-mentioned code obfuscation configuration method can reduce the recognizability of the names of objects in the current project and improve the security of the program by determining the keywords corresponding to the programming language used by the current project as obfuscated replacement names that can be selected by the code obfuscation tool. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 It is a flowchart of the code obfuscation configuration method provided in Example 1 of the present application;

[0020] Figure 2 This is an example diagram of an obfuscated file list provided in Example 1 of the present application;

[0021] Figure 3This is an example diagram of the obfuscated file code provided in Example 1 of the present application;

[0022] Figure 4 It is a flowchart of the code obfuscation configuration method provided in Example 2 of the present application;

[0023] Figure 5 It is a flowchart of the code obfuscation configuration method provided in Example 3 of the present application;

[0024] Figure 6 It is a flowchart of the code obfuscation configuration method provided in Example 4 of the present application;

[0025] Figure 7 This is an example diagram of an abnormal error report of a project provided in Example 4 of the present application;

[0026] Figure 8 This is a flowchart of the ProGuard configuration method provided in Example 4 of the present application;

[0027] Fig. 9 It is a structural diagram of a code obfuscation configuration device provided in Embodiment 5 of the present application;

[0028] Fig.10 It is a structural diagram of an electronic device provided in Example 6 of the present application. DETAILED DESCRIPTION

[0029] In order to make the purpose, technical scheme and advantages of the present application clearer, the specific embodiments of the present application are further described in detail below in conjunction with the accompanying drawings. It is understood that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for the convenience of description, only the part related to the present application but not all the contents are shown in the accompanying drawings. Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow chart describes each operation (or step) as a sequential process, many of the operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of each operation can be rearranged. The process can be terminated when its operation is completed, but it can also have additional steps not included in the accompanying drawings. The process can correspond to a method, a function, a procedure, a subroutine, a subprogram, etc.

[0030] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.

[0031] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0032] The following, in conjunction with the accompanying drawings, describes in detail the code obfuscation configuration method, device, equipment and medium provided in the embodiments of the present application through specific embodiments and their application scenarios.

[0033] Embodiment 1

[0034] Figure 1 Schematic diagram of the code obfuscation configuration method provided in Example 1 of the present application. Figure 1 As shown, the specific steps include:

[0035] S101, obtaining a target naming rule file of the current project; wherein the target naming rule file includes keywords corresponding to target programming language information;

[0036] First of all, this application is applicable to scenarios where code obfuscation of the project is required. Based on the above usage scenarios, it can be understood that the execution subject of this application can be a project development platform. Specifically, the acquisition of the target naming rule file, the configuration of the code obfuscation rule file, and the activation of the code obfuscation function can be performed by the project development platform, and the generated obfuscated file is not easily recognized by the decompiler.

[0037] A project can be a series of codes developed to meet a business requirement or solve a practical problem. A project development platform can be a software tool or system that can provide support and management for the entire development life cycle of the current project. The target programming language information can be a project development platform suitable for the current project, and the type of computer program language that can be used to develop the current project. For example, if the current project is an Android software project, the project development platform can be an Android application development IDE (Integrated Development Environment), and the target programming language information can be Java or Kotlin, etc.

[0038] Code obfuscation is a software security technology that converts and modifies source code or compiled binary code to make it difficult to understand and reverse analyze the code, increasing the difficulty for decompilers to crack the software. The target naming rule file can refer to a file that is applicable to the current project and provides a name range for the code obfuscation function of the current project. The content of the target naming rule file consists of the keywords corresponding to the target compilation language information of the current project.

[0039] The keywords corresponding to the target programming language information may refer to reserved words with special meanings that are predefined in the target programming language. Specifically, keywords may define the basic grammatical structure of a programming language, such as loops, conditions, and variable declarations; keywords may describe key concepts and operations in a programming language; keywords may reflect the compilation or interpretation method of a programming language; and keywords may call functions provided by a standard library of a programming language.

[0040] The target naming rule file of the current project can be directly pre-built by the developers of the current project. Optionally, the method of obtaining the target naming rule file of the current project can also be to identify whether there is a naming rule file with non-empty content in the current project, and determine the naming rule file as the target naming rule file if it is identified as existing, or determine the target keyword set of the current project if it is identified as not existing, and generate the target naming rule file according to the target keyword set.

[0041] S102, configuring a code obfuscation rule file of a code obfuscation tool according to the target naming rule file;

[0042] A code obfuscation tool is a software tool used to perform obfuscation conversion on source code or compiled binary code. For example, if the target programming language information is Java or Kotlin, the code obfuscation tool can use ProGuard.

[0043] The code obfuscation rule file of the code obfuscation tool may be a configuration file for configuring the behavior of the code obfuscation tool, and includes a series of rules and instructions for instructing the code obfuscation tool on how to process and convert source code or compiled binary code.

[0044] The method of configuring the code obfuscation rule file of the code obfuscation tool according to the target naming rule file can be adopted by obtaining the target obfuscation object information, and setting the name range parameter of the target obfuscation object information to the target naming rule file in the code obfuscation rule file of the code obfuscation tool.

[0045] S103, enabling the code obfuscation function of the current project according to the code obfuscation rule file;

[0046] The code obfuscation function of the current project means that when the packaging command is executed on the current project, the code obfuscation tool can perform code obfuscation on each target obfuscation object in the current project.

[0047] To enable the code obfuscation function of the current project, you can turn on the code obfuscation switch in the build configuration file of the current project and specify the code obfuscation rule file as the configuration file of the code obfuscation tool. The build configuration file is a file used to define the build settings and dependencies of the project.

[0048] For example, if the current project is an Android software project and ProGuard is used as the obfuscation tool, the sample code for enabling the code obfuscation function of the current project is as follows:

[0049] android{

[0050] / / ……

[0051] buildTypes{

[0052] release{

[0053] debuggable true

[0054] minifyEnabled true

[0055] zipAlignEnabled true

[0056] proguardFilesetDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'

[0057] }

[0058] }

[0059] / / ……

[0060] }

[0061] Among them, minifyEnabled is the code obfuscation switch, minifyEnabled true means setting the code obfuscation switch to on, proguardFiles represents the ProGuard configuration file, and proguard-rules.pro is the code obfuscation rule file.

[0062] S104: When a packaging request is received, a packaging command is executed on the current project to control the code obfuscation tool to generate an obfuscated file according to the code obfuscation rule file.

[0063] The packaging request may be information sent by the developer to package the current project after the developer has completed the development of the current project. The packaging request can be received by monitoring the developer clicking the packaging button or other events that may indicate that the developer needs to package the current project.

[0064] The packaging command is a special build task that generates a release package for a project. The packaging command packages the compiled and obfuscated code and resource files into a distributable file format. The distributable file format is an obfuscated file, which can include .apk, .aar, and .jar files.

[0065] The way to execute the packaging command for the current project is to trigger the Gradle build tool to collect, package and optimize the build products of the current project. During the triggering and execution of the Gradle build tool, the code obfuscation tool is triggered to execute, and the name of the target obfuscated object is replaced with a keyword in the target naming rule file, and finally the obfuscated file is obtained. Among them, the Gradle build tool is a project automation build tool.

[0066] Figure 2 This is an example diagram of the obfuscated file list provided in Example 1 of this application. Figure 2 As shown, the name of each object in the obfuscated file list is a keyword.

[0067] Figure 3 This is an example diagram of the obfuscated file code provided in Example 1 of this application. Figure 3 As shown, the name of each object is a keyword, which is no different from the keywords that constitute the basic grammatical structure and the keywords used to call functions, and is not easily detected by the decompiler.

[0068] In an embodiment of the present application, a target naming rule file of the current project is obtained; wherein the target naming rule file includes keywords corresponding to the target programming language information; the code obfuscation rule file of the code obfuscation tool is configured according to the target naming rule file; according to the code obfuscation rule file, the code obfuscation function of the current project is enabled; upon receiving a packaging request, a packaging command is executed on the current project to control the code obfuscation tool to generate an obfuscated file according to the code obfuscation rule file. The above-mentioned code obfuscation configuration method can reduce the recognizability of the names of objects in the current project and improve the security of the program by determining the keywords corresponding to the programming language used by the current project as obfuscated replacement names that can be selected by the code obfuscation tool.

[0069] Embodiment 2

[0070] Figure 4This is a flowchart of the code obfuscation configuration method provided in Example 2 of the present application. This solution makes a better improvement on the above-mentioned embodiment, and the specific improvement is: obtaining the target naming rule file of the current project, including: identifying whether there is a naming rule file with non-empty content in the current project; if it is identified as existing, determining the naming rule file as the target naming rule file; if it is identified as not existing, determining the target keyword set of the current project, and generating the target naming rule file according to the target keyword set.

[0071] like Figure 4 As shown, the specific steps include:

[0072] S401, identifying whether there is a naming rule file with non-empty content in the current project; if so, executing S402; if not, executing S403;

[0073] By defining a task that can automatically generate a naming rule file in the build configuration file of the current project, the automatic generation of the naming rule file can be achieved. Among them, task refers to a work unit to be executed during the project build process, and the task that can automatically generate a naming rule file can be named generateConfuseFile.

[0074] The naming rule file whose content is not empty can be a naming rule file automatically generated before the current packaging command of the current project is executed if the packaging command is executed. The naming rule file can be defined as confuseName.txt.

[0075] Check whether there is confuseName.txt in the root directory of the current project. If there is confuseName.txt, identify whether the file content of confuseName.txt is empty. If it is empty, identify it as existing, otherwise identify it as not existing.

[0076] The following is a sample code for identifying whether a naming rule file confuseName.txt with non-empty content already exists in the current project:

[0077] def confuseFile=new File(project.projectDir,'confuseName.txt')

[0078] if(confuseFile.exists()&&confuseFile.length()>0){

[0079] return

[0080] }

[0081] Among them, project.projectDir indicates the root directory of the current project, confuseFile is a naming rule file object, confuseFile.exists() is used to identify whether confuseName.txt exists, confuseFile.length()>0 is used to identify whether the file content of confuseName.txt is empty, and the content of generateConfuseFile can include the sample code.

[0082] S402, determining the naming rule file as a target naming rule file;

[0083] If it is recognized as existing, since the existing naming rule file whose content is not empty is also automatically generated according to the keywords corresponding to the target programming language information of the current project, it is also applicable to this packaging command. Therefore, the naming rule file can be directly used as the target naming rule file of this packaging command.

[0084] S403, determining a target keyword set of the current project, and generating a target naming rule file according to the target keyword set;

[0085] If it is identified as not existing, the execution of this packaging command lacks the target naming rule file and needs to be automatically generated.

[0086] The target keyword set may refer to a set consisting of various keywords that may exist in the current project. The target keyword set of the current project may be determined by obtaining at least one target programming language information of the current project, determining a keyword set consisting of keywords corresponding to each target programming language information, and determining the intersection of each keyword set as the target keyword set.

[0087] The target naming rule file is generated according to the target keyword set by generating a blank document file, writing the target keyword set into the blank document file, and obtaining the target naming rule file.

[0088] In this technical solution, optionally, determining a target keyword set for the current project includes:

[0089] Get at least one target programming language information of the current project;

[0090] Determine a keyword set consisting of keywords corresponding to each target programming language information;

[0091] The intersection of each keyword set is determined as the target keyword set.

[0092] The target programming language information of the current project can be obtained by reading a configuration file or a description file of a project development platform of the current project.

[0093] The keyword set consisting of the keywords corresponding to each programming language information can be pre-set according to the programming language and stored in association. Accordingly, by querying the associated stored data with a target programming language information as the query condition, the query result obtained is the keyword set consisting of the keywords corresponding to the target programming language information.

[0094] The keywords in the intersection of each keyword set are the keywords common to each keyword set. By using the intersection operation of the set, such as the intersection() method, the intersection of each keyword set can be determined as the target keyword set.

[0095] The advantage of this setting of the present invention is that by using the intersection of the keyword sets consisting of the keywords corresponding to the target programming language information as the target keyword set, it is possible to avoid the appearance of keywords that are impossible to exist in the current project code in the generated obfuscated file, thereby increasing the difficulty of deciphering the obfuscated file.

[0096] S404, configuring a code obfuscation rule file of a code obfuscation tool according to the target naming rule file;

[0097] By configuring generateConfuseFile as a dependency of the packaging command before executing the packaging command for the current project, you can automatically execute the content of generateConfuseFile before executing the packaging command for the current project, that is, automatically generate a naming rule file. The sample code is as follows:

[0098] tasks.named('assemble').configure{

[0099] dependsOn(generateConfuseFile)

[0100] Among them, assemble represents the packaging task, the dependsOn() method can be configured as a dependency, and generateConfuseFile is a task for automatically generating a naming rule file.

[0101] S405, enabling the code obfuscation function of the current project according to the code obfuscation rule file;

[0102] S406: When a packaging request is received, a packaging command is executed on the current project to control the code obfuscation tool to generate an obfuscated file according to the code obfuscation rule file.

[0103] The benefit of this setting of the scheme is that by identifying whether there is a naming rule file with non-empty content in the current project, it is possible to avoid repeated generation of naming rule files, improve efficiency, and ensure that the same naming rule file is used for each packaging command execution of a project, which facilitates the troubleshooting of packaging problems.

[0104] Embodiment 3

[0105] Figure 5 This is a flowchart of the code obfuscation configuration method provided in Example 3 of the present application. This solution makes a better improvement on the above-mentioned embodiment, and the specific improvement is: generating a target naming rule file according to the target keyword set, including: generating a blank document file; writing the target keyword set into the blank document file to obtain a target naming rule file.

[0106] like Figure 5 As shown, the specific steps include:

[0107] S501, identifying whether there is a naming rule file with non-empty content in the current project; if so, executing S502; if not, executing S503;

[0108] S502, determining the naming rule file as a target naming rule file;

[0109] S503, determining a target keyword set for the current project;

[0110] S504, generating a blank document file;

[0111] A blank document file may refer to a txt format file with empty content.

[0112] In the sample code for identifying whether there is a naming rule file confuseName.txt with non-empty content in the current project, a naming rule file object confuseFile has been defined to store the obtained naming rule file with non-empty content. If there is no naming rule file with non-empty content, the naming rule file object confuseFile itself is a blank document file.

[0113] S505, writing the target keyword set into the blank document file to obtain a target naming rule file;

[0114] The target naming rule file can be obtained by directly integrating the target keyword set into a list and writing it into a blank document file to obtain the target naming rule file. Optionally, the target naming rule file can also be obtained by sorting the keywords in the target keyword set in alphabetical order to obtain an ordered keyword list, obtaining the current timestamp information and randomly sorting the ordered keyword list according to the timestamp information to obtain the target keyword list, and writing the target keyword list into a blank document file to obtain the target naming rule file.

[0115] In this technical solution, optionally, the target keyword set is written into the blank document file to obtain a target naming rule file, including:

[0116] Sort the keywords in the target keyword set in alphabetical order to obtain an ordered keyword list;

[0117] Acquire current timestamp information, and randomly sort the ordered keyword list according to the timestamp information to obtain a target keyword list;

[0118] The target keyword list is written into the blank document file to obtain a target naming rule file.

[0119] The alphabetical order may refer to the order in which letters are arranged in the alphabet. The method of sorting the keywords in the target keyword set in alphabetical order may be to compare any two keywords in the target keyword set, and place the keyword with the first letter in the alphabetical order before the keyword with the first letter in the alphabetical order, and if the first letters of the two keywords are the same, then compare the second letters, and so on, until different letters are found, and finally obtain a permutation list of the keywords, which is an ordered keyword list.

[0120] The following is a sample code that sorts the keywords in the target keyword set in alphabetical order to obtain an ordered keyword list:

[0121] def keywords=["import","extends","class","interface","enum","super","this","public","protected","private","new","static","final","try","catch","finally","return","void","String","boolean","true","false"]

[0122] def sortedKeywords=keywords.sort{a,b->

[0123] return a.compareToIgnoreCase(b)

[0124] Among them, keywords is the target keyword set; sortedKeywords is an ordered keyword list; a and b are closure parameters, representing two adjacent elements in the list; the compareToIgnoreCase() method compares the alphabetical order of a and b; the content of generateConfuseFile can include the sample code.

[0125] Timestamp information can refer to the length of time that has passed since a specific time (such as 00:00:00 Greenwich time on January 1, 1970), usually in seconds or milliseconds. The current timestamp information can refer to the length of time between the current time and the specific time. The project development platform generally provides a method for obtaining the current timestamp information, and the current timestamp information can be obtained by calling this method.

[0126] Randomly sorting the ordered keyword list according to the timestamp information means randomly sorting the ordered keyword list with the timestamp information as the random seed, and the sorting result is the target keyword list. The following is a sample code for randomly sorting the ordered keyword list according to the current timestamp information to obtain the target keyword list:

[0127] Random random=new Random(System.currentTimeMillis())

[0128] Collections.shuffle(sortedKeywords,random)

[0129] Among them, random is a random seed object, the System.currentTimeMillis() method can return the current system time, the Collections.shuffle() method randomly sorts the sortedKeywords, and the sorted sortedKeywords is the target keyword list. The content of generateConfuseFile can include the sample code.

[0130] The following is a sample code that writes the target keyword list into a blank document file to obtain the target naming rule file:

[0131] confuseFile.text=sortedKeywords.join(System.lineSeparator())

[0132] Among them, confuseFile is a naming rule file object, which becomes the target naming rule file after assignment; confuseFile.text represents the file content of confuseFile; the join() method connects all elements of sortedKeywords into a string; the System.lineSeparator() method can return the line separator of the current operating system; the content of generateConfuseFile can include the sample code.

[0133] The benefit of this setting is that by using the current timestamp information as a random seed to randomly sort the keywords sorted in alphabetical order, the uniqueness of the target keyword list can be ensured, so that the names of the obfuscated target obfuscated objects are unique, ensuring that the obfuscated code will not conflict due to names.

[0134] S506, configuring a code obfuscation rule file of a code obfuscation tool according to the target naming rule file;

[0135] S507, enabling the code obfuscation function of the current project according to the code obfuscation rule file;

[0136] S508: When a packaging request is received, a packaging command is executed on the current project to control the code obfuscation tool to generate an obfuscated file according to the code obfuscation rule file.

[0137] The benefit of this arrangement of the scheme is that by writing the target keyword set into a blank document file to obtain a target naming rule file, it is easy to pass the name selection range to the code obfuscation tool, thereby improving efficiency.

[0138] Embodiment 4

[0139] Figure 6 This is a flowchart of the code obfuscation configuration method provided in Example 4 of the present application. This solution makes better improvements to the above-mentioned embodiments, and the specific improvements are: configuring the code obfuscation rule file of the code obfuscation tool according to the target naming rule file, including: obtaining target obfuscation object information; in the code obfuscation rule file of the code obfuscation tool, setting the name range parameter of the target obfuscation object information to the target naming rule file.

[0140] like Figure 6 As shown, the specific steps include:

[0141] S601, obtaining a target naming rule file of the current project; wherein the target naming rule file includes keywords corresponding to target programming language information;

[0142] S602, obtaining target obfuscation object information;

[0143] The target obfuscation object information may refer to an object whose name needs to be obfuscated and replaced, and may include a package, a class, a method, and a member variable, etc. The target obfuscation object information may be set by a developer.

[0144] S603, in the code obfuscation rule file of the code obfuscation tool, setting the name range parameter of the target obfuscation object information to the target naming rule file;

[0145] The name range parameter of the target obfuscation object information may be a parameter used to provide a replaceable name of the target obfuscation object to a code obfuscation tool.

[0146] The following is a sample code for setting the name range parameter of the target obfuscation object information to the target naming rule file:

[0147] -packageobfuscationdictionary confuseName.txt

[0148] -classobfuscationdictionary confuseName.txt

[0149] -obfuscationdictionary confuseName.txt

[0150] Among them, confuseName.txt is the target naming rule file, packageobfuscationdictionary is the scope parameter for the package name, classobfuscationdictionary is the scope parameter for the class name, and obfuscationdictionary is the scope parameter for the method and member variable names.

[0151] In the technical solution, optionally, after setting the name range parameter of the target obfuscation object information to the target naming rule file, the method further includes:

[0152] In the code obfuscation rule file of the code obfuscation tool, the source file name and line number information are determined as obfuscation retention objects.

[0153] The source file name may refer to the original name of the target obfuscated object; the line number information may refer to the line number position of the error object in the code. The obfuscated reserved object may refer to the object that is retained without obfuscation, and the information of the obfuscated reserved object displayed is the information before obfuscation.

[0154] The following is a sample code for identifying source file names and line number information as obfuscation-preserved objects:

[0155] keepattributes SourceFile,LineNumberTable

[0156] Among them, keepattributes is a directive used to specify which Java bytecode attributes should be retained when optimizing, obfuscating, or shrinking the APK; SourceFile is the source file name; LineNumberTable is the line number information.

[0157] Figure 7 This is an example diagram of an abnormal error report for a project provided in Example 4 of this application. Figure 7 As shown, the exception stack log shows that a null pointer exception occurs when the equalesIgnoreCase method is called in line 70 of the ApkInfoUtil class. The complete obfuscated class name of the ApkInfoUtil class is: class.class.class.class.import.class.class.

[0158] The benefit of this setting is that by determining the source file name and line number information as obfuscation retention objects, it is easy for developers to troubleshoot code exceptions.

[0159] S604, enabling the code obfuscation function of the current project according to the code obfuscation rule file;

[0160] S605: When a packaging request is received, a packaging command is executed on the current project to control the code obfuscation tool to generate an obfuscated file according to the code obfuscation rule file.

[0161] Figure 8 : is a flowchart of the ProGuard configuration method provided in Example 4 of the present application. Figure 8As shown, first create the task generateConfuseFile in the build.gradle of the current project to automatically generate the obfuscation naming rule file confuseName.txt; configure confuseName.txt as the obfuscation dictionary in proguard-rules.pro, and retain the source file name and line number information, where proguard-rules.pro is the code obfuscation rule file, and the obfuscation dictionary is the name range parameter; configure build.gradle, that is, turn on the code obfuscation switch of the current project, and determine proguard-rules.pro as the configuration file of the code obfuscation tool; finally, execute the packaging command to generate the obfuscated file.

[0162] The advantage of this arrangement of the present solution is that, by setting the name range parameter of the target obfuscation object information to the target naming rule file, the code obfuscation tool can be controlled to only obfuscate the name of the target obfuscation object, providing a personalized obfuscation mechanism.

[0163] Embodiment 5

[0164] Fig. 9 Schematic diagram of the structure of the code obfuscation configuration device provided in Example 5 of the present application. Fig. 9 As shown, the device comprises:

[0165] The naming rule acquisition module 910 is used to acquire a target naming rule file of the current project; wherein the target naming rule file includes keywords corresponding to target programming language information;

[0166] The obfuscation rule configuration module 920 is used to configure the code obfuscation rule file of the code obfuscation tool according to the target naming rule file;

[0167] The obfuscation function activation module 930 is used to activate the code obfuscation function of the current project according to the code obfuscation rule file;

[0168] The obfuscation file generation module 940 is used to execute a packaging command on the current project when a packaging request is received, so as to control the code obfuscation tool to generate an obfuscation file according to the code obfuscation rule file.

[0169] In an embodiment of the present application, a naming rule acquisition module is used to obtain a target naming rule file of the current project; wherein the target naming rule file includes keywords corresponding to the target programming language information; an obfuscation rule configuration module is used to configure the code obfuscation rule file of the code obfuscation tool according to the target naming rule file; an obfuscation function activation module is used to activate the code obfuscation function of the current project according to the code obfuscation rule file; an obfuscation file generation module is used to execute a packaging command on the current project upon receiving a packaging request, so as to control the code obfuscation tool to generate an obfuscation file according to the code obfuscation rule file. The above-mentioned code obfuscation configuration device can reduce the recognizability of the names of various objects in the current project and improve the security of the program by determining the keywords corresponding to the programming language used by the current project as obfuscated replacement names that can be selected by the code obfuscation tool.

[0170] The code obfuscation configuration device in the embodiment of the present application can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, an in-vehicle electronic device, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.

[0171] The code obfuscation configuration device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an IOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.

[0172] The code obfuscation configuration device provided in the embodiment of the present application can implement each process implemented in the above-mentioned embodiments one to four, and will not be described again here to avoid repetition.

[0173] Embodiment 6

[0174] like Fig.10As shown, an embodiment of the present application also provides an electronic device 1000, including a processor 1001, a memory 1002, and a program or instruction stored in the memory 1002 and executable on the processor 1001. When the program or instruction is executed by the processor 1001, each process of the above-mentioned code obfuscation configuration method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0175] It should be noted that the electronic devices in the embodiments of the present application include the mobile electronic devices and non-mobile electronic devices mentioned above.

[0176] Embodiment 7

[0177] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above-mentioned code obfuscation configuration method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0178] The processor is a processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0179] Embodiment 8

[0180] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned code obfuscation configuration method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0181] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.

[0182] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0183] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0184] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.

[0185] The above are only preferred embodiments of the present application and the technical principles used. The present application is not limited to the specific embodiments described herein, and various obvious changes, readjustments and substitutions that can be made by those skilled in the art will not deviate from the scope of protection of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the claims.

Claims

1. A code obfuscation configuration method, characterized in that: The method comprises: Obtain a target naming rule file for the current project; wherein the target naming rule file includes keywords corresponding to target programming language information; Configuring the code obfuscation rule file of the code obfuscation tool according to the target naming rule file; According to the code obfuscation rule file, enable the code obfuscation function of the current project; When a packaging request is received, a packaging command is executed on the current project to control the code obfuscation tool to generate an obfuscated file according to the code obfuscation rule file.

2. The code obfuscation configuration method according to claim 1, characterized in that: Get the target naming rule file of the current project, including: Identify whether there is a naming rule file with non-empty content in the current project; If it is identified as existing, the naming rule file is determined as the target naming rule file; If it is identified as not existing, a target keyword set of the current project is determined, and a target naming rule file is generated according to the target keyword set.

3. The code obfuscation configuration method according to claim 2, characterized in that: Determine the target keyword set for the current project, including: Get at least one target programming language information of the current project; Determine a keyword set consisting of keywords corresponding to each target programming language information; The intersection of each keyword set is determined as the target keyword set.

4. The code obfuscation configuration method according to claim 2, characterized in that: Generating a target naming rule file according to the target keyword set includes: Generate a blank document file; The target keyword set is written into the blank document file to obtain a target naming rule file.

5. The code obfuscation configuration method according to claim 4, characterized in that: The target keyword set is written into the blank document file to obtain a target naming rule file, including: Sort the keywords in the target keyword set in alphabetical order to obtain an ordered keyword list; Acquire current timestamp information, and randomly sort the ordered keyword list according to the timestamp information to obtain a target keyword list; The target keyword list is written into the blank document file to obtain a target naming rule file.

6. The code obfuscation configuration method according to claim 1, characterized in that: The code obfuscation rule file of the code obfuscation tool is configured according to the target naming rule file, including: Obtain target obfuscated object information; In the code obfuscation rule file of the code obfuscation tool, the name range parameter of the target obfuscation object information is set to the target naming rule file.

7. The code obfuscation configuration method according to claim 6, characterized in that: After setting the name range parameter of the target obfuscation object information to the target naming rule file, the method further includes: In the code obfuscation rule file of the code obfuscation tool, the source file name and line number information are determined as obfuscation retention objects.

8. A code obfuscation configuration device, characterized in that: The device comprises: A naming rule acquisition module, used to acquire a target naming rule file of the current project; wherein the target naming rule file includes keywords corresponding to target programming language information; An obfuscation rule configuration module, used to configure a code obfuscation rule file of a code obfuscation tool according to the target naming rule file; An obfuscation function activation module is used to activate the code obfuscation function of the current project according to the code obfuscation rule file; The obfuscation file generation module is used to execute a packaging command on the current project when a packaging request is received, so as to control the code obfuscation tool to generate an obfuscation file according to the code obfuscation rule file.

9. An electronic device, characterized in that: The method comprises a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the code obfuscation configuration method as described in any one of claims 1 to 7.

10. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the steps of the code obfuscation configuration method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Code obfuscation method and device

    CN118981756A

  • Code obfuscation method and device, equipment and storage medium

    CN119808034A