Skip to content

Commit 982a50e

Browse files
yag00christophe.duvernois
authored andcommitted
struct { char* x = "str"; } encryption is not supported
1 parent 7c5444f commit 982a50e

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

lib/Transforms/Obfuscation/AbstractStringEncryptionPass.cpp

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,45 @@ void AbstractStringEncryptionPass::checkStringsCanBeEncrypted(Module &M, std::ve
108108
if(array){
109109
for(unsigned int i = 0; i < array->getNumOperands(); i++){
110110
ConstantExpr* ce = dyn_cast<ConstantExpr>(array->getOperand(i));
111-
if(ce == 0)
112-
continue;
113-
114-
GetElementPtrInst *gepElementFromArray = dyn_cast<GetElementPtrInst>(ce->getAsInstruction());
115-
if(gepElementFromArray == 0)
116-
continue;
111+
if(ce == 0){
112+
ConstantStruct* cs = dyn_cast<ConstantStruct>(array->getOperand(i));
113+
if(cs == 0)
114+
continue;
115+
116+
for(unsigned int j = 0; j < cs->getNumOperands(); j++){
117+
ConstantExpr* structelement = dyn_cast<ConstantExpr>(cs->getOperand(j));
118+
if(structelement == 0)
119+
continue;
120+
GetElementPtrInst *gepElementFromStruct = dyn_cast<GetElementPtrInst>(structelement->getAsInstruction());
121+
if(gepElementFromStruct == 0)
122+
continue;
123+
124+
if(GlobalVariable* gv = dyn_cast<GlobalVariable>(gepElementFromStruct->getPointerOperand())){
125+
if(dyn_cast<ConstantDataSequential>(gv->getInitializer())){
126+
std::vector<GlobalVariable*>::iterator it = std::find(StringGlobalVars.begin(), StringGlobalVars.end(), gv);
127+
if(it != StringGlobalVars.end()){
128+
errs() << "WARNING : " << getGlobalStringValue(gv) << " won't be ecnrypted (struct { char* x = \"str\"; } encryption is not supported!) - conversion from string literal to 'char *' is deprecated!\n";
129+
StringGlobalVars.erase(it);
130+
}
131+
}
132+
}
133+
}
134+
}else{
135+
GetElementPtrInst *gepElementFromArray = dyn_cast<GetElementPtrInst>(ce->getAsInstruction());
136+
if(gepElementFromArray == 0)
137+
continue;
117138

118-
if(GlobalVariable* gv = dyn_cast<GlobalVariable>(gepElementFromArray->getPointerOperand())){
119-
if(dyn_cast<ConstantDataSequential>(gv->getInitializer())){
120-
std::vector<GlobalVariable*>::iterator it = std::find(StringGlobalVars.begin(), StringGlobalVars.end(), gv);
121-
if(it != StringGlobalVars.end()){
122-
errs() << "WARNING : " << getGlobalStringValue(gv) << " won't be ecnrypted (char** encryption is not supported!)!\n";
123-
StringGlobalVars.erase(it);
139+
if(GlobalVariable* gv = dyn_cast<GlobalVariable>(gepElementFromArray->getPointerOperand())){
140+
if(dyn_cast<ConstantDataSequential>(gv->getInitializer())){
141+
std::vector<GlobalVariable*>::iterator it = std::find(StringGlobalVars.begin(), StringGlobalVars.end(), gv);
142+
if(it != StringGlobalVars.end()){
143+
errs() << "WARNING : " << getGlobalStringValue(gv) << " won't be ecnrypted (char** encryption is not supported!)!\n";
144+
StringGlobalVars.erase(it);
145+
}
124146
}
125147
}
126148
}
127149
}
128-
continue;
129150
}
130151
}
131152

0 commit comments

Comments
 (0)