CN112115427B - Code confusion method, device, electronic equipment and storage medium - Google Patents
Code confusion method, device, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN112115427B CN112115427B CN202010819524.9A CN202010819524A CN112115427B CN 112115427 B CN112115427 B CN 112115427B CN 202010819524 A CN202010819524 A CN 202010819524A CN 112115427 B CN112115427 B CN 112115427B
- Authority
- CN
- China
- Prior art keywords
- code block
- address
- instruction
- code
- sub
- 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.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; 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
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Multimedia (AREA)
- Technology Law (AREA)
- Computer Hardware Design (AREA)
- Computer Security & Cryptography (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
Description
技术领域Technical Field
本发明涉及计算机安全技术领域,尤其涉及一种代码混淆方法、装置、电子设备及存储介质。The present invention relates to the field of computer security technology, and in particular to a code obfuscation method, device, electronic device and storage medium.
背景技术Background technique
随着信息科学技术的发展,软件系统在为用户带来便利的同时,其安全性也面临严重威胁。攻击者通过反编译、反汇编、动态调试等逆向手段,可轻易获取软件包含的用户私有信息、核心算法、关键业务流程,甚至软件的源代码。这给企业的软件知识产权保护造成了巨大损失。With the development of information science and technology, software systems bring convenience to users, but their security also faces serious threats. Attackers can easily obtain user private information, core algorithms, key business processes, and even software source code contained in the software through reverse means such as decompilation, disassembly, and dynamic debugging. This has caused huge losses to the company's software intellectual property protection.
为了有效抵御攻击者针对软件的逆向分析,软件开发人员提出了软件加密,代码混淆,软件水印,防篡改等保护技术。代码混淆技术是保障软件安全的关键技术之一,它在不改变原程序语义的前提下,把程序的源代码和内部结构逻辑转换为一种更难分析、更难修改的形式,大大增加攻击者逆向分析成本。In order to effectively resist the reverse analysis of software by attackers, software developers have proposed protection technologies such as software encryption, code obfuscation, software watermarking, and anti-tampering. Code obfuscation technology is one of the key technologies to ensure software security. Without changing the semantics of the original program, it converts the source code and internal structure logic of the program into a form that is more difficult to analyze and modify, greatly increasing the cost of reverse analysis for attackers.
控制流混淆是代码混淆中比较成熟和关键的技术,它通过改变原程序的控制流或使控制流复杂化来隐藏程序真实的执行逻辑,增加破解者分析及重构程序控制流的难度,从而保护源代码。目前研究较多的控制流混淆技术的实现方法包括:Control flow obfuscation is a relatively mature and key technology in code obfuscation. It hides the real execution logic of the program by changing the control flow of the original program or making the control flow complicated, making it more difficult for crackers to analyze and reconstruct the control flow of the program, thereby protecting the source code. The implementation methods of control flow obfuscation technology that are currently being studied include:
(1)不透明谓词(1) Opaque predicates
对控制流图中的基本块,添加从表达式本身很难推断出其值的恒真、恒假或时真时假的不透明谓词,混淆基本块的真实执行流程,使控制流变得更复杂。For the basic blocks in the control flow graph, add opaque predicates whose values are always true, always false, or sometimes true and sometimes false, which are difficult to infer from the expression itself, to confuse the actual execution flow of the basic blocks and make the control flow more complicated.
(2)控制流平坦化(2) Control flow flattening
通过破坏函数控制流图中容易识别的条件及循环结构,将易于阅读的代码流程重组成一个难于理解的switch case形式的代码执行流程。By destroying the easily identifiable conditions and loop structures in the function control flow graph, the easy-to-read code flow is reorganized into a difficult-to-understand switch case code execution flow.
(3)插入虚假控制流(3) Inserting false control flow
利用不透明谓词技术,向原始控制流中插入多余的控制流,增加原始控制流的复杂度,提高攻击者重建出原始控制流的难度。By using opaque predicate technology, redundant control flows are inserted into the original control flow, increasing the complexity of the original control flow and making it more difficult for attackers to reconstruct the original control flow.
使用上述控制流混淆方法混淆程序后特征较明显,容易被攻击者发现并利用现有的逆向技术进行破解,还原代码控制流。如经常被使用的不透明谓词是有限数量的较复杂的数学表达式,可收集整理后在逆向分析时直接过滤掉;又如控制流平坦化后程序拥有一个明显的switch case结构,可在动态调试过程记录代码块的执行顺序,重建控制流。The features of the program after being obfuscated using the above control flow obfuscation method are obvious, and it is easy for attackers to discover and crack it using existing reverse engineering techniques to restore the code control flow. For example, the frequently used opaque predicates are a limited number of complex mathematical expressions, which can be collected and sorted and directly filtered out during reverse analysis; for example, after the control flow is flattened, the program has an obvious switch case structure, and the execution order of the code blocks can be recorded during the dynamic debugging process to reconstruct the control flow.
发明内容Summary of the invention
本发明实施例提供一种代码混淆方法、装置、电子设备及存储介质,用以解决现有技术中的代码混淆方法混淆程序代码后,程序特征较为明显,容易被攻击者发现并破解的缺陷。The embodiments of the present invention provide a code obfuscation method, device, electronic device and storage medium, which are used to solve the defect that after the code obfuscation method in the prior art obfuscates the program code, the program features are more obvious and can be easily discovered and cracked by attackers.
本发明第一方面实施例提供一种代码混淆方法,包括:A first aspect of the present invention provides a code obfuscation method, comprising:
根据目标程序中的函数的控制流走向,确定所述函数中的基本代码块;Determine the basic code block in the function according to the control flow direction of the function in the target program;
对所述基本代码块进行分割,得到子代码块;Splitting the basic code block to obtain sub-code blocks;
将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址;其中,所述代码块包括子代码块,或包括子代码块以及未被分割的基本代码块。Converting a target address of a non-conditional jump instruction in a code block into an address determined when the target program is running; wherein the code block includes a sub-code block, or includes a sub-code block and an undivided basic code block.
上述技术方案中,在所述对所述基本代码块进行分割,得到子代码块的步骤之后,方法还包括:In the above technical solution, after the step of dividing the basic code block to obtain sub-code blocks, the method further includes:
打乱所述目标程序中的函数内的代码块在所属函数内的排布顺序。The arrangement order of the code blocks in the function in the target program is disrupted.
上述技术方案中,所述将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址,具体包括:In the above technical solution, converting the target address of the non-conditional jump instruction in the code block into an address determined when the target program is running specifically includes:
在具有非条件跳转指令的第一代码块与根据所述非条件跳转指令所要跳转的第二代码块之间插入地址计算代码块,并将所述非条件跳转指令的跳转目标变更为所述地址计算代码块;其中,所述地址计算代码块用于在运行时动态计算所述第二代码块的地址。An address calculation code block is inserted between a first code block having an unconditional jump instruction and a second code block to be jumped according to the unconditional jump instruction, and the jump target of the unconditional jump instruction is changed to the address calculation code block; wherein the address calculation code block is used to dynamically calculate the address of the second code block at runtime.
上述技术方案中,所述在具有非条件跳转指令的第一代码块与根据所述非条件跳转指令所要跳转的第二代码块之间插入地址计算代码块,具体包括:In the above technical solution, inserting an address calculation code block between a first code block having an unconditional jump instruction and a second code block to be jumped according to the unconditional jump instruction specifically includes:
在所述第一代码块与所述第二代码块之间插入地址计算代码块;Inserting an address calculation code block between the first code block and the second code block;
根据所述地址计算代码块的地址信息以及所述第二代码块的地址信息,计算所述地址计算代码块与所述第二代码块之间的地址偏移量;Calculating an address offset between the address calculation code block and the second code block according to the address information of the address calculation code block and the address information of the second code block;
将所述地址计算代码块内的非条件跳转指令所要跳转的地址修改为一个地址计算式,所述地址计算式包括:所述地址计算代码块自身的地址信息,所述地址计算代码块与所述第二代码块之间的地址偏移量。The address to be jumped by the unconditional jump instruction in the address calculation code block is modified into an address calculation formula, wherein the address calculation formula includes: the address information of the address calculation code block itself, and the address offset between the address calculation code block and the second code block.
上述技术方案中,方法还包括:In the above technical solution, the method further comprises:
将所述目标程序中对系统函数的直接调用指令替换为对系统函数的间接调用指令。The direct calling instruction to the system function in the target program is replaced by an indirect calling instruction to the system function.
上述技术方案中,所述将所述目标程序中对系统函数的直接调用指令替换为对系统函数的间接调用指令,具体包括:In the above technical solution, the step of replacing the direct call instruction to the system function in the target program with the indirect call instruction to the system function specifically includes:
根据系统函数的真实地址以及动态链接库生成间接调用指令,所述间接调用指令通过解析动态链接库中的函数地址的形式获取要执行的系统函数的真实地址;Generate an indirect call instruction according to the real address of the system function and the dynamic link library, wherein the indirect call instruction obtains the real address of the system function to be executed by parsing the function address in the dynamic link library;
将目标程序中对系统函数的直接调用指令替换为对系统函数的间接调用指令。Replace the direct call instructions to the system function in the target program with indirect call instructions to the system function.
上述技术方案中,所述根据第二预设规则对所述基本代码块进行分割,得到子代码块,具体包括:In the above technical solution, the basic code block is segmented according to the second preset rule to obtain sub-code blocks, which specifically includes:
判断所述基本代码块是否满足预设规则,当满足预设规则时,对所述基本代码块进行分割,得到第一分割结果;Determine whether the basic code block satisfies a preset rule, and when the preset rule is satisfied, segment the basic code block to obtain a first segmentation result;
判断所述第一分割结果的尾部是否存在跳转指令,当不存在跳转指令时,在所述第一分割结果的尾部添加跳转指令,得到子代码块;其中,所述跳转指令用于跳转到所述第一分割结果的最后一条指令在所述基本代码块中的下一条指令。Determine whether there is a jump instruction at the end of the first segmentation result. When there is no jump instruction, add a jump instruction at the end of the first segmentation result to obtain a sub-code block; wherein the jump instruction is used to jump to the next instruction of the last instruction of the first segmentation result in the basic code block.
本发明第二方面实施例提供一种代码混淆装置,包括:A second aspect of the present invention provides a code obfuscation device, comprising:
基本代码块确定模块,用于根据目标程序中的函数的控制流走向,确定所述函数中的基本代码块;A basic code block determination module, used to determine a basic code block in a function in a target program according to the control flow direction of the function;
子代码块生成模块,用于对所述基本代码块进行分割,得到子代码块;A sub-code block generation module, used for segmenting the basic code block to obtain sub-code blocks;
指令转换模块,用于将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址;其中,所述代码块包括子代码块,或包括子代码块以及未被分割的基本代码块。An instruction conversion module is used to convert the target address of the non-conditional jump instruction in the code block into an address determined when the target program is running; wherein the code block includes a sub-code block, or includes a sub-code block and an undivided basic code block.
本发明第三方面实施例提供一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现如本发明第一方面实施例所述代码混淆方法的步骤。The third aspect of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the code obfuscation method described in the first aspect of the present invention are implemented.
本发明第四方面实施例提供一种非暂态计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现如本发明第一方面实施例所述代码混淆方法的步骤。The fourth aspect of the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the code obfuscation method described in the first aspect of the present invention are implemented.
本发明实施例提供的代码混淆方法、装置、电子设备及存储介质,通过将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址,从而切断了具有非条件跳转指令的代码块与所要跳转的代码块之间的直接跳转关系,增加了反向分析的难度。The code obfuscation method, device, electronic device and storage medium provided by the embodiments of the present invention convert the target address of the unconditional jump instruction in the code block into an address determined when the target program is running, thereby cutting off the direct jump relationship between the code block with the unconditional jump instruction and the code block to be jumped, thereby increasing the difficulty of reverse analysis.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
图1为本发明实施例提供的代码混淆方法的流程图;FIG1 is a flow chart of a code obfuscation method provided by an embodiment of the present invention;
图2为在具有非条件跳转指令的代码块与所要跳转的代码块之间插入地址计算代码块的示意图;FIG2 is a schematic diagram of inserting an address calculation code block between a code block having a non-conditional jump instruction and a code block to be jumped;
图3为一个函数未混淆前,用逆向工具IDA查看到的控制流图;Figure 3 shows a control flow graph of a function before it is obfuscated, viewed using the reverse engineering tool IDA;
图4为与图3相关的函数在被混淆后,用逆向工具IDA查看到的控制流图;FIG4 is a control flow graph of the function related to FIG3 after being obfuscated, viewed using the reverse engineering tool IDA;
图5为本发明实施例提供的代码混淆装置的示意图;FIG5 is a schematic diagram of a code obfuscation device provided by an embodiment of the present invention;
图6为本发明实施例提供的一种电子设备的实体结构示意图。FIG6 is a schematic diagram of a physical structure of an electronic device provided by an embodiment of the present invention.
具体实施方式Detailed ways
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
图1为本发明实施例提供的代码混淆方法的流程图,如图1所示,本发明实施例提供的代码混淆方法包括:FIG. 1 is a flow chart of a code obfuscation method provided by an embodiment of the present invention. As shown in FIG. 1 , the code obfuscation method provided by an embodiment of the present invention includes:
步骤101、根据目标程序中的函数的控制流走向,确定所述函数中的基本代码块。Step 101: Determine a basic code block in a function in a target program according to the control flow direction of the function.
在本发明实施例中,目标程序是指采用本发明实施例提供的代码混淆方法进行代码混淆的程序。具体的说,目标程序中的函数是代码混淆操作的对象,即需要对目标程序所包含的函数内的代码进行混淆。In the embodiment of the present invention, the target program refers to a program that is obfuscated using the code obfuscation method provided by the embodiment of the present invention. Specifically, the function in the target program is the object of the code obfuscation operation, that is, the code in the function contained in the target program needs to be obfuscated.
本领域技术人员都知道,计算机领域中的函数是一个固定的程序段,它能够独立地完成一个特定的功能。函数的基本组成单位是指令。执行指令可实现某一步具体的操作。基本代码块介于函数与指令之间。基本代码块包括多个指令,而函数又可包括一个或多个基本代码块。Those skilled in the art know that a function in the computer field is a fixed program segment that can independently complete a specific function. The basic unit of a function is an instruction. Executing an instruction can achieve a specific operation. A basic code block is between a function and an instruction. A basic code block includes multiple instructions, and a function can include one or more basic code blocks.
目标程序内部的执行逻辑被称为控制流走向。控制流走向反映了函数之间的调用关系以及函数内部各个指令的执行流程。作为一种可选的实现方式,目标程序的函数的控制流走向可以采用控制流图表示。The execution logic inside the target program is called the control flow. The control flow reflects the calling relationship between functions and the execution flow of each instruction inside the function. As an optional implementation method, the control flow of the function of the target program can be represented by a control flow graph.
在本发明实施例中,控制流走向为预先分析得到的,在本发明的其他实施例中,也可通过LLVM提供的工具及函数库对目标程序进行分析,从而得到目标程序的函数的控制流走向。LLVM将目标程序的源代码编译为中间代码文件,解析中间代码文件,并遍历中间代码文件中的函数,从而得到函数的控制流走向。In the embodiment of the present invention, the control flow direction is obtained by pre-analysis. In other embodiments of the present invention, the target program can also be analyzed by the tools and function libraries provided by LLVM to obtain the control flow direction of the function of the target program. LLVM compiles the source code of the target program into an intermediate code file, parses the intermediate code file, and traverses the functions in the intermediate code file to obtain the control flow direction of the function.
作为一种可选的实现方式,可利用LLVM提供的工具及函数库分析函数的控制流走向,将函数中所有switch-case结构替换为if-else结构,获取函数原始控制流基本代码块。由于switch-case结构容易被攻击者用于对目标程序的反向分析,因此需要替换函数中的所有switch-case结构为if-else结构。As an optional implementation method, you can use the tools and function libraries provided by LLVM to analyze the control flow of the function, replace all switch-case structures in the function with if-else structures, and obtain the basic code blocks of the original control flow of the function. Since the switch-case structure can be easily used by attackers to reverse analyze the target program, it is necessary to replace all switch-case structures in the function with if-else structures.
根据目标程序的控制流走向,对函数做进一步的切分,可得到基本代码块。在对函数做进一步切分时,可根据目标程序中的函数的控制流走向以及第一预设规则,从函数中切分出基本代码块。According to the control flow direction of the target program, the function is further segmented to obtain basic code blocks. When the function is further segmented, the basic code blocks can be segmented from the function according to the control flow direction of the function in the target program and the first preset rule.
根据所述第一预设规则,可确定基本代码块的起始指令,所述第一预设规则包括以下三项中的任意一项:According to the first preset rule, the starting instruction of the basic code block can be determined, and the first preset rule includes any one of the following three items:
a)函数的入口指令;a) Function entry instruction;
b)跳转指令的目标指令;b) target instruction of jump instruction;
c)跳转指令后的下一条指令且该指令并非跳转指令的目标指令。c) The next instruction after the jump instruction and this instruction is not the target instruction of the jump instruction.
在确定基本代码块的起始指令之后,将同一函数中两个基本代码块的起始指令之间的所有指令(不含第二个起始指令)构成一个基本代码块。After the start instruction of the basic code block is determined, all instructions between the start instructions of two basic code blocks in the same function (excluding the second start instruction) form a basic code block.
需要说明的是,本领域技术人员很容易理解,若一个函数中包括有switch-case结构,在将switch-case结构替换后,由该函数进一步切分所得到的基本代码块中,也将不再有switch-case结构。It should be noted that it is easy for those skilled in the art to understand that if a function includes a switch-case structure, after the switch-case structure is replaced, the basic code block obtained by further segmenting the function will no longer have the switch-case structure.
步骤102、对所述基本代码块进行分割,得到子代码块。Step 102: Segment the basic code block to obtain sub-code blocks.
为了进一步增加反向分析的难度,在本发明实施例中,可对基本代码块做进一步分割,得到子代码块。In order to further increase the difficulty of reverse analysis, in the embodiment of the present invention, the basic code block may be further divided to obtain sub-code blocks.
子代码块是基本代码块的一部分,包括有多个指令。在对基本代码块进行分割前,首先要判断基本代码块是否满足第二预设规则。所述第二预设规则用于描述基本代码块的分割条件。例如,第二预设规则的一种实现方式是预设的指令条数,如5条。则在判断基本代码块是否满足第二预设规则时,判断基本代码块中的指令条数是否有5条,如果大于或等于5条,则基本代码块满足第二预设规则,可做进一步的分割处理;如果小于5条,则不能对该基本代码块做分割处理。第二预设规则的内容并不局限于预设的指令条数,还可以根据实际需要确定第二预设规则的内容。The sub-code block is a part of the basic code block, including multiple instructions. Before the basic code block is segmented, it is necessary to first determine whether the basic code block meets the second preset rule. The second preset rule is used to describe the segmentation condition of the basic code block. For example, one implementation method of the second preset rule is a preset number of instructions, such as 5. When determining whether the basic code block meets the second preset rule, determine whether the number of instructions in the basic code block is 5. If it is greater than or equal to 5, the basic code block meets the second preset rule and can be further segmented; if it is less than 5, the basic code block cannot be segmented. The content of the second preset rule is not limited to the preset number of instructions, and the content of the second preset rule can also be determined according to actual needs.
第二预设规则不仅可以用于判断基本代码块是否能被分割,还可以用于指导基本代码块的分割。在对基本代码块进行分割时,可根据第二预设规则(如预设的指令条数)分割基本代码块,得到子代码块。例如,预先设定每5条指令组成一个子代码块,那么在分割基本代码块时,将基本代码块中的连续的5条指令作为一个基本单元进行分割,得到相应的子代码块。若基本代码块在某一次分割后,剩余的指令不足5条时,可将剩余指令作为一个基本单元组成一个子代码块。The second preset rule can not only be used to determine whether the basic code block can be split, but also can be used to guide the splitting of the basic code block. When the basic code block is split, the basic code block can be split according to the second preset rule (such as the preset number of instructions) to obtain sub-code blocks. For example, it is preset that every 5 instructions form a sub-code block, then when splitting the basic code block, the 5 consecutive instructions in the basic code block are split as a basic unit to obtain the corresponding sub-code block. If the basic code block has less than 5 instructions left after a certain split, the remaining instructions can be used as a basic unit to form a sub-code block.
需要说明的是,在生成基本代码块时,以跳转指令作为分割的界线,因此切分所得到的基本代码块之间的逻辑关系不会被中断。但在生成子代码块时,除了少数子代码块(如基本代码块尾部的子代码块)之外,子代码块的尾部在被分割前并不存在诸如跳转指令等与其他子代码块发生明确逻辑关系的指令,因此在分割基本代码块、生成子代码块时,需要在子代码块的尾部添加一个跳转指令,从而明确当前子代码块执行完成后所要执行的下一个子代码块。It should be noted that when generating a basic code block, the jump instruction is used as the dividing line, so the logical relationship between the basic code blocks obtained by segmentation will not be interrupted. However, when generating a sub-code block, except for a few sub-code blocks (such as the sub-code block at the end of the basic code block), there are no instructions such as jump instructions at the end of the sub-code block that have a clear logical relationship with other sub-code blocks before being segmented. Therefore, when segmenting a basic code block and generating a sub-code block, a jump instruction needs to be added to the end of the sub-code block to clarify the next sub-code block to be executed after the current sub-code block is executed.
例如,某一函数中的一个基本代码块的代码如下:For example, a basic code block in a function is as follows:
label%3:label%3:
%4=alloca i8*,align 8%4 = alloca i8*, align 8
%5=alloca i32*,align 8%5 = alloca i32*, align 8
%6=alloca i32*,align 4%6 = alloca i32*, align 4
%7=alloca i32*,align 4%7 = alloca i32*, align 4
%8=alloca i32*,align 4%8 = alloca i32*, align 4
store i8*%0,i8**%4,align 8store i8*%0,i8**%4,align 8
store i32*%1,i32**%5,align 8store i32*%1,i32**%5,align 8
store i32*%2,i32**%6,align 4store i32*%2,i32**%6,align 4
store i32*%0,i32**%7,align 4store i32*%0,i32**%7,align 4
store i32*%0,i32**%8,align 4store i32*%0,i32**%8,align 4
br label%9br label%9
对上述基本代码块按照一定的规则进行切分,可得到以下多个子代码块:By dividing the above basic code block according to certain rules, the following multiple sub-code blocks can be obtained:
子代码块1Subcode block 1
label%3:label%3:
%4=alloca i8*,align 8%4 = alloca i8*, align 8
%5=alloca i32*,align 8%5 = alloca i32*, align 8
%6=alloca i32*,align 4%6 = alloca i32*, align 4
br label%.splitbr label%.split
子代码块2Subcode block 2
label.split:label.split:
%7=alloca i32*,align 4%7 = alloca i32*, align 4
%8=alloca i32*,align 4%8 = alloca i32*, align 4
br label%.split.splitbr label%.split.split
子代码块3Subcode block 3
label.split.split:label.split.split:
store i8*%0,i8**%4,align 8store i8*%0,i8**%4,align 8
br label%.split.split.splitbr label%.split.split.split
子代码块4Subcode block 4
label.split.split.split:label.split.split.split:
store i32*%1,i32**%5,align 8store i32*%1,i32**%5,align 8
store i32*%2,i32**%6,align 4store i32*%2,i32**%6,align 4
store i32*%0,i32**%7,align 4store i32*%0,i32**%7,align 4
store i32*%0,i32**%8,align 4store i32*%0,i32**%8,align 4
br label%9br label%9
从上述的例子中可以看出,从基本代码块新划分得到的子代码块1—子代码块3的尾部都新添加了跳转指令,根据这些新添加的跳转指令可以跳转到下一个子代码块。It can be seen from the above example that jump instructions are newly added to the tails of sub-code blocks 1 to sub-code blocks 3 newly divided from the basic code block, and the next sub-code block can be jumped according to these newly added jump instructions.
步骤103、将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址。Step 103: Convert the target address of the non-conditional jump instruction in the code block to an address determined when the target program is running.
目标程序中的各个函数在经过之前步骤的操作后,函数中包括有子代码块,在某些情况下,函数内的一些基本代码块不满足分割的条件,因此函数中也会包括未被分割的基本代码块。将未被分割的基本代码块(如果有的话)与子代码块统一记为代码块。After the operations in the previous steps, each function in the target program includes sub-code blocks. In some cases, some basic code blocks in the function do not meet the conditions for segmentation, so the function also includes unsegmented basic code blocks. The unsegmented basic code blocks (if any) and sub-code blocks are uniformly recorded as code blocks.
所述将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址,具体包括:The converting the target address of the non-conditional jump instruction in the code block into an address determined when the target program is running specifically includes:
在具有非条件跳转指令的第一代码块与根据所述非条件跳转指令所要跳转的第二代码块之间插入地址计算代码块,并将所述非条件跳转指令的跳转目标变更为所述地址计算代码块;所述地址计算代码块用于在运行时动态计算所述第二代码块的地址。An address calculation code block is inserted between a first code block having an unconditional jump instruction and a second code block to be jumped according to the unconditional jump instruction, and the jump target of the unconditional jump instruction is changed to the address calculation code block; the address calculation code block is used to dynamically calculate the address of the second code block at runtime.
跳转指令包括条件跳转指令与非条件跳转指令。非条件跳转指令也被称为直接跳转指令,该指令无需进行条件判断即需要进行跳转操作。跳转指令能够清晰地反映目标程序的执行顺序,因此为了增加反向分析的难度,需要对跳转指令进行隐藏。Jump instructions include conditional jump instructions and unconditional jump instructions. Unconditional jump instructions are also called direct jump instructions, which require jump operations without conditional judgment. Jump instructions can clearly reflect the execution order of the target program, so in order to increase the difficulty of reverse analysis, jump instructions need to be hidden.
具体的说,在具有非条件跳转指令的第一代码块与所要跳转的第二代码块之间插入地址计算代码块,同时通过修改第一代码块的非条件跳转指令的目标地址来切断具有非条件跳转指令的第一代码块与根据所述非条件跳转指令所要跳转的第二代码块之间的直接控制流关系,即将第一代码块的非条件跳转指令的目标地址由所述第二代码块修改为所述地址计算代码块。所述地址计算模块中包括有一条非条件跳转指令,该非条件跳转指令所要跳转的地址是一个地址计算式,所述地址计算式包括:地址计算代码块自身的地址信息,地址计算代码块与第二代码块之间的地址偏移量。所述地址计算代码块与所述第二代码块之间的地址偏移量可根据所述地址计算代码块的地址信息以及所述第二代码块的地址信息预先计算得到。Specifically, an address calculation code block is inserted between a first code block having an unconditional jump instruction and a second code block to be jumped, and at the same time, the direct control flow relationship between the first code block having an unconditional jump instruction and the second code block to be jumped according to the unconditional jump instruction is cut off by modifying the target address of the unconditional jump instruction of the first code block, that is, the target address of the unconditional jump instruction of the first code block is modified from the second code block to the address calculation code block. The address calculation module includes an unconditional jump instruction, and the address to be jumped by the unconditional jump instruction is an address calculation formula, and the address calculation formula includes: the address information of the address calculation code block itself, and the address offset between the address calculation code block and the second code block. The address offset between the address calculation code block and the second code block can be pre-calculated based on the address information of the address calculation code block and the address information of the second code block.
目标程序在运行时,可确定地址计算代码块自身的地址信息的具体取值,从而结合地址计算代码块与第二代码块之间的地址偏移量,计算出第二代码块的地址信息,进而实现到第二代码块的跳转。When the target program is running, it can determine the specific value of the address information of the address calculation code block itself, and then calculate the address information of the second code block in combination with the address offset between the address calculation code block and the second code block, thereby realizing a jump to the second code block.
这一操作可切断第一代码块与第二代码块之间的直接跳转关系,使得第二代码块的地址只能在目标程序运行时才能动态计算得到,增加了反向分析的难度。This operation can cut off the direct jump relationship between the first code block and the second code block, so that the address of the second code block can only be dynamically calculated when the target program is running, which increases the difficulty of reverse analysis.
例如,图2为在具有非条件跳转指令的代码块与所要跳转的代码块之间插入地址计算代码块的示意图。在图2所示的实施例中,假设目标程序中有代码块A和代码块B,图2最左侧描述了代码块A和代码块B的原始执行流程。按照原始执行流程,代码块A直接跳转到代码块B,代码块A中包括有伪跳转指令Jump B(实际可以是jump,mov,bx,jne等多种类型的指令)。按照本发明实施例的描述,首先,在代码块A与代码块B之间增加一个代码块T,此时代码块T的内容仅包含一条跳转代码块B的指令,同时代码块A中跳转到代码块B的指令Jump B变更为跳转到代码块T的指令Jump T。图2中间部分描述了在代码块A和代码块B之间增加代码块T。接着,计算代码块B与代码块T之间的地址偏移,记为offset。修改代码块T的内容为:获取T的地址,修改直接跳转指令为间接跳转,即将代码块T中直接跳转代码块B的Jump B指令替换为Jump T+offset,从而切断代码块A与代码块B的直接跳转关系,使得代码块B的地址只能在运行时动态计算得到。图2最右侧描述了修改代码块T中的地址内容。For example, FIG. 2 is a schematic diagram of inserting an address calculation code block between a code block with an unconditional jump instruction and a code block to be jumped. In the embodiment shown in FIG. 2 , it is assumed that there are code blocks A and code blocks B in the target program, and the leftmost side of FIG. 2 describes the original execution flow of code blocks A and code blocks B. According to the original execution flow, code block A directly jumps to code block B, and code block A includes a pseudo jump instruction Jump B (which can actually be various types of instructions such as jump, mov, bx, jne, etc.). According to the description of the embodiment of the present invention, first, a code block T is added between code block A and code block B. At this time, the content of code block T only includes an instruction to jump to code block B, and at the same time, the instruction Jump B in code block A that jumps to code block B is changed to the instruction Jump T that jumps to code block T. The middle part of FIG. 2 describes adding code block T between code block A and code block B. Next, the address offset between code block B and code block T is calculated, which is recorded as offset. Modify the content of code block T as follows: Get the address of T, modify the direct jump instruction to an indirect jump, that is, replace the Jump B instruction in code block T that directly jumps to code block B with Jump T+offset, thereby cutting off the direct jump relationship between code block A and code block B, so that the address of code block B can only be calculated dynamically at runtime. The rightmost side of Figure 2 describes the modification of the address content in code block T.
本发明实施例提供的代码混淆方法通过将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址,从而切断了具有非条件跳转指令的代码块与所要跳转的代码块之间的直接跳转关系,增加了反向分析的难度。The code obfuscation method provided by the embodiment of the present invention converts the target address of the unconditional jump instruction in the code block into an address determined when the target program is running, thereby cutting off the direct jump relationship between the code block with the unconditional jump instruction and the code block to be jumped, thereby increasing the difficulty of reverse analysis.
基于上述任一实施例,在本发明实施例中,在步骤102之后,方法还包括:Based on any of the above embodiments, in an embodiment of the present invention, after step 102, the method further includes:
打乱目标程序中的函数内部的代码块在所属函数内的顺序。Disrupt the order of code blocks within the target program's functions.
各个函数内部的代码块之间存在线性顺序,为了提高反向分析的难度,在本实施例中,打乱函数内部的代码块之间的顺序。There is a linear order between the code blocks within each function. In order to increase the difficulty of reverse analysis, in this embodiment, the order between the code blocks within the function is disrupted.
具体的说,在本发明实施例中,可为函数中的各个代码块设定编号,并生成一个能反映代码块编号的随机数组。例如,某一函数中共有N个代码块,按照从1至N的顺序为这些代码块编号。在为代码块编号后,可生成一个大小为N,内容为1至N且无重复数据的随机数组。这一随机数组中的数字并不按照数字的大小进行排序,而是随机排序。Specifically, in an embodiment of the present invention, a number may be set for each code block in a function, and a random array reflecting the code block number may be generated. For example, there are N code blocks in a function, and these code blocks are numbered in order from 1 to N. After the code blocks are numbered, a random array of size N, content from 1 to N and no repeated data may be generated. The numbers in this random array are not sorted according to the size of the numbers, but are randomly sorted.
有了所述的随机数组后,可将代码块按照随机数组的顺序重新排列,达到破坏函数原始布局的目的。例如,一个大小为10的随机数组中的数字排序为:1、3、8、5、7、4、6、2、9、10。在对代码块进行排序时,将编号为1的代码块放在函数中的首位,接着将编号为3的代码块放在函数中的第2位,再接着将编号为8的代码块放在函数中的第3位,以此类推,最后将编号为10的代码块放在函数中的第10位。With the random array, the code blocks can be rearranged in the order of the random array to achieve the purpose of destroying the original layout of the function. For example, the numbers in a random array of size 10 are arranged as follows: 1, 3, 8, 5, 7, 4, 6, 2, 9, 10. When sorting the code blocks, the code block numbered 1 is placed at the first position in the function, followed by the code block numbered 3 at the second position in the function, followed by the code block numbered 8 at the third position in the function, and so on, and finally the code block numbered 10 is placed at the tenth position in the function.
需要说明的是,本发明实施例中,打乱函数内部的代码块的顺序是指打乱代码块在函数中的静态布局顺序,由于各个代码块中包含有跳转指令,因此整个函数的动态执行逻辑并未改变,该函数依然可以正常执行。It should be noted that, in the embodiment of the present invention, disrupting the order of code blocks within a function refers to disrupting the static layout order of the code blocks in the function. Since each code block contains a jump instruction, the dynamic execution logic of the entire function is not changed, and the function can still be executed normally.
目标程序中包括有多个函数,对各个函数均可按照上述描述打乱其内部的代码块顺序。The target program includes multiple functions, and the order of the code blocks inside each function can be disrupted according to the above description.
本发明实施例提供的代码混淆方法通过从目标程序所包含的函数中获取基本代码块,并对基本代码块做分割,得到子代码块,然后对函数内未被分割的基本代码块以及子代码块进行乱序排布,从而改变目标程序中各个函数的内容布局,达到增加反向分析难度的目的。The code obfuscation method provided by the embodiment of the present invention obtains basic code blocks from the functions included in the target program, divides the basic code blocks to obtain sub-code blocks, and then arranges the undivided basic code blocks and sub-code blocks in the function in random order, thereby changing the content layout of each function in the target program, thereby increasing the difficulty of reverse analysis.
基于上述任一实施例,在本发明实施例中,方法还包括:Based on any of the above embodiments, in an embodiment of the present invention, the method further includes:
将目标函数中对系统函数的直接调用指令替换为对系统函数的间接调用指令。Replace the direct call instructions to the system function in the target function with indirect call instructions to the system function.
在本发明实施例中,系统函数是指C语言标准规定的库函数,如glibc中的函数。系统函数容易暴露某些关键代码的位置,因此需要隐藏目标程序中的系统函数。In the embodiment of the present invention, the system function refers to a library function specified by the C language standard, such as a function in glibc. The system function easily exposes the location of certain key codes, so the system function in the target program needs to be hidden.
在具体实现时,将目标程序中对系统函数的直接调用指令替换为对系统函数的间接调用指令,所述间接调用指令通过解析动态链接库中的函数地址的形式获取要执行的系统函数的真实地址。例如,在linux下,通过dlsym函数形式解析要执行的系统函数地址,从而引入系统函数;在windows下,通过GetProcAddress函数形式获取要执行的系统函数地址,从而引入系统函数。In the specific implementation, the direct call instruction of the system function in the target program is replaced with an indirect call instruction of the system function, and the indirect call instruction obtains the real address of the system function to be executed by parsing the function address in the dynamic link library. For example, under Linux, the address of the system function to be executed is parsed through the dlsym function form, thereby introducing the system function; under Windows, the address of the system function to be executed is obtained through the GetProcAddress function form, thereby introducing the system function.
例如,在一个实施例中,首先遍历目标程序中的函数,分析并获取函数调用中的系统函数,将所述系统函数记为sysFunc;接着,加密系统函数名,得到加密后的系统函数名encStr;然后,将目标程序中所有系统函数调用指令转变为间接调用指令,具体包括:用dlsym加载需要调用的系统函数,将相关函数的名称记为indirectCall,系统函数名将在运行时解密;最后,函数indirectCall替换目标函数中之前的系统函数。For example, in one embodiment, the functions in the target program are first traversed, the system functions in the function calls are analyzed and obtained, and the system functions are recorded as sysFunc; then, the system function name is encrypted to obtain the encrypted system function name encStr; then, all system function call instructions in the target program are converted into indirect call instructions, specifically including: using dlsym to load the system function to be called, recording the name of the related function as indirectCall, and the system function name will be decrypted at runtime; finally, the function indirectCall replaces the previous system function in the target function.
对应该实施例的相关代码如下:The relevant codes corresponding to this embodiment are as follows:
系统函数被替换前:Before the system function is replaced:
……
sysFunc(…)sysFunc(…)
……
系统函数被替换后:After the system function is replaced:
……
encStr=encode(“sysFunc”);encStr = encode("sysFunc");
indirectCall=dls ym((void*)0,decode(encStr))indirectCall = dls ym ((void*)0, decode (encStr))
indirectCall(…)indirectCall(…)
……
经过上述操作后,目标程序中对系统函数的调用被隐藏,使得攻击者无法通过反向分析找出目标程序中的系统函数。After the above operations, the calls to the system functions in the target program are hidden, making it impossible for attackers to find the system functions in the target program through reverse analysis.
在上述的实施例中,作为一种优选实现方式,在将系统函数的直接调用指令替换为对系统函数的间接调用指令的同时,还执行了加密系统函数名的操作。这样做可以进一步加深系统函数的混淆程度。在其他实施例中,也可根据实际需要省去加密系统函数名的操作。In the above embodiment, as a preferred implementation, while replacing the direct call instruction of the system function with the indirect call instruction of the system function, the operation of encrypting the system function name is also performed. This can further deepen the obfuscation degree of the system function. In other embodiments, the operation of encrypting the system function name can also be omitted according to actual needs.
本发明实施例提供的代码混淆方法通过隐藏目标程序中对系统函数的调用,使得攻击者无法通过反向分析找出目标程序中的系统函数,可有效防止静态分析,并延迟对软件的复制或篡改。The code obfuscation method provided by the embodiment of the present invention hides the call to the system function in the target program, so that the attacker cannot find the system function in the target program through reverse analysis, which can effectively prevent static analysis and delay the copying or tampering of the software.
为了说明本发明实施例提供的代码混淆方法的技术效果,通过附图对目标程序在代码混淆前后的控制流图进行比较。In order to illustrate the technical effect of the code obfuscation method provided by the embodiment of the present invention, the control flow graphs of the target program before and after code obfuscation are compared through the accompanying drawings.
图3为一个函数未混淆前,用逆向工具IDA查看到的控制流图。根据该控制流图,攻击者可以清晰的看到程序的布局以及执行流程。使用本发明实施例提供的代码混淆方法后,通过IDA逆向工具查看该函数的控制流如图4所示,从图中可以看到程序代码块增多了,且存在很多互不相关的代码块,攻击者很难读懂代码且直接分析程序执行流程。FIG3 is a control flow graph of a function before it is obfuscated, viewed using the reverse tool IDA. According to the control flow graph, an attacker can clearly see the layout and execution flow of the program. After using the code obfuscation method provided by an embodiment of the present invention, the control flow of the function is viewed using the IDA reverse tool as shown in FIG4. From the figure, it can be seen that the program code blocks have increased, and there are many unrelated code blocks, making it difficult for an attacker to understand the code and directly analyze the program execution flow.
图5为本发明实施例提供的代码混淆装置的示意图,如图5所示,本发明实施例提供的代码混淆装置包括:FIG5 is a schematic diagram of a code obfuscation device provided by an embodiment of the present invention. As shown in FIG5 , the code obfuscation device provided by an embodiment of the present invention includes:
基本代码块确定模块501,用于根据目标程序中的函数的控制流走向,确定所述函数中的基本代码块;A basic code block determination module 501 is used to determine a basic code block in a function in a target program according to the control flow direction of the function;
子代码块生成模块502,用于对所述基本代码块进行分割,得到子代码块;A sub-code block generation module 502 is used to divide the basic code block into sub-code blocks;
指令转换模块503,用于将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址;其中,所述代码块包括子代码块,或包括子代码块以及未被分割的基本代码块。The instruction conversion module 503 is used to convert the target address of the non-conditional jump instruction in the code block into an address determined when the target program is running; wherein the code block includes a sub-code block, or includes a sub-code block and an undivided basic code block.
本发明实施例提供的代码混淆装置通过将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址,从而切断了具有非条件跳转指令的代码块与所要跳转的代码块之间的直接跳转关系,增加了反向分析的难度。The code obfuscation device provided by the embodiment of the present invention converts the target address of the unconditional jump instruction in the code block into an address determined when the target program is running, thereby cutting off the direct jump relationship between the code block with the unconditional jump instruction and the code block to be jumped, thereby increasing the difficulty of reverse analysis.
图6为本发明实施例提供的一种电子设备的实体结构示意图,如图6所示,该电子设备可以包括:处理器(processor)610、通信接口(Communications Interface)620、存储器(memory)630和通信总线640,其中,处理器610,通信接口620,存储器630通过通信总线640完成相互间的通信。处理器610可以调用存储器630中的逻辑指令,以执行如下方法:根据目标程序中的函数的控制流走向,确定所述函数中的基本代码块;对所述基本代码块进行分割,得到子代码块;将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址;其中,所述代码块包括子代码块,或包括子代码块以及未被分割的基本代码块。FIG6 is a schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention. As shown in FIG6 , the electronic device may include: a processor 610, a communication interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communication interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the following method: according to the control flow direction of the function in the target program, determine the basic code block in the function; divide the basic code block to obtain a sub-code block; convert the target address of the non-conditional jump instruction in the code block to the address determined when the target program is running; wherein the code block includes a sub-code block, or includes a sub-code block and an undivided basic code block.
需要说明的是,本实施例中的电子设备在具体实现时可以为服务器,也可以为PC机,还可以为其他设备,只要其结构中包括如图6所示的处理器610、通信接口620、存储器630和通信总线640,其中处理器610,通信接口620,存储器630通过通信总线640完成相互间的通信,且处理器610可以调用存储器630中的逻辑指令以执行上述方法即可。本实施例不对电子设备的具体实现形式进行限定。It should be noted that the electronic device in this embodiment can be a server, a PC, or other devices in specific implementation, as long as its structure includes the processor 610, the communication interface 620, the memory 630, and the communication bus 640 shown in FIG6, wherein the processor 610, the communication interface 620, and the memory 630 communicate with each other through the communication bus 640, and the processor 610 can call the logic instructions in the memory 630 to execute the above method. This embodiment does not limit the specific implementation form of the electronic device.
此外,上述的存储器630中的逻辑指令可以通过软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
进一步地,本发明实施例公开一种计算机程序产品,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,计算机能够执行上述各方法实施例所提供的方法,例如包括:根据目标程序中的函数的控制流走向,确定所述函数中的基本代码块;对所述基本代码块进行分割,得到子代码块;将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址;其中,所述代码块包括子代码块,或包括子代码块以及未被分割的基本代码块。Furthermore, an embodiment of the present invention discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments, for example, including: determining a basic code block in the function according to the control flow direction of the function in the target program; dividing the basic code block to obtain sub-code blocks; converting the target address of the non-conditional jump instruction in the code block to an address determined when the target program is running; wherein the code block includes sub-code blocks, or includes sub-code blocks and undivided basic code blocks.
另一方面,本发明实施例还提供一种非暂态计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现以执行上述各实施例提供的方法,例如包括:根据目标程序中的函数的控制流走向,确定所述函数中的基本代码块;对所述基本代码块进行分割,得到子代码块;将代码块中的非条件跳转指令的目标地址转换为在所述目标程序运行时确定的地址;其中,所述代码块包括子代码块,或包括子代码块以及未被分割的基本代码块。On the other hand, an embodiment of the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it is implemented to execute the methods provided in the above embodiments, for example, including: determining a basic code block in the function according to the control flow direction of the function in the target program; dividing the basic code block to obtain sub-code blocks; converting the target address of the non-conditional jump instruction in the code block to an address determined when the target program is running; wherein the code block includes sub-code blocks, or includes sub-code blocks and undivided basic code blocks.
以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative work.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM/RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims (11)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010819524.9A CN112115427B (en) | 2020-08-14 | 2020-08-14 | Code confusion method, device, electronic equipment and storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010819524.9A CN112115427B (en) | 2020-08-14 | 2020-08-14 | Code confusion method, device, electronic equipment and storage medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN112115427A CN112115427A (en) | 2020-12-22 |
| CN112115427B true CN112115427B (en) | 2024-05-31 |
Family
ID=73804123
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202010819524.9A Active CN112115427B (en) | 2020-08-14 | 2020-08-14 | Code confusion method, device, electronic equipment and storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN112115427B (en) |
Families Citing this family (8)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114675878B (en) * | 2020-12-25 | 2024-08-20 | 奇安信安全技术(珠海)有限公司 | Jump instruction data acquisition method and device, electronic equipment and storage medium |
| CN113836545B (en) * | 2021-08-20 | 2024-07-16 | 咪咕音乐有限公司 | Code encryption method, device, equipment and storage medium |
| CN113569269B (en) | 2021-09-23 | 2022-12-27 | 苏州浪潮智能科技有限公司 | Encryption method, device, equipment and readable medium for code obfuscation |
| CN114090119B (en) * | 2021-11-16 | 2024-10-18 | 交控科技股份有限公司 | Control flow verification method, device, equipment and storage medium |
| CN114662063B (en) * | 2022-04-22 | 2024-06-25 | 苏州浪潮智能科技有限公司 | A method, device and medium for obfuscating codes |
| CN114969679A (en) * | 2022-05-11 | 2022-08-30 | 上海蒜芽信息科技有限公司 | Web front-end security reinforcement method, electronic device and medium |
| CN116956245A (en) * | 2023-09-19 | 2023-10-27 | 安徽大学 | Software watermark realization method and system based on control flow flattening confusion |
| CN117313047B (en) * | 2023-11-28 | 2024-03-15 | 深圳润世华软件和信息技术服务有限公司 | Source code confusion method, confusion reversal method, corresponding device and storage medium |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103547993A (en) * | 2011-03-25 | 2014-01-29 | 索夫特机械公司 | Executing instruction sequence code blocks by using virtual cores instantiated by partitionable engines |
| CN108537012A (en) * | 2018-02-12 | 2018-09-14 | 北京梆梆安全科技有限公司 | Source code based on variable and code execution sequence obscures method and device |
| CN110688120A (en) * | 2018-07-06 | 2020-01-14 | 武汉斗鱼网络科技有限公司 | Method for jumping to designated module and electronic equipment |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US8918768B2 (en) * | 2012-12-06 | 2014-12-23 | Apple Inc. | Methods and apparatus for correlation protected processing of data operations |
-
2020
- 2020-08-14 CN CN202010819524.9A patent/CN112115427B/en active Active
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103547993A (en) * | 2011-03-25 | 2014-01-29 | 索夫特机械公司 | Executing instruction sequence code blocks by using virtual cores instantiated by partitionable engines |
| CN108537012A (en) * | 2018-02-12 | 2018-09-14 | 北京梆梆安全科技有限公司 | Source code based on variable and code execution sequence obscures method and device |
| CN110688120A (en) * | 2018-07-06 | 2020-01-14 | 武汉斗鱼网络科技有限公司 | Method for jumping to designated module and electronic equipment |
Non-Patent Citations (1)
| Title |
|---|
| 代码克隆检测研究进展;陈秋远;李善平;鄢萌;夏鑫;;软件学报(第04期);全文 * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN112115427A (en) | 2020-12-22 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN112115427B (en) | Code confusion method, device, electronic equipment and storage medium | |
| JP6257754B2 (en) | Data protection | |
| JP5458184B2 (en) | System and method for aggressive automatic correction in a dynamic function call system | |
| CN106462677B (en) | Method and device for protecting software project | |
| CN104680039B (en) | A kind of data guard method and device of application program installation kit | |
| CN107341374B (en) | Insertion method and device of opaque predicates | |
| EP3729306B1 (en) | Compiling device and method | |
| KR102352066B1 (en) | Method of protecting secret data when used in a cryptographic algorithm | |
| CN104102860A (en) | Protecting method and running method and device and system for Android platform application program | |
| Yang et al. | Srcmarker: Dual-channel source code watermarking via scalable code transformations | |
| EP2937803B1 (en) | Control flow flattening for code obfuscation where the next block calculation needs run-time information | |
| US8775826B2 (en) | Counteracting memory tracing on computing systems by code obfuscation | |
| CN113366474B (en) | System, method and storage medium for obfuscating a computer program by representing a control flow of the computer program as data | |
| CN117009931A (en) | Watermarking and watermarking application methods, devices, equipment and storage medium | |
| JP2003337629A (en) | Program obfuscation method and device | |
| Kang et al. | Obfus: An obfuscation tool for software copyright and vulnerability protection | |
| Yang et al. | Towards code watermarking with dual-channel transformations | |
| CN111651781B (en) | Log content protection method, device, computer equipment and storage medium | |
| Gautam et al. | A novel software protection approach for code obfuscation to enhance software security | |
| WO2020261430A1 (en) | Information processing device, information processing method, and information processing program | |
| Zhang et al. | Analysis on technique for code obfuscation | |
| WO2022238851A1 (en) | Neural network configuration method and binary file processing method | |
| EP2947590A1 (en) | Program code obfuscation based upon recently executed program code | |
| CN114417266B (en) | Sensitive code protection method, device, computer equipment and storage medium | |
| CN116628697B (en) | Code protection methods, devices, electronic equipment and storage media |
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 | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |