/** * Translates an object of this type to its unboxed representation. */ public void translateUnBox(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(new CHECKCAST(cpg.addClass(BOOLEAN_CLASS))); il.append(new INVOKEVIRTUAL(cpg.addMethodref(BOOLEAN_CLASS, BOOLEAN_VALUE, BOOLEAN_VALUE_SIG))); }
Location location = i.next(); Instruction inst = location.getHandle().getInstruction(); INVOKESTATIC invoke = (INVOKESTATIC) inst; if ("javax.crypto.KeyGenerator".equals(invoke.getClassName(cpg)) && "getInstance".equals(invoke.getMethodName(cpg))) { String value = ByteCode.getConstantLDC(location.getHandle().getPrev(), cpg, String.class); if ("Blowfish".equals(value)) { createBlowfishKeyGen = true; if ("javax.crypto.KeyGenerator".equals(invoke.getClassName(cpg)) && "init".equals(invoke.getMethodName(cpg))) { Number n = null; if ("(I)V".equals(invoke.getSignature(cpg))) { n = ByteCode.getPushNumber(location.getHandle().getPrev()); else if ("(ILjava/security/SecureRandom;)V".equals(invoke.getSignature(cpg))) {
private boolean isStringAppend(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL invoke = (INVOKEVIRTUAL) ins; if ("append".equals(invoke.getMethodName(cpg)) && invoke.getClassName(cpg).startsWith("java.lang.StringB")) { String sig = invoke.getSignature(cpg); char firstChar = sig.charAt(1); return firstChar == '[' || firstChar == 'L'; } } return false; }
@Override public void visitINVOKEVIRTUAL(INVOKEVIRTUAL obj) { if ("cast".equals(obj.getMethodName(cpg)) && "java.lang.Class".equals(obj.getClassName(cpg))) { // treat as no-op try { ValueNumberFrame frame = getFrame(); ValueNumber resultType = frame.popValue(); frame.popValue(); frame.pushValue(resultType); } catch (DataflowAnalysisException e) { AnalysisContext.logError("oops", e); } return; } handleNormalInstruction(obj); }
InstructionHandle nextNextHandle = nextHandle.getNext(); // aload if (nextNextHandle == null) { return false; Instruction nextInstruction = nextNextHandle.getInstruction(); return false; InstructionHandle nextNextNextHandle = nextNextHandle.getNext(); // invoke if (nextNextNextHandle == null) { return false; String methodName = invokeVirtual.getMethodName(classContext.getConstantPoolGen()); String methodSig = invokeVirtual.getSignature(classContext.getConstantPoolGen()); if (!"close".equals(methodName)) { return false;
int outlineChunkStartOffset = first.getPosition(); int outlineChunkEndOffset = last.getPosition() + last.getInstruction().getLength(); final InstructionList newIL = new InstructionList(); InstructionList oldMethCopyInIL = new InstructionList(); InstructionList oldMethCopyOutIL = new InstructionList(); InstructionList newMethCopyInIL = new InstructionList(); InstructionList newMethCopyOutIL = new InstructionList(); oldMethCopyInIL.append(new NEW(cpg.addClass(argTypeName))); oldMethCopyInIL.append(InstructionConstants.DUP); oldMethCopyInIL.append(InstructionConstants.DUP); oldMethCopyInIL.append( new INVOKESPECIAL(cpg.addMethodref(argTypeName, "<init>", "()V"))); outlinedMethodRef = oldMethCopyOutIL.append( new INVOKESTATIC(cpg.addMethodref( classGen.getClassName(), outlinedMethodName, outlinedMethodRef = oldMethCopyOutIL.append( new INVOKEVIRTUAL(cpg.addMethodref( classGen.getClassName(), outlinedMethodName,
final int getKeyIndex = cpg.addMethodref(TRANSLET_CLASS, "getKeyIndex", "(Ljava/lang/String;)"+ final int lookupId = cpg.addMethodref(KEY_INDEX_CLASS, "containsID", "(ILjava/lang/Object;)I"); final int lookupKey = cpg.addMethodref(KEY_INDEX_CLASS, "containsKey", "(ILjava/lang/Object;)I"); il.append(classGen.loadTranslet()); il.append(new PUSH(cpg,_index)); il.append(new INVOKEVIRTUAL(getKeyIndex)); if (this instanceof IdPattern) il.append(new INVOKEVIRTUAL(lookupId)); il.append(new INVOKEVIRTUAL(lookupKey));
InstructionList invokeInstructions = new InstructionList(); MethodEntry[] operations = getOperations(info); int invokeIndex = cp.addMethodref( SUPER_CLASS.getName(), "invoke", invokeInstructions.append(new ALOAD(1)); // Stack: => ..., arg1 [String] invokeInstructions.append(ifOperationEqualsNull); // Stack: => ... invokeInstructions.append(new ALOAD(1)); // Stack: => ..., arg1 [String] invokeInstructions.append(new LDC(operations[i].nameIndexInCP)); // Stack: => ..., opName [String] invokeInstructions.append(new INVOKEVIRTUAL(strEqualsIndex)); // Stack: => ..., 0 | 1 [boolean] invokeInstructions.append(new ALOAD(0)); // Stack: => ..., this invokeInstructions.append(new INVOKEVIRTUAL(getResourceObjectIndex)); // Stack: => ..., resource [Object] int x = cp.addClass(resourceClassName); invokeInstructions.append(new INVOKEVIRTUAL(x)); // Stack: => ..., returnvalue beginTryBlock = beginTryBlock.getNext(); endTryBlock = jumpToSuperInvoke.getPrev();
/** * Compile the expression - leave boolean expression on stack */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); _base.translate(classGen, methodGen); _token.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS, "startsWith", "("+STRING_SIG+")Z"))); } }
il.append(loadInstruction()); BranchHandle ifBlock = il.append(new IFNONNULL(null)); translateValue(classGen, methodGen); il.append(storeInstruction()); ifBlock.setTarget(il.append(NOP)); return; il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, ADD_PARAMETER, ADD_PARAMETER_SIG))); if (className != EMPTYSTRING) { il.append(new CHECKCAST(cpg.addClass(className))); classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name), cpg.addUtf8(signature), null, cpg.getConstantPool())); il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, ADD_PARAMETER, ADD_PARAMETER_SIG)));
il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(methodGen.loadHandler()); il.append(methodGen.loadCurrentNode()); il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, "("
Location location = i.next(); Instruction inst = location.getHandle().getInstruction(); String value = ByteCode.getConstantLDC(location.getHandle().getPrev(), cpg, String.class); if (value != null && value.toUpperCase().startsWith("RSA")) { createRsaKeyGen = true; if ("java.security.KeyPairGenerator".equals(invoke.getClassName(cpg)) && "initialize".equals(invoke.getMethodName(cpg))) { Number n = null; if ("(I)V".equals(invoke.getSignature(cpg))) { n = ByteCode.getPushNumber(location.getHandle().getPrev()); else if ("(ILjava/security/SecureRandom;)V".equals(invoke.getSignature(cpg))) { if ("java.security.spec.RSAKeyGenParameterSpec".equals(invoke.getClassName(cpg)) && "<init>".equals(invoke.getMethodName(cpg))) { Number n = null; if ("(ILjava/math/BigInteger;)V".equals(invoke.getSignature(cpg))) { SIPUSH push = ByteCode.getPrevInstruction(location.getHandle(), SIPUSH.class); if (push != null) {
while ((bState.getUncheckedFieldSize() > 0) && ii.hasNext()) { InstructionHandle ih = ii.next(); Instruction ins = ih.getInstruction(); if (ins instanceof FieldInstruction) { FieldInstruction fi = (FieldInstruction) ins; finfo.setSrcLineAnnotation(SourceLineAnnotation.fromVisitedInstruction(clsContext, this, ih.getPosition())); INVOKESPECIAL is = (INVOKESPECIAL) ins; ReferenceType rt = is.getReferenceType(cpg); if (Values.CONSTRUCTOR.equals(is.getMethodName(cpg))) { if ((rt instanceof ObjectType) && ((ObjectType) rt).getClassName().startsWith(clsContext.getJavaClass().getClassName() + Values.INNER_CLASS_SEPARATOR)) { INVOKEVIRTUAL is = (INVOKEVIRTUAL) ins; ReferenceType rt = is.getReferenceType(cpg); if ((rt instanceof ObjectType) && ((ObjectType) rt).getClassName().equals(clsName)) { String methodDesc = is.getName(cpg) + is.getSignature(cpg); Set<String> fields = methodFieldModifiers.get(methodDesc); if (fields != null) {
public boolean preScreen(MethodGen mg) { ConstantPoolGen cpg = mg.getConstantPool(); int lockCount = mg.isSynchronized() ? 1 : 0; boolean sawWaitOrNotify = false; InstructionHandle handle = mg.getInstructionList().getStart(); while (handle != null && !(lockCount >= 2 && sawWaitOrNotify)) { Instruction ins = handle.getInstruction(); if (ins instanceof MONITORENTER) { ++lockCount; } else if (ins instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL inv = (INVOKEVIRTUAL) ins; String methodName = inv.getMethodName(cpg); if ("wait".equals(methodName) || methodName.startsWith("notify")) { sawWaitOrNotify = true; } } handle = handle.getNext(); } return lockCount >= 2 && sawWaitOrNotify; }
/** Create an invoke instruction. * * @param class_name name of the called class * @param name name of the called method * @param ret_type return type of method * @param arg_types argument types of method * @param kind how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, * or INVOKESPECIAL * @see Constants */ public InvokeInstruction createInvoke(String class_name, String name, Type ret_type, Type[] arg_types, short kind) { int index; int nargs = 0; String signature = Type.getMethodSignature(ret_type, arg_types); for(int i=0; i < arg_types.length; i++) // Count size of arguments nargs += arg_types[i].getSize(); if(kind == Constants.INVOKEINTERFACE) index = cp.addInterfaceMethodref(class_name, name, signature); else index = cp.addMethodref(class_name, name, signature); switch(kind) { case Constants.INVOKESPECIAL: return new INVOKESPECIAL(index); case Constants.INVOKEVIRTUAL: return new INVOKEVIRTUAL(index); case Constants.INVOKESTATIC: return new INVOKESTATIC(index); case Constants.INVOKEINTERFACE: return new INVOKEINTERFACE(index, nargs + 1); default: throw new RuntimeException("Oops: Unknown invoke kind:" + kind); } }
Instruction inst = location.getHandle().getInstruction(); if (("javax.crypto.Cipher").equals(invoke.getClassName(cpg)) && "init".equals(invoke.getMethodName(cpg))) { ICONST iconst = ByteCode.getPrevInstruction(location.getHandle(), ICONST.class); if (iconst != null) { else if (("javax.crypto.Cipher").equals(invoke.getClassName(cpg)) && "getIV".equals(invoke.getMethodName(cpg))) { ivFetchFromCipher = true; Instruction inst = location.getHandle().getInstruction(); if ("java.security.SecureRandom".equals(invoke.getClassName(cpg)) && "nextBytes".equals(invoke.getMethodName(cpg))) { foundSafeIvGeneration = true; if (("javax.crypto.spec.IvParameterSpec").equals(invoke.getClassName(cpg)) && "<init>".equals(invoke.getMethodName(cpg))) {
continue; //No instruction .. nothing to do for (Iterator itIns = methodGen.getInstructionList().iterator();itIns.hasNext();) { Instruction inst = ((InstructionHandle) itIns.next()).getInstruction(); if ("java.security.MessageDigest".equals(invoke.getClassName(cpg)) && "digest".equals(invoke.getMethodName(cpg))) { invokeMessageDigest = true;
Instruction ins = handle.getInstruction(); if (!(ins instanceof INVOKEVIRTUAL)) { continue; String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); int numConsumed = inv.consumeStack(cpg); if (numConsumed == Const.UNPREDICTABLE) { throw new DataflowAnalysisException("Unpredictable stack consumption", methodGen, handle);
Instruction ins = handle.getInstruction(); String methodName = iv.getMethodName(cpg); String methodSig = iv.getSignature(cpg); if ("wait".equals(methodName) && ("()V".equals(methodSig) || "(J)V".equals(methodSig) || "(JI)V".equals(methodSig))
private Map<String, List<Location>> get_line_location(Method m, ClassContext classContext){ HashMap<String, List<Location>> all_line_location = new HashMap<>(); ConstantPoolGen cpg = classContext.getConstantPoolGen(); CFG cfg = null; try { cfg = classContext.getCFG(m); } catch (CFGBuilderException e) { e.printStackTrace(); return all_line_location; } for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) { Location loc = i.next(); Instruction inst = loc.getHandle().getInstruction(); if(inst instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL invoke = (INVOKEVIRTUAL) inst; // if (classname.equals(invoke.getClassName(cpg)) && // methodName.equals(invoke.getMethodName(cpg))) { if(all_line_location.containsKey(invoke.getMethodName(cpg))){ all_line_location.get(invoke.getMethodName(cpg)).add(loc); }else { LinkedList<Location> loc_list = new LinkedList<>(); loc_list.add(loc); all_line_location.put(invoke.getMethodName(cpg), loc_list); } // } } } return all_line_location; }