如何解决查找局部变量的所有用途ghidra 脚本
有没有办法在给定的局部变量的给定函数中获取所有 PcodeOps?到目前为止,我可以根据函数和名称找到 HighSymbol,但我想然后获取该变量的所有用途?
DecompileResults res = decomplib.decompileFunction(f,200,monitor);
if (res.decompileCompleted())
{
HighFunction highFunc = res.getHighFunction();
LocalSymbolMap localmap = highFunc.getLocalSymbolMap();
Iterator<HighSymbol> localSymbols = localmap.getSymbols();
HighSymbol localSymbol = null;
while (localSymbols.hasNext())
{
HighSymbol current = localSymbols.next();
if (current.getName().equals(theName)) {
localSymbol = current;
break;
}
}
}
解决方法
如果您从 HighSymbol
开始,您首先通过访问 HighVariable
获得 highSymbol.highVariable
。
然后您可以通过访问类型为 instances
的 HighVariable
的 VarnodeAST
获取使用该变量的所有 PCodeOP,然后获取它们的 def
(定义)和descendants
hvar = currentLocation.token.highVariable # get the high variable that is currently selected highlighted in the decompiler window
for varnode in hvar.instances:
print(varnode.def) # the PCodeOp that defines this instance of the variable
for dsc in varnode.descendants:
print(dsc) # every PCodeOp that uses this variable
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。