Code protection method, device, electronic device and readable storage medium

By generating a code file selection interface, judging the encryption of the code file and converting it into static type code, the problem of easy-to-break Python code protection methods in the existing technology is solved, and efficient and secure protection of the code file is achieved.

CN112966228BActive Publication Date: 2025-05-13TIANMIAN INFORMATION TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110248627.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-05
Publication Date
2025-05-13
Estimated Expiration
2041-03-05

AI Technical Summary

Technical Problem

The existing Python code protection methods have the problem that encryption tools can crack and package tools are easy to unpack, resulting in insufficient code security.

Method used

By parsing the user's code protection request, a code file selection interface is generated, a code file selection interface is determined, and the encryptable code file is converted into static type code, compiled into an unbreakable dynamic link library file, and other code files are compiled into .pyc files to form the target file.

Benefits of technology

It realizes comprehensive protection of Python code, avoids the problem of not being able to run normally after encryption, improves the security of code files, and allows it to not disclose source code content when used by multiple parties.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112966228B_ABST
    Figure CN112966228B_ABST
Patent Text Reader

Abstract

The present invention relates to data processing, and discloses a code protection method, including: generating a code file selection interface according to a storage address carried by a code protection request; receiving a code file to be protected selected by a user based on the code file selection interface, and judging whether the code file to be protected can be encrypted; storing the code file judged to be encryptable in the storage space corresponding to the storage address to a first folder, and storing the remaining code files in the storage space corresponding to the storage address to a second folder; converting the code in each code file in the first folder into a static type of code, compiling the converted code file into a file of the first type, compiling each code file in the second folder into a file of the second type, and aggregating the files of the first type and the second type to obtain a target file. The present invention also provides a code protection device, an electronic device, and a readable storage medium. The present invention comprehensively improves the code security.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing, and in particular to a code protection method, device, electronic device and readable storage medium. Background Art

[0002] With the development of science and technology, codes have been integrated into people's lives. For example, Python codes are used to develop games, control robots, and perform cloud computing. Python is an interpreted language, and its code files are similar to text files. You can use a text editor to open its code files to view the source code, which can lead to the leakage of Python codes.

[0003] In order to improve the security of Python code, the following two code protection schemes are usually adopted:

[0004] 1. Use encryption tools to encrypt Python code files;

[0005] 2. Use the packaging tool to package the Python code file into an exe executable file.

[0006] For solution 1, existing Python encryption tools can usually be cracked or can only encrypt some files; for solution 2, you can understand the packaging process by reading the packaging tool source code, and then unpack it according to the reverse process. Therefore, a code protection method is urgently needed to comprehensively improve code security. Summary of the invention

[0007] In view of the above, it is necessary to provide a code protection method to comprehensively improve code security.

[0008] The code protection method provided by the present invention is applied to electronic equipment, and the method comprises:

[0009] Parse a code protection request issued by a user based on a client, obtain a storage address of a code file carried in the request, obtain names of all code files stored in a storage space corresponding to the storage address, and generate a code file selection interface based on the names;

[0010] Displaying the code file selection interface on the client interface, receiving the code file to be protected selected by the user based on the code file selection interface, and determining whether the code file to be protected can be encrypted;

[0011] The code files determined to be encryptable in the storage space corresponding to the storage address are stored in a first folder, and the remaining code files in the storage space corresponding to the storage address are stored in a second folder;

[0012] Convert the code in each code file in the first folder into a static type of code, compile the converted code file into a first type of file, compile each code file in the second folder into a second type of file, aggregate the first type and second type of files, and obtain a target file.

[0013] Optionally, the determining whether the code file to be protected is encryptable includes:

[0014] Obtaining encryption judgment rules from a preset database, and judging whether the code in the code file to be protected complies with the encryption judgment rules;

[0015] When it is determined that the code in a certain designated code file meets the encryption judgment rule, it is considered that the designated code file can be encrypted.

[0016] Optionally, after determining whether the code in the code file to be protected complies with the encryption determination rule, the method further includes:

[0017] If it is determined that the code in a certain designated code file does not conform to the encryption judgment rule, an error message is generated, and the error message and the designated code file are sent to the client;

[0018] The modified designated code file fed back by the client is received, and it is determined whether the modified designated code file complies with the encryption determination rule.

[0019] Optionally, converting the code in each code file in the first folder into a static type of code, and compiling the converted code file into a first type of file includes:

[0020] Encapsulate the operation of converting the dynamic type code into the static type code and the operation of compiling the code file into the first type file into an operation package;

[0021] Acquire resource utilization information of the electronic device, and determine the target process number corresponding to the electronic device based on a predetermined mapping relationship between resource utilization and process number and the resource utilization information;

[0022] The target number of processes are used to execute the operation package in parallel on the code files in the first folder to obtain files of the first type.

[0023] Optionally, the using the target number of processes to execute the operation package on the code files in the first folder in parallel includes:

[0024] Sort the code files in the first folder according to file size;

[0025] The target number of processes are used to execute the operation package on the sorted code files in parallel.

[0026] Optionally, before converting the code in each code file in the first folder into a static type of code, the method further includes:

[0027] Perform a syntax correctness check on each code file in the first folder and the second folder. When the syntax correctness check passes, perform the step of converting the code in each code file in the first folder into a static type of code and compiling the converted code file into a first type of file.

[0028] In order to solve the above problem, the present invention further provides a code protection device, the device comprising:

[0029] A parsing module, used to parse a code protection request issued by a user based on a client, obtain a storage address of a code file carried in the request, obtain the names of all code files stored in a storage space corresponding to the storage address, and generate a code file selection interface based on the names;

[0030] A judgment module, used to display the code file selection interface on the client interface, receive the code file to be protected selected by the user based on the code file selection interface, and judge whether the code file to be protected can be encrypted;

[0031] A storage module, used for storing the code files determined to be encryptable in the storage space corresponding to the storage address into a first folder, and storing the remaining code files in the storage space corresponding to the storage address into a second folder;

[0032] A compilation module is used to convert the code in each code file in the first folder into a static type of code, compile the converted code file into a first type of file, compile each code file in the second folder into a second type of file, and aggregate the first type and second type of files to obtain a target file.

[0033] Optionally, the determining whether the code file to be protected is encryptable includes:

[0034] Obtaining encryption judgment rules from a preset database, and judging whether the code in the code file to be protected complies with the encryption judgment rules;

[0035] When it is determined that the code in a certain designated code file meets the encryption judgment rule, it is considered that the designated code file can be encrypted.

[0036] In order to solve the above problem, the present invention further provides an electronic device, the electronic device comprising:

[0037] at least one processor; and,

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

[0039] The memory stores a code protection program executable by the at least one processor, and the code protection program is executed by the at least one processor so that the at least one processor can perform the above-mentioned code protection method.

[0040] In order to solve the above problem, the present invention further provides a computer-readable storage medium, on which a code protection program is stored. The code protection program can be executed by one or more processors to implement the above code protection method.

[0041] Compared with the prior art, the present invention first generates a code file selection interface according to the storage address of the code file carried in the code protection request, receives the code file to be protected selected by the user based on the code file selection interface, and determines whether the code file to be protected can be encrypted. This step can avoid the situation where the non-encryptable code file cannot run normally after encryption; then, the code file judged to be encryptable in the storage space corresponding to the storage address is stored in the first folder, and the remaining code files in the storage space corresponding to the storage address are stored in the second folder. This step separates different types of code files; finally, the code in each code file in the first folder is converted into a static type of code, the converted code file is compiled into a file of the first type, and each code file in the second folder is compiled into a file of the second type, and the first type and the second type of files are aggregated to obtain the target file. Among them, the first type of file cannot be cracked, the second type of file is more difficult to crack, and the first type and the second type of files can be directly executed. The present invention realizes that all code files can be used by multiple parties without leaking the source code content. Therefore, the present invention comprehensively improves the security of code files. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A schematic diagram of a flow chart of a code protection method provided by an embodiment of the present invention;

[0043] Figure 2 A schematic diagram of a module of a code protection device provided by an embodiment of the present invention;

[0044] Figure 3 A schematic diagram of the structure of an electronic device for implementing a code protection method provided by an embodiment of the present invention;

[0045] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0046] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0047] It should be noted that the descriptions of "first", "second", etc. in the present invention are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.

[0048] The present invention provides a code protection method. Figure 1 FIG. 1 is a flow chart of a code protection method provided by an embodiment of the present invention. The method can be executed by an electronic device, and the electronic device can be implemented by software and / or hardware.

[0049] In this embodiment, the code protection method includes:

[0050] S1. parse a code protection request issued by a user based on a client, obtain a storage address of a code file carried in the request, obtain the names of all code files stored in a storage space corresponding to the storage address, and generate a code file selection interface based on the names.

[0051] The code in this embodiment is Python code. After parsing the storage address of the code file, the names of all code files stored in the storage space corresponding to the storage address can be obtained, and then a code file selection interface can be generated. The selection interface can display the names of all code files in the storage space for the user to select the code file to be protected; a code file name input box can also be set in the selection interface for the user to enter the name of the code file to be protected.

[0052] S2. Display the code file selection interface on the client interface, receive the code file to be protected selected by the user based on the code file selection interface, and determine whether the code file to be protected can be encrypted.

[0053] The user can select the code files that need to be protected on the code file selection interface according to actual needs. For example, the user can select all the code files in the storage space corresponding to the storage address as files that need to be protected; or the user can select the core code files as files that need to be protected and the general code files as files that do not need to be protected.

[0054] The determining whether the code file to be protected is encryptable includes:

[0055] A11. Obtain encryption judgment rules from a preset database, and judge whether the code in the code file to be protected complies with the encryption judgment rules;

[0056] A12. When it is determined that the code in a certain designated code file meets the encryption judgment rule, it is considered that the designated code file can be encrypted.

[0057] In this embodiment, the encryption judgment rule may be a serialization judgment rule. It has been found through testing that if the code that needs to be serialized does not comply with the serialization rule, the encrypted code will not be serialized during operation.

[0058] For example, if you use the serialization tool Pickle to perform serialization operations, in order to ensure that the program can run normally after submitting the serialized function method to spark (a computing framework), you need to refer to the official documentation of Pickle to determine whether the code in the code file to be protected complies with the rules described in the official documentation of Pickle.

[0059] In this embodiment, after determining whether the code in the code file to be protected complies with the encryption determination rule, the method further includes:

[0060] B11. If it is determined that the code in a certain designated code file does not comply with the encryption judgment rule, an error message is generated, and the error message and the designated code file are sent to the client;

[0061] B12. Receive the modified designated code file fed back by the client, and determine whether the modified designated code file complies with the encryption determination rule.

[0062] When it is determined that the specified code file does not comply with the encryption judgment rules, the code statements that do not comply with the encryption judgment rules can be extracted, and the corresponding rule entries can be summarized to generate error information. The error information and the specified code file are sent to the client so that the client user can correct the specified code file.

[0063] S3: Store the code files determined to be encryptable in the storage space corresponding to the storage address into a first folder, and store the remaining code files in the storage space corresponding to the storage address into a second folder.

[0064] In this embodiment, the first folder stores encryptable code files that need to be protected, and the second folder stores non-encryptable code files that need to be protected and code files that do not need to be protected.

[0065] S4. Convert the code in each code file in the first folder into a static type of code, compile the converted code file into a first type of file, compile each code file in the second folder into a second type of file, aggregate the first type and second type of files, and obtain a target file.

[0066] Python is an interpreted language and a high-level language. Its code type is dynamic. Compared with other programming languages ​​such as Java, C, and C++, Python is easy to learn and has higher development efficiency. Therefore, Python is more widely used. However, Python code files are similar to text files. You can use a text editor to open the code file to view the source code. Therefore, the security of Python code files cannot be guaranteed, and Python code files need to be protected.

[0067] In this embodiment, the encryption tool Cython can be used to convert the dynamic type code into a static type code. The static type code can be C / C++ code. The running speed of static type language is higher than that of dynamic type language.

[0068] The first type of file is a dynamic link library file. The suffix of the dynamic link library file in the Windows environment is .pyd, and the suffix of the dynamic link library file in the Linux environment is .so. The dynamic link library file is a file that can be directly called and is irreversible (that is, it cannot be cracked and the file security is extremely high). Therefore, the dynamic link library file can be used by multiple parties without disclosing its source code content, effectively ensuring the security of the source code.

[0069] The second type of file is a file with a suffix of .pyc. The compilation tool py_compile can be used to compile Python code files into .pyc files. The cracking of .pyc files is relatively complex. By compiling into the second type of file, a certain degree of protection can be achieved for the code files in the second folder. To ensure that the compiled second type of file can run normally, the suffix of the second type of file needs to be deleted.

[0070] In this embodiment, converting the code in each code file in the first folder into a static type of code, and compiling the converted code file into a first type of file includes:

[0071] C11. Encapsulating an operation of converting a dynamic type code into a static type code and an operation of compiling a code file into a first type file into an operation package;

[0072] C12. Acquire resource utilization information of the electronic device, and determine the target number of processes corresponding to the electronic device based on a predetermined mapping relationship between resource utilization and the number of processes and the resource utilization information;

[0073] The electronic device is the executor of the present invention. This embodiment pre-establishes a mapping relationship between resource utilization and process number. The number of processes corresponding to various resource utilizations can be determined through this mapping relationship. By comparing the current resource utilization information of the electronic device with the mapping relationship, the target number of processes that the electronic device can provide can be determined.

[0074] C13. Use the target number of processes to execute the operation package in parallel on the code files in the first folder to obtain files of the first type.

[0075] The execution of Python code is controlled by the Python virtual machine (interpreter). Python was designed to be in the main loop with only one thread executing at the same time, just like running multiple processes in a single CPU system, multiple programs can be stored in the memory, but at any time, only one program is running in the CPU. Similarly, although the Python interpreter can run multiple threads, only one thread is running in the interpreter, so the use of multi-threaded processing cannot achieve the purpose of parallel processing, so this embodiment uses multi-process parallel processing to improve processing efficiency.

[0076] The using the target number of processes to execute the operation package on the code files in the first folder in parallel comprises:

[0077] D11, sorting the code files in the first folder according to file size;

[0078] D12. Use the target number of processes to execute the operation package on the sorted code files in parallel.

[0079] Assuming that the number of target processes is 10 and the number of code files in the first folder is 80, sorting the code files in the first folder by file size can ensure that the sizes of the 10 code files executed in the same batch are similar, thereby eliminating the situation where individual processes execute slowly due to large differences in file sizes and other processes need to wait after execution, effectively improving the processing speed.

[0080] In this embodiment, before converting the code in each code file in the first folder into a static type of code, the method further includes:

[0081] Perform a syntax correctness check on each code file in the first folder and the second folder. When the syntax correctness check passes, perform the step of converting the code in each code file in the first folder into a static type of code and compiling the converted code file into a first type of file.

[0082] It can be seen from the above embodiments that the code protection method proposed by the present invention, first, generates a code file selection interface according to the storage address of the code file carried in the code protection request, receives the code file to be protected selected by the user based on the code file selection interface, and determines whether the code file to be protected can be encrypted. This step can avoid the situation that the non-encryptable code file cannot run normally after encryption; then, the code file determined to be encryptable in the storage space corresponding to the storage address is stored in the first folder, and the remaining code files in the storage space corresponding to the storage address are stored in the second folder. This step separates different types of code files; finally, the code in each code file in the first folder is converted into a static type of code, the converted code file is compiled into a file of the first type, and each code file in the second folder is compiled into a file of the second type, and the first type and the second type of files are aggregated to obtain the target file. Among them, the first type of file cannot be cracked, the second type of file is more difficult to crack, and the first type and the second type of files can be directly executed. The present invention realizes that all code files can be used by multiple parties without leaking the source code content. Therefore, the present invention comprehensively improves the security of code files.

[0083] like Figure 2 FIG. 1 is a schematic diagram of a module of a code protection device provided by an embodiment of the present invention.

[0084] The code protection device 100 of the present invention can be installed in an electronic device. According to the functions to be implemented, the code protection device 100 can include a parsing module 110, a judgment module 120, a storage module 130 and a compilation module 140. The module of the present invention can also be called a unit, which refers to a series of computer program segments that can be executed by a processor of an electronic device and can complete fixed functions, which are stored in the memory of the electronic device.

[0085] In this embodiment, the functions of each module / unit are as follows:

[0086] The parsing module 110 is used to parse the code protection request issued by the user based on the client, obtain the storage address of the code file carried in the request, obtain the names of all code files stored in the storage space corresponding to the storage address, and generate a code file selection interface based on the names.

[0087] The code in this embodiment is Python code. After parsing the storage address of the code file, the names of all code files stored in the storage space corresponding to the storage address can be obtained, and then a code file selection interface can be generated. The selection interface can display the names of all code files in the storage space for the user to select the code file to be protected; a code file name input box can also be set in the selection interface for the user to enter the name of the code file to be protected.

[0088] The judgment module 120 is used to display the code file selection interface on the client interface, receive the code file to be protected selected by the user based on the code file selection interface, and judge whether the code file to be protected can be encrypted.

[0089] The user can select the code files that need to be protected on the code file selection interface according to actual needs. For example, the user can select all the code files in the storage space corresponding to the storage address as files that need to be protected; or the user can select the core code files as files that need to be protected and the general code files as files that do not need to be protected.

[0090] The determining whether the code file to be protected is encryptable includes:

[0091] A21. Obtain encryption judgment rules from a preset database, and judge whether the code in the code file to be protected complies with the encryption judgment rules;

[0092] A22. When it is determined that the code in a certain designated code file meets the encryption judgment rule, it is considered that the designated code file can be encrypted.

[0093] In this embodiment, the encryption judgment rule may be a serialization judgment rule. It has been found through testing that if the code that needs to be serialized does not comply with the serialization rule, the encrypted code will not be serialized during operation.

[0094] For example, if you use the serialization tool Pickle to perform serialization operations, in order to ensure that the program can run normally after submitting the serialized function method to spark (a computing framework), you need to refer to the official documentation of Pickle to determine whether the code in the code file to be protected complies with the rules described in the official documentation of Pickle.

[0095] In this embodiment, after determining whether the code in the code file to be protected complies with the encryption determination rule, the determination module 120 is further configured to:

[0096] B21. If it is determined that the code in a specified code file does not comply with the encryption judgment rule, an error message is generated, and the error message and the specified code file are sent to the client;

[0097] B22. Receive the modified designated code file fed back by the client, and determine whether the modified designated code file complies with the encryption determination rule.

[0098] When it is determined that the specified code file does not comply with the encryption judgment rules, the code statements that do not comply with the encryption judgment rules can be extracted, and the corresponding rule entries can be summarized to generate error information. The error information and the specified code file are sent to the client so that the client user can correct the specified code file.

[0099] The storage module 130 is used to store the code files determined to be encryptable in the storage space corresponding to the storage address into a first folder, and store the remaining code files in the storage space corresponding to the storage address into a second folder.

[0100] In this embodiment, the first folder stores encryptable code files that need to be protected, and the second folder stores non-encryptable code files that need to be protected and code files that do not need to be protected.

[0101] The compilation module 140 is used to convert the code in each code file in the first folder into a static type of code, compile the converted code file into a first type of file, compile each code file in the second folder into a second type of file, and aggregate the first type and second type of files to obtain a target file.

[0102] Python is an interpreted language and a high-level language. Its code type is dynamic. Compared with other programming languages ​​such as Java, C, and C++, Python is easy to learn and has higher development efficiency. Therefore, Python is more widely used. However, Python code files are similar to text files. You can use a text editor to open the code file to view the source code. Therefore, the security of Python code files cannot be guaranteed, and Python code files need to be protected.

[0103] In this embodiment, the encryption tool Cython can be used to convert the dynamic type code into a static type code. The static type code can be C / C++ code. The running speed of static type language is higher than that of dynamic type language.

[0104] The first type of file is a dynamic link library file. The suffix of the dynamic link library file in the Windows environment is .pyd, and the suffix of the dynamic link library file in the Linux environment is .so. The dynamic link library file is a file that can be directly called and is irreversible (that is, it cannot be cracked and the file security is extremely high). Therefore, the dynamic link library file can be used by multiple parties without disclosing its source code content, effectively ensuring the security of the source code.

[0105] The second type of file is a file with a suffix of .pyc. The compilation tool py_compile can be used to compile Python code files into .pyc files. The cracking of .pyc files is relatively complex. By compiling into the second type of file, a certain degree of protection can be achieved for the code files in the second folder. To ensure that the compiled second type of file can run normally, the suffix of the second type of file needs to be deleted.

[0106] In this embodiment, converting the code in each code file in the first folder into a static type of code, and compiling the converted code file into a first type of file includes:

[0107] C21, encapsulating an operation of converting a dynamic type code into a static type code and an operation of compiling a code file into a first type file into an operation package;

[0108] C22, obtaining resource utilization information of the electronic device, and determining the target number of processes corresponding to the electronic device based on a predetermined mapping relationship between resource utilization and the number of processes and the resource utilization information;

[0109] The electronic device is the executor of the present invention. This embodiment pre-establishes a mapping relationship between resource utilization and process number. The number of processes corresponding to various resource utilizations can be determined through this mapping relationship. By comparing the current resource utilization information of the electronic device with the mapping relationship, the target number of processes that the electronic device can provide can be determined.

[0110] C23. Use the target number of processes to execute the operation package in parallel on the code files in the first folder to obtain files of the first type.

[0111] The execution of Python code is controlled by the Python virtual machine (interpreter). Python was designed to be in the main loop with only one thread executing at the same time, just like running multiple processes in a single CPU system, multiple programs can be stored in the memory, but at any time, only one program is running in the CPU. Similarly, although the Python interpreter can run multiple threads, only one thread is running in the interpreter, so the use of multi-threaded processing cannot achieve the purpose of parallel processing, so this embodiment uses multi-process parallel processing to improve processing efficiency.

[0112] The using the target number of processes to execute the operation package on the code files in the first folder in parallel comprises:

[0113] D21, sorting the code files in the first folder according to file size;

[0114] D22. Use the target number of processes to execute the operation package on the sorted code files in parallel.

[0115] Assuming that the number of target processes is 10 and the number of code files in the first folder is 80, sorting the code files in the first folder by file size can ensure that the sizes of the 10 code files executed in the same batch are similar, thereby eliminating the situation where individual processes execute slowly due to large differences in file sizes and other processes need to wait after execution, effectively improving the processing speed.

[0116] In this embodiment, before converting the code in each code file in the first folder into a static type of code, the compiling module 140 is further used to:

[0117] Perform a syntax correctness check on each code file in the first folder and the second folder. When the syntax correctness check passes, perform the step of converting the code in each code file in the first folder into a static type of code and compiling the converted code file into a first type of file.

[0118] like Figure 3FIG. 1 is a schematic diagram of the structure of an electronic device for implementing a code protection method provided by an embodiment of the present invention.

[0119] The electronic device 1 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. The electronic device 1 can be a computer, a single network server, a server group consisting of multiple network servers, or a cloud based on cloud computing consisting of a large number of hosts or network servers, wherein cloud computing is a type of distributed computing, a super virtual computer composed of a group of loosely coupled computer sets.

[0120] In this embodiment, the electronic device 1 includes, but is not limited to, a memory 11, a processor 12, and a network interface 13 that can be interconnected and communicated via a system bus. The memory 11 stores a code protection program 10 that can be executed by the processor 12. Figure 3 Only the electronic device 1 having components 11-13 and the code protection program 10 is shown, and those skilled in the art can understand that Figure 3 The structure shown does not constitute a limitation on the electronic device 1 , and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.

[0121] The memory 11 includes a memory and at least one type of readable storage medium. The memory provides a cache for the operation of the electronic device 1; the readable storage medium may be a non-volatile storage medium such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the readable storage medium may be an internal storage unit of the electronic device 1, such as a hard disk of the electronic device 1; in other embodiments, the non-volatile storage medium may also be an external storage device of the electronic device 1, such as a plug-in hard disk equipped on the electronic device 1, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card, etc. In this embodiment, the readable storage medium of the memory 11 is generally used to store an operating system and various application software installed on the electronic device 1, such as storing the code of the code protection program 10 in an embodiment of the present invention, etc. In addition, the memory 11 may also be used to temporarily store various types of data that have been output or are to be output.

[0122] In some embodiments, the processor 12 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 12 is generally used to control the overall operation of the electronic device 1, such as performing control and processing related to data interaction or communication with other devices. In this embodiment, the processor 12 is used to run the program code stored in the memory 11 or process data, such as running the code protection program 10.

[0123] The network interface 13 may include a wireless network interface or a wired network interface, and the network interface 13 is used to establish a communication connection between the electronic device 1 and a client (not shown in the figure).

[0124] Optionally, the electronic device 1 may further include a user interface, which may include a display (Display), an input unit such as a keyboard (Keyboard), and the optional user interface may also include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device 1 and to display a visual user interface.

[0125] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.

[0126] The code protection program 10 stored in the memory 11 in the electronic device 1 is a combination of multiple instructions. When running in the processor 12, it can achieve:

[0127] Parse a code protection request issued by a user based on a client, obtain a storage address of a code file carried in the request, obtain names of all code files stored in a storage space corresponding to the storage address, and generate a code file selection interface based on the names;

[0128] Displaying the code file selection interface on the client interface, receiving the code file to be protected selected by the user based on the code file selection interface, and determining whether the code file to be protected can be encrypted;

[0129] The code files determined to be encryptable in the storage space corresponding to the storage address are stored in a first folder, and the remaining code files in the storage space corresponding to the storage address are stored in a second folder;

[0130] Convert the code in each code file in the first folder into a static type of code, compile the converted code file into a first type of file, compile each code file in the second folder into a second type of file, aggregate the first type and second type of files, and obtain a target file.

[0131] Specifically, the specific implementation method of the processor 12 for the above code protection program 10 can refer to Figure 1 The description of the relevant steps in the corresponding embodiments will not be repeated here.

[0132] Furthermore, if the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable medium can be non-volatile or non-volatile. The computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).

[0133] The computer-readable storage medium stores a code protection program 10, which can be executed by one or more processors. The specific implementation of the computer-readable storage medium of the present invention is basically the same as the above-mentioned embodiments of the code protection method, and will not be described in detail here.

[0134] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.

[0135] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0136] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.

[0137] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.

[0138] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.

[0139] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the system claim can also be implemented by one unit or device through software or hardware. The second and other words are used to indicate names, but not to indicate any particular order.

[0140] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.

Claims

1. A code protection method, applied to electronic equipment, characterized in that: The method comprises: Parse a code protection request issued by a user based on a client, obtain a storage address of a code file carried in the request, obtain names of all code files stored in a storage space corresponding to the storage address, and generate a code file selection interface based on the names; The code file selection interface is displayed on the client interface, a code file to be protected selected by a user based on the code file selection interface is received, an encryption judgment rule is obtained from a preset database, and it is judged whether the code in the code file to be protected complies with the encryption judgment rule. When it is judged that the code in a certain specified code file complies with the encryption judgment rule, it is judged that the specified code file can be encrypted, and the encryption judgment rule is a serialization judgment rule for judging whether the code can be serialized after being encrypted and run; The code files determined to be encryptable in the storage space corresponding to the storage address are stored in a first folder, and the remaining code files in the storage space corresponding to the storage address are stored in a second folder; Convert the code in each code file in the first folder into a static type of code, compile the converted code files into files of the first type, which are dynamic link library files, compile each code file in the second folder into files of the second type, which are .pyc files, and aggregate the first and second types of files to obtain a target file.

2. The code protection method according to claim 1, characterized in that: After determining whether the code in the code file to be protected complies with the encryption determination rule, the method further includes: If it is determined that the code in a certain designated code file does not conform to the encryption judgment rule, an error message is generated, and the error message and the designated code file are sent to the client; The modified designated code file fed back by the client is received, and it is determined whether the modified designated code file complies with the encryption determination rule.

3. The code protection method according to claim 1, characterized in that: The converting the code in each code file in the first folder into a static type of code, and compiling the converted code file into a first type of file comprises: Encapsulate the operation of converting the dynamic type code into the static type code and the operation of compiling the code file into the first type file into an operation package; Acquire resource utilization information of the electronic device, and determine the target process number corresponding to the electronic device based on a predetermined mapping relationship between resource utilization and process number and the resource utilization information; The target number of processes are used to execute the operation package in parallel on the code files in the first folder to obtain files of the first type.

4. The code protection method according to claim 3, characterized in that: The using the target number of processes to execute the operation package on the code files in the first folder in parallel comprises: Sort the code files in the first folder according to file size; The target number of processes are used to execute the operation package on the sorted code files in parallel.

5. The code protection method according to any one of claims 1 to 4, characterized in that: Before converting the code in each code file in the first folder into a static type of code, the method further includes: Perform a syntax correctness check on each code file in the first folder and the second folder. When the syntax correctness check passes, perform the step of converting the code in each code file in the first folder into a static type of code and compiling the converted code file into a first type of file.

6. A code protection device, characterized in that: The device comprises: A parsing module, used to parse a code protection request issued by a user based on a client, obtain a storage address of a code file carried in the request, obtain the names of all code files stored in a storage space corresponding to the storage address, and generate a code file selection interface based on the names; A judgment module is used to display the code file selection interface on the client interface, receive the code file to be protected selected by the user based on the code file selection interface, obtain encryption judgment rules from a preset database, judge whether the code in the code file to be protected complies with the encryption judgment rules, and when it is judged that the code in a specified code file complies with the encryption judgment rules, judge that the specified code file can be encrypted, and the encryption judgment rules are serialization judgment rules for judging whether the code can be serialized after being encrypted and run; A storage module, used to store the code files determined to be encryptable in the storage space corresponding to the storage address into a first folder, and store the remaining code files in the storage space corresponding to the storage address into a second folder; A compilation module is used to convert the code in each code file in the first folder into a static type of code, compile the converted code file into a first type of file, the first type of file is a dynamic link library file, compile each code file in the second folder into a second type of file, aggregate the first type and second type of files, the second type of file is a .pyc file, and obtain a target file.

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

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a code protection program, and the code protection program can be executed by one or more processors to implement the code protection method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Document protection method, device and system

    CN107967430A

  • Package file generation method and device for software project, equipment and storage medium

    CN111880805A