Skip to content

Commit

Permalink
修复全局变量间接应用的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
KomiMoe committed May 26, 2022
1 parent fd871c0 commit 31c84f4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions llvm/lib/Transforms/Obfuscation/IndirectGlobalVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ struct IndirectGlobalVariable : public FunctionPass {
Instruction *Inst = &*I;
if (isa<LandingPadInst>(Inst) || isa<CleanupPadInst>(Inst) ||
isa<CatchPadInst>(Inst) || isa<CatchReturnInst>(Inst) ||
isa<CatchSwitchInst>(Inst)) {
isa<CatchSwitchInst>(Inst) || isa<ResumeInst>(Inst) ||
isa<CallInst>(Inst)) {
continue;
}
if (PHINode *PHI = dyn_cast<PHINode>(Inst)) {
Expand All @@ -116,7 +117,7 @@ struct IndirectGlobalVariable : public FunctionPass {

Value *Idx = ConstantInt::get(Type::getInt32Ty(Ctx), GVNumbering[GV]);
Value *GEP = IRB.CreateGEP(
GVars->getType()->getScalarType()->getPointerElementType(),
GVars->getType()->getPointerElementType(),
GVars,
{Zero, Idx});
LoadInst *EncGVAddr = IRB.CreateLoad(
Expand All @@ -126,12 +127,12 @@ struct IndirectGlobalVariable : public FunctionPass {

Value *Secret = IRB.CreateSub(X, MySecret);
Value *GVAddr = IRB.CreateGEP(
EncGVAddr->getType()->getScalarType()->getPointerElementType(),
EncGVAddr->getType()->getPointerElementType(),
EncGVAddr,
Secret);
GVAddr = IRB.CreateBitCast(GVAddr, GV->getType());
GVAddr->setName("IndGV");
Inst->replaceUsesOfWith(GV, GVAddr);
GVAddr->setName("IndGV0_");
PHI->setIncomingValue(i, GVAddr);
}
}
} else {
Expand All @@ -144,7 +145,7 @@ struct IndirectGlobalVariable : public FunctionPass {
IRBuilder<> IRB(Inst);
Value *Idx = ConstantInt::get(Type::getInt32Ty(Ctx), GVNumbering[GV]);
Value *GEP = IRB.CreateGEP(
GVars->getType()->getScalarType()->getPointerElementType(),
GVars->getType()->getPointerElementType(),
GVars,
{Zero, Idx});
LoadInst *EncGVAddr = IRB.CreateLoad(
Expand All @@ -155,11 +156,11 @@ struct IndirectGlobalVariable : public FunctionPass {

Value *Secret = IRB.CreateSub(X, MySecret);
Value *GVAddr = IRB.CreateGEP(
EncGVAddr->getType()->getScalarType()->getPointerElementType(),
EncGVAddr->getType()->getPointerElementType(),
EncGVAddr,
Secret);
GVAddr = IRB.CreateBitCast(GVAddr, GV->getType());
GVAddr->setName("IndGV");
GVAddr->setName("IndGV1_");
Inst->replaceUsesOfWith(GV, GVAddr);
}
}
Expand Down

0 comments on commit 31c84f4

Please sign in to comment.