想写个简单的pass看看,发现好蛋疼,想对程序中的字符串加密,然后有了下文:
"Hello,world" 该字符串是要替换成加密字符串的原字符串。
好吧,我首先转成ConstantDataSequential,然后调用getAsString()函数得到该字符串,但是得到的长度是12.(不应该是11?)然后我进行xor处理,再使用replaceAllUsesWith函数全局替换。
出现第一个问题:type不匹配,后来我发现是长度的问题,不是12,改成11就好了(那为什么getAsString()得到的长度是12?)。
然后我替换后,出现第二个问题:
While deleting: [13 x i8]* %.encstr0_3064045518
Use still stuck around after Def is destroyed:@.encstr0_3064045518 = private constant [13 x i8] <null operand!>
Assertion failed: (use_empty() && "Uses remain when a value is destroyed!"), function ~Value,
encstr0_3064045518这个是我替换后的加密字符串变量名,为何会莫名的被删除?后面有引用肯定是不能删除的。
部分代码如下:
GlobalVariable* GV = *it;
//get clear text string
std::string clearstr = getGlobalStringValue(GV);//通过getAsString获取的
GlobalVariable::LinkageTypes lt = GV->getLinkage();
//encrypt current string
std::string encryptedString = stringEncryption(clearstr); //简单xor不改变长度
//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);
GV->eraseFromParent();
感觉里面的各种类不知道指的哪个结构
有弄过的大牛快来指点下下
[课程]FART 脱壳王!加量不加价!FART作者讲授!