Java 跨不同方法调用跟踪同一对象

Java 跨不同方法调用跟踪同一对象,java,jvm,bytecode,bytecode-manipulation,bcel,Java,Jvm,Bytecode,Bytecode Manipulation,Bcel,我最近开始使用BCEL库来实现我自己的FindBugs插件。我有一个Intent对象(它是一个Android静态分析插件)。我想检查我的方法中是否声明了一个Intent对象,它的ACTION设置为“android.media.ACTION.VIDEO\u CAPTURE”。如果满足此条件,我还想检查这是否是作为参数传递给startActivityForResult的同一个intent对象。现在,我只是检查在我的方法中,是否有一个意图是让setAction本身被调用,以及该方法是否在以后调用sta

我最近开始使用BCEL库来实现我自己的FindBugs插件。我有一个Intent对象(它是一个Android静态分析插件)。我想检查我的方法中是否声明了一个Intent对象,它的ACTION设置为“android.media.ACTION.VIDEO\u CAPTURE”。如果满足此条件,我还想检查这是否是作为参数传递给startActivityForResult的同一个intent对象。现在,我只是检查在我的方法中,是否有一个意图是让setAction本身被调用,以及该方法是否在以后调用startActivityForResult

Android代码示例:

protected void onCreate(Bundle savedInstanceState) {
        android.content.Intent intent = new android.content.Intent();
        intent.setAction("android.media.action.VIDEO_CAPTURE");
        Uri uri = Uri.fromFile(file);
        intent.putExtra("output", uri);
        startActivityForResult(intent, 105);
        }
    }
插件代码:

private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException {
        boolean isStartActivityForResult = false;
        boolean isIntentWithPickUri = false;
        
        MethodGen methodGen = classContext.getMethodGen(m);
        ConstantPoolGen cpg = classContext.getConstantPoolGen();
        CFG cfg = classContext.getCFG(m);

        if (methodGen == null || methodGen.getInstructionList() == null) {
            return;
        }

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
            Location location = i.next();
            Instruction inst = location.getHandle().getInstruction();
            
            if (inst instanceof INVOKEVIRTUAL) {
                InvokeInstruction invoke = (InvokeInstruction) inst;
                if ("setAction".equals(invoke.getMethodName(cpg))) {
                    LDC loadConst = ByteCode.getPrevInstruction(location.getHandle(), LDC.class);
                    if (loadConst != null) {
                        if ("android.media.action.VIDEO_CAPTURE".equals(loadConst.getValue(cpg)) || "android.media.action.IMAGE_CAPTURE".equals(loadConst.getValue(cpg))
                            || "android.media.action.STILL_IMAGE_CAMERA".equals(loadConst.getValue(cpg)) || "android.media.action.VIDEO_CAMERA".equals(loadConst.getValue(cpg))){
                            isIntentWithPickUri = true;
                        }
                    }
                }
            } else if (inst instanceof INVOKEVIRTUAL) {
                InvokeInstruction invoke = (InvokeInstruction) inst;
                if ("startActivityForResult".equals(invoke.getMethodName(cpg))) {
                    isStartActivityForResult = true;
                }
            }
        }
        if (isStartActivityForResult && isIntentWithPickUri) {
            bugReporter.reportBug(new BugInstance(this, INTERCEPT_FILE_INTENT, Priorities.NORMAL_PRIORITY) 
                    .addClass(classContext.getJavaClass()).addMethod(classContext.getJavaClass(), m));
        } else if ((isStartActivityForResult && !isIntentWithPickUri) || (!isStartActivityForResult && isIntentWithPickUri)) {
            bugReporter.reportBug(new BugInstance(this, INTERCEPT_FILE_INTENT, Priorities.LOW_PRIORITY) 
                    .addClass(classContext.getJavaClass()).addMethod(classContext.getJavaClass(), m));
        }
    }
private void analyzeMethod(方法m,ClassContext ClassContext)抛出CFGBuilderException、DataflowAnalysisException{
布尔值isStartActivityForResult=false;
布尔值isIntentWithPickUri=false;
MethodGen MethodGen=classContext.getMethodGen(m);
ConstantPoolGen cpg=classContext.getConstantPoolGen();
CFG CFG=classContext.getCFG(m);
if(methodGen==null | | methodGen.getInstructionList()==null){
返回;
}
for(迭代器i=cfg.locationIterator();i.hasNext();){
位置=i.next();
指令inst=location.getHandle().getInstruction();
if(inst instanceof INVOKEVIRTUAL){
InvokeInstruction invoke=(InvokeInstruction)inst;
if(“setAction”.equals(invoke.getMethodName(cpg))){
LDC loadConst=ByteCode.getPrevInstruction(location.getHandle(),LDC.class);
如果(loadConst!=null){
if(“android.media.action.VIDEO_CAPTURE.”等于(loadConst.getValue(cpg))| |“android.media.action.IMAGE_CAPTURE.”等于(loadConst.getValue(cpg))
||“android.media.action.STILL_IMAGE_CAMERA”.equals(loadConst.getValue(cpg))| |“android.media.action.VIDEO_CAMERA”.equals(loadConst.getValue(cpg))){
isIntentWithPickUri=true;
}
}
}
}else if(inst instanceof INVOKEVIRTUAL){
InvokeInstruction invoke=(InvokeInstruction)inst;
if(“startActivityForResult.equals(invoke.getMethodName(cpg))){
isStartActivityForResult=true;
}
}
}
if(isStartActivityForResult&&isIntentWithPickUri){
bugReporter.reportBug(新的BugInstance(这个,拦截文件,优先级,正常优先级)
.addClass(classContext.getJavaClass()).addMethod(classContext.getJavaClass(),m));
}else if((isStartActivityForResult&!isIntentWithPickUri)| |(!isStartActivityForResult&&isIntentWithPickUri)){
bugReporter.reportBug(新的BugInstance(这个,拦截文件的意图,优先级,低优先级)
.addClass(classContext.getJavaClass()).addMethod(classContext.getJavaClass(),m));
}
}
如您所见,我无法判断将其操作设置为给定操作的相同意图是否正在发送到startActivityForResult。如果不向startActivityForResult传递任何操作,这很可能是一个不同的意图

我想我可能可以使用该方法的局部变量表来实现这一点,但我不知道如何实现

谢谢