for (IField f : klass.getDeclaredInstanceFields()) { int tempValue = nextLocal++; SSAGetInstruction G = insts.GetInstruction(statements.size(), tempValue, 1, f.getReference()); statements.add(G); SSAPutInstruction P = insts.PutInstruction(statements.size(), retValue, tempValue, f.getReference()); statements.add(P);
for (IField f : klass.getDeclaredInstanceFields()) { int tempValue = nextLocal++; SSAGetInstruction G = insts.GetInstruction(statements.size(), tempValue, 1, f.getReference()); statements.add(G); SSAPutInstruction P = insts.PutInstruction(statements.size(), retValue, tempValue, f.getReference()); statements.add(P);
@SuppressWarnings("unchecked") @Override public Set<FlowType<IExplodedBasicBlock>> findSources( CGAnalysisContext<IExplodedBasicBlock> ctx, TabulationResult<BasicBlockInContext<IExplodedBasicBlock>, CGNode, DomainElement> flowResult, IFDSTaintDomain<IExplodedBasicBlock> domain) { Set<FlowType<IExplodedBasicBlock>> sources = HashSetFactory.make(); for (DomainElement de : domain .getPossibleElements(new StaticFieldElement(field .getReference()))) { if (de.taintSource instanceof StaticFieldFlow<?>) { StaticFieldFlow<IExplodedBasicBlock> source = (StaticFieldFlow<IExplodedBasicBlock>) de.taintSource; if (source.getField().equals(field)) { continue; } } else if (flowResult.getResult(block).contains(domain.getMappedIndex(de))) { sources.add(de.taintSource); } } return sources; }
/** * This main program shows one example use of thread escape analysis: producing a set of fields to be monitored for a * dynamic race detector. The idea is that any field might have a race with two exceptions: final fields do not have * races since there are no writes to them, and volatile fields have atomic read and write semantics provided by the * VM. Hence, this piece of code produces a list of all other fields. */ public static void main(String[] args) throws IOException, IllegalArgumentException, CancelException { String mainClassName = args[0]; Set<JarFile> jars = HashSetFactory.make(); for (int i = 1; i < args.length; i++) { jars.add(new JarFile(args[i], false)); } Set<IClass> escapingTypes = (new SimpleThreadEscapeAnalysis(jars, mainClassName)).gatherThreadEscapingClasses(); for (IClass cls : escapingTypes) { if (!cls.isArrayClass()) { for (IField f : cls.getAllFields()) { if (!f.isVolatile() && !f.isFinal()) { System.err.println(f.getReference()); } } } } } }
elts.add(new FieldElement(ik, field.getReference())); final IClass fieldClass = analysisContext.getClassHierarchy().lookupClass(fieldTypeRef); if (fieldTypeRef.isPrimitiveType() || fieldClass == null) {
private boolean allFieldsArePrimitive(IClass c) { if (c.isArrayClass()) { TypeReference t = c.getReference().getArrayElementType(); return t.isPrimitiveType(); } else { if (c.getReference().equals(TypeReference.JavaLangObject)) { return true; } else { for (IField f : c.getDeclaredInstanceFields()) { if (f.getReference().getFieldType().isReferenceType()) { return false; } } return allFieldsArePrimitive(c.getSuperclass()); } } }
private boolean allFieldsArePrimitive(IClass c) { if (c.isArrayClass()) { TypeReference t = c.getReference().getArrayElementType(); return t.isPrimitiveType(); } else { if (c.getReference().equals(TypeReference.JavaLangObject)) { return true; } else { for (IField f : c.getDeclaredInstanceFields()) { if (f.getReference().getFieldType().isReferenceType()) { return false; } } return allFieldsArePrimitive(c.getSuperclass()); } } }
valueElements.add(new StaticFieldElement(field.getReference())); FlowType<E> flow = new StaticFieldFlow<>(block, field, true);
assert(f.isStatic()) : "All fields of AndroidModelClass are expected to be static! " + f + " is not."; final TypeReference fdType = f.getReference().getFieldType(); final VariableKey subKey = new SSAValue.WeaklyNamedKey(fdType.getName(), "ctx" + fdType.getName().getClassName().toString()); instance = this.pm.getUnallocated(fdType, subKey); final SSAInstruction getInst = instructionFactory.GetInstruction(pc, instance, f.getReference()); this.body.addStatement(getInst); this.pm.setAllocation(instance, getInst);
assert(f.isStatic()) : "All fields of AndroidModelClass are expected to be static! " + f + " is not."; final TypeReference fdType = f.getReference().getFieldType(); final VariableKey subKey = new SSAValue.WeaklyNamedKey(fdType.getName(), "ctx" + fdType.getName().getClassName().toString()); instance = this.pm.getUnallocated(fdType, subKey); final SSAInstruction getInst = instructionFactory.GetInstruction(pc, instance, f.getReference()); this.body.addStatement(getInst); this.pm.setAllocation(instance, getInst);
public void visitPutInternal(int rval, int ref, boolean isStatic, FieldReference field) { if (DEBUG) { System.err.println("visitPut " + field); } // skip putfields of primitive type if (field.getFieldType().isPrimitiveType()) { return; } IField f = getClassHierarchy().resolveField(field); if (f == null) { if (DEBUG) { System.err.println("Could not resolve field " + field); } Warnings.add(FieldResolutionFailure.create(field)); return; } assert f.getFieldTypeReference().getName().equals(field.getFieldType().getName()) : "name clash of two fields with the same name but different type: " + f.getReference() + " <=> " + field; assert isStatic || !symbolTable.isStringConstant(ref) : "put to string constant shouldn't be allowed?"; if (isStatic) { processPutStatic(rval, field, f); } else { processPutField(rval, ref, f); } }
public void visitPutInternal(int rval, int ref, boolean isStatic, FieldReference field) { if (DEBUG) { System.err.println("visitPut " + field); } // skip putfields of primitive type if (field.getFieldType().isPrimitiveType()) { return; } IField f = getClassHierarchy().resolveField(field); if (f == null) { if (DEBUG) { System.err.println("Could not resolve field " + field); } Warnings.add(FieldResolutionFailure.create(field)); return; } assert f.getFieldTypeReference().getName().equals(field.getFieldType().getName()) : "name clash of two fields with the same name but different type: " + f.getReference() + " <=> " + field; assert isStatic || !symbolTable.isStringConstant(ref) : "put to string constant shouldn't be allowed?"; if (isStatic) { processPutStatic(rval, field, f); } else { processPutField(rval, ref, f); } }
MutableSparseIntSet result = MutableSparseIntSet.makeEmpty(); for (IField f : klass.getAllInstanceFields()) { if (!f.getReference().getFieldType().isPrimitiveType()) { PointerKey p = getHeapModel().getPointerKeyForInstanceField(I, f); if (p != null && nodeManager.containsNode(p)) {
MutableSparseIntSet result = MutableSparseIntSet.makeEmpty(); for (IField f : klass.getAllInstanceFields()) { if (!f.getReference().getFieldType().isPrimitiveType()) { PointerKey p = getHeapModel().getPointerKeyForInstanceField(I, f); if (p != null && nodeManager.containsNode(p)) {
for(int i = 0; i < site.getDeclaredTarget().getNumberOfParameters(); i++) { summary.addStatement( insts.PutInstruction(index++, v, i+1, lambda.getField(Atom.findOrCreateUnicodeAtom("c" + i)).getReference()));
for(int i = 0; i < site.getDeclaredTarget().getNumberOfParameters(); i++) { summary.addStatement( insts.PutInstruction(index++, v, i+1, lambda.getField(Atom.findOrCreateUnicodeAtom("c" + i)).getReference()));
for(int i = 0; i < invoke.getNumberOfPositionalParameters(); i++) { Atom f = Atom.findOrCreateUnicodeAtom("c" + i); summary.addStatement(insts.GetInstruction(inst++, v++, 1, getField(f).getReference()));
arg = pm.getUnallocated(argT, new SSAValue.WeaklyNamedKey(argT.getName(), "got" + fdName.toString())); final SSAInstruction getInst = instructionFactory.GetInstruction(instPC, arg, field.getReference()); encap.addStatement(getInst); pm.setAllocation(arg, getInst);
for(int i = 0; i < invoke.getNumberOfPositionalParameters(); i++) { Atom f = Atom.findOrCreateUnicodeAtom("c" + i); summary.addStatement(insts.GetInstruction(inst++, v++, 1, getField(f).getReference()));
arg = pm.getUnallocated(argT, new SSAValue.WeaklyNamedKey(argT.getName(), "got" + fdName.toString())); final SSAInstruction getInst = instructionFactory.GetInstruction(instPC, arg, field.getReference()); encap.addStatement(getInst); pm.setAllocation(arg, getInst);