Code obfuscation method and device, equipment and storage medium

By performing multi-level code obfuscation on the original bytecode files of the application source code, the problem of degradation of code invasiveness and maintainability in the prior art is solved, and higher code security and resistance are achieved.

CN119808034APending Publication Date: 2025-04-11INDUSTRIAL AND COMMERCIAL BANK OF CHINA

Patent Information

Application Number
CN202411890148.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-20
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

While existing code obfuscation solutions increase code complexity and obfuscation, they have problems of deteriorating code invasiveness and maintainability, making it difficult to effectively resist the risk of decompilation.

Method used

By obtaining the original bytecode file of the application source code, identifying and obfuscating data to be renamed, reorganizing the control flow, and obfuscating the method, multi-level and multi-faceted obfuscated files are formed, and the code resistance is enhanced.

Benefits of technology

It realizes multi-level code obfuscation of application source code, enhances code security and resistance, reduces decompilation risks, and improves code maintainability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119808034A_ABST
    Figure CN119808034A_ABST
Patent Text Reader

Abstract

The invention discloses a code obfuscation method, device and equipment and a storage medium, and belongs to the field of financial science and technology, and the method comprises the steps: obtaining an original byte code file corresponding to an application program source code; identifying to-be-confused data in the original byte code file, and confusing and renaming the to-be-confused data according to a mapping name of the to-be-confused data in the naming mapping table to obtain a first confused file corresponding to the original byte code file; identifying a control flow in the first confusion file, and performing confusion recombination on the identified control flow to obtain a second confusion file; and performing confusion processing on methods contained in various types in the second confusion file to obtain a target confusion file. According to the method, the maintainability and the resistance of the application program source code are enhanced, the risk that the application program source code is decompiled is reduced, the safety of the application program source code is improved, and then the safety of the application program is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of financial technology, and in particular to a code obfuscation method, device, equipment and storage medium. Background Art

[0002] In application development, source code is usually compiled into bytecode files, which can run on different platforms. However, since application source code in bytecode files is relatively easy to decompile, developers and organizations have higher requirements for the security of application source code.

[0003] Traditional code obfuscation solutions usually involve variable renaming with fixed rules. Although this can increase the complexity and obfuscation of the code to a certain extent, it also has some disadvantages. For example, the control flow in the code cannot be automatically added with noise, and even requires invasive programming of the code, which reduces the maintainability of the code. Summary of the invention

[0004] The present invention provides a code obfuscation method, apparatus, device and storage medium to enhance the maintainability and resistance of application source code, reduce the risk of application source code being decompiled, improve the security of application source code, and thus improve the security of the application.

[0005] According to one aspect of the present invention, a code obfuscation method is provided, the method comprising:

[0006] Get the original bytecode file corresponding to the application source code;

[0007] Identify the data to be obfuscated in the original bytecode file, and perform obfuscated renaming on the data to be obfuscated according to the mapping name of the data to be obfuscated in the naming mapping table, to obtain a first obfuscated file corresponding to the original bytecode file;

[0008] Identify the control flow in the first obfuscated file, and perform obfuscation and reorganization on the identified control flow to obtain a second obfuscated file;

[0009] The methods contained in each category in the second obfuscated file are obfuscated to obtain a target obfuscated file.

[0010] According to another aspect of the present invention, a code obfuscation device is provided, the device comprising:

[0011] The original bytecode file acquisition module is used to obtain the original bytecode file corresponding to the application source code;

[0012] A first obfuscated file determination module is used to identify the data to be obfuscated in the original bytecode file, and perform obfuscated renaming on the data to be obfuscated according to the mapping name of the data to be obfuscated in the naming mapping table, so as to obtain a first obfuscated file corresponding to the original bytecode file;

[0013] A second obfuscated file determination module is used to identify the control flow in the first obfuscated file and perform obfuscation and reorganization on the identified control flow to obtain a second obfuscated file;

[0014] The target obfuscation file determination module is used to perform obfuscation processing on the methods contained in each category in the second obfuscation file to obtain a target obfuscation file.

[0015] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0016] at least one processor; and

[0017] a memory communicatively connected to at least one processor; wherein,

[0018] The memory stores a computer program that can be executed by at least one processor. The computer program is executed by at least one processor so that the at least one processor can execute the code obfuscation method of any embodiment of the present invention.

[0019] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to implement the code obfuscation method of any embodiment of the present invention when executed by a processor.

[0020] According to another aspect of the present invention, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the code obfuscation method of any embodiment of the present invention is implemented.

[0021] The technical solution of the embodiment of the present invention obtains the original bytecode file corresponding to the application source code; identifies the data to be obfuscated in the original bytecode file, and according to the mapping name of the data to be obfuscated in the naming mapping table, performs obfuscated renaming on the obfuscated data to obtain the first obfuscated file corresponding to the original bytecode file; identifies the control flow in the first obfuscated file, and performs obfuscated reorganization on the identified control flow to obtain the second obfuscated file; performs obfuscated processing on the methods contained in each category in the second obfuscated file to obtain the target obfuscated file. The above technical solution obtains the first obfuscated file by performing naming obfuscation on the data to be obfuscated in the original bytecode file; then, obtains the second obfuscated file by performing obfuscated reorganization on the control flow in the first obfuscated file; then, obtains the target obfuscated file by performing obfuscated processing on the methods contained in each category in the second obfuscated file. The multi-level and multi-faceted code obfuscation of the original bytecode file corresponding to the application source code is realized, the code obfuscation degree of the original bytecode file is enhanced, the resistance of the application source code is enhanced, and the risk of the application source code being decompiled is reduced, thereby improving the security of the application source code, and then improving the security of the application; at the same time, there is no need for manual participation in the obfuscation of the control flow in the application source code, thereby enhancing the maintainability of the application source code.

[0022] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0024] Figure 1 is a flowchart of a code obfuscation method provided according to Embodiment 1 of the present invention;

[0025] Figure 2 is a flowchart of a code obfuscation method provided according to Embodiment 2 of the present invention;

[0026] Figure 3 2 is a schematic diagram of the structure of a code obfuscation device provided according to Embodiment 3 of the present invention;

[0027] Figure 4 It is a structural schematic diagram of an electronic device for implementing the code obfuscation method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0028] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0029] It should be noted that the terms "target", "original", "first" and "second" in the specification and claims of the present invention 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 invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0030] In addition, it should be noted that the collection, storage, use, processing, transmission, provision and disclosure of the naming mapping tables and naming mapping rule tables involved in the technical solution of the present invention are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0031] Embodiment 1

[0032] Figure 1 This is a flowchart of a code obfuscation method provided in the first embodiment of the present invention. This embodiment can be applied to the case of ensuring the security of application source code, especially to the case of ensuring the security of Java application source code. The method can be executed by a code obfuscation device, which can be implemented in the form of hardware and / or software and can be configured in an electronic device. Figure 1 As shown, the method includes:

[0033] S101. Obtain an original bytecode file corresponding to an application source code.

[0034] Among them, an application refers to a computer program for completing one or more specific tasks. The application source code refers to the uncompiled text file corresponding to the application that is written in accordance with a certain programming language specification; optionally, the application source code can be a Java application source code. The original bytecode file refers to the file obtained after the application source code is processed by the compiler. For example, the original bytecode file corresponding to the Java application source code is a .class file, and the original bytecode file corresponding to the Python application source code is a .pyc file.

[0035] Specifically, the original bytecode file corresponding to the application source code can be obtained from the specified file system through a bytecode processing tool. The bytecode processing tool refers to a tool used to read, analyze and modify bytecode files; optionally, the bytecode processing tool can be determined according to the programming language of the original bytecode file. For example, if the programming language of the original bytecode file is Java, the bytecode processing tool can be ASM (ObjectWeb ASM). ASM is a lightweight open source application framework for Java bytecode analysis, creation and modification. It can dynamically generate stub classes or other proxy classes in binary format, or dynamically modify classes before the classes are loaded into memory by the JAVA virtual machine.

[0036] S102: Identify the data to be obfuscated in the original bytecode file, and perform obfuscated renaming on the data to be obfuscated according to the mapping name of the data to be obfuscated in the naming mapping table, to obtain a first obfuscated file corresponding to the original bytecode file.

[0037] Among them, the data to be obfuscated refers to the data in the original bytecode file that needs to be obfuscated; optionally, the data to be obfuscated is the class name, variable name or method name in the original bytecode file. In this way, the data that needs to be obfuscated and renamed in the original bytecode file is clarified. The naming mapping table refers to a data table used to store the original name and mapping name of all data in the original bytecode file. Among them, the original name of the data refers to the actual name of the data in the source code of the application. It should be noted that the naming mapping table includes but is not limited to the following fields: data identifier, fully qualified class name, attribute type, original name of the data and mapping name. Among them, the data identifier is used to uniquely identify a data, for example, the data identifier can be a data ID (unique number, Identity document); the fully qualified class name refers to the complete class name including registration; the attribute type includes class name, variable name and method name. The first obfuscated file refers to the bytecode file obtained after the obfuscated and renamed data to be obfuscated in the original bytecode file.

[0038] Specifically, the original bytecode file can be parsed by the parsing unit in the bytecode processing tool to obtain the first parsed file; then, the attribute identification unit in the bytecode processing tool identifies the data to be obfuscated in the first parsed file starting from the head of the first parsed file, and when the data to be obfuscated is identified, the original data name of the identified data to be obfuscated is used as an index to obtain the mapping name of the data to be obfuscated from the naming mapping table; then, the original data name of the data to be obfuscated is replaced with the mapping name until the end of the first parsed file is identified, and the obfuscated renaming of all the data to be obfuscated in the original bytecode file is completed, thereby obtaining the first obfuscated file corresponding to the original bytecode file. Among them, the first parsed file refers to the file obtained after the original bytecode file is parsed by the parsing unit in the bytecode processing tool, which is used to record the abstract representation of the bytecode in the original bytecode file.

[0039] Optionally, the process of generating the mapping name of the data to be obfuscated in the naming mapping table is as follows: according to the target attribute type of the data to be obfuscated, based on the correspondence between the attribute type and the data naming mapping rule in the naming mapping rule table, determine the target naming mapping rule corresponding to the data to be obfuscated from the candidate naming mapping rules in the naming mapping rule table; based on the target naming mapping rule, rename the data to be obfuscated to obtain the mapping name of the data to be obfuscated in the naming mapping table.

[0040] The target attribute type refers to the attribute type of the data to be obfuscated; optionally, the target attribute type may be a class name, a variable name, or a method name. The naming mapping rule table refers to a data table for storing pre-defined data naming mapping rules. The candidate naming mapping rule refers to the data naming mapping rule stored in the naming mapping rule table.

[0041] Specifically, taking the target attribute type of the data to be obfuscated as an index, based on the correspondence between the attribute type and the data naming mapping rule in the naming mapping rule table, determine the candidate naming mapping rule corresponding to the target attribute type from the candidate naming mapping rules in the naming mapping rule table, and use it as the target naming mapping rule corresponding to the data to be obfuscated; according to the target naming mapping rule, rename the data to be obfuscated to obtain the mapping name of the data to be obfuscated in the naming mapping table.

[0042] It can be understood that, according to the target attribute type of the data to be obfuscated, based on the correspondence between the attribute type and the data naming mapping rule in the naming mapping rule table, the target naming mapping rule corresponding to the data to be obfuscated is determined from the candidate naming mapping rules in the naming mapping rule table; based on the target naming mapping rule, the data to be obfuscated is renamed to obtain the mapping name of the data to be obfuscated in the naming mapping table, so that the data to be obfuscated can generate the mapping name of the data to be obfuscated in the naming mapping table according to the clear data naming mapping rule, thereby improving the efficiency of generating the mapping name.

[0043] Optionally, in order to better meet the obfuscation renaming requirements for the obfuscated data in the original bytecode file, the naming mapping rule table includes at least the following candidate naming mapping rules:

[0044] 1) Data naming mapping rules corresponding to the class name: obtain the current timestamp; perform string concatenation on the class name and the current timestamp to obtain a first concatenated string; perform a hash operation on the first concatenated string to obtain a first hash operation result, and use the first hash operation result as the mapping name of the class name in the naming mapping table;

[0045] 2) Data naming mapping rules corresponding to variable names: obtain the MAC address (Media Access Control Address) of the current computer and the current timestamp; perform string concatenation on the variable name and the MAC address of the current computer to obtain a second concatenated string; perform a hash operation on the second concatenated string to obtain a second hash operation result; perform string concatenation on the second hash operation result and the current timestamp to obtain a mapping name of the variable name in the naming mapping table;

[0046] 3) Data naming mapping rules corresponding to the method name: obtain the current timestamp and randomly obtain a number of random numbers, for example, randomly obtain a 100-bit random number; perform string concatenation on the randomly obtained random number and the method name to obtain a third concatenated string; perform a hash operation on the third concatenated string to obtain a third hash operation result; perform string concatenation on the third hash operation result and the current timestamp to obtain a mapping name of the method name in the naming mapping table.

[0047] S103: Identify the control flow in the first obfuscated file, and perform obfuscation and reorganization on the identified control flow to obtain a second obfuscated file.

[0048] Among them, the control flow refers to the mechanism used in the first obfuscated file to control the program execution process; optionally, the control flow includes but is not limited to conditional judgment, loop, method call and exception handling.

[0049] Specifically, the first obfuscated file can be parsed by the parsing unit in the bytecode processing tool to obtain the second parsed file; then, the control flow identification unit in the bytecode processing tool can identify the control flow in the second parsed file starting from the head of the second parsed file; and based on the preset control obfuscation strategy, the identified control flow is obfuscated and reorganized until the tail of the second parsed file is identified, and the obfuscated reorganization of all control flows in the first obfuscated file is completed, thereby obtaining the second obfuscated file. Among them, the preset control obfuscation strategy refers to a pre-set strategy for code obfuscation of the control flow in the bytecode file; the second parsed file refers to the file obtained after the first obfuscated file is parsed by the parsing unit in the bytecode processing tool, which is used to record the abstract representation of the bytecode in the first obfuscated file.

[0050] S104, performing obfuscation processing on the methods included in each category in the second obfuscated file to obtain a target obfuscated file.

[0051] The target obfuscated file refers to the bytecode file obtained after the second obfuscated file is obfuscated.

[0052] Specifically, the second obfuscated file can be parsed by the parsing unit in the bytecode processing tool to obtain the third parsed file; then, the class identification unit in the bytecode processing tool can be used to identify the classes in the third parsed file starting from the head of the third parsed file; for each identified class, the method identification unit in the bytecode processing tool can be used to further identify the methods contained in the class, and based on the preset method obfuscation strategy, the methods in the identified class are obfuscated until the end of the third parsed file is identified, and the obfuscation of each method contained in each class in the second obfuscated file is completed, thereby obtaining the target obfuscated file. Among them, the preset method obfuscation strategy refers to a pre-set strategy for code obfuscation of methods in each class in the bytecode file; the third parsed file refers to the file obtained after the second obfuscated file is parsed by the parsing unit in the bytecode processing tool, which is used to record the abstract representation of the bytecode in the second obfuscated file.

[0053] The technical solution of the embodiment of the present invention obtains the original bytecode file corresponding to the application source code; identifies the data to be obfuscated in the original bytecode file, and according to the mapping name of the data to be obfuscated in the naming mapping table, performs obfuscated renaming on the obfuscated data to obtain the first obfuscated file corresponding to the original bytecode file; identifies the control flow in the first obfuscated file, and performs obfuscated reorganization on the identified control flow to obtain the second obfuscated file; performs obfuscated processing on the methods contained in each category in the second obfuscated file to obtain the target obfuscated file. The above technical solution obtains the first obfuscated file by performing naming obfuscation on the data to be obfuscated in the original bytecode file; then, obtains the second obfuscated file by performing obfuscated reorganization on the control flow in the first obfuscated file; then, obtains the target obfuscated file by performing obfuscated processing on the methods contained in each category in the second obfuscated file. The multi-level and multi-faceted code obfuscation of the original bytecode file corresponding to the application source code is realized, the code obfuscation degree of the original bytecode file is enhanced, the resistance of the application source code is enhanced, and the risk of the application source code being decompiled is reduced, thereby improving the security of the application source code, and then improving the security of the application; at the same time, there is no need for manual participation in the obfuscation of the control flow in the application source code, thereby enhancing the maintainability of the application source code.

[0054] Embodiment 2

[0055] Figure 2 This is a flowchart of a code obfuscation method provided in Example 2 of the present invention. Based on the above example, this example further optimizes "obfuscating and reorganizing the identified control flow" and provides an optional implementation scheme. It should be noted that for the parts not described in detail in the example of the present invention, reference can be made to the relevant descriptions of other examples. Figure 2 As shown, the method includes:

[0056] S201. Obtain the original bytecode file corresponding to the application source code.

[0057] S202: Identify the data to be obfuscated in the original bytecode file, and perform obfuscated renaming on the data to be obfuscated according to the mapping name of the data to be obfuscated in the naming mapping table, to obtain a first obfuscated file corresponding to the original bytecode file.

[0058] S203: Identify the control flow in the first obfuscated file.

[0059] S204, construct a new method whose judgment condition is always satisfied, and store the identified control flow into the method body of the new method.

[0060] Specifically, a new method in which the judgment condition is always satisfied can be constructed based on the experience of those skilled in the art. For example, the new method can be if(1){}; then, the identified control flow is stored in the method body of the new method.

[0061] S205. Construct a false control flow outside the new method; wherein the false control flow includes a false judgment condition and a false method body.

[0062] Among them, false control flow refers to a mechanism that is never executed when the application is actually running. For example, false control flow can be:

[0063] if(false){

[0064] System.out.println("xxxxxx");

[0065] }

[0066] The false judgment condition refers to a false judgment condition in a false control flow. Correspondingly, the false method body refers to a false method body in a false control flow.

[0067] Specifically, according to the experience of those skilled in the art, a false control flow can be constructed outside the new method. More specifically, according to the experience of those skilled in the art, a false control flow can be constructed before the new method; according to the experience of those skilled in the art, a false control flow can be constructed after the new method; according to the experience of those skilled in the art, a false control flow can be constructed before the new method and a false control flow can be constructed after the new method.

[0068] S206: Generate obfuscated code in the fake method body.

[0069] Specifically, the starting line number of the fake method body may be obtained; according to the starting line number, an obfuscated code adding rule may be determined; and based on the obfuscated code adding rule, an obfuscated code in the fake method body may be generated.

[0070] The starting line number refers to the line number at the starting position of the fake method body. The obfuscated code adding rule refers to the rule for adding obfuscated code to the fake method body.

[0071] More specifically, the starting line number of the fake method body can be obtained; the starting line number is modulo-calculated with a preset value to obtain the calculation result; wherein the preset value can be determined based on the experimental experience of technicians in this field or actual business needs, for example, the preset value can be 2, which is not specifically limited in the embodiment of the present invention. Afterwards, if the calculation result is the first preset value, the obfuscated code adding rules are as follows:

[0072] Define two local variables of numerical type in the false method body, namely the first numerical variable and the second numerical variable; then, randomly obtain a specified number of random numbers, and perform a sum operation on the randomly obtained random numbers and the values ​​of the second numerical variable to obtain a sum result; perform a modulus algorithm on the sum result and the specified number to obtain an assigned value; assign the assigned value to the first numerical variable. Among them, the first preset value can be determined based on the experimental experience of technicians in this field or actual business needs. For example, the first preset value can be 0, and the embodiment of the present invention does not specifically limit it. The specified number refers to a number that is specified in advance. For example, the specified number is 10. The assigned value refers to the value used to assign to the first numerical variable.

[0073] Afterwards, if the operation result is the second preset value, the obfuscation code adding rule is as follows:

[0074] Two string local variables are defined in the fake method body, namely the first string variable and the second string variable; then, a specified number of random numbers are randomly obtained, and the randomly obtained random data are spliced ​​to the back of the second string variable to obtain an assignment string; the assignment string is assigned to the first string variable. The second preset value can be determined based on the experimental experience of those skilled in the art or actual business needs. For example, the second preset value can be 1, and the embodiment of the present invention does not specifically limit it.

[0075] Afterwards, rules are added based on the obfuscated code corresponding to the operation result to generate the obfuscated code in the fake method body.

[0076] It can be understood that the obfuscated code adding rule is determined according to the starting line number of the false method body, and the obfuscated code in the false method body is determined based on the determined obfuscated code adding rule, and the rule for adding obfuscated code to the false method body is clarified, so that the obfuscated code in the false method body is generated according to the specified adding rule, thereby improving the generation efficiency of the obfuscated code in the false method body.

[0077] Optionally, the variable name of the first numerical variable can be determined in the following manner: randomly obtain an original data name from the original data names whose attribute type is the variable name in the naming mapping table; then, obtain the current timestamp; perform string concatenation on the randomly obtained original data name and the current timestamp to obtain the variable name of the first numerical variable. Based on the above principle of determining the variable name of the first numerical variable, the variable name of the second numerical variable, the variable name of the first string variable, and the variable name of the second string variable can be determined. It should be noted that the variable name of the first numerical variable, the variable name of the second numerical variable, the variable name of the first string variable, and the variable name of the second string variable are different.

[0078] S207: Obtain a second obfuscated file.

[0079] Specifically, all control flows identified in the first obfuscated file are obfuscated and reorganized according to the method from S204 to S206 to obtain a second obfuscated file.

[0080] S208, performing obfuscation processing on the methods included in each category in the second obfuscated file to obtain a target obfuscated file.

[0081] Specifically, for each class in the second obfuscated file, determine the method type of each method contained in the class; and perform obfuscation processing on each method contained in the class according to the method type of each method contained in the class to obtain each obfuscated method of the class. The method type includes but is not limited to public methods and private methods.

[0082] More specifically, for each class in the second obfuscation file, determine the method type of each method contained in the class; for each method in each class, if the method type of the method is a public method, add invalid variables and invalid identity judgments after every three lines of code in the method; if the method type of the method is a private method, add invalid local variables to the method; and assign values ​​to the invalid local variables according to the variable type of the invalid local variables.

[0083] Among them, the variable name of the invalid variable can be determined in the following way: randomly obtain a data original name from the data original name with attribute type as variable name in the naming mapping table; then, randomly obtain several random numbers; perform string concatenation on the randomly obtained data original name and several random numbers to obtain the variable name of the invalid variable.

[0084] Among them, according to the variable type of the invalid local variable, the invalid local variable is assigned a value, specifically: if the variable type of the invalid local variable is a numeric type, a random number between 0 and 100 is assigned to the invalid local variable; if the variable type of the invalid local variable is a string type, an empty string is assigned to the invalid local variable; if the variable type of the invalid local variable is a Boolean type, false is assigned to the invalid local variable; otherwise, an empty object is assigned to the invalid member variable.

[0085] Optionally, assigning a value to an invalid local variable according to the variable type of the invalid local variable may also be: determining the assignment method corresponding to the invalid local variable from the variable assignment table based on the correspondence between the variable type and the assignment method in the variable assignment table according to the variable type of the invalid local variable; assigning a value to the invalid local variable using the assignment method corresponding to the invalid local variable. The variable assignment table refers to a data table used to store variable assignment methods; optionally, the variable assignment table may be determined based on a large amount of experimental experience and expert experience.

[0086] It can be understood that for each class in the second obfuscated file, each method contained in the class is obfuscated according to the method type of each method contained in the class to obtain the obfuscated methods of the class, thereby enhancing the code obfuscation degree of each class in the second obfuscated file, thereby enhancing the security of each class in the application source code.

[0087] The technical solution of the embodiment of the present invention is to obtain the original bytecode file corresponding to the application source code; identify the data to be obfuscated in the original bytecode file, and perform obfuscated renaming on the obfuscated data according to the mapping name of the data to be obfuscated in the naming mapping table, so as to obtain a first obfuscated file corresponding to the original bytecode file; identify the control flow in the first obfuscated file; construct a new method in which the judgment condition is always satisfied, and store the identified control flow in the method body of the new method; construct a false control flow outside the new method; wherein the false control flow includes a false judgment condition and a false method body; generate obfuscated code in the false method body; obtain a second obfuscated file; perform obfuscation processing on the methods contained in each category in the second obfuscated file, so as to obtain a target obfuscated file. The above technical solution obtains the first obfuscated file by performing name obfuscation on the data to be obfuscated in the original bytecode file; then, by constructing a new method whose judgment condition is always satisfied, constructing a false control flow outside the new method, and generating obfuscated code in the false method body in the false control flow, the obfuscated reorganization of the control flow in the first obfuscated file is realized to obtain the second obfuscated file, which enhances the resistance of the control flow in the application source code, reduces the risk of the control flow in the application source code being decompiled, and does not require manual participation in the obfuscation of the control flow in the application source code, thereby enhancing the maintainability of the application source code; then, the target obfuscated file is obtained by obfuscating the methods contained in each category in the second obfuscated file. The multi-level and multi-faceted code obfuscation of the original bytecode file corresponding to the application source code is realized, the code obfuscation degree of the original bytecode file is enhanced, the resistance of the application source code is enhanced, and the risk of the application source code being decompiled is reduced, thereby improving the security of the application source code, and then improving the security of the application.

[0088] Embodiment 3

[0089] Figure 3 This is a schematic diagram of the structure of a code obfuscation device provided in the third embodiment of the present invention. This embodiment can be applied to the case of ensuring the security of application source code, especially to the case of ensuring the security of Java application source code. The device can be implemented in the form of hardware and / or software and can be configured in an electronic device. Figure 3 As shown, the device comprises:

[0090] The original bytecode file acquisition module 301 is used to acquire the original bytecode file corresponding to the application source code;

[0091] The first obfuscated file determination module 302 is used to identify the data to be obfuscated in the original bytecode file, and perform obfuscated renaming on the data to be obfuscated according to the mapping name of the data to be obfuscated in the naming mapping table, so as to obtain a first obfuscated file corresponding to the original bytecode file;

[0092] A second obfuscated file determination module 303 is used to identify the control flow in the first obfuscated file and perform obfuscation and reorganization on the identified control flow to obtain a second obfuscated file;

[0093] The target obfuscated file determination module 304 is used to perform obfuscation processing on the methods included in each category in the second obfuscated file to obtain a target obfuscated file.

[0094] The technical solution of the embodiment of the present invention obtains the original bytecode file corresponding to the application source code; identifies the data to be obfuscated in the original bytecode file, and according to the mapping name of the data to be obfuscated in the naming mapping table, performs obfuscated renaming on the obfuscated data to obtain the first obfuscated file corresponding to the original bytecode file; identifies the control flow in the first obfuscated file, and performs obfuscated reorganization on the identified control flow to obtain the second obfuscated file; performs obfuscated processing on the methods contained in each category in the second obfuscated file to obtain the target obfuscated file. The above technical solution obtains the first obfuscated file by performing naming obfuscation on the data to be obfuscated in the original bytecode file; then, obtains the second obfuscated file by performing obfuscated reorganization on the control flow in the first obfuscated file; then, obtains the target obfuscated file by performing obfuscated processing on the methods contained in each category in the second obfuscated file. The multi-level and multi-faceted code obfuscation of the original bytecode file corresponding to the application source code is realized, the code obfuscation degree of the original bytecode file is enhanced, the resistance of the application source code is enhanced, and the risk of the application source code being decompiled is reduced, thereby improving the security of the application source code, and then improving the security of the application; at the same time, there is no need for manual participation in the obfuscation of the control flow in the application source code, thereby enhancing the maintainability of the application source code.

[0095] Optionally, the device further includes a mapping name generating module, wherein the mapping name generating module is specifically used to:

[0096] According to the target attribute type of the data to be obfuscated, based on the correspondence between the attribute type and the data naming mapping rule in the naming mapping rule table, determine the target naming mapping rule corresponding to the data to be obfuscated from the candidate naming mapping rules in the naming mapping rule table;

[0097] Based on the target naming mapping rule, the data to be obfuscated is renamed to obtain the mapping name of the data to be obfuscated in the naming mapping table.

[0098] Optionally, the second obfuscated file determination module 303 includes:

[0099] A new method construction unit is used to construct a new method for determining whether a condition is always satisfied and store the identified control flow in the method body of the new method;

[0100] A false control flow construction unit, used to construct a false control flow outside the new method; wherein the false control flow includes a false judgment condition and a false method body;

[0101] The obfuscated code generation unit is used to generate obfuscated codes in the fake method body.

[0102] Optional, obfuscated code generation unit, specifically used for:

[0103] Get the starting line number of the fake method body;

[0104] Determine the rules for adding obfuscated code based on the starting line number;

[0105] Based on the obfuscated code adding rules, the obfuscated code in the fake method body is generated.

[0106] Optionally, the target obfuscation file determination module 304 is specifically used to:

[0107] For each class in the second obfuscated file, determine the method type of each method contained in the class;

[0108] According to the method type of each method contained in the class, each method contained in the class is obfuscated to obtain each obfuscated method of the class.

[0109] Optionally, the data to be obfuscated is a class name, a variable name, or a method name in the original bytecode file.

[0110] The code obfuscation device provided in the embodiment of the present invention can execute the code obfuscation method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing each code obfuscation method.

[0111] According to an embodiment of the present invention, the present invention also provides an electronic device, a readable storage medium and a computer program product.

[0112] Embodiment 4

[0113] Figure 4A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0114] like Figure 4 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, ROM 12 and RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0115] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0116] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 performs the various methods and processes described above, such as the code obfuscation method.

[0117] In some embodiments, the code obfuscation method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the code obfuscation method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the code obfuscation method in any other appropriate manner (e.g., by means of firmware).

[0118] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0119] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0120] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0121] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0122] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0123] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0124] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0125] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A code obfuscation method, characterized in that: include: Get the original bytecode file corresponding to the application source code; Identify the data to be obfuscated in the original bytecode file, and perform obfuscated renaming on the data to be obfuscated according to the mapping name of the data to be obfuscated in the naming mapping table, to obtain a first obfuscated file corresponding to the original bytecode file; Identify the control flow in the first obfuscated file, and perform obfuscation and reorganization on the identified control flow to obtain a second obfuscated file; Obfuscation processing is performed on the methods contained in each category in the second obfuscated file to obtain a target obfuscated file.

2. The method according to claim 1, characterized in that The process of generating the mapping name of the data to be obfuscated in the naming mapping table is as follows: According to the target attribute type of the data to be obfuscated, based on the correspondence between the attribute type and the data naming mapping rule in the naming mapping rule table, determining the target naming mapping rule corresponding to the data to be obfuscated from the candidate naming mapping rules in the naming mapping rule table; Based on the target naming mapping rule, the data to be obfuscated is renamed to obtain a mapping name of the data to be obfuscated in a naming mapping table.

3. The method according to claim 1, characterized in that Obfuscate and reorganize the identified control flow, including: Constructing a new method for determining that a condition is always satisfied, and storing the identified control flow in a method body of the new method; Constructing a false control flow outside the new method; wherein the false control flow includes a false judgment condition and a false method body; Obfuscated code in the fake method body is generated.

4. The method according to claim 3, characterized in that The generating of the obfuscated code in the false method body comprises: Get the starting line number of the false method body; Determine the obfuscated code adding rule according to the starting line number; Based on the obfuscated code adding rule, the obfuscated code in the false method body is generated.

5. The method according to claim 1, characterized in that Obfuscating the methods contained in each category in the second obfuscated file includes: For each class in the second obfuscated file, determining a method type of each method included in the class; According to the method type of each method contained in the class, each method contained in the class is obfuscated to obtain each obfuscated method of the class.

6. The method according to claim 1, characterized in that The data to be obfuscated is a class name, a variable name or a method name in the original bytecode file.

7. A code obfuscation device, characterized in that: include: The original bytecode file acquisition module is used to obtain the original bytecode file corresponding to the application source code; A first obfuscated file determination module is used to identify the data to be obfuscated in the original bytecode file, and perform obfuscated renaming on the data to be obfuscated according to the mapping name of the data to be obfuscated in the naming mapping table, so as to obtain a first obfuscated file corresponding to the original bytecode file; A second obfuscated file determination module, used for identifying the control flow in the first obfuscated file, and performing obfuscated reorganization on the identified control flow to obtain a second obfuscated file; The target obfuscation file determination module is used to perform obfuscation processing on the methods included in each category in the second obfuscation file to obtain a target obfuscation file.

8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the code obfuscation method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the code obfuscation method according to any one of claims 1 to 6 when executed.

10. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the code obfuscation method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Scrambling and obfuscating method for Lua language and decryption method

    CN105354449A

  • Python code obfuscation method based on control flow and appearance obfuscation

    CN106778101A

  • Code obfuscation method and device

    CN113885872A

  • Java source code protection module based on code obfuscation technology

    CN116226797A

  • Code obfuscation configuration method and device, equipment and medium

    CN118779850A

Cited By

  • Code obfuscation method, electronic device, storage medium and program product

    CN120541813A

  • Method and device for obfuscating and restoring android character strings, computer equipment and medium

    CN120910833A

  • Program protection method and device

    CN122346852A