Code obfuscation method, business execution method, medium, equipment and product

By integrating a second language code as a string constant within a first language code and applying a security compiler for obfuscation, the method addresses the inadequacies of existing tools, enhancing the security of cross-language integrated software systems against reverse engineering.

HK40134554APending Publication Date: 2026-07-10ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD

Patent Information

Authority / Receiving Office
HK · HK
Patent Type
Applications
Current Assignee / Owner
ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD
Filing Date
2026-04-20
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

Existing code obfuscation tools are inadequate for protecting cross-language integrated software systems, as they typically focus on single-language environments and lack unified methods to effectively obfuscate mixed code, leading to insufficient protection against reverse engineering.

Method used

A method involving writing a second language code as a string constant into a first language code, followed by obfuscation using a security compiler to generate an executable file, ensuring resistance to reverse engineering.

Benefits of technology

The method enhances the security of cross-language integrated code by effectively resisting reverse engineering attacks, improving overall security and protection of hybrid code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 00000000_0000_ABST
    Figure 00000000_0000_ABST
Patent Text Reader

Abstract

The invention discloses a code obfuscation method, a business execution method, a medium, equipment and a product. According to the scheme, the to-be-mixed first language code and the to-be-mixed second language code are firstly obtained, then the second language code serves as the character string constant in the first language code and is written into the first language code, the mixed code is obtained, finally, the mixed code is subjected to obfuscation processing through the preset security compiler, and the safety of the mixed code is improved. And obtaining an executable file corresponding to the mixed code.
Need to check novelty before this filing date? Find Prior Art

Description

(19) State Intellectual Property Office (12) Invention Patent Application (10) Application Publication Number (43) Application Publication Date (21) Application Number 202511378009.0 (22) Application Date 2025.09.24 (71) Applicant Ant Blockchain Technology (Shanghai) Co., Ltd. Address Room 803, 8th Floor, No. 618 Waima Road, Huangpu District, Shanghai 200010 (72) Inventors Huang Xuebing, Lu Linpeng, Wu Xing, Li Wei, Wei Yawen (74) Patent Agency Beijing Bosijia Intellectual Property Agency Co., Ltd. 11415 Patent Attorney Li Wei (51) Int.Cl. G06F 21 / 14 (2013.01) (54) Invention Title A code obfuscation method, business execution method, medium, device and product (57) Abstract This specification discloses a code obfuscation method, business execution method, medium, device and product. This solution first obtains the first language code and the second language code to be mixed. Then, the second language code is written into the first language code as a string constant to obtain the mixed code. Finally, the mixed code is obfuscated by a preset security compiler to obtain the executable file corresponding to the mixed code. Claims (2 pages), Description (12 pages), Drawings (5 pages), CN 121256756 A 2026.01.02 CN 1 21 25 67 56 A 1. A code obfuscation method, comprising: obtaining first language code and second language code to be obfuscated, wherein the first language code is used to provide a target service, and when the target service is executed, the second language code is called by the first language code to implement a specified function required when executing the target service, the first language code is compiled into machine code and executed by the operating system on which the first language code is based, and the second language code is compiled into bytecode and executed by the interpreter corresponding to the second language code; writing the second language code as a string constant in the first language code into the first language code to obtain obfuscated code; and obfuscating the obfuscated code using a preset security compiler to obtain an executable file corresponding to the obfuscated code.2. The method of claim 1, wherein the second language code is written into the first language code as a string constant in the first language code to obtain hybrid code, specifically includes: determining the functional description text of the second language code; performing semantic analysis on the functional description text to determine keywords used to describe functional characteristics; determining, based on the keywords, a target function in the first language code for calling the second language code to implement the specified function; determining, based on the target function, the embedding position corresponding to the second language code; and, based on the embedding position, writing the second language code into the first language code as a string constant in the first language code to obtain hybrid code. 3. The method of any one of claims 1 to 2, wherein the first language code includes C++ code or C code, the second language code includes Python code, and when the second language code is Python code, the interpreter is a Python interpreter. 4. A business execution method, comprising: obtaining an executable file, wherein the executable file is obtained by obfuscating hybrid code using a preset security compiler, the hybrid code being obtained by writing second language code as a string constant into first language code, the first language code being used to provide a target business, the second language code being called by the first language code to implement a specified function required when executing the target business, the first language code being compiled into machine code and executed by the operating system on which the first language code is based, and the second language code being compiled into bytecode by an interpreter corresponding to the second language code and executed; when executing the target business by running the executable file, loading the executable file into a preset memory and starting the interpreter corresponding to the second language code; when the first language code calls the second language code, executing the second language code through the interpreter to obtain an execution result.5. The method as described in claim 4, wherein the first language code includes C++ code or C code, the second language code includes Python code, and when the second language code is Python code, the interpreter is a Python interpreter; when the first language code calls the second language code, the second language code is executed through the interpreter to obtain an execution result, specifically including: when the first language code calls the second language code, the Python interpreter is initialized through pybind11, and various functional modules are created through the Python interpreter, with different functional modules used to provide different Python functions; the Python code is executed to determine the functional module to be called from the various functional modules as the target module, and the execution result is obtained by calling the Python function provided in the target module. 6. The method of claim 5, wherein obtaining the execution result by calling the Python function provided in the target module specifically includes: determining the parameters that the first language code needs to transmit when calling the second language code; converting the data type of the parameters to a Python-defined data type using pybind11 to obtain the converted parameters; and calling the target module to process the converted parameters through the Python function in the target module to obtain the execution result. 7. The method of claim 6, wherein executing the second language code to determine the functional module to be called from the functional modules as the target module, specifically includes: compiling the second language code using a compilation module created by the Python interpreter to obtain bytecode corresponding to the second language code; and executing the bytecode using a preset Python virtual machine to determine the functional module to be called from the functional modules as the target module. 8. An electronic device, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor implements the steps of the method of any one of claims 1 to 7 by executing the executable instructions. 9. A computer-readable storage medium storing computer instructions thereon, which, when executed by a processor, implement the steps of the method of any one of claims 1 to 7. 10. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the steps of the method as described in any one of claims 1 to 7.Claims 2 / 2 Page 3 CN 121256756 A A code obfuscation method, business execution method, medium, device and product Technical Field

[0001] One or more embodiments of this specification relate to the field of computer technology, and more particularly to a code obfuscation method, business execution method, medium, device and product. Background Art

[0002] With the increasing complexity of software functions, a single programming language is often difficult to meet development needs, so cross-language code integration has emerged.

[0003] Cross-language code integration refers to the technical practice of integrating code modules written in different programming languages ​​in the same software system and making them work together. This integration method allows developers to choose the most suitable programming language according to specific tasks (such as performance, library ecosystem or domain characteristics), effectively breaking through the limitations of a single language, thereby improving development efficiency and optimizing the overall performance of the system.

[0004] For software systems built through cross-language code integration, their core business logic and algorithm code are crucial assets. Therefore, these codes must be protected to prevent attackers from obtaining the actual implementation details of the system through reverse engineering means (such as decompilation, disassembly).

[0005] Currently, code obfuscation is a common technique for protecting software code from reverse engineering. Its core principle is to convert source code or intermediate representations (such as bytecode) into a functionally equivalent but formally complex and poorly readable version.

[0006] However, existing code obfuscation tools and techniques typically focus on a single language environment. Because different programming languages ​​differ significantly in many aspects, such as runtime mechanisms and compilation, there is currently a lack of unified and efficient methods to systematically obfuscate the overall mixed code resulting from cross-language integration. This leads to the inability to effectively protect software products obtained through cross-language code integration.

[0007] In view of the above, one or more embodiments of this specification provide the following technical solutions:

[0008] According to a first aspect of one or more embodiments of this specification, a code obfuscation method is proposed, comprising:

[0009] obtaining a first language code to be mixed and a second language code, wherein the first language code is used to provide a target service, and when the target service is executed, the second language code is called by the first language code to implement the specified function required when executing the target service, the first language code is compiled into machine code and executed by the operating system on which the first language code is based, and the second language code is compiled into bytecode by the interpreter corresponding to the second language code and executed;

[0010] writing the second language code as a string constant in the first language code into the first language code to obtain mixed code;

[0011] obfuscating the mixed code by a preset security compiler to obtain an executable file corresponding to the mixed code.

[0012] Optionally, the second language code is written into the first language code as a string constant in the first language code to obtain hybrid code, specifically including:

[0013] Determining the functional description text of the second language code; Specification 1 / 12 Page 4 CN 121256756 A

[0014] Performing semantic analysis on the functional description text to determine keywords used to describe functional characteristics;

[0015] Determining the target function in the first language code for calling the second language code to implement the specified function according to the keywords;

[0016] Determining the embedding position corresponding to the second language code according to the target function;

[0017] Writing the second language code into the first language code as a string constant in the first language code according to the embedding position to obtain hybrid code.

[0018] Optionally, the first language code includes C++ code or C code, and the second language code includes Python code. When the second language code is Python code, the interpreter is a Python interpreter.

[0019] According to a second aspect of one or more embodiments of this specification, a business execution method is proposed, comprising:

[0020] obtaining an executable file, wherein the executable file is obtained by obfuscating hybrid code through a preset security compiler, the hybrid code being obtained by writing a second language code as a string constant into a first language code, the first language code being used to provide a target business, the second language code being called by the first language code to implement a specified function required when executing the target business, the first language code being compiled into machine code and executed by the operating system on which the first language code is based, and the second language code being compiled into bytecode by an interpreter corresponding to the second language code and executed;

[0021] when executing the target business by running the executable file, loading the executable file into a preset memory, and starting the interpreter corresponding to the second language code;

[0022] when the first language code calls the second language code, executing the second language code through the interpreter to obtain an execution result.

[0023] Optionally, the first language code includes C++ code or C code, and the second language code includes Python code. When the second language code is Python code, the interpreter is a Python interpreter;

[0024] When the first language code calls the second language code, the second language code is executed through the interpreter to obtain an execution result, specifically including:

[0025] When the first language code calls the second language code, the Python interpreter is initialized through pybind11, and various functional modules are created through the Python interpreter. Different functional modules are used to provide different Python functions;

[0026] The Python code is executed to determine the functional module to be called from the various functional modules as the target module, and the execution result is obtained by calling the Python function provided in the target module.

[0027] Optionally, the execution result is obtained by calling the Python function provided in the target module, specifically including:

[0028] Determining the parameters that the first language code needs to transmit when calling the second language code;

[0029] Converting the data type of the parameters to the data type specified by Python using pybind11 to obtain the converted parameters;

[0030] Calling the target module to process the converted parameters through the Python function in the target module to obtain the execution result.

[0031] Optionally, executing the second language code to determine the functional module to be called from the functional modules as the target module specifically includes:

[0032] compiling the second language code through a compilation module created by the Python interpreter to obtain bytecode corresponding to the second language code;

[0033] executing the bytecode through a preset Python virtual machine to determine the functional module to be called from the functional modules as the target module.

[0034] According to a third aspect of one or more embodiments of this specification, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor implements the steps of the above-described code obfuscation method or business execution method by running the executable instructions.

[0035] According to a fourth aspect of one or more embodiments of this specification, a computer-readable storage medium is provided, on which computer instructions are stored, which, when executed by a processor, implement the steps of the above-described code obfuscation method or business execution method.

[0036] According to a fifth aspect of one or more embodiments of this specification, a computer program product is provided, including a computer program / instruction that, when executed by a processor, implements the steps of the above-described code obfuscation method or business execution method.

[0037] As can be seen from the above embodiments, firstly, a first language code and a second language code to be mixed are obtained. Then, the second language code is written into the first language code as a string constant, resulting in mixed code. Finally, the mixed code is obfuscated using a preset security compiler to obtain an executable file corresponding to the mixed code.

[0038] As can be seen from the above method, by writing the second language code into the first language code as a string constant and using a security compiler to perform overall obfuscation on the obtained mixed code, the final executable file can effectively resist reverse engineering attacks, thereby effectively improving the overall security of the mixed code.

[0039] Figure 1 is a schematic diagram of the steps involved in the code obfuscation method provided in this specification;

[0040] Figure 2 is a schematic diagram of the steps involved in the business execution method provided in this specification;

[0041] Figure 3 is a schematic diagram of the preparation stage in a business execution provided in this specification;

[0042] Figure 4 is a schematic diagram of the actual execution stage in the business execution process provided in this specification;

[0043] Figure 5 is a schematic structural diagram of a device provided in this specification;

[0044] Figure 6 is a block diagram of a code obfuscation device provided in this specification;

[0045] Figure 7 is a block diagram of a business execution device provided in this specification.Detailed Implementation

[0046] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this specification are all information and data authorized by the user or fully authorized by all parties. The collection, use and processing of related data need to comply with the relevant laws, regulations and standards of relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.

[0047] Existing code obfuscation tools and technologies usually focus on a single language environment. Due to the significant differences between different programming languages ​​in many aspects such as operating mechanism and compilation, there is currently a lack of unified and efficient means to systematically obfuscate the overall mixed code formed after cross-language integration, resulting in the inability to effectively protect the software products obtained through cross-language code integration.

[0048] To this end, this specification provides a code obfuscation method and a business execution method. First, the first language code and the second language code to be mixed are obtained. Then, the second language code is written into the first language code as a string constant in the first language code to obtain the mixed code. Finally, the mixed code is obfuscated by a preset security compiler to obtain the executable file corresponding to the mixed code. In this way, an executable instruction manual resistant to reverse engineering can be effectively obtained (page 3 / 12, CN 121256756 A), thereby improving the overall execution security of the hybrid code.

[0049] In this specification, the first language code can refer to code compiled into machine code and directly executed by the operating system on which the first language code is based, and can refer to code written in programming languages ​​such as C++ and C. The second language code can refer to code compiled into bytecode and executed by the interpreter corresponding to the second language code, and can refer to code written in programming languages ​​such as Python.

[0050] For ease of description, the following will only use C++ code as the first language code and Python code as the second language code as an example to describe a code obfuscation and business execution method provided in this specification. As for other cases, such as C code as the first language code and Python code as the second language code, the same applies.

[0051] In order to clearly describe the code obfuscation and business execution method provided in this specification, some concepts appearing in this specification will be explained first.

[0052] Python interpreter: mainly used to read written Python code, then "translate" it into instructions (machine code) that the computer can understand and execute, and then execute these instructions.

[0053] During the execution of Python code, the Python interpreter typically performs lexical analysis first to extract various keywords, variable names, operators, and other lexical units contained in the code, and checks for obvious spelling errors in the Python code. Then, the Python interpreter further checks whether the combination of these lexical units conforms to Python's syntax rules. If the combination of these lexical units conforms to Python's syntax rules, the Python interpreter constructs an abstract syntax tree for the Python code and compiles the Python code using this abstract syntax tree to obtain the corresponding bytecode. Finally, the core component of the Python interpreter, the Python virtual machine, reads this bytecode and translates it line by line into machine code that the current operating system and CPU can execute, and executes it immediately.

[0054] In addition, during the execution of Python code, the Python interpreter creates various built-in modules. Some of these built-in modules are mainly used to provide Python functions with different functionalities, such as math, datetime, and re, to implement different functions. Some built-in modules are used to provide the necessary execution environment for executing Python code. For example, the built-in modules include a compiler module, which can compile Python code to obtain the corresponding bytecode.

[0055] In addition, during the execution of Python code, the Python interpreter can also initialize a memory allocator to allocate the required memory space for the bytecode compiled during the execution of Python code.

[0056] In summary, the Python interpreter can provide the environment and various modules required during the execution of Python code to ensure the smooth operation of Python code.

[0057] Python Virtual Machine: It is an abstract computing machine that provides a runtime environment for Python programs and can execute instructions compiled into Python bytecode.

[0058] The Python Virtual Machine is actually more like a "translator". It can understand general bytecode and then tell the underlying hardware what to do by calling the functions of the local operating system. Therefore, when Python code is compiled into bytecode using a compiler module, this bytecode is not specific to any particular hardware machine. As long as the Python Virtual Machine is installed on the operating system of these machines, this bytecode can be run.

[0059] pybind11: is a lightweight C++ library that only includes header files. Its main function is to act as a "bridge" between C++ code and Python code. Through pybind11, seamless bidirectional interaction between the two languages ​​can be achieved.

[0060] The main function of pybind11 is to perform data type conversion. That is, since this manual embeds Python code in C++ code, it is necessary to convert the data type of the parameters passed by the C++ code into the data type specified by Python during the process of calling the Python code from the C++ code. For example, converting the int type parameter into the pyLong type. Manual 4 / 12 Page 7 CN 121256756 A

[0061] In addition, pybind11 is also used to manage the Python interpreter. For example, when Python code needs to be executed, the Python interpreter will be initialized and started, and after the Python code is executed, the Python interpreter will be released and the various resources required to run the Python interpreter will be cleaned up.

[0062] Obfuscation compilation: refers to the process of compiling source code into executable files or intermediate code by using special obfuscation methods to perform various transformations and transformations on the code, making the final generated code difficult for humans to read and understand, but at the same time completely retaining its original function. Its core idea is that the obfuscated code becomes obscure and difficult to understand. However, this obfuscation is not for encryption, but to increase the cost of attack by increasing the difficulty of understanding and analysis.

[0063] Common obfuscation methods include the following:

[0064] Name obfuscation: renaming meaningful names of classes, methods, variables, fields, etc., to meaningless short characters (e.g., renaming calculateTotalRevenue to 'a').

[0065] Control flow obfuscation: changing the execution flow structure of the code, for example, breaking down a simple if-else or while loop into logically chaotic but equivalent branches and jumps connected by goto statements.

[0066] Code and data obfuscation: inserting useless code that will never be executed (e.g., junk instructions), or implementing simple instructions in a complex way.

[0067] Debugging information removal: stripping all debugging symbols, file names, line numbers, and other information from the compilation output.

[0068] In addition, the code obtained after obfuscation through obfuscated compilation does not need to be deobfuscated during execution. The obfuscated code can be directly executed by the machine's execution engine (e.g., interpreter, virtual machine, etc.). This is mainly because the purpose of obfuscation is to increase the difficulty of human understanding, not the difficulty of machine execution. Because the code after obfuscation is still syntactically correct, the machine's execution engine doesn't care what the variable names are or how complex the code logic is; it only cares about syntactic correctness.

[0069] The following will describe a code obfuscation method provided in this specification.

[0070] The obfuscation method provided in this specification can be roughly divided into several processes, as shown in Figure 1.

[0071] Figure 1 is a schematic diagram of the steps involved in the code obfuscation method provided in this specification.

[0072] S100: Obtain the first language code and the second language code to be mixed.

[0073] In the code obfuscation method provided in this specification, the execution subject can be the server used by the developer of the application or client, or a server cluster consisting of multiple servers in the developer's platform, or a client installed on the server or server cluster. Of course, the execution subject can also be the terminal device used by the developer (such as a desktop computer, laptop computer, or other electronic device), or a client installed on the terminal device. For ease of explanation, the code obfuscation method provided in this specification will be described below using the terminal device as the execution subject as an example.

[0074] In practical applications, cross-code integration allows developers to leverage the advantages of multiple programming languages ​​to build complex and high-performance applications, especially common in system programming, high-performance computing, embedded development, or specific field applications. Therefore, developers can write the required code on the terminal device they use according to actual needs. In the case of embedding Python code in C++ code, the C++ code can be used to execute the target business required by the developer and to determine when and how to call the Python code. The embedded Python code is mainly used to be called by the C++ code when executing the target business, so as to achieve the specified functions required to execute the target business.

[0075] For example, a developer develops a quantitative trading client. The main body of the client is written in C++ programming language, while the functional modules that provide trading strategies in the client can be written in Python programming language.

[0076] For another example, a developer develops a game program based on C++. The core graphics and physics / audio engines involved in the game are written in C++ to ensure performance. However, the developer also hopes that some community members or mod authors can create plugins such as custom tasks and damage statistics in the game. Then, these plugins can be written in Python code.

[0077] In practical applications, there are many other examples of cross-code integration of embedding Python code in C++ code, which will not be listed here.

[0078] In this specification, developers can use various programming software running on a terminal device to input C++ code and Python code in the input interface, so that the terminal device can obtain the C++ code and Python code written by the developer.

[0079] S102: The second language code is written into the first language code as a string constant in the first language code to obtain mixed code.

[0080] In practical applications, the files ultimately distributed to users are often executable files such as .exe and .dll, which are compiled by a compiler. For C++ code, the executable file (binary machine code) obtained after compilation has good anti-decompilation properties because some key information is lost in the compiled executable file, causing the decompiled code to be uninterpretable or to contain errors.

[0081] For example, C++ code usually contains clear function names that reflect the original intent of the function. However, in the executable file obtained after compiling C++ code, these functions are usually only represented as a memory address (e.g., 0x00411A30). Therefore, the decompiler often only obtains a function name modified based on the memory address (e.g., sub_411A30), but it is clear that this function name no longer reflects the original intent of the function.

[0082] For example, the decompilation process can be roughly divided into two steps: the first step is disassembly, that is, the binary machine code is read byte by byte by the executable file through the disassembler, thereby translating the machine code into the corresponding assembly code; the second step is decompilation, that is, the assembly code is analyzed by the decompiler. The second step is actually full of guessing and inference, so the variable types in the executable file compiled by decompilation are often incorrect.

[0083] Specifically, during the execution of the executable file, the processor does not care about the specific type of the data to be processed (such as int, float, etc.). The processor only knows that there is a string of bytes at a certain memory address, and it needs to perform specified operations on these bytes through assembly code (such as addition, comparison, shift, etc.). After seeing these assembly codes, the decompilation tool needs to guess the type of data read from memory through the assembly code, which causes the decompiler to guess the data type incorrectly.

[0084] For example, advanced for, while, if / else are compiled into simple jump instructions (such as jmp, je, jne) at the underlying level. Decompilers need to work hard to reconstruct the high-level control flow from these jumps, a process that is very complex and error-prone.

[0085] There are many other situations where decompilers encounter decompilation errors due to the corresponding executable files of C++ code, which will not be listed here.

[0086] Compared to C++, the bytecode obtained after compiling Python code does not have a good decompilation effect. This is mainly because the obtained bytecode is fundamentally different from binary machine code. Bytecode is designed to be interpreted and executed by the Python virtual machine, and it retains a large amount of high-level semantic information. Therefore, through the retained high-level semantic information, the corresponding code can be well compiled by the decompiler.

[0087] For the reasons mentioned above, it is necessary to embed Python code as part of C++ code into C++ code, so that the Python code part also has good decompilation characteristics. Therefore, in this specification, the terminal device can embed Python code as a string constant into C++ code, that is, hard-code the Python code into C++ code. And because the executable file obtained by compiling C++ code has good decompilation characteristics, the Python code as the string constant part also has good decompilation characteristics, thereby further protecting the Python code.

[0088] S104: Obfuscate the mixed code using a preset security compiler to obtain the executable file corresponding to the mixed code.

[0089] After obtaining the mixed code, it is necessary to obfuscate the mixed code using a preset security compiler to obtain the executable file corresponding to the mixed code. The specific obfuscation method is as mentioned above, and can be implemented by means such as name obfuscation, control flow obfuscation, code and data obfuscation, etc.

[0090] As can be seen from the above method, by writing Python code as a constant into C++ code and using a security compiler to perform overall obfuscation on the resulting hybrid code, the final executable file can effectively resist reverse engineering attacks, thereby effectively improving the overall security of the hybrid code.

[0091] It should be noted that developers can declare the embedding position of Python code in C++ code through the terminal device, so that the terminal device can embed Python code into C++ code according to the embedding position.

[0092] The above method can be understood as the developer actively declaring the embedding position. In this specification, the terminal device can also determine the embedding position of Python code in C++ code itself.

[0093] Specifically, while obtaining C++ code and Python code, the terminal device can obtain functional description text for Python code. This functional description text is used to describe the specified functions that Python code can provide in the target business. Afterwards, the terminal device can perform semantic analysis on the functional description text to determine the keywords used to describe the functional characteristics. The determined keywords often reflect the core characteristics of the specified function.

[0094] The terminal device can further determine the target function in the C++ code to call the Python code to implement the specified function based on the keyword, and determine the embedding position of the Python code based on the target function.The terminal device can determine the target function based on keywords in various ways. For example, if a correspondence between keywords and functions has been established in advance, the target function can be determined through this correspondence. Another example is that the terminal device can input the keyword and prompt statement into a preset intelligent model. This intelligent model can analyze the input data to determine the probability values ​​of each function that matches the function corresponding to the keyword, and output the function with the highest probability as the target function. Other methods will not be listed here.

[0095] In the process of determining the above embedding position based on the target function, the terminal device can first determine the position of the target function in the C++ code, then extract the context code at this position and perform semantic analysis to determine the embedding position corresponding to the Python code. Finally, the terminal device can embed the Python code as a string constant into the C++ code according to this embedding position to obtain mixed code.

[0096] In addition, the C++ code and Python code obtained by the terminal device can be written by the same developer, or they can be written by different developers, such as one developer being responsible for writing the C++ code and another developer being responsible for writing the Python code. When multiple developers are responsible for writing C++ code and Python code respectively, the written C++ code and Python code need to be aggregated into the same terminal device.

[0097] Whether the developer actively declares the embedding position of Python code in C++ code or the terminal device automatically analyzes the embedding position of Python code in C++ code, after receiving the aggregated C++ code or Python code, the terminal device can generate a code mixing task for C++ code and Python code, and then determine the embedding position of Python code in C++ code through the above method to generate mixed code, and further generate the final executable file.

[0098] After completing the above obfuscation process, the generated executable file can be further distributed to each user, so as to provide the required target service to each user through the executable file. The following describes a service execution specification 7 / 12 pages 10 CN 121256756 A method provided in this specification.

[0099] Figure 2 is a schematic diagram of the steps involved in the service execution method provided in this specification, which specifically includes the following steps:

[0100] S200: Obtain the executable file.

[0101] In this specification, the execution subject of the business execution method can be a terminal device used by the user, such as a desktop computer or a laptop computer, or a device such as a server or a server cluster (when the execution subject is a server or a server cluster, it can be understood that after the developer develops the executable file, it provides it to the business party to which the server or server cluster belongs, so that the business party can execute the required target business based on the executable file). For ease of explanation, the following only uses a server as an example to describe the business execution method provided in this specification. The server can receive the executable file released by the developer or the developer's developer, so that the target task can be executed through the executable file in the subsequent process. The executable file is generated by the above-mentioned code obfuscation method.

[0102] S202: When executing the target business by running the executable file, the executable file is loaded into a preset memory, and the interpreter corresponding to the second language code is started.

[0103] When executing the target business by running the executable file, the above-mentioned pybind11 is used to start the Python interpreter. During the execution of C++ code, the Python interpreter can be started using a preset Resource Acquisition Is Initialization (RAII) class (such as py::scoped_interpreter) provided in the pybind11 library. This RAII class is used to safely and conveniently initialize and manage the lifecycle of the embedded Python interpreter in C++ code.

[0104] In practical applications, Python code that is a string constant is stored by the secure compiler in the read-only data segment (usually called .rodata) of the generated executable file. This data segment is specifically used to store constant data, which is read-only during program execution to prevent accidental modification.

[0105] When the above executable file is executed, the loader of the operating system in the server will load the executable file into the preset memory. Since the Python code is placed in the read-only data segment of the executable file, the Python code will be placed in the read-only area of ​​the preset memory.

[0106] In traditional implementations, Python code is often stored as an independent file in a preset file system or disk. Therefore, when executing C++ code, if Python code needs to be called, the required Python code needs to be read from the default file system or disk.

[0107] However, when Python code is stored in the default file system or disk, some attackers may exploit web application vulnerabilities or system vulnerabilities to gain access to the server, and then directly read and download bytecode from the file system or disk, resulting in the leakage of core information such as the developer's core algorithms, business logic, and proprietary technologies.

[0108] Storing Python code in preset memory in the above manner can effectively protect the Python code. Storing Python code in preset memory does not mean that it is impossible to obtain Python code from preset memory by any means, but rather that it is much more difficult for attackers to steal data from memory than directly from the default file system or disk. This is mainly because even if an attacker can monitor memory, they must capture a memory snapshot at the correct time (i.e., before the Python code has been compiled but not yet reclaimed by the Python virtual machine). This time window is very short, significantly increasing the difficulty of capturing the snapshot. Therefore, in this specification, Python code is written as a string constant into the C++ code.

[0109] S204: When the first language code calls the second language code, the second language code is executed through the interpreter to obtain the execution result.

[0110] In practical applications, C++ code may need to call different Python functions during execution to meet different data processing requirements. Therefore, after initializing the Python interpreter through pybind11, various functional modules can be created through the Python interpreter. Different functional modules are used to provide different Python functions. Therefore, during the execution of Python code, the functional module to be called can be determined from these functional modules as the target module. Then, the parameters transmitted by the C++ code are processed by calling the Python function provided in the target module to obtain the execution result.

[0111] It should be noted that since C++ and Python are two different programming languages, they differ in data types. Therefore, in order to enable interaction between C++ code and Python code, the data type of the parameters transmitted by C++ code needs to be converted to the data type specified by Python, that is, the data type that Python code can process.

[0112] Therefore, in this specification, during the execution of the executable file, it is necessary to first determine the parameters that the C++ code needs to transmit when calling the Python code. Then, through the aforementioned pybind11, the data type of the parameter is converted to the data type specified by Python to obtain the converted parameter. Finally, by calling the aforementioned target module, the converted parameter is processed by the Python function in the target module to obtain the execution result.

[0113] In addition, since the Python code is embedded in the C++ code, the C++ code belongs to the main program, so the execution of the Python code needs to be based on the Python virtual machine.

[0114] Specifically, the aforementioned Python interpreter can create the compilation module required to compile the Python code, and through the compilation module, the Python code can be compiled to obtain the bytecode corresponding to the Python code. Then, through the preset Python virtual machine, the bytecode is executed, thereby determining the functional module to be called from the aforementioned functional modules as the target module. And by calling the Python function in the target module, the parameters passed by the C++ code (i.e., the aforementioned converted parameters) are processed to obtain the execution result.

[0115] In this specification, the Python interpreter allocates a storage location in preset memory for the bytecode compiled by the above-mentioned compilation module through the memory allocator. Therefore, during the execution of the bytecode, the Python virtual machine can read the required bytecode from the storage location and execute it.

[0116] In this process, the Python virtual machine does not execute the bytecode immediately after reading it. Instead, it copies the bytecode from the storage location and allocates a storage space (such as the method area / metaspace) for the bytecode in the memory space managed by the Python virtual machine, and then caches the bytecode in the storage space. After that, the bytecode needs to be security verified to determine whether the bytecode is safe. Only after the bytecode passes the security verification can it be executed.

[0117] After obtaining the execution result through the Python virtual machine, the execution result needs to be sent back to the C++ code so that the C++ code can continue to execute the subsequent code parts after obtaining the execution result. In this process, since Python code and C++ code are different programming languages, the server needs to use pybind11 to convert the execution results obtained by the Python virtual machine into the data format or data type required by C++ before sending them back to the C++ code for execution. This process has already been explained in detail with examples when introducing pybind11 above, so it will not be repeated here.

[0118] After the execution of the Python code is completed, the Python interpreter can be released through pybind11, and the various resources occupied by the Python interpreter can be released. When the Python code needs to be called again, the Python interpreter is initialized and started through pybind11, and the Python code is executed based on the Python interpreter.

[0119] For further description, the entire business execution process will be further explained by connecting the preparation stage and the actual execution stage in the process of executing the executable file, as shown in Figures 3 and 4.

[0120] Figure 3 is a schematic diagram of the preparation stage in a business execution provided in this specification. Specification 9 / 12 pages 12 CN 121256756 A

[0121] The preparation stage shown in Figure 3 is mainly divided into four sub-stages. In Phase 1, when C++ code calls Python code, the initialization of the Python interpreter can be triggered by Python 11. This phase mainly uses the RAII class py::scoped_interpreter to trigger the initialization of the Python interpreter by pybind11, which in turn can complete the initialization of the Python interpreter by calling the Py_InitializeEx() function.

[0122] In Phase 2, the Python interpreter performs the core initialization actions, which mainly involve two aspects. One is the initialization of the memory allocator, which is used to allocate storage locations in memory for the compiled bytecode in subsequent processes. The other is the creation of the Global Interpreter Lock (GIL) to ensure that errors do not occur due to multiple threads accessing or competing for modification of the same object at the same time.

[0123] In stage three, the Python interpreter loads various built-in modules required to execute Python code. These built-in modules include the compiler modules mentioned above and various function modules that provide different functions of Python. At the same time, these loaded built-in modules also need to register their identification information in the module table. The module table can maintain these built-in modules and provide a query basis when calling these built-in modules in the future, so that the built-in modules to be used can be queried based on the module table during the execution of Python code.

[0124] In stage four, after the Python interpreter completes initialization, it returns information to pybind11 to indicate that the initialization is successful. Once the initialization is completed, the entire environment is ready, and Python code can be executed.

[0125] Figure 4 is a schematic diagram of the actual execution stage in the business execution process provided in this specification.

[0126] In the actual execution stage shown in Figure 4, the Python code first needs to be compiled by a compilation module created based on the Python interpreter. This compilation process is mainly divided into three steps. First, the Python code needs to be parsed to extract word units such as keywords and variable names from the Python code, and to verify whether the combination of these word units conforms to the syntax rules of Python. After the Python code is verified, an AST can be generated, and based on the AST, the bytecode corresponding to the Python code can be generated.

[0127] After obtaining the bytecode, the bytecode can be cached in the storage location allocated in memory based on the memory allocator mentioned above, and the Python virtual machine can read the bytecode from the storage location and execute it. In this process, the Python virtual machine will convert the bytecode into machine code, so that the CPU can obtain the execution result by executing the machine code.

[0128] It should be noted that, as mentioned at the beginning, the code obfuscation and business execution methods provided in this specification are mainly illustrated by embedding Python code in C++ code. In practical applications, the first language code and the second language code can also be in other forms. Therefore, the methods provided in this specification are also applicable to the mixing of code written in other different programming languages. For example, Lua code can be embedded in C++ code. Similarly, Lua code is first written into C++ code as a constant string to obtain mixed code. When executing the executable file corresponding to the mixed code, the executable file is first loaded into memory, and the Lua code is compiled into bytecode and executed by the interpreter corresponding to the Lua code that is started. Other combinations will not be illustrated here.

[0129] Figure 5 is a schematic structural diagram of a device provided in this specification. Referring to Figure 5, at the hardware level, the device includes a processor 502, an internal bus 504, a network interface 506, a memory 508, and a non-volatile memory 510. Of course, it may also include other hardware required for other functions. One or more embodiments of this specification can be implemented in software, such as by processor 502 reading the corresponding computer program from non-volatile memory 510 into memory 508 and then running it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0130] Please refer to Figure 6. A code obfuscation device provided in this specification can be applied to the device shown in Figure 5 to implement the technical solution of this specification. The device includes:

[0131] an acquisition module 600, used to acquire a first language code and a second language code to be mixed. The first language code is used to provide a target service. When the target service is executed, the second language code is called by the first language code to implement the specified function required when executing the target service. The first language code is compiled into machine code and executed by the operating system on which the first language code is based. The second language code is compiled into bytecode by the interpreter corresponding to the second language code and executed;

[0132] a mixing module 602, used to write the second language code as a string constant in the first language code into the first language code to obtain mixed code;

[0133] an obfuscation module 604, used to obfuscate the mixed code through a preset security compiler to obtain an executable file corresponding to the mixed code.

[0134] Optionally, the hybrid module 602 is specifically used to: determine the functional description text of the second language code; perform semantic analysis on the functional description text to determine keywords used to describe functional characteristics; determine, according to the keywords, a target function in the first language code for calling the second language code to implement the specified function; determine, according to the target function, the embedding position corresponding to the second language code; and, according to the embedding position, write the second language code as a string constant in the first language code into the first language code to obtain hybrid code.

[0135] Optionally, the first language code includes C++ code or C code, and the second language code includes Python code. When the second language code is Python code, the interpreter is a Python interpreter.

[0136] Please refer to Figure 7. A business execution device provided in this specification can be applied to the device shown in Figure 5 to implement the technical solution of this specification. The device includes:

[0137] an acquisition module 700, used to acquire an executable file. The executable file is obtained by obfuscating the mixed code through a preset security compiler. The mixed code is obtained by writing the second language code as a string constant into the first language code. The first language code is used to provide a target business. The second language code is called by the first language code to implement the specified function required when executing the target business. The first language code is compiled into machine code and executed by the operating system on which the first language code is based. The second language code is compiled into bytecode by the interpreter corresponding to the second language code and executed;

[0138] a startup module 702, used to load the executable file into a preset memory and start the interpreter corresponding to the second language code when executing the target business by running the executable file;

[0139] an execution module 704, used to execute the second language code through the interpreter when the first language code calls the second language code to obtain the execution result.

[0140] Optionally, the first language code includes C++ code or C code, and the second language code includes Python code. When the second language code is Python code, the interpreter is a Python interpreter.

[0141] The execution module 704 is specifically used to initialize the Python interpreter through pybind11 when the first language code calls the second language code, and create various functional modules through the Python interpreter. Different functional modules are used to provide different Python functions. Execute the Python code to determine the functional module to be called from the various functional modules as the target module, and obtain the execution result by calling the Python function provided in the target module.

[0142] Optionally, the execution module 704 is specifically used to determine the parameters that the first language code needs to transmit when calling the second language code; convert the data type of the parameters to the data type specified by Python through pybind11 to obtain the converted parameters; call the target module to process the converted parameters through the Python function in the target module to obtain the execution result.

[0143] Optionally, the execution module 704 is specifically used to compile the second language code through a compilation module created by the Python interpreter to obtain bytecode corresponding to the second language code; and to execute the bytecode through a preset Python virtual machine to determine the functional module to be called from the functional modules as the target module.

[0144] Based on the same concept as the above method, this specification also provides an electronic device, including: a processor; a memory for storing processor-executable instructions; wherein the processor implements the steps of the method as described in any of the above embodiments by running the executable instructions.

[0145] Based on the same concept as the above method, this specification also provides a computer-readable storage medium storing computer instructions thereon, which, when executed by a processor, implement the steps of the method as described in any of the above embodiments.

[0146] Based on the same concept as the above method, this specification also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the method as described in any of the above embodiments.

[0147] This specification can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0148] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the description of the method embodiments.

[0149] The above are merely embodiments of this specification and are not intended to limit this specification. Various modifications and variations can be made to this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims of this specification.Instruction manual 12 / 12 pages 15 CN 121256756 A Figure 1 Figure 2 Instruction manual drawing 1 / 5 pages 16 CN 121256756 A Figure 3 Instruction manual drawing 2 / 5 pages 17 CN 121256756 A Figure 4 Instruction manual drawing 3 / 5 pages 18 CN 121256756 A Figure 5 Figure 6 Instruction manual drawing 4 / 5 pages 19 CN 121256756 A Figure 7 Instruction manual drawing 5 / 5 pages 20 CN 121256756 A Abstract equipment and product The invention discloses a code obfuscation method, a business execution method, a medium, equipment and a product. According to the scheme, the to-be-mixed first language code and the to-be-mixed second language code are firstly obtained, then the second language code serves as the character string constant in the first language code and is written into the first language code, the mixed code is obtained, finally, the mixed code is subjected to obfuscation processing through the preset security compiler, and the safety of the mixed code is improved. And obtaining an executable file corresponding to the mixed code..

Claims

1. A code obfuscation method, comprising: Obtain the first language code and the second language code to be mixed. The first language code is used to provide the target service. When the target service is executed, the second language code is called by the first language code to realize the specified function required when executing the target service. The first language code is compiled into machine code and executed by the operating system on which the first language code is based. The second language code is compiled into bytecode by the interpreter corresponding to the second language code and executed. The second language code is written into the first language code as a string constant, resulting in hybrid code; The mixed code is obfuscated using a preset security compiler to obtain the executable file corresponding to the mixed code.

2. The method as described in claim 1, wherein the second language code is written as a string constant in the first language code into the first language code to obtain hybrid code, specifically includes: Determine the functional description text of the second language code; Semantic analysis is performed on the functional description text to identify keywords used to describe the functional characteristics; Based on the keywords, a target function is determined in the first language code for calling the second language code to implement the specified function; Based on the target function, determine the embedding position corresponding to the second language code; Based on the embedding location, the second language code is written into the first language code as a string constant in the first language code to obtain the hybrid code.

3. The method according to any one of claims 1 to 2, wherein the first language code includes C++ code or C code, the second language code includes Python code, and when the second language code is Python code, the interpreter is a Python interpreter.

4. A business execution method, comprising: An executable file is obtained by obfuscating the hybrid code using a preset security compiler. The hybrid code is obtained by writing the second language code as a string constant into the first language code. The first language code is used to provide the target business. The second language code is called by the first language code to implement the specified function required when executing the target business. The first language code is compiled into machine code and executed by the operating system on which the first language code is based. The second language code is compiled into bytecode by the interpreter corresponding to the second language code and executed. When executing the target service by running the executable file, the executable file is loaded into a preset memory, and the interpreter corresponding to the second language code is started; When the first language code calls the second language code, the second language code is executed through the interpreter to obtain the execution result.

5. The method as described in claim 4, wherein the first language code includes C++ code or C code, the second language code includes Python code, and when the second language code is Python code, the interpreter is a Python interpreter; When the first language code calls the second language code, the second language code is executed by the interpreter to obtain an execution result, specifically including: When the first language code calls the second language code, the Python interpreter is initialized through pybind11, and various functional modules are created through the Python interpreter. Different functional modules are used to provide different Python functions. The Python code is executed to determine the functional module to be called from the various functional modules, which is then used as the target module. The execution result is obtained by calling the Python function provided in the target module.

6. The method as described in claim 5, wherein the execution result is obtained by calling the Python function provided in the target module, specifically includes: Determine the parameters that the first language code needs to transmit when calling the second language code; Using pybind11, the data type of the parameter is converted to the data type specified by Python to obtain the converted parameter; The target module is invoked to process the transformed parameters through Python functions within the target module, thereby obtaining the execution result.

7. The method of claim 6, wherein executing the second language code to determine the functional module to be called from the functional modules as the target module, specifically includes: The compilation module created by the Python interpreter compiles the second language code to obtain the bytecode corresponding to the second language code; The bytecode is executed using a pre-defined Python virtual machine to determine the functional module to be called from among the various functional modules, which is then used as the target module.

8. An electronic device, comprising: processor; A memory for storing processor-executable instructions; wherein the processor implements the steps of the method as described in any one of claims 1 to 7 by executing the executable instructions.

9. A computer-readable storage medium having stored thereon computer instructions that, when executed by a processor, implement the steps of the method as claimed in any one of claims 1 to 7.

10. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the steps of the method as described in any one of claims 1 to 7.