Container-based Python code protection method, device, equipment and medium
By generating the random opcode in the out-of-order source code in the container environment, and using these opcodes to compile the engineering source code and generate the target bytecode, the problems of Python code leakage and decompilation are solved, and more efficient protection and authorization management are achieved.
Patent Information
- Application Number
- CN202111557813.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-16
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2041-12-16
AI Technical Summary
The explanatory nature of the Python language makes the source code unable to be encrypted directly. The source code needs to be released when publishing Python programs, which poses a risk of leakage. The source code can still be parsed through decompilation tools using bytecode files.
By generating random operation codes in the container environment, the operation code in the out-of-order source code is used to compile the engineering source code and generate the target byte code to ensure that the source code cannot be cracked by the decompilation tool.
It effectively improves the protection effect of Python code and prevents source code leakage. Due to random obfuscation, the target byte codes of different publishing channels cannot be universal, which enhances authorization management and avoids the situation of invoking external service.
Smart Images

Figure CN114329362B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, specifically to the field of programming language compilation technology, and in particular to a container-based Python code protection method, device, equipment and medium. Background Art
[0002] With the development of artificial intelligence technology, Python has become more and more popular, and a large number of algorithm applications and services are written in Python. However, Python is an interpreted language, and the code cannot be directly encrypted. If you want to publish a Python program, you are actually publishing the source code.
[0003] In the related art, it is considered to edit the Python language into a bytecode file (pyc file) to avoid source code leakage. Among them, the pyc file is a binary file, which is a file generated by compiling the py file. After the py file becomes a pyc file, the loading speed is improved, and the pyc file is a cross-platform bytecode, which is executed by the virtual machine of the Python language. However, the code cannot be read directly using the pyc file, but the pyc file can still be converted into a source code that is easy to read through a third-party tool, such as the open source uncompyle6. Therefore, protecting the code of the Python language is a problem that needs to be solved urgently. Summary of the invention
[0004] The present application provides a container-based Python code protection method, apparatus, device and medium, which realizes the protection of Python program content.
[0005] According to one aspect of the present application, a container-based Python code protection method is provided, comprising: creating a container environment for generating and running a Python program, wherein the container environment is configured with a source code set and dependency files of the Python language;
[0006] Obtaining a random operation code corresponding to the source code set in the current container environment, wherein the random operation code is obtained by randomly shuffling the source code set according to a random number sequence, and the random number sequence is determined by the current container environment;
[0007] The engineering source code recording the target Python program is obtained, and the engineering source code is compiled using the random operation code to obtain the target bytecode released to the user.
[0008] Optionally, obtaining a random operation code corresponding to the source code set in the container environment includes:
[0009] Obtaining current time data and the container serial number;
[0010] Generate the random number sequence using the time data and the container serial number as seeds;
[0011] The operation codes in the source code set are shuffled according to the random number sequence to obtain the random operation codes.
[0012] Optionally, the step of shuffling the operation codes in the source code set according to the random number sequence to obtain the random operation code includes:
[0013] Respectively obtaining the operation code and the serial number corresponding to the random number in the random number sequence;
[0014] For each operation code, a random value having the same number as the operation code is used as a new number position corresponding to the operation code.
[0015] Optionally, the step of shuffling the operation codes in the source code set according to the random number sequence to obtain the random operation code includes:
[0016] Obtain the number corresponding to the operation code;
[0017] The numbers corresponding to the operation codes are moved to positions corresponding to the random number sequence according to a preset rule to obtain new number positions corresponding to each of the operation codes.
[0018] Optionally, compiling the engineering source code using the random operation code to obtain a target bytecode to be released to a target user includes:
[0019] Based on the first mapping relationship between the opcode in the source code set and the random opcode, obtaining a second mapping relationship between the opcode and the bytecode;
[0020] Based on the second mapping relationship, the project source code is compiled into the target bytecode.
[0021] Optionally, the method further includes:
[0022] When running the Python program, parsing the target bytecode to obtain the random opcode;
[0023] Decoding the random operation code to obtain the engineering source code corresponding to the target bytecode;
[0024] Execute the project source code.
[0025] According to another aspect of the present application, a container-based Python code protection device is provided, comprising:
[0026] A creation module is used to create a container environment for generating and running Python programs, wherein the container environment is configured with a source code set and dependency files of the Python language;
[0027] An encryption module, used for obtaining a random operation code corresponding to the source code set in the current container environment, wherein the random operation code is obtained by randomly scrambling the source code set according to a random number sequence, and the random number sequence is determined by the current container environment;
[0028] The compiling module is used to obtain the engineering source code recording the target Python program, compile the engineering source code using the random operation code, and obtain the target bytecode released to the user.
[0029] Optionally, the device further comprises:
[0030] A parsing module, used for parsing the target bytecode to obtain the random operation code when running the Python program;
[0031] A decoding module, used for decoding the random operation code to obtain the engineering source code corresponding to the target bytecode;
[0032] The running module is used to execute the project source code.
[0033] According to another aspect of the present application, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the container-based Python code protection method of the present application.
[0034] According to another aspect of the present application, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the container-based Python code protection method for an electronic device disclosed in an embodiment of the present application.
[0035] The container-based Python code protection method, device, equipment and medium proposed in the embodiments of the present application compile the project source code according to a random number sequence, so that the project source code cannot be cracked by decompilation tools, thereby effectively improving the protection effect of the Python code. At the same time, since a random number sequence is generated by a container environment for running Python code for random obfuscation, the target bytecodes of different release channels cannot be used interchangeably, thereby effectively improving the authorization management of product releases and avoiding the situation where users exchange bytecodes to implement unauthorized service calls.
[0036] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present application.
[0038] Figure 1 It is a flowchart of a container-based Python code protection method proposed according to an embodiment of the present application;
[0039] Figure 2 This is a schematic diagram of the principle of disorderly operation codes proposed in an embodiment of the present application;
[0040] Figure 3 It is a schematic diagram of another operation code disorder principle proposed according to an embodiment of the present application;
[0041] Figure 4 This is a schematic diagram of the principle of a container-based Python code protection method proposed in an embodiment of the present application;
[0042] Figure 5 It is a block diagram of a protection device for Python code based on a container proposed in an embodiment of the present application;
[0043] Figure 6 It is a block diagram of another container-based Python code protection device proposed according to an embodiment of the present application;
[0044] Figure 7 It is a block diagram of an electronic device used to implement the container-based Python code protection method of an embodiment of the present application. DETAILED DESCRIPTION
[0045] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0046] The following describes a container-based Python code protection method, apparatus, device and medium according to an embodiment of the present application with reference to the accompanying drawings.
[0047] Figure 1It is a flowchart of a container-based Python code protection method proposed according to an embodiment of the present application. It should be noted that the execution subject of the container-based Python code protection method of this embodiment is a container-based Python code protection device, which can be implemented by software and / or hardware. The container-based Python code protection device in this embodiment can be configured in an electronic device, or in a server for controlling the electronic device, which communicates with the electronic device and controls it.
[0048] Among them, the electronic device in this embodiment may include but is not limited to personal computers, platform computers, smart phones and other devices, and this embodiment does not specifically limit the electronic device.
[0049] like Figure 1 As shown, the container-based Python code protection method may include:
[0050] Step 101, creating a container for generating and running Python programs, wherein the container environment is configured with a source code set and dependency files of the Python language.
[0051] Among them, the container environment is a virtualized operating environment that uses a sandbox mechanism and has no interfaces between each other.
[0052] Source code is the original code, which refers to an uncompiled text file written in a certain programming language specification. It is a series of human-readable computer language instructions. There are two main functions of source code. One is to generate target code, that is, code that can be recognized by the computer, and the other is to explain the software, that is, to explain the writing of the software.
[0053] Dependency is used to describe a "use and being used" relationship between "classes". Therefore, in order to ensure the effective operation of Python programs, Python language dependency files need to be installed in the container environment. It should be noted that dependency files are usually limited to dependency files used to enable the target Python program to run effectively.
[0054] Step 102, obtaining a random operation code corresponding to the source code set in the current container environment, wherein the random operation code is obtained by randomly shuffling the source code set according to a random number sequence, and the random number sequence is determined by the current container environment.
[0055] That is to say, in the current container environment, the present application changes the mapping relationship between the opcode and the bytecode by randomly scrambling the opcode, thereby making it impossible to obtain the accurate engineering source code from the bytecode decoding.
[0056] Specifically, obtaining the random operation code corresponding to the source code set in the container environment includes: obtaining the current time data and the container serial number; generating a random number sequence using the time data and the container serial number as seeds; and shuffling the operation codes in the source code set according to the random number sequence to obtain the random operation code.
[0057] The current time data may be the current time of building the container environment, or the time of shuffling the opcode. It should also be noted that in the embodiment of the present application, shuffling the source code set requires shuffling the dependent files, that is, the random opcodes after shuffling can still satisfy the call to the dependency.
[0058] It should be understood that since the random opcode is constructed using the current time data and container serial number related to the container environment, the random number sequence generated based on the time data and the container serial number has better confidentiality, that is, it is more difficult for reverse users to obtain the seed used to generate the random number sequence.
[0059] Optionally, the opcodes in the source code set are shuffled according to a random number sequence to obtain random opcodes, including but not limited to, when the random number is a value, converting the position of the opcode sequence according to a preset rule, for example, when the random number is 2, each opcode is moved backward by two positions as a whole, and the last two opcodes are moved to the first two positions of the opcode sequence accordingly; when the random number is multiple values, the position of the opcode can be changed according to the random value.
[0060] Step 103, obtain the engineering source code recording the target Python program, compile the engineering source code using the random operation code, and obtain the target bytecode released to the user.
[0061] Among them, the engineering source code of the target Python program is the code file that needs to be protected.
[0062] That is to say, the present application changes the traditional method of compiling the engineering source code by using the mapping relationship between the opcode and the bytecode to compiling the engineering source code by using the mapping relationship between the encrypted random opcode and the bytecode.
[0063] Specifically, when creating a container environment for generating and running Python programs, the source code set and dependent files of the Python language are configured in the container environment to ensure that the target bytecode can run accurately and stably in the container environment. Then, the random opcode corresponding to the source code set in the current container environment is obtained, so that the compilation of the engineering source code of the target Python program is based on the container environment, which improves the dependence of the Python program on the environment and reduces unauthorized service calls. Then, according to the engineering source code of the target Python program, the engineering source code is compiled using the random opcode to obtain the target bytecode released to the user, and finally the encryption protection of the Python program is realized.
[0064] Therefore, the container-based Python code protection method proposed in the embodiment of the present application, by compiling the project source code according to a random number sequence, makes the project source code impossible to be cracked by decompilation tools, thereby effectively improving the protection effect of the Python code. At the same time, since a random number sequence is generated by a container environment running the Python code for random obfuscation, the target bytecodes of different release channels cannot be used interchangeably, effectively improving the authorization management of product releases and avoiding the situation where users exchange bytecodes to implement unauthorized service calls.
[0065] As a feasible embodiment, the opcodes in the source code set are shuffled according to a random number sequence to obtain random opcodes, including: obtaining the opcodes and the numbers corresponding to the random numbers in the random number sequence respectively; for each opcode, using the random value that is the same as its number as the new number position corresponding to the opcode.
[0066] In this embodiment, the number of random numbers in the random number sequence is the same as the number of the operation number sequence, and multiple random numbers in the random number sequence are not equal.
[0067] Specifically, the operation code and the random number sequence are numbered respectively, and then a mapping relationship between the operation code and the random number sequence is established based on the number, that is, it is determined that there is a mapping relationship between the operation code and the random number with the same number, and at this time, the random number with the same number is used as the new number position corresponding to the operation code. The operation code sequence formed according to the new number position is a random operation code sequence.
[0068] For example, if Figure 2 As shown, column 1 is the number column of the operation code, column 2 is the operation code column, column 3 is the number column of the random number sequence, column 4 is the random number column, and column 5 is the random operation code column adjusted according to the random number. Figure 2 It can be seen that the operation code OP1 is adjusted from the first to the third after being shuffled by the random number sequence, thereby effectively achieving the purpose of randomly changing the operation code position information.
[0069] In one or more embodiments, the opcodes in the source code set are shuffled according to a random number sequence to obtain random opcodes, including: obtaining the number corresponding to the opcode, moving the number corresponding to the opcode to the position corresponding to the random number sequence according to a preset rule, and obtaining a new number position corresponding to each opcode.
[0070] That is to say, in the embodiment of the present application, the operation code is moved as a whole according to the value corresponding to the random number sequence. In the embodiment of the present application, the random number sequence corresponds to a random value.
[0071] For example, if Figure 3 As shown, when the random value corresponding to the random number sequence is 2, there is a random number 2 in the entire random number sequence that is the same as the number of operation codes. At this time, if the preset rule is to move forward, each operation code in the entire operation code sequence moves forward by two positions, that is, the operation code originally numbered 3 moves to the position numbered 1, that is, the new number position corresponding to the operation code OP3 is 1, and the first two operation codes in the operation code sequence move to the end of the entire operation code sequence. If the preset rule is to move backward, each operation code in the entire operation code sequence moves backward by two positions, that is, the operation code originally numbered 3 moves to the position numbered 5.
[0072] It should be understood that the out-of-order operation of the opcode according to the random number sequence can be set according to the actual situation, or the out-of-order rule can be randomly selected when building the container environment, further increasing the difficulty of decompiling the target bytecode.
[0073] In one or more feasible embodiments, random opcodes are used to compile the project source code to obtain target bytecodes that are released to target users, including: based on a first mapping relationship between opcodes in a source code set and random opcodes, a second mapping relationship between opcodes and bytecodes is obtained; based on the second mapping relationship, the project source code is compiled into target bytecodes.
[0074] The first mapping relationship may be a random value, that is, a random value that adjusts the operation code to a random operation code position in a random number sequence, and the second mapping relationship is generated based on the first mapping relationship, and the second mapping relationship may be the same as the first mapping relationship.
[0075] It should be understood that, since there is a regular mapping relationship between the bytecode and the opcode when no encryption protection is performed, when the opcode is converted into a random opcode based on the first mapping relationship, a second mapping relationship is formed between the bytecode and the random opcode based on the change in the opcode.
[0076] For example, if Figure 2As shown, the operation code OP1 is converted into the random operation code OP1' based on the first mapping relationship (random number 3), so that the byte code PYC3 is mapped with the random operation code OP1' based on the second mapping relationship.
[0077] That is to say, the present application changes the mapping relationship between bytecodes and opcodes based on a random number sequence. For example, the bytecode PYC3 originally corresponding to the opcode OP3 is randomly converted into a mapping relationship with the opcode OP1 based on a random number sequence. In the reverse direction, since the random number sequence used for compilation cannot be accurately obtained, the published target bytecode cannot be effectively decoded to obtain an easy-to-read engineering source code.
[0078] In one or more embodiments, the method further includes: when running the Python program, parsing the target bytecode to obtain a random opcode, decoding the random opcode to obtain an engineering source code corresponding to the target bytecode, and executing the engineering source code.
[0079] That is to say, when executing the target bytecode, the container environment also needs to decode the target bytecode to obtain the engineering source code that records the target Python program, and then execute it according to the engineering source code to ensure that the executed content is what the customer needs.
[0080] Furthermore, if Figure 4 As shown, the applicant builds a container D, configures a source code set S and a dependent file DP in the container D, determines the time T and the container serial number M for building the container environment, generates a random number sequence R according to the time T and the container serial number M, takes the source code set S as the basis and the dependent file DP as the dependency, and obtains a random opcode set S' by shuffling the random number sequence R, wherein the random opcode set S' constitutes a customized Python program P' corresponding to the container D, compiles the engineering source code PY using the customized Python program P' (random opcode set S') to obtain the target bytecode PYC', compiles the engineering source code PY using the publicly released Python program P (opcode set S) to obtain the bytecode PYC, and after verification, the running results of running the target bytecode PYC' in the container D are the same as those of running PYC in the container D.
[0081] In summary, the container-based Python code protection method proposed in the embodiment of the present application compiles the project source code according to a random number sequence, so that the project source code cannot be cracked by decompilation tools, thereby effectively improving the protection effect of the Python code. At the same time, since a random number sequence is generated by a container environment for running Python code for random obfuscation, the target bytecodes of different release channels cannot be used interchangeably, which effectively improves the authorization management of product releases and avoids the situation where users exchange bytecodes to implement unauthorized service calls.
[0082] Figure 5 A block diagram of a protection device for container-based Python code according to an embodiment of the present application.
[0083] like Figure 5 As shown, the container-based Python code protection device 10 includes:
[0084] A creation module 11 is used to create a container environment for generating and running Python programs, wherein the container environment is configured with a source code set and dependency files of the Python language;
[0085] An encryption module 12 is used to obtain a random operation code corresponding to the source code set in the current container environment, wherein the random operation code is obtained by randomly scrambling the source code set according to a random number sequence, and the random number sequence is determined by the current container environment;
[0086] The compiling module 13 is used to obtain the engineering source code recording the target Python program, and compile the engineering source code using the random operation code to obtain the target bytecode released to the user.
[0087] In some embodiments, the encryption module 12 is further configured to:
[0088] Obtaining current time data and the container serial number;
[0089] Generate the random number sequence using the time data and the container serial number as seeds;
[0090] The operation codes in the source code set are shuffled according to the random number sequence to obtain the random operation codes.
[0091] In some embodiments, the encryption module 12 is further configured to:
[0092] Respectively obtaining the operation code and the serial number corresponding to the random number in the random number sequence;
[0093] For each operation code, a random value having the same number as the operation code is used as a new number position corresponding to the operation code.
[0094] In some embodiments, the encryption module 12 is further configured to:
[0095] Obtain the number corresponding to the operation code;
[0096] The numbers corresponding to the operation codes are moved to positions corresponding to the random number sequence according to a preset rule to obtain new number positions corresponding to each of the operation codes.
[0097] In some embodiments, the encryption module 12 is further configured to:
[0098] Based on the first mapping relationship between the opcode in the source code set and the random opcode, obtaining a second mapping relationship between the opcode and the bytecode;
[0099] Based on the second mapping relationship, the project source code is compiled into the target bytecode.
[0100] like Figure 6 As shown, the container-based Python code protection device 10 further includes:
[0101] A parsing module 14, used for parsing the target bytecode to obtain the random operation code when running the Python program;
[0102] A decoding module 15, used for decoding the random operation code to obtain the engineering source code corresponding to the target bytecode;
[0103] The running module 16 is used to execute the engineering source code.
[0104] It should be noted that the aforementioned explanation of the embodiment of the container-based Python code protection method is also applicable to the container-based Python code protection device in this embodiment, and will not be repeated here.
[0105] In summary, the container-based Python code protection device proposed in the embodiment of the present application compiles the project source code according to a random number sequence, so that the project source code cannot be cracked by decompilation tools, thereby effectively improving the protection effect of the Python code. At the same time, since a random number sequence is generated by a container environment for running Python code for random obfuscation, the target bytecodes of different release channels cannot be used interchangeably, which effectively improves the authorization management of product releases and avoids the situation where users exchange bytecodes to implement unauthorized service calls.
[0106] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.
[0107] like Figure 7 , is a block diagram of an electronic device according to a protection method of a Python code based on a container according to an embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples, and are not intended to limit the implementation of the present application described herein and / or required.
[0108] like Figure 7 As shown, the electronic device includes: one or more processors 701, a memory 702, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are interconnected using different buses and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the electronic device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In other embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple electronic devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 701 is taken as an example.
[0109] The memory 702 is a non-transient computer-readable storage medium provided in the present application. The memory stores instructions executable by at least one processor to enable the at least one processor to execute the container-based Python code protection method provided in the present application. The non-transient computer-readable storage medium of the present application stores computer instructions, which are used to enable a computer to execute the container-based Python code protection method provided in the present application.
[0110] The memory 702 is a non-transient computer-readable storage medium that can be used to store non-transient software programs, non-transient computer executable programs and modules, such as the program instructions / modules corresponding to the container-based Python code protection method in the embodiment of the present application (for example, the attached Figure 5 The processor 701 executes various functional applications and data processing of the server by running the non-transient software programs, instructions and modules stored in the memory 702, that is, the container-based Python code protection method in the above method embodiment is implemented.
[0111] The memory 702 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the use of an electronic device based on a container-based Python code protection method, etc. In addition, the memory 702 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory 702 may optionally include a memory remotely disposed relative to the processor 701, and these remote memories may be connected to the electronic device of the container-based Python code protection method via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0112] The electronic device of the container-based Python code protection method may further include: an input device 703 and an output device 704. The processor 701, the memory 702, the input device 703 and the output device 704 may be connected via a bus or other means. Figure 7 The example of connecting through bus is taken in the following.
[0113] The input device 703 can receive input digital or character information, and generate key signal input related to user settings and function control of the electronic device of the container-based Python code protection method, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator rod, one or more mouse buttons, a trackball, a joystick and other input devices. The output device 704 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The display device may include, but is not limited to, a liquid crystal display (LCD), a light emitting diode (LED) display and a plasma display. In some embodiments, the display device may be a touch screen.
[0114] Various implementations of the systems and techniques described herein can be realized in digital electronic circuit systems, integrated circuit systems, dedicated ASICs (application specific integrated circuits), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0115] These computer programs (also referred to as programs, software, software applications, or code) include machine instructions for programmable processors and can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or means (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0116] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0117] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0118] A computer system may include clients and servers. Clients and servers are generally remote from each other and typically interact through a communication network. The relationship of client and server arises through computer programs running on the respective computers and having a client-server relationship to each other.
[0119] The container-based Python code protection method, device, equipment and medium proposed in the embodiments of the present application compile the project source code according to a random number sequence, so that the project source code cannot be cracked by decompilation tools, thereby effectively improving the protection effect of the Python code. At the same time, since a random number sequence is generated by a container environment for running Python code for random obfuscation, the target bytecodes of different release channels cannot be used interchangeably, thereby effectively improving the authorization management of product releases and avoiding the situation where users exchange bytecodes to implement unauthorized service calls.
[0120] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.
[0121] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.
Claims
1. A container-based Python code protection method, characterized in that: The following steps are involved: Creating a container environment for generating and running Python programs, wherein the container environment is configured with a source code set and dependency files of the Python language; Obtaining a random operation code corresponding to the source code set in the current container environment, wherein the random operation code is obtained by randomly shuffling the source code set according to a random number sequence, and the random number sequence is determined by the current container environment; Obtaining the engineering source code recording the target Python program, compiling the engineering source code using the random operation code, and obtaining the target bytecode released to the user; Among them, obtaining the random operation code corresponding to the source code set in the container environment includes: obtaining the current time data and the container serial number; generating the random number sequence with the time data and the container serial number as seeds; and scrambling the operation codes in the source code set according to the random number sequence to obtain the random operation code.
2. The method according to claim 1, characterized in that The step of shuffling the operation codes in the source code set according to the random number sequence to obtain the random operation codes includes: Respectively obtaining the operation code and the serial number corresponding to the random number in the random number sequence; For each operation code, a random value having the same number as the operation code is used as a new number position corresponding to the operation code.
3. The method according to claim 1, characterized in that The step of shuffling the operation codes in the source code set according to the random number sequence to obtain the random operation codes includes: Obtain the number corresponding to the operation code; The numbers corresponding to the operation codes are moved to positions corresponding to the random number sequence according to a preset rule to obtain new number positions corresponding to each of the operation codes.
4. The method according to claim 1, characterized in that: The process of compiling the engineering source code using the random operation code to obtain the target bytecode to be released to the target user includes: Based on the first mapping relationship between the opcode in the source code set and the random opcode, obtaining a second mapping relationship between the opcode and the bytecode; Based on the second mapping relationship, the project source code is compiled into the target bytecode.
5. The method according to claim 1, characterized in that Also includes: When running the Python program, parsing the target bytecode to obtain the random opcode; Decoding the random operation code to obtain the engineering source code corresponding to the target bytecode; Execute the project source code.
6. A container-based Python code protection device, characterized in that: include: A creation module is used to create a container environment for generating and running Python programs, wherein the container environment is configured with a source code set and dependency files of the Python language; An encryption module, used for obtaining a random operation code corresponding to the source code set in the current container environment, wherein the random operation code is obtained by randomly scrambling the source code set according to a random number sequence, and the random number sequence is determined by the current container environment; A compiling module, used to obtain the engineering source code recording the target Python program, and compile the engineering source code using the random operation code to obtain the target bytecode released to the user; The encryption module is also used to: obtain current time data and the container serial number; The random number sequence is generated by taking the time data and the container serial number as seeds; and the operation codes in the source code set are shuffled according to the random number sequence to obtain the random operation codes.
7. The device according to claim 6, characterized in that Also includes: A parsing module, used for parsing the target bytecode to obtain the random operation code when running the Python program; A decoding module, used for decoding the random operation code to obtain the engineering source code corresponding to the target bytecode; The running module is used to execute the project source code.
8. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the container-based Python code protection method according to any one of claims 1 to 5.
9. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to enable the computer to execute the container-based Python code protection method according to any one of claims 1 to 5.