我目前正在使用OPAL框架开发Java代码的静态分析。我想分析以下Java方法:
private void indirectCaller2b(double d, Object o1, Object o2) {
indirectCaller1(d, o1, o2);
}我知道,indirectCaller2b只使用参数(double,ArrayList,LinkedList)调用。
考虑到这一点,我构建了一个IndexedSeq of DomainValues,并将其传递给执行方法ob BaseAI。看起来是这样的:
Vector({ai.native_methods_parameter_type_approximation.PublicClass,null}@0;t=101,ADoubleValue,{_ <:java.util.ArrayList,null}@-4;t=102,{_ <:java.util.LinkedList,null}@-5;t=103)
此参数({ai.native_methods_parameter_type_approximation.PublicClass,null}@0;t=101)是用以下代码创建的:
domain.TypedValue(0, project.classFile(caller).thisType)其他域值是使用parameterToValueIndex方法创建的:
org.opalj.ai.parameterToValueIndex(caller.isStatic, caller.descriptor, index), t)在这里,调用者代表方法indirectCaller2b,t是参数的已知运行时类型(参数索引1的ArrayList和参数索引2的LinkedList )。
执行方法的抽象解释时,
BaseAI.perform(classFile, caller, domain)(Some(parameters))并在程序计数器上打印堆栈索引,其中调用indirectCaller1的代码如下,
for (i <- 0 to analysisResult.operandsArray(pc).size - 1) {
println(s"stack index $i: ${analysisResult.operandsArray(pc)(i)}")
}我得到以下输出:
堆栈索引0: null
堆栈索引1:{_ <:java.util.LinkedList,null}@-5;t=103个
堆栈索引2: ADoubleValue
堆栈索引3:{ai.native_methods_parameter_type_approximation.PublicClass,null}@0;t=101
这有点让人困惑,因为我只是将indirectCaller2b的参数传递给indirectCaller1。因此,输出应该与传递给IndexedSeq方法的输出相同。
但是在输出中,双参数后面的参数是LinkedList而不是ArrayList。ArrayList参数不知何故消失了,而operandStack上的最后一个参数是"null“。
有人能解释一下为什么会发生这种事吗?
发布于 2016-06-19 13:39:41
“本”的表述
要获得"this“引用的正确表示形式,应使用以下方法
InitializedObjectValue(
origin: ValueOrigin,
objectType: ObjectType ): DomainReferenceValue若要创建此值的表示形式,请执行以下操作。不同之处在于,在这种情况下,AI将尝试使用以下信息:(a)值保证为非空值,并保证值被初始化。特别是,前一个属性通常是有趣的,通常会导致更精确的结果。
初始化局部变量
函数:org.opalj.ai.parameterToValueIndex只计算逻辑原点信息(与该值相关联的"pc“,以便以后能够将相应的值识别为参数)。
要正确地将操作数映射到局部变量,可以使用mapOperandsToParameters方法,或者只需将所有值添加到IndexedSeq,而是为计算类型类别2的值添加另一个null值。
https://stackoverflow.com/questions/37896414
复制相似问题