obfuscator-llvm / obfuscator

3.93k stars 1.18k forks source link

BogusControlFlow bug #165

Open bluesadi opened 3 years ago

bluesadi commented 3 years ago

In obfuscator/lib/Transforms/Obfuscation/BogusControlFlow.cpp:

// Split the block: first part with only the phi nodes and debug info and terminator
//                  created by splitBasicBlock. (-> No instruction)
//                  Second part with every instructions from the original block
// We do this way, so we don't have to adjust all the phi nodes, metadatas and so on
// for the first block. We have to let the phi nodes in the first part, because they
// actually are updated in the second part according to them.
BasicBlock::iterator i1 = basicBlock->begin();
if(basicBlock->getFirstNonPHIOrDbgOrLifetime())
 i1 = (BasicBlock::iterator)basicBlock->getFirstNonPHIOrDbgOrLifetime();

It really confuse me. As far as I know, there is no constraint that a basic block can only have one phi node. So we still have to adjust the phi nodes in the second part, or can we let all the phi nodes in the first part?

v4kst1z commented 3 years ago

In obfuscator/lib/Transforms/Obfuscation/BogusControlFlow.cpp:

// Split the block: first part with only the phi nodes and debug info and terminator
//                  created by splitBasicBlock. (-> No instruction)
//                  Second part with every instructions from the original block
// We do this way, so we don't have to adjust all the phi nodes, metadatas and so on
// for the first block. We have to let the phi nodes in the first part, because they
// actually are updated in the second part according to them.
BasicBlock::iterator i1 = basicBlock->begin();
if(basicBlock->getFirstNonPHIOrDbgOrLifetime())
 i1 = (BasicBlock::iterator)basicBlock->getFirstNonPHIOrDbgOrLifetime();

It really confuse me. As far as I know, there is no constraint that a basic block can only have one phi node. So we still have to adjust the phi nodes in the second part, or can we let all the phi nodes in the first part?

getFirstNonPHIOrDbgOrLifetime 函数得到的就是第一个不属于 Phi、Dbg 和 Lifetime 的指令,所有所有 phi 节点都在第一部分