A programming language code dynamic obfuscation method and system
By compressing and building obfuscation functions on the original programming language, generating obfuscated anonymous functions and injecting valid period logic, the problems of repeated obfuscating and original code leakage in the existing technology are solved, and the code is efficient, secure and within the authorization period. run.
Patent Information
- Application Number
- CN202210575389.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-25
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2042-05-25
AI Technical Summary
Existing programming language code obfuscation techniques cannot effectively avoid the problem of the same code producing the same obfuscated code, and there is a risk of original code leakage.
By compressing the original programming language code, building obfuscation functions and random functions, appending obfuscation comments and obfuscation code, generating obfuscation anonymous functions, and injecting valid period logic into the code to ensure that the code is valid within the authorization period.
It enhances the variability and randomness of the source code, avoids the risk of the same code being confusing the same code, improves the execution efficiency and security of the code, and prevents the risk of the code running indefinitely.
Smart Images

Figure CN114968206B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure belongs to the field of data protection technology, and specifically relates to a programming language code dynamic obfuscation method and system. Background Art
[0002] The statements in this section merely provide background information related to the present disclosure and do not necessarily constitute prior art.
[0003] During the processing of programming languages, the source code needs to be downloaded to the browser for parsing and running; the source code will be directly exposed to users. If the user has programming skills or has attack intentions, they can find code vulnerabilities by analyzing the code logic in the source code, thereby stealing key data and causing economic losses.
[0004] According to the inventors, commonly used programming language code obfuscation technologies include:
[0005] (1) Programming language code compression technology converts the variable and method names in the programming language code into meaningless ones, removes line breaks, spaces, and tabs in the code, reduces the size of the code, and reduces the readability of the code. It has a low cost and can improve the readability of the code through a special decompression method; however, it cannot avoid the same programming language code from generating the same obfuscated code.
[0006] (2) Certificate-based programming language code encryption technology uses SSL certificates to encrypt source code, and the browser uses local certificates to decrypt data. The data is encrypted during transmission. If there is no certificate, the source code cannot be obtained after interception. However, the programming language code can be obtained through the console tool provided by the browser, which poses a risk of leakage of the original programming language code.
[0007] (3) Programming language code obfuscation technology based on browser obfuscation SDK: write code for decoding obfuscated code on the browser side, download the obfuscated code through the browser, and run it after decoding the obfuscated code; however, it is impossible to determine whether the code for decoding the obfuscated code has also been obfuscated. If the decoded code is not obfuscated, there is still a risk of leakage of the original programming language code. Summary of the invention
[0008] In order to solve the above problems, the present invention proposes a method and system for dynamic obfuscation of programming language codes, which enhances the variability and randomness of source code, avoids the same obfuscated code being generated every time for the same programming language code, combines the browser to execute the obfuscated second programming language code, improves the execution efficiency and code security of the programming language code, and injects the code validity period into the obfuscated code to prevent the code from being stolen and used indefinitely.
[0009] According to some embodiments, a first solution of the present disclosure provides a method for dynamic obfuscation of programming language codes, which adopts the following technical solution:
[0010] A programming language code dynamic obfuscation method, comprising:
[0011] Compressing the original programming language to obtain a first programming code;
[0012] Reading characters in the obtained first programming code, and constructing a confusion function and a random function;
[0013] Adding obfuscation comments to the constructed obfuscation function to obtain a second programming code;
[0014] Reading binary values of characters in the first programming code, and obtaining an obfuscated code based on the constructed random function;
[0015] Appending the obtained obfuscated code to the second programming code to obtain an obfuscated anonymous function;
[0016] According to the obtained obfuscated anonymous function and obfuscated code, the characters in the first programming code are returned to restore the original programming language.
[0017] As a further technical limitation, the code of the original programming language is compressed by using JavaScript code compression technology, and the carriage return characters and tab characters in the original programming language code are replaced with JavaScript code to obtain the first programming code.
[0018] As a further technical limitation, all characters in the first programming code are read, an obfuscation function is created according to the number of characters read, a random string of 8-bit character length is obtained based on GUID character compression, and a random function is constructed; based on the obtained random function, obfuscation comments are appended to the obfuscation function to obtain a second programming code.
[0019] Furthermore, the obfuscated comment is obtained by wrapping a random string of 8 bits in length obtained by compressing the GUID string with multiple lines of comment characters.
[0020] As a further technical limitation, the binary values of all characters in the first programming code are read, and the binary values and the randomly generated integer values are added to form new integer values; the formed new integer values are bound to random functions, and the random functions are appended to the obtained new integer values to restore the operation expression of the binary values and obtain the obfuscated code.
[0021] Furthermore, the obtained obfuscated code is appended to the second programming code to obtain the String.fromCharCode obfuscated anonymous function, and the obfuscated validity period logic code is appended to the obfuscated function.
[0022] As a further technical limitation, the obfuscated second programming code is returned to the browser, and based on the String.fromCharCode function in the obfuscated code, the character corresponding to the binary value in the first programming code is returned, and the original programming language is restored on the browser side.
[0023] According to some embodiments, the second solution of the present disclosure provides a programming language code dynamic obfuscation system, which adopts the following technical solution:
[0024] A programming language code dynamic obfuscation system, comprising:
[0025] An acquisition module is configured to perform code compression on the original programming language to obtain a first programming code;
[0026] A construction module configured to read characters in the obtained first programming code and construct a confusion function and a random function;
[0027] The anonymous module is configured to append obfuscated comments to the constructed obfuscated function to obtain a second programming code; read the binary values of the characters in the first programming code to obtain an obfuscated code based on the constructed random function; append the obtained obfuscated code to the second programming code to obtain an obfuscated anonymous function;
[0028] The obfuscation module is configured to return the characters in the first programming code according to the obtained obfuscated anonymous function and obfuscated code, and restore the original programming language.
[0029] According to some embodiments, a third solution of the present disclosure provides a computer-readable storage medium, which adopts the following technical solution:
[0030] A computer-readable storage medium stores a program, which, when executed by a processor, implements the steps in the method for dynamic obfuscation of programming language codes as described in the first aspect of the present disclosure.
[0031] According to some embodiments, a fourth solution of the present disclosure provides an electronic device, which adopts the following technical solution:
[0032] An electronic device comprises a memory, a processor and a program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps in the method for dynamic obfuscation of programming language codes as described in the first aspect of the present disclosure are implemented.
[0033] Compared with the prior art, the present invention has the following beneficial effects:
[0034] The present invention obfuscates the binary value of the original code by adding a random integer value to the binary value of the code; reduces the readability of the code by adding a random function with a random 8-bit character length to the code and adding random comments to the function; and injects the obfuscated validity logic code into the code to ensure the authorization period of the code and prevent the code from being run indefinitely after being downloaded. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The accompanying drawings constituting a part of the present disclosure are used to provide a further understanding of the present disclosure. The illustrative embodiments of the present disclosure and their descriptions are used to explain the present disclosure and do not constitute an improper limitation on the present disclosure.
[0036] Figure 1 is a flowchart of the method for dynamic obfuscation of programming language codes in the first embodiment of the present disclosure;
[0037] Figure 2 It is a structural block diagram of the programming language code dynamic obfuscation system in the second embodiment of the present disclosure. DETAILED DESCRIPTION
[0038] The present disclosure is further described below in conjunction with the accompanying drawings and embodiments.
[0039] It should be noted that the following detailed descriptions are all illustrative and are intended to provide further explanation of the present disclosure. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present disclosure belongs.
[0040] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present disclosure. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0041] In the absence of conflict, the embodiments in the present disclosure and the features in the embodiments may be combined with each other.
[0042] Terminology explanation:
[0043] GUID: Globally Unique Identifier is a binary-length digital identifier generated by an algorithm and is globally unique.
[0044] JavaScript: is a function-first, lightweight, interpreted or just-in-time compiled programming language.
[0045] Code obfuscation: refers to changing the names of variables, functions, and classes in the source code into meaningless ones, and increasing the difficulty of reading by adding comments, meaningless characters, etc.
[0046] GUID string compression: GUID string compression is to calculate the MD5 value of the randomly generated GUID string through the MD5 operation method. The calculated MD5 value is a 32-bit hexadecimal string. The integer 62 is modulo operation is performed on each group of four bits. The remainder is used as an index to obtain characters in the string of 0-9A-Za-z. Finally, the 8 characters after the operation are concatenated to obtain an 8-bit compressed string.
[0047] Obfuscating anonymous functions: converting the original plain text function, which is easy to read and understand, into an obscure and difficult to read function name through calculation.
[0048] Embodiment 1
[0049] Embodiment 1 of the present disclosure introduces a method for dynamic obfuscation of programming language codes.
[0050] like Figure 1 A programming language code dynamic obfuscation method is shown, comprising:
[0051] Compressing the original programming language to obtain a first programming code;
[0052] Reading characters in the obtained first programming code, and constructing a confusion function and a random function;
[0053] Adding obfuscation comments to the constructed obfuscation function to obtain a second programming code;
[0054] Reading binary values of characters in the first programming code, and obtaining an obfuscated code based on the constructed random function;
[0055] Appending the obtained obfuscated code to the second programming code to obtain an obfuscated anonymous function;
[0056] According to the obtained obfuscated anonymous function and obfuscated code, the characters in the first programming code are returned to restore the original programming language.
[0057] As one or more implementation modes, the code of the original programming language is compressed by using JavaScript code compression technology, and the carriage return characters and tab characters in the original programming language code are replaced with JavaScript code to obtain the first programming code.
[0058] As one or more implementation methods, all characters in the first programming code are read, an obfuscation function is created according to the number of characters read, a random string of 8-bit character length is obtained based on GUID character compression, and a random function is constructed; based on the obtained random function, obfuscation comments are appended to the obfuscation function to obtain a second programming code.
[0059] In this embodiment, the obfuscated comment is an 8-bit string compressed by the GUID, wrapped with multi-line comment characters, and used to disrupt the source code.
[0060] In this embodiment, the random function is also called an anonymous function, that is, a function without a specified function name; the anonymous function used for obfuscation is referred to as an obfuscated anonymous function.
[0061] In this embodiment, after the number of character strings is divided by the base and rounded, a loop is performed based on the calculated integer value to complete the obfuscation function of the corresponding proportion.
[0062] The function name is obtained by compressing the GUID string into an 8-bit string. The function body is obfuscated with comments obtained by compressing the GUID string into an 8-bit string using multiple paragraphs and multiple lines of comment characters. The comments are separated by return and arguments[0].
[0063] As one or more implementation methods, the binary values of all characters in the first programming code are read, and an addition operation is performed on the binary value and the randomly generated integer value to form a new integer value; a random function is bound to the formed new integer value, and an operation expression for restoring the binary value by appending the random function to the obtained new integer value) is obtained to obtain an obfuscated code;
[0064] The obtained obfuscated code is appended to the second programming code to obtain the String.fromCharCode obfuscated anonymous function, and the obfuscated validity period logic code is appended to the obfuscated function.
[0065] In this embodiment, the validity period logic code is fixed, and the difference operation can be performed by obtaining the browser local time and the server obfuscated time. If the difference is within the allowable range, it means that the code is within the validity period.
[0066] As one or more implementation methods, the obfuscated second programming code is returned to the browser, and based on the String.fromCharCode function in the obfuscated code, the character corresponding to the binary value in the first programming code is returned, and the original programming language is restored on the browser side.
[0067] This embodiment adds a random integer value to the binary value of the code to confuse the binary value of the original code; adds a random function with a random 8-bit character length to the code and adds random comments to the function to reduce the readability of the code; injects the obfuscated validity logic code into the code to ensure the authorization period of the code and prevent the code from running indefinitely after being downloaded.
[0068] Embodiment 2
[0069] Embodiment 2 of the present disclosure introduces a programming language code dynamic obfuscation system.
[0070] like Figure 2 A programming language code dynamic obfuscation system is shown, comprising:
[0071] An acquisition module is configured to perform code compression on the original programming language to obtain a first programming code;
[0072] A construction module configured to read characters in the obtained first programming code and construct a confusion function and a random function;
[0073] The anonymous module is configured to append obfuscated comments to the constructed obfuscated function to obtain a second programming code; read the binary values of the characters in the first programming code to obtain an obfuscated code based on the constructed random function; append the obtained obfuscated code to the second programming code to obtain an obfuscated anonymous function;
[0074] The obfuscation module is configured to return the characters in the first programming code according to the obtained obfuscated anonymous function and obfuscated code, and restore the original programming language.
[0075] The detailed steps are the same as those of the programming language code dynamic obfuscation method provided in Example 1 and will not be repeated here.
[0076] Embodiment 3
[0077] A third embodiment of the present disclosure provides a computer-readable storage medium.
[0078] A computer-readable storage medium stores a program, which, when executed by a processor, implements the steps of the method for dynamic obfuscation of programming language codes as described in the first embodiment of the present disclosure.
[0079] The detailed steps are the same as those of the programming language code dynamic obfuscation method provided in Example 1 and will not be repeated here.
[0080] Embodiment 4
[0081] A fourth embodiment of the present disclosure provides an electronic device.
[0082] An electronic device comprises a memory, a processor and a program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps in the method for dynamic obfuscation of programming language codes as described in the first embodiment of the present disclosure are implemented.
[0083] The detailed steps are the same as those of the programming language code dynamic obfuscation method provided in Example 1 and will not be repeated here.
[0084] The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure. For those skilled in the art, the present disclosure may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for dynamic obfuscation of programming language codes, characterized in that: include: Compressing the original programming language to obtain a first programming code; Reading characters in the obtained first programming code, and constructing a confusion function and a random function; Adding obfuscation comments to the constructed obfuscation function to obtain a second programming code; Reading binary values of characters in the first programming code, and obtaining an obfuscated code based on the constructed random function; Appending the obtained obfuscated code to the second programming code to obtain an obfuscated anonymous function; According to the obtained obfuscated anonymous function and obfuscated code, returning the characters in the first programming code to restore the original programming language; Read all characters in the first programming code, create an obfuscation function according to the number of characters read, obtain a random string of 8-bit characters based on GUID character compression, and construct a random function; based on the obtained random function, add an obfuscation comment to the obfuscation function to obtain a second programming code; The obfuscated comment is obtained by compressing the GUID string and wrapping it with a multi-line comment symbol. Reading the binary values of all characters in the first programming code, performing an addition operation on the binary value and a randomly generated integer value to form a new integer value; performing a random function binding on the formed new integer value, and appending an operation expression for restoring the binary value of the obtained new integer value through the random function to obtain an obfuscated code; Append the obtained obfuscated code to the second programming code to obtain the String.fromCharCode obfuscated anonymous function, and append the obfuscated validity period logic code to the obfuscated function; Return the obfuscated second programming code to the browser, and based on the String.fromCharCode function in the obfuscated code, return the character corresponding to the binary value in the first programming code, and restore the original programming language on the browser side; GUID string compression is to calculate the MD5 value of the randomly generated GUID string through the MD5 operation method. The calculated MD5 value is a 32-bit hexadecimal string; the integer 62 is modulo operation is performed on every four bits, and the remainder is used as an index to obtain characters in the string of 0-9A-Za-z. Finally, the 8 characters after the operation are concatenated to obtain an 8-bit compressed string.
2. A method for dynamic obfuscation of programming language codes as claimed in claim 1, characterized in that: The original programming language code is compressed by using JavaScript code compression technology, and the carriage return characters and tab characters in the original programming language code are replaced with JavaScript code to obtain the first programming code.
3. A programming language code dynamic obfuscation system, based on a programming language code dynamic obfuscation method as claimed in any one of claims 1 to 2, characterized in that: include: An acquisition module is configured to perform code compression on the original programming language to obtain a first programming code; A construction module configured to read characters in the obtained first programming code and construct a confusion function and a random function; The anonymous module is configured to append obfuscated comments to the constructed obfuscated function to obtain a second programming code; read the binary values of the characters in the first programming code, and obtain the obfuscated code based on the constructed random function; Appending the obtained obfuscated code to the second programming code to obtain an obfuscated anonymous function; The obfuscation module is configured to return the characters in the first programming code according to the obtained obfuscated anonymous function and obfuscated code, and restore the original programming language.
4. A computer-readable storage medium having a program stored thereon, characterized in that: When the program is executed by a processor, the steps in the method for dynamic obfuscation of programming language codes as described in any one of claims 1 to 2 are implemented.
5. An electronic device comprising a memory, a processor, and a program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps in the method for dynamic obfuscation of programming language codes as described in any one of claims 1-2 are implemented.
Citation Information
Patent Citations
Go language source code obfuscation method, system, terminal and storage medium
CN113849781A
Java code obfuscation method and system, computer equipment and storage medium
CN114090965A