使用encryptedString替換GlobalVariable
但類型不匹配。llvm pass replaceAllUsesWith類型不匹配
GlobalVariable
a const char *
字符串。 代碼這樣的:
GlobalVariable* GV = *it;
//get clear text string
std::string clearstr = getGlobalStringValue(GV);
GlobalVariable::LinkageTypes lt = GV->getLinkage();
//encrypt current string
std::string encryptedString = stringEncryption(clearstr);
//create new global string with the encrypted string
std::ostringstream oss;
oss << ".encstr" << encryptedStringCounter << "_" << sys::Process::GetRandomNumber();
Constant *cryptedStr = ConstantDataArray::getString(M.getContext(), encryptedString, true);
GlobalVariable* gCryptedStr = new GlobalVariable(M, cryptedStr->getType(), true, GV->getLinkage(), cryptedStr, oss.str());
StringMapGlobalVars[oss.str()] = gCryptedStr;
//replace use of clear string with encrypted string
GV->replaceAllUsesWith(gCryptedStr);
但失敗:
斷言失敗:(新建 - >的getType()==的getType() 值與不同類型的新值的& &「replaceAllUses !「),
如果替換類型[7×6-18],和 「getelementptr界外球([12×6-18] * @名爲.str,I32 0,I64 9)」 將變爲「getelementptr inbounds([7 x i8] * @ .str,i32 0,i64 9)」? – AloneMonkey 2015-02-12 08:48:55
是的,如果你看看Value類的'replaceAllUsesWith'函數,你會看到'ReplaceUnsafe'函數基本上是一樣的。 'replaceAllUsesWith'函數後面沒有語義檢查。你所擁有的只是檢查(一些)可以在IR中完成的錯誤的驗證通行證,並且我認爲它會告訴你GEP指令有問題,但我不確定。 – 2015-02-12 09:17:57
謝謝你的回答! – AloneMonkey 2015-02-13 01:32:32