CN116561717A - Python flattening control flow confusion method based on computational aggregation joint confusion - Google Patents
Python flattening control flow confusion method based on computational aggregation joint confusion Download PDFInfo
- Publication number
- CN116561717A CN116561717A CN202310505365.9A CN202310505365A CN116561717A CN 116561717 A CN116561717 A CN 116561717A CN 202310505365 A CN202310505365 A CN 202310505365A CN 116561717 A CN116561717 A CN 116561717A
- Authority
- CN
- China
- Prior art keywords
- code
- block
- blocks
- confusion
- code block
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 30
- 230000002776 aggregation Effects 0.000 title claims abstract description 15
- 238000004220 aggregation Methods 0.000 title claims abstract description 15
- 238000004422 calculation algorithm Methods 0.000 claims abstract description 8
- 238000004364 calculation method Methods 0.000 claims abstract description 7
- 230000006870 function Effects 0.000 claims description 30
- 230000004083 survival effect Effects 0.000 claims description 12
- 125000004122 cyclic group Chemical group 0.000 claims description 6
- 238000003780 insertion Methods 0.000 claims description 6
- 230000037431 insertion Effects 0.000 claims description 6
- 238000013507 mapping Methods 0.000 claims description 6
- 230000008569 process Effects 0.000 claims description 6
- 230000007704 transition Effects 0.000 claims description 3
- 230000009286 beneficial effect Effects 0.000 abstract description 2
- 238000005516 engineering process Methods 0.000 description 2
- 238000005206 flow analysis Methods 0.000 description 2
- 238000010949 in-process test method Methods 0.000 description 2
- 238000011160 research Methods 0.000 description 2
- 230000004931 aggregating effect Effects 0.000 description 1
- 230000004075 alteration Effects 0.000 description 1
- 238000006243 chemical reaction Methods 0.000 description 1
- 238000004883 computer application Methods 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/10—Protecting distributed programs or content, e.g. vending or licensing of copyrighted material ; Digital rights management [DRM]
- G06F21/12—Protecting executable software
- G06F21/14—Protecting executable software against software analysis or reverse engineering, e.g. by obfuscation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/425—Lexical analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/427—Parsing
-
- Y—GENERAL 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
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D30/00—Reducing energy consumption in communication networks
- Y02D30/50—Reducing energy consumption in communication networks in wire-line communication networks, e.g. low power modes or reduced link rate
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Multimedia (AREA)
- Technology Law (AREA)
- Computer Hardware Design (AREA)
- Computer Security & Cryptography (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
The invention discloses a Python flattening control flow confusion method based on computational aggregation joint confusion, which comprises the following steps: step S1: computing an aggregate joint confusion construct invalid code block; step S2: the dynamic branch assignment algorithm is executed with the N-state opaque predicate control code block; step S3: flattening the control flow, analyzing the codes after calculation and aggregation, and flattening the source program codes by combining the code block relation maintained by the Blocks, wherein the method has the beneficial effects that: the control flow circulation complexity is improved, namely the reverse attack difficulty is increased, the time is improved, the code comprehensive complexity and the code confusion index are improved, and the confusion intensity and the performance are greatly improved.
Description
Technical Field
The invention relates to the field of computer application, in particular to a Python flattening control flow confusion method based on computational aggregation joint confusion.
Background
At present, there are many researches on protection of compiled languages, and there are still few researches on code protection technology of Python dynamic explanatory scripting languages. This is mainly because the Python code execution flow is flexible, and the implementation difficulty of the execution code confusion technology is high. In order to protect the security of software, common code protection methods include techniques of encrypting the software by different encryption methods, adding digital watermarks, and code confusion, where code confusion is one of the most common techniques.
The flattening control flow method adopted by the prior Python control flow confusion method mainly aims at maintaining a correct control flow structure by updating the value of a variable next to the entry value of the next code block after the execution of each code block is finished, and cannot resist dynamic control flow analysis while having much additional cost.
Disclosure of Invention
The invention aims to provide a Python flattening control flow confusion method based on computational aggregation joint confusion, which aims to solve the problems in the background art.
In order to achieve the above purpose, the present invention provides the following technical solutions: a Python flattening control flow confusion method based on computational aggregation joint confusion comprises the following steps:
step S1: computing an aggregate joint confusion construct invalid code block;
step S2: the dynamic branch assignment algorithm is executed with the N-state opaque predicate control code block;
step S3: flattening the control flow, analyzing the codes after calculation aggregation, and flattening the source program codes by combining the code block relation maintained by the Blocks.
Specifically, the specific flow of step S1 is as follows:
step S11: analyzing an abstract syntax tree of the acquired codes by using an AST module of a Python official;
step S12: declaring a global variable list to record survival variables in the code execution sequence process, searching a module selection function with function Call assignment (value=call ()) type in a sequence execution code block, randomly selecting one survival variable in the global variable list, constructing a statement containing the survival variable, adding the statement to the insertion point before adding the statement variable to the insertion point, and adding the created statement variable at the position of the Call function;
step S13: adopting an aggregation confusion method for code blocks which are sequentially executed, adopting inlining to obtain a function f and a code block A, and calling f at the position of the original code block which is sequentially executed;
step S14: copying a new function used by calling the survival variable after the function is built-in to the code blocks in the cyclic code block and the branch code block, and calling the code blocks after the selected code block;
step S15: externally connecting the functions after the code blocks are added, separating the code blocks which have different logics but do not influence the execution result into different functions, and reserving part of the code blocks;
step S16: in the whole process, carrying out attribute marking on the body of the code block, circulating the code block and the externally connected code block;
specifically, the specific steps of step S2 are as follows:
step S21: marking the attribute of the code blocks in the sequential execution blocks as N, marking the added invalid code blocks as R, maintaining a blocks table, and marking the leading code blocks and the following code blocks;
step S22: marking the partitioned code blocks with BSKEY and BS according to the execution sequence, wherein the BSKEY is unique, BN is Body (grammar tree form) of the code block, and BN marked on the block is BSKEY of the code block;
step S23: for a cyclic code block in the function, a branch code block True branches to mark Flag as T, false as F, and default is not marked;
step S24: creating dynamic GetBranch dynamic branch assignment algorithm function according to the basic Block value, controlling the execution sequence and the next value of the externally connected code blocks through blocks and the current BSKEY, and controlling the execution sequence and whether to execute the internally connected code blocks;
step S25: performing entry in the control loop code block by using the N-state opaque predicate, and hiding jump-in entry value.
Specifically, the specific steps of step S3 are as follows:
step S31: obtaining blocks and a source code program SA after invalid codes are added according to the steps of the second section;
step S32: code blocks joining the jumps are constructed. Obtaining the relation between the key of the Block and the Block object, mapping the relation into the map, and then constructing the key and the code Block lexical Block added with the entering code Block and the skip according to the mapping relation;
step S33: an entry code block operation using an N-state opaque predicate addition; the jump Block dynamic GetBranch is added to control the jump transition quantity to be divided into two types, wherein one type is that the branch sentences are separated according to the follow-up relation in the Block, and the other type of non-branch sentences are directly added;
step S34: the joining distributor combines the code blocks. Flattening the code blocks in the step S32, and keeping the execution sequence unchanged;
step S35: using layout confusion to carry out confusion on the calculation of the Block and the N-state opaque predicate output;
step S36: replacing the original code tree with the flattened code tree.
Compared with the prior art, the invention has the beneficial effects that:
the method is characterized in that an irrelevant branch code block is created by a method of computing, aggregating and mixing, and is inserted into a basic block path to perform control flow flattening processing together, an execution flow is controlled by a mode of combining a dynamic branch assignment algorithm with an N-state opaque predicate, the value of a jump node is hidden, the data flow is changed from in-process analysis to in-process analysis, the actual running path of a program is mixed, the control flow analysis difficulty is increased, the control flow circulation complexity is improved, namely the reverse attack difficulty is increased, the time is increased, the code comprehensive complexity and the code confusion index are improved, and the confusion intensity and the performance are greatly improved.
Drawings
FIG. 1 is a schematic flow chart of constructing invalid code blocks;
FIG. 2 is a schematic diagram of an inline and an inline conversion;
FIG. 3 is a schematic flow chart of the function1 building of invalid blocks;
FIG. 4 is a Block class and example;
fig. 5 is a flattening control flow result.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Referring to fig. 1-5, the present invention provides a technical solution: a Python flattening control flow confusion method based on computational aggregation joint confusion comprises the following steps:
step S1: computing an aggregate joint confusion construct invalid code block;
step S2: the dynamic branch assignment algorithm is executed with the N-state opaque predicate control code block;
step S3: flattening the control flow, analyzing the codes after calculation aggregation, and flattening the source program codes by combining the code block relation maintained by the Blocks.
The specific flow of step S1 is as follows:
step S11: analyzing an abstract syntax tree of the acquired codes by using an AST module of a Python official;
step S12: declaring a global variable list to record survival variables in the code execution sequence process, searching a module selection function with function Call assignment (value=call ()) type in a sequence execution code block, randomly selecting one survival variable in the global variable list, constructing a statement containing the survival variable, adding the statement to the insertion point before adding the statement variable to the insertion point, and adding the created statement variable at the position of the Call function;
step S13: adopting an aggregation confusion method for code blocks which are sequentially executed, adopting inlining to obtain a function f and a code block A, and calling f at the position of the original code block which is sequentially executed;
step S14: copying a new function used by calling the survival variable after the function is built-in to the code blocks in the cyclic code block and the branch code block, and calling the code blocks after the selected code block;
step S15: externally connecting the functions after the code blocks are added, separating the code blocks which have different logics but do not influence the execution result into different functions, and reserving part of the code blocks;
step S16: in the whole process, carrying out attribute marking on the body of the code block, circulating the code block and the externally connected code block;
the specific steps of step S2 are as follows:
step S21: marking the attribute of the code blocks in the sequential execution blocks as N, marking the added invalid code blocks as R, maintaining a blocks table, and marking the leading code blocks and the following code blocks;
step S22: marking the partitioned code blocks with BSKEY and BS according to the execution sequence, wherein the BSKEY is unique, BN is Body (grammar tree form) of the code block, and BN marked on the block is BSKEY of the code block;
step S23: for a cyclic code block in the function, a branch code block True branches to mark Flag as T, false as F, and default is not marked;
step S24: creating dynamic GetBranch dynamic branch assignment algorithm function according to the basic Block value, controlling the execution sequence and the next value of the externally connected code blocks through blocks and the current BSKEY, and controlling the execution sequence and whether to execute the internally connected code blocks;
step S25: performing entry in the control loop code block by using the N-state opaque predicate, and hiding jump-in entry value.
The specific steps of step S3 are as follows:
step S31: obtaining blocks and a source code program SA after invalid codes are added according to the steps of the second section;
step S32: code blocks joining the jumps are constructed. Obtaining the relation between the key of the Block and the Block object, mapping the relation into the map, and then constructing the key and the code Block lexical Block added with the entering code Block and the skip according to the mapping relation;
step S33: an entry code block operation using an N-state opaque predicate addition; the jump Block dynamic GetBranch is added to control the jump transition quantity to be divided into two types, wherein one type is that the branch sentences are separated according to the follow-up relation in the Block, and the other type of non-branch sentences are directly added;
step S34: the joining distributor combines the code blocks. Flattening the code blocks in the step S32, and keeping the execution sequence unchanged;
step S35: using layout confusion to carry out confusion on the calculation of the Block and the N-state opaque predicate output;
step S36: replacing the original code tree with the flattened code tree.
Although embodiments of the present invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made therein without departing from the principles and spirit of the invention, the scope of which is defined in the appended claims and their equivalents.
Claims (4)
1. A Python flattening control flow confusion method based on computational aggregation joint confusion is characterized by comprising the following steps:
step S1: computing an aggregate joint confusion construct invalid code block;
step S2: the dynamic branch assignment algorithm is executed with the N-state opaque predicate control code block;
step S3: flattening the control flow, analyzing the codes after calculation aggregation, and flattening the source program codes by combining the code block relation maintained by the Blocks.
2. The method for obfuscating a Python flat control flow based on computational-aggregate-joint-obfuscation of claim 1, wherein the specific flow of step S1 is as follows:
step S11: analyzing an abstract syntax tree of the acquired codes by using an AST module of a Python official;
step S12: declaring a global variable list to record survival variables in the code execution sequence process, searching a module selection function with function Call assignment (value=call ()) type in a sequence execution code block, randomly selecting one survival variable in the global variable list, constructing a statement containing the survival variable, adding the statement to the insertion point before adding the statement variable to the insertion point, and adding the created statement variable at the position of the Call function;
step S13: adopting an aggregation confusion method for code blocks which are sequentially executed, adopting inlining to obtain a function f and a code block A, and calling f at the position of the original code block which is sequentially executed;
step S14: copying a new function used by calling the survival variable after the function is built-in to the code blocks in the cyclic code block and the branch code block, and calling the code blocks after the selected code block;
step S15: externally connecting the functions after the code blocks are added, separating the code blocks which have different logics but do not influence the execution result into different functions, and reserving part of the code blocks;
step S16: and in the whole process, marking the body of the code block, circulating the code block and externally-connected code blocks by attributes.
3. The method for obfuscating a Python flat control flow based on computational-aggregate-joint-obfuscation of claim 1, wherein the specific steps of step S2 are as follows:
step S21: marking the attribute of the code blocks in the sequential execution blocks as N, marking the added invalid code blocks as R, maintaining a blocks table, and marking the leading code blocks and the following code blocks;
step S22: marking the partitioned code blocks with BSKEY and BS according to the execution sequence, wherein the BSKEY is unique, BN is Body of the code block, and BN of the last block is marked as the BSKEY of the code block;
step S23: for a cyclic code block in the function, a branch code block True branches to mark Flag as T, false as F, and default is not marked;
step S24: creating dynamic GetBranch dynamic branch assignment algorithm function according to the basic Block value, controlling the execution sequence and the next value of the externally connected code blocks through blocks and the current BSKEY, and controlling the execution sequence and whether to execute the internally connected code blocks;
step S25: performing entry in the control loop code block by using the N-state opaque predicate, and hiding jump-in entry value.
4. The method for obfuscating a Python flat control flow based on computational-aggregate-joint-obfuscation of claim 1, wherein the specific steps of step S3 are as follows:
step S31: obtaining blocks and a source code program SA after invalid codes are added according to the steps;
step S32: constructing a code Block added with a jump to obtain a key and Block object relation of a Block, mapping the key and the Block object relation into a map, and then constructing a key and a word method Block added with the code Block and the jump according to the mapping relation;
step S33: an entry code block operation using an N-state opaque predicate addition; the jump Block dynamic GetBranch is added to control the jump transition quantity to be divided into two types, wherein one type is that the branch sentences are separated according to the follow-up relation in the Block, and the other type of non-branch sentences are directly added;
step S34: adding a distributor to combine the code blocks, flattening the code blocks in the step S32, and keeping the execution sequence unchanged;
step S35: using layout confusion to carry out confusion on the calculation of the Block and the N-state opaque predicate output;
step S36: replacing the original code tree with the flattened code tree.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310505365.9A CN116561717A (en) | 2023-05-08 | 2023-05-08 | Python flattening control flow confusion method based on computational aggregation joint confusion |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310505365.9A CN116561717A (en) | 2023-05-08 | 2023-05-08 | Python flattening control flow confusion method based on computational aggregation joint confusion |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116561717A true CN116561717A (en) | 2023-08-08 |
Family
ID=87494050
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310505365.9A Pending CN116561717A (en) | 2023-05-08 | 2023-05-08 | Python flattening control flow confusion method based on computational aggregation joint confusion |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116561717A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114428743A (en) * | 2022-01-27 | 2022-05-03 | 北京信息科技大学 | Software replication rate measuring method |
-
2023
- 2023-05-08 CN CN202310505365.9A patent/CN116561717A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114428743A (en) * | 2022-01-27 | 2022-05-03 | 北京信息科技大学 | Software replication rate measuring method |
CN114428743B (en) * | 2022-01-27 | 2024-08-16 | 北京信息科技大学 | Software replication rate measurement method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112100054B (en) | Data management and control oriented program static analysis method and system | |
US11579856B2 (en) | Multi-chip compatible compiling method and device | |
Christopoulou et al. | Automated refactoring to the strategy design pattern | |
CN111249736B (en) | Code processing method and device | |
CN103984582A (en) | Method and device for hot updating | |
CN109739494B (en) | Tree-LSTM-based API (application program interface) use code generation type recommendation method | |
CN105511873A (en) | User interface control display method and device | |
Feliachi et al. | Isabelle/Circus: A process specification and verification environment | |
CN114611074A (en) | Method, system, equipment and storage medium for obfuscating source code of solid language | |
CN110673852B (en) | Method, system and equipment for realizing control flow flattening based on front end of compiler | |
CN107515739A (en) | Improve the method and device of code execution performance | |
CN116561717A (en) | Python flattening control flow confusion method based on computational aggregation joint confusion | |
JP2006085740A (en) | Application software configuration method | |
US5845126A (en) | Method of, system for, and computer program product for providing inlined nested array constructors using normalized counters | |
De Roover | A logic meta-programming foundation for example-driven pattern detection in object-oriented programs | |
US7831964B2 (en) | Program automatic converting method and program automatic converting device | |
CN109086038B (en) | Spark-based big data development method and device, and terminal | |
US20090064092A1 (en) | Visual programming language optimization | |
Wang et al. | Learning Program Representations with a Tree-Structured Transformer | |
CN113641361B (en) | Code hiding method and device based on Clang | |
Garcia-Contreras et al. | Efficient modular SMT-based model checking of pointer programs | |
CN111796832A (en) | Hot patch file generation method, device, equipment and storage medium | |
US20120330878A1 (en) | Conventions for inferring data models | |
CN117369867B (en) | Instruction set and tool chain automatic generation oriented instruction set architecture model description method | |
CN118779851A (en) | Code confusion method and electronic equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |