java get method name,Java MethodGen.getName方法代码示例

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类

private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {

MethodGen methodGen = classContext.getMethodGen(method);

if (methodGen == null)

return;

BitSet bytecodeSet = classContext.getBytecodeSet(method);

if (bytecodeSet == null)

return;

// We don't adequately model instanceof interfaces yet

if (bytecodeSet.get(Constants.INSTANCEOF) || bytecodeSet.get(Constants.CHECKCAST))

return;

CFG cfg = classContext.getCFG(method);

TypeDataflow typeDataflow = classContext.getTypeDataflow(method);

ConstantPoolGen cpg = classContext.getConstantPoolGen();

String sourceFile = classContext.getJavaClass().getSourceFileName();

if (DEBUG) {

String methodName = methodGen.getClassName() + "." + methodGen.getName();

System.out.println("Checking " + methodName);

}

for (Iterator i = cfg.locationIterator(); i.hasNext();) {

Location location = i.next();

InstructionHandle handle = location.getHandle();

Instruction ins = handle.getInstruction();

if (!(ins instanceof INVOKEINTERFACE))

continue;

INVOKEINTERFACE invoke = (INVOKEINTERFACE) ins;

String mName = invoke.getMethodName(cpg);

if (!mName.equals("setAttribute"))

continue;

String cName = invoke.getClassName(cpg);

if (!cName.equals("javax.servlet.http.HttpSession"))

continue;

TypeFrame frame = typeDataflow.getFactAtLocation(location);

if (!frame.isValid()) {

// This basic block is probably dead

continue;

}

Type operandType = frame.getTopValue();

if (operandType.equals(TopType.instance())) {

// unreachable

continue;

}

if (!(operandType instanceof ReferenceType)) {

// Shouldn't happen - illegal bytecode

continue;

}

ReferenceType refType = (ReferenceType) operandType;

if (refType.equals(NullType.instance())) {

continue;

}

try {

double isSerializable = DeepSubtypeAnalysis.isDeepSerializable(refType);

if (isSerializable < 0.9) {

SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext,

methodGen, sourceFile, handle);

ReferenceType problem = DeepSubtypeAnalysis.getLeastSerializableTypeComponent(refType);

bugAccumulator.accumulateBug(new BugInstance(this, "J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION",

isSerializable < 0.15 ? HIGH_PRIORITY : isSerializable > 0.5 ? LOW_PRIORITY : NORMAL_PRIORITY)

.addClassAndMethod(methodGen, sourceFile).addType(problem).describe(TypeAnnotation.FOUND_ROLE),

sourceLineAnnotation);

}

} catch (ClassNotFoundException e) {

// ignore

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值