CN116339688A - Python code reinforcement method, system, storage medium and computer equipment based on byte code replacement - Google Patents

Python code reinforcement method, system, storage medium and computer equipment based on byte code replacement Download PDF

Info

Publication number
CN116339688A
CN116339688A CN202111536748.XA CN202111536748A CN116339688A CN 116339688 A CN116339688 A CN 116339688A CN 202111536748 A CN202111536748 A CN 202111536748A CN 116339688 A CN116339688 A CN 116339688A
Authority
CN
China
Prior art keywords
python
script
code
python script
predefined rule
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111536748.XA
Other languages
Chinese (zh)
Inventor
林聚伟
孙逊
王菁华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
360 Digital Security Technology Group Co Ltd
Original Assignee
360 Digital Security Technology Group Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 360 Digital Security Technology Group Co Ltd filed Critical 360 Digital Security Technology Group Co Ltd
Priority to CN202111536748.XA priority Critical patent/CN116339688A/en
Publication of CN116339688A publication Critical patent/CN116339688A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • G06F8/24Object-oriented
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/602Providing cryptographic facilities or services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/74Reverse engineering; Extracting design information from source code
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Storage Device Security (AREA)

Abstract

The invention provides a Python code reinforcement method based on byte code replacement, which is used for carrying out replacement processing on byte codes in a first Python script according to a predefined rule so as to generate a second Python script; detecting and identifying the reinforced second Python script; rewriting an analysis program of Python source codes according to reverse analysis rules associated with the predefined rule mapping; and executing the second Python script through the parsing program. The invention also provides a Python code reinforcement system based on byte code replacement, a storage medium and computer equipment. Therefore, the invention can effectively prevent the python code from being maliciously leaked and hacked.

Description

Python code reinforcement method, system, storage medium and computer equipment based on byte code replacement
Technical Field
The present invention relates to the field of code encryption technologies, and in particular, to a method, a system, a storage medium, and a computer device for reinforcing a Python code based on byte code substitution.
Background
Python provides an efficient, high-level data structure that can also be easily and efficiently programmed towards objects. Python grammar and dynamic type, and the nature of interpreted language make it the programming language for writing scripts and fast developing applications on most platforms, gradually used for independent, large-scale project development with the continuous updating of versions and the addition of new language functions.
Background programs developed using Python code are numerous, but how to protect against leakage is a problem. However, the existing background program directly exposes the script code in the background or is compiled into an executable program by using a PyInstaller and the like, but decompilation is also very simple and is easy to be plagiarized maliciously.
In summary, the conventional method has many problems in practical use, so that improvement is necessary.
Disclosure of Invention
In view of the above-mentioned drawbacks, an object of the present invention is to provide a method, a system, a storage medium and a computer device for reinforcing Python codes based on byte code substitution, which can effectively prevent Python codes from being hacked by malicious disclosure.
In order to achieve the above object, the present invention provides a method for reinforcing a Python code based on bytecode substitution, comprising the steps of:
according to a predefined rule, replacing the byte codes in the first Python script to generate a second Python script;
detecting and identifying the reinforced second Python script;
rewriting an analysis program of Python source codes according to reverse analysis rules associated with the predefined rule mapping;
and executing the second Python script through the parsing program.
Optionally, after the step of performing substitution processing on the byte codes in the first Python script according to the predefined rule to generate the second Python script, the method further includes:
performing RC4 encryption processing on the pyc file of the second Python script;
after the step of detecting and identifying the second reinforced Python script, the method further comprises:
and performing RC4 decryption processing on the pyc file.
Optionally, the step of performing RC4 encryption processing on the pyc file of the second Python script specifically includes:
and carrying out RC4 encryption processing on the preset byte code segment in the pyc file.
Optionally, the step of replacing the bytecode in the first Python script according to a predefined rule to generate a second Python script includes:
and exchanging odd numbers and even numbers in the byte codes of the first Python script according to the predefined rule.
Optionally, the step of replacing the bytecode in the first Python script according to a predefined rule to generate a second Python script includes:
and according to the predefined rule, replacing the byte code mapping to be replaced in the first Python script with a preset byte code.
Optionally, the step of detecting and identifying the second reinforced Python script specifically includes:
and according to the setting of the target byte code segment of the pyc file of the script to be tested, identifying and determining whether the script to be tested is the second Python script.
Optionally, the step of rewriting the parsing program of the Python source code according to the reverse parsing rule associated with the predefined rule mapping specifically includes:
acquiring reverse analysis rules associated based on the predefined rule mapping;
and changing a byte code analysis engine in the Python source code according to the reverse analysis rule.
The invention also provides a Python code reinforcement system based on byte code substitution, which comprises:
the script reinforcement unit is used for carrying out replacement processing on the byte codes in the first Python script according to a predefined rule so as to generate a second Python script;
the script identification unit is used for detecting and identifying the reinforced second Python script;
the source code rewriting unit is used for rewriting an analysis program of the Python source code according to the reverse analysis rule mapped and associated with the predefined rule;
and the script execution unit is used for executing the second Python script through the analysis program.
In addition, a storage medium and a computer device are provided, the storage medium being used for storing a computer program for executing the above-mentioned Python code reinforcement method based on byte code substitution.
The computer device comprises a storage medium, a processor and a computer program stored on the storage medium and capable of running on the processor, wherein the processor realizes the Python code reinforcement method based on byte code substitution when executing the computer program.
According to the bytecode replacement-based Python code reinforcement method and the system thereof, a preset predefined rule is adopted to replace the bytecode in a first Python script to be reinforced, and a second Python script is generated; in the script execution link, the reinforced second Python script is detected and identified; and then rewriting the analysis program of the Python source code according to the reverse analysis rule associated with the predefined rule mapping; and finally executing a second Python script through the analysis program. Therefore, the second Python script is only analyzed and executed internally, malicious leakage and plagiarism after the second Python script is acquired externally are effectively avoided, and confidentiality of the Python script is enhanced.
Drawings
FIG. 1 is a flowchart illustrating steps of a method for reinforcing a Python code based on byte code substitution according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating optional steps for executing a script according to the method for reinforcing a Python code based on bytecode replacement according to an embodiment of the present invention;
FIG. 3 is a schematic block diagram of a Python code reinforcement system based on byte code substitution according to an embodiment of the present invention;
fig. 4 is a schematic block diagram of an alternative structure of the source code rewriting unit of the bytecode replacement-based Python code reinforcement system according to an embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present invention more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
It should be noted that references in the specification to "one embodiment," "an example embodiment," etc., indicate that the embodiment described may include a particular feature, structure, or characteristic, but every embodiment may not necessarily include the particular feature, structure, or characteristic. Furthermore, such phrases are not intended to refer to the same embodiment. Further, when a particular feature, structure, or characteristic is described in connection with an embodiment, it is submitted that it is within the knowledge of one skilled in the art to effect such feature, structure, or characteristic in connection with other embodiments whether or not explicitly described.
Furthermore, certain terms are used throughout the specification and the claims that follow to refer to particular components or parts, and it will be understood by those of ordinary skill in the art that manufacturers may refer to a component or part by different terms or terminology. The present specification and the following claims do not take the form of an element or component with the difference in name, but rather take the form of an element or component with the difference in function as a criterion for distinguishing. In the following description and in the claims, the terms "include" and "comprise" are used in an open-ended fashion, and thus should be interpreted to mean "include, but not limited to. The term "coupled," as used herein, includes any direct or indirect electrical connection. Indirect electrical connection means include connection via other devices.
Fig. 1 shows a method for reinforcing a Python code based on byte code substitution according to an embodiment of the present invention, including the following steps:
s101: and replacing the byte codes in the first Python script according to a predefined rule to generate a second Python script. Wherein the predefined rule is a custom replacement rule for the bytecode; the first Python script is an original script code, and in practical application, if the first Python script is leaked, the first Python script is easily executed by external personnel by adopting the existing Python source code, so that the first Python script is easily plagiarism; for this reason, the present embodiment replaces the byte code in the first Python script by the predefined rule, so as to form a new second Python script; namely, the byte code in the second Python script is a random code without any nutation for an external person who does not know the predefined rule; at this time, the external person cannot execute or decrypt the second Python script even if the external person acquires the second Python script.
Optionally, step S101 further includes: and performing RC4 encryption processing on the pyc file of the second Python script. RC4 encryption is a symmetric encryption algorithm using a single key (or "private key"). Instead of performing packet processing on the plaintext, the RC4 encryption encrypts each byte in the plaintext in sequence in a byte stream manner, and decrypts each byte in the ciphertext in sequence during decryption. In specific implementation, RC4 encryption processing is carried out on a preset byte code segment in the pyc file; the preset byte codes in this embodiment are preferably the content of the co_code and the co_consts in the pyc file, that is, in this embodiment, the content of the co_code and the co_consts only needs to be encrypted by adopting an RC4 encryption method.
S102: and detecting and identifying the second Python script after reinforcement. In the execution stage of the script, whether the script to be executed is a reinforced second Python script needs to be identified; preferably, the script execution terminal of the present embodiment supports script execution of a standard Python script (including a py file or a pyc file) and a second Python script; wherein the py file is a Python script file. When the Python is executed, the source code in the py file is first compiled into Python bytecodes, and then the Python virtual machine executes the compiled bytecodes. The pyc file is a binary file, and is a file generated by compiling the py file, and the loading speed is improved after the py file becomes the pyc file.
In this embodiment, it is required to detect in advance in the script execution terminal whether the identified Python script to be executed is the second Python script that has been reinforced in step S101; if the script is a standard Python script (i.e. a script file which is not subjected to reinforcement processing), processing according to the existing execution rule; otherwise, if the fixed Python script to be executed is detected and identified as the second Python script, the next process step S103 is entered.
If the embodiment generates the second pyc script, performing RC4 encryption processing on the pyc file of the second Python script; then after step S102, it further includes: and performing RC4 decryption processing on the pyc file. Specifically, when the Python script to be executed is detected to be a second Python script, the pyc file of the second Python script is also decrypted by adopting an RC4 method. That is, the embodiment provides double encryption guarantee on the basis of combining the byte code replacement means, so that the second Python script has higher encryption performance.
S103: and rewriting an analysis program of the Python source codes according to the reverse analysis rule associated with the predefined rule mapping. The reverse analysis rule is generated according to a predefined rule and is specifically used for carrying out reverse engineering analysis on the second Python script; in a specific implementation, the embodiment rewrites the Python source code of the open source according to the reverse parsing rule, so that the parsing program of the rewritten new Python source code obtains the parsing execution capability of executing the second Python script.
S104: and executing the second Python script through the parsing program. The second Python script can be executed by adopting an analysis program which is rewritten in a targeted manner based on the Python source code; if the original Python source code is not based on the rewriting of the Python source code according to the reverse analysis rule, the second Python script cannot be executed, so that the second Python script is only analyzed and executed internally, malicious leakage and plagiarism after the second Python script is acquired externally are effectively avoided, and confidentiality of the Python script is enhanced.
In one embodiment, step S101 specifically includes: and exchanging odd numbers and even numbers in the byte codes of the first Python script according to the predefined rule. For example, determining a one-to-one correspondence between odd and even numbers according to a predefined rule, so as to perform word exchange according to the correspondence; if 1< - >2,3< - >4, it means that odd 1 and even 2 are swapped and odd 3 and even 4 are swapped. After the first Python script is subjected to one-to-one corresponding exchange processing between the odd number and the even number, generating a second distinct Python script; if the external person maliciously obtains the second Python script, the second Python script is only a few random codes without any legal method for the external person, and at this time, the second Python script cannot be resolved and executed obviously by the external person.
In another embodiment, the step S101 specifically includes: and according to the predefined rule, replacing the byte code mapping to be replaced in the first Python script with a preset byte code. In specific implementation, the embodiment is provided with a preset byte code, and a plurality of byte codes to be replaced in the first Python script can be determined according to the predefined rule, and the preset byte code and the byte codes to be replaced are adopted to replace, so that the whole second Python script is changed to be different from the original first Python script. For example, the preset bytecode 200 is mapped to the original bytecode 100, and the preset bytecode 201: mapping to the original bytecode 101; thereby forming a completely new second Python script.
Of course, in other embodiments, odd-numbered and even-numbered exchange is performed on the byte codes in the first Python script according to a predefined rule, and a part of byte codes in the byte codes are replaced by preset byte codes at the same time; to form a more complex second Python script.
Referring to fig. 2, in an alternative embodiment, step S102 specifically includes:
s111: and according to the setting of the target byte code segment of the pyc file of the script to be tested, identifying and determining whether the script to be tested is a second Python script. In the stage of script execution, firstly, a standard Python script and a second Python script which is already reinforced need to be supported and identified; in specific implementation, the target byte code segment is code_type and co_flags in the pyc file structure; namely, the embodiment realizes the detection and identification of the second Python script through the setting of the code_type and the co_flags of the pyc file structure. Setting means that a certain byte is set to 1, so that a specific code can be identified and determined.
The step S103 specifically includes:
s112: and acquiring reverse analysis rules associated based on the predefined rule mapping. The reverse parsing rule is generated according to a predefined rule, i.e. the reverse parsing rule is applied to reverse parsing of the first Python script hardened with the predefined rule.
S113: and changing a byte code analysis engine in the Python source code according to the reverse analysis rule.
The step S104 specifically includes:
s114: and executing the consolidated byte code in the second Python script through the byte code parsing engine.
In order to support the second reinforced Python script, the embodiment alters the byte code analysis engine in the Python source code according to the reverse analysis rule, so that when executing the byte code of the second Python script, the altered byte code analysis engine is utilized to analyze and execute the second Python script.
The reverse parsing rule of the embodiment is stored in the authorized parsing terminal. The authorization analysis terminal may be an analysis execution terminal of the second Python script, or may be a management terminal that manages the analysis execution terminals. Namely, the reverse analysis rule is only pre-stored in the internal management system, and the second Python script can not be analyzed and executed even if the second Python script leaks; so that encryption firmness of the second Python script can be ensured.
Fig. 3 shows a bytecode replacement-based Python code reinforcement system 100 according to an embodiment of the present invention, which includes a script reinforcement unit 10, a script identification unit 20, a source code rewrite unit 30, and a script execution unit 40, wherein:
the script reinforcement unit 10 is configured to perform substitution processing on the byte codes in the first Python script according to a predefined rule, so as to generate a second Python script; the script identifying unit 20 is configured to detect and identify the consolidated second Python script; the source code rewriting unit 30 is configured to rewrite an analysis program of the Python source code according to an inverse analysis rule associated with the predefined rule mapping; the script execution unit 40 is configured to execute the second Python script through the parser.
In the embodiment, the byte code of the first Python script to be consolidated is replaced, so that a second Python script which cannot be analyzed by an external person is formed; the open source Python source codes are changed by utilizing a reverse analysis rule, so that the second Python script is executed by utilizing an execution program of the changed Python source codes in an enterprise; the second Python script in this embodiment is only used for internal analysis and execution, so that malicious leakage and plagiarism after the second Python script is obtained from the outside are effectively avoided, and confidentiality of the Python script is enhanced.
Optionally, the system further comprises an encryption unit and a parsing unit, wherein:
the encryption unit is used for performing RC4 encryption processing on the pyc file of the second Python script; and the decryption unit is used for performing RC4 decryption processing on the pyc file. Preferably, the encryption unit is specifically configured to: and carrying out RC4 encryption processing on the preset byte code segment in the pyc file.
In one embodiment, the script reinforcement unit 10 is configured to: and exchanging odd numbers and even numbers in the byte codes of the first Python script according to the predefined rule.
In another embodiment, the script reinforcement unit 10 is configured to: and according to the predefined rule, replacing the byte code mapping to be replaced in the first Python script with a preset byte code.
Of course, in other embodiments, odd-numbered and even-numbered exchange is performed on the byte codes in the first Python script according to a predefined rule, and a part of byte codes in the byte codes are replaced by preset byte codes at the same time; to form a more complex second Python script.
Optionally, the script identifying unit 20 is specifically configured to: and according to the setting of the target byte code segment of the pyc file of the script to be tested, identifying and determining whether the script to be tested is the second Python script.
Referring to fig. 4, in an alternative embodiment, the source code rewriting unit 30 specifically includes an obtaining subunit 31 and a modifying subunit 32, where:
the obtaining subunit 31 is configured to obtain a reverse parsing rule associated based on the predefined rule mapping; the modification subunit 32 is configured to modify a bytecode parsing engine in the Python source code according to the reverse parsing rule.
Further, the script execution unit 40 is specifically configured to: executing, by the bytecode parsing engine, the consolidated bytecode in the second Python script.
Optionally, the reverse parsing rule is stored in the authorized parsing terminal. The authorization analysis terminal may be an analysis execution terminal of the second Python script, or may be a management terminal that manages the analysis execution terminals. Namely, the reverse analysis rule is only pre-stored in the internal management system, and the second Python script can not be analyzed and executed even if the second Python script leaks; so that encryption firmness of the second Python script can be ensured.
The present invention also provides a storage medium storing a computer program for a bytecode replacement-based Python code reinforcement method as described in fig. 1 to 2. Such as computer program instructions, which, when executed by a computer, may invoke or provide methods and/or techniques in accordance with the present application. Program instructions for invoking the methods of the present application may be stored in fixed or removable storage media and/or transmitted via a data stream in a broadcast or other signal bearing medium and/or stored within a storage medium of a computer device operating according to the program instructions. Here, an embodiment according to the present application includes a computer device of a Python code reinforcement system based on bytecode replacement as shown in fig. 3, preferably including a storage medium for storing a computer program and a processor for executing the computer program, wherein the computer program, when executed by the processor, is triggered to perform the method and/or the technical solution based on the foregoing embodiments.
It should be noted that the present application may be implemented in software and/or a combination of software and hardware, for example, using Application Specific Integrated Circuits (ASIC), a general purpose computer or any other similar hardware device. In one embodiment, the software program of the present application may be executed by a processor to implement the above steps or functions. Likewise, the software programs of the present application (including associated data structures) may be stored on a computer readable recording medium, such as RAM memory, magnetic or optical drive or diskette and the like. In addition, some steps or functions of the present application may be implemented in hardware, for example, as circuitry that cooperates with the processor to perform various steps or functions.
The method according to the invention may be implemented as a computer implemented method on a computer, or in dedicated hardware, or in a combination of both. Executable code or parts thereof for the method according to the invention may be stored on a computer program product. Examples of computer program products include memory devices, optical storage devices, integrated circuits, servers, online software, and the like. Preferably, the computer program product comprises non-transitory program code means stored on a computer readable medium for performing the method according to the invention when said program product is executed on a computer.
In a preferred embodiment the computer program comprises computer program code means adapted to perform all the steps of the method according to the invention when the computer program is run on a computer. Preferably, the computer program is embodied on a computer readable medium.
In summary, according to the bytecode replacement-based method and system for reinforcing the Python codes, the preset predefined rule is adopted to replace the bytecode in the first Python script to be reinforced, and the second Python script is generated; in the script execution link, the reinforced second Python script is detected and identified; and then rewriting the analysis program of the Python source code according to the reverse analysis rule associated with the predefined rule mapping; and finally executing a second Python script through the analysis program. Therefore, the second Python script is only analyzed and executed internally, malicious leakage and plagiarism after the second Python script is acquired externally are effectively avoided, and confidentiality of the Python script is enhanced.
Of course, the present invention is capable of other various embodiments and its several details are capable of modification and variation in light of the present invention, as will be apparent to those skilled in the art, without departing from the spirit and scope of the invention as defined in the appended claims.
The invention also provides A1, a Python code reinforcement method based on byte code substitution, comprising the following steps:
according to a predefined rule, replacing the byte codes in the first Python script to generate a second Python script;
detecting and identifying the reinforced second Python script;
rewriting an analysis program of Python source codes according to reverse analysis rules associated with the predefined rule mapping;
and executing the second Python script through the parsing program.
A2, the method for reinforcing the Python code based on the byte code replacement according to A1, wherein the step of replacing the byte code in the first Python script according to the predefined rule to generate the second Python script further comprises:
performing RC4 encryption processing on the pyc file of the second Python script;
after the step of detecting and identifying the second reinforced Python script, the method further comprises:
and performing RC4 decryption processing on the pyc file.
A3, according to the method for reinforcing the Python code based on the byte code substitution of A2, the step of performing RC4 encryption processing on the pyc file of the second Python script specifically comprises the following steps:
and carrying out RC4 encryption processing on the preset byte code segment in the pyc file.
A4, according to the method for reinforcing the Python code based on the byte code replacement of A1, the step of replacing the byte code in the first Python script according to the predefined rule to generate the second Python script comprises the following steps:
and exchanging odd numbers and even numbers in the byte codes of the first Python script according to the predefined rule.
A5, according to the method for reinforcing the Python code based on the byte code replacement of A1, the step of replacing the byte code in the first Python script according to the predefined rule to generate the second Python script comprises the following steps:
and according to the predefined rule, replacing the byte code mapping to be replaced in the first Python script with a preset byte code.
A6, according to the method for reinforcing the Python code based on the byte code substitution of A1, the step of detecting and identifying the reinforced second Python script specifically comprises the following steps:
and according to the setting of the target byte code segment of the pyc file of the script to be tested, identifying and determining whether the script to be tested is the second Python script.
A7, according to the method for reinforcing the Python code based on the byte code substitution of A1, the step of rewriting the analysis program of the Python source code according to the reverse analysis rule mapped and associated with the predefined rule specifically comprises the following steps:
acquiring reverse analysis rules associated based on the predefined rule mapping;
and changing a byte code analysis engine in the Python source code according to the reverse analysis rule.
A8, according to the bytecode replacement-based Python code reinforcement method of A7, the step of executing the second Python script by the parsing program specifically includes:
executing, by the bytecode parsing engine, the consolidated bytecode in the second Python script.
A9, according to the Python code reinforcement method based on byte code replacement of A7, the reverse parsing rule is stored in the authorized parsing terminal.
Also provided is a B10, a bytecode substitution-based Python code reinforcement system, comprising:
the script reinforcement unit is used for carrying out replacement processing on the byte codes in the first Python script according to a predefined rule so as to generate a second Python script;
the script identification unit is used for detecting and identifying the reinforced second Python script;
the source code rewriting unit is used for rewriting an analysis program of the Python source code according to the reverse analysis rule mapped and associated with the predefined rule;
and the script execution unit is used for executing the second Python script through the analysis program.
B11, the Python code reinforcement system based on byte code substitution according to B10, further comprising:
an encryption unit, configured to perform RC4 encryption processing on a pyc file of the second Python script;
and the decryption unit is used for performing RC4 decryption processing on the pyc file.
B12, the Python code reinforcement system based on byte code substitution according to B11, wherein the encryption unit is specifically configured to:
and carrying out RC4 encryption processing on the preset byte code segment in the pyc file.
B13, the Python code reinforcement system based on byte code substitution according to B10, wherein the script reinforcement unit is used for:
and exchanging odd numbers and even numbers in the byte codes of the first Python script according to the predefined rule.
B14, the Python code reinforcement system based on byte code substitution according to B10, wherein the script reinforcement unit is used for:
and according to the predefined rule, replacing the byte code mapping to be replaced in the first Python script with a preset byte code.
B15, the Python code reinforcement system based on byte code substitution according to B10, wherein the script identification unit is specifically used for:
and according to the setting of the target byte code segment of the pyc file of the script to be tested, identifying and determining whether the script to be tested is the second Python script.
B16, the Python code reinforcement system based on byte code substitution according to B10, wherein the source code rewriting unit specifically comprises:
an obtaining subunit, configured to obtain a reverse parsing rule mapped and associated based on the predefined rule;
and the modification subunit is used for modifying the byte code analysis engine in the Python source code according to the reverse analysis rule.
B17, the Python code reinforcement system based on byte code substitution according to B16, wherein the script execution unit is specifically configured to:
executing, by the bytecode parsing engine, the consolidated bytecode in the second Python script.
B18, the Python code reinforcement system based on byte code substitution according to the B16, wherein the reverse parsing rule is stored in the authorized parsing terminal.
There is also provided C19, a storage medium storing a computer program for executing the bytecode replacement-based Python code reinforcement method of any one of A1 to A9.
Also provided is a D20, a computer device comprising a storage medium, a processor and a computer program stored on the storage medium and executable on the processor, the processor implementing the bytecode replacement-based Python code reinforcement method of any one of A1 to A9 when executing the computer program.

Claims (10)

1. A Python code reinforcement method based on byte code replacement is characterized by comprising the following steps:
according to a predefined rule, replacing the byte codes in the first Python script to generate a second Python script;
detecting and identifying the reinforced second Python script;
rewriting an analysis program of Python source codes according to reverse analysis rules associated with the predefined rule mapping;
and executing the second Python script through the parsing program.
2. The method for reinforcing a Python code based on a bytecode replacement according to claim 1, wherein after the step of performing a replacement process on the bytecode in the first Python script according to a predefined rule to generate the second Python script, further comprising:
performing RC4 encryption processing on the pyc file of the second Python script;
after the step of detecting and identifying the second reinforced Python script, the method further comprises:
and performing RC4 decryption processing on the pyc file.
3. The method for reinforcing a pyc code based on a bytecode replacement according to claim 2, wherein the step of performing RC4 encryption processing on the pyc file of the second Python script specifically comprises:
and carrying out RC4 encryption processing on the preset byte code segment in the pyc file.
4. The method for reinforcing a Python code based on a bytecode replacement according to claim 1, wherein the step of replacing the bytecode in the first Python script according to a predefined rule to generate the second Python script comprises:
and exchanging odd numbers and even numbers in the byte codes of the first Python script according to the predefined rule.
5. The method for reinforcing a Python code based on a bytecode replacement according to claim 1, wherein the step of replacing the bytecode in the first Python script according to a predefined rule to generate the second Python script comprises:
and according to the predefined rule, replacing the byte code mapping to be replaced in the first Python script with a preset byte code.
6. The method for reinforcing a Python code based on bytecode substitution according to claim 1, wherein said step of detecting and identifying the reinforced second Python script specifically comprises:
and according to the setting of the target byte code segment of the pyc file of the script to be tested, identifying and determining whether the script to be tested is the second Python script.
7. The method for reinforcing a Python code based on bytecode replacement according to claim 1, wherein the step of rewriting a parser of Python source code according to a reverse parsing rule associated with the predefined rule map specifically comprises:
acquiring reverse analysis rules associated based on the predefined rule mapping;
and changing a byte code analysis engine in the Python source code according to the reverse analysis rule.
8. A bytecode replacement-based Python code reinforcement system, comprising:
the script reinforcement unit is used for carrying out replacement processing on the byte codes in the first Python script according to a predefined rule so as to generate a second Python script;
the script identification unit is used for detecting and identifying the reinforced second Python script;
the source code rewriting unit is used for rewriting an analysis program of the Python source code according to the reverse analysis rule mapped and associated with the predefined rule;
and the script execution unit is used for executing the second Python script through the analysis program.
9. A storage medium storing a computer program for executing the bytecode replacement-based Python code reinforcement method of any one of claims 1 to 7.
10. A computer device comprising a storage medium, a processor and a computer program stored on the storage medium and executable on the processor, characterized in that the processor implements the bytecode replacement based Python code reinforcement method of any one of claims 1 to 7 when the computer program is executed by the processor.
CN202111536748.XA 2021-12-15 2021-12-15 Python code reinforcement method, system, storage medium and computer equipment based on byte code replacement Pending CN116339688A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111536748.XA CN116339688A (en) 2021-12-15 2021-12-15 Python code reinforcement method, system, storage medium and computer equipment based on byte code replacement

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111536748.XA CN116339688A (en) 2021-12-15 2021-12-15 Python code reinforcement method, system, storage medium and computer equipment based on byte code replacement

Publications (1)

Publication Number Publication Date
CN116339688A true CN116339688A (en) 2023-06-27

Family

ID=86888074

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111536748.XA Pending CN116339688A (en) 2021-12-15 2021-12-15 Python code reinforcement method, system, storage medium and computer equipment based on byte code replacement

Country Status (1)

Country Link
CN (1) CN116339688A (en)

Similar Documents

Publication Publication Date Title
US10402179B1 (en) Application randomization mechanism
US7254586B2 (en) Secure and opaque type library providing secure data protection of variables
JP5990654B2 (en) Application code obfuscation device and method
US20160364707A1 (en) Potentate: A Cryptography-Obfuscating, Self-Policing, Pervasive Distribution System For Digital Content
CN109784007B (en) Byte code encryption method, byte code decryption method and terminal
EP3924848A1 (en) Securing virtual-machine software applications
JP2012118956A (en) Index table-based code encryption and decryption device and method therefor
CN106599627A (en) Method and apparatus for protecting application security based on virtual machine
US20180181729A1 (en) Protecting a computer program against reverse engineering
KR102266342B1 (en) Method of encoding and decoding memory data for software security, readable medium and apparatus for performing the method
JP7242675B2 (en) Compilation device and method
CN108804913B (en) Application program running method and device
CN117313046A (en) Code reinforcement method, code loading method, device and medium
CN113626773B (en) Code protection method based on intermediate language
CN110535642B (en) Method for distributing storage keys, intelligent terminal and storage medium
US20090138848A1 (en) Computer readable recording medium on which program converting process program is recorded, program converting method, and program converting apparatus
CN111475168A (en) Code compiling method and device
CN116339688A (en) Python code reinforcement method, system, storage medium and computer equipment based on byte code replacement
CN110147655A (en) The security protection system and method for application program
CN104866740A (en) Static analysis preventing method and device for files
EP3876119A1 (en) Method for protecting a data in a software application
CN116235174A (en) Apparatus and method for performing encryption algorithm
CN107205001A (en) The update method and device of python scripts, client, server
US20170134379A1 (en) Method for securing an application and data
CN111291333A (en) Java application program encryption method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication