⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classcontext.java

📁 A static analysis tool to find bugs in Java programs
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		switch(0xff & codeBytes[pos]) {		case Constants.IF_ACMPEQ:		case Constants.IF_ACMPNE:		case Constants.IF_ICMPEQ:		case Constants.IF_ICMPGE:		case Constants.IF_ICMPGT:		case Constants.IF_ICMPLE:		case Constants.IF_ICMPLT:		case Constants.IF_ICMPNE:			break;			default: 				return false;		}		int branchTarget = pos+getBranchOffset(codeBytes, pos+1);		if (branchTarget-3 < pos || branchTarget >= codeBytes.length) return false;		if ((codeBytes[branchTarget-3] & 0xff) != Constants.GOTO) return false;		int backBranchTarget = branchTarget + getBranchOffset(codeBytes, branchTarget-2);		if (backBranchTarget <= pos && backBranchTarget + 12 >= pos) return true;		return false;	}	/**	 * Get array mapping bytecode offsets to opcodes for given method.	 * Array elements containing zero are either not valid instruction offsets,	 * or contain a NOP instruction.  (It is convenient not to distinguish	 * these cases.)	 * 	 * @param method the method	 * @return map of bytecode offsets to opcodes, or null if the method has no code	 */	public short[] getOffsetToOpcodeMap(Method method) {		UnpackedCode unpackedCode = unpackedCodeFactory.getAnalysis(method);		return unpackedCode != null ? unpackedCode.getOffsetToBytecodeMap() : null;	}	/**	 * Get dataflow for LockAnalysis for given method.	 *	 * @param method the method	 * @return the LockDataflow	 */	public LockDataflow getLockDataflow(Method method)			throws CFGBuilderException, DataflowAnalysisException {		return lockDataflowFactory.getAnalysis(method);	}	/**	 * Get LockChecker for method.	 * This is like LockDataflow, but may be able to avoid performing	 * the actual dataflow analyses if the method doesn't contain	 * explicit monitorenter/monitorexit instructions.	 * 	 * @param method the method	 * @return the LockChecker	 * @throws CFGBuilderException	 * @throws DataflowAnalysisException	 */	public LockChecker getLockChecker(Method method) throws CFGBuilderException, DataflowAnalysisException {		return lockCheckerFactory.getAnalysis(method);	}	/**	 * Get ReturnPathDataflow for method.	 *	 * @param method the method	 * @return the ReturnPathDataflow	 */	public ReturnPathDataflow getReturnPathDataflow(Method method)			throws CFGBuilderException, DataflowAnalysisException {		return returnPathDataflowFactory.getAnalysis(method);	}	/**	 * Get DominatorsAnalysis for given method,	 * where exception edges are ignored.	 *	 * @param method the method	 * @return the DominatorsAnalysis	 */	public DominatorsAnalysis getNonExceptionDominatorsAnalysis(Method method)			throws CFGBuilderException, DataflowAnalysisException {		return nonExceptionDominatorsAnalysisFactory.getAnalysis(method);	}	/**	 * Get DominatorsAnalysis for given method,	 * where implicit exception edges are ignored.	 *	 * @param method the method	 * @return the DominatorsAnalysis	 */	public PostDominatorsAnalysis getNonImplicitExceptionDominatorsAnalysis(Method method)			throws CFGBuilderException, DataflowAnalysisException {		return nonImplicitExceptionPostDominatorsAnalysisFactory.getAnalysis(method);	}	/**	 * Get PostDominatorsAnalysis for given method,	 * where exception edges are ignored.	 *	 * @param method the method	 * @return the PostDominatorsAnalysis	 */	public PostDominatorsAnalysis getNonExceptionPostDominatorsAnalysis(Method method)			throws CFGBuilderException, DataflowAnalysisException {		return nonExceptionPostDominatorsAnalysisFactory.getAnalysis(method);	}	/**	 * Get ExceptionSetFactory for given method.	 *	 * @param method the method	 * @return the ExceptionSetFactory	 */	public ExceptionSetFactory getExceptionSetFactory(Method method) {		return exceptionSetFactoryFactory.getAnalysis(method);	}	/**	 * Get array of type signatures of parameters for given method.	 *	 * @param method the method	 * @return an array of type signatures indicating the types	 *         of the method's parameters	 */	public String[] getParameterSignatureList(Method method) {		return parameterSignatureListFactory.getAnalysis(method);	}	/**	 * Get the set of fields loaded by given method.	 *	 * @param method the method	 * @return the set of fields loaded by the method	 */	public LoadedFieldSet getLoadedFieldSet(Method method) {		return loadedFieldSetFactory.getAnalysis(method);	}	/**	 * Get LiveLocalStoreAnalysis dataflow for given method.	 *	 * @param method the method	 * @return the Dataflow object for LiveLocalStoreAnalysis on the method	 */	public LiveLocalStoreDataflow getLiveLocalStoreDataflow(Method method)			throws DataflowAnalysisException, CFGBuilderException {		return liveLocalStoreDataflowFactory.getAnalysis(method);	}	/**	 * Get BlockType dataflow for given method.	 *	 * @param method the method	 * @return the Dataflow object for BlockTypeAnalysis on the method	 */	public Dataflow<BlockType, BlockTypeAnalysis> getBlockTypeDataflow(Method method)			throws DataflowAnalysisException, CFGBuilderException {		return blockTypeDataflowFactory.getAnalysis(method);	}	/**	 * Get the assigned field map for the class.	 *	 * @return the AssignedFieldMap	 * @throws ClassNotFoundException if a class lookup prevents	 *                                the class's superclasses from being searched for	 *                                assignable fields	 */	public AssignedFieldMap getAssignedFieldMap() throws ClassNotFoundException {		if (assignedFieldMap == null) {			assignedFieldMap = new AssignedFieldMap(this);		}		return assignedFieldMap;	}	/**	 * Get AssertionMethods for class.	 *	 * @return the AssertionMethods	 */	public AssertionMethods getAssertionMethods() {		if (assertionMethods == null) {			assertionMethods = new AssertionMethods(jclass);		}		return assertionMethods;	}	/**	 * Get ConstantDataflow for method.	 * 	 * @param method the method	 * @return the ConstantDataflow	 * @throws CFGBuilderException	 * @throws DataflowAnalysisException	 */	public ConstantDataflow getConstantDataflow(Method method)			throws CFGBuilderException, DataflowAnalysisException {		return constantDataflowFactory.getAnalysis(method);	}	/**	 * Get load dataflow.	 * 	 * @param method the method	 * @return the LoadDataflow	 * @throws CFGBuilderException	 * @throws DataflowAnalysisException	 */	public LoadDataflow getLoadDataflow(Method method) throws CFGBuilderException, DataflowAnalysisException {		return loadDataflowFactory.getAnalysis(method);	}	/**	 * Get store dataflow.	 * 	 * @param method the method	 * @return the StoreDataflow	 * @throws CFGBuilderException	 * @throws DataflowAnalysisException	 */	public StoreDataflow getStoreDataflow(Method method) throws CFGBuilderException, DataflowAnalysisException {		return storeDataflowFactory.getAnalysis(method);	}	/**	 * Get CallListDataflow for method.	 * 	 * @param method the method	 * @return the CallListDataflow	 * @throws CFGBuilderException	 * @throws DataflowAnalysisException	 */	public CallListDataflow getCallListDataflow(Method method)			throws CFGBuilderException, DataflowAnalysisException {		return callListDataflowFactory.getAnalysis(method);	}	public static BitSet linesMentionedMultipleTimes(Method method) {		BitSet lineMentionedMultipleTimes = new BitSet();		Code code = method.getCode();		if (code == null || code.getExceptionTable() == null) return lineMentionedMultipleTimes;		BitSet foundOnce = new BitSet();		LineNumberTable lineNumberTable = method.getLineNumberTable();		int lineNum = -1;		if (lineNumberTable != null) 			for(LineNumber  line : lineNumberTable.getLineNumberTable()) {				int newLine = line.getLineNumber();				if (newLine == lineNum || newLine == -1) continue;				lineNum = newLine;				if (foundOnce.get(lineNum)  ) {					lineMentionedMultipleTimes.set(lineNum);				}				else  {					foundOnce.set(lineNum);					}			}		return lineMentionedMultipleTimes;	}	/**	 * Get the UnconditionalValueDerefDataflow for a method.	 * 	 * @param method the method	 * @return the UnconditionalValueDerefDataflow 	 * @throws CFGBuilderException	 * @throws DataflowAnalysisException	 */	public UnconditionalValueDerefDataflow getUnconditionalValueDerefDataflow(Method method)			throws CFGBuilderException, DataflowAnalysisException {		return 	unconditionalValueDerefDataflowFactory.getAnalysis(method);	}	/**	 * Get a CompactLocationNumbering for a method.	 * 	 * @param method a method	 * @return the CompactLocationNumbering for the method	 * @throws CFGBuilderException	 */	public CompactLocationNumbering getCompactLocationNumbering(Method method)			throws CFGBuilderException {		return compactLocationNumberingFactory.getAnalysis(method); 	}	/**	 * Get DefinitelyNullSetDataflow for a method.	 * 	 * @param method a method	 * @return the DefinitelyNullSetDataflow for the method 	 * @throws DataflowAnalysisException 	 * @throws CFGBuilderException 	 */	public DefinitelyNullSetDataflow getDefinitelyNullSetDataflow(Method method)			throws CFGBuilderException, DataflowAnalysisException {		return definitelyNullSetDataflowFactory.getAnalysis(method);	}	/**	 * Get ReturnPathTypeDataflow for a method.	 * 	 * @param method the method	 * @return the ReturnPathTypeDataflow for the method	 * @throws CFGBuilderException	 * @throws DataflowAnalysisException	 */	public ReturnPathTypeDataflow getReturnPathTypeDataflow(Method method)			throws CFGBuilderException, DataflowAnalysisException {		return returnPathTypeDataflowFactory.getAnalysis(method);	}	public  void dumpDataflowInformation(Method method) {		try {			dumpDataflowInformation(method, getCFG(method), getValueNumberDataflow(method), getIsNullValueDataflow(method), getUnconditionalValueDerefDataflow(method), getTypeDataflow(method));		} catch (DataflowAnalysisException e) {			AnalysisContext.logError("Could not dump data information for " + getJavaClass().getClassName() +"." + method.getName(), e);		} catch (CFGBuilderException e) {			AnalysisContext.logError("Could not dump data information for " + getJavaClass().getClassName() +"." + method.getName(), e);		}	}	/**	 * @param method	 * @param cfg	 * @param vnd	 * @param inv	 * @param dataflow	 * @param typeDataflow TODO	 * @throws DataflowAnalysisException	 */	public static void dumpDataflowInformation(Method method, CFG cfg, ValueNumberDataflow vnd, IsNullValueDataflow inv, UnconditionalValueDerefDataflow dataflow, TypeDataflow typeDataflow) throws DataflowAnalysisException {		System.out.println("\n\n{ UnconditionalValueDerefAnalysis analysis for " + method.getName());		TreeSet<Location> tree = new TreeSet<Location>();		for(Iterator<Location> locs = cfg.locationIterator(); locs.hasNext(); ) {			Location loc = locs.next();			tree.add(loc);		}		for(Location loc : tree) {			UnconditionalValueDerefSet factAfterLocation = dataflow.getFactAfterLocation(loc);			System.out.println("\n Pre: " + factAfterLocation);			System.out.println("Vna: " + vnd.getFactAtLocation(loc));			System.out.println("inv: " + inv.getFactAtLocation(loc));			if (typeDataflow != null) System.out.println("type: " + typeDataflow.getFactAtLocation(loc));			System.out.println("Location: " + loc);			System.out.println("Post: " + dataflow.getFactAtLocation(loc));			System.out.println("Vna: " + vnd.getFactAfterLocation(loc));			System.out.println("inv: " + inv.getFactAfterLocation(loc));			   if (typeDataflow != null)  System.out.println("type: " + typeDataflow.getFactAfterLocation(loc));		}		System.out.println("}\n\n");	}	/**	 * @param method	 * @param cfg	 * @param typeDataflow	 * @throws DataflowAnalysisException	 */	public static void dumpTypeDataflow(Method method, CFG cfg, TypeDataflow typeDataflow) throws DataflowAnalysisException {		System.out.println("\n\n{ Type analysis for " + cfg.getMethodGen().getClassName() + "." + method.getName());		TreeSet<Location> tree = new TreeSet<Location>();		for(Iterator<Location> locs = cfg.locationIterator(); locs.hasNext(); ) {			Location loc = locs.next();			tree.add(loc);		}		for(Location loc : tree) {			System.out.println("\n Pre: " + typeDataflow.getFactAtLocation(loc));			System.out.println("Location: " + loc);			System.out.println("Post: " + typeDataflow.getFactAfterLocation(loc));			}		S

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -