提问者:小点点

查找局部变量的所有用途(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;
      }
  }
}

共1个答案

匿名用户

如果您从HighSymbol开始,您首先通过访问HighSymbol. hyVariable来获取HighVariable

然后,您可以通过访问VarnodeAST类型的HighVariable实例来获取使用该变量的所有PCodeOP,然后获取它们的def(定义)和后代

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

相关问题