proj_name
stringclasses
131 values
relative_path
stringlengths
30
228
class_name
stringlengths
1
68
func_name
stringlengths
1
48
masked_class
stringlengths
78
9.82k
func_body
stringlengths
46
9.61k
len_input
int64
29
2.01k
len_output
int64
14
1.94k
total
int64
55
2.05k
relevant_context
stringlengths
0
38.4k
soot-oss_soot
soot/src/main/java/soot/UnknownMethodSource.java
UnknownMethodSource
getBody
class UnknownMethodSource implements MethodSource { UnknownMethodSource() { } public Body getBody(SootMethod m, String phaseName) {<FILL_FUNCTION_BODY>} }
// we ignore options here. // actually we should have default option verbatim, // and apply phase options. // in fact we probably want to allow different // phase options depending on app vs. lib. throw new RuntimeException("Can't get body for unknown source!"); // InputStream classFileStream; // try { // classFileStream = SourceLocator.getInputStreamOf(m.getDeclaringClass().toString()); // } // catch(ClassNotFoundException e) { // throw new RuntimeException("Can't find jimple file: " + e); // } // Parser.parse(classFileStream, m.getDeclaringClass());
51
173
224
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/XMLAttributesPrinter.java
XMLAttributesPrinter
initFile
class XMLAttributesPrinter { private static final Logger logger = LoggerFactory.getLogger(XMLAttributesPrinter.class); private String useFilename; private String outputDir; private FileOutputStream streamOut = null; private PrintWriter writerOut = null; private void setOutputDir(String dir) { outputDir = dir; } private String getOutputDir() { return outputDir; } public XMLAttributesPrinter(String filename, String outputDir) { setInFilename(filename); setOutputDir(outputDir); initAttributesDir(); createUseFilename(); } private void initFile() {<FILL_FUNCTION_BODY>} private void finishFile() { writerOut.println("</attributes>"); writerOut.close(); } public void printAttrs(SootClass c, soot.xml.TagCollector tc) { printAttrs(c, tc, false); } public void printAttrs(SootClass c) { printAttrs(c, new soot.xml.TagCollector(), true); } private void printAttrs(SootClass c, soot.xml.TagCollector tc, boolean includeBodyTags) { tc.collectKeyTags(c); tc.collectTags(c, includeBodyTags); // If there are no attributes, then the attribute file is not created. if (tc.isEmpty()) { return; } initFile(); tc.printTags(writerOut); tc.printKeys(writerOut); finishFile(); } private void initAttributesDir() { final String attrDir = "attributes"; File dir = new File(getOutputDir() + File.separatorChar + attrDir); if (!dir.exists()) { try { dir.mkdirs(); } catch (SecurityException se) { logger.debug("Unable to create " + attrDir); // System.exit(0); } } } private void createUseFilename() { String tmp = getInFilename(); // logger.debug("attribute file name: "+tmp); tmp = tmp.substring(0, tmp.lastIndexOf('.')); int slash = tmp.lastIndexOf(File.separatorChar); if (slash != -1) { tmp = tmp.substring(slash + 1, tmp.length()); } final String attrDir = "attributes"; StringBuilder sb = new StringBuilder(); sb.append(getOutputDir()); sb.append(File.separatorChar); sb.append(attrDir); sb.append(File.separatorChar); sb.append(tmp); sb.append(".xml"); // tmp = sb.toString()+tmp+".xml"; setUseFilename(sb.toString()); } private void setInFilename(String file) { useFilename = file; } private String getInFilename() { return useFilename; } private void setUseFilename(String file) { useFilename = file; } private String getUseFilename() { return useFilename; } }
try { streamOut = new FileOutputStream(getUseFilename()); writerOut = new PrintWriter(new OutputStreamWriter(streamOut)); writerOut.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); writerOut.println("<attributes>"); } catch (IOException e1) { logger.debug(e1.getMessage()); }
839
105
944
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/asm/AnnotationElemBuilder.java
AnnotationElemBuilder
getAnnotationElement
class AnnotationElemBuilder extends AnnotationVisitor { protected final ArrayList<AnnotationElem> elems; AnnotationElemBuilder(int expected) { super(Opcodes.ASM5); this.elems = new ArrayList<AnnotationElem>(expected); } AnnotationElemBuilder() { this(4); } public AnnotationElem getAnnotationElement(String name, Object value) {<FILL_FUNCTION_BODY>} @Override public void visit(String name, Object value) { AnnotationElem elem = getAnnotationElement(name, value); this.elems.add(elem); } @Override public void visitEnum(String name, String desc, String value) { elems.add(new AnnotationEnumElem(desc, value, 'e', name)); } @Override public AnnotationVisitor visitArray(final String name) { return new AnnotationElemBuilder() { @Override public void visitEnd() { String ename = name; if (ename == null) { ename = "default"; } AnnotationElemBuilder.this.elems.add(new AnnotationArrayElem(this.elems, '[', ename)); } }; } @Override public AnnotationVisitor visitAnnotation(final String name, final String desc) { return new AnnotationElemBuilder() { @Override public void visitEnd() { AnnotationTag tag = new AnnotationTag(desc, elems); AnnotationElemBuilder.this.elems.add(new AnnotationAnnotationElem(tag, '@', name)); } }; } @Override public abstract void visitEnd(); }
AnnotationElem elem; if (value instanceof Byte) { elem = new AnnotationIntElem((Byte) value, 'B', name); } else if (value instanceof Boolean) { elem = new AnnotationIntElem(((Boolean) value) ? 1 : 0, 'Z', name); } else if (value instanceof Character) { elem = new AnnotationIntElem((Character) value, 'C', name); } else if (value instanceof Short) { elem = new AnnotationIntElem((Short) value, 'S', name); } else if (value instanceof Integer) { elem = new AnnotationIntElem((Integer) value, 'I', name); } else if (value instanceof Long) { elem = new AnnotationLongElem((Long) value, 'J', name); } else if (value instanceof Float) { elem = new AnnotationFloatElem((Float) value, 'F', name); } else if (value instanceof Double) { elem = new AnnotationDoubleElem((Double) value, 'D', name); } else if (value instanceof String) { elem = new AnnotationStringElem(value.toString(), 's', name); } else if (value instanceof Type) { Type t = (Type) value; elem = new AnnotationClassElem(t.getDescriptor(), 'c', name); } else if (value.getClass().isArray()) { ArrayList<AnnotationElem> annotationArray = new ArrayList<AnnotationElem>(); if (value instanceof byte[]) { for (Object element : (byte[]) value) { annotationArray.add(getAnnotationElement(name, element)); } } else if (value instanceof boolean[]) { for (Object element : (boolean[]) value) { annotationArray.add(getAnnotationElement(name, element)); } } else if (value instanceof char[]) { for (Object element : (char[]) value) { annotationArray.add(getAnnotationElement(name, element)); } } else if (value instanceof short[]) { for (Object element : (short[]) value) { annotationArray.add(getAnnotationElement(name, element)); } } else if (value instanceof int[]) { for (Object element : (int[]) value) { annotationArray.add(getAnnotationElement(name, element)); } } else if (value instanceof long[]) { for (Object element : (long[]) value) { annotationArray.add(getAnnotationElement(name, element)); } } else if (value instanceof float[]) { for (Object element : (float[]) value) { annotationArray.add(getAnnotationElement(name, element)); } } else if (value instanceof double[]) { for (Object element : (double[]) value) { annotationArray.add(getAnnotationElement(name, element)); } } else if (value instanceof String[]) { for (Object element : (String[]) value) { annotationArray.add(getAnnotationElement(name, element)); } } else if (value instanceof Type[]) { for (Object element : (Type[]) value) { annotationArray.add(getAnnotationElement(name, element)); } } else { throw new UnsupportedOperationException("Unsupported array value type: " + value.getClass()); } elem = new AnnotationArrayElem(annotationArray, '[', name); } else { throw new UnsupportedOperationException("Unsupported value type: " + value.getClass()); } return (elem);
448
895
1,343
<methods>public org.objectweb.asm.AnnotationVisitor getDelegate() ,public void visit(java.lang.String, java.lang.Object) ,public org.objectweb.asm.AnnotationVisitor visitAnnotation(java.lang.String, java.lang.String) ,public org.objectweb.asm.AnnotationVisitor visitArray(java.lang.String) ,public void visitEnd() ,public void visitEnum(java.lang.String, java.lang.String, java.lang.String) <variables>protected final int api,protected org.objectweb.asm.AnnotationVisitor av
soot-oss_soot
soot/src/main/java/soot/asm/AsmJava9ClassProvider.java
AsmJava9ClassProvider
find
class AsmJava9ClassProvider implements ClassProvider { private static final Logger logger = LoggerFactory.getLogger(AsmJava9ClassProvider.class); @Override public ClassSource find(String cls) {<FILL_FUNCTION_BODY>} }
final String clsFile = cls.replace('.', '/') + ".class"; // here we go through all modules, since we are in classpath mode IFoundFile file = null; Path p = ModulePathSourceLocator.getRootModulesPathOfJDK(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) { for (Path entry : stream) { // check each module folder for the class file = ModulePathSourceLocator.v().lookUpInVirtualFileSystem(entry.toUri().toString(), clsFile); if (file != null) { break; } } } catch (FileSystemNotFoundException ex) { logger.debug("Could not read my modules (perhaps not Java 9?)."); } catch (IOException e) { logger.debug(e.getMessage(), e); } return file == null ? null : new AsmClassSource(cls, file);
68
235
303
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/asm/CastAndReturnInliner.java
CastAndReturnInliner
internalTransform
class CastAndReturnInliner extends BodyTransformer { @Override protected void internalTransform(Body body, String phaseName, Map<String, String> options) {<FILL_FUNCTION_BODY>} }
final UnitPatchingChain units = body.getUnits(); for (Iterator<Unit> it = units.snapshotIterator(); it.hasNext();) { Unit u = it.next(); if (u instanceof GotoStmt) { GotoStmt gtStmt = (GotoStmt) u; if (gtStmt.getTarget() instanceof AssignStmt) { AssignStmt assign = (AssignStmt) gtStmt.getTarget(); if (assign.getRightOp() instanceof CastExpr) { CastExpr ce = (CastExpr) assign.getRightOp(); // We have goto that ends up at a cast statement Unit nextStmt = units.getSuccOf(assign); if (nextStmt instanceof ReturnStmt) { ReturnStmt retStmt = (ReturnStmt) nextStmt; if (retStmt.getOp() == assign.getLeftOp()) { // We need to replace the GOTO with the return ReturnStmt newStmt = (ReturnStmt) retStmt.clone(); Local a = (Local) ce.getOp(); for (Trap t : body.getTraps()) { for (UnitBox ubox : t.getUnitBoxes()) { if (ubox.getUnit() == gtStmt) { ubox.setUnit(newStmt); } } } Jimple j = Jimple.v(); Local n = j.newLocal(a.getName() + "_ret", ce.getCastType()); body.getLocals().add(n); newStmt.setOp(n); final List<UnitBox> boxesRefGtStmt = gtStmt.getBoxesPointingToThis(); while (!boxesRefGtStmt.isEmpty()) { boxesRefGtStmt.get(0).setUnit(newStmt); } units.swapWith(gtStmt, newStmt); ce = (CastExpr) ce.clone(); units.insertBefore(j.newAssignStmt(n, ce), newStmt); } } } } } }
55
547
602
<methods>public non-sealed void <init>() ,public final void transform(soot.Body, java.lang.String, Map<java.lang.String,java.lang.String>) ,public final void transform(soot.Body, java.lang.String) ,public final void transform(soot.Body) <variables>private static final Map<java.lang.String,java.lang.String> enabledOnlyMap
soot-oss_soot
soot/src/main/java/soot/asm/FieldBuilder.java
FieldBuilder
getTagBuilder
class FieldBuilder extends FieldVisitor { private TagBuilder tb; private final SootField field; private final SootClassBuilder scb; FieldBuilder(SootField field, SootClassBuilder scb) { super(Opcodes.ASM5); this.field = field; this.scb = scb; } private TagBuilder getTagBuilder() {<FILL_FUNCTION_BODY>} @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { return getTagBuilder().visitAnnotation(desc, visible); } @Override public void visitAttribute(Attribute attr) { getTagBuilder().visitAttribute(attr); } }
TagBuilder t = tb; if (t == null) { t = tb = new TagBuilder(field, scb); } return t;
186
45
231
<methods>public org.objectweb.asm.FieldVisitor getDelegate() ,public org.objectweb.asm.AnnotationVisitor visitAnnotation(java.lang.String, boolean) ,public void visitAttribute(org.objectweb.asm.Attribute) ,public void visitEnd() ,public org.objectweb.asm.AnnotationVisitor visitTypeAnnotation(int, org.objectweb.asm.TypePath, java.lang.String, boolean) <variables>protected final int api,protected org.objectweb.asm.FieldVisitor fv
soot-oss_soot
soot/src/main/java/soot/baf/internal/AbstractOpTypeBranchInst.java
AbstractOpTypeBranchInst
toString
class AbstractOpTypeBranchInst extends AbstractBranchInst { protected Type opType; AbstractOpTypeBranchInst(Type opType, UnitBox targetBox) { super(targetBox); setOpType(opType); } public Type getOpType() { return this.opType; } public void setOpType(Type t) { this.opType = Baf.getDescriptorTypeOf(t); } @Override public int getInCount() { return 2; } @Override public int getOutCount() { return 0; } @Override public String toString() {<FILL_FUNCTION_BODY>} @Override public void toString(UnitPrinter up) { up.literal(getName()); up.literal("."); up.literal(Baf.bafDescriptorOf(opType)); up.literal(" "); targetBox.toString(up); } }
// do stuff with opType later. return getName() + "." + Baf.bafDescriptorOf(opType) + " " + getTarget();
261
41
302
<methods>public boolean branches() ,public soot.Unit getTarget() ,public soot.UnitBox getTargetBox() ,public List<soot.UnitBox> getUnitBoxes() ,public void setTarget(soot.Unit) ,public java.lang.String toString() ,public void toString(soot.UnitPrinter) <variables>soot.UnitBox targetBox,final non-sealed List<soot.UnitBox> targetBoxes
soot-oss_soot
soot/src/main/java/soot/baf/internal/AbstractSwitchInst.java
AbstractSwitchInst
setTargets
class AbstractSwitchInst extends AbstractInst implements SwitchInst { UnitBox defaultTargetBox; UnitBox[] targetBoxes; List<UnitBox> unitBoxes; public AbstractSwitchInst(Unit defaultTarget, List<? extends Unit> targets) { this.defaultTargetBox = Baf.v().newInstBox(defaultTarget); // Build up 'targetBoxes' final int numTargets = targets.size(); UnitBox[] tgts = new UnitBox[numTargets]; for (int i = 0; i < numTargets; i++) { tgts[i] = Baf.v().newInstBox(targets.get(i)); } this.targetBoxes = tgts; // Build up 'unitBoxes' List<UnitBox> unitBoxes = new ArrayList<UnitBox>(numTargets + 1); for (UnitBox element : tgts) { unitBoxes.add(element); } unitBoxes.add(defaultTargetBox); this.unitBoxes = Collections.unmodifiableList(unitBoxes); } @Override public int getInCount() { return 1; } @Override public int getInMachineCount() { return 1; } @Override public int getOutCount() { return 0; } @Override public int getOutMachineCount() { return 0; } @Override public List<UnitBox> getUnitBoxes() { return unitBoxes; } @Override public boolean fallsThrough() { return false; } @Override public boolean branches() { return true; } @Override public Unit getDefaultTarget() { return defaultTargetBox.getUnit(); } @Override public void setDefaultTarget(Unit defaultTarget) { defaultTargetBox.setUnit(defaultTarget); } @Override public UnitBox getDefaultTargetBox() { return defaultTargetBox; } @Override public int getTargetCount() { return targetBoxes.length; } @Override public Unit getTarget(int index) { return targetBoxes[index].getUnit(); } @Override public void setTarget(int index, Unit target) { targetBoxes[index].setUnit(target); } @Override public void setTargets(List<Unit> targets) {<FILL_FUNCTION_BODY>} @Override public UnitBox getTargetBox(int index) { return targetBoxes[index]; } @Override public List<Unit> getTargets() { List<Unit> targets = new ArrayList<Unit>(); for (UnitBox element : targetBoxes) { targets.add(element.getUnit()); } return targets; } }
final UnitBox[] targetBoxes = this.targetBoxes; for (int i = 0; i < targets.size(); i++) { targetBoxes[i].setUnit(targets.get(i)); }
749
59
808
<methods>public non-sealed void <init>() ,public boolean branches() ,public java.lang.Object clone() ,public boolean containsArrayRef() ,public boolean containsFieldRef() ,public boolean containsInvokeExpr() ,public boolean containsNewExpr() ,public boolean fallsThrough() ,public int getInCount() ,public int getInMachineCount() ,public abstract java.lang.String getName() ,public int getNetCount() ,public int getNetMachineCount() ,public int getOutCount() ,public int getOutMachineCount() ,public java.lang.String toString() ,public void toString(soot.UnitPrinter) <variables>
soot-oss_soot
soot/src/main/java/soot/baf/internal/BDup2Inst.java
BDup2Inst
getOpTypes
class BDup2Inst extends BDupInst implements Dup2Inst { private final Type mOp1Type; private final Type mOp2Type; public BDup2Inst(Type aOp1Type, Type aOp2Type) { this.mOp1Type = Baf.getDescriptorTypeOf(aOp1Type); this.mOp2Type = Baf.getDescriptorTypeOf(aOp2Type); } @Override public Type getOp1Type() { return mOp1Type; } @Override public Type getOp2Type() { return mOp2Type; } @Override public List<Type> getOpTypes() {<FILL_FUNCTION_BODY>} @Override public List<Type> getUnderTypes() { return new ArrayList<Type>(); } @Override final public String getName() { return "dup2"; } @Override public void apply(Switch sw) { ((InstSwitch) sw).caseDup2Inst(this); } @Override public String toString() { return "dup2." + Baf.bafDescriptorOf(mOp1Type) + Baf.bafDescriptorOf(mOp2Type); } }
List<Type> res = new ArrayList<Type>(); res.add(mOp1Type); res.add(mOp2Type); return res;
332
44
376
<methods>public non-sealed void <init>() ,public void apply(soot.util.Switch) ,public int getInCount() ,public int getInMachineCount() ,public int getOutCount() ,public int getOutMachineCount() <variables>
soot-oss_soot
soot/src/main/java/soot/baf/internal/BDup2_x1Inst.java
BDup2_x1Inst
toString
class BDup2_x1Inst extends BDupInst implements Dup2_x1Inst { private final Type mOp1Type; private final Type mOp2Type; private final Type mUnderType; public BDup2_x1Inst(Type aOp1Type, Type aOp2Type, Type aUnderType) { this.mOp1Type = Baf.getDescriptorTypeOf(aOp1Type); this.mOp2Type = Baf.getDescriptorTypeOf(aOp2Type); this.mUnderType = Baf.getDescriptorTypeOf(aUnderType); } @Override public Type getOp1Type() { return mOp1Type; } @Override public Type getOp2Type() { return mOp2Type; } @Override public Type getUnder1Type() { return mUnderType; } @Override public List<Type> getOpTypes() { List<Type> res = new ArrayList<Type>(); res.add(mOp1Type); res.add(mOp2Type); return res; } @Override public List<Type> getUnderTypes() { List<Type> res = new ArrayList<Type>(); res.add(mUnderType); return res; } @Override final public String getName() { return "dup2_x1"; } @Override public void apply(Switch sw) { ((InstSwitch) sw).caseDup2_x1Inst(this); } @Override public String toString() {<FILL_FUNCTION_BODY>} }
return "dup2_x1." + Baf.bafDescriptorOf(mOp1Type) + "." + Baf.bafDescriptorOf(mOp2Type) + "_" + Baf.bafDescriptorOf(mUnderType);
431
63
494
<methods>public non-sealed void <init>() ,public void apply(soot.util.Switch) ,public int getInCount() ,public int getInMachineCount() ,public int getOutCount() ,public int getOutMachineCount() <variables>
soot-oss_soot
soot/src/main/java/soot/baf/internal/BDup2_x2Inst.java
BDup2_x2Inst
toString
class BDup2_x2Inst extends BDupInst implements Dup2_x2Inst { private final Type mOp1Type; private final Type mOp2Type; private final Type mUnder1Type; private final Type mUnder2Type; public BDup2_x2Inst(Type aOp1Type, Type aOp2Type, Type aUnder1Type, Type aUnder2Type) { this.mOp1Type = Baf.getDescriptorTypeOf(aOp1Type); this.mOp2Type = Baf.getDescriptorTypeOf(aOp2Type); this.mUnder1Type = Baf.getDescriptorTypeOf(aUnder1Type); this.mUnder2Type = Baf.getDescriptorTypeOf(aUnder2Type); } @Override public Type getOp1Type() { return mOp1Type; } @Override public Type getOp2Type() { return mOp2Type; } @Override public Type getUnder1Type() { return mUnder1Type; } @Override public Type getUnder2Type() { return mUnder2Type; } @Override public List<Type> getOpTypes() { List<Type> res = new ArrayList<Type>(); res.add(mOp1Type); // 07-20-2006 Michael Batchelder // previously did not handle all types of dup2_x2 Now, will take null as mOp2Type, so don't add to overtypes if it is // null if (mOp2Type != null) { res.add(mOp2Type); } return res; } @Override public List<Type> getUnderTypes() { List<Type> res = new ArrayList<Type>(); res.add(mUnder1Type); // 07-20-2006 Michael Batchelder // previously did not handle all types of dup2_x2 Now, will take null as mUnder2Type, so don't add to undertypes if it is // null if (mUnder2Type != null) { res.add(mUnder2Type); } return res; } @Override final public String getName() { return "dup2_x2"; } @Override public void apply(Switch sw) { ((InstSwitch) sw).caseDup2_x2Inst(this); } @Override public String toString() {<FILL_FUNCTION_BODY>} }
// 07-20-2006 Michael Batchelder // previously did not handle all types of dup2_x2 Now, will take null as either mOp2Type or null as mUnder2Type to handle // ALL types of dup2_x2 // old code: // return "dup2_x2." + Baf.bafDescriptorOf(mOp1Type) + "." + Baf.bafDescriptorOf(mOp2Type) + "_" + // Baf.bafDescriptorOf(mUnder1Type) + "." + // Baf.bafDescriptorOf(mUnder2Type); String optypes = Baf.bafDescriptorOf(mOp1Type); if (mOp2Type != null) { optypes += "." + Baf.bafDescriptorOf(mOp2Type); } String undertypes = Baf.bafDescriptorOf(mUnder1Type); if (mUnder2Type != null) { optypes += "." + Baf.bafDescriptorOf(mUnder2Type); } return "dup2_x2." + optypes + "_" + undertypes; // END 07-20-2006 Michael Batchelder
666
316
982
<methods>public non-sealed void <init>() ,public void apply(soot.util.Switch) ,public int getInCount() ,public int getInMachineCount() ,public int getOutCount() ,public int getOutMachineCount() <variables>
soot-oss_soot
soot/src/main/java/soot/baf/internal/BDupInst.java
BDupInst
getInMachineCount
class BDupInst extends AbstractInst implements DupInst { @Override public int getInCount() { return getUnderTypes().size() + getOpTypes().size(); } @Override public int getInMachineCount() {<FILL_FUNCTION_BODY>} @Override public int getOutCount() { return getUnderTypes().size() + 2 * getOpTypes().size(); } @Override public int getOutMachineCount() { int count = 0; for (Type t : getUnderTypes()) { count += AbstractJasminClass.sizeOfType(t); } for (Type t : getOpTypes()) { count += 2 * AbstractJasminClass.sizeOfType(t); } return count; } @Override public void apply(Switch sw) { throw new RuntimeException(); } }
int count = 0; for (Type t : getUnderTypes()) { count += AbstractJasminClass.sizeOfType(t); } for (Type t : getOpTypes()) { count += AbstractJasminClass.sizeOfType(t); } return count;
230
77
307
<methods>public non-sealed void <init>() ,public boolean branches() ,public java.lang.Object clone() ,public boolean containsArrayRef() ,public boolean containsFieldRef() ,public boolean containsInvokeExpr() ,public boolean containsNewExpr() ,public boolean fallsThrough() ,public int getInCount() ,public int getInMachineCount() ,public abstract java.lang.String getName() ,public int getNetCount() ,public int getNetMachineCount() ,public int getOutCount() ,public int getOutMachineCount() ,public java.lang.String toString() ,public void toString(soot.UnitPrinter) <variables>
soot-oss_soot
soot/src/main/java/soot/baf/internal/BDynamicInvokeInst.java
BDynamicInvokeInst
toString
class BDynamicInvokeInst extends AbstractInvokeInst implements DynamicInvokeInst { protected final SootMethodRef bsmRef; private final List<Value> bsmArgs; protected int tag; public BDynamicInvokeInst(SootMethodRef bsmMethodRef, List<Value> bsmArgs, SootMethodRef methodRef, int tag) { super.methodRef = methodRef; this.bsmRef = bsmMethodRef; this.bsmArgs = bsmArgs; this.tag = tag; } @Override public Object clone() { return new BDynamicInvokeInst(bsmRef, bsmArgs, methodRef, tag); } @Override public int getInCount() { return methodRef.getParameterTypes().size(); } @Override public int getOutCount() { return (methodRef.getReturnType() instanceof VoidType) ? 0 : 1; } @Override public SootMethodRef getBootstrapMethodRef() { return bsmRef; } @Override public List<Value> getBootstrapArgs() { return bsmArgs; } @Override public String getName() { return "dynamicinvoke"; } @Override public void apply(Switch sw) { ((InstSwitch) sw).caseDynamicInvokeInst(this); } @Override public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append(Jimple.DYNAMICINVOKE + " \""); buffer.append(methodRef.getName()); // quoted method name (can be any UTF8 string) buffer.append("\" <"); buffer.append( SootMethod.getSubSignature(""/* no method name here */, methodRef.getParameterTypes(), methodRef.getReturnType())); buffer.append('>'); buffer.append(bsmRef.getSignature()); buffer.append('('); for (Iterator<Value> it = bsmArgs.iterator(); it.hasNext();) { Value v = it.next(); buffer.append(v.toString()); if (it.hasNext()) { buffer.append(", "); } } buffer.append(')'); return buffer.toString(); } @Override public void toString(UnitPrinter up) {<FILL_FUNCTION_BODY>} @Override public int getHandleTag() { return tag; } }
up.literal(Jimple.DYNAMICINVOKE + " \""); up.literal(methodRef.getName()); up.literal("\" <"); up.literal( SootMethod.getSubSignature(""/* no method name here */, methodRef.getParameterTypes(), methodRef.getReturnType())); up.literal("> "); up.methodRef(bsmRef); up.literal("("); for (Iterator<Value> it = bsmArgs.iterator(); it.hasNext();) { Value v = it.next(); v.toString(up); if (it.hasNext()) { up.literal(", "); } } up.literal(")");
641
191
832
<methods>public non-sealed void <init>() ,public boolean containsInvokeExpr() ,public int getInCount() ,public int getInMachineCount() ,public soot.SootMethod getMethod() ,public soot.SootMethodRef getMethodRef() ,public abstract java.lang.String getName() ,public int getOutCount() ,public int getOutMachineCount() ,public soot.Type getType() ,public java.lang.String toString() <variables>soot.SootMethodRef methodRef
soot-oss_soot
soot/src/main/java/soot/baf/internal/BIdentityInst.java
BIdentityInst
getUseBoxes
class BIdentityInst extends AbstractInst implements IdentityInst { ValueBox leftBox; ValueBox rightBox; List<ValueBox> defBoxes; protected BIdentityInst(ValueBox localBox, ValueBox identityValueBox) { this.leftBox = localBox; this.rightBox = identityValueBox; this.defBoxes = Collections.singletonList(localBox); } public BIdentityInst(Value local, Value identityValue) { this(Baf.v().newLocalBox(local), Baf.v().newIdentityRefBox(identityValue)); } @Override public Object clone() { return new BIdentityInst(getLeftOp(), getRightOp()); } @Override public int getInCount() { return 0; } @Override public int getInMachineCount() { return 0; } @Override public int getOutCount() { return 0; } @Override public int getOutMachineCount() { return 0; } @Override public Value getLeftOp() { return leftBox.getValue(); } @Override public Value getRightOp() { return rightBox.getValue(); } @Override public ValueBox getLeftOpBox() { return leftBox; } @Override public ValueBox getRightOpBox() { return rightBox; } @Override public List<ValueBox> getDefBoxes() { return defBoxes; } @Override public List<ValueBox> getUseBoxes() {<FILL_FUNCTION_BODY>} @Override public String toString() { return leftBox.getValue().toString() + " := " + rightBox.getValue().toString(); } @Override public void toString(UnitPrinter up) { leftBox.toString(up); up.literal(" := "); rightBox.toString(up); } @Override final public String getName() { return ":="; } @Override public void setLeftOp(Value local) { leftBox.setValue(local); } @Override public void setRightOp(Value identityRef) { rightBox.setValue(identityRef); } @Override public void apply(Switch sw) { ((InstSwitch) sw).caseIdentityInst(this); } }
List<ValueBox> list = new ArrayList<ValueBox>(); list.addAll(rightBox.getValue().getUseBoxes()); list.add(rightBox); list.addAll(leftBox.getValue().getUseBoxes()); return list;
641
69
710
<methods>public non-sealed void <init>() ,public boolean branches() ,public java.lang.Object clone() ,public boolean containsArrayRef() ,public boolean containsFieldRef() ,public boolean containsInvokeExpr() ,public boolean containsNewExpr() ,public boolean fallsThrough() ,public int getInCount() ,public int getInMachineCount() ,public abstract java.lang.String getName() ,public int getNetCount() ,public int getNetMachineCount() ,public int getOutCount() ,public int getOutMachineCount() ,public java.lang.String toString() ,public void toString(soot.UnitPrinter) <variables>
soot-oss_soot
soot/src/main/java/soot/baf/internal/BIncInst.java
BIncInst
toString
class BIncInst extends AbstractInst implements IncInst { final ValueBox localBox; final ValueBox defLocalBox; final List<ValueBox> useBoxes; final List<ValueBox> mDefBoxes; Constant mConstant; public BIncInst(Local local, Constant constant) { this.mConstant = constant; this.localBox = new BafLocalBox(local); this.useBoxes = Collections.singletonList(localBox); this.defLocalBox = new BafLocalBox(local); this.mDefBoxes = Collections.singletonList(defLocalBox); } @Override public Object clone() { return new BIncInst(getLocal(), getConstant()); } @Override public int getInCount() { return 0; } @Override public int getInMachineCount() { return 0; } @Override public int getOutCount() { return 0; } @Override public int getOutMachineCount() { return 0; } @Override public Constant getConstant() { return mConstant; } @Override public void setConstant(Constant aConstant) { this.mConstant = aConstant; } @Override final public String getName() { return "inc.i"; } @Override final String getParameters() { return " " + localBox.getValue().toString(); } @Override protected void getParameters(UnitPrinter up) { up.literal(" "); localBox.toString(up); } @Override public void apply(Switch sw) { ((InstSwitch) sw).caseIncInst(this); } @Override public void setLocal(Local l) { localBox.setValue(l); } @Override public Local getLocal() { return (Local) localBox.getValue(); } @Override public List<ValueBox> getUseBoxes() { return useBoxes; } @Override public List<ValueBox> getDefBoxes() { return mDefBoxes; } @Override public String toString() {<FILL_FUNCTION_BODY>} @Override public void toString(UnitPrinter up) { up.literal("inc.i "); localBox.toString(up); up.literal(" "); up.constant(mConstant); } }
return "inc.i " + getLocal() + " " + getConstant();
662
22
684
<methods>public non-sealed void <init>() ,public boolean branches() ,public java.lang.Object clone() ,public boolean containsArrayRef() ,public boolean containsFieldRef() ,public boolean containsInvokeExpr() ,public boolean containsNewExpr() ,public boolean fallsThrough() ,public int getInCount() ,public int getInMachineCount() ,public abstract java.lang.String getName() ,public int getNetCount() ,public int getNetMachineCount() ,public int getOutCount() ,public int getOutMachineCount() ,public java.lang.String toString() ,public void toString(soot.UnitPrinter) <variables>
soot-oss_soot
soot/src/main/java/soot/baf/internal/BafLocal.java
BafLocal
clone
class BafLocal implements Local { String name; Type type; int fixedHashCode; boolean isHashCodeChosen; private Local originalLocal; private int number = 0; public BafLocal(String name, Type t) { this.name = name; this.type = t; } @Override public Object clone() {<FILL_FUNCTION_BODY>} /* JimpleLocals are *NOT* equivalent to Baf Locals! */ @Override public boolean equivTo(Object o) { return this.equals(o); } /** Returns a hash code for this object, consistent with structural equality. */ @Override public int equivHashCode() { return name.hashCode() * 101 + type.hashCode() * 17; } public Local getOriginalLocal() { return this.originalLocal; } public void setOriginalLocal(Local l) { this.originalLocal = l; } @Override public String getName() { return this.name; } @Override public void setName(String name) { this.name = name; } @Override public Type getType() { return this.type; } @Override public void setType(Type t) { this.type = t; } @Override public String toString() { return getName(); } @Override public void toString(UnitPrinter up) { up.local(this); } @Override public List<ValueBox> getUseBoxes() { return Collections.emptyList(); } @Override public void apply(Switch s) { throw new RuntimeException("invalid case switch"); } @Override public final int getNumber() { return number; } @Override public final void setNumber(int number) { this.number = number; } @Override public boolean isStackLocal() { return true; } }
BafLocal baf = new BafLocal(name, type); baf.originalLocal = this.originalLocal; return baf;
546
39
585
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/baf/toolkits/base/ExamplePeephole.java
ExamplePeephole
apply
class ExamplePeephole implements Peephole { @Override public boolean apply(Body b) {<FILL_FUNCTION_BODY>} }
boolean changed = false; for (Iterator<Unit> it = b.getUnits().iterator(); it.hasNext();) { Unit u = it.next(); if (u instanceof InstanceCastInst) { it.remove(); changed = true; } } return changed;
40
79
119
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/baf/toolkits/base/PeepholeOptimizer.java
PeepholeOptimizer
internalTransform
class PeepholeOptimizer extends BodyTransformer { private static final Logger logger = LoggerFactory.getLogger(PeepholeOptimizer.class); public PeepholeOptimizer(Singletons.Global g) { } public static PeepholeOptimizer v() { return G.v().soot_baf_toolkits_base_PeepholeOptimizer(); } private final String packageName = "soot.baf.toolkits.base"; private static boolean peepholesLoaded = false; private static final Object loaderLock = new Object(); private final Map<String, Class<?>> peepholeMap = new HashMap<String, Class<?>>(); /* This is the public interface to PeepholeOptimizer */ /** * The method that drives the optimizations. */ @Override protected void internalTransform(Body body, String phaseName, Map<String, String> options) {<FILL_FUNCTION_BODY>} }
if (!peepholesLoaded) { synchronized (loaderLock) { if (!peepholesLoaded) { peepholesLoaded = true; InputStream peepholeListingStream = null; peepholeListingStream = PeepholeOptimizer.class.getResourceAsStream("/peephole.dat"); if (peepholeListingStream == null) { logger.warn("Could not find peephole.dat in the classpath"); return; } BufferedReader reader = new BufferedReader(new InputStreamReader(peepholeListingStream)); String line = null; List<String> peepholes = new LinkedList<String>(); try { line = reader.readLine(); while (line != null) { if (line.length() > 0) { if (!(line.charAt(0) == '#')) { peepholes.add(line); } } line = reader.readLine(); } } catch (IOException e) { throw new RuntimeException( "IO error occured while reading file: " + line + System.getProperty("line.separator") + e); } try { reader.close(); peepholeListingStream.close(); } catch (IOException e) { logger.debug(e.getMessage(), e); } for (String peepholeName : peepholes) { Class<?> peepholeClass; if ((peepholeClass = peepholeMap.get(peepholeName)) == null) { try { peepholeClass = Class.forName(packageName + '.' + peepholeName); } catch (ClassNotFoundException e) { throw new RuntimeException(e.toString()); } peepholeMap.put(peepholeName, peepholeClass); } } } } } boolean changed = true; while (changed) { changed = false; for (String peepholeName : peepholeMap.keySet()) { boolean peepholeWorked = true; while (peepholeWorked) { peepholeWorked = false; Peephole p = null; try { p = (Peephole) peepholeMap.get(peepholeName).newInstance(); } catch (IllegalAccessException e) { throw new RuntimeException(e.toString()); } catch (InstantiationException e) { throw new RuntimeException(e.toString()); } if (p.apply(body)) { peepholeWorked = true; changed = true; } } } }
255
693
948
<methods>public non-sealed void <init>() ,public final void transform(soot.Body, java.lang.String, Map<java.lang.String,java.lang.String>) ,public final void transform(soot.Body, java.lang.String) ,public final void transform(soot.Body) <variables>private static final Map<java.lang.String,java.lang.String> enabledOnlyMap
soot-oss_soot
soot/src/main/java/soot/baf/toolkits/base/StoreChainOptimizer.java
StoreChainOptimizer
internalTransform
class StoreChainOptimizer extends BodyTransformer { public StoreChainOptimizer(Singletons.Global g) { } public static StoreChainOptimizer v() { return G.v().soot_baf_toolkits_base_StoreChainOptimizer(); } @Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) {<FILL_FUNCTION_BODY>} }
// We keep track of all the stored values Map<Local, Pair<Unit, Unit>> stores = new HashMap<Local, Pair<Unit, Unit>>(); Set<Unit> toRemove = new HashSet<Unit>(); Unit lastPush = null; for (Unit u : b.getUnits()) { // If we can jump here from somewhere, do not modify this code if (!u.getBoxesPointingToThis().isEmpty()) { stores.clear(); lastPush = null; } else if (u instanceof PushInst) { // Emulate pushing stuff on the stack lastPush = u; } else if (u instanceof StoreInst && lastPush != null) { StoreInst si = (StoreInst) u; Pair<Unit, Unit> pushStorePair = stores.get(si.getLocal()); if (pushStorePair != null) { // We can remove the push and the store toRemove.add(pushStorePair.getO1()); toRemove.add(pushStorePair.getO2()); } stores.put(si.getLocal(), new Pair<Unit, Unit>(lastPush, u)); } else { // We're outside of the trivial initialization chain stores.clear(); lastPush = null; } } b.getUnits().removeAll(toRemove);
116
349
465
<methods>public non-sealed void <init>() ,public final void transform(soot.Body, java.lang.String, Map<java.lang.String,java.lang.String>) ,public final void transform(soot.Body, java.lang.String) ,public final void transform(soot.Body) <variables>private static final Map<java.lang.String,java.lang.String> enabledOnlyMap
soot-oss_soot
soot/src/main/java/soot/dava/DavaStaticBlockCleaner.java
DavaStaticBlockCleaner
staticBlockInlining
class DavaStaticBlockCleaner { SootClass sootClass; public DavaStaticBlockCleaner(Singletons.Global g) { } public static DavaStaticBlockCleaner v() { return G.v().soot_dava_DavaStaticBlockCleaner(); } // invoked by the PackManager public void staticBlockInlining(SootClass sootClass) {<FILL_FUNCTION_BODY>} /* * Method called with a sootMethod to decide whether this method should be inlined or not returns null if it shouldnt be * inlined * * A method can be inlined if it belongs to the same class and also if its static....(why???) */ public ASTMethodNode inline(SootMethod maybeInline) { // check if this method should be inlined if (sootClass != null) { // 1, method should belong to the same class as the clinit method if (sootClass.declaresMethod(maybeInline.getSubSignature())) { // System.out.println("The method invoked is from the same class"); // 2, method should be static if (Modifier.isStatic(maybeInline.getModifiers())) { // decided to inline // send the ASTMethod node of the TO BE INLINED METHOD // retireve the active body if (!maybeInline.hasActiveBody()) { throw new RuntimeException("method " + maybeInline.getName() + " has no active body!"); } Body bod = maybeInline.getActiveBody(); Chain units = ((DavaBody) bod).getUnits(); if (units.size() != 1) { throw new RuntimeException("DavaBody AST doesn't have single root."); } ASTNode ASTtemp = (ASTNode) units.getFirst(); if (!(ASTtemp instanceof ASTMethodNode)) { throw new RuntimeException("Starting node of DavaBody AST is not an ASTMethodNode"); } // restricting to methods which do not have any variables declared ASTMethodNode toReturn = (ASTMethodNode) ASTtemp; ASTStatementSequenceNode declarations = toReturn.getDeclarations(); if (declarations.getStatements().size() == 0) { // inline only if there are no declarations in the method inlined // System.out.println("No declarations in the method. we can inline this method"); return toReturn; } } } } return null;// meaning dont inline } }
this.sootClass = sootClass; // retrieve the clinit method if any for sootClass // the clinit method gets converted into the static block which could initialize the final variable if (!sootClass.declaresMethod("void <clinit>()")) { // System.out.println("no clinit"); return; } SootMethod clinit = sootClass.getMethod("void <clinit>()"); // System.out.println(clinit); // retireve the active body if (!clinit.hasActiveBody()) { throw new RuntimeException("method " + clinit.getName() + " has no active body!"); } Body clinitBody = clinit.getActiveBody(); Chain units = ((DavaBody) clinitBody).getUnits(); if (units.size() != 1) { throw new RuntimeException("DavaBody AST doesn't have single root."); } ASTNode AST = (ASTNode) units.getFirst(); if (!(AST instanceof ASTMethodNode)) { throw new RuntimeException("Starting node of DavaBody AST is not an ASTMethodNode"); } // running methodCallFinder on the Clinit method AST.apply(new MethodCallFinder(this));
658
328
986
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/DecompilationException.java
DecompilationException
report
class DecompilationException extends RuntimeException { private static final Logger logger = LoggerFactory.getLogger(DecompilationException.class); public DecompilationException() { System.out.println("DECOMPILATION INCOMPLETE:"); // printStackTrace(); } public DecompilationException(String message) { super("DECOMPILATION INCOMPLETE" + message); // printStackTrace(); } public void report() {<FILL_FUNCTION_BODY>} }
System.out.println("\n\nPlease report this exception to nomair.naeem@mail.mcgill.ca"); System.out.println("Please include the soot version, sample code and this output.\n\n");
132
59
191
<methods>public void <init>() ,public void <init>(java.lang.String) ,public void <init>(java.lang.Throwable) ,public void <init>(java.lang.String, java.lang.Throwable) <variables>static final long serialVersionUID
soot-oss_soot
soot/src/main/java/soot/dava/StaticDefinitionFinder.java
StaticDefinitionFinder
inDefinitionStmt
class StaticDefinitionFinder extends DepthFirstAdapter { SootMethod method; boolean finalFieldDefined; public StaticDefinitionFinder(SootMethod method) { this.method = method; finalFieldDefined = false; } public StaticDefinitionFinder(boolean verbose, SootMethod method) { super(verbose); this.method = method; finalFieldDefined = false; } public void inDefinitionStmt(DefinitionStmt s) {<FILL_FUNCTION_BODY>} public boolean anyFinalFieldDefined() { return finalFieldDefined; } }
Value leftOp = s.getLeftOp(); if (leftOp instanceof FieldRef) { // System.out.println("leftOp is a fieldRef:"+s); SootField field = ((FieldRef) leftOp).getField(); // check if this is a final field if (field.isFinal()) { // System.out.println("the field is a final variable"); finalFieldDefined = true; } }
166
114
280
<methods>public void <init>() ,public void <init>(boolean) ,public void caseASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void caseASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void caseASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void caseASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void caseASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void caseASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void caseASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void caseASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void caseASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void caseASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void caseASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void caseASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void caseASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void caseASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void caseASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void caseASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void caseArrayRef(soot.jimple.ArrayRef) ,public void caseBinopExpr(soot.jimple.BinopExpr) ,public void caseCastExpr(soot.jimple.CastExpr) ,public void caseDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void caseDefinitionStmt(soot.jimple.DefinitionStmt) ,public void caseExpr(soot.jimple.Expr) ,public void caseExprOrRefValueBox(soot.ValueBox) ,public void caseInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void caseInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void caseInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void caseInvokeExpr(soot.jimple.InvokeExpr) ,public void caseInvokeStmt(soot.jimple.InvokeStmt) ,public void caseNewArrayExpr(soot.jimple.NewArrayExpr) ,public void caseNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void caseRef(soot.jimple.Ref) ,public void caseReturnStmt(soot.jimple.ReturnStmt) ,public void caseStaticFieldRef(soot.jimple.StaticFieldRef) ,public void caseStmt(soot.jimple.Stmt) ,public void caseThrowStmt(soot.jimple.ThrowStmt) ,public void caseType(soot.Type) ,public void caseUnopExpr(soot.jimple.UnopExpr) ,public void caseValue(soot.Value) ,public void debug(java.lang.String, java.lang.String, java.lang.String) ,public void decideCaseExpr(soot.jimple.Expr) ,public void decideCaseExprOrRef(soot.Value) ,public void decideCaseRef(soot.jimple.Ref) ,public void inASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void inASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void inASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void inASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void inASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void inASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void inASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void inASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void inASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void inASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void inASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void inASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void inASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void inASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void inASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void inASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void inArrayRef(soot.jimple.ArrayRef) ,public void inBinopExpr(soot.jimple.BinopExpr) ,public void inCastExpr(soot.jimple.CastExpr) ,public void inDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void inDefinitionStmt(soot.jimple.DefinitionStmt) ,public void inExpr(soot.jimple.Expr) ,public void inExprOrRefValueBox(soot.ValueBox) ,public void inInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void inInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void inInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void inInvokeExpr(soot.jimple.InvokeExpr) ,public void inInvokeStmt(soot.jimple.InvokeStmt) ,public void inNewArrayExpr(soot.jimple.NewArrayExpr) ,public void inNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void inRef(soot.jimple.Ref) ,public void inReturnStmt(soot.jimple.ReturnStmt) ,public void inStaticFieldRef(soot.jimple.StaticFieldRef) ,public void inStmt(soot.jimple.Stmt) ,public void inThrowStmt(soot.jimple.ThrowStmt) ,public void inType(soot.Type) ,public void inUnopExpr(soot.jimple.UnopExpr) ,public void inValue(soot.Value) ,public void normalRetrieving(soot.dava.internal.AST.ASTNode) ,public void outASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void outASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void outASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void outASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void outASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void outASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void outASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void outASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void outASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void outASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void outASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void outASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void outASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void outASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void outASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void outASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void outArrayRef(soot.jimple.ArrayRef) ,public void outBinopExpr(soot.jimple.BinopExpr) ,public void outCastExpr(soot.jimple.CastExpr) ,public void outDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void outDefinitionStmt(soot.jimple.DefinitionStmt) ,public void outExpr(soot.jimple.Expr) ,public void outExprOrRefValueBox(soot.ValueBox) ,public void outInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void outInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void outInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void outInvokeExpr(soot.jimple.InvokeExpr) ,public void outInvokeStmt(soot.jimple.InvokeStmt) ,public void outNewArrayExpr(soot.jimple.NewArrayExpr) ,public void outNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void outRef(soot.jimple.Ref) ,public void outReturnStmt(soot.jimple.ReturnStmt) ,public void outStaticFieldRef(soot.jimple.StaticFieldRef) ,public void outStmt(soot.jimple.Stmt) ,public void outThrowStmt(soot.jimple.ThrowStmt) ,public void outType(soot.Type) ,public void outUnopExpr(soot.jimple.UnopExpr) ,public void outValue(soot.Value) <variables>public boolean DEBUG,boolean verbose
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTAggregatedCondition.java
ASTAggregatedCondition
flip
class ASTAggregatedCondition extends ASTCondition { ASTCondition left; ASTCondition right; boolean not;// used to see if the condition has a not infront of it public ASTAggregatedCondition(ASTCondition left, ASTCondition right) { not = false;// by default condition does not have a not this.left = left; this.right = right; } public ASTCondition getLeftOp() { return left; } public ASTCondition getRightOp() { return right; } public void setLeftOp(ASTCondition left) { this.left = left; } public void setRightOp(ASTCondition right) { this.right = right; } public void flip() {<FILL_FUNCTION_BODY>} public boolean isNotted() { return not; } }
if (not) { not = false; } else { not = true; }
229
30
259
<methods>public non-sealed void <init>() ,public abstract void apply(soot.dava.toolkits.base.AST.analysis.Analysis) ,public abstract void flip() ,public abstract boolean isNotted() ,public abstract void toString(soot.UnitPrinter) <variables>
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTAndCondition.java
ASTAndCondition
toString
class ASTAndCondition extends ASTAggregatedCondition { public ASTAndCondition(ASTCondition left, ASTCondition right) { super(left, right); } public void apply(Analysis a) { a.caseASTAndCondition(this); } public String toString() { if (left instanceof ASTUnaryBinaryCondition) { if (right instanceof ASTUnaryBinaryCondition) { if (not) { return "!(" + left.toString() + " && " + right.toString() + ")"; } else { return left.toString() + " && " + right.toString(); } } else { // right is ASTAggregatedCondition if (not) { return "!(" + left.toString() + " && (" + right.toString() + " ))"; } else { return left.toString() + " && (" + right.toString() + " )"; } } } else { // left is ASTAggregatedCondition if (right instanceof ASTUnaryBinaryCondition) { if (not) { return "!(( " + left.toString() + ") && " + right.toString() + ")"; } else { return "( " + left.toString() + ") && " + right.toString(); } } else { // right is ASTAggregatedCondition also if (not) { return "!(( " + left.toString() + ") && (" + right.toString() + " ))"; } else { return "( " + left.toString() + ") && (" + right.toString() + " )"; } } } } public void toString(UnitPrinter up) {<FILL_FUNCTION_BODY>} }
if (up instanceof DavaUnitPrinter) { if (not) { // print ! ((DavaUnitPrinter) up).addNot(); // print left paren ((DavaUnitPrinter) up).addLeftParen(); } if (left instanceof ASTUnaryBinaryCondition) { if (right instanceof ASTUnaryBinaryCondition) { left.toString(up); ((DavaUnitPrinter) up).addAggregatedAnd(); right.toString(up); } else { // right is ASTAggregatedCondition left.toString(up); ((DavaUnitPrinter) up).addAggregatedAnd(); ((DavaUnitPrinter) up).addLeftParen(); right.toString(up); ((DavaUnitPrinter) up).addRightParen(); } } else { // left is ASTAggregatedCondition if (right instanceof ASTUnaryBinaryCondition) { ((DavaUnitPrinter) up).addLeftParen(); left.toString(up); ((DavaUnitPrinter) up).addRightParen(); ((DavaUnitPrinter) up).addAggregatedAnd(); right.toString(up); } else { // right is ASTAggregatedCondition also ((DavaUnitPrinter) up).addLeftParen(); left.toString(up); ((DavaUnitPrinter) up).addRightParen(); ((DavaUnitPrinter) up).addAggregatedAnd(); ((DavaUnitPrinter) up).addLeftParen(); right.toString(up); ((DavaUnitPrinter) up).addRightParen(); } } if (not) { // print right paren ((DavaUnitPrinter) up).addRightParen(); } } else { throw new RuntimeException(); }
438
478
916
<methods>public void <init>(soot.dava.internal.AST.ASTCondition, soot.dava.internal.AST.ASTCondition) ,public void flip() ,public soot.dava.internal.AST.ASTCondition getLeftOp() ,public soot.dava.internal.AST.ASTCondition getRightOp() ,public boolean isNotted() ,public void setLeftOp(soot.dava.internal.AST.ASTCondition) ,public void setRightOp(soot.dava.internal.AST.ASTCondition) <variables>soot.dava.internal.AST.ASTCondition left,boolean not,soot.dava.internal.AST.ASTCondition right
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTForLoopNode.java
ASTForLoopNode
toString
class ASTForLoopNode extends ASTControlFlowNode { private List<AugmentedStmt> init; // list of values // notice B is an ASTCondition and is stored in the parent private List<AugmentedStmt> update; // list of values private List<Object> body; public ASTForLoopNode(SETNodeLabel label, List<AugmentedStmt> init, ASTCondition condition, List<AugmentedStmt> update, List<Object> body) { super(label, condition); this.body = body; this.init = init; this.update = update; subBodies.add(body); } public List<AugmentedStmt> getInit() { return init; } public List<AugmentedStmt> getUpdate() { return update; } public void replaceBody(List<Object> body) { this.body = body; subBodies = new ArrayList<Object>(); subBodies.add(body); } public Object clone() { return new ASTForLoopNode(get_Label(), init, get_Condition(), update, body); } public void toString(UnitPrinter up) { label_toString(up); up.literal("for"); up.literal(" "); up.literal("("); Iterator<AugmentedStmt> it = init.iterator(); while (it.hasNext()) { AugmentedStmt as = it.next(); Unit u = as.get_Stmt(); u.toString(up); if (it.hasNext()) { up.literal(" , "); } } up.literal("; "); condition.toString(up); up.literal("; "); it = update.iterator(); while (it.hasNext()) { AugmentedStmt as = it.next(); Unit u = as.get_Stmt(); u.toString(up); if (it.hasNext()) { up.literal(" , "); } } up.literal(")"); up.newline(); up.literal("{"); up.newline(); up.incIndent(); body_toString(up, body); up.decIndent(); up.literal("}"); up.newline(); } public String toString() {<FILL_FUNCTION_BODY>} public void apply(Analysis a) { a.caseASTForLoopNode(this); } }
StringBuffer b = new StringBuffer(); b.append(label_toString()); b.append("for ("); Iterator<AugmentedStmt> it = init.iterator(); while (it.hasNext()) { b.append(it.next().get_Stmt().toString()); if (it.hasNext()) { b.append(" , "); } } b.append("; "); b.append(get_Condition().toString()); b.append("; "); it = update.iterator(); while (it.hasNext()) { b.append(it.next().get_Stmt().toString()); if (it.hasNext()) { b.append(" , "); } } b.append(")"); b.append(NEWLINE); b.append("{"); b.append(NEWLINE); b.append(body_toString(body)); b.append("}"); b.append(NEWLINE); return b.toString();
669
266
935
<methods>public void <init>(soot.dava.internal.SET.SETNodeLabel, soot.jimple.ConditionExpr) ,public void <init>(soot.dava.internal.SET.SETNodeLabel, soot.dava.internal.AST.ASTCondition) ,public soot.dava.internal.AST.ASTCondition get_Condition() ,public void perform_Analysis(soot.dava.toolkits.base.AST.ASTAnalysis) ,public void set_Condition(soot.dava.internal.AST.ASTCondition) <variables>soot.dava.internal.AST.ASTCondition condition
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTLabeledNode.java
ASTLabeledNode
label_toString
class ASTLabeledNode extends ASTNode { private SETNodeLabel label; public ASTLabeledNode(SETNodeLabel label) { super(); set_Label(label); } public SETNodeLabel get_Label() { return label; } public void set_Label(SETNodeLabel label) { this.label = label; } public void perform_Analysis(ASTAnalysis a) { perform_AnalysisOnSubBodies(a); } public void label_toString(UnitPrinter up) { if (label.toString() != null) { up.literal(label.toString()); up.literal(":"); up.newline(); } } public String label_toString() {<FILL_FUNCTION_BODY>} }
if (label.toString() == null) { return new String(); } else { StringBuffer b = new StringBuffer(); b.append(label.toString()); b.append(":"); b.append(ASTNode.NEWLINE); return b.toString(); }
211
78
289
<methods>public void <init>() ,public void apply(soot.dava.toolkits.base.AST.analysis.Analysis) ,public boolean branches() ,public boolean fallsThrough() ,public List<java.lang.Object> get_SubBodies() ,public abstract void perform_Analysis(soot.dava.toolkits.base.AST.ASTAnalysis) ,public abstract void toString(soot.UnitPrinter) <variables>public static final java.lang.String NEWLINE,public static final java.lang.String TAB,protected List<java.lang.Object> subBodies
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTNode.java
ASTNode
perform_AnalysisOnSubBodies
class ASTNode extends AbstractUnit { public static final String TAB = " ", NEWLINE = "\n"; protected List<Object> subBodies; public ASTNode() { subBodies = new ArrayList<Object>(); } public abstract void toString(UnitPrinter up); protected void body_toString(UnitPrinter up, List<Object> body) { Iterator<Object> it = body.iterator(); while (it.hasNext()) { ((ASTNode) it.next()).toString(up); if (it.hasNext()) { up.newline(); } } } protected String body_toString(List<Object> body) { StringBuffer b = new StringBuffer(); Iterator<Object> it = body.iterator(); while (it.hasNext()) { b.append(((ASTNode) it.next()).toString()); if (it.hasNext()) { b.append(NEWLINE); } } return b.toString(); } public List<Object> get_SubBodies() { return subBodies; } public abstract void perform_Analysis(ASTAnalysis a); protected void perform_AnalysisOnSubBodies(ASTAnalysis a) {<FILL_FUNCTION_BODY>} public boolean fallsThrough() { return false; } public boolean branches() { return false; } /* * Nomair A. Naeem, 7-FEB-05 Part of Visitor Design Implementation for AST See: soot.dava.toolkits.base.AST.analysis For * details */ public void apply(Analysis a) { throw new RuntimeException("Analysis invoked apply method on ASTNode"); } }
Iterator<Object> sbit = subBodies.iterator(); while (sbit.hasNext()) { Object subBody = sbit.next(); Iterator it = null; if (this instanceof ASTTryNode) { it = ((List) ((ASTTryNode.container) subBody).o).iterator(); } else { it = ((List) subBody).iterator(); } while (it.hasNext()) { ((ASTNode) it.next()).perform_Analysis(a); } } a.analyseASTNode(this);
457
149
606
<methods>public non-sealed void <init>() ,public void addBoxPointingToThis(soot.UnitBox) ,public void apply(soot.util.Switch) ,public void clearUnitBoxes() ,public abstract java.lang.Object clone() ,public List<soot.UnitBox> getBoxesPointingToThis() ,public List<soot.ValueBox> getDefBoxes() ,public List<soot.UnitBox> getUnitBoxes() ,public List<soot.ValueBox> getUseAndDefBoxes() ,public List<soot.ValueBox> getUseBoxes() ,public void redirectJumpsToThisTo(soot.Unit) ,public void removeBoxPointingToThis(soot.UnitBox) <variables>protected List<soot.UnitBox> boxesPointingToThis
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTOrCondition.java
ASTOrCondition
toString
class ASTOrCondition extends ASTAggregatedCondition { public ASTOrCondition(ASTCondition left, ASTCondition right) { super(left, right); } public void apply(Analysis a) { a.caseASTOrCondition(this); } public String toString() {<FILL_FUNCTION_BODY>} public void toString(UnitPrinter up) { if (up instanceof DavaUnitPrinter) { if (not) { // print ! ((DavaUnitPrinter) up).addNot(); // print LeftParen ((DavaUnitPrinter) up).addLeftParen(); } if (left instanceof ASTUnaryBinaryCondition) { if (right instanceof ASTUnaryBinaryCondition) { left.toString(up); ((DavaUnitPrinter) up).addAggregatedOr(); right.toString(up); } else { // right is ASTAggregatedCondition left.toString(up); ((DavaUnitPrinter) up).addAggregatedOr(); ((DavaUnitPrinter) up).addLeftParen(); right.toString(up); ((DavaUnitPrinter) up).addRightParen(); } } else { // left is ASTAggregatedCondition if (right instanceof ASTUnaryBinaryCondition) { ((DavaUnitPrinter) up).addLeftParen(); left.toString(up); ((DavaUnitPrinter) up).addRightParen(); ((DavaUnitPrinter) up).addAggregatedOr(); right.toString(up); } else { // right is ASTAggregatedCondition also ((DavaUnitPrinter) up).addLeftParen(); left.toString(up); ((DavaUnitPrinter) up).addRightParen(); ((DavaUnitPrinter) up).addAggregatedOr(); ((DavaUnitPrinter) up).addLeftParen(); right.toString(up); ((DavaUnitPrinter) up).addRightParen(); } } if (not) { ((DavaUnitPrinter) up).addRightParen(); } } else { throw new RuntimeException(); } } }
if (left instanceof ASTUnaryBinaryCondition) { if (right instanceof ASTUnaryBinaryCondition) { if (not) { return "!(" + left.toString() + " || " + right.toString() + ")"; } else { return left.toString() + " || " + right.toString(); } } else { // right is ASTAggregatedCondition if (not) { return "!(" + left.toString() + " || (" + right.toString() + " ))"; } else { return left.toString() + " || (" + right.toString() + " )"; } } } else { // left is ASTAggregatedCondition if (right instanceof ASTUnaryBinaryCondition) { if (not) { return "!(( " + left.toString() + ") || " + right.toString() + ")"; } else { return "( " + left.toString() + ") || " + right.toString(); } } else { // right is ASTAggregatedCondition also if (not) { return "!(( " + left.toString() + ") || (" + right.toString() + " ))"; } else { return "( " + left.toString() + ") || (" + right.toString() + " )"; } } }
574
332
906
<methods>public void <init>(soot.dava.internal.AST.ASTCondition, soot.dava.internal.AST.ASTCondition) ,public void flip() ,public soot.dava.internal.AST.ASTCondition getLeftOp() ,public soot.dava.internal.AST.ASTCondition getRightOp() ,public boolean isNotted() ,public void setLeftOp(soot.dava.internal.AST.ASTCondition) ,public void setRightOp(soot.dava.internal.AST.ASTCondition) <variables>soot.dava.internal.AST.ASTCondition left,boolean not,soot.dava.internal.AST.ASTCondition right
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTStatementSequenceNode.java
ASTStatementSequenceNode
perform_Analysis
class ASTStatementSequenceNode extends ASTNode { private List<AugmentedStmt> statementSequence; public ASTStatementSequenceNode(List<AugmentedStmt> statementSequence) { super(); this.statementSequence = statementSequence; } public Object clone() { return new ASTStatementSequenceNode(statementSequence); } public void perform_Analysis(ASTAnalysis a) {<FILL_FUNCTION_BODY>} public void toString(UnitPrinter up) { for (AugmentedStmt as : statementSequence) { // System.out.println("Stmt is:"+as.get_Stmt()); Unit u = as.get_Stmt(); up.startUnit(u); u.toString(up); up.literal(";"); up.endUnit(u); up.newline(); } } public String toString() { StringBuffer b = new StringBuffer(); for (AugmentedStmt as : statementSequence) { b.append(as.get_Stmt().toString()); b.append(";"); b.append(NEWLINE); } return b.toString(); } /* * Nomair A. Naeem, 7-FEB-05 Part of Visitor Design Implementation for AST See: soot.dava.toolkits.base.AST.analysis For * details */ public List<AugmentedStmt> getStatements() { return statementSequence; } public void apply(Analysis a) { a.caseASTStatementSequenceNode(this); } /* * Nomair A. Naeem added 3-MAY-05 */ public void setStatements(List<AugmentedStmt> statementSequence) { this.statementSequence = statementSequence; } }
if (a.getAnalysisDepth() > ASTAnalysis.ANALYSE_AST) { for (AugmentedStmt as : statementSequence) { ASTWalker.v().walk_stmt(a, as.get_Stmt()); } } if (a instanceof TryContentsFinder) { TryContentsFinder.v().add_ExceptionSet(this, TryContentsFinder.v().remove_CurExceptionSet()); }
476
115
591
<methods>public void <init>() ,public void apply(soot.dava.toolkits.base.AST.analysis.Analysis) ,public boolean branches() ,public boolean fallsThrough() ,public List<java.lang.Object> get_SubBodies() ,public abstract void perform_Analysis(soot.dava.toolkits.base.AST.ASTAnalysis) ,public abstract void toString(soot.UnitPrinter) <variables>public static final java.lang.String NEWLINE,public static final java.lang.String TAB,protected List<java.lang.Object> subBodies
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTSwitchNode.java
ASTSwitchNode
toString
class ASTSwitchNode extends ASTLabeledNode { private ValueBox keyBox; private List<Object> indexList; private Map<Object, List<Object>> index2BodyList; public ASTSwitchNode(SETNodeLabel label, Value key, List<Object> indexList, Map<Object, List<Object>> index2BodyList) { super(label); this.keyBox = Jimple.v().newRValueBox(key); this.indexList = indexList; this.index2BodyList = index2BodyList; Iterator<Object> it = indexList.iterator(); while (it.hasNext()) { List body = index2BodyList.get(it.next()); if (body != null) { subBodies.add(body); } } } /* * Nomair A. Naeem 22-FEB-2005 Added for ASTCleaner */ public List<Object> getIndexList() { return indexList; } public Map<Object, List<Object>> getIndex2BodyList() { return index2BodyList; } public void replaceIndex2BodyList(Map<Object, List<Object>> index2BodyList) { this.index2BodyList = index2BodyList; subBodies = new ArrayList<Object>(); Iterator<Object> it = indexList.iterator(); while (it.hasNext()) { List body = index2BodyList.get(it.next()); if (body != null) { subBodies.add(body); } } } public ValueBox getKeyBox() { return keyBox; } public Value get_Key() { return keyBox.getValue(); } public void set_Key(Value key) { this.keyBox = Jimple.v().newRValueBox(key); } public Object clone() { return new ASTSwitchNode(get_Label(), get_Key(), indexList, index2BodyList); } public void perform_Analysis(ASTAnalysis a) { ASTWalker.v().walk_value(a, get_Key()); if (a instanceof TryContentsFinder) { TryContentsFinder.v().add_ExceptionSet(this, TryContentsFinder.v().remove_CurExceptionSet()); } perform_AnalysisOnSubBodies(a); } public void toString(UnitPrinter up) {<FILL_FUNCTION_BODY>} public String toString() { StringBuffer b = new StringBuffer(); b.append(label_toString()); b.append("switch ("); b.append(get_Key()); b.append(")"); b.append(NEWLINE); b.append("{"); b.append(NEWLINE); Iterator<Object> it = indexList.iterator(); while (it.hasNext()) { Object index = it.next(); b.append(TAB); if (index instanceof String) { b.append("default"); } else { b.append("case "); b.append(((Integer) index).toString()); } b.append(":"); b.append(NEWLINE); List<Object> subBody = index2BodyList.get(index); if (subBody != null) { b.append(body_toString(subBody)); if (it.hasNext()) { b.append(NEWLINE); } } } b.append("}"); b.append(NEWLINE); return b.toString(); } /* * Nomair A. Naeem, 7-FEB-05 Part of Visitor Design Implementation for AST See: soot.dava.toolkits.base.AST.analysis For * details */ public void apply(Analysis a) { a.caseASTSwitchNode(this); } }
label_toString(up); up.literal("switch"); up.literal(" "); up.literal("("); keyBox.toString(up); up.literal(")"); up.newline(); up.literal("{"); up.newline(); Iterator<Object> it = indexList.iterator(); while (it.hasNext()) { Object index = it.next(); up.incIndent(); if (index instanceof String) { up.literal("default"); } else { up.literal("case"); up.literal(" "); up.literal(index.toString()); } up.literal(":"); up.newline(); List<Object> subBody = index2BodyList.get(index); if (subBody != null) { up.incIndent(); body_toString(up, subBody); if (it.hasNext()) { up.newline(); } up.decIndent(); } up.decIndent(); } up.literal("}"); up.newline();
1,026
301
1,327
<methods>public void <init>(soot.dava.internal.SET.SETNodeLabel) ,public soot.dava.internal.SET.SETNodeLabel get_Label() ,public void label_toString(soot.UnitPrinter) ,public java.lang.String label_toString() ,public void perform_Analysis(soot.dava.toolkits.base.AST.ASTAnalysis) ,public void set_Label(soot.dava.internal.SET.SETNodeLabel) <variables>private soot.dava.internal.SET.SETNodeLabel label
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTTryNode.java
container
replaceTryBody
class container { public Object o; public container(Object o) { this.o = o; } public void replaceBody(Object newBody) { this.o = newBody; } } public ASTTryNode(SETNodeLabel label, List<Object> tryBody, List<Object> catchList, Map<Object, Object> exceptionMap, Map<Object, Object> paramMap) { super(label); this.tryBody = tryBody; tryBodyContainer = new container(tryBody); this.catchList = new ArrayList<Object>(); Iterator<Object> cit = catchList.iterator(); while (cit.hasNext()) { this.catchList.add(new container(cit.next())); } this.exceptionMap = new HashMap<Object, Object>(); cit = this.catchList.iterator(); while (cit.hasNext()) { container c = (container) cit.next(); this.exceptionMap.put(c, exceptionMap.get(c.o)); } this.paramMap = new HashMap<Object, Object>(); cit = this.catchList.iterator(); while (cit.hasNext()) { container c = (container) cit.next(); this.paramMap.put(c, paramMap.get(c.o)); } subBodies.add(tryBodyContainer); cit = this.catchList.iterator(); while (cit.hasNext()) { subBodies.add(cit.next()); } } /* * Nomair A Naeem 21-FEB-2005 used to support UselessLabeledBlockRemover */ public void replaceTryBody(List<Object> tryBody) {<FILL_FUNCTION_BODY>
this.tryBody = tryBody; tryBodyContainer = new container(tryBody); List<Object> oldSubBodies = subBodies; subBodies = new ArrayList<Object>(); subBodies.add(tryBodyContainer); Iterator<Object> oldIt = oldSubBodies.iterator(); // discard the first since that was the old tryBodyContainer oldIt.next(); while (oldIt.hasNext()) { subBodies.add(oldIt.next()); }
457
135
592
<methods>public void <init>(soot.dava.internal.SET.SETNodeLabel) ,public soot.dava.internal.SET.SETNodeLabel get_Label() ,public void label_toString(soot.UnitPrinter) ,public java.lang.String label_toString() ,public void perform_Analysis(soot.dava.toolkits.base.AST.ASTAnalysis) ,public void set_Label(soot.dava.internal.SET.SETNodeLabel) <variables>private soot.dava.internal.SET.SETNodeLabel label
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTUnaryCondition.java
ASTUnaryCondition
flip
class ASTUnaryCondition extends ASTUnaryBinaryCondition { Value value; public ASTUnaryCondition(Value value) { this.value = value; } public void apply(Analysis a) { a.caseASTUnaryCondition(this); } public Value getValue() { return value; } public void setValue(Value value) { this.value = value; } public String toString() { return value.toString(); } public void toString(UnitPrinter up) { value.toString(up); } public void flip() {<FILL_FUNCTION_BODY>} public boolean isNotted() { return (value instanceof DNotExpr); } }
/* * Since its a unarycondition we know this is a flag See if its a DNotExpr if yes set this.value to the op inside * DNotExpr If it is NOT a DNotExpr make one */ if (value instanceof DNotExpr) { this.value = ((DNotExpr) value).getOp(); } else { this.value = new DNotExpr(value); }
200
105
305
<methods>public non-sealed void <init>() <variables>
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTUnconditionalLoopNode.java
ASTUnconditionalLoopNode
toString
class ASTUnconditionalLoopNode extends ASTLabeledNode { private List<Object> body; public ASTUnconditionalLoopNode(SETNodeLabel label, List<Object> body) { super(label); this.body = body; subBodies.add(body); } /* * Nomair A Naeem 20-FEB-2005 Added for UselessLabeledBlockRemover */ public void replaceBody(List<Object> body) { this.body = body; subBodies = new ArrayList<Object>(); subBodies.add(body); } public Object clone() { return new ASTUnconditionalLoopNode(get_Label(), body); } public void toString(UnitPrinter up) {<FILL_FUNCTION_BODY>} public String toString() { StringBuffer b = new StringBuffer(); b.append(label_toString()); b.append("while (true)"); b.append(NEWLINE); b.append("{"); b.append(NEWLINE); b.append(body_toString(body)); b.append("}"); b.append(NEWLINE); return b.toString(); } /* * Nomair A. Naeem, 7-FEB-05 Part of Visitor Design Implementation for AST See: soot.dava.toolkits.base.AST.analysis For * details */ public void apply(Analysis a) { a.caseASTUnconditionalLoopNode(this); } }
label_toString(up); up.literal("while"); up.literal(" "); up.literal("("); up.literal("true"); up.literal(")"); up.newline(); up.literal("{"); up.newline(); up.incIndent(); body_toString(up, body); up.decIndent(); up.literal("}"); up.newline();
414
120
534
<methods>public void <init>(soot.dava.internal.SET.SETNodeLabel) ,public soot.dava.internal.SET.SETNodeLabel get_Label() ,public void label_toString(soot.UnitPrinter) ,public java.lang.String label_toString() ,public void perform_Analysis(soot.dava.toolkits.base.AST.ASTAnalysis) ,public void set_Label(soot.dava.internal.SET.SETNodeLabel) <variables>private soot.dava.internal.SET.SETNodeLabel label
soot-oss_soot
soot/src/main/java/soot/dava/internal/AST/ASTWhileNode.java
ASTWhileNode
toString
class ASTWhileNode extends ASTControlFlowNode { private List<Object> body; public ASTWhileNode(SETNodeLabel label, ConditionExpr ce, List<Object> body) { super(label, ce); this.body = body; subBodies.add(body); } /* * Nomair A. Naeem 17-FEB-05 Needed because of change of grammar of condition being stored as a ASTCondition rather than * the ConditionExpr which was the case before */ public ASTWhileNode(SETNodeLabel label, ASTCondition ce, List<Object> body) { super(label, ce); this.body = body; subBodies.add(body); } /* * Nomair A Naeem 20-FEB-2005 Added for UselessLabeledBlockRemover */ public void replaceBody(List<Object> body) { this.body = body; subBodies = new ArrayList<Object>(); subBodies.add(body); } public Object clone() { return new ASTWhileNode(get_Label(), get_Condition(), body); } public void toString(UnitPrinter up) { label_toString(up); up.literal("while"); up.literal(" "); up.literal("("); condition.toString(up); up.literal(")"); up.newline(); up.literal("{"); up.newline(); up.incIndent(); body_toString(up, body); up.decIndent(); up.literal("}"); up.newline(); } public String toString() {<FILL_FUNCTION_BODY>} /* * Nomair A. Naeem, 7-FEB-05 Part of Visitor Design Implementation for AST See: soot.dava.toolkits.base.AST.analysis For * details */ public void apply(Analysis a) { a.caseASTWhileNode(this); } }
StringBuffer b = new StringBuffer(); b.append(label_toString()); b.append("while ("); b.append(get_Condition().toString()); b.append(")"); b.append(NEWLINE); b.append("{"); b.append(NEWLINE); b.append(body_toString(body)); b.append("}"); b.append(NEWLINE); return b.toString();
540
120
660
<methods>public void <init>(soot.dava.internal.SET.SETNodeLabel, soot.jimple.ConditionExpr) ,public void <init>(soot.dava.internal.SET.SETNodeLabel, soot.dava.internal.AST.ASTCondition) ,public soot.dava.internal.AST.ASTCondition get_Condition() ,public void perform_Analysis(soot.dava.toolkits.base.AST.ASTAnalysis) ,public void set_Condition(soot.dava.internal.AST.ASTCondition) <variables>soot.dava.internal.AST.ASTCondition condition
soot-oss_soot
soot/src/main/java/soot/dava/internal/SET/SETBasicBlock.java
SETBasicBlock
compareTo
class SETBasicBlock implements Comparable { private static final Logger logger = LoggerFactory.getLogger(SETBasicBlock.class); private SETNode entryNode, exitNode; private final IterableSet predecessors, successors, body; private int priority; public SETBasicBlock() { predecessors = new IterableSet(); successors = new IterableSet(); body = new IterableSet(); entryNode = exitNode = null; priority = -1; } public int compareTo(Object o) {<FILL_FUNCTION_BODY>} private int get_Priority() { if (priority == -1) { priority = 0; if (predecessors.size() == 1) { Iterator sit = successors.iterator(); while (sit.hasNext()) { int sucScore = ((SETBasicBlock) sit.next()).get_Priority(); if (sucScore > priority) { priority = sucScore; } } priority++; } } return priority; } /* * adds must be done in order such that the entry node is done first and the exit is done last. */ public void add(SETNode sn) { if (body.isEmpty()) { entryNode = sn; } body.add(sn); G.v().SETBasicBlock_binding.put(sn, this); exitNode = sn; } public SETNode get_EntryNode() { return entryNode; } public SETNode get_ExitNode() { return exitNode; } public IterableSet get_Predecessors() { return predecessors; } public IterableSet get_Successors() { return successors; } public IterableSet get_Body() { return body; } public static SETBasicBlock get_SETBasicBlock(SETNode o) { return G.v().SETBasicBlock_binding.get(o); } public void printSig() { Iterator it = body.iterator(); while (it.hasNext()) { ((SETNode) it.next()).dump(); } } public void dump() { printSig(); logger.debug("" + "=== preds ==="); Iterator it = predecessors.iterator(); while (it.hasNext()) { ((SETBasicBlock) it.next()).printSig(); } logger.debug("" + "=== succs ==="); it = successors.iterator(); while (it.hasNext()) { ((SETBasicBlock) it.next()).printSig(); } } }
if (o == this) { return 0; } SETBasicBlock other = (SETBasicBlock) o; int difference = other.get_Priority() - get_Priority(); // major sorting order ... _descending_ if (difference == 0) { difference = 1; // but it doesn't matter. } return difference;
697
96
793
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/internal/SET/SETIfElseNode.java
SETIfElseNode
emit_AST
class SETIfElseNode extends SETDagNode { private IterableSet ifBody, elseBody; public SETIfElseNode(AugmentedStmt characterizingStmt, IterableSet body, IterableSet ifBody, IterableSet elseBody) { super(characterizingStmt, body); this.ifBody = ifBody; this.elseBody = elseBody; add_SubBody(ifBody); add_SubBody(elseBody); } public IterableSet get_NaturalExits() { IterableSet c = new IterableSet(); IterableSet ifChain = body2childChain.get(ifBody); if (!ifChain.isEmpty()) { c.addAll(((SETNode) ifChain.getLast()).get_NaturalExits()); } IterableSet elseChain = body2childChain.get(elseBody); if (!elseChain.isEmpty()) { c.addAll(((SETNode) elseChain.getLast()).get_NaturalExits()); } return c; } public ASTNode emit_AST() {<FILL_FUNCTION_BODY>} }
List<Object> astBody0 = emit_ASTBody(body2childChain.get(ifBody)), astBody1 = emit_ASTBody(body2childChain.get(elseBody)); ConditionExpr ce = (ConditionExpr) ((IfStmt) get_CharacterizingStmt().get_Stmt()).getCondition(); if (astBody0.isEmpty()) { List<Object> tbody = astBody0; astBody0 = astBody1; astBody1 = tbody; ce = ConditionFlipper.flip(ce); } if (astBody1.isEmpty()) { return new ASTIfNode(get_Label(), ce, astBody0); } else { return new ASTIfElseNode(get_Label(), ce, astBody0, astBody1); }
293
206
499
<methods>public void <init>(soot.dava.internal.asg.AugmentedStmt, IterableSet#RAW) ,public soot.dava.internal.asg.AugmentedStmt get_EntryStmt() <variables>
soot-oss_soot
soot/src/main/java/soot/dava/internal/SET/SETNodeLabel.java
SETNodeLabel
set_Name
class SETNodeLabel { private String name; public SETNodeLabel() { name = null; } public void set_Name() {<FILL_FUNCTION_BODY>} public void set_Name(String name) { this.name = name; } public String toString() { return name; } public void clear_Name() { name = null; } }
if (name == null) { name = "label_" + Integer.toString(G.v().SETNodeLabel_uniqueId++); }
114
39
153
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/internal/SET/SETStatementSequenceNode.java
SETStatementSequenceNode
emit_AST
class SETStatementSequenceNode extends SETNode { private DavaBody davaBody; private boolean hasContinue; public SETStatementSequenceNode(IterableSet body, DavaBody davaBody) { super(body); add_SubBody(body); this.davaBody = davaBody; hasContinue = false; } public SETStatementSequenceNode(IterableSet body) { this(body, null); } public boolean has_Continue() { return hasContinue; } public IterableSet get_NaturalExits() { IterableSet c = new IterableSet(); AugmentedStmt last = (AugmentedStmt) get_Body().getLast(); if ((last.csuccs != null) && !last.csuccs.isEmpty()) { c.add(last); } return c; } public ASTNode emit_AST() {<FILL_FUNCTION_BODY>} public AugmentedStmt get_EntryStmt() { return (AugmentedStmt) get_Body().getFirst(); } public void insert_AbruptStmt(DAbruptStmt stmt) { if (hasContinue) { return; } get_Body().addLast(new AugmentedStmt(stmt)); hasContinue = stmt.is_Continue(); } protected boolean resolve(SETNode parent) { throw new RuntimeException("Attempting auto-nest a SETStatementSequenceNode."); } }
List<AugmentedStmt> l = new LinkedList<AugmentedStmt>(); boolean isStaticInitializer = davaBody.getMethod().getName().equals(SootMethod.staticInitializerName); Iterator it = get_Body().iterator(); while (it.hasNext()) { AugmentedStmt as = (AugmentedStmt) it.next(); Stmt s = as.get_Stmt(); if (davaBody != null) { if (((s instanceof ReturnVoidStmt) && (isStaticInitializer)) || (s instanceof GotoStmt) || (s instanceof MonitorStmt)) { continue; } /* * January 12th 2006 Trying to fix the super problem we need to not ignore constructor unit i.e. this or super */ if (s == davaBody.get_ConstructorUnit()) { // System.out.println("ALLOWING this.init STMT TO GET ADDED..............SETStatementSequenceNode"); // continue; } if (s instanceof IdentityStmt) { IdentityStmt ids = (IdentityStmt) s; Value rightOp = ids.getRightOp(), leftOp = ids.getLeftOp(); if (davaBody.get_ThisLocals().contains(leftOp) || (rightOp instanceof ParameterRef) || (rightOp instanceof CaughtExceptionRef)) { continue; } } } l.add(as); } if (l.isEmpty()) { return null; } else { return new ASTStatementSequenceNode(l); }
404
421
825
<methods>public void <init>(IterableSet<soot.dava.internal.asg.AugmentedStmt>) ,public boolean add_Child(soot.dava.internal.SET.SETNode, IterableSet#RAW) ,public void add_SubBody(IterableSet#RAW) ,public boolean contains(java.lang.Object) ,public void dump() ,public void dump(java.io.PrintStream) ,public abstract soot.dava.internal.AST.ASTNode emit_AST() ,public List<java.lang.Object> emit_ASTBody(IterableSet#RAW) ,public boolean equals(java.lang.Object) ,public void find_AbruptEdges(soot.dava.toolkits.base.finders.AbruptEdgeFinder) ,public void find_LabeledBlocks(soot.dava.toolkits.base.finders.LabeledBlockFinder) ,public void find_SmallestSETNode(soot.dava.internal.asg.AugmentedStmt) ,public void find_StatementSequences(soot.dava.toolkits.base.finders.SequenceFinder, soot.dava.DavaBody) ,public IterableSet<soot.dava.internal.asg.AugmentedStmt> get_Body() ,public Map<IterableSet#RAW,IterableSet#RAW> get_Body2ChildChain() ,public abstract soot.dava.internal.asg.AugmentedStmt get_EntryStmt() ,public IterableSet<soot.dava.internal.asg.AugmentedStmt> get_IntersectionWith(soot.dava.internal.SET.SETNode) ,public soot.dava.internal.SET.SETNodeLabel get_Label() ,public abstract IterableSet#RAW get_NaturalExits() ,public soot.dava.internal.SET.SETNode get_Parent() ,public IterableSet#RAW get_Predecessors() ,public List<IterableSet#RAW> get_SubBodies() ,public IterableSet#RAW get_Successors() ,public boolean has_IntersectionWith(soot.dava.internal.SET.SETNode) ,public int hashCode() ,public boolean insert_ChildBefore(soot.dava.internal.SET.SETNode, soot.dava.internal.SET.SETNode, IterableSet#RAW) ,public boolean is_StrictSupersetOf(soot.dava.internal.SET.SETNode) ,public boolean is_SupersetOf(soot.dava.internal.SET.SETNode) ,public boolean nest(soot.dava.internal.SET.SETNode) ,public boolean remove_Child(soot.dava.internal.SET.SETNode, IterableSet#RAW) ,public void verify() <variables>private IterableSet<soot.dava.internal.asg.AugmentedStmt> body,protected Map<IterableSet#RAW,IterableSet#RAW> body2childChain,protected soot.dava.internal.asg.AugmentedStmt entryStmt,private final non-sealed soot.dava.internal.SET.SETNodeLabel label,private static final org.slf4j.Logger logger,protected soot.dava.internal.SET.SETNode parent,protected IterableSet#RAW predecessors,protected LinkedList<IterableSet#RAW> subBodies,protected IterableSet#RAW successors
soot-oss_soot
soot/src/main/java/soot/dava/internal/SET/SETSwitchNode.java
SETSwitchNode
emit_AST
class SETSwitchNode extends SETDagNode { private List<SwitchNode> switchNodeList; private Value key; public SETSwitchNode(AugmentedStmt characterizingStmt, Value key, IterableSet body, List<SwitchNode> switchNodeList, IterableSet junkBody) { super(characterizingStmt, body); this.key = key; this.switchNodeList = switchNodeList; Iterator<SwitchNode> it = switchNodeList.iterator(); while (it.hasNext()) { add_SubBody(it.next().get_Body()); } add_SubBody(junkBody); } public IterableSet get_NaturalExits() { return new IterableSet(); } public ASTNode emit_AST() {<FILL_FUNCTION_BODY>} public AugmentedStmt get_EntryStmt() { return get_CharacterizingStmt(); } }
LinkedList<Object> indexList = new LinkedList<Object>(); Map<Object, List<Object>> index2ASTBody = new HashMap<Object, List<Object>>(); Iterator<SwitchNode> it = switchNodeList.iterator(); while (it.hasNext()) { SwitchNode sn = it.next(); Object lastIndex = sn.get_IndexSet().last(); Iterator iit = sn.get_IndexSet().iterator(); while (iit.hasNext()) { Object index = iit.next(); indexList.addLast(index); if (index != lastIndex) { index2ASTBody.put(index, null); } else { index2ASTBody.put(index, emit_ASTBody(get_Body2ChildChain().get(sn.get_Body()))); } } } return new ASTSwitchNode(get_Label(), key, indexList, index2ASTBody);
245
242
487
<methods>public void <init>(soot.dava.internal.asg.AugmentedStmt, IterableSet#RAW) ,public soot.dava.internal.asg.AugmentedStmt get_EntryStmt() <variables>
soot-oss_soot
soot/src/main/java/soot/dava/internal/SET/SETTopNode.java
SETTopNode
get_EntryStmt
class SETTopNode extends SETNode { public SETTopNode(IterableSet body) { super(body); add_SubBody(body); } public IterableSet get_NaturalExits() { return new IterableSet(); } public ASTNode emit_AST() { return new ASTMethodNode(emit_ASTBody(body2childChain.get(subBodies.get(0)))); } public AugmentedStmt get_EntryStmt() {<FILL_FUNCTION_BODY>} protected boolean resolve(SETNode parent) { throw new RuntimeException("Attempting auto-nest a SETTopNode."); } }
throw new RuntimeException("Not implemented."); // FIXME the following turned out to be ill-typed after applying type // inference for generics // body2childChain maps to IterableSet ! // return (AugmentedStmt) ((SETNode) body2childChain.get( // subBodies.get(0))).get_EntryStmt();
174
91
265
<methods>public void <init>(IterableSet<soot.dava.internal.asg.AugmentedStmt>) ,public boolean add_Child(soot.dava.internal.SET.SETNode, IterableSet#RAW) ,public void add_SubBody(IterableSet#RAW) ,public boolean contains(java.lang.Object) ,public void dump() ,public void dump(java.io.PrintStream) ,public abstract soot.dava.internal.AST.ASTNode emit_AST() ,public List<java.lang.Object> emit_ASTBody(IterableSet#RAW) ,public boolean equals(java.lang.Object) ,public void find_AbruptEdges(soot.dava.toolkits.base.finders.AbruptEdgeFinder) ,public void find_LabeledBlocks(soot.dava.toolkits.base.finders.LabeledBlockFinder) ,public void find_SmallestSETNode(soot.dava.internal.asg.AugmentedStmt) ,public void find_StatementSequences(soot.dava.toolkits.base.finders.SequenceFinder, soot.dava.DavaBody) ,public IterableSet<soot.dava.internal.asg.AugmentedStmt> get_Body() ,public Map<IterableSet#RAW,IterableSet#RAW> get_Body2ChildChain() ,public abstract soot.dava.internal.asg.AugmentedStmt get_EntryStmt() ,public IterableSet<soot.dava.internal.asg.AugmentedStmt> get_IntersectionWith(soot.dava.internal.SET.SETNode) ,public soot.dava.internal.SET.SETNodeLabel get_Label() ,public abstract IterableSet#RAW get_NaturalExits() ,public soot.dava.internal.SET.SETNode get_Parent() ,public IterableSet#RAW get_Predecessors() ,public List<IterableSet#RAW> get_SubBodies() ,public IterableSet#RAW get_Successors() ,public boolean has_IntersectionWith(soot.dava.internal.SET.SETNode) ,public int hashCode() ,public boolean insert_ChildBefore(soot.dava.internal.SET.SETNode, soot.dava.internal.SET.SETNode, IterableSet#RAW) ,public boolean is_StrictSupersetOf(soot.dava.internal.SET.SETNode) ,public boolean is_SupersetOf(soot.dava.internal.SET.SETNode) ,public boolean nest(soot.dava.internal.SET.SETNode) ,public boolean remove_Child(soot.dava.internal.SET.SETNode, IterableSet#RAW) ,public void verify() <variables>private IterableSet<soot.dava.internal.asg.AugmentedStmt> body,protected Map<IterableSet#RAW,IterableSet#RAW> body2childChain,protected soot.dava.internal.asg.AugmentedStmt entryStmt,private final non-sealed soot.dava.internal.SET.SETNodeLabel label,private static final org.slf4j.Logger logger,protected soot.dava.internal.SET.SETNode parent,protected IterableSet#RAW predecessors,protected LinkedList<IterableSet#RAW> subBodies,protected IterableSet#RAW successors
soot-oss_soot
soot/src/main/java/soot/dava/internal/SET/SETTryNode.java
SETTryNode
emit_AST
class SETTryNode extends SETNode { private ExceptionNode en; private DavaBody davaBody; private AugmentedStmtGraph asg; private final HashMap<IterableSet, IterableSet> cb2clone; public SETTryNode(IterableSet body, ExceptionNode en, AugmentedStmtGraph asg, DavaBody davaBody) { super(body); this.en = en; this.asg = asg; this.davaBody = davaBody; add_SubBody(en.get_TryBody()); cb2clone = new HashMap<IterableSet, IterableSet>(); Iterator it = en.get_CatchList().iterator(); while (it.hasNext()) { IterableSet catchBody = (IterableSet) it.next(); IterableSet clone = (IterableSet) catchBody.clone(); cb2clone.put(catchBody, clone); add_SubBody(clone); } getEntryStmt: { entryStmt = null; it = body.iterator(); while (it.hasNext()) { AugmentedStmt as = (AugmentedStmt) it.next(); Iterator pit = as.cpreds.iterator(); while (pit.hasNext()) { if (!body.contains(pit.next())) { entryStmt = as; break getEntryStmt; } } } } } public AugmentedStmt get_EntryStmt() { if (entryStmt != null) { return entryStmt; } else { return (AugmentedStmt) (en.get_TryBody()).getFirst(); } // return ((SETNode) ((IterableSet) body2childChain.get( // en.get_TryBody())).getFirst()).get_EntryStmt(); } public IterableSet get_NaturalExits() { IterableSet c = new IterableSet(); Iterator<IterableSet> it = subBodies.iterator(); while (it.hasNext()) { Iterator eit = ((SETNode) body2childChain.get(it.next()).getLast()).get_NaturalExits().iterator(); while (eit.hasNext()) { Object o = eit.next(); if (!c.contains(o)) { c.add(o); } } } return c; } public ASTNode emit_AST() {<FILL_FUNCTION_BODY>} protected boolean resolve(SETNode parent) { Iterator<IterableSet> sbit = parent.get_SubBodies().iterator(); while (sbit.hasNext()) { IterableSet subBody = sbit.next(); if (subBody.intersects(en.get_TryBody())) { IterableSet childChain = parent.get_Body2ChildChain().get(subBody); Iterator ccit = childChain.iterator(); while (ccit.hasNext()) { SETNode child = (SETNode) ccit.next(); IterableSet childBody = child.get_Body(); if (!childBody.intersects(en.get_TryBody()) || (childBody.isSubsetOf(en.get_TryBody()))) { continue; } if (childBody.isSupersetOf(get_Body())) { return true; } IterableSet newTryBody = childBody.intersection(en.get_TryBody()); if (newTryBody.isStrictSubsetOf(en.get_TryBody())) { en.splitOff_ExceptionNode(newTryBody, asg, davaBody.get_ExceptionFacts()); Iterator enlit = davaBody.get_ExceptionFacts().iterator(); while (enlit.hasNext()) { ((ExceptionNode) enlit.next()).refresh_CatchBody(ExceptionFinder.v()); } return false; } Iterator cit = en.get_CatchList().iterator(); while (cit.hasNext()) { Iterator bit = cb2clone.get(cit.next()).snapshotIterator(); while (bit.hasNext()) { AugmentedStmt as = (AugmentedStmt) bit.next(); if (!childBody.contains(as)) { remove_AugmentedStmt(as); } else if ((child instanceof SETControlFlowNode) && !(child instanceof SETUnconditionalWhileNode)) { SETControlFlowNode scfn = (SETControlFlowNode) child; if ((scfn.get_CharacterizingStmt() == as) || ((as.cpreds.size() == 1) && (as.get_Stmt() instanceof GotoStmt) && (scfn.get_CharacterizingStmt() == as.cpreds.get(0)))) { remove_AugmentedStmt(as); } } } } return true; } } } return true; } }
LinkedList<Object> catchList = new LinkedList<Object>(); HashMap<Object, Object> exceptionMap = new HashMap<Object, Object>(), paramMap = new HashMap<Object, Object>(); Iterator it = en.get_CatchList().iterator(); while (it.hasNext()) { IterableSet originalCatchBody = (IterableSet) it.next(); IterableSet catchBody = cb2clone.get(originalCatchBody); List<Object> astBody = emit_ASTBody(body2childChain.get(catchBody)); exceptionMap.put(astBody, en.get_Exception(originalCatchBody)); catchList.addLast(astBody); Iterator bit = catchBody.iterator(); while (bit.hasNext()) { Stmt s = ((AugmentedStmt) bit.next()).get_Stmt(); /* * 04.04.2006 mbatch if an implicit try due to a finally block, make sure to get the exception identifier from the * goto target (it's a different block) */ // TODO: HOW the heck do you handle finallys with NO finally? // Semantics are // technically incorrect here if (s instanceof GotoStmt) { s = (Stmt) ((GotoStmt) s).getTarget(); /* 04.04.2006 mbatch end */ } if (s instanceof IdentityStmt) { IdentityStmt ids = (IdentityStmt) s; Value rightOp = ids.getRightOp(), leftOp = ids.getLeftOp(); if (rightOp instanceof CaughtExceptionRef) { paramMap.put(astBody, leftOp); break; } } } } return new ASTTryNode(get_Label(), emit_ASTBody(body2childChain.get(en.get_TryBody())), catchList, exceptionMap, paramMap);
1,288
500
1,788
<methods>public void <init>(IterableSet<soot.dava.internal.asg.AugmentedStmt>) ,public boolean add_Child(soot.dava.internal.SET.SETNode, IterableSet#RAW) ,public void add_SubBody(IterableSet#RAW) ,public boolean contains(java.lang.Object) ,public void dump() ,public void dump(java.io.PrintStream) ,public abstract soot.dava.internal.AST.ASTNode emit_AST() ,public List<java.lang.Object> emit_ASTBody(IterableSet#RAW) ,public boolean equals(java.lang.Object) ,public void find_AbruptEdges(soot.dava.toolkits.base.finders.AbruptEdgeFinder) ,public void find_LabeledBlocks(soot.dava.toolkits.base.finders.LabeledBlockFinder) ,public void find_SmallestSETNode(soot.dava.internal.asg.AugmentedStmt) ,public void find_StatementSequences(soot.dava.toolkits.base.finders.SequenceFinder, soot.dava.DavaBody) ,public IterableSet<soot.dava.internal.asg.AugmentedStmt> get_Body() ,public Map<IterableSet#RAW,IterableSet#RAW> get_Body2ChildChain() ,public abstract soot.dava.internal.asg.AugmentedStmt get_EntryStmt() ,public IterableSet<soot.dava.internal.asg.AugmentedStmt> get_IntersectionWith(soot.dava.internal.SET.SETNode) ,public soot.dava.internal.SET.SETNodeLabel get_Label() ,public abstract IterableSet#RAW get_NaturalExits() ,public soot.dava.internal.SET.SETNode get_Parent() ,public IterableSet#RAW get_Predecessors() ,public List<IterableSet#RAW> get_SubBodies() ,public IterableSet#RAW get_Successors() ,public boolean has_IntersectionWith(soot.dava.internal.SET.SETNode) ,public int hashCode() ,public boolean insert_ChildBefore(soot.dava.internal.SET.SETNode, soot.dava.internal.SET.SETNode, IterableSet#RAW) ,public boolean is_StrictSupersetOf(soot.dava.internal.SET.SETNode) ,public boolean is_SupersetOf(soot.dava.internal.SET.SETNode) ,public boolean nest(soot.dava.internal.SET.SETNode) ,public boolean remove_Child(soot.dava.internal.SET.SETNode, IterableSet#RAW) ,public void verify() <variables>private IterableSet<soot.dava.internal.asg.AugmentedStmt> body,protected Map<IterableSet#RAW,IterableSet#RAW> body2childChain,protected soot.dava.internal.asg.AugmentedStmt entryStmt,private final non-sealed soot.dava.internal.SET.SETNodeLabel label,private static final org.slf4j.Logger logger,protected soot.dava.internal.SET.SETNode parent,protected IterableSet#RAW predecessors,protected LinkedList<IterableSet#RAW> subBodies,protected IterableSet#RAW successors
soot-oss_soot
soot/src/main/java/soot/dava/internal/javaRep/DAbruptStmt.java
DAbruptStmt
toString
class DAbruptStmt extends AbstractStmt { private String command; private SETNodeLabel label; public boolean surpressDestinationLabel; public DAbruptStmt(String command, SETNodeLabel label) { this.command = command; this.label = label; label.set_Name(); surpressDestinationLabel = false; } public boolean fallsThrough() { return false; } public boolean branches() { return false; } public Object clone() { return new DAbruptStmt(command, label); } public String toString() { StringBuffer b = new StringBuffer(); b.append(command); if (!surpressDestinationLabel && (label.toString() != null)) { b.append(" "); b.append(label.toString()); } return b.toString(); } public void toString(UnitPrinter up) {<FILL_FUNCTION_BODY>} public boolean is_Continue() { return command.equals("continue"); } public boolean is_Break() { return command.equals("break"); } /* * Nomair A. Naeem 20-FEB-2005 getter and setter methods for the label are needed for the aggregators of the AST * conditionals */ public void setLabel(SETNodeLabel label) { this.label = label; } public SETNodeLabel getLabel() { return label; } }
up.literal(command); if (!surpressDestinationLabel && (label.toString() != null)) { up.literal(" "); up.literal(label.toString()); }
403
54
457
<methods>public non-sealed void <init>() ,public boolean containsArrayRef() ,public boolean containsFieldRef() ,public boolean containsInvokeExpr() ,public void convertToBaf(soot.jimple.JimpleToBafContext, List<soot.Unit>) ,public soot.jimple.ArrayRef getArrayRef() ,public soot.ValueBox getArrayRefBox() ,public soot.jimple.FieldRef getFieldRef() ,public soot.ValueBox getFieldRefBox() ,public soot.jimple.InvokeExpr getInvokeExpr() ,public soot.ValueBox getInvokeExprBox() <variables>
soot-oss_soot
soot/src/main/java/soot/dava/internal/javaRep/DInstanceFieldRef.java
DInstanceFieldRef
toString
class DInstanceFieldRef extends GInstanceFieldRef { private HashSet<Object> thisLocals; public DInstanceFieldRef(Value base, SootFieldRef fieldRef, HashSet<Object> thisLocals) { super(base, fieldRef); this.thisLocals = thisLocals; } public void toString(UnitPrinter up) {<FILL_FUNCTION_BODY>} public String toString() { if (thisLocals.contains(getBase())) { return fieldRef.name(); } return super.toString(); } public Object clone() { return new DInstanceFieldRef(getBase(), fieldRef, thisLocals); } }
if (thisLocals.contains(getBase())) { up.fieldRef(fieldRef); } else { super.toString(up); }
181
43
224
<methods>public void <init>(soot.Value, soot.SootFieldRef) ,public java.lang.Object clone() ,public int getPrecedence() ,public java.lang.String toString() <variables>
soot-oss_soot
soot/src/main/java/soot/dava/internal/javaRep/DInterfaceInvokeExpr.java
DInterfaceInvokeExpr
toString
class DInterfaceInvokeExpr extends GInterfaceInvokeExpr { public DInterfaceInvokeExpr(Value base, SootMethodRef methodRef, java.util.List args) { super(base, methodRef, args); } public void toString(UnitPrinter up) {<FILL_FUNCTION_BODY>} public String toString() { if (getBase().getType() instanceof NullType) { StringBuffer b = new StringBuffer(); b.append("(("); b.append(getMethodRef().declaringClass().getJavaStyleName()); b.append(") "); String baseStr = (getBase()).toString(); if ((getBase() instanceof Precedence) && (((Precedence) getBase()).getPrecedence() < getPrecedence())) { baseStr = "(" + baseStr + ")"; } b.append(baseStr); b.append(")."); b.append(getMethodRef().name()); b.append("("); if (argBoxes != null) { for (int i = 0; i < argBoxes.length; i++) { if (i != 0) { b.append(", "); } b.append((argBoxes[i].getValue()).toString()); } } b.append(")"); return b.toString(); } return super.toString(); } public Object clone() { ArrayList clonedArgs = new ArrayList(getArgCount()); for (int i = 0; i < getArgCount(); i++) { clonedArgs.add(i, Grimp.cloneIfNecessary(getArg(i))); } return new DInterfaceInvokeExpr(getBase(), methodRef, clonedArgs); } }
if (getBase().getType() instanceof NullType) { // OL: I don't know what this is for; I'm just refactoring the // original code. An explanation here would be welcome. up.literal("(("); up.type(getMethodRef().declaringClass().getType()); up.literal(") "); if (PrecedenceTest.needsBrackets(baseBox, this)) { up.literal("("); } baseBox.toString(up); if (PrecedenceTest.needsBrackets(baseBox, this)) { up.literal(")"); } up.literal(")"); up.literal("."); up.methodRef(methodRef); up.literal("("); if (argBoxes != null) { for (int i = 0; i < argBoxes.length; i++) { if (i != 0) { up.literal(", "); } argBoxes[i].toString(up); } } up.literal(")"); } else { super.toString(up); }
458
304
762
<methods>public void <init>(soot.Value, soot.SootMethodRef, List<? extends soot.Value>) ,public java.lang.Object clone() ,public int getPrecedence() ,public java.lang.String toString() ,public void toString(soot.UnitPrinter) <variables>
soot-oss_soot
soot/src/main/java/soot/dava/internal/javaRep/DLengthExpr.java
DLengthExpr
toString
class DLengthExpr extends AbstractLengthExpr implements Precedence { public DLengthExpr(Value op) { super(Grimp.v().newObjExprBox(op)); } public int getPrecedence() { return 950; } public Object clone() { return new DLengthExpr(Grimp.cloneIfNecessary(getOp())); } public void toString(UnitPrinter up) { if (PrecedenceTest.needsBrackets(getOpBox(), this)) { up.literal("("); } getOpBox().toString(up); if (PrecedenceTest.needsBrackets(getOpBox(), this)) { up.literal(")"); } up.literal("."); up.literal("length"); } public String toString() {<FILL_FUNCTION_BODY>} }
StringBuffer b = new StringBuffer(); if (PrecedenceTest.needsBrackets(getOpBox(), this)) { b.append("("); } b.append(getOpBox().getValue().toString()); if (PrecedenceTest.needsBrackets(getOpBox(), this)) { b.append(")"); } b.append(".length"); return b.toString();
232
107
339
<methods>public void apply(soot.util.Switch) ,public int equivHashCode() ,public boolean equivTo(java.lang.Object) ,public soot.Type getType() ,public java.lang.String toString() ,public void toString(soot.UnitPrinter) <variables>
soot-oss_soot
soot/src/main/java/soot/dava/internal/javaRep/DNewMultiArrayExpr.java
DNewMultiArrayExpr
toString
class DNewMultiArrayExpr extends AbstractNewMultiArrayExpr { public DNewMultiArrayExpr(ArrayType type, List sizes) { super(type, new ValueBox[sizes.size()]); for (int i = 0; i < sizes.size(); i++) { sizeBoxes[i] = Grimp.v().newExprBox((Value) sizes.get(i)); } } public Object clone() { List clonedSizes = new ArrayList(getSizeCount()); for (int i = 0; i < getSizeCount(); i++) { clonedSizes.add(i, Grimp.cloneIfNecessary(getSize(i))); } return new DNewMultiArrayExpr(getBaseType(), clonedSizes); } public void toString(UnitPrinter up) { up.literal("new"); up.literal(" "); up.type(getBaseType().baseType); for (ValueBox element : sizeBoxes) { up.literal("["); element.toString(up); up.literal("]"); } for (int i = getSizeCount(); i < getBaseType().numDimensions; i++) { up.literal("[]"); } } public String toString() {<FILL_FUNCTION_BODY>} }
StringBuffer buffer = new StringBuffer(); buffer.append("new " + getBaseType().baseType); List sizes = getSizes(); Iterator it = getSizes().iterator(); while (it.hasNext()) { buffer.append("[" + it.next().toString() + "]"); } for (int i = getSizeCount(); i < getBaseType().numDimensions; i++) { buffer.append("[]"); } return buffer.toString();
344
127
471
<methods>public void apply(soot.util.Switch) ,public abstract java.lang.Object clone() ,public void convertToBaf(soot.jimple.JimpleToBafContext, List<soot.Unit>) ,public int equivHashCode() ,public boolean equivTo(java.lang.Object) ,public soot.ArrayType getBaseType() ,public soot.Value getSize(int) ,public soot.ValueBox getSizeBox(int) ,public int getSizeCount() ,public List<soot.Value> getSizes() ,public soot.Type getType() ,public final List<soot.ValueBox> getUseBoxes() ,public void setBaseType(soot.ArrayType) ,public void setSize(int, soot.Value) ,public java.lang.String toString() ,public void toString(soot.UnitPrinter) <variables>protected soot.ArrayType baseType,protected final non-sealed soot.ValueBox[] sizeBoxes
soot-oss_soot
soot/src/main/java/soot/dava/internal/javaRep/DNotExpr.java
DNotExpr
getType
class DNotExpr extends AbstractUnopExpr { public DNotExpr(Value op) { super(Grimp.v().newExprBox(op)); } public Object clone() { return new DNotExpr(Grimp.cloneIfNecessary(getOpBox().getValue())); } public void toString(UnitPrinter up) { up.literal(" ! ("); getOpBox().toString(up); up.literal(")"); } public String toString() { return " ! (" + (getOpBox().getValue()).toString() + ")"; } public Type getType() {<FILL_FUNCTION_BODY>} /* * NOTE THIS IS AN EMPTY IMPLEMENTATION OF APPLY METHOD */ public void apply(Switch sw) { } /** Compares the specified object with this one for structural equality. */ public boolean equivTo(Object o) { if (o instanceof DNotExpr) { return getOpBox().getValue().equivTo(((DNotExpr) o).getOpBox().getValue()); } return false; } /** Returns a hash code for this object, consistent with structural equality. */ public int equivHashCode() { return getOpBox().getValue().equivHashCode(); } }
Value op = getOpBox().getValue(); if (op.getType().equals(IntType.v()) || op.getType().equals(ByteType.v()) || op.getType().equals(ShortType.v()) || op.getType().equals(BooleanType.v()) || op.getType().equals(CharType.v())) { return IntType.v(); } else if (op.getType().equals(LongType.v())) { return LongType.v(); } else if (op.getType().equals(DoubleType.v())) { return DoubleType.v(); } else if (op.getType().equals(FloatType.v())) { return FloatType.v(); } else { return UnknownType.v(); }
337
192
529
<methods>public abstract java.lang.Object clone() ,public soot.Value getOp() ,public soot.ValueBox getOpBox() ,public final List<soot.ValueBox> getUseBoxes() ,public void setOp(soot.Value) <variables>protected final non-sealed soot.ValueBox opBox
soot-oss_soot
soot/src/main/java/soot/dava/internal/javaRep/DShortcutAssignStmt.java
DShortcutAssignStmt
toString
class DShortcutAssignStmt extends DAssignStmt { Type type; public DShortcutAssignStmt(DAssignStmt assignStmt, Type type) { super(assignStmt.getLeftOpBox(), assignStmt.getRightOpBox()); this.type = type; } public void toString(UnitPrinter up) { up.type(type); up.literal(" "); super.toString(up); } public String toString() {<FILL_FUNCTION_BODY>} }
return type.toString() + " " + leftBox.getValue().toString() + " = " + rightBox.getValue().toString();
144
33
177
<methods>public void <init>(soot.ValueBox, soot.ValueBox) ,public java.lang.Object clone() ,public void setLeftOp(soot.Value) ,public void setRightOp(soot.Value) ,public void toString(soot.UnitPrinter) ,public java.lang.String toString() <variables>
soot-oss_soot
soot/src/main/java/soot/dava/internal/javaRep/DSpecialInvokeExpr.java
DSpecialInvokeExpr
toString
class DSpecialInvokeExpr extends GSpecialInvokeExpr { public DSpecialInvokeExpr(Value base, SootMethodRef methodRef, java.util.List args) { super(base, methodRef, args); } public void toString(UnitPrinter up) {<FILL_FUNCTION_BODY>} public String toString() { if (getBase().getType() instanceof NullType) { StringBuffer b = new StringBuffer(); b.append("(("); b.append(methodRef.declaringClass().getJavaStyleName()); b.append(") "); String baseStr = (getBase()).toString(); if ((getBase() instanceof Precedence) && (((Precedence) getBase()).getPrecedence() < getPrecedence())) { baseStr = "(" + baseStr + ")"; } b.append(baseStr); b.append(")."); b.append(methodRef.name()); b.append("("); if (argBoxes != null) { for (int i = 0; i < argBoxes.length; i++) { if (i != 0) { b.append(", "); } b.append((argBoxes[i].getValue()).toString()); } } b.append(")"); return b.toString(); } return super.toString(); } public Object clone() { ArrayList clonedArgs = new ArrayList(getArgCount()); for (int i = 0; i < getArgCount(); i++) { clonedArgs.add(i, Grimp.cloneIfNecessary(getArg(i))); } return new DSpecialInvokeExpr(getBase(), methodRef, clonedArgs); } }
if (getBase().getType() instanceof NullType) { // OL: I don't know what this is for; I'm just refactoring the // original code. An explanation here would be welcome. up.literal("(("); up.type(methodRef.declaringClass().getType()); up.literal(") "); if (PrecedenceTest.needsBrackets(baseBox, this)) { up.literal("("); } baseBox.toString(up); if (PrecedenceTest.needsBrackets(baseBox, this)) { up.literal(")"); } up.literal(")"); up.literal("."); up.methodRef(methodRef); up.literal("("); if (argBoxes != null) { for (int i = 0; i < argBoxes.length; i++) { if (i != 0) { up.literal(", "); } argBoxes[i].toString(up); } } up.literal(")"); } else { super.toString(up); }
456
303
759
<methods>public void <init>(soot.Value, soot.SootMethodRef, List<? extends soot.Value>) ,public java.lang.Object clone() ,public int getPrecedence() ,public java.lang.String toString() ,public void toString(soot.UnitPrinter) <variables>
soot-oss_soot
soot/src/main/java/soot/dava/internal/javaRep/DStaticInvokeExpr.java
DStaticInvokeExpr
clone
class DStaticInvokeExpr extends GStaticInvokeExpr { public DStaticInvokeExpr(SootMethodRef methodRef, java.util.List args) { super(methodRef, args); } public void toString(UnitPrinter up) { up.type(methodRef.declaringClass().getType()); up.literal("."); super.toString(up); } public Object clone() {<FILL_FUNCTION_BODY>} }
ArrayList clonedArgs = new ArrayList(getArgCount()); for (int i = 0; i < getArgCount(); i++) { clonedArgs.add(i, Grimp.cloneIfNecessary(getArg(i))); } return new DStaticInvokeExpr(methodRef, clonedArgs);
121
82
203
<methods>public void <init>(soot.SootMethodRef, List<? extends soot.Value>) ,public java.lang.Object clone() <variables>
soot-oss_soot
soot/src/main/java/soot/dava/internal/javaRep/DVariableDeclarationStmt.java
DVariableDeclarationStmt
clone
class DVariableDeclarationStmt extends AbstractUnit implements Stmt { Type declarationType = null; List declarations = null; // added solely for the purpose of retrieving packages used when printing DavaBody davaBody = null; public DVariableDeclarationStmt(Type decType, DavaBody davaBody) { if (declarationType != null) { throw new RuntimeException("creating a VariableDeclaration which has already been created"); } else { declarationType = decType; declarations = new ArrayList(); this.davaBody = davaBody; } } public List getDeclarations() { return declarations; } public void addLocal(Local add) { declarations.add(add); } public void removeLocal(Local remove) { for (int i = 0; i < declarations.size(); i++) { Local temp = (Local) declarations.get(i); if (temp.getName().compareTo(remove.getName()) == 0) { // this is the local to be removed // System.out.println("REMOVED"+temp); declarations.remove(i); return; } } } public Type getType() { return declarationType; } public boolean isOfType(Type type) { if (type.toString().compareTo(declarationType.toString()) == 0) { return true; } else { return false; } } public Object clone() {<FILL_FUNCTION_BODY>} public String toString() { StringBuffer b = new StringBuffer(); if (declarations.size() == 0) { return b.toString(); } String type = declarationType.toString(); if (type.equals("null_type")) { b.append("Object"); } else { b.append(type); } b.append(" "); Iterator decIt = declarations.iterator(); while (decIt.hasNext()) { Local tempDec = (Local) decIt.next(); b.append(tempDec.getName()); if (decIt.hasNext()) { b.append(", "); } } return b.toString(); } public void toString(UnitPrinter up) { if (declarations.size() == 0) { return; } if (!(up instanceof DavaUnitPrinter)) { throw new RuntimeException("DavaBody should always be printed using the DavaUnitPrinter"); } else { DavaUnitPrinter dup = (DavaUnitPrinter) up; String type = declarationType.toString(); if (type.equals("null_type")) { dup.printString("Object"); } else { IterableSet importSet = davaBody.getImportList(); if (!importSet.contains(type)) { davaBody.addToImportList(type); } type = RemoveFullyQualifiedName.getReducedName(davaBody.getImportList(), type, declarationType); dup.printString(type); } dup.printString(" "); Iterator decIt = declarations.iterator(); while (decIt.hasNext()) { Local tempDec = (Local) decIt.next(); dup.printString(tempDec.getName()); if (decIt.hasNext()) { dup.printString(", "); } } } } /* * Methods needed to satisfy all obligations due to extension from AbstractUnit and implementing Stmt * */ public boolean fallsThrough() { return true; } public boolean branches() { return false; } public boolean containsInvokeExpr() { return false; } public InvokeExpr getInvokeExpr() { throw new RuntimeException("getInvokeExpr() called with no invokeExpr present!"); } public ValueBox getInvokeExprBox() { throw new RuntimeException("getInvokeExprBox() called with no invokeExpr present!"); } public boolean containsArrayRef() { return false; } public ArrayRef getArrayRef() { throw new RuntimeException("getArrayRef() called with no ArrayRef present!"); } public ValueBox getArrayRefBox() { throw new RuntimeException("getArrayRefBox() called with no ArrayRef present!"); } public boolean containsFieldRef() { return false; } public FieldRef getFieldRef() { throw new RuntimeException("getFieldRef() called with no FieldRef present!"); } public ValueBox getFieldRefBox() { throw new RuntimeException("getFieldRefBox() called with no FieldRef present!"); } }
DVariableDeclarationStmt temp = new DVariableDeclarationStmt(declarationType, davaBody); Iterator it = declarations.iterator(); while (it.hasNext()) { Local obj = (Local) it.next(); Value temp1 = Grimp.cloneIfNecessary(obj); if (temp1 instanceof Local) { temp.addLocal((Local) temp1); } } return temp;
1,236
111
1,347
<methods>public non-sealed void <init>() ,public void addBoxPointingToThis(soot.UnitBox) ,public void apply(soot.util.Switch) ,public void clearUnitBoxes() ,public abstract java.lang.Object clone() ,public List<soot.UnitBox> getBoxesPointingToThis() ,public List<soot.ValueBox> getDefBoxes() ,public List<soot.UnitBox> getUnitBoxes() ,public List<soot.ValueBox> getUseAndDefBoxes() ,public List<soot.ValueBox> getUseBoxes() ,public void redirectJumpsToThisTo(soot.Unit) ,public void removeBoxPointingToThis(soot.UnitBox) <variables>protected List<soot.UnitBox> boxesPointingToThis
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/TryContentsFinder.java
TryContentsFinder
add_ExceptionSet
class TryContentsFinder extends ASTAnalysis { public TryContentsFinder(Singletons.Global g) { } public static TryContentsFinder v() { return G.v().soot_dava_toolkits_base_AST_TryContentsFinder(); } private IterableSet curExceptionSet = new IterableSet(); private final HashMap<Object, IterableSet> node2ExceptionSet = new HashMap<Object, IterableSet>(); public int getAnalysisDepth() { return ANALYSE_VALUES; } public IterableSet remove_CurExceptionSet() { IterableSet s = curExceptionSet; set_CurExceptionSet(new IterableSet()); return s; } public void set_CurExceptionSet(IterableSet curExceptionSet) { this.curExceptionSet = curExceptionSet; } public void analyseThrowStmt(ThrowStmt s) { Value op = (s).getOp(); if (op instanceof Local) { add_ThrownType(((Local) op).getType()); } else if (op instanceof FieldRef) { add_ThrownType(((FieldRef) op).getType()); } } private void add_ThrownType(Type t) { if (t instanceof RefType) { curExceptionSet.add(((RefType) t).getSootClass()); } } public void analyseInvokeExpr(InvokeExpr ie) { curExceptionSet.addAll(ie.getMethod().getExceptions()); } public void analyseInstanceInvokeExpr(InstanceInvokeExpr iie) { analyseInvokeExpr(iie); } public void analyseASTNode(ASTNode n) { if (n instanceof ASTTryNode) { ASTTryNode tryNode = (ASTTryNode) n; ArrayList<Object> toRemove = new ArrayList<Object>(); IterableSet tryExceptionSet = node2ExceptionSet.get(tryNode.get_TryBodyContainer()); if (tryExceptionSet == null) { tryExceptionSet = new IterableSet(); node2ExceptionSet.put(tryNode.get_TryBodyContainer(), tryExceptionSet); } List<Object> catchBodies = tryNode.get_CatchList(); List<Object> subBodies = tryNode.get_SubBodies(); Iterator<Object> cit = catchBodies.iterator(); while (cit.hasNext()) { Object catchBody = cit.next(); SootClass exception = (SootClass) tryNode.get_ExceptionMap().get(catchBody); if (!catches_Exception(tryExceptionSet, exception) && !catches_RuntimeException(exception)) { toRemove.add(catchBody); } } Iterator<Object> trit = toRemove.iterator(); while (trit.hasNext()) { Object catchBody = trit.next(); subBodies.remove(catchBody); catchBodies.remove(catchBody); } IterableSet passingSet = (IterableSet) tryExceptionSet.clone(); cit = catchBodies.iterator(); while (cit.hasNext()) { passingSet.remove(tryNode.get_ExceptionMap().get(cit.next())); } cit = catchBodies.iterator(); while (cit.hasNext()) { passingSet.addAll(get_ExceptionSet(cit.next())); } node2ExceptionSet.put(n, passingSet); } else { Iterator<Object> sbit = n.get_SubBodies().iterator(); while (sbit.hasNext()) { Iterator it = ((List) sbit.next()).iterator(); while (it.hasNext()) { add_ExceptionSet(n, get_ExceptionSet(it.next())); } } } remove_CurExceptionSet(); } public IterableSet get_ExceptionSet(Object node) { IterableSet fullSet = node2ExceptionSet.get(node); if (fullSet == null) { fullSet = new IterableSet(); node2ExceptionSet.put(node, fullSet); } return fullSet; } public void add_ExceptionSet(Object node, IterableSet s) {<FILL_FUNCTION_BODY>} private boolean catches_Exception(IterableSet tryExceptionSet, SootClass c) { Iterator it = tryExceptionSet.iterator(); while (it.hasNext()) { SootClass thrownException = (SootClass) it.next(); while (true) { if (thrownException == c) { return true; } if (!thrownException.hasSuperclass()) { break; } thrownException = thrownException.getSuperclass(); } } return false; } private boolean catches_RuntimeException(SootClass c) { if ((c == Scene.v().getSootClass("java.lang.Throwable")) || (c == Scene.v().getSootClass("java.lang.Exception"))) { return true; } SootClass caughtException = c, runtimeException = Scene.v().getSootClass("java.lang.RuntimeException"); while (true) { if (caughtException == runtimeException) { return true; } if (!caughtException.hasSuperclass()) { return false; } caughtException = caughtException.getSuperclass(); } } }
IterableSet fullSet = node2ExceptionSet.get(node); if (fullSet == null) { fullSet = new IterableSet(); node2ExceptionSet.put(node, fullSet); } fullSet.addAll(s);
1,418
68
1,486
<methods>public non-sealed void <init>() ,public void analyseASTNode(soot.dava.internal.AST.ASTNode) ,public void analyseArrayRef(soot.jimple.ArrayRef) ,public void analyseBinopExpr(soot.jimple.BinopExpr) ,public void analyseDefinitionStmt(soot.jimple.DefinitionStmt) ,public void analyseExpr(soot.jimple.Expr) ,public void analyseInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void analyseInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void analyseInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void analyseInvokeExpr(soot.jimple.InvokeExpr) ,public void analyseInvokeStmt(soot.jimple.InvokeStmt) ,public void analyseNewArrayExpr(soot.jimple.NewArrayExpr) ,public void analyseNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void analyseRef(soot.jimple.Ref) ,public void analyseReturnStmt(soot.jimple.ReturnStmt) ,public void analyseStmt(soot.jimple.Stmt) ,public void analyseThrowStmt(soot.jimple.ThrowStmt) ,public void analyseUnopExpr(soot.jimple.UnopExpr) ,public void analyseValue(soot.Value) ,public abstract int getAnalysisDepth() <variables>public static final int ANALYSE_AST,public static final int ANALYSE_STMTS,public static final int ANALYSE_VALUES
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/UselessTryRemover.java
UselessTryRemover
analyseASTNode
class UselessTryRemover extends ASTAnalysis { public UselessTryRemover(Singletons.Global g) { } public static UselessTryRemover v() { return G.v().soot_dava_toolkits_base_AST_UselessTryRemover(); } public int getAnalysisDepth() { return ANALYSE_AST; } public void analyseASTNode(ASTNode n) {<FILL_FUNCTION_BODY>} }
Iterator<Object> sbit = n.get_SubBodies().iterator(); while (sbit.hasNext()) { List<Object> subBody = null, toRemove = new ArrayList<Object>(); if (n instanceof ASTTryNode) { subBody = (List<Object>) ((ASTTryNode.container) sbit.next()).o; } else { subBody = (List<Object>) sbit.next(); } Iterator<Object> cit = subBody.iterator(); while (cit.hasNext()) { Object child = cit.next(); if (child instanceof ASTTryNode) { ASTTryNode tryNode = (ASTTryNode) child; tryNode.perform_Analysis(TryContentsFinder.v()); if ((tryNode.get_CatchList().isEmpty()) || (tryNode.isEmpty())) { toRemove.add(tryNode); } } } Iterator<Object> trit = toRemove.iterator(); while (trit.hasNext()) { ASTTryNode tryNode = (ASTTryNode) trit.next(); subBody.addAll(subBody.indexOf(tryNode), tryNode.get_TryBody()); subBody.remove(tryNode); } if (!toRemove.isEmpty()) { G.v().ASTAnalysis_modified = true; } }
131
357
488
<methods>public non-sealed void <init>() ,public void analyseASTNode(soot.dava.internal.AST.ASTNode) ,public void analyseArrayRef(soot.jimple.ArrayRef) ,public void analyseBinopExpr(soot.jimple.BinopExpr) ,public void analyseDefinitionStmt(soot.jimple.DefinitionStmt) ,public void analyseExpr(soot.jimple.Expr) ,public void analyseInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void analyseInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void analyseInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void analyseInvokeExpr(soot.jimple.InvokeExpr) ,public void analyseInvokeStmt(soot.jimple.InvokeStmt) ,public void analyseNewArrayExpr(soot.jimple.NewArrayExpr) ,public void analyseNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void analyseRef(soot.jimple.Ref) ,public void analyseReturnStmt(soot.jimple.ReturnStmt) ,public void analyseStmt(soot.jimple.Stmt) ,public void analyseThrowStmt(soot.jimple.ThrowStmt) ,public void analyseUnopExpr(soot.jimple.UnopExpr) ,public void analyseValue(soot.Value) ,public abstract int getAnalysisDepth() <variables>public static final int ANALYSE_AST,public static final int ANALYSE_STMTS,public static final int ANALYSE_VALUES
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/structuredAnalysis/CPHelper.java
CPHelper
isAConstantValue
class CPHelper { /* * The helper class just checks the type of the data being sent and create a clone of it * * If it is not a data of interest a null is send back */ public static Object wrapperClassCloner(Object value) { if (value instanceof Double) { return new Double(((Double) value).doubleValue()); } else if (value instanceof Float) { return new Float(((Float) value).floatValue()); } else if (value instanceof Long) { return new Long(((Long) value).longValue()); } else if (value instanceof Boolean) { return new Boolean(((Boolean) value).booleanValue()); } else if (value instanceof Integer) { return new Integer(((Integer) value).intValue()); } else { return null; } } /* * isAConstantValue(Value toCheck) it will check whether toCheck is one of the interesting Constants IntConstant * FloatConstant etc etc if yes return the Integer/Long/float/Double * * Notice for integer the callee has to check whether what is required is a Boolean!!!! */ public static Object isAConstantValue(Value toCheck) {<FILL_FUNCTION_BODY>} public static Value createConstant(Object toConvert) { if (toConvert instanceof Long) { return LongConstant.v(((Long) toConvert).longValue()); } else if (toConvert instanceof Double) { return DoubleConstant.v(((Double) toConvert).doubleValue()); } else if (toConvert instanceof Boolean) { boolean val = ((Boolean) toConvert).booleanValue(); if (val) { return DIntConstant.v(1, BooleanType.v()); } else { return DIntConstant.v(0, BooleanType.v()); } } else if (toConvert instanceof Float) { return FloatConstant.v(((Float) toConvert).floatValue()); } else if (toConvert instanceof Integer) { return IntConstant.v(((Integer) toConvert).intValue()); } else { return null; } } }
Object value = null; if (toCheck instanceof LongConstant) { value = new Long(((LongConstant) toCheck).value); } else if (toCheck instanceof DoubleConstant) { value = new Double(((DoubleConstant) toCheck).value); } else if (toCheck instanceof FloatConstant) { value = new Float(((FloatConstant) toCheck).value); } else if (toCheck instanceof IntConstant) { int val = ((IntConstant) toCheck).value; value = new Integer(val); } return value;
532
142
674
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/structuredAnalysis/CPTuple.java
CPTuple
clone
class CPTuple { private String sootClass; // hold the name of the class to which the val belongs .... needed for interprocedural constant // Fields info /* * */ private CPVariable variable; // Double Float Long Boolean Integer private Object constant; // the known constant value for the local or field /* * false means not top true mean TOP */ private Boolean TOP = new Boolean(false); /* * Dont care about className and variable but the CONSTANT VALUE HAS TO BE A NEW ONE otherwise the clone of the flowset * keeps pointing to the same bloody constant value */ public CPTuple clone() {<FILL_FUNCTION_BODY>} public CPTuple(String sootClass, CPVariable variable, Object constant) { if (!(constant instanceof Float || constant instanceof Double || constant instanceof Long || constant instanceof Boolean || constant instanceof Integer)) { throw new DavaFlowAnalysisException( "Third argument of VariableValuePair not an acceptable constant value...report to developer"); } this.sootClass = sootClass; this.variable = variable; this.constant = constant; TOP = new Boolean(false); } public CPTuple(String sootClass, CPVariable variable, boolean top) { this.sootClass = sootClass; this.variable = variable; // notice we dont really care whether the argument top was true or false setTop(); } public boolean containsLocal() { return variable.containsLocal(); } public boolean containsField() { return variable.containsSootField(); } /* * If TOP is non null then that means it is set to TOP */ public boolean isTop() { return TOP.booleanValue(); } public void setTop() { constant = null; TOP = new Boolean(true); } public boolean isValueADouble() { return (constant instanceof Double); } public boolean isValueAFloat() { return (constant instanceof Float); } public boolean isValueALong() { return (constant instanceof Long); } public boolean isValueABoolean() { return (constant instanceof Boolean); } public boolean isValueAInteger() { return (constant instanceof Integer); } public Object getValue() { return constant; } public void setValue(Object constant) { // System.out.println("here currently valued as"+this.constant); if (!(constant instanceof Float || constant instanceof Double || constant instanceof Long || constant instanceof Boolean || constant instanceof Integer)) { throw new DavaFlowAnalysisException("argument to setValue not an acceptable constant value...report to developer"); } this.constant = constant; TOP = new Boolean(false); } public String getSootClassName() { return sootClass; } public CPVariable getVariable() { return variable; } public boolean equals(Object other) { if (other instanceof CPTuple) { CPTuple var = (CPTuple) other; // if both are top thats all right if (sootClass.equals(var.getSootClassName()) && variable.equals(var.getVariable()) && isTop() & var.isTop()) { return true; } // if any one is top thats no good if (isTop() || var.isTop()) { return false; } if (sootClass.equals(var.getSootClassName()) && variable.equals(var.getVariable()) && constant.equals(var.getValue())) { // System.out.println("constant value "+constant.toString() + " is equal to "+ var.toString()); return true; } } return false; } public String toString() { StringBuffer b = new StringBuffer(); if (isTop()) { b.append("<" + sootClass + ", " + variable.toString() + ", TOP>"); } else { b.append("<" + sootClass + ", " + variable.toString() + "," + constant.toString() + ">"); } return b.toString(); } }
if (isTop()) { return new CPTuple(sootClass, variable, true); } else if (isValueADouble()) { return new CPTuple(sootClass, variable, new Double(((Double) constant).doubleValue())); } else if (isValueAFloat()) { return new CPTuple(sootClass, variable, new Float(((Float) constant).floatValue())); } else if (isValueALong()) { return new CPTuple(sootClass, variable, new Long(((Long) constant).longValue())); } else if (isValueABoolean()) { return new CPTuple(sootClass, variable, new Boolean(((Boolean) constant).booleanValue())); } else if (isValueAInteger()) { return new CPTuple(sootClass, variable, new Integer(((Integer) constant).intValue())); } else { throw new RuntimeException("illegal Constant Type...report to developer" + constant); }
1,085
241
1,326
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/structuredAnalysis/CPVariable.java
CPVariable
toString
class CPVariable { private Local local; private SootField field; public CPVariable(SootField field) { this.field = field; this.local = null; if (!(field.getType() instanceof PrimType)) { throw new DavaFlowAnalysisException("Variables managed for CP should only be primitives"); } } public CPVariable(Local local) { this.field = null; this.local = local; if (!(local.getType() instanceof PrimType)) { throw new DavaFlowAnalysisException("Variables managed for CP should only be primitives"); } } public boolean containsLocal() { return (local != null); } public boolean containsSootField() { return (field != null); } public SootField getSootField() { if (containsSootField()) { return field; } else { throw new DavaFlowAnalysisException("getsootField invoked when variable is not a sootfield!!!"); } } public Local getLocal() { if (containsLocal()) { return local; } else { throw new DavaFlowAnalysisException("getLocal invoked when variable is not a local"); } } /* * VERY IMPORTANT METHOD: invoked from ConstantPropagationTuple equals method which is invoked from the main merge * intersection method of CPFlowSet */ public boolean equals(CPVariable var) { // check they have the same type Local or SootField if (this.containsLocal() && var.containsLocal()) { // both locals and same name if (this.getLocal().getName().equals(var.getLocal().getName())) { return true; } } if (this.containsSootField() && var.containsSootField()) { // both SootFields check they have same name if (this.getSootField().getName().equals(var.getSootField().getName())) { return true; } } return false; } public String toString() {<FILL_FUNCTION_BODY>} }
if (containsLocal()) { return "Local: " + getLocal().getName(); } else if (containsSootField()) { return "SootField: " + getSootField().getName(); } else { return "UNKNOWN CONSTANT_PROPAGATION_VARIABLE"; }
555
81
636
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/structuredAnalysis/MustMayInitialize.java
MustMayInitialize
processStatement
class MustMayInitialize extends StructuredAnalysis { HashMap<Object, List> mapping; DavaFlowSet finalResult; public static final int MUST = 0; public static final int MAY = 1; int MUSTMAY; public MustMayInitialize(Object analyze, int MUSTorMAY) { super(); mapping = new HashMap<Object, List>(); MUSTMAY = MUSTorMAY; // System.out.println("MustOrMay value is"+MUSTorMAY); setMergeType(); // the input to the process method is an empty DavaFlow Set meaning // out(start) ={} (no var initialized) finalResult = (DavaFlowSet) process(analyze, new DavaFlowSet()); // finalResult contains the flowSet of having processed the whole of the // method } public DavaFlowSet emptyFlowSet() { return new DavaFlowSet(); } public void setMergeType() { // System.out.println("here"+MUSTMAY); if (MUSTMAY == MUST) { MERGETYPE = INTERSECTION; // System.out.println("MERGETYPE set to intersection"); } else if (MUSTMAY == MAY) { MERGETYPE = UNION; // System.out.println("MERGETYPE set to union"); } else { throw new DavaFlowAnalysisException("Only allowed 0 or 1 for MUST or MAY values"); } } /* * newInitialFlow set is used only for start of catch bodies and here we assume that no var is ever being initialized */ @Override public DavaFlowSet newInitialFlow() { return new DavaFlowSet(); } @Override public DavaFlowSet cloneFlowSet(DavaFlowSet flowSet) { return ((DavaFlowSet) flowSet).clone(); } /* * By construction conditions never have assignment statements. Hence processing a condition has no effect on this analysis */ @Override public DavaFlowSet processUnaryBinaryCondition(ASTUnaryBinaryCondition cond, DavaFlowSet input) { return input; } /* * By construction the synchronized Local is a Value and can definetly not have an assignment stmt Processing a synch local * has no effect on this analysis */ @Override public DavaFlowSet processSynchronizedLocal(Local local, DavaFlowSet input) { return input; } /* * The switch key is stored as a value and hence can never have an assignment stmt Processing the switch key has no effect * on the analysis */ @Override public DavaFlowSet processSwitchKey(Value key, DavaFlowSet input) { return input; } /* * This method internally invoked by the process method decides which Statement specialized method to call */ @Override public DavaFlowSet processStatement(Stmt s, DavaFlowSet inSet) {<FILL_FUNCTION_BODY>} public boolean isMayInitialized(SootField field) { if (MUSTMAY == MAY) { Object temp = mapping.get(field); if (temp == null) { return false; } else { List list = (List) temp; if (list.size() == 0) { return false; } else { return true; } } } else { throw new RuntimeException("Cannot invoke isMayInitialized for a MUST analysis"); } } public boolean isMayInitialized(Value local) { if (MUSTMAY == MAY) { Object temp = mapping.get(local); if (temp == null) { return false; } else { List list = (List) temp; if (list.size() == 0) { return false; } else { return true; } } } else { throw new RuntimeException("Cannot invoke isMayInitialized for a MUST analysis"); } } public boolean isMustInitialized(SootField field) { if (MUSTMAY == MUST) { if (finalResult.contains(field)) { return true; } return false; } else { throw new RuntimeException("Cannot invoke isMustinitialized for a MAY analysis"); } } public boolean isMustInitialized(Value local) { if (MUSTMAY == MUST) { if (finalResult.contains(local)) { return true; } return false; } else { throw new RuntimeException("Cannot invoke isMustinitialized for a MAY analysis"); } } /* * Given a local ask for all def positions Notice this could be null in the case there was no definition */ public List getDefs(Value local) { Object temp = mapping.get(local); if (temp == null) { return null; } else { return (List) temp; } } /* * Given a field ask for all def positions Notice this could be null in the case there was no definition */ public List getDefs(SootField field) { Object temp = mapping.get(field); if (temp == null) { return null; } else { return (List) temp; } } }
/* * If this path will not be taken return no path straightaway */ if (inSet == NOPATH) { return inSet; } if (s instanceof DefinitionStmt) { DavaFlowSet toReturn = (DavaFlowSet) cloneFlowSet(inSet); // x = expr; Value leftOp = ((DefinitionStmt) s).getLeftOp(); SootField field = null; if (leftOp instanceof Local) { toReturn.add(leftOp); /* * Gather more information just in case someone might need the def points */ Object temp = mapping.get(leftOp); List<Stmt> defs; if (temp == null) { // first definition defs = new ArrayList<Stmt>(); } else { defs = (ArrayList<Stmt>) temp; } defs.add(s); mapping.put(leftOp, defs); } else if (leftOp instanceof FieldRef) { field = ((FieldRef) leftOp).getField(); toReturn.add(field); /* * Gather more information just in case someone might need the def points */ Object temp = mapping.get(field); List<Stmt> defs; if (temp == null) { // first definition defs = new ArrayList<Stmt>(); } else { defs = (ArrayList<Stmt>) temp; } defs.add(s); mapping.put(field, defs); } return toReturn; } return inSet;
1,388
420
1,808
<methods>public void <init>() ,public abstract DavaFlowSet#RAW cloneFlowSet(DavaFlowSet#RAW) ,public void debug(java.lang.String, java.lang.String) ,public void debug(java.lang.String) ,public abstract DavaFlowSet#RAW emptyFlowSet() ,public DavaFlowSet#RAW getAfterSet(java.lang.Object) ,public DavaFlowSet#RAW getBeforeSet(java.lang.Object) ,public java.lang.String getLabel(soot.dava.internal.AST.ASTNode) ,public DavaFlowSet#RAW handleBreak(java.lang.String, DavaFlowSet#RAW, soot.dava.internal.AST.ASTNode) ,public DavaFlowSet#RAW handleContinue(java.lang.String, DavaFlowSet#RAW, soot.dava.internal.AST.ASTNode) ,public boolean isDifferent(DavaFlowSet#RAW, DavaFlowSet#RAW) ,public DavaFlowSet#RAW merge(DavaFlowSet#RAW, DavaFlowSet#RAW) ,public DavaFlowSet#RAW mergeExplicitAndImplicit(java.lang.String, DavaFlowSet#RAW, List#RAW, List#RAW) ,public abstract DavaFlowSet#RAW newInitialFlow() ,public void print(java.lang.Object) ,public DavaFlowSet#RAW process(java.lang.Object, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTIfNode(soot.dava.internal.AST.ASTIfNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTMethodNode(soot.dava.internal.AST.ASTMethodNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTNode(soot.dava.internal.AST.ASTNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTTryNode(soot.dava.internal.AST.ASTTryNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTWhileNode(soot.dava.internal.AST.ASTWhileNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processAbruptStatements(soot.jimple.Stmt, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processCondition(soot.dava.internal.AST.ASTCondition, DavaFlowSet#RAW) ,public final DavaFlowSet#RAW processSingleSubBodyNode(soot.dava.internal.AST.ASTNode, DavaFlowSet#RAW) ,public abstract DavaFlowSet#RAW processStatement(soot.jimple.Stmt, DavaFlowSet#RAW) ,public abstract DavaFlowSet#RAW processSwitchKey(soot.Value, DavaFlowSet#RAW) ,public abstract DavaFlowSet#RAW processSynchronizedLocal(soot.Local, DavaFlowSet#RAW) ,public abstract DavaFlowSet#RAW processUnaryBinaryCondition(soot.dava.internal.AST.ASTUnaryBinaryCondition, DavaFlowSet#RAW) ,public abstract void setMergeType() <variables>public static boolean DEBUG,public static boolean DEBUG_IF,public static boolean DEBUG_STATEMENTS,public static boolean DEBUG_TRY,public static boolean DEBUG_WHILE,final int INTERSECTION,public int MERGETYPE,DavaFlowSet#RAW NOPATH,final int UNDEFINED,final int UNION,HashMap#RAW afterSets,HashMap#RAW beforeSets
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/structuredAnalysis/ReachingDefs.java
ReachingDefs
processStatement
class ReachingDefs extends StructuredAnalysis<Stmt> { Object toAnalyze; public ReachingDefs(Object analyze) { super(); toAnalyze = analyze; process(analyze, new DavaFlowSet<Stmt>()); } @Override public DavaFlowSet<Stmt> emptyFlowSet() { return new DavaFlowSet<Stmt>(); } /* * Initial flow into catch statements is empty meaning no definition reaches */ @Override public DavaFlowSet<Stmt> newInitialFlow() { DavaFlowSet<Stmt> initial = new DavaFlowSet<Stmt>(); // find all definitions in the program AllDefinitionsFinder defFinder = new AllDefinitionsFinder(); ((ASTNode) toAnalyze).apply(defFinder); List<DefinitionStmt> allDefs = defFinder.getAllDefs(); // all defs is the list of all augmented stmts which contains // DefinitionStmts for (DefinitionStmt def : allDefs) { initial.add(def); } // initial is not the universal set of all definitions return initial; } /* * Using union */ public void setMergeType() { MERGETYPE = UNION; } @Override public DavaFlowSet<Stmt> cloneFlowSet(DavaFlowSet<Stmt> flowSet) { return flowSet.clone(); } /* * In the case of reachingDefs the evaluation of a condition has no effect on the reachingDefs */ @Override public DavaFlowSet<Stmt> processUnaryBinaryCondition(ASTUnaryBinaryCondition cond, DavaFlowSet<Stmt> inSet) { return inSet; } /* * In the case of reachingDefs the use of a local has no effect on reachingDefs */ @Override public DavaFlowSet<Stmt> processSynchronizedLocal(Local local, DavaFlowSet<Stmt> inSet) { return inSet; } /* * In the case of reachingDefs a value has no effect on reachingDefs */ @Override public DavaFlowSet<Stmt> processSwitchKey(Value key, DavaFlowSet<Stmt> inSet) { return inSet; } /* * This method internally invoked by the process method decides which Statement specialized method to call */ @Override public DavaFlowSet<Stmt> processStatement(Stmt s, DavaFlowSet<Stmt> inSet) {<FILL_FUNCTION_BODY>} public void gen(DavaFlowSet<Stmt> in, DefinitionStmt s) { // System.out.println("Adding Definition Stmt: "+s); in.add(s); } public void kill(DavaFlowSet<Stmt> in, Local redefined) { String redefinedLocalName = redefined.getName(); // kill any previous localpairs which have the redefined Local in the // left i.e. previous definitions for (Iterator<Stmt> listIt = in.iterator(); listIt.hasNext();) { DefinitionStmt tempStmt = (DefinitionStmt) listIt.next(); Value leftOp = tempStmt.getLeftOp(); if (leftOp instanceof Local) { String storedLocalName = ((Local) leftOp).getName(); if (redefinedLocalName.compareTo(storedLocalName) == 0) { // need to kill this from the list // System.out.println("Killing "+tempStmt); listIt.remove(); } } } } public List<DefinitionStmt> getReachingDefs(Local local, Object node) { ArrayList<DefinitionStmt> toReturn = new ArrayList<DefinitionStmt>(); // get the reaching defs of this node DavaFlowSet<Stmt> beforeSet = null; /* * If this object is some sort of loop while, for dowhile, unconditional then return after set */ if (node instanceof ASTWhileNode || node instanceof ASTDoWhileNode || node instanceof ASTUnconditionalLoopNode || node instanceof ASTForLoopNode) { beforeSet = getAfterSet(node); } else { beforeSet = getBeforeSet(node); } if (beforeSet == null) { throw new RuntimeException("Could not get reaching defs of node"); } // find all reachingdefs matching this local for (Object temp : beforeSet) { // checking each def to see if it is a def of local if (!(temp instanceof DefinitionStmt)) { throw new RuntimeException("Not an instanceof DefinitionStmt" + temp); } DefinitionStmt stmt = (DefinitionStmt) temp; Value leftOp = stmt.getLeftOp(); if (leftOp.toString().compareTo(local.toString()) == 0) { toReturn.add(stmt); } } return toReturn; } public void reachingDefsToString(Object node) { // get the reaching defs of this node DavaFlowSet<Stmt> beforeSet = null; /* * If this object is some sort of loop while, for dowhile, unconditional then return after set */ if (node instanceof ASTWhileNode || node instanceof ASTDoWhileNode || node instanceof ASTUnconditionalLoopNode || node instanceof ASTForLoopNode) { beforeSet = getAfterSet(node); } else { beforeSet = getBeforeSet(node); } if (beforeSet == null) { throw new RuntimeException("Could not get reaching defs of node"); } // find all reachingdefs matching this local for (Object o : beforeSet) { System.out.println("Reaching def:" + o); } } }
/* * If this path will not be taken return no path straightaway */ if (inSet == NOPATH) { return inSet; } if (s instanceof DefinitionStmt) { DavaFlowSet<Stmt> toReturn = cloneFlowSet(inSet); // d:x = expr // gen is x // kill is all previous defs of x Value leftOp = ((DefinitionStmt) s).getLeftOp(); if (leftOp instanceof Local) { // KILL any reaching defs of leftOp kill(toReturn, (Local) leftOp); // GEN gen(toReturn, (DefinitionStmt) s); return toReturn; } // leftop is a local } return inSet;
1,506
200
1,706
<methods>public void <init>() ,public abstract DavaFlowSet<soot.jimple.Stmt> cloneFlowSet(DavaFlowSet<soot.jimple.Stmt>) ,public void debug(java.lang.String, java.lang.String) ,public void debug(java.lang.String) ,public abstract DavaFlowSet<soot.jimple.Stmt> emptyFlowSet() ,public DavaFlowSet<soot.jimple.Stmt> getAfterSet(java.lang.Object) ,public DavaFlowSet<soot.jimple.Stmt> getBeforeSet(java.lang.Object) ,public java.lang.String getLabel(soot.dava.internal.AST.ASTNode) ,public DavaFlowSet<soot.jimple.Stmt> handleBreak(java.lang.String, DavaFlowSet<soot.jimple.Stmt>, soot.dava.internal.AST.ASTNode) ,public DavaFlowSet<soot.jimple.Stmt> handleContinue(java.lang.String, DavaFlowSet<soot.jimple.Stmt>, soot.dava.internal.AST.ASTNode) ,public boolean isDifferent(DavaFlowSet<soot.jimple.Stmt>, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> merge(DavaFlowSet<soot.jimple.Stmt>, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> mergeExplicitAndImplicit(java.lang.String, DavaFlowSet<soot.jimple.Stmt>, List<DavaFlowSet<soot.jimple.Stmt>>, List<DavaFlowSet<soot.jimple.Stmt>>) ,public abstract DavaFlowSet<soot.jimple.Stmt> newInitialFlow() ,public void print(java.lang.Object) ,public DavaFlowSet<soot.jimple.Stmt> process(java.lang.Object, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTIfNode(soot.dava.internal.AST.ASTIfNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTMethodNode(soot.dava.internal.AST.ASTMethodNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTNode(soot.dava.internal.AST.ASTNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTTryNode(soot.dava.internal.AST.ASTTryNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processASTWhileNode(soot.dava.internal.AST.ASTWhileNode, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processAbruptStatements(soot.jimple.Stmt, DavaFlowSet<soot.jimple.Stmt>) ,public DavaFlowSet<soot.jimple.Stmt> processCondition(soot.dava.internal.AST.ASTCondition, DavaFlowSet<soot.jimple.Stmt>) ,public final DavaFlowSet<soot.jimple.Stmt> processSingleSubBodyNode(soot.dava.internal.AST.ASTNode, DavaFlowSet<soot.jimple.Stmt>) ,public abstract DavaFlowSet<soot.jimple.Stmt> processStatement(soot.jimple.Stmt, DavaFlowSet<soot.jimple.Stmt>) ,public abstract DavaFlowSet<soot.jimple.Stmt> processSwitchKey(soot.Value, DavaFlowSet<soot.jimple.Stmt>) ,public abstract DavaFlowSet<soot.jimple.Stmt> processSynchronizedLocal(soot.Local, DavaFlowSet<soot.jimple.Stmt>) ,public abstract DavaFlowSet<soot.jimple.Stmt> processUnaryBinaryCondition(soot.dava.internal.AST.ASTUnaryBinaryCondition, DavaFlowSet<soot.jimple.Stmt>) ,public abstract void setMergeType() <variables>public static boolean DEBUG,public static boolean DEBUG_IF,public static boolean DEBUG_STATEMENTS,public static boolean DEBUG_TRY,public static boolean DEBUG_WHILE,final int INTERSECTION,public int MERGETYPE,DavaFlowSet<soot.jimple.Stmt> NOPATH,final int UNDEFINED,final int UNION,HashMap<java.lang.Object,DavaFlowSet<soot.jimple.Stmt>> afterSets,HashMap<java.lang.Object,DavaFlowSet<soot.jimple.Stmt>> beforeSets
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/structuredAnalysis/UnreachableCodeFinder.java
UnreachableCodeFlowSet
clone
class UnreachableCodeFlowSet extends DavaFlowSet { public UnreachableCodeFlowSet clone() {<FILL_FUNCTION_BODY>} @Override public void intersection(FlowSet otherFlow, FlowSet destFlow) { if (DEBUG) { System.out.println("In intersection"); } if (!(otherFlow instanceof UnreachableCodeFlowSet) || !(destFlow instanceof UnreachableCodeFlowSet)) { super.intersection(otherFlow, destFlow); return; } UnreachableCodeFlowSet other = (UnreachableCodeFlowSet) otherFlow; UnreachableCodeFlowSet dest = (UnreachableCodeFlowSet) destFlow; UnreachableCodeFlowSet workingSet; if (dest == other || dest == this) { workingSet = new UnreachableCodeFlowSet(); } else { workingSet = dest; workingSet.clear(); } if (other.size() != 1 || this.size() != 1) { System.out.println("Other size = " + other.size()); System.out.println("This size = " + this.size()); throw new DecompilationException("UnreachableCodeFlowSet size should always be one"); } Boolean thisPath = (Boolean) this.elements[0]; Boolean otherPath = (Boolean) other.elements[0]; if (!thisPath.booleanValue() && !otherPath.booleanValue()) { // both say there is no path workingSet.add((new Boolean(false))); } else { workingSet.add((new Boolean(true))); } (workingSet).copyInternalDataFrom(this); if (otherFlow instanceof DavaFlowSet) { (workingSet).copyInternalDataFrom((DavaFlowSet) otherFlow); } if (workingSet != dest) { workingSet.copy(dest); } if (DEBUG) { System.out.println("destFlow contains size:" + ((UnreachableCodeFlowSet) destFlow).size()); } } }
if (this.size() != 1) { throw new DecompilationException("unreachableCodeFlow set size should always be 1"); } Boolean temp = (Boolean) this.elements[0]; UnreachableCodeFlowSet toReturn = new UnreachableCodeFlowSet(); toReturn.add(new Boolean(temp.booleanValue())); toReturn.copyInternalDataFrom(this); return toReturn;
523
107
630
<methods>public void <init>() ,public abstract DavaFlowSet#RAW cloneFlowSet(DavaFlowSet#RAW) ,public void debug(java.lang.String, java.lang.String) ,public void debug(java.lang.String) ,public abstract DavaFlowSet#RAW emptyFlowSet() ,public DavaFlowSet#RAW getAfterSet(java.lang.Object) ,public DavaFlowSet#RAW getBeforeSet(java.lang.Object) ,public java.lang.String getLabel(soot.dava.internal.AST.ASTNode) ,public DavaFlowSet#RAW handleBreak(java.lang.String, DavaFlowSet#RAW, soot.dava.internal.AST.ASTNode) ,public DavaFlowSet#RAW handleContinue(java.lang.String, DavaFlowSet#RAW, soot.dava.internal.AST.ASTNode) ,public boolean isDifferent(DavaFlowSet#RAW, DavaFlowSet#RAW) ,public DavaFlowSet#RAW merge(DavaFlowSet#RAW, DavaFlowSet#RAW) ,public DavaFlowSet#RAW mergeExplicitAndImplicit(java.lang.String, DavaFlowSet#RAW, List#RAW, List#RAW) ,public abstract DavaFlowSet#RAW newInitialFlow() ,public void print(java.lang.Object) ,public DavaFlowSet#RAW process(java.lang.Object, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTIfNode(soot.dava.internal.AST.ASTIfNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTMethodNode(soot.dava.internal.AST.ASTMethodNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTNode(soot.dava.internal.AST.ASTNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTTryNode(soot.dava.internal.AST.ASTTryNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processASTWhileNode(soot.dava.internal.AST.ASTWhileNode, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processAbruptStatements(soot.jimple.Stmt, DavaFlowSet#RAW) ,public DavaFlowSet#RAW processCondition(soot.dava.internal.AST.ASTCondition, DavaFlowSet#RAW) ,public final DavaFlowSet#RAW processSingleSubBodyNode(soot.dava.internal.AST.ASTNode, DavaFlowSet#RAW) ,public abstract DavaFlowSet#RAW processStatement(soot.jimple.Stmt, DavaFlowSet#RAW) ,public abstract DavaFlowSet#RAW processSwitchKey(soot.Value, DavaFlowSet#RAW) ,public abstract DavaFlowSet#RAW processSynchronizedLocal(soot.Local, DavaFlowSet#RAW) ,public abstract DavaFlowSet#RAW processUnaryBinaryCondition(soot.dava.internal.AST.ASTUnaryBinaryCondition, DavaFlowSet#RAW) ,public abstract void setMergeType() <variables>public static boolean DEBUG,public static boolean DEBUG_IF,public static boolean DEBUG_STATEMENTS,public static boolean DEBUG_TRY,public static boolean DEBUG_WHILE,final int INTERSECTION,public int MERGETYPE,DavaFlowSet#RAW NOPATH,final int UNDEFINED,final int UNION,HashMap#RAW afterSets,HashMap#RAW beforeSets
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/AndAggregator.java
AndAggregator
changeUses
class AndAggregator extends DepthFirstAdapter { public AndAggregator() { } public AndAggregator(boolean verbose) { super(verbose); } public void caseASTStatementSequenceNode(ASTStatementSequenceNode node) { } public void outASTIfNode(ASTIfNode node) { List<Object> bodies = node.get_SubBodies(); if (bodies.size() == 1) { // this should always be one since there is // only one body of an if statement List body = (List) bodies.get(0); // this is the if body check to see if this is a single if Node if (body.size() == 1) { // size is good ASTNode bodyNode = (ASTNode) body.get(0); if (bodyNode instanceof ASTIfNode) { /* * We can do AndAggregation at this point node contains the outer if (ASTIfNode)bodyNode is the inner if */ ASTCondition outerCond = node.get_Condition(); ASTCondition innerCond = ((ASTIfNode) bodyNode).get_Condition(); SETNodeLabel outerLabel = (node).get_Label(); SETNodeLabel innerLabel = ((ASTIfNode) bodyNode).get_Label(); SETNodeLabel newLabel = null; if (outerLabel.toString() == null && innerLabel.toString() == null) { newLabel = outerLabel; } else if (outerLabel.toString() != null && innerLabel.toString() == null) { newLabel = outerLabel; } else if (outerLabel.toString() == null && innerLabel.toString() != null) { newLabel = innerLabel; } else if (outerLabel.toString() != null && innerLabel.toString() != null) { newLabel = outerLabel; // however we have to change all occurance of inner // label to point to that // of outerlabel now changeUses(outerLabel.toString(), innerLabel.toString(), bodyNode); } // aggregate the conditions ASTCondition newCond = new ASTAndCondition(outerCond, innerCond); // Get the body of the inner Node that will be the overall // body List<Object> newBodyList = ((ASTIfNode) bodyNode).get_SubBodies(); // retireve the actual body List if (newBodyList.size() == 1) { // should always be one since // this is body of IF List<Object> newBody = (List<Object>) newBodyList.get(0); node.replace(newLabel, newCond, newBody); // System.out.println("ANDDDDDD AGGREGATING !!!"); G.v().ASTTransformations_modified = true; } } else { // not an if node } } else { // IfBody has more than 1 nodes cant do AND aggregation } } } private void changeUses(String to, String from, ASTNode node) {<FILL_FUNCTION_BODY>} }
// remember this method is only called when "to" and "from" are both non // null List<Object> subBodies = node.get_SubBodies(); Iterator<Object> it = subBodies.iterator(); while (it.hasNext()) { // going over all subBodies if (node instanceof ASTStatementSequenceNode) { // check for abrupt stmts ASTStatementSequenceNode stmtSeq = (ASTStatementSequenceNode) node; for (AugmentedStmt as : stmtSeq.getStatements()) { Stmt s = as.get_Stmt(); if (s instanceof DAbruptStmt) { DAbruptStmt abStmt = (DAbruptStmt) s; if (abStmt.is_Break() || abStmt.is_Continue()) { SETNodeLabel label = abStmt.getLabel(); String labelBroken = label.toString(); if (labelBroken != null) { // stmt breaks some label if (labelBroken.compareTo(from) == 0) { // have to replace the "from" label to "to" // label label.set_Name(to); } } } } } } else { // need to recursively call changeUses List subBodyNodes = null; if (node instanceof ASTTryNode) { ASTTryNode.container subBody = (ASTTryNode.container) it.next(); subBodyNodes = (List) subBody.o; } else { subBodyNodes = (List) it.next(); } Iterator nodesIt = subBodyNodes.iterator(); while (nodesIt.hasNext()) { changeUses(to, from, (ASTNode) nodesIt.next()); } } } // going through subBodies
771
477
1,248
<methods>public void <init>() ,public void <init>(boolean) ,public void caseASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void caseASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void caseASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void caseASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void caseASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void caseASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void caseASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void caseASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void caseASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void caseASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void caseASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void caseASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void caseASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void caseASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void caseASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void caseASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void caseArrayRef(soot.jimple.ArrayRef) ,public void caseBinopExpr(soot.jimple.BinopExpr) ,public void caseCastExpr(soot.jimple.CastExpr) ,public void caseDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void caseDefinitionStmt(soot.jimple.DefinitionStmt) ,public void caseExpr(soot.jimple.Expr) ,public void caseExprOrRefValueBox(soot.ValueBox) ,public void caseInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void caseInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void caseInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void caseInvokeExpr(soot.jimple.InvokeExpr) ,public void caseInvokeStmt(soot.jimple.InvokeStmt) ,public void caseNewArrayExpr(soot.jimple.NewArrayExpr) ,public void caseNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void caseRef(soot.jimple.Ref) ,public void caseReturnStmt(soot.jimple.ReturnStmt) ,public void caseStaticFieldRef(soot.jimple.StaticFieldRef) ,public void caseStmt(soot.jimple.Stmt) ,public void caseThrowStmt(soot.jimple.ThrowStmt) ,public void caseType(soot.Type) ,public void caseUnopExpr(soot.jimple.UnopExpr) ,public void caseValue(soot.Value) ,public void debug(java.lang.String, java.lang.String, java.lang.String) ,public void decideCaseExpr(soot.jimple.Expr) ,public void decideCaseExprOrRef(soot.Value) ,public void decideCaseRef(soot.jimple.Ref) ,public void inASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void inASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void inASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void inASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void inASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void inASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void inASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void inASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void inASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void inASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void inASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void inASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void inASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void inASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void inASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void inASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void inArrayRef(soot.jimple.ArrayRef) ,public void inBinopExpr(soot.jimple.BinopExpr) ,public void inCastExpr(soot.jimple.CastExpr) ,public void inDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void inDefinitionStmt(soot.jimple.DefinitionStmt) ,public void inExpr(soot.jimple.Expr) ,public void inExprOrRefValueBox(soot.ValueBox) ,public void inInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void inInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void inInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void inInvokeExpr(soot.jimple.InvokeExpr) ,public void inInvokeStmt(soot.jimple.InvokeStmt) ,public void inNewArrayExpr(soot.jimple.NewArrayExpr) ,public void inNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void inRef(soot.jimple.Ref) ,public void inReturnStmt(soot.jimple.ReturnStmt) ,public void inStaticFieldRef(soot.jimple.StaticFieldRef) ,public void inStmt(soot.jimple.Stmt) ,public void inThrowStmt(soot.jimple.ThrowStmt) ,public void inType(soot.Type) ,public void inUnopExpr(soot.jimple.UnopExpr) ,public void inValue(soot.Value) ,public void normalRetrieving(soot.dava.internal.AST.ASTNode) ,public void outASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void outASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void outASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void outASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void outASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void outASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void outASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void outASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void outASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void outASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void outASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void outASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void outASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void outASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void outASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void outASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void outArrayRef(soot.jimple.ArrayRef) ,public void outBinopExpr(soot.jimple.BinopExpr) ,public void outCastExpr(soot.jimple.CastExpr) ,public void outDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void outDefinitionStmt(soot.jimple.DefinitionStmt) ,public void outExpr(soot.jimple.Expr) ,public void outExprOrRefValueBox(soot.ValueBox) ,public void outInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void outInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void outInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void outInvokeExpr(soot.jimple.InvokeExpr) ,public void outInvokeStmt(soot.jimple.InvokeStmt) ,public void outNewArrayExpr(soot.jimple.NewArrayExpr) ,public void outNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void outRef(soot.jimple.Ref) ,public void outReturnStmt(soot.jimple.ReturnStmt) ,public void outStaticFieldRef(soot.jimple.StaticFieldRef) ,public void outStmt(soot.jimple.Stmt) ,public void outThrowStmt(soot.jimple.ThrowStmt) ,public void outType(soot.Type) ,public void outUnopExpr(soot.jimple.UnopExpr) ,public void outValue(soot.Value) <variables>public boolean DEBUG,boolean verbose
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/BooleanConditionSimplification.java
BooleanConditionSimplification
outASTIfNode
class BooleanConditionSimplification extends DepthFirstAdapter { public BooleanConditionSimplification(boolean verbose) { super(verbose); } public void caseASTStatementSequenceNode(ASTStatementSequenceNode node) { } public BooleanConditionSimplification() { } /* * The method checks whether a particular ASTBinaryCondition is a comparison of a local with a boolean If so the * ASTBinaryCondition is replaced by a ASTUnaryCondition */ public void outASTIfNode(ASTIfNode node) {<FILL_FUNCTION_BODY>} public void outASTIfElseNode(ASTIfElseNode node) { ASTCondition condition = node.get_Condition(); if (condition instanceof ASTBinaryCondition) { ConditionExpr condExpr = ((ASTBinaryCondition) condition).getConditionExpr(); Value unary = checkBooleanUse(condExpr); if (unary != null) { node.set_Condition(new ASTUnaryCondition(unary)); } } } public void outASTWhileNode(ASTWhileNode node) { ASTCondition condition = node.get_Condition(); if (condition instanceof ASTBinaryCondition) { ConditionExpr condExpr = ((ASTBinaryCondition) condition).getConditionExpr(); Value unary = checkBooleanUse(condExpr); if (unary != null) { node.set_Condition(new ASTUnaryCondition(unary)); } } } public void outASTDoWhileNode(ASTDoWhileNode node) { ASTCondition condition = node.get_Condition(); if (condition instanceof ASTBinaryCondition) { ConditionExpr condExpr = ((ASTBinaryCondition) condition).getConditionExpr(); Value unary = checkBooleanUse(condExpr); if (unary != null) { node.set_Condition(new ASTUnaryCondition(unary)); } } } private Value checkBooleanUse(ConditionExpr condition) { // check whether the condition qualifies as a boolean use if (condition instanceof NeExpr || condition instanceof EqExpr) { Value op1 = condition.getOp1(); Value op2 = condition.getOp2(); if (op1 instanceof DIntConstant) { Type op1Type = ((DIntConstant) op1).type; if (op1Type instanceof BooleanType) { return decideCondition(op2, ((DIntConstant) op1).toString(), condition); } } else if (op2 instanceof DIntConstant) { Type op2Type = ((DIntConstant) op2).type; if (op2Type instanceof BooleanType) { return decideCondition(op1, ((DIntConstant) op2).toString(), condition); } } else { return null;// meaning no Value used as boolean found } } return null; // meaning no local used as boolean found } /* * Used to decide what the condition should be if we are converting from ConditionExpr to Value A != false/0 --> A A != * true/1 --> !A A == false/0 --> !A A == true/1 --> A */ private Value decideCondition(Value A, String truthString, ConditionExpr condition) { int truthValue = 0; boolean notEqual = false; // find out whether we are dealing with a false or true if (truthString.compareTo("false") == 0) { truthValue = 0; } else if (truthString.compareTo("true") == 0) { truthValue = 1; } else { throw new RuntimeException(); } // find out whether the comparison operator is != or == if (condition instanceof NeExpr) { notEqual = true; } else if (condition instanceof EqExpr) { notEqual = false; } else { throw new RuntimeException(); } // decide and return if (notEqual && truthValue == 0) { // A != false -->A return A; } else if (notEqual && truthValue == 1) { // A != true --> !A if (A instanceof DNotExpr) { // A is actually !B return ((DNotExpr) A).getOp(); } else { return (new DNotExpr(A)); } } else if (!notEqual && truthValue == 0) { // A == false --> !A if (A instanceof DNotExpr) { // A is actually !B return ((DNotExpr) A).getOp(); } else { return new DNotExpr(A); } } else if (!notEqual && truthValue == 1) { // A == true --> A return A; } else { throw new RuntimeException(); } } }
ASTCondition condition = node.get_Condition(); if (condition instanceof ASTBinaryCondition) { ConditionExpr condExpr = ((ASTBinaryCondition) condition).getConditionExpr(); Value unary = checkBooleanUse(condExpr); if (unary != null) { node.set_Condition(new ASTUnaryCondition(unary)); } }
1,202
94
1,296
<methods>public void <init>() ,public void <init>(boolean) ,public void caseASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void caseASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void caseASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void caseASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void caseASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void caseASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void caseASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void caseASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void caseASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void caseASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void caseASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void caseASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void caseASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void caseASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void caseASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void caseASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void caseArrayRef(soot.jimple.ArrayRef) ,public void caseBinopExpr(soot.jimple.BinopExpr) ,public void caseCastExpr(soot.jimple.CastExpr) ,public void caseDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void caseDefinitionStmt(soot.jimple.DefinitionStmt) ,public void caseExpr(soot.jimple.Expr) ,public void caseExprOrRefValueBox(soot.ValueBox) ,public void caseInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void caseInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void caseInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void caseInvokeExpr(soot.jimple.InvokeExpr) ,public void caseInvokeStmt(soot.jimple.InvokeStmt) ,public void caseNewArrayExpr(soot.jimple.NewArrayExpr) ,public void caseNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void caseRef(soot.jimple.Ref) ,public void caseReturnStmt(soot.jimple.ReturnStmt) ,public void caseStaticFieldRef(soot.jimple.StaticFieldRef) ,public void caseStmt(soot.jimple.Stmt) ,public void caseThrowStmt(soot.jimple.ThrowStmt) ,public void caseType(soot.Type) ,public void caseUnopExpr(soot.jimple.UnopExpr) ,public void caseValue(soot.Value) ,public void debug(java.lang.String, java.lang.String, java.lang.String) ,public void decideCaseExpr(soot.jimple.Expr) ,public void decideCaseExprOrRef(soot.Value) ,public void decideCaseRef(soot.jimple.Ref) ,public void inASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void inASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void inASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void inASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void inASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void inASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void inASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void inASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void inASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void inASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void inASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void inASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void inASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void inASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void inASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void inASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void inArrayRef(soot.jimple.ArrayRef) ,public void inBinopExpr(soot.jimple.BinopExpr) ,public void inCastExpr(soot.jimple.CastExpr) ,public void inDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void inDefinitionStmt(soot.jimple.DefinitionStmt) ,public void inExpr(soot.jimple.Expr) ,public void inExprOrRefValueBox(soot.ValueBox) ,public void inInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void inInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void inInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void inInvokeExpr(soot.jimple.InvokeExpr) ,public void inInvokeStmt(soot.jimple.InvokeStmt) ,public void inNewArrayExpr(soot.jimple.NewArrayExpr) ,public void inNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void inRef(soot.jimple.Ref) ,public void inReturnStmt(soot.jimple.ReturnStmt) ,public void inStaticFieldRef(soot.jimple.StaticFieldRef) ,public void inStmt(soot.jimple.Stmt) ,public void inThrowStmt(soot.jimple.ThrowStmt) ,public void inType(soot.Type) ,public void inUnopExpr(soot.jimple.UnopExpr) ,public void inValue(soot.Value) ,public void normalRetrieving(soot.dava.internal.AST.ASTNode) ,public void outASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void outASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void outASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void outASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void outASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void outASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void outASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void outASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void outASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void outASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void outASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void outASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void outASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void outASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void outASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void outASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void outArrayRef(soot.jimple.ArrayRef) ,public void outBinopExpr(soot.jimple.BinopExpr) ,public void outCastExpr(soot.jimple.CastExpr) ,public void outDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void outDefinitionStmt(soot.jimple.DefinitionStmt) ,public void outExpr(soot.jimple.Expr) ,public void outExprOrRefValueBox(soot.ValueBox) ,public void outInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void outInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void outInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void outInvokeExpr(soot.jimple.InvokeExpr) ,public void outInvokeStmt(soot.jimple.InvokeStmt) ,public void outNewArrayExpr(soot.jimple.NewArrayExpr) ,public void outNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void outRef(soot.jimple.Ref) ,public void outReturnStmt(soot.jimple.ReturnStmt) ,public void outStaticFieldRef(soot.jimple.StaticFieldRef) ,public void outStmt(soot.jimple.Stmt) ,public void outThrowStmt(soot.jimple.ThrowStmt) ,public void outType(soot.Type) ,public void outUnopExpr(soot.jimple.UnopExpr) ,public void outValue(soot.Value) <variables>public boolean DEBUG,boolean verbose
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/DecrementIncrementStmtCreation.java
DecrementIncrementStmtCreation
caseASTStatementSequenceNode
class DecrementIncrementStmtCreation extends DepthFirstAdapter { public DecrementIncrementStmtCreation() { } public DecrementIncrementStmtCreation(boolean verbose) { super(verbose); } public void caseASTStatementSequenceNode(ASTStatementSequenceNode node) {<FILL_FUNCTION_BODY>} }
for (AugmentedStmt as : node.getStatements()) { // System.out.println(temp); Stmt s = as.get_Stmt(); if (!(s instanceof DefinitionStmt)) { continue; } // check if its i= i+1 Value left = ((DefinitionStmt) s).getLeftOp(); Value right = ((DefinitionStmt) s).getRightOp(); if (right instanceof SubExpr) { Value op1 = ((SubExpr) right).getOp1(); Value op2 = ((SubExpr) right).getOp2(); if (left.toString().compareTo(op1.toString()) != 0) { // not the same continue; } // if they are the same // check if op2 is a constant with value 1 or -1 if (op2 instanceof IntConstant) { if (((IntConstant) op2).value == 1) { // this is i = i-1 DDecrementStmt newStmt = new DDecrementStmt(left, right); as.set_Stmt(newStmt); } else if (((IntConstant) op2).value == -1) { // this is i = i+1 DIncrementStmt newStmt = new DIncrementStmt(left, right); as.set_Stmt(newStmt); } } } else if (right instanceof AddExpr) { Value op1 = ((AddExpr) right).getOp1(); Value op2 = ((AddExpr) right).getOp2(); if (left.toString().compareTo(op1.toString()) != 0) { continue; } // check if op2 is a constant with value 1 or -1 if (op2 instanceof IntConstant) { if (((IntConstant) op2).value == 1) { // this is i = i+1 DIncrementStmt newStmt = new DIncrementStmt(left, right); as.set_Stmt(newStmt); } else if (((IntConstant) op2).value == -1) { // this is i = i-1 DDecrementStmt newStmt = new DDecrementStmt(left, right); as.set_Stmt(newStmt); } } } // right expr was addExpr } // going through statements
99
610
709
<methods>public void <init>() ,public void <init>(boolean) ,public void caseASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void caseASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void caseASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void caseASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void caseASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void caseASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void caseASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void caseASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void caseASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void caseASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void caseASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void caseASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void caseASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void caseASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void caseASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void caseASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void caseArrayRef(soot.jimple.ArrayRef) ,public void caseBinopExpr(soot.jimple.BinopExpr) ,public void caseCastExpr(soot.jimple.CastExpr) ,public void caseDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void caseDefinitionStmt(soot.jimple.DefinitionStmt) ,public void caseExpr(soot.jimple.Expr) ,public void caseExprOrRefValueBox(soot.ValueBox) ,public void caseInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void caseInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void caseInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void caseInvokeExpr(soot.jimple.InvokeExpr) ,public void caseInvokeStmt(soot.jimple.InvokeStmt) ,public void caseNewArrayExpr(soot.jimple.NewArrayExpr) ,public void caseNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void caseRef(soot.jimple.Ref) ,public void caseReturnStmt(soot.jimple.ReturnStmt) ,public void caseStaticFieldRef(soot.jimple.StaticFieldRef) ,public void caseStmt(soot.jimple.Stmt) ,public void caseThrowStmt(soot.jimple.ThrowStmt) ,public void caseType(soot.Type) ,public void caseUnopExpr(soot.jimple.UnopExpr) ,public void caseValue(soot.Value) ,public void debug(java.lang.String, java.lang.String, java.lang.String) ,public void decideCaseExpr(soot.jimple.Expr) ,public void decideCaseExprOrRef(soot.Value) ,public void decideCaseRef(soot.jimple.Ref) ,public void inASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void inASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void inASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void inASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void inASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void inASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void inASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void inASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void inASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void inASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void inASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void inASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void inASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void inASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void inASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void inASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void inArrayRef(soot.jimple.ArrayRef) ,public void inBinopExpr(soot.jimple.BinopExpr) ,public void inCastExpr(soot.jimple.CastExpr) ,public void inDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void inDefinitionStmt(soot.jimple.DefinitionStmt) ,public void inExpr(soot.jimple.Expr) ,public void inExprOrRefValueBox(soot.ValueBox) ,public void inInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void inInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void inInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void inInvokeExpr(soot.jimple.InvokeExpr) ,public void inInvokeStmt(soot.jimple.InvokeStmt) ,public void inNewArrayExpr(soot.jimple.NewArrayExpr) ,public void inNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void inRef(soot.jimple.Ref) ,public void inReturnStmt(soot.jimple.ReturnStmt) ,public void inStaticFieldRef(soot.jimple.StaticFieldRef) ,public void inStmt(soot.jimple.Stmt) ,public void inThrowStmt(soot.jimple.ThrowStmt) ,public void inType(soot.Type) ,public void inUnopExpr(soot.jimple.UnopExpr) ,public void inValue(soot.Value) ,public void normalRetrieving(soot.dava.internal.AST.ASTNode) ,public void outASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void outASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void outASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void outASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void outASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void outASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void outASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void outASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void outASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void outASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void outASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void outASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void outASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void outASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void outASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void outASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void outArrayRef(soot.jimple.ArrayRef) ,public void outBinopExpr(soot.jimple.BinopExpr) ,public void outCastExpr(soot.jimple.CastExpr) ,public void outDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void outDefinitionStmt(soot.jimple.DefinitionStmt) ,public void outExpr(soot.jimple.Expr) ,public void outExprOrRefValueBox(soot.ValueBox) ,public void outInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void outInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void outInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void outInvokeExpr(soot.jimple.InvokeExpr) ,public void outInvokeStmt(soot.jimple.InvokeStmt) ,public void outNewArrayExpr(soot.jimple.NewArrayExpr) ,public void outNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void outRef(soot.jimple.Ref) ,public void outReturnStmt(soot.jimple.ReturnStmt) ,public void outStaticFieldRef(soot.jimple.StaticFieldRef) ,public void outStmt(soot.jimple.Stmt) ,public void outThrowStmt(soot.jimple.ThrowStmt) ,public void outType(soot.Type) ,public void outUnopExpr(soot.jimple.UnopExpr) ,public void outValue(soot.Value) <variables>public boolean DEBUG,boolean verbose
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/EmptyElseRemover.java
EmptyElseRemover
createNewNodeBody
class EmptyElseRemover { public static void removeElseBody(ASTNode node, ASTIfElseNode ifElseNode, int subBodyNumber, int nodeNumber) { if (!(node instanceof ASTIfElseNode)) { // these are the nodes which always have one subBody List<Object> subBodies = node.get_SubBodies(); if (subBodies.size() != 1) { // there is something wrong throw new RuntimeException("Please report this benchmark to the programmer"); } List<Object> onlySubBody = (List<Object>) subBodies.get(0); /* * The onlySubBody contains the ASTIfElseNode whose elsebody has to be removed at location given by the nodeNumber * variable */ List<Object> newBody = createNewNodeBody(onlySubBody, nodeNumber, ifElseNode); if (newBody == null) { // something went wrong return; } if (node instanceof ASTMethodNode) { ((ASTMethodNode) node).replaceBody(newBody); G.v().ASTTransformations_modified = true; // System.out.println("REMOVED ELSE BODY"); } else if (node instanceof ASTSynchronizedBlockNode) { ((ASTSynchronizedBlockNode) node).replaceBody(newBody); G.v().ASTTransformations_modified = true; // System.out.println("REMOVED ELSE BODY"); } else if (node instanceof ASTLabeledBlockNode) { ((ASTLabeledBlockNode) node).replaceBody(newBody); G.v().ASTTransformations_modified = true; // System.out.println("REMOVED ELSE BODY"); } else if (node instanceof ASTUnconditionalLoopNode) { ((ASTUnconditionalLoopNode) node).replaceBody(newBody); G.v().ASTTransformations_modified = true; // System.out.println("REMOVED ELSE BODY"); } else if (node instanceof ASTIfNode) { ((ASTIfNode) node).replaceBody(newBody); G.v().ASTTransformations_modified = true; // System.out.println("REMOVED ELSE BODY"); } else if (node instanceof ASTWhileNode) { ((ASTWhileNode) node).replaceBody(newBody); G.v().ASTTransformations_modified = true; // System.out.println("REMOVED ELSE BODY"); } else if (node instanceof ASTDoWhileNode) { ((ASTDoWhileNode) node).replaceBody(newBody); G.v().ASTTransformations_modified = true; // System.out.println("REMOVED ELSE BODY"); } else { // there is no other case something is wrong if we get here return; } } else { // its an ASTIfElseNode // if its an ASIfElseNode then check which Subbody has the labeledBlock if (subBodyNumber != 0 && subBodyNumber != 1) { // something bad is happening dont do nothin // System.out.println("Error-------not modifying AST"); return; } List<Object> subBodies = node.get_SubBodies(); if (subBodies.size() != 2) { // there is something wrong throw new RuntimeException("Please report this benchmark to the programmer"); } List<Object> toModifySubBody = (List<Object>) subBodies.get(subBodyNumber); /* * The toModifySubBody contains the ASTIfElseNode to be removed at location given by the nodeNumber variable */ List<Object> newBody = createNewNodeBody(toModifySubBody, nodeNumber, ifElseNode); if (newBody == null) { // something went wrong return; } if (subBodyNumber == 0) { // the if body was modified // System.out.println("REMOVED ELSE BODY"); G.v().ASTTransformations_modified = true; ((ASTIfElseNode) node).replaceBody(newBody, (List<Object>) subBodies.get(1)); } else if (subBodyNumber == 1) { // else body was modified // System.out.println("REMOVED ELSE BODY"); G.v().ASTTransformations_modified = true; ((ASTIfElseNode) node).replaceBody((List<Object>) subBodies.get(0), newBody); } else { // realllly shouldnt come here // something bad is happening dont do nothin // System.out.println("Error-------not modifying AST"); return; } } // end of ASTIfElseNode } public static List<Object> createNewNodeBody(List<Object> oldSubBody, int nodeNumber, ASTIfElseNode ifElseNode) {<FILL_FUNCTION_BODY>} }
// create a new SubBody List<Object> newSubBody = new ArrayList<Object>(); // this is an iterator of ASTNodes Iterator<Object> it = oldSubBody.iterator(); // copy to newSubBody all nodes until you get to nodeNumber int index = 0; while (index != nodeNumber) { if (!it.hasNext()) { return null; } newSubBody.add(it.next()); index++; } // at this point the iterator is pointing to the ASTIfElseNode to be removed // just to make sure check this ASTNode toRemove = (ASTNode) it.next(); if (!(toRemove instanceof ASTIfElseNode)) { // something is wrong return null; } else { ASTIfElseNode toRemoveNode = (ASTIfElseNode) toRemove; // just double checking that this is a empty else node List<Object> elseBody = toRemoveNode.getElseBody(); if (elseBody.size() != 0) { // something is wrong we cant remove a non empty elsebody return null; } // so this is the ElseBody to remove // need to create an ASTIfNode from the ASTIfElseNode ASTIfNode newNode = new ASTIfNode(toRemoveNode.get_Label(), toRemoveNode.get_Condition(), toRemoveNode.getIfBody()); // add this node to the newSubBody newSubBody.add(newNode); } // add any remaining nodes in the oldSubBody to the new one while (it.hasNext()) { newSubBody.add(it.next()); } // newSubBody is ready return it return newSubBody;
1,280
456
1,736
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/IfElseBreaker.java
IfElseBreaker
checkStmt
class IfElseBreaker { ASTIfNode newIfNode; List<Object> remainingBody; public IfElseBreaker() { newIfNode = null; remainingBody = null; } public boolean isIfElseBreakingPossiblePatternOne(ASTIfElseNode node) { List<Object> ifBody = node.getIfBody(); if (ifBody.size() != 1) { // we are only interested if size is one return false; } ASTNode onlyNode = (ASTNode) ifBody.get(0); boolean check = checkStmt(onlyNode, node); if (!check) { return false; } // breaking is possible // break and store newIfNode = new ASTIfNode(((ASTLabeledNode) node).get_Label(), node.get_Condition(), ifBody); remainingBody = node.getElseBody(); return true; } public boolean isIfElseBreakingPossiblePatternTwo(ASTIfElseNode node) { List<Object> elseBody = node.getElseBody(); if (elseBody.size() != 1) { // we are only interested if size is one return false; } ASTNode onlyNode = (ASTNode) elseBody.get(0); boolean check = checkStmt(onlyNode, node); if (!check) { return false; } // breaking is possible ASTCondition cond = node.get_Condition(); // flip cond.flip(); newIfNode = new ASTIfNode(((ASTLabeledNode) node).get_Label(), cond, elseBody); remainingBody = node.getIfBody(); return true; } private boolean checkStmt(ASTNode onlyNode, ASTIfElseNode node) {<FILL_FUNCTION_BODY>} /* * The purpose of this method is to replace the ASTIfElseNode given by the var nodeNumber with the new ASTIfNode and to add * the remianing list of bodies after this ASTIfNode * * The new body is then returned; * */ public List<Object> createNewBody(List<Object> oldSubBody, int nodeNumber) { if (newIfNode == null) { return null; } List<Object> newSubBody = new ArrayList<Object>(); if (oldSubBody.size() <= nodeNumber) { // something is wrong since the oldSubBody has lesser nodes than nodeNumber return null; } Iterator<Object> oldIt = oldSubBody.iterator(); int index = 0; while (index != nodeNumber) { newSubBody.add(oldIt.next()); index++; } // check to see that the next is an ASTIfElseNode ASTNode temp = (ASTNode) oldIt.next(); if (!(temp instanceof ASTIfElseNode)) { return null; } newSubBody.add(newIfNode); newSubBody.addAll(remainingBody); // copy any remaining nodes while (oldIt.hasNext()) { newSubBody.add(oldIt.next()); } return newSubBody; } }
if (!(onlyNode instanceof ASTStatementSequenceNode)) { // only interested in StmtSeq nodes return false; } ASTStatementSequenceNode stmtNode = (ASTStatementSequenceNode) onlyNode; List<AugmentedStmt> statements = stmtNode.getStatements(); if (statements.size() != 1) { // need one stmt only return false; } AugmentedStmt as = statements.get(0); Stmt stmt = as.get_Stmt(); if (!(stmt instanceof DAbruptStmt)) { // interested in abrupt stmts only return false; } DAbruptStmt abStmt = (DAbruptStmt) stmt; if (!(abStmt.is_Break() || abStmt.is_Continue())) { // interested in breaks and continues only return false; } // make sure that the break is not that of the if // unliekly but good to check SETNodeLabel ifLabel = ((ASTLabeledNode) node).get_Label(); if (ifLabel != null) { if (ifLabel.toString() != null) { if (abStmt.is_Break()) { String breakLabel = abStmt.getLabel().toString(); if (breakLabel != null) { if (breakLabel.compareTo(ifLabel.toString()) == 0) { // is a break of this label return false; } } } } } return true;
844
399
1,243
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/LocalVariableCleaner.java
LocalVariableCleaner
removeStmt
class LocalVariableCleaner extends DepthFirstAdapter { public final boolean DEBUG = false; ASTNode AST; ASTUsesAndDefs useDefs; ASTParentNodeFinder parentOf; public LocalVariableCleaner(ASTNode AST) { super(); this.AST = AST; parentOf = new ASTParentNodeFinder(); AST.apply(parentOf); } public LocalVariableCleaner(boolean verbose, ASTNode AST) { super(verbose); this.AST = AST; parentOf = new ASTParentNodeFinder(); AST.apply(parentOf); } /* * Get all locals declared in the method If the local is never defined (and hence never used) remove it If the local is * defined BUT never used then you may remove it IF AND ONLY IF The definition is either a copy stmt or an assignment of a * constant (i.e. no side effects) */ public void outASTMethodNode(ASTMethodNode node) { boolean redo = false; useDefs = new ASTUsesAndDefs(AST); // create the uD and dU chains AST.apply(useDefs); // get all local variables declared in this method Iterator decIt = node.getDeclaredLocals().iterator(); ArrayList<Local> removeList = new ArrayList<Local>(); while (decIt.hasNext()) { // going through each local declared Local var = (Local) decIt.next(); List<DefinitionStmt> defs = getDefs(var); // if defs is 0 it means var never got defined if (defs.size() == 0) { // var is never defined and hence is certainly not used anywhere removeList.add(var); } else { // if a var is defined but not used then in some conditions we can remove it // check that each def is removable Iterator<DefinitionStmt> defIt = defs.iterator(); while (defIt.hasNext()) { DefinitionStmt ds = defIt.next(); if (canRemoveDef(ds)) { // if removeStmt is successful since something change we need to redo // everything hoping something else might be removed.... // in this case method returns true redo = removeStmt(ds); } } // while going through defs } // end else defs was not zero } // going through each stmt // go through the removeList and remove all locals Iterator<Local> remIt = removeList.iterator(); while (remIt.hasNext()) { Local removeLocal = remIt.next(); node.removeDeclaredLocal(removeLocal); /* * Nomair A. Naeem 7th Feb 2005 these have to be removed from the legacy lists in DavaBody also * */ // retrieve DavaBody if (AST instanceof ASTMethodNode) { // this should always be true but whatever DavaBody body = ((ASTMethodNode) AST).getDavaBody(); if (DEBUG) { System.out.println("body information"); System.out.println("Control local is: " + body.get_ControlLocal()); System.out.println("his locals are: " + body.get_ThisLocals()); System.out.println("Param Map is: " + body.get_ParamMap()); System.out.println("Locals are:" + body.getLocals()); } Collection<Local> localChain = body.getLocals(); if (removeLocal != null && localChain != null) { localChain.remove(removeLocal); } } else { throw new DecompilationException("found AST which is not a methodNode"); } if (DEBUG) { System.out.println("Removed" + removeLocal); } redo = true; } if (redo) { // redo the whole function outASTMethodNode(node); } } /* * A def can be removed if and only if: 1, there are no uses of this definition 2, the right hand size is either a local or * a constant i.e. no need to worry about side effects */ public boolean canRemoveDef(DefinitionStmt ds) { List uses = useDefs.getDUChain(ds); if (uses.size() != 0) { return false; } // there is no use of this def, we can remove it if it is copy stmt or a constant assignment if (ds.getRightOp() instanceof Local || ds.getRightOp() instanceof Constant) { return true; } return false; } /* * This method looks up all defs and returns those of this local */ public List<DefinitionStmt> getDefs(Local var) { List<DefinitionStmt> toReturn = new ArrayList<DefinitionStmt>(); HashMap<Object, List> dU = useDefs.getDUHashMap(); Iterator<Object> it = dU.keySet().iterator(); while (it.hasNext()) { DefinitionStmt s = (DefinitionStmt) it.next(); Value left = s.getLeftOp(); if (left instanceof Local) { if (((Local) left).getName().compareTo(var.getName()) == 0) { toReturn.add(s); } } } return toReturn; } public boolean removeStmt(Stmt stmt) {<FILL_FUNCTION_BODY>} }
Object tempParent = parentOf.getParentOf(stmt); if (tempParent == null) { // System.out.println("NO PARENT FOUND CANT DO ANYTHING"); return false; } // parents are always ASTNodes, hence safe to cast ASTNode parent = (ASTNode) tempParent; // REMOVING STMT if (!(parent instanceof ASTStatementSequenceNode)) { // parent of a statement should always be a ASTStatementSequenceNode return false; } ASTStatementSequenceNode parentNode = (ASTStatementSequenceNode) parent; ArrayList<AugmentedStmt> newSequence = new ArrayList<AugmentedStmt>(); int size = parentNode.getStatements().size(); for (AugmentedStmt as : parentNode.getStatements()) { Stmt s = as.get_Stmt(); if (s.toString().compareTo(stmt.toString()) != 0) { // this is not the stmt to be removed newSequence.add(as); } } // System.out.println("STMT REMOVED---------------->"+stmt); parentNode.setStatements(newSequence); if (newSequence.size() < size) { return true; // size of new node is smaller than orignal size } return false;// didnt actually delete anything for some weird reason...shouldnt happen
1,424
356
1,780
<methods>public void <init>() ,public void <init>(boolean) ,public void caseASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void caseASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void caseASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void caseASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void caseASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void caseASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void caseASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void caseASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void caseASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void caseASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void caseASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void caseASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void caseASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void caseASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void caseASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void caseASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void caseArrayRef(soot.jimple.ArrayRef) ,public void caseBinopExpr(soot.jimple.BinopExpr) ,public void caseCastExpr(soot.jimple.CastExpr) ,public void caseDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void caseDefinitionStmt(soot.jimple.DefinitionStmt) ,public void caseExpr(soot.jimple.Expr) ,public void caseExprOrRefValueBox(soot.ValueBox) ,public void caseInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void caseInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void caseInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void caseInvokeExpr(soot.jimple.InvokeExpr) ,public void caseInvokeStmt(soot.jimple.InvokeStmt) ,public void caseNewArrayExpr(soot.jimple.NewArrayExpr) ,public void caseNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void caseRef(soot.jimple.Ref) ,public void caseReturnStmt(soot.jimple.ReturnStmt) ,public void caseStaticFieldRef(soot.jimple.StaticFieldRef) ,public void caseStmt(soot.jimple.Stmt) ,public void caseThrowStmt(soot.jimple.ThrowStmt) ,public void caseType(soot.Type) ,public void caseUnopExpr(soot.jimple.UnopExpr) ,public void caseValue(soot.Value) ,public void debug(java.lang.String, java.lang.String, java.lang.String) ,public void decideCaseExpr(soot.jimple.Expr) ,public void decideCaseExprOrRef(soot.Value) ,public void decideCaseRef(soot.jimple.Ref) ,public void inASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void inASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void inASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void inASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void inASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void inASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void inASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void inASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void inASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void inASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void inASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void inASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void inASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void inASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void inASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void inASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void inArrayRef(soot.jimple.ArrayRef) ,public void inBinopExpr(soot.jimple.BinopExpr) ,public void inCastExpr(soot.jimple.CastExpr) ,public void inDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void inDefinitionStmt(soot.jimple.DefinitionStmt) ,public void inExpr(soot.jimple.Expr) ,public void inExprOrRefValueBox(soot.ValueBox) ,public void inInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void inInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void inInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void inInvokeExpr(soot.jimple.InvokeExpr) ,public void inInvokeStmt(soot.jimple.InvokeStmt) ,public void inNewArrayExpr(soot.jimple.NewArrayExpr) ,public void inNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void inRef(soot.jimple.Ref) ,public void inReturnStmt(soot.jimple.ReturnStmt) ,public void inStaticFieldRef(soot.jimple.StaticFieldRef) ,public void inStmt(soot.jimple.Stmt) ,public void inThrowStmt(soot.jimple.ThrowStmt) ,public void inType(soot.Type) ,public void inUnopExpr(soot.jimple.UnopExpr) ,public void inValue(soot.Value) ,public void normalRetrieving(soot.dava.internal.AST.ASTNode) ,public void outASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void outASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void outASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void outASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void outASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void outASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void outASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void outASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void outASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void outASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void outASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void outASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void outASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void outASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void outASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void outASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void outArrayRef(soot.jimple.ArrayRef) ,public void outBinopExpr(soot.jimple.BinopExpr) ,public void outCastExpr(soot.jimple.CastExpr) ,public void outDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void outDefinitionStmt(soot.jimple.DefinitionStmt) ,public void outExpr(soot.jimple.Expr) ,public void outExprOrRefValueBox(soot.ValueBox) ,public void outInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void outInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void outInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void outInvokeExpr(soot.jimple.InvokeExpr) ,public void outInvokeStmt(soot.jimple.InvokeStmt) ,public void outNewArrayExpr(soot.jimple.NewArrayExpr) ,public void outNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void outRef(soot.jimple.Ref) ,public void outReturnStmt(soot.jimple.ReturnStmt) ,public void outStaticFieldRef(soot.jimple.StaticFieldRef) ,public void outStmt(soot.jimple.Stmt) ,public void outThrowStmt(soot.jimple.ThrowStmt) ,public void outType(soot.Type) ,public void outUnopExpr(soot.jimple.UnopExpr) ,public void outValue(soot.Value) <variables>public boolean DEBUG,boolean verbose
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/NewStringBufferSimplification.java
NewStringBufferSimplification
inExprOrRefValueBox
class NewStringBufferSimplification extends DepthFirstAdapter { public static boolean DEBUG = false; public NewStringBufferSimplification() { } public NewStringBufferSimplification(boolean verbose) { super(verbose); } public void inExprOrRefValueBox(ValueBox argBox) {<FILL_FUNCTION_BODY>} }
if (DEBUG) { System.out.println("ValBox is: " + argBox.toString()); } Value tempArgValue = argBox.getValue(); if (DEBUG) { System.out.println("arg value is: " + tempArgValue); } if (!(tempArgValue instanceof DVirtualInvokeExpr)) { if (DEBUG) { System.out.println("Not a DVirtualInvokeExpr" + tempArgValue.getClass()); } return; } // check this is a toString for StringBuffer if (DEBUG) { System.out.println("arg value is a virtual invokeExpr"); } DVirtualInvokeExpr vInvokeExpr = ((DVirtualInvokeExpr) tempArgValue); // need this try catch since DavaStmtHandler expr will not have a "getMethod" try { if (!(vInvokeExpr.getMethod().toString().equals("<java.lang.StringBuffer: java.lang.String toString()>"))) { return; } } catch (Exception e) { return; } if (DEBUG) { System.out.println("Ends in toString()"); } Value base = vInvokeExpr.getBase(); List args = new ArrayList(); while (base instanceof DVirtualInvokeExpr) { DVirtualInvokeExpr tempV = (DVirtualInvokeExpr) base; if (DEBUG) { System.out.println("base method is " + tempV.getMethod()); } if (!tempV.getMethod().toString().startsWith("<java.lang.StringBuffer: java.lang.StringBuffer append")) { if (DEBUG) { System.out.println("Found a virtual invoke which is not a append" + tempV.getMethod()); } return; } args.add(0, tempV.getArg(0)); // System.out.println("Append: "+((DVirtualInvokeExpr)base).getArg(0) ); // move to next base base = ((DVirtualInvokeExpr) base).getBase(); } if (!(base instanceof DNewInvokeExpr)) { return; } if (DEBUG) { System.out.println("New expr is " + ((DNewInvokeExpr) base).getMethod()); } if (!((DNewInvokeExpr) base).getMethod().toString().equals("<java.lang.StringBuffer: void <init>()>")) { return; } /* * The arg is a new invoke expr of StringBuffer and all the appends are present in the args list */ if (DEBUG) { System.out.println("Found a new StringBuffer.append list in it"); } // argBox contains the new StringBuffer Iterator it = args.iterator(); Value newVal = null; while (it.hasNext()) { Value temp = (Value) it.next(); if (newVal == null) { newVal = temp; } else { // create newVal + temp newVal = new GAddExpr(newVal, temp); } } if (DEBUG) { System.out.println("New expression for System.out.println is" + newVal); } argBox.setValue(newVal);
97
846
943
<methods>public void <init>() ,public void <init>(boolean) ,public void caseASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void caseASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void caseASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void caseASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void caseASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void caseASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void caseASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void caseASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void caseASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void caseASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void caseASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void caseASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void caseASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void caseASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void caseASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void caseASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void caseArrayRef(soot.jimple.ArrayRef) ,public void caseBinopExpr(soot.jimple.BinopExpr) ,public void caseCastExpr(soot.jimple.CastExpr) ,public void caseDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void caseDefinitionStmt(soot.jimple.DefinitionStmt) ,public void caseExpr(soot.jimple.Expr) ,public void caseExprOrRefValueBox(soot.ValueBox) ,public void caseInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void caseInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void caseInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void caseInvokeExpr(soot.jimple.InvokeExpr) ,public void caseInvokeStmt(soot.jimple.InvokeStmt) ,public void caseNewArrayExpr(soot.jimple.NewArrayExpr) ,public void caseNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void caseRef(soot.jimple.Ref) ,public void caseReturnStmt(soot.jimple.ReturnStmt) ,public void caseStaticFieldRef(soot.jimple.StaticFieldRef) ,public void caseStmt(soot.jimple.Stmt) ,public void caseThrowStmt(soot.jimple.ThrowStmt) ,public void caseType(soot.Type) ,public void caseUnopExpr(soot.jimple.UnopExpr) ,public void caseValue(soot.Value) ,public void debug(java.lang.String, java.lang.String, java.lang.String) ,public void decideCaseExpr(soot.jimple.Expr) ,public void decideCaseExprOrRef(soot.Value) ,public void decideCaseRef(soot.jimple.Ref) ,public void inASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void inASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void inASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void inASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void inASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void inASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void inASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void inASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void inASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void inASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void inASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void inASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void inASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void inASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void inASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void inASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void inArrayRef(soot.jimple.ArrayRef) ,public void inBinopExpr(soot.jimple.BinopExpr) ,public void inCastExpr(soot.jimple.CastExpr) ,public void inDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void inDefinitionStmt(soot.jimple.DefinitionStmt) ,public void inExpr(soot.jimple.Expr) ,public void inExprOrRefValueBox(soot.ValueBox) ,public void inInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void inInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void inInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void inInvokeExpr(soot.jimple.InvokeExpr) ,public void inInvokeStmt(soot.jimple.InvokeStmt) ,public void inNewArrayExpr(soot.jimple.NewArrayExpr) ,public void inNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void inRef(soot.jimple.Ref) ,public void inReturnStmt(soot.jimple.ReturnStmt) ,public void inStaticFieldRef(soot.jimple.StaticFieldRef) ,public void inStmt(soot.jimple.Stmt) ,public void inThrowStmt(soot.jimple.ThrowStmt) ,public void inType(soot.Type) ,public void inUnopExpr(soot.jimple.UnopExpr) ,public void inValue(soot.Value) ,public void normalRetrieving(soot.dava.internal.AST.ASTNode) ,public void outASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void outASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void outASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void outASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void outASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void outASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void outASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void outASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void outASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void outASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void outASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void outASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void outASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void outASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void outASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void outASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void outArrayRef(soot.jimple.ArrayRef) ,public void outBinopExpr(soot.jimple.BinopExpr) ,public void outCastExpr(soot.jimple.CastExpr) ,public void outDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void outDefinitionStmt(soot.jimple.DefinitionStmt) ,public void outExpr(soot.jimple.Expr) ,public void outExprOrRefValueBox(soot.ValueBox) ,public void outInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void outInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void outInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void outInvokeExpr(soot.jimple.InvokeExpr) ,public void outInvokeStmt(soot.jimple.InvokeStmt) ,public void outNewArrayExpr(soot.jimple.NewArrayExpr) ,public void outNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void outRef(soot.jimple.Ref) ,public void outReturnStmt(soot.jimple.ReturnStmt) ,public void outStaticFieldRef(soot.jimple.StaticFieldRef) ,public void outStmt(soot.jimple.Stmt) ,public void outThrowStmt(soot.jimple.ThrowStmt) ,public void outType(soot.Type) ,public void outUnopExpr(soot.jimple.UnopExpr) ,public void outValue(soot.Value) <variables>public boolean DEBUG,boolean verbose
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/OrAggregatorTwo.java
OrAggregatorTwo
matchPatternTwo
class OrAggregatorTwo extends DepthFirstAdapter { public OrAggregatorTwo() { DEBUG = false; } public OrAggregatorTwo(boolean verbose) { super(verbose); DEBUG = false; } public void caseASTStatementSequenceNode(ASTStatementSequenceNode node) { } public void outASTIfElseNode(ASTIfElseNode node) { // check whether the else body has another if and nothing else List<Object> ifBody = node.getIfBody(); List<Object> elseBody = node.getElseBody(); List<Object> innerIfBody = checkElseHasOnlyIf(elseBody); // pattern 1 is fine till now // compare the ifBody with the innerIfBody // They need to match exactly if ((innerIfBody == null) || (ifBody.toString().compareTo(innerIfBody.toString()) != 0)) { matchPatternTwo(node); return; } ASTCondition leftCond = node.get_Condition(); ASTCondition rightCond = getRightCond(elseBody); ASTCondition newCond = new ASTOrCondition(leftCond, rightCond); /* * The outer if and inner if could both have labels. Note that if the inner if had a label which was broken from inside * its body the two bodies would not have been the same since the outerifbody could not have the same label. * * We therefore keep the outerIfElse label */ // System.out.println("OR AGGREGATOR TWO"); node.set_Condition(newCond); /* * Always have to follow with a parse to remove unwanted empty ElseBodies */ node.replaceElseBody(new ArrayList<Object>()); G.v().ASTTransformations_modified = true; } public ASTCondition getRightCond(List<Object> elseBody) { // We know from checkElseHasOnlyIf that there is only one node // in this body and it is an ASTIfNode ASTIfNode innerIfNode = (ASTIfNode) elseBody.get(0); return innerIfNode.get_Condition(); } public List<Object> checkElseHasOnlyIf(List<Object> elseBody) { if (elseBody.size() != 1) { // there should only be on IfNode here return null; } // there is only one node check that its a ASTIFNode ASTNode temp = (ASTNode) elseBody.get(0); if (!(temp instanceof ASTIfNode)) { // should have been an If node to match the pattern return null; } ASTIfNode innerIfNode = (ASTIfNode) temp; List<Object> innerIfBody = innerIfNode.getIfBody(); return innerIfBody; } public void matchPatternTwo(ASTIfElseNode node) {<FILL_FUNCTION_BODY>} }
debug("OrAggregatorTwo", "matchPatternTwo", "Did not match patternOne...trying patternTwo"); List<Object> ifBody = node.getIfBody(); if (ifBody.size() != 1) { // we are only interested if size is one return; } ASTNode onlyNode = (ASTNode) ifBody.get(0); if (!(onlyNode instanceof ASTStatementSequenceNode)) { // only interested in StmtSeq nodes return; } ASTStatementSequenceNode stmtNode = (ASTStatementSequenceNode) onlyNode; List<AugmentedStmt> statements = stmtNode.getStatements(); if (statements.size() != 1) { // there is more than one statement return; } // there is only one statement AugmentedStmt as = statements.get(0); Stmt stmt = as.get_Stmt(); if (!(stmt instanceof DAbruptStmt)) { // this is not a break/continue stmt return; } DAbruptStmt abStmt = (DAbruptStmt) stmt; if (!(abStmt.is_Break() || abStmt.is_Continue())) { // not a break/continue return; } // pattern matched // flip condition and switch bodies ASTCondition cond = node.get_Condition(); cond.flip(); List<Object> elseBody = node.getElseBody(); SETNodeLabel label = node.get_Label(); node.replace(label, cond, elseBody, ifBody); debug("", "", "REVERSED CONDITIONS AND BODIES"); debug("", "", "elseBody is" + elseBody); debug("", "", "ifBody is" + ifBody); G.v().ASTIfElseFlipped = true;
749
478
1,227
<methods>public void <init>() ,public void <init>(boolean) ,public void caseASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void caseASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void caseASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void caseASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void caseASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void caseASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void caseASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void caseASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void caseASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void caseASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void caseASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void caseASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void caseASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void caseASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void caseASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void caseASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void caseArrayRef(soot.jimple.ArrayRef) ,public void caseBinopExpr(soot.jimple.BinopExpr) ,public void caseCastExpr(soot.jimple.CastExpr) ,public void caseDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void caseDefinitionStmt(soot.jimple.DefinitionStmt) ,public void caseExpr(soot.jimple.Expr) ,public void caseExprOrRefValueBox(soot.ValueBox) ,public void caseInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void caseInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void caseInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void caseInvokeExpr(soot.jimple.InvokeExpr) ,public void caseInvokeStmt(soot.jimple.InvokeStmt) ,public void caseNewArrayExpr(soot.jimple.NewArrayExpr) ,public void caseNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void caseRef(soot.jimple.Ref) ,public void caseReturnStmt(soot.jimple.ReturnStmt) ,public void caseStaticFieldRef(soot.jimple.StaticFieldRef) ,public void caseStmt(soot.jimple.Stmt) ,public void caseThrowStmt(soot.jimple.ThrowStmt) ,public void caseType(soot.Type) ,public void caseUnopExpr(soot.jimple.UnopExpr) ,public void caseValue(soot.Value) ,public void debug(java.lang.String, java.lang.String, java.lang.String) ,public void decideCaseExpr(soot.jimple.Expr) ,public void decideCaseExprOrRef(soot.Value) ,public void decideCaseRef(soot.jimple.Ref) ,public void inASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void inASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void inASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void inASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void inASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void inASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void inASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void inASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void inASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void inASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void inASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void inASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void inASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void inASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void inASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void inASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void inArrayRef(soot.jimple.ArrayRef) ,public void inBinopExpr(soot.jimple.BinopExpr) ,public void inCastExpr(soot.jimple.CastExpr) ,public void inDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void inDefinitionStmt(soot.jimple.DefinitionStmt) ,public void inExpr(soot.jimple.Expr) ,public void inExprOrRefValueBox(soot.ValueBox) ,public void inInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void inInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void inInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void inInvokeExpr(soot.jimple.InvokeExpr) ,public void inInvokeStmt(soot.jimple.InvokeStmt) ,public void inNewArrayExpr(soot.jimple.NewArrayExpr) ,public void inNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void inRef(soot.jimple.Ref) ,public void inReturnStmt(soot.jimple.ReturnStmt) ,public void inStaticFieldRef(soot.jimple.StaticFieldRef) ,public void inStmt(soot.jimple.Stmt) ,public void inThrowStmt(soot.jimple.ThrowStmt) ,public void inType(soot.Type) ,public void inUnopExpr(soot.jimple.UnopExpr) ,public void inValue(soot.Value) ,public void normalRetrieving(soot.dava.internal.AST.ASTNode) ,public void outASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void outASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void outASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void outASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void outASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void outASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void outASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void outASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void outASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void outASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void outASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void outASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void outASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void outASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void outASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void outASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void outArrayRef(soot.jimple.ArrayRef) ,public void outBinopExpr(soot.jimple.BinopExpr) ,public void outCastExpr(soot.jimple.CastExpr) ,public void outDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void outDefinitionStmt(soot.jimple.DefinitionStmt) ,public void outExpr(soot.jimple.Expr) ,public void outExprOrRefValueBox(soot.ValueBox) ,public void outInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void outInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void outInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void outInvokeExpr(soot.jimple.InvokeExpr) ,public void outInvokeStmt(soot.jimple.InvokeStmt) ,public void outNewArrayExpr(soot.jimple.NewArrayExpr) ,public void outNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void outRef(soot.jimple.Ref) ,public void outReturnStmt(soot.jimple.ReturnStmt) ,public void outStaticFieldRef(soot.jimple.StaticFieldRef) ,public void outStmt(soot.jimple.Stmt) ,public void outThrowStmt(soot.jimple.ThrowStmt) ,public void outType(soot.Type) ,public void outUnopExpr(soot.jimple.UnopExpr) ,public void outValue(soot.Value) <variables>public boolean DEBUG,boolean verbose
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/RemoveEmptyBodyDefaultConstructor.java
RemoveEmptyBodyDefaultConstructor
checkAndRemoveDefault
class RemoveEmptyBodyDefaultConstructor { public static boolean DEBUG = false; public static void checkAndRemoveDefault(SootClass s) {<FILL_FUNCTION_BODY>} public static void debug(String debug) { if (DEBUG) { System.out.println("DEBUG: " + debug); } } }
debug("\n\nRemoveEmptyBodyDefaultConstructor----" + s.getName()); List methods = s.getMethods(); Iterator it = methods.iterator(); List<SootMethod> constructors = new ArrayList<SootMethod>(); while (it.hasNext()) { SootMethod method = (SootMethod) it.next(); debug("method name is" + method.getName()); if (method.getName().indexOf("<init>") > -1) { // constructor add to constructor list constructors.add(method); } } if (constructors.size() != 1) { // cant do anything since there are more than one constructors debug("class has more than one constructors cant do anything"); return; } // only one constructor check its default (no arguments) SootMethod constructor = constructors.get(0); if (constructor.getParameterCount() != 0) { // can only deal with default constructors debug("constructor is not the default constructor"); return; } debug("Check that the body is empty....and call to super contains no arguments and delete"); if (!constructor.hasActiveBody()) { debug("No active body found for the default constructor"); return; } if (!constructor.isPublic()) { debug("Default constructor is not public."); return; } Body body = constructor.getActiveBody(); Chain units = ((DavaBody) body).getUnits(); if (units.size() != 1) { debug(" DavaBody AST does not have single root"); return; } ASTNode AST = (ASTNode) units.getFirst(); if (!(AST instanceof ASTMethodNode)) { throw new RuntimeException("Starting node of DavaBody AST is not an ASTMethodNode"); } ASTMethodNode methodNode = (ASTMethodNode) AST; debug("got methodnode check body is empty and super has nothing in it"); List<Object> subBodies = methodNode.get_SubBodies(); if (subBodies.size() != 1) { debug("Method node does not have one subBody!!!"); return; } List methodBody = (List) subBodies.get(0); if (methodBody.size() != 0) { debug("Method body size is greater than 1 so cant do nothing"); return; } debug("Method body is empty...check super call is empty"); if (((DavaBody) body).get_ConstructorExpr().getArgCount() != 0) { debug("call to super not empty"); return; } debug("REMOVE METHOD"); s.removeMethod(constructor);
88
698
786
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/SimplifyExpressions.java
SimplifyExpressions
getResult
class SimplifyExpressions extends DepthFirstAdapter { public static boolean DEBUG = false; public SimplifyExpressions() { super(); } public SimplifyExpressions(boolean verbose) { super(verbose); } /* * public void inASTBinaryCondition(ASTBinaryCondition cond){ ConditionExpr condExpr = cond.getConditionExpr(); * * ValueBox op1Box = condExpr.getOp1Box(); * * ValueBox op2Box = condExpr.getOp2Box(); } */ public void outExprOrRefValueBox(ValueBox vb) { // System.out.println("here"+vb); Value v = vb.getValue(); if (!(v instanceof BinopExpr)) { return; } BinopExpr binop = (BinopExpr) v; if (DEBUG) { System.out.println("calling getResult"); } NumericConstant constant = getResult(binop); if (constant == null) { return; } if (DEBUG) { System.out.println("Changin" + vb + " to...." + constant); } vb.setValue(constant); } public NumericConstant getResult(BinopExpr binop) {<FILL_FUNCTION_BODY>} }
if (DEBUG) { System.out.println("Binop expr" + binop); } Value leftOp = binop.getOp1(); Value rightOp = binop.getOp2(); int op = 0; if (binop instanceof AddExpr) { op = 1; } else if (binop instanceof SubExpr || binop instanceof DCmpExpr || binop instanceof DCmpgExpr || binop instanceof DCmplExpr) { op = 2; } else if (binop instanceof MulExpr) { op = 3; } if (op == 0) { if (DEBUG) { System.out.println("not add sub or mult"); System.out.println(binop.getClass().getName()); } return null; } NumericConstant constant = null; if (leftOp instanceof LongConstant && rightOp instanceof LongConstant) { if (DEBUG) { System.out.println("long constants!!"); } if (op == 1) { constant = ((LongConstant) leftOp).add((LongConstant) rightOp); } else if (op == 2) { constant = ((LongConstant) leftOp).subtract((LongConstant) rightOp); } else if (op == 3) { constant = ((LongConstant) leftOp).multiply((LongConstant) rightOp); } } else if (leftOp instanceof DoubleConstant && rightOp instanceof DoubleConstant) { if (DEBUG) { System.out.println("double constants!!"); } if (op == 1) { constant = ((DoubleConstant) leftOp).add((DoubleConstant) rightOp); } else if (op == 2) { constant = ((DoubleConstant) leftOp).subtract((DoubleConstant) rightOp); } else if (op == 3) { constant = ((DoubleConstant) leftOp).multiply((DoubleConstant) rightOp); } } else if (leftOp instanceof FloatConstant && rightOp instanceof FloatConstant) { if (DEBUG) { System.out.println("Float constants!!"); } if (op == 1) { constant = ((FloatConstant) leftOp).add((FloatConstant) rightOp); } else if (op == 2) { constant = ((FloatConstant) leftOp).subtract((FloatConstant) rightOp); } else if (op == 3) { constant = ((FloatConstant) leftOp).multiply((FloatConstant) rightOp); } } else if (leftOp instanceof IntConstant && rightOp instanceof IntConstant) { if (DEBUG) { System.out.println("Integer constants!!"); } if (op == 1) { constant = ((IntConstant) leftOp).add((IntConstant) rightOp); } else if (op == 2) { constant = ((IntConstant) leftOp).subtract((IntConstant) rightOp); } else if (op == 3) { constant = ((IntConstant) leftOp).multiply((IntConstant) rightOp); } } return constant;
357
774
1,131
<methods>public void <init>() ,public void <init>(boolean) ,public void caseASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void caseASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void caseASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void caseASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void caseASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void caseASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void caseASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void caseASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void caseASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void caseASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void caseASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void caseASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void caseASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void caseASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void caseASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void caseASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void caseArrayRef(soot.jimple.ArrayRef) ,public void caseBinopExpr(soot.jimple.BinopExpr) ,public void caseCastExpr(soot.jimple.CastExpr) ,public void caseDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void caseDefinitionStmt(soot.jimple.DefinitionStmt) ,public void caseExpr(soot.jimple.Expr) ,public void caseExprOrRefValueBox(soot.ValueBox) ,public void caseInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void caseInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void caseInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void caseInvokeExpr(soot.jimple.InvokeExpr) ,public void caseInvokeStmt(soot.jimple.InvokeStmt) ,public void caseNewArrayExpr(soot.jimple.NewArrayExpr) ,public void caseNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void caseRef(soot.jimple.Ref) ,public void caseReturnStmt(soot.jimple.ReturnStmt) ,public void caseStaticFieldRef(soot.jimple.StaticFieldRef) ,public void caseStmt(soot.jimple.Stmt) ,public void caseThrowStmt(soot.jimple.ThrowStmt) ,public void caseType(soot.Type) ,public void caseUnopExpr(soot.jimple.UnopExpr) ,public void caseValue(soot.Value) ,public void debug(java.lang.String, java.lang.String, java.lang.String) ,public void decideCaseExpr(soot.jimple.Expr) ,public void decideCaseExprOrRef(soot.Value) ,public void decideCaseRef(soot.jimple.Ref) ,public void inASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void inASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void inASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void inASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void inASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void inASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void inASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void inASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void inASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void inASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void inASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void inASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void inASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void inASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void inASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void inASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void inArrayRef(soot.jimple.ArrayRef) ,public void inBinopExpr(soot.jimple.BinopExpr) ,public void inCastExpr(soot.jimple.CastExpr) ,public void inDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void inDefinitionStmt(soot.jimple.DefinitionStmt) ,public void inExpr(soot.jimple.Expr) ,public void inExprOrRefValueBox(soot.ValueBox) ,public void inInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void inInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void inInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void inInvokeExpr(soot.jimple.InvokeExpr) ,public void inInvokeStmt(soot.jimple.InvokeStmt) ,public void inNewArrayExpr(soot.jimple.NewArrayExpr) ,public void inNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void inRef(soot.jimple.Ref) ,public void inReturnStmt(soot.jimple.ReturnStmt) ,public void inStaticFieldRef(soot.jimple.StaticFieldRef) ,public void inStmt(soot.jimple.Stmt) ,public void inThrowStmt(soot.jimple.ThrowStmt) ,public void inType(soot.Type) ,public void inUnopExpr(soot.jimple.UnopExpr) ,public void inValue(soot.Value) ,public void normalRetrieving(soot.dava.internal.AST.ASTNode) ,public void outASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void outASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void outASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void outASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void outASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void outASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void outASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void outASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void outASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void outASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void outASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void outASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void outASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void outASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void outASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void outASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void outArrayRef(soot.jimple.ArrayRef) ,public void outBinopExpr(soot.jimple.BinopExpr) ,public void outCastExpr(soot.jimple.CastExpr) ,public void outDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void outDefinitionStmt(soot.jimple.DefinitionStmt) ,public void outExpr(soot.jimple.Expr) ,public void outExprOrRefValueBox(soot.ValueBox) ,public void outInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void outInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void outInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void outInvokeExpr(soot.jimple.InvokeExpr) ,public void outInvokeStmt(soot.jimple.InvokeStmt) ,public void outNewArrayExpr(soot.jimple.NewArrayExpr) ,public void outNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void outRef(soot.jimple.Ref) ,public void outReturnStmt(soot.jimple.ReturnStmt) ,public void outStaticFieldRef(soot.jimple.StaticFieldRef) ,public void outStmt(soot.jimple.Stmt) ,public void outThrowStmt(soot.jimple.ThrowStmt) ,public void outType(soot.Type) ,public void outUnopExpr(soot.jimple.UnopExpr) ,public void outValue(soot.Value) <variables>public boolean DEBUG,boolean verbose
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/UselessAbruptStmtRemover.java
UselessAbruptStmtRemover
caseASTStatementSequenceNode
class UselessAbruptStmtRemover extends DepthFirstAdapter { public static boolean DEBUG = false; ASTParentNodeFinder finder; ASTMethodNode methodNode; LabelToNodeMapper mapper; public UselessAbruptStmtRemover() { finder = null; } public UselessAbruptStmtRemover(boolean verbose) { super(verbose); finder = null; } public void inASTMethodNode(ASTMethodNode node) { methodNode = node; mapper = new LabelToNodeMapper(); methodNode.apply(mapper); } public void caseASTStatementSequenceNode(ASTStatementSequenceNode node) {<FILL_FUNCTION_BODY>} public boolean checkChildLastInParent(ASTNode child, ASTNode parent) { List<Object> subBodies = parent.get_SubBodies(); Iterator<Object> it = subBodies.iterator(); while (it.hasNext()) { List subBody = null; if (parent instanceof ASTTryNode) { subBody = (List) ((ASTTryNode.container) it.next()).o; } else { subBody = (List) it.next(); } if (subBody.contains(child)) { if (subBody.indexOf(child) != subBody.size() - 1) { return false; } else { return true; } } } return false; } }
Iterator<AugmentedStmt> it = node.getStatements().iterator(); AugmentedStmt remove = null; ASTLabeledNode target = null; while (it.hasNext()) { AugmentedStmt as = it.next(); Stmt s = as.get_Stmt(); // we only care about break and continue stmts if (!(s instanceof DAbruptStmt)) { continue; } DAbruptStmt abrupt = (DAbruptStmt) s; String label = abrupt.getLabel().toString(); if (label == null) { // could at some time implement a version of the same // analysis with implicit abrupt flow but not needed currently continue; } if (it.hasNext()) { // there is an abrupt stmt and this stmt seq node has something // afterwards...that is for sure dead code throw new DecompilationException("Dead code detected. Report to developer"); } // get the target node Object temp = mapper.getTarget(label); if (temp == null) { continue; // throw new DecompilationException("Could not find target for abrupt stmt"+abrupt.toString()); } target = (ASTLabeledNode) temp; // will need to find parents of ancestors see if we need to initialize the finder if (finder == null) { finder = new ASTParentNodeFinder(); methodNode.apply(finder); } if (DEBUG) { System.out.println("Starting useless check for abrupt stmt: " + abrupt); } // start condition is that ancestor is the stmt seq node ASTNode ancestor = node; while (ancestor != target) { Object tempParent = finder.getParentOf(ancestor); if (tempParent == null) { throw new DecompilationException("Parent found was null!!. Report to Developer"); } ASTNode ancestorsParent = (ASTNode) tempParent; if (DEBUG) { System.out.println("\tCurrent ancestorsParent has type" + ancestorsParent.getClass()); } // ancestor should be last child of ancestorsParent if (!checkChildLastInParent(ancestor, ancestorsParent)) { if (DEBUG) { System.out.println("\t\tCurrent ancestorParent has more children after this ancestor"); } // return from the method since this is the last stmt and we cant do anything return; } // ancestorsParent should not be a loop of any kind OR A SWITCH if (ancestorsParent instanceof ASTWhileNode || ancestorsParent instanceof ASTDoWhileNode || ancestorsParent instanceof ASTUnconditionalLoopNode || ancestorsParent instanceof ASTForLoopNode || ancestorsParent instanceof ASTSwitchNode) { if (DEBUG) { System.out.println("\t\tAncestorsParent is a loop shouldnt remove abrupt stmt"); } return; } ancestor = ancestorsParent; } if (DEBUG) { System.out.println("\tGot to target without returning means we can remove stmt"); } remove = as; } // end of while going through the statement sequence if (remove != null) { List<AugmentedStmt> stmts = node.getStatements(); stmts.remove(remove); if (DEBUG) { System.out.println("\tRemoved abrupt stmt"); } if (target != null) { if (DEBUG) { System.out.println("Invoking findAndKill on the target"); } UselessLabelFinder.v().findAndKill(target); } // TODO what if we just emptied a stmt seq block?? // not doing this for the moment // set modified flag make finder null G.v().ASTTransformations_modified = true; finder = null; }
394
1,026
1,420
<methods>public void <init>() ,public void <init>(boolean) ,public void caseASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void caseASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void caseASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void caseASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void caseASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void caseASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void caseASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void caseASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void caseASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void caseASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void caseASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void caseASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void caseASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void caseASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void caseASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void caseASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void caseArrayRef(soot.jimple.ArrayRef) ,public void caseBinopExpr(soot.jimple.BinopExpr) ,public void caseCastExpr(soot.jimple.CastExpr) ,public void caseDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void caseDefinitionStmt(soot.jimple.DefinitionStmt) ,public void caseExpr(soot.jimple.Expr) ,public void caseExprOrRefValueBox(soot.ValueBox) ,public void caseInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void caseInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void caseInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void caseInvokeExpr(soot.jimple.InvokeExpr) ,public void caseInvokeStmt(soot.jimple.InvokeStmt) ,public void caseNewArrayExpr(soot.jimple.NewArrayExpr) ,public void caseNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void caseRef(soot.jimple.Ref) ,public void caseReturnStmt(soot.jimple.ReturnStmt) ,public void caseStaticFieldRef(soot.jimple.StaticFieldRef) ,public void caseStmt(soot.jimple.Stmt) ,public void caseThrowStmt(soot.jimple.ThrowStmt) ,public void caseType(soot.Type) ,public void caseUnopExpr(soot.jimple.UnopExpr) ,public void caseValue(soot.Value) ,public void debug(java.lang.String, java.lang.String, java.lang.String) ,public void decideCaseExpr(soot.jimple.Expr) ,public void decideCaseExprOrRef(soot.Value) ,public void decideCaseRef(soot.jimple.Ref) ,public void inASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void inASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void inASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void inASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void inASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void inASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void inASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void inASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void inASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void inASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void inASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void inASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void inASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void inASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void inASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void inASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void inArrayRef(soot.jimple.ArrayRef) ,public void inBinopExpr(soot.jimple.BinopExpr) ,public void inCastExpr(soot.jimple.CastExpr) ,public void inDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void inDefinitionStmt(soot.jimple.DefinitionStmt) ,public void inExpr(soot.jimple.Expr) ,public void inExprOrRefValueBox(soot.ValueBox) ,public void inInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void inInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void inInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void inInvokeExpr(soot.jimple.InvokeExpr) ,public void inInvokeStmt(soot.jimple.InvokeStmt) ,public void inNewArrayExpr(soot.jimple.NewArrayExpr) ,public void inNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void inRef(soot.jimple.Ref) ,public void inReturnStmt(soot.jimple.ReturnStmt) ,public void inStaticFieldRef(soot.jimple.StaticFieldRef) ,public void inStmt(soot.jimple.Stmt) ,public void inThrowStmt(soot.jimple.ThrowStmt) ,public void inType(soot.Type) ,public void inUnopExpr(soot.jimple.UnopExpr) ,public void inValue(soot.Value) ,public void normalRetrieving(soot.dava.internal.AST.ASTNode) ,public void outASTAndCondition(soot.dava.internal.AST.ASTAndCondition) ,public void outASTBinaryCondition(soot.dava.internal.AST.ASTBinaryCondition) ,public void outASTDoWhileNode(soot.dava.internal.AST.ASTDoWhileNode) ,public void outASTForLoopNode(soot.dava.internal.AST.ASTForLoopNode) ,public void outASTIfElseNode(soot.dava.internal.AST.ASTIfElseNode) ,public void outASTIfNode(soot.dava.internal.AST.ASTIfNode) ,public void outASTLabeledBlockNode(soot.dava.internal.AST.ASTLabeledBlockNode) ,public void outASTMethodNode(soot.dava.internal.AST.ASTMethodNode) ,public void outASTOrCondition(soot.dava.internal.AST.ASTOrCondition) ,public void outASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) ,public void outASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode) ,public void outASTSynchronizedBlockNode(soot.dava.internal.AST.ASTSynchronizedBlockNode) ,public void outASTTryNode(soot.dava.internal.AST.ASTTryNode) ,public void outASTUnaryCondition(soot.dava.internal.AST.ASTUnaryCondition) ,public void outASTUnconditionalLoopNode(soot.dava.internal.AST.ASTUnconditionalLoopNode) ,public void outASTWhileNode(soot.dava.internal.AST.ASTWhileNode) ,public void outArrayRef(soot.jimple.ArrayRef) ,public void outBinopExpr(soot.jimple.BinopExpr) ,public void outCastExpr(soot.jimple.CastExpr) ,public void outDVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) ,public void outDefinitionStmt(soot.jimple.DefinitionStmt) ,public void outExpr(soot.jimple.Expr) ,public void outExprOrRefValueBox(soot.ValueBox) ,public void outInstanceFieldRef(soot.jimple.InstanceFieldRef) ,public void outInstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) ,public void outInstanceOfExpr(soot.jimple.InstanceOfExpr) ,public void outInvokeExpr(soot.jimple.InvokeExpr) ,public void outInvokeStmt(soot.jimple.InvokeStmt) ,public void outNewArrayExpr(soot.jimple.NewArrayExpr) ,public void outNewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) ,public void outRef(soot.jimple.Ref) ,public void outReturnStmt(soot.jimple.ReturnStmt) ,public void outStaticFieldRef(soot.jimple.StaticFieldRef) ,public void outStmt(soot.jimple.Stmt) ,public void outThrowStmt(soot.jimple.ThrowStmt) ,public void outType(soot.Type) ,public void outUnopExpr(soot.jimple.UnopExpr) ,public void outValue(soot.Value) <variables>public boolean DEBUG,boolean verbose
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/AST/transformations/UselessLabelFinder.java
UselessLabelFinder
findAndKill
class UselessLabelFinder { public static boolean DEBUG = false; public UselessLabelFinder(Singletons.Global g) { } public static UselessLabelFinder v() { return G.v().soot_dava_toolkits_base_AST_transformations_UselessLabelFinder(); } // check whether label on a node is useless public boolean findAndKill(ASTNode node) {<FILL_FUNCTION_BODY>} /* * Returns True if finds a break for this label */ private boolean checkForBreak(List ASTNodeBody, String outerLabel) { // if(DEBUG) // System.out.println("method checkForBreak..... label is "+outerLabel); Iterator it = ASTNodeBody.iterator(); while (it.hasNext()) { ASTNode temp = (ASTNode) it.next(); // check if this is ASTStatementSequenceNode if (temp instanceof ASTStatementSequenceNode) { // if(DEBUG) System.out.println("Stmt seq Node"); ASTStatementSequenceNode stmtSeq = (ASTStatementSequenceNode) temp; for (AugmentedStmt as : stmtSeq.getStatements()) { Stmt s = as.get_Stmt(); String labelBroken = breaksLabel(s); if (labelBroken != null && outerLabel != null) { // stmt breaks some label if (labelBroken.compareTo(outerLabel) == 0) { // we have found a break breaking this label return true; } } } } // if it was a StmtSeq node else { // otherwise recursion // getSubBodies // if(DEBUG) System.out.println("Not Stmt seq Node"); List<Object> subBodies = temp.get_SubBodies(); Iterator<Object> subIt = subBodies.iterator(); while (subIt.hasNext()) { List subBodyTemp = null; if (temp instanceof ASTTryNode) { ASTTryNode.container subBody = (ASTTryNode.container) subIt.next(); subBodyTemp = (List) subBody.o; // System.out.println("Try body node"); } else { subBodyTemp = (List) subIt.next(); } if (checkForBreak(subBodyTemp, outerLabel)) { // if this is true there was a break found return true; } } } } return false; } /* * If the stmt is a break/continue stmt then this method returns the labels name else returns null */ private String breaksLabel(Stmt stmt) { if (!(stmt instanceof DAbruptStmt)) { // this is not a break stmt return null; } DAbruptStmt abStmt = (DAbruptStmt) stmt; if (abStmt.is_Break() || abStmt.is_Continue()) { SETNodeLabel label = abStmt.getLabel(); return label.toString(); } else { return null; } } }
if (!(node instanceof ASTLabeledNode)) { if (DEBUG) { System.out.println("Returning from findAndKill for node of type " + node.getClass()); } return false; } else { if (DEBUG) { System.out.println("FindAndKill continuing for node fo type" + node.getClass()); } } String label = ((ASTLabeledNode) node).get_Label().toString(); if (label == null) { return false; } if (DEBUG) { System.out.println("dealing with labeled node" + label); } List<Object> subBodies = node.get_SubBodies(); Iterator<Object> it = subBodies.iterator(); while (it.hasNext()) { List subBodyTemp = null; if (node instanceof ASTTryNode) { // an astTryNode ASTTryNode.container subBody = (ASTTryNode.container) it.next(); subBodyTemp = (List) subBody.o; // System.out.println("\ntryNode body"); } else { // not an astTryNode // System.out.println("not try node in findAndkill"); subBodyTemp = (List) it.next(); } if (checkForBreak(subBodyTemp, label)) { // found a break return false; } } // only if all bodies dont contain a break can we remove the label // means break was not found so we can remove ((ASTLabeledNode) node).set_Label(new SETNodeLabel()); if (DEBUG) { System.out.println("USELESS LABEL DETECTED"); } return true;
813
449
1,262
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/DavaMonitor/DavaMonitor.java
DavaMonitor
enter
class DavaMonitor { private static final DavaMonitor instance = new DavaMonitor(); private final HashMap<Object, Lock> ref, lockTable; private DavaMonitor() { ref = new HashMap<Object, Lock>(1, 0.7f); lockTable = new HashMap<Object, Lock>(1, 0.7f); } public static DavaMonitor v() { return instance; } public synchronized void enter(Object o) throws NullPointerException {<FILL_FUNCTION_BODY>} public synchronized void exit(Object o) throws NullPointerException, IllegalMonitorStateException { if (o == null) { throw new NullPointerException(); } Lock lock = ref.get(o); if ((lock == null) || (lock.level == 0) || (lock.owner != Thread.currentThread())) { throw new IllegalMonitorStateException(); } lock.level--; if (lock.level == 0) { notifyAll(); } } }
Thread currentThread = Thread.currentThread(); if (o == null) { throw new NullPointerException(); } Lock lock = ref.get(o); if (lock == null) { lock = new Lock(); ref.put(o, lock); } if (lock.level == 0) { lock.level = 1; lock.owner = currentThread; return; } if (lock.owner == currentThread) { lock.level++; return; } lockTable.put(currentThread, lock); lock.enQ(currentThread); while ((lock.level > 0) || (lock.nextThread() != currentThread)) { try { wait(); } catch (InterruptedException e) { throw new RuntimeException(e); } currentThread = Thread.currentThread(); lock = lockTable.get(currentThread); } lock.deQ(currentThread); lock.level = 1; lock.owner = currentThread;
270
273
543
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/DavaMonitor/Lock.java
Lock
deQ
class Lock { public Thread owner; public int level; private final LinkedList<Thread> q; Lock() { level = 0; owner = null; q = new LinkedList<Thread>(); } public Thread nextThread() { return q.getFirst(); } public Thread deQ(Thread t) throws IllegalMonitorStateException {<FILL_FUNCTION_BODY>} public void enQ(Thread t) { q.add(t); } }
if (t != q.getFirst()) { throw new IllegalMonitorStateException(); } return q.removeFirst();
134
37
171
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/finders/AbruptEdgeFinder.java
AbruptEdgeFinder
find_Breaks
class AbruptEdgeFinder implements FactFinder { public AbruptEdgeFinder(Singletons.Global g) { } public static AbruptEdgeFinder v() { return G.v().soot_dava_toolkits_base_finders_AbruptEdgeFinder(); } public void find(DavaBody body, AugmentedStmtGraph asg, SETNode SET) throws RetriggerAnalysisException { Dava.v().log("AbruptEdgeFinder::find()"); SET.find_AbruptEdges(this); } public void find_Continues(SETNode SETParent, IterableSet body, IterableSet children) { if (!(SETParent instanceof SETCycleNode)) { return; } SETCycleNode scn = (SETCycleNode) SETParent; IterableSet naturalPreds = ((SETNode) children.getLast()).get_NaturalExits(); Iterator pit = scn.get_CharacterizingStmt().bpreds.iterator(); while (pit.hasNext()) { AugmentedStmt pas = (AugmentedStmt) pit.next(); if ((body.contains(pas)) && !naturalPreds.contains(pas)) { ((SETStatementSequenceNode) pas.myNode).insert_AbruptStmt(new DAbruptStmt("continue", scn.get_Label())); } } } public void find_Breaks(SETNode prev, SETNode cur) {<FILL_FUNCTION_BODY>} }
IterableSet naturalPreds = prev.get_NaturalExits(); Iterator pit = cur.get_EntryStmt().bpreds.iterator(); while (pit.hasNext()) { AugmentedStmt pas = (AugmentedStmt) pit.next(); if (!prev.get_Body().contains(pas)) { continue; } if (!naturalPreds.contains(pas)) { Object temp = pas.myNode; /* * Nomair debugging bug number 29 */ // System.out.println(); // ((SETNode)temp).dump(); // System.out.println("Statement is"+pas); ((SETStatementSequenceNode) temp).insert_AbruptStmt(new DAbruptStmt("break", prev.get_Label())); } }
399
215
614
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/finders/IfFinder.java
IfFinder
find
class IfFinder implements FactFinder { public IfFinder(Singletons.Global g) { } public static IfFinder v() { return G.v().soot_dava_toolkits_base_finders_IfFinder(); } public void find(DavaBody body, AugmentedStmtGraph asg, SETNode SET) throws RetriggerAnalysisException {<FILL_FUNCTION_BODY>} private IterableSet find_Body(AugmentedStmt targetBranch, AugmentedStmt otherBranch) { IterableSet body = new IterableSet(); if (targetBranch.get_Reachers().contains(otherBranch)) { return body; } LinkedList<AugmentedStmt> worklist = new LinkedList<AugmentedStmt>(); worklist.addLast(targetBranch); while (!worklist.isEmpty()) { AugmentedStmt as = worklist.removeFirst(); if (!body.contains(as)) { body.add(as); Iterator sit = as.csuccs.iterator(); while (sit.hasNext()) { AugmentedStmt sas = (AugmentedStmt) sit.next(); if (!sas.get_Reachers().contains(otherBranch) && sas.get_Dominators().contains(targetBranch)) { worklist.addLast(sas); } } } } return body; } }
Dava.v().log("IfFinder::find()"); Iterator asgit = asg.iterator(); while (asgit.hasNext()) { AugmentedStmt as = (AugmentedStmt) asgit.next(); Stmt s = as.get_Stmt(); if (s instanceof IfStmt) { IfStmt ifs = (IfStmt) s; if (body.get_ConsumedConditions().contains(as)) { continue; } body.consume_Condition(as); AugmentedStmt succIf = asg.get_AugStmt(ifs.getTarget()), succElse = (AugmentedStmt) as.bsuccs.get(0); if (succIf == succElse) { succElse = (AugmentedStmt) as.bsuccs.get(1); } asg.calculate_Reachability(succIf, succElse, as); asg.calculate_Reachability(succElse, succIf, as); IterableSet fullBody = new IterableSet(), ifBody = find_Body(succIf, succElse), elseBody = find_Body(succElse, succIf); fullBody.add(as); fullBody.addAll(ifBody); fullBody.addAll(elseBody); Iterator enlit = body.get_ExceptionFacts().iterator(); while (enlit.hasNext()) { ExceptionNode en = (ExceptionNode) enlit.next(); IterableSet tryBody = en.get_TryBody(); if (tryBody.contains(as)) { Iterator fbit = fullBody.snapshotIterator(); while (fbit.hasNext()) { AugmentedStmt fbas = (AugmentedStmt) fbit.next(); if (!tryBody.contains(fbas)) { fullBody.remove(fbas); if (ifBody.contains(fbas)) { ifBody.remove(fbas); } if (elseBody.contains(fbas)) { elseBody.remove(fbas); } } } } } SET.nest(new SETIfElseNode(as, fullBody, ifBody, elseBody)); } }
384
597
981
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/finders/IndexComparator.java
IndexComparator
compare
class IndexComparator implements Comparator { public int compare(Object o1, Object o2) {<FILL_FUNCTION_BODY>} public boolean equals(Object o) { return (o instanceof IndexComparator); } }
if (o1 == o2) { return 0; } if (o1 instanceof String) { return 1; } if (o2 instanceof String) { return -1; } return ((Integer) o1).intValue() - ((Integer) o2).intValue();
65
86
151
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/finders/IndexSetComparator.java
IndexSetComparator
compare
class IndexSetComparator implements Comparator { public int compare(Object o1, Object o2) {<FILL_FUNCTION_BODY>} public boolean equals(Object o) { return (o instanceof IndexSetComparator); } }
if (o1 == o2) { return 0; } o1 = ((TreeSet) o1).last(); o2 = ((TreeSet) o2).last(); if (o1 instanceof String) { return 1; } if (o2 instanceof String) { return -1; } return ((Integer) o1).intValue() - ((Integer) o2).intValue();
67
115
182
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/finders/SequenceFinder.java
SequenceFinder
find_StatementSequences
class SequenceFinder implements FactFinder { public SequenceFinder(Singletons.Global g) { } public static SequenceFinder v() { return G.v().soot_dava_toolkits_base_finders_SequenceFinder(); } public void find(DavaBody body, AugmentedStmtGraph asg, SETNode SET) throws RetriggerAnalysisException { Dava.v().log("SequenceFinder::find()"); SET.find_StatementSequences(this, body); } public void find_StatementSequences(SETNode SETParent, IterableSet body, HashSet<AugmentedStmt> childUnion, DavaBody davaBody) {<FILL_FUNCTION_BODY>} }
Iterator bit = body.iterator(); while (bit.hasNext()) { AugmentedStmt as = (AugmentedStmt) bit.next(); if (childUnion.contains(as)) { continue; } IterableSet sequenceBody = new IterableSet(); while (as.bpreds.size() == 1) { AugmentedStmt pas = (AugmentedStmt) as.bpreds.get(0); if (!body.contains(pas) || childUnion.contains(pas)) { break; } as = pas; } while ((body.contains(as)) && !childUnion.contains(as)) { childUnion.add(as); sequenceBody.addLast(as); if (!as.bsuccs.isEmpty()) { as = (AugmentedStmt) as.bsuccs.get(0); } if (as.bpreds.size() != 1) { break; } } SETParent.add_Child(new SETStatementSequenceNode(sequenceBody, davaBody), SETParent.get_Body2ChildChain().get(body)); }
197
311
508
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/finders/SwitchNode.java
SwitchNode
compareTo
class SwitchNode implements Comparable { private final LinkedList preds, succs; private AugmentedStmt as; private int score; private TreeSet<Object> indexSet; private IterableSet body; public SwitchNode(AugmentedStmt as, TreeSet<Object> indexSet, IterableSet body) { this.as = as; this.indexSet = indexSet; this.body = body; preds = new LinkedList(); succs = new LinkedList(); score = -1; } public int get_Score() { if (score == -1) { score = 0; if (preds.size() < 2) { Iterator sit = succs.iterator(); while (sit.hasNext()) { SwitchNode ssn = (SwitchNode) sit.next(); int curScore = ssn.get_Score(); if (score < curScore) { score = curScore; } } score++; } } return score; } public List get_Preds() { return preds; } public List get_Succs() { return succs; } public AugmentedStmt get_AugStmt() { return as; } public TreeSet<Object> get_IndexSet() { return new TreeSet<Object>(indexSet); } public IterableSet get_Body() { return body; } public SwitchNode reset() { preds.clear(); succs.clear(); return this; } public void setup_Graph(HashMap<AugmentedStmt, SwitchNode> binding) { Iterator rit = ((AugmentedStmt) as.bsuccs.get(0)).get_Reachers().iterator(); while (rit.hasNext()) { SwitchNode pred = binding.get(rit.next()); if (pred != null) { if (!preds.contains(pred)) { preds.add(pred); } if (!pred.succs.contains(this)) { pred.succs.add(this); } } } } /* * Can compare to an Integer, a String, a set of Indices, and another SwitchNode. */ public int compareTo(Object o) {<FILL_FUNCTION_BODY>} }
if (o == this) { return 0; } if (indexSet.last() instanceof String) { return 1; } if (o instanceof String) { return -1; } if (o instanceof Integer) { return ((Integer) indexSet.last()).intValue() - ((Integer) o).intValue(); } if (o instanceof TreeSet) { TreeSet other = (TreeSet) o; if (other.last() instanceof String) { return -1; } return ((Integer) indexSet.last()).intValue() - ((Integer) other.last()).intValue(); } SwitchNode other = (SwitchNode) o; if (other.indexSet.last() instanceof String) { return -1; } return ((Integer) indexSet.last()).intValue() - ((Integer) other.indexSet.last()).intValue();
633
240
873
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/misc/MonitorConverter.java
MonitorConverter
convert
class MonitorConverter { public MonitorConverter(Singletons.Global g) { SootClass davaMonitor = new SootClass("soot.dava.toolkits.base.DavaMonitor.DavaMonitor", Modifier.PUBLIC); davaMonitor.setSuperclass(Scene.v().loadClassAndSupport("java.lang.Object")); LinkedList objectSingleton = new LinkedList(); objectSingleton.add(RefType.v("java.lang.Object")); v = Scene.v().makeSootMethod("v", new LinkedList(), RefType.v("soot.dava.toolkits.base.DavaMonitor.DavaMonitor"), Modifier.PUBLIC | Modifier.STATIC); enter = Scene.v().makeSootMethod("enter", objectSingleton, VoidType.v(), Modifier.PUBLIC | Modifier.SYNCHRONIZED); exit = Scene.v().makeSootMethod("exit", objectSingleton, VoidType.v(), Modifier.PUBLIC | Modifier.SYNCHRONIZED); davaMonitor.addMethod(v); davaMonitor.addMethod(enter); davaMonitor.addMethod(exit); Scene.v().addClass(davaMonitor); } public static MonitorConverter v() { return G.v().soot_dava_toolkits_base_misc_MonitorConverter(); } private final SootMethod v, enter, exit; public void convert(DavaBody body) {<FILL_FUNCTION_BODY>} }
for (AugmentedStmt mas : body.get_MonitorFacts()) { MonitorStmt ms = (MonitorStmt) mas.get_Stmt(); body.addToImportList("soot.dava.toolkits.base.DavaMonitor.DavaMonitor"); ArrayList arg = new ArrayList(); arg.add(ms.getOp()); if (ms instanceof EnterMonitorStmt) { mas.set_Stmt(new GInvokeStmt(new DVirtualInvokeExpr(new DStaticInvokeExpr(v.makeRef(), new ArrayList()), enter.makeRef(), arg, new HashSet<Object>()))); } else { mas.set_Stmt(new GInvokeStmt(new DVirtualInvokeExpr(new DStaticInvokeExpr(v.makeRef(), new ArrayList()), exit.makeRef(), arg, new HashSet<Object>()))); } }
395
226
621
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/misc/PackageNamer.java
NameHolder
retrieve_FixedPackageName
class NameHolder { private final String originalName; private String packageName, className; private final ArrayList<NameHolder> children; private NameHolder parent; private boolean isClass; public NameHolder(String name, NameHolder parent, boolean isClass) { originalName = name; className = name; packageName = name; this.parent = parent; this.isClass = isClass; children = new ArrayList<NameHolder>(); } public NameHolder get_Parent() { return parent; } public void set_ClassAttr() { isClass = true; } public boolean is_Class() { if (children.isEmpty()) { return true; } else { return isClass; } } public boolean is_Package() { return !children.isEmpty(); } public String get_PackageName() { return packageName; } public String get_ClassName() { return className; } public void set_PackageName(String packageName) { this.packageName = packageName; } public void set_ClassName(String className) { this.className = className; } public String get_OriginalName() { return originalName; } public ArrayList<NameHolder> get_Children() { return children; } public String get_FixedPackageName() { if (parent == null) { return ""; } return parent.retrieve_FixedPackageName(); } public String retrieve_FixedPackageName() {<FILL_FUNCTION_BODY>} public String get_FixedName(StringTokenizer st, boolean forClass) { if (!st.nextToken().equals(originalName)) { throw new RuntimeException("Unable to resolve naming."); } return retrieve_FixedName(st, forClass); } private String retrieve_FixedName(StringTokenizer st, boolean forClass) { if (!st.hasMoreTokens()) { if (forClass) { return className; } else { return packageName; } } String subName = st.nextToken(); Iterator<NameHolder> cit = children.iterator(); while (cit.hasNext()) { NameHolder h = cit.next(); if (h.get_OriginalName().equals(subName)) { if (forClass) { return h.retrieve_FixedName(st, forClass); } else { return packageName + "." + h.retrieve_FixedName(st, forClass); } } } throw new RuntimeException("Unable to resolve naming."); } public String get_OriginalPackageName(StringTokenizer st) { if (!st.hasMoreTokens()) { return get_OriginalName(); } String subName = st.nextToken(); Iterator<NameHolder> cit = children.iterator(); while (cit.hasNext()) { NameHolder h = cit.next(); if (h.get_PackageName().equals(subName)) { String originalSubPackageName = h.get_OriginalPackageName(st); if (originalSubPackageName == null) { return null; } else { return get_OriginalName() + "." + originalSubPackageName; } } } return null; } public boolean contains_OriginalName(StringTokenizer st, boolean forClass) { if (!get_OriginalName().equals(st.nextToken())) { return false; } return finds_OriginalName(st, forClass); } private boolean finds_OriginalName(StringTokenizer st, boolean forClass) { if (!st.hasMoreTokens()) { return (((forClass) && (is_Class())) || ((!forClass) && (is_Package()))); } String subName = st.nextToken(); Iterator<NameHolder> cit = children.iterator(); while (cit.hasNext()) { NameHolder h = cit.next(); if (h.get_OriginalName().equals(subName)) { return h.finds_OriginalName(st, forClass); } } return false; } public void fix_ClassNames(String curPackName) { if ((is_Class()) && (keywords.contains(className))) { String tClassName = className; if (Character.isLowerCase(className.charAt(0))) { tClassName = tClassName.substring(0, 1).toUpperCase() + tClassName.substring(1); className = tClassName; } for (int i = 0; keywords.contains(className); i++) { className = tClassName + "_c" + i; } } Iterator<NameHolder> it = children.iterator(); while (it.hasNext()) { it.next().fix_ClassNames(curPackName + "." + packageName); } } public void fix_PackageNames() { if ((is_Package()) && !verify_PackageName()) { String tPackageName = packageName; if (Character.isUpperCase(packageName.charAt(0))) { tPackageName = tPackageName.substring(0, 1).toLowerCase() + tPackageName.substring(1); packageName = tPackageName; } for (int i = 0; !verify_PackageName(); i++) { packageName = tPackageName + "_p" + i; } } Iterator<NameHolder> it = children.iterator(); while (it.hasNext()) { it.next().fix_PackageNames(); } } public boolean verify_PackageName() { return (!keywords.contains(packageName) && !siblingClashes(packageName) && (!is_Class() || !className.equals(packageName))); } public boolean siblingClashes(String name) { Iterator<NameHolder> it = null; if (parent == null) { if (appRoots.contains(this)) { it = appRoots.iterator(); } else { throw new RuntimeException("Unable to find package siblings."); } } else { it = parent.get_Children().iterator(); } while (it.hasNext()) { NameHolder sibling = it.next(); if (sibling == this) { continue; } if (((sibling.is_Package()) && (sibling.get_PackageName().equals(name))) || ((sibling.is_Class()) && (sibling.get_ClassName().equals(name)))) { return true; } } return false; } public void dump(String indentation) { logger.debug("" + indentation + "\"" + originalName + "\", \"" + packageName + "\", \"" + className + "\" ("); if (is_Class()) { logger.debug("c"); } if (is_Package()) { logger.debug("p"); } logger.debug("" + ")"); Iterator<NameHolder> it = children.iterator(); while (it.hasNext()) { it.next().dump(indentation + " "); } } }
if (parent == null) { return packageName; } return parent.get_FixedPackageName() + "." + packageName;
1,905
40
1,945
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/misc/ThrowNullConverter.java
ThrowNullConverter
convert
class ThrowNullConverter { public ThrowNullConverter(Singletons.Global g) { } public static ThrowNullConverter v() { return G.v().soot_dava_toolkits_base_misc_ThrowNullConverter(); } private final RefType npeRef = RefType.v(Scene.v().loadClassAndSupport("java.lang.NullPointerException")); public void convert(DavaBody body) {<FILL_FUNCTION_BODY>} }
Iterator it = body.getUnits().iterator(); while (it.hasNext()) { Unit u = (Unit) it.next(); if (u instanceof ThrowStmt) { ValueBox opBox = ((ThrowStmt) u).getOpBox(); Value op = opBox.getValue(); if (op.getType() instanceof NullType) { opBox.setValue(new DNewInvokeExpr(npeRef, null, new ArrayList())); } } }
128
128
256
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/renamer/RemoveFullyQualifiedName.java
RemoveFullyQualifiedName
containsMultiple
class RemoveFullyQualifiedName { public static boolean containsMultiple(Iterator it, String qualifiedName, Type t) {<FILL_FUNCTION_BODY>} /* * Method finds the last . and returns the className after that if no dot is found (shouldnt happen) then the name is * simply returned back */ public static String getClassName(String qualifiedName) { if (qualifiedName.lastIndexOf('.') > -1) { return qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1); } return qualifiedName; } public static String getReducedName(IterableSet importList, String qualifiedName, Type t) { // if two explicit imports dont import the same class we can remove explicit qualification if (!containsMultiple(importList.iterator(), qualifiedName, t)) { return getClassName(qualifiedName); } return qualifiedName; } }
/* * The fully qualified name might contain [] in the end if the type is an ArrayType */ if (t != null) { if (t instanceof ArrayType) { if (qualifiedName.indexOf('[') >= 0) { qualifiedName = qualifiedName.substring(0, qualifiedName.indexOf('[')); } } } // get last name String className = getClassName(qualifiedName); int count = 0; while (it.hasNext()) { String tempName = getClassName((String) it.next()); if (tempName.equals(className)) { count++; } } if (count > 1) { return true; } return false;
238
193
431
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dava/toolkits/base/renamer/heuristicSet.java
heuristicSet
contains
class heuristicSet { HashMap<Local, heuristicTuple> set; public heuristicSet() { set = new HashMap<Local, heuristicTuple>(); } private heuristicTuple getTuple(Local var) { return set.get(var); } public void add(Local var, int bits) { heuristicTuple temp = new heuristicTuple(bits); set.put(var, temp); } public void addCastString(Local var, String castString) { heuristicTuple retrieved = getTuple(var); retrieved.addCastString(castString); } public List<String> getCastStrings(Local var) { heuristicTuple retrieved = getTuple(var); return retrieved.getCastStrings(); } public void setFieldName(Local var, String fieldName) { heuristicTuple retrieved = getTuple(var); retrieved.setFieldName(fieldName); } public List<String> getFieldName(Local var) { heuristicTuple retrieved = getTuple(var); return retrieved.getFieldName(); } public void setObjectClassName(Local var, String objectClassName) { heuristicTuple retrieved = getTuple(var); retrieved.setObjectClassName(objectClassName); } public List<String> getObjectClassName(Local var) { heuristicTuple retrieved = getTuple(var); return retrieved.getObjectClassName(); } public void setMethodName(Local var, String methodName) { heuristicTuple retrieved = getTuple(var); retrieved.setMethodName(methodName); } public List<String> getMethodName(Local var) { heuristicTuple retrieved = getTuple(var); return retrieved.getMethodName(); } public void setHeuristic(Local var, int bitIndex) { heuristicTuple retrieved = getTuple(var); retrieved.setHeuristic(bitIndex); } public boolean getHeuristic(Local var, int bitIndex) { heuristicTuple retrieved = getTuple(var); return retrieved.getHeuristic(bitIndex); } public boolean isAnyHeuristicSet(Local var) { heuristicTuple retrieved = getTuple(var); return retrieved.isAnyHeuristicSet(); } public void print() { Iterator<Local> it = set.keySet().iterator(); while (it.hasNext()) { Object local = it.next(); heuristicTuple temp = set.get(local); String tuple = temp.getPrint(); System.out.println(local + " " + tuple + " DefinedType: " + ((Local) local).getType()); } } public Iterator<Local> getLocalsIterator() { return set.keySet().iterator(); } public boolean contains(Local var) {<FILL_FUNCTION_BODY>} }
if (set.get(var) != null) { return true; } else { return false; }
813
36
849
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dexpler/AbstractNullTransformer.java
AbstractNullTransformer
replaceWithNull
class AbstractNullTransformer extends DexTransformer { /** * Examine expr if it is a comparison with 0. * * @param expr * the ConditionExpr to examine */ protected boolean isZeroComparison(ConditionExpr expr) { if (expr instanceof EqExpr || expr instanceof NeExpr) { if ((expr.getOp2() instanceof IntConstant && ((IntConstant) expr.getOp2()).value == 0) || (expr.getOp2() instanceof LongConstant && ((LongConstant) expr.getOp2()).value == 0)) { return true; } } return false; } /** * Replace 0 with null in the given unit. * * @param u * the unit where 0 will be replaced with null. */ protected void replaceWithNull(Unit u) {<FILL_FUNCTION_BODY>} protected static boolean isObject(Type t) { return t instanceof RefLikeType; } }
if (u instanceof IfStmt) { ConditionExpr expr = (ConditionExpr) ((IfStmt) u).getCondition(); if (isZeroComparison(expr)) { expr.setOp2(NullConstant.v()); } } else if (u instanceof AssignStmt) { AssignStmt s = (AssignStmt) u; Value v = s.getRightOp(); if ((v instanceof IntConstant && ((IntConstant) v).value == 0) || (v instanceof LongConstant && ((LongConstant) v).value == 0)) { // If this is a field assignment, double-check the type. We // might have a.f = 2 with a being a null candidate, but a.f // being an int. if (!(s.getLeftOp() instanceof InstanceFieldRef) || ((InstanceFieldRef) s.getLeftOp()).getFieldRef().type() instanceof RefLikeType) { s.setRightOp(NullConstant.v()); } } }
259
253
512
<methods>public non-sealed void <init>() <variables>
soot-oss_soot
soot/src/main/java/soot/dexpler/DalvikThrowAnalysis.java
DalvikThrowAnalysis
caseCastExpr
class DalvikThrowAnalysis extends UnitThrowAnalysis { /** * Constructs a <code>DalvikThrowAnalysis</code> for inclusion in Soot's global variable manager, {@link G}. * * @param g * guarantees that the constructor may only be called from {@link Singletons}. */ public DalvikThrowAnalysis(Singletons.Global g) { } /** * Returns the single instance of <code>DalvikThrowAnalysis</code>. * * @return Soot's <code>UnitThrowAnalysis</code>. */ public static DalvikThrowAnalysis v() { return G.v().soot_dexpler_DalvikThrowAnalysis(); } protected DalvikThrowAnalysis(boolean isInterproc) { super(isInterproc); } public DalvikThrowAnalysis(Singletons.Global g, boolean isInterproc) { super(isInterproc); } public static DalvikThrowAnalysis interproceduralAnalysis = null; public static DalvikThrowAnalysis interproc() { return G.v().interproceduralDalvikThrowAnalysis(); } @Override protected ThrowableSet defaultResult() { return mgr.EMPTY; } @Override protected UnitSwitch unitSwitch(SootMethod sm) { return new UnitThrowAnalysis.UnitSwitch(sm) { // Dalvik does not throw an exception for this instruction @Override public void caseReturnInst(ReturnInst i) { } // Dalvik does not throw an exception for this instruction @Override public void caseReturnVoidInst(ReturnVoidInst i) { } @Override public void caseEnterMonitorInst(EnterMonitorInst i) { result = result.add(mgr.NULL_POINTER_EXCEPTION); result = result.add(mgr.ILLEGAL_MONITOR_STATE_EXCEPTION); } @Override public void caseEnterMonitorStmt(EnterMonitorStmt s) { result = result.add(mgr.NULL_POINTER_EXCEPTION); result = result.add(mgr.ILLEGAL_MONITOR_STATE_EXCEPTION); result = result.add(mightThrow(s.getOp())); } @Override public void caseAssignStmt(AssignStmt s) { // Dalvik only throws ArrayIndexOutOfBounds and // NullPointerException which are both handled through the // ArrayRef expressions. There is no ArrayStoreException in // Dalvik. result = result.add(mightThrow(s.getLeftOp())); result = result.add(mightThrow(s.getRightOp())); } }; } @Override protected ValueSwitch valueSwitch() { return new UnitThrowAnalysis.ValueSwitch() { // from ./vm/mterp/c/OP_CONST_STRING.c // // HANDLE_OPCODE(OP_CONST_STRING /*vAA, string@BBBB*/) // { // StringObject* strObj; // // vdst = INST_AA(inst); // ref = FETCH(1); // ILOGV("|const-string v%d string@0x%04x", vdst, ref); // strObj = dvmDexGetResolvedString(methodClassDex, ref); // if (strObj == NULL) { // EXPORT_PC(); // strObj = dvmResolveString(curMethod->clazz, ref); // if (strObj == NULL) // GOTO_exceptionThrown(); <--- HERE // } // SET_REGISTER(vdst, (u4) strObj); // } // FINISH(2); // OP_END // @Override public void caseStringConstant(StringConstant c) { // // the string is already fetched when converting // Dalvik bytecode to Jimple. A potential error // would be detected there. // // result = result.add(mgr.RESOLVE_FIELD_ERRORS); // should we add another kind of exception for this? } // // from ./vm/mterp/c/OP_CONST_CLASS.c // // HANDLE_OPCODE(OP_CONST_CLASS /*vAA, class@BBBB*/) // { // ClassObject* clazz; // // vdst = INST_AA(inst); // ref = FETCH(1); // ILOGV("|const-class v%d class@0x%04x", vdst, ref); // clazz = dvmDexGetResolvedClass(methodClassDex, ref); // if (clazz == NULL) { // EXPORT_PC(); // clazz = dvmResolveClass(curMethod->clazz, ref, true); // if (clazz == NULL) // GOTO_exceptionThrown(); <--- HERE // } // SET_REGISTER(vdst, (u4) clazz); // } // FINISH(2); // OP_END // @Override public void caseClassConstant(ClassConstant c) { // // the string is already fetched and stored in a // ClassConstant object when converting // Dalvik bytecode to Jimple. A potential error // would be detected there. // // result = result.add(mgr.RESOLVE_CLASS_ERRORS); } @Override public void caseCastExpr(CastExpr expr) {<FILL_FUNCTION_BODY>} }; } }
if (expr.getCastType() instanceof PrimType) { // No exception are thrown for primitive casts return; } Type fromType = expr.getOp().getType(); Type toType = expr.getCastType(); result = result.add(mgr.RESOLVE_CLASS_ERRORS); if (toType instanceof RefLikeType) { // fromType might still be unknown when we are called, // but toType will have a value. FastHierarchy h = Scene.v().getOrMakeFastHierarchy(); if (fromType == null || fromType instanceof UnknownType || ((!(fromType instanceof NullType)) && (!h.canStoreType(fromType, toType)))) { result = result.add(mgr.CLASS_CAST_EXCEPTION); } } result = result.add(mightThrow(expr.getOp()));
1,465
226
1,691
<methods>public void <init>(Singletons.Global) ,public static soot.toolkits.exceptions.UnitThrowAnalysis interproc() ,public soot.toolkits.exceptions.ThrowableSet mightThrow(soot.Unit) ,public soot.toolkits.exceptions.ThrowableSet mightThrow(soot.Unit, soot.SootMethod) ,public soot.toolkits.exceptions.ThrowableSet mightThrow(soot.SootMethodRef) ,public soot.toolkits.exceptions.ThrowableSet mightThrow(soot.SootMethod) ,public soot.toolkits.exceptions.ThrowableSet mightThrowImplicitly(soot.baf.ThrowInst) ,public soot.toolkits.exceptions.ThrowableSet mightThrowImplicitly(soot.jimple.ThrowStmt) ,public static soot.toolkits.exceptions.UnitThrowAnalysis v() <variables>private static final soot.jimple.IntConstant INT_CONSTANT_ZERO,private static final soot.jimple.LongConstant LONG_CONSTANT_ZERO,private final soot.toolkits.exceptions.ThrowableSet implicitThrowExceptions,public static soot.toolkits.exceptions.UnitThrowAnalysis interproceduralAnalysis,protected final non-sealed boolean isInterproc,protected final LoadingCache<soot.SootMethod,soot.toolkits.exceptions.ThrowableSet> methodToThrowSet,protected final soot.toolkits.exceptions.ThrowableSet.Manager mgr
soot-oss_soot
soot/src/main/java/soot/dexpler/DexArrayInitReducer.java
DexArrayInitReducer
internalTransform
class DexArrayInitReducer extends BodyTransformer { private static final Logger logger = LoggerFactory.getLogger(DexArrayInitReducer.class); public static DexArrayInitReducer v() { return new DexArrayInitReducer(); } @Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) {<FILL_FUNCTION_BODY>} }
// Make sure that we only have linear control flow if (!b.getTraps().isEmpty()) { return; } // Look for a chain of two constant assignments followed by an array put Unit u1 = null, u2 = null; for (Iterator<Unit> uIt = b.getUnits().snapshotIterator(); uIt.hasNext();) { Unit u = uIt.next(); // If this is not an assignment, it does not matter. if (!(u instanceof AssignStmt) || !((Stmt) u).getBoxesPointingToThis().isEmpty()) { u1 = null; u2 = null; continue; } // If this is an assignment to an array, we must already have two // preceding constant assignments AssignStmt assignStmt = (AssignStmt) u; if (assignStmt.getLeftOp() instanceof ArrayRef) { if (u1 != null && u2 != null && u2.getBoxesPointingToThis().isEmpty() && assignStmt.getBoxesPointingToThis().isEmpty()) { ArrayRef arrayRef = (ArrayRef) assignStmt.getLeftOp(); Value u1val = u1.getDefBoxes().get(0).getValue(); Value u2val = u2.getDefBoxes().get(0).getValue(); // index if (arrayRef.getIndex() == u1val) { arrayRef.setIndex(((AssignStmt) u1).getRightOp()); } else if (arrayRef.getIndex() == u2val) { arrayRef.setIndex(((AssignStmt) u2).getRightOp()); } // value if (assignStmt.getRightOp() == u1val) { assignStmt.setRightOp(((AssignStmt) u1).getRightOp()); } else if (assignStmt.getRightOp() == u2val) { assignStmt.setRightOp(((AssignStmt) u2).getRightOp()); } // Remove the unnecessary assignments Iterator<Unit> checkIt = b.getUnits().iterator(u); boolean foundU1 = false, foundU2 = false, doneU1 = false, doneU2 = false; while (!(doneU1 && doneU2) && !(foundU1 && foundU2) && checkIt.hasNext()) { Unit checkU = checkIt.next(); // Does the current statement use the value? for (ValueBox vb : checkU.getUseBoxes()) { if (!doneU1 && vb.getValue() == u1val) { foundU1 = true; } if (!doneU2 && vb.getValue() == u2val) { foundU2 = true; } } // Does the current statement overwrite the value? for (ValueBox vb : checkU.getDefBoxes()) { if (vb.getValue() == u1val) { doneU1 = true; } else if (vb.getValue() == u2val) { doneU2 = true; } } // If this statement branches, we abort if (checkU.branches()) { foundU1 = true; foundU2 = true; break; } } if (!foundU1) { // only remove constant assignment if the left value is Local if (u1val instanceof Local) { b.getUnits().remove(u1); if (Options.v().verbose()) { logger.debug("[" + b.getMethod().getName() + "] remove 1 " + u1); } } } if (!foundU2) { // only remove constant assignment if the left value is Local if (u2val instanceof Local) { b.getUnits().remove(u2); if (Options.v().verbose()) { logger.debug("[" + b.getMethod().getName() + "] remove 2 " + u2); } } } u1 = null; u2 = null; } else { // No proper initialization before u1 = null; u2 = null; continue; } } // We have a normal assignment. This could be an array index or // value. if (!(assignStmt.getRightOp() instanceof Constant)) { u1 = null; u2 = null; continue; } if (u1 == null) { u1 = assignStmt; } else if (u2 == null) { u2 = assignStmt; // If the last value is overwritten again, we start again at the beginning if (u1 != null) { Value op1 = ((AssignStmt) u1).getLeftOp(); if (op1 == ((AssignStmt) u2).getLeftOp()) { u1 = u2; u2 = null; } } } else { u1 = u2; u2 = assignStmt; } } // Remove all locals that are no longer necessary UnusedLocalEliminator.v().transform(b);
113
1,329
1,442
<methods>public non-sealed void <init>() ,public final void transform(soot.Body, java.lang.String, Map<java.lang.String,java.lang.String>) ,public final void transform(soot.Body, java.lang.String) ,public final void transform(soot.Body) <variables>private static final Map<java.lang.String,java.lang.String> enabledOnlyMap
soot-oss_soot
soot/src/main/java/soot/dexpler/DexClassLoader.java
DexClassLoader
loadField
class DexClassLoader { /** * Loads a single method from a dex file * * @param method * The method to load * @param declaringClass * The class that declares the method to load * @param annotations * The worker object for handling annotations * @param dexMethodFactory * The factory method for creating dex methods */ protected void loadMethod(Method method, SootClass declaringClass, DexAnnotation annotations, DexMethod dexMethodFactory) { SootMethod sm = dexMethodFactory.makeSootMethod(method); if (declaringClass.declaresMethod(sm.getName(), sm.getParameterTypes(), sm.getReturnType())) { return; } declaringClass.addMethod(sm); annotations.handleMethodAnnotation(sm, method); } public Dependencies makeSootClass(SootClass sc, ClassDef defItem, DexEntry<? extends DexFile> dexEntry) { String superClass = defItem.getSuperclass(); Dependencies deps = new Dependencies(); // source file String sourceFile = defItem.getSourceFile(); if (sourceFile != null) { sc.addTag(new SourceFileTag(sourceFile)); } // super class for hierarchy level if (superClass != null) { String superClassName = Util.dottedClassName(superClass); SootClass sootSuperClass = SootResolver.v().makeClassRef(superClassName); sc.setSuperclass(sootSuperClass); deps.typesToHierarchy.add(sootSuperClass.getType()); } // access flags int accessFlags = defItem.getAccessFlags(); sc.setModifiers(accessFlags); // Retrieve interface names if (defItem.getInterfaces() != null) { for (String interfaceName : defItem.getInterfaces()) { String interfaceClassName = Util.dottedClassName(interfaceName); if (sc.implementsInterface(interfaceClassName)) { continue; } SootClass interfaceClass = SootResolver.v().makeClassRef(interfaceClassName); interfaceClass.setModifiers(interfaceClass.getModifiers() | Modifier.INTERFACE); sc.addInterface(interfaceClass); deps.typesToHierarchy.add(interfaceClass.getType()); } } if (Options.v().oaat() && sc.resolvingLevel() <= SootClass.HIERARCHY) { return deps; } DexAnnotation da = createDexAnnotation(sc, deps); // get the fields of the class for (Field sf : defItem.getStaticFields()) { loadField(sc, da, sf); } for (Field f : defItem.getInstanceFields()) { loadField(sc, da, f); } // get the methods of the class DexMethod dexMethod = createDexMethodFactory(dexEntry, sc); for (Method method : defItem.getDirectMethods()) { loadMethod(method, sc, da, dexMethod); } for (Method method : defItem.getVirtualMethods()) { loadMethod(method, sc, da, dexMethod); } da.handleClassAnnotation(defItem); // In contrast to Java, Dalvik associates the InnerClassAttribute // with the inner class, not the outer one. We need to copy the // tags over to correspond to the Soot semantics. InnerClassAttribute ica = (InnerClassAttribute) sc.getTag(InnerClassAttribute.NAME); if (ica != null) { Iterator<InnerClassTag> innerTagIt = ica.getSpecs().iterator(); while (innerTagIt.hasNext()) { Tag t = innerTagIt.next(); if (t instanceof InnerClassTag) { InnerClassTag ict = (InnerClassTag) t; // Get the outer class name String outer = DexInnerClassParser.getOuterClassNameFromTag(ict); if (outer == null || outer.length() == 0) { // If we don't have any clue what the outer class is, we // just remove the reference entirely innerTagIt.remove(); continue; } // If the tag is already associated with the outer class, // we leave it as it is if (outer.equals(sc.getName())) { continue; } // Check the inner class to make sure that this tag actually // refers to the current class as the inner class String inner = ict.getInnerClass().replaceAll("/", "."); if (!inner.equals(sc.getName())) { innerTagIt.remove(); continue; } SootClass osc = SootResolver.v().makeClassRef(outer); if (osc == sc) { if (!sc.hasOuterClass()) { continue; } osc = sc.getOuterClass(); } else { deps.typesToHierarchy.add(osc.getType()); } // Get the InnerClassAttribute of the outer class InnerClassAttribute icat = (InnerClassAttribute) osc.getTag(InnerClassAttribute.NAME); if (icat == null) { icat = new InnerClassAttribute(); osc.addTag(icat); } // Transfer the tag from the inner class to the outer class icat.add(ict); // Remove the tag from the inner class as inner classes do // not have these tags in the Java / Soot semantics. The // DexPrinter will copy it back if we do dex->dex. innerTagIt.remove(); // Add the InnerClassTag to the inner class. This tag will // be put in an InnerClassAttribute // within the PackManager in method handleInnerClasses(). if (!sc.hasTag(InnerClassTag.NAME)) { if (((InnerClassTag) t).getInnerClass().replaceAll("/", ".").equals(sc.toString())) { sc.addTag(t); } } } } // remove tag if empty if (ica.getSpecs().isEmpty()) { sc.getTags().remove(ica); } } return deps; } /** * Allow custom implementations to use different dex annotation implementations * * @param clazz * @param deps * @return */ protected DexAnnotation createDexAnnotation(SootClass clazz, Dependencies deps) { return new DexAnnotation(clazz, deps); } /** * Allow custom implementations to use different dex method factories * * @param dexFile * @param sc * @return */ protected DexMethod createDexMethodFactory(DexEntry<? extends DexFile> dexEntry, SootClass sc) { return new DexMethod(dexEntry, sc); } /** * Loads a single field from a dex file * * @param declaringClass * The class that declares the method to load * @param annotations * The worker object for handling annotations * @param field * The field to load */ protected void loadField(SootClass declaringClass, DexAnnotation annotations, Field sf) {<FILL_FUNCTION_BODY>} }
if (declaringClass.declaresField(sf.getName(), DexType.toSoot(sf.getType()))) { return; } SootField sootField = DexField.makeSootField(sf); sootField = declaringClass.getOrAddField(sootField); annotations.handleFieldAnnotation(sootField, sf);
1,907
97
2,004
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dexpler/DexDefUseAnalysis.java
DexDefUseAnalysis
getDefsOf
class DexDefUseAnalysis implements LocalDefs { private final Body body; private final Map<Local, Set<Unit>> localToUses = new HashMap<Local, Set<Unit>>(); private final Map<Local, Set<Unit>> localToDefs = new HashMap<Local, Set<Unit>>(); private final Map<Local, Set<Unit>> localToDefsWithAliases = new HashMap<Local, Set<Unit>>(); protected Map<Local, Integer> localToNumber = new HashMap<>(); protected BitSet[] localToDefsBits; protected BitSet[] localToUsesBits; protected List<Unit> unitList; public DexDefUseAnalysis(Body body) { this.body = body; initialize(); } protected void initialize() { int lastLocalNumber = 0; for (Local l : body.getLocals()) { localToNumber.put(l, lastLocalNumber++); } localToDefsBits = new BitSet[body.getLocalCount()]; localToUsesBits = new BitSet[body.getLocalCount()]; unitList = new ArrayList<>(body.getUnits()); for (int i = 0; i < unitList.size(); i++) { Unit u = unitList.get(i); // Record the definitions if (u instanceof DefinitionStmt) { Value val = ((DefinitionStmt) u).getLeftOp(); if (val instanceof Local) { final int localIdx = localToNumber.get((Local) val); BitSet bs = localToDefsBits[localIdx]; if (bs == null) { localToDefsBits[localIdx] = bs = new BitSet(); } bs.set(i); } } // Record the uses for (ValueBox vb : u.getUseBoxes()) { Value val = vb.getValue(); if (val instanceof Local) { final int localIdx = localToNumber.get((Local) val); BitSet bs = localToUsesBits[localIdx]; if (bs == null) { localToUsesBits[localIdx] = bs = new BitSet(); } bs.set(i); } } } } public Set<Unit> getUsesOf(Local l) { Set<Unit> uses = localToUses.get(l); if (uses == null) { uses = new HashSet<>(); BitSet bs = localToUsesBits[localToNumber.get(l)]; if (bs != null) { for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { uses.add(unitList.get(i)); } } localToUses.put(l, uses); } return uses; } /** * Collect definitions of l in body including the definitions of aliases of l. This analysis exploits that the problem is * flow-insensitive anyway. * * In this context an alias is a local that propagates its value to l. * * @param l * the local whose definitions are to collect */ protected Set<Unit> collectDefinitionsWithAliases(Local l) { Set<Unit> defs = localToDefsWithAliases.get(l); if (defs == null) { defs = new HashSet<Unit>(); Set<Local> seenLocals = new HashSet<Local>(); List<Local> newLocals = new ArrayList<Local>(); newLocals.add(l); while (!newLocals.isEmpty()) { Local curLocal = newLocals.remove(0); // Definition of l? BitSet bsDefs = localToDefsBits[localToNumber.get(curLocal)]; if (bsDefs != null) { for (int i = bsDefs.nextSetBit(0); i >= 0; i = bsDefs.nextSetBit(i + 1)) { Unit u = unitList.get(i); defs.add(u); DefinitionStmt defStmt = (DefinitionStmt) u; if (defStmt.getRightOp() instanceof Local && seenLocals.add((Local) defStmt.getRightOp())) { newLocals.add((Local) defStmt.getRightOp()); } } } // Use of l? BitSet bsUses = localToUsesBits[localToNumber.get(curLocal)]; if (bsUses != null) { for (int i = bsUses.nextSetBit(0); i >= 0; i = bsUses.nextSetBit(i + 1)) { Unit use = unitList.get(i); if (use instanceof AssignStmt) { AssignStmt assignUse = (AssignStmt) use; if (assignUse.getRightOp() == curLocal && assignUse.getLeftOp() instanceof Local && seenLocals.add((Local) assignUse.getLeftOp())) { newLocals.add((Local) assignUse.getLeftOp()); } } } } } localToDefsWithAliases.put(l, defs); } return defs; } @Override public List<Unit> getDefsOfAt(Local l, Unit s) { return getDefsOf(l); } @Override public List<Unit> getDefsOf(Local l) {<FILL_FUNCTION_BODY>} }
Set<Unit> defs = localToDefs.get(l); if (defs == null) { defs = new HashSet<>(); BitSet bs = localToDefsBits[localToNumber.get(l)]; if (bs != null) { for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { Unit u = unitList.get(i); if (u instanceof DefinitionStmt) { if (((DefinitionStmt) u).getLeftOp() == l) { defs.add(u); } } } } localToDefs.put(l, defs); } return new ArrayList<>(defs);
1,451
198
1,649
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dexpler/DexInnerClassParser.java
DexInnerClassParser
getOuterClassNameFromTag
class DexInnerClassParser { /** * Gets the name of the outer class (in Soot notation) from the given InnerClassTag * * @param icTag * The InnerClassTag from which to read the name of the outer class * @return The nam,e of the outer class (in Soot notation) as specified in the tag. If the specification is invalid, null * is returned. */ public static String getOuterClassNameFromTag(InnerClassTag icTag) {<FILL_FUNCTION_BODY>} }
String outerClass; if (icTag.getOuterClass() == null) { // anonymous and local classes String inner = icTag.getInnerClass().replaceAll("/", "."); if (inner.contains("$-")) { /* * This is a special case for generated lambda classes of jack and jill compiler. Generated lambda classes may * contain '$' which do not indicate an inner/outer class separator if the '$' occurs after a inner class with a name * starting with '-'. Thus we search for '$-' and anything after it including '-' is the inner classes name and * anything before it is the outer classes name. */ outerClass = inner.substring(0, inner.indexOf("$-")); } else if (inner.contains("$")) { // remove everything after the last '$' including the last '$' outerClass = inner.substring(0, inner.lastIndexOf('$')); } else { // This tag points nowhere outerClass = null; } } else { outerClass = icTag.getOuterClass().replaceAll("/", "."); } return outerClass;
142
289
431
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dexpler/DexJumpChainShortener.java
DexJumpChainShortener
internalTransform
class DexJumpChainShortener extends BodyTransformer { public static DexJumpChainShortener v() { return new DexJumpChainShortener(); } @Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) {<FILL_FUNCTION_BODY>} }
for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext();) { Unit u = unitIt.next(); if (u instanceof GotoStmt) { GotoStmt stmt = (GotoStmt) u; while (stmt.getTarget() instanceof GotoStmt) { GotoStmt nextTarget = (GotoStmt) stmt.getTarget(); stmt.setTarget(nextTarget.getTarget()); } } else if (u instanceof IfStmt) { IfStmt stmt = (IfStmt) u; while (stmt.getTarget() instanceof GotoStmt) { GotoStmt nextTarget = (GotoStmt) stmt.getTarget(); stmt.setTarget(nextTarget.getTarget()); } } }
87
214
301
<methods>public non-sealed void <init>() ,public final void transform(soot.Body, java.lang.String, Map<java.lang.String,java.lang.String>) ,public final void transform(soot.Body, java.lang.String) ,public final void transform(soot.Body) <variables>private static final Map<java.lang.String,java.lang.String> enabledOnlyMap
soot-oss_soot
soot/src/main/java/soot/dexpler/DexNullArrayRefTransformer.java
DexNullArrayRefTransformer
internalTransform
class DexNullArrayRefTransformer extends BodyTransformer { public static DexNullArrayRefTransformer v() { return new DexNullArrayRefTransformer(); } protected void internalTransform(final Body body, String phaseName, Map<String, String> options) {<FILL_FUNCTION_BODY>} /** * Checks whether the given local is guaranteed to be always null at the given statement * * @param s * The statement at which to check the local * @param base * The local to check * @param defs * The definition analysis object to use for the check * @return True if the given local is guaranteed to always be null at the given statement, otherwise false */ private boolean isAlwaysNullBefore(Stmt s, Local base, LocalDefs defs) { List<Unit> baseDefs = defs.getDefsOfAt(base, s); if (baseDefs.isEmpty()) { return true; } for (Unit u : baseDefs) { if (!(u instanceof DefinitionStmt)) { return false; } DefinitionStmt defStmt = (DefinitionStmt) u; if (defStmt.getRightOp() != NullConstant.v()) { return false; } } return true; } /** * Creates a new statement that throws a NullPointerException * * @param body * The body in which to create the statement * @param oldStmt * The old faulty statement that shall be replaced with the exception * @param lc * The object for creating new locals */ private void createThrowStmt(Body body, Unit oldStmt, LocalCreation lc) { RefType tp = RefType.v("java.lang.NullPointerException"); Local lcEx = lc.newLocal(tp); SootMethodRef constructorRef = Scene.v().makeConstructorRef(tp.getSootClass(), Collections.singletonList((Type) RefType.v("java.lang.String"))); // Create the exception instance Stmt newExStmt = Jimple.v().newAssignStmt(lcEx, Jimple.v().newNewExpr(tp)); body.getUnits().insertBefore(newExStmt, oldStmt); Stmt invConsStmt = Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(lcEx, constructorRef, Collections.singletonList(StringConstant.v("Invalid array reference replaced by Soot")))); body.getUnits().insertBefore(invConsStmt, oldStmt); // Throw the exception body.getUnits().swapWith(oldStmt, Jimple.v().newThrowStmt(lcEx)); } }
final ExceptionalUnitGraph g = ExceptionalUnitGraphFactory.createExceptionalUnitGraph(body, DalvikThrowAnalysis.v()); final LocalDefs defs = G.v().soot_toolkits_scalar_LocalDefsFactory().newLocalDefs(g); final LocalCreation lc = Scene.v().createLocalCreation(body.getLocals(), "ex"); boolean changed = false; for (Iterator<Unit> unitIt = body.getUnits().snapshotIterator(); unitIt.hasNext();) { Stmt s = (Stmt) unitIt.next(); if (s.containsArrayRef()) { // Check array reference Value base = s.getArrayRef().getBase(); if (isAlwaysNullBefore(s, (Local) base, defs)) { createThrowStmt(body, s, lc); changed = true; } } else if (s instanceof AssignStmt) { AssignStmt ass = (AssignStmt) s; Value rightOp = ass.getRightOp(); if (rightOp instanceof LengthExpr) { // Check lengthof expression LengthExpr l = (LengthExpr) ass.getRightOp(); Value base = l.getOp(); if (base instanceof IntConstant) { IntConstant ic = (IntConstant) base; if (ic.value == 0) { createThrowStmt(body, s, lc); changed = true; } } else if (base == NullConstant.v() || isAlwaysNullBefore(s, (Local) base, defs)) { createThrowStmt(body, s, lc); changed = true; } } } } if (changed) { UnreachableCodeEliminator.v().transform(body); }
714
459
1,173
<methods>public non-sealed void <init>() ,public final void transform(soot.Body, java.lang.String, Map<java.lang.String,java.lang.String>) ,public final void transform(soot.Body, java.lang.String) ,public final void transform(soot.Body) <variables>private static final Map<java.lang.String,java.lang.String> enabledOnlyMap
soot-oss_soot
soot/src/main/java/soot/dexpler/DexNullInstanceofTransformer.java
DexNullInstanceofTransformer
internalTransform
class DexNullInstanceofTransformer extends BodyTransformer { public static DexNullInstanceofTransformer v() { return new DexNullInstanceofTransformer(); } @Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) {<FILL_FUNCTION_BODY>} }
for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext();) { Unit u = unitIt.next(); if (u instanceof AssignStmt) { AssignStmt assignStmt = (AssignStmt) u; if (assignStmt.getRightOp() instanceof InstanceOfExpr) { InstanceOfExpr iof = (InstanceOfExpr) assignStmt.getRightOp(); // If the operand of the "instanceof" expression is null or // the zero constant, we replace the whole operation with // its outcome "false" if (iof.getOp() == NullConstant.v()) { assignStmt.setRightOp(IntConstant.v(0)); } if (iof.getOp() instanceof IntConstant && ((IntConstant) iof.getOp()).value == 0) { assignStmt.setRightOp(IntConstant.v(0)); } } } }
87
247
334
<methods>public non-sealed void <init>() ,public final void transform(soot.Body, java.lang.String, Map<java.lang.String,java.lang.String>) ,public final void transform(soot.Body, java.lang.String) ,public final void transform(soot.Body) <variables>private static final Map<java.lang.String,java.lang.String> enabledOnlyMap
soot-oss_soot
soot/src/main/java/soot/dexpler/DexNullThrowTransformer.java
DexNullThrowTransformer
internalTransform
class DexNullThrowTransformer extends BodyTransformer { public static DexNullThrowTransformer v() { return new DexNullThrowTransformer(); } @Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) {<FILL_FUNCTION_BODY>} /** * Creates a new statement that throws a NullPointerException * * @param body * The body in which to create the statement * @param oldStmt * The old faulty statement that shall be replaced with the exception * @param lc * The object for creating new locals */ private void createThrowStmt(Body body, Unit oldStmt, LocalCreation lc) { RefType tp = RefType.v("java.lang.NullPointerException"); Local lcEx = lc.newLocal(tp); SootMethodRef constructorRef = Scene.v().makeConstructorRef(tp.getSootClass(), Collections.singletonList((Type) RefType.v("java.lang.String"))); // Create the exception instance Stmt newExStmt = Jimple.v().newAssignStmt(lcEx, Jimple.v().newNewExpr(tp)); body.getUnits().insertBefore(newExStmt, oldStmt); Stmt invConsStmt = Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(lcEx, constructorRef, Collections.singletonList(StringConstant.v("Null throw statement replaced by Soot")))); body.getUnits().insertBefore(invConsStmt, oldStmt); // Throw the exception body.getUnits().swapWith(oldStmt, Jimple.v().newThrowStmt(lcEx)); } }
LocalCreation lc = Scene.v().createLocalCreation(b.getLocals(), "ex"); for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext();) { Unit u = unitIt.next(); // Check for a null exception if (u instanceof ThrowStmt) { ThrowStmt throwStmt = (ThrowStmt) u; if (throwStmt.getOp() == NullConstant.v() || throwStmt.getOp().equals(IntConstant.v(0)) || throwStmt.getOp().equals(LongConstant.v(0))) { createThrowStmt(b, throwStmt, lc); } } }
457
187
644
<methods>public non-sealed void <init>() ,public final void transform(soot.Body, java.lang.String, Map<java.lang.String,java.lang.String>) ,public final void transform(soot.Body, java.lang.String) ,public final void transform(soot.Body) <variables>private static final Map<java.lang.String,java.lang.String> enabledOnlyMap
soot-oss_soot
soot/src/main/java/soot/dexpler/DexReturnInliner.java
DexReturnInliner
internalTransform
class DexReturnInliner extends DexTransformer { public static DexReturnInliner v() { return new DexReturnInliner(); } private boolean isInstanceofReturn(Unit u) { if (u instanceof ReturnStmt || u instanceof ReturnVoidStmt) { return true; } return false; } private boolean isInstanceofFlowChange(Unit u) { if (u instanceof GotoStmt || isInstanceofReturn(u)) { return true; } return false; } @Override protected void internalTransform(final Body body, String phaseName, Map<String, String> options) {<FILL_FUNCTION_BODY>} /** * Gets the set of return statements that can be reached via fall-throughs, i.e. normal sequential code execution. Dually, * these are the statements that can be reached without jumping there. * * @param body * The method body * @return The set of fall-through return statements */ private Set<Unit> getFallThroughReturns(Body body) { Set<Unit> fallThroughReturns = null; Unit lastUnit = null; for (Unit u : body.getUnits()) { if (lastUnit != null && isInstanceofReturn(u) && !isInstanceofFlowChange(lastUnit)) { if (fallThroughReturns == null) { fallThroughReturns = new HashSet<Unit>(); } fallThroughReturns.add(u); } lastUnit = u; } return fallThroughReturns; } }
Set<Unit> duplicateIfTargets = getFallThroughReturns(body); Iterator<Unit> it = body.getUnits().snapshotIterator(); boolean mayBeMore = false; Unit last = null; do { mayBeMore = false; while (it.hasNext()) { Unit u = it.next(); if (u instanceof GotoStmt) { GotoStmt gtStmt = (GotoStmt) u; if (isInstanceofReturn(gtStmt.getTarget())) { Stmt stmt = (Stmt) gtStmt.getTarget().clone(); for (Trap t : body.getTraps()) { for (UnitBox ubox : t.getUnitBoxes()) { if (ubox.getUnit() == u) { ubox.setUnit(stmt); } } } while (!u.getBoxesPointingToThis().isEmpty()) { u.getBoxesPointingToThis().get(0).setUnit(stmt); } // the cloned return stmt gets the tags of u stmt.addAllTagsOf(u); body.getUnits().swapWith(u, stmt); mayBeMore = true; } } else if (u instanceof IfStmt) { IfStmt ifstmt = (IfStmt) u; Unit t = ifstmt.getTarget(); if (isInstanceofReturn(t)) { // We only copy this return if it is used more than // once, otherwise we will end up with unused copies if (duplicateIfTargets == null) { duplicateIfTargets = new HashSet<Unit>(); } if (!duplicateIfTargets.add(t)) { Unit newTarget = (Unit) t.clone(); body.getUnits().addLast(newTarget); ifstmt.setTarget(newTarget); } } } else if (isInstanceofReturn(u)) { // the original return stmt gets the tags of its predecessor if (last != null) { u.removeAllTags(); u.addAllTagsOf(last); } } last = u; } } while (mayBeMore);
408
571
979
<methods>public non-sealed void <init>() <variables>
soot-oss_soot
soot/src/main/java/soot/dexpler/DexReturnPacker.java
DexReturnPacker
internalTransform
class DexReturnPacker extends BodyTransformer { public static DexReturnPacker v() { return new DexReturnPacker(); } @Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) {<FILL_FUNCTION_BODY>} /** * Checks whether the two given units are semantically equal * * @param unit1 * The first unit * @param unit2 * The second unit * @return True if the two given units are semantically equal, otherwise false */ private boolean isEqual(Unit unit1, Unit unit2) { // Trivial case if (unit1 == unit2 || unit1.equals(unit2)) { return true; } // Semantic check if (unit1.getClass() == unit2.getClass()) { if (unit1 instanceof ReturnVoidStmt) { return true; } else if (unit1 instanceof ReturnStmt) { return ((ReturnStmt) unit1).getOp() == ((ReturnStmt) unit2).getOp(); } } return false; } }
// Look for consecutive return statements Unit lastUnit = null; for (Iterator<Unit> unitIt = b.getUnits().iterator(); unitIt.hasNext();) { Unit curUnit = unitIt.next(); if (curUnit instanceof ReturnStmt || curUnit instanceof ReturnVoidStmt) { // Check for duplicates if (lastUnit != null && isEqual(lastUnit, curUnit)) { curUnit.redirectJumpsToThisTo(lastUnit); unitIt.remove(); } else { lastUnit = curUnit; } } else { // Start over lastUnit = null; } }
301
168
469
<methods>public non-sealed void <init>() ,public final void transform(soot.Body, java.lang.String, Map<java.lang.String,java.lang.String>) ,public final void transform(soot.Body, java.lang.String) ,public final void transform(soot.Body) <variables>private static final Map<java.lang.String,java.lang.String> enabledOnlyMap
soot-oss_soot
soot/src/main/java/soot/dexpler/DexReturnValuePropagator.java
DexReturnValuePropagator
internalTransform
class DexReturnValuePropagator extends BodyTransformer { public static DexReturnValuePropagator v() { return new DexReturnValuePropagator(); } @Override protected void internalTransform(Body body, String phaseName, Map<String, String> options) {<FILL_FUNCTION_BODY>} /** * Checks whether the given local has been redefined between the original definition unitDef and the use unitUse. * * @param l * The local for which to check for redefinitions * @param unitUse * The unit that uses the local * @param unitDef * The unit that defines the local * @param graph * The unit graph to use for the check * @return True if there is at least one path between unitDef and unitUse on which local l gets redefined, otherwise false */ private boolean isRedefined(Local l, Unit unitUse, AssignStmt unitDef, UnitGraph graph) { List<Unit> workList = new ArrayList<Unit>(); workList.add(unitUse); Set<Unit> doneSet = new HashSet<Unit>(); // Check for redefinitions of the local between definition and use while (!workList.isEmpty()) { Unit curStmt = workList.remove(0); if (!doneSet.add(curStmt)) { continue; } for (Unit u : graph.getPredsOf(curStmt)) { if (u != unitDef) { if (u instanceof DefinitionStmt) { DefinitionStmt defStmt = (DefinitionStmt) u; if (defStmt.getLeftOp() == l) { return true; } } workList.add(u); } } } return false; } }
ExceptionalUnitGraph graph = ExceptionalUnitGraphFactory.createExceptionalUnitGraph(body, DalvikThrowAnalysis.v(), true); LocalDefs localDefs = G.v().soot_toolkits_scalar_LocalDefsFactory().newLocalDefs(graph); LocalUses localUses = null; LocalCreation localCreation = null; // If a return statement's operand has only one definition and this is // a copy statement, we take the original operand for (Unit u : body.getUnits()) { if (u instanceof ReturnStmt) { ReturnStmt retStmt = (ReturnStmt) u; if (retStmt.getOp() instanceof Local) { List<Unit> defs = localDefs.getDefsOfAt((Local) retStmt.getOp(), retStmt); if (defs.size() == 1 && defs.get(0) instanceof AssignStmt) { AssignStmt assign = (AssignStmt) defs.get(0); final Value rightOp = assign.getRightOp(); final Value leftOp = assign.getLeftOp(); // Copy over the left side if it is a local if (rightOp instanceof Local) { // We must make sure that the definition we propagate to // the return statement is not overwritten in between // a = 1; b = a; a = 3; return b; may not be translated // to return a; if (!isRedefined((Local) rightOp, u, assign, graph)) { retStmt.setOp(rightOp); } } else if (rightOp instanceof Constant) { retStmt.setOp(rightOp); } // If this is a field access which has no other uses, // we rename the local to help splitting else if (rightOp instanceof FieldRef) { if (localUses == null) { localUses = LocalUses.Factory.newLocalUses(body, localDefs); } if (localUses.getUsesOf(assign).size() == 1) { if (localCreation == null) { localCreation = Scene.v().createLocalCreation(body.getLocals(), "ret"); } Local newLocal = localCreation.newLocal(leftOp.getType()); assign.setLeftOp(newLocal); retStmt.setOp(newLocal); } } } } } }
466
622
1,088
<methods>public non-sealed void <init>() ,public final void transform(soot.Body, java.lang.String, Map<java.lang.String,java.lang.String>) ,public final void transform(soot.Body, java.lang.String) ,public final void transform(soot.Body) <variables>private static final Map<java.lang.String,java.lang.String> enabledOnlyMap
soot-oss_soot
soot/src/main/java/soot/dexpler/DexTrapStackFixer.java
DexTrapStackFixer
isCaughtExceptionRef
class DexTrapStackFixer extends BodyTransformer { public static DexTrapStackFixer v() { return new DexTrapStackFixer(); } @Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { for (Trap t : b.getTraps()) { // If the first statement already catches the exception, we're fine if (isCaughtExceptionRef(t.getHandlerUnit())) { continue; } // Add the exception reference Local l = Scene.v().createLocalGenerator(b).generateLocal(t.getException().getType()); Stmt caughtStmt = Jimple.v().newIdentityStmt(l, Jimple.v().newCaughtExceptionRef()); b.getUnits().add(caughtStmt); b.getUnits().add(Jimple.v().newGotoStmt(t.getHandlerUnit())); t.setHandlerUnit(caughtStmt); } } /** * Checks whether the given statement stores an exception reference * * @param handlerUnit * The statement to check * @return True if the given statement stores an exception reference, otherwise false */ private boolean isCaughtExceptionRef(Unit handlerUnit) {<FILL_FUNCTION_BODY>} }
if (!(handlerUnit instanceof IdentityStmt)) { return false; } IdentityStmt stmt = (IdentityStmt) handlerUnit; return stmt.getRightOp() instanceof CaughtExceptionRef;
342
58
400
<methods>public non-sealed void <init>() ,public final void transform(soot.Body, java.lang.String, Map<java.lang.String,java.lang.String>) ,public final void transform(soot.Body, java.lang.String) ,public final void transform(soot.Body) <variables>private static final Map<java.lang.String,java.lang.String> enabledOnlyMap
soot-oss_soot
soot/src/main/java/soot/dexpler/DexType.java
DexType
toSoot
class DexType { protected String name; protected TypeReference type; public DexType(TypeReference type) { if (type == null) { throw new RuntimeException("error: type ref is null!"); } this.type = type; this.name = type.getType(); } public DexType(String type) { if (type == null) { throw new RuntimeException("error: type is null!"); } this.type = new ImmutableTypeReference(type); this.name = type; } public String getName() { return name; } public boolean overwriteEquivalent(DexType field) { return name.equals(field.getName()); } public TypeReference getType() { return type; } /** * Return the appropriate Soot Type for this DexType. * * @return the Soot Type */ public Type toSoot() { return toSoot(type.getType(), 0); } /** * Return the appropriate Soot Type for the given TypeReference. * * @param type * the TypeReference to convert * @return the Soot Type */ public static Type toSoot(TypeReference type) { return toSoot(type.getType(), 0); } public static Type toSoot(String type) { return toSoot(type, 0); } /** * Return if the given TypeIdItem is wide (i.e. occupies 2 registers). * * @param typeReference.getType() * the TypeIdItem to analyze * @return if type is wide */ public static boolean isWide(TypeReference typeReference) { String t = typeReference.getType(); return isWide(t); } public static boolean isWide(String type) { return type.startsWith("J") || type.startsWith("D"); } /** * Determine the soot type from a byte code type descriptor. * */ private static Type toSoot(String typeDescriptor, int pos) {<FILL_FUNCTION_BODY>} /** * Seems that representation of Annotation type in Soot is not consistent with the normal type representation. Normal type * representation would be a.b.c.ClassName Java bytecode representation is La/b/c/ClassName; Soot Annotation type * representation (and Jasmin's) is a/b/c/ClassName. * * This method transforms the Java bytecode representation into the Soot annotation type representation. * * Ljava/lang/Class<Ljava/lang/Enum<*>;>; becomes java/lang/Class<java/lang/Enum<*>> * * @param type * @param pos * @return */ public static String toSootICAT(String type) { type = type.replace(".", "/"); String r = ""; String[] split1 = type.split(";"); for (String s : split1) { if (s.startsWith("L")) { s = s.replaceFirst("L", ""); } if (s.startsWith("<L")) { s = s.replaceFirst("<L", "<"); } r += s; } return r; } public static String toDalvikICAT(String type) { type = type.replaceAll("<", "<L"); type = type.replaceAll(">", ">;"); type = "L" + type; // a class name cannot be a primitive type = type.replaceAll("L\\*;", "*"); if (!type.endsWith(";")) { type += ";"; } return type; } /** * Types read from annotations should be converted to Soot type. However, to maintain compatibility with Soot code most * type will not be converted. * * @param type * @return */ public static String toSootAT(String type) { return type; } @Override public String toString() { return name; } }
Type type; char typeDesignator = typeDescriptor.charAt(pos); // see https://code.google.com/p/smali/wiki/TypesMethodsAndFields switch (typeDesignator) { case 'Z': // boolean type = BooleanType.v(); break; case 'B': // byte type = ByteType.v(); break; case 'S': // short type = ShortType.v(); break; case 'C': // char type = CharType.v(); break; case 'I': // int type = IntType.v(); break; case 'J': // long type = LongType.v(); break; case 'F': // float type = FloatType.v(); break; case 'D': // double type = DoubleType.v(); break; case 'L': // object type = RefType.v(Util.dottedClassName(typeDescriptor)); break; case 'V': // void type = VoidType.v(); break; case '[': // array type = toSoot(typeDescriptor, pos + 1).makeArrayType(); break; default: type = UnknownType.v(); } return type;
1,093
330
1,423
<no_super_class>
soot-oss_soot
soot/src/main/java/soot/dexpler/DexlibWrapper.java
ClassInformation
initialize
class ClassInformation { public DexEntry<? extends DexFile> dexEntry; public ClassDef classDefinition; public ClassInformation(DexEntry<? extends DexFile> entry, ClassDef classDef) { this.dexEntry = entry; this.classDefinition = classDef; } } private final Map<String, ClassInformation> classesToDefItems = new HashMap<String, ClassInformation>(); private final Collection<DexEntry<? extends DexFile>> dexFiles; /** * Construct a DexlibWrapper from a dex file and stores its classes referenced by their name. No further process is done * here. */ public DexlibWrapper(File dexSource) { try { List<DexFileProvider.DexContainer<? extends DexFile>> containers = DexFileProvider.v().getDexFromSource(dexSource); this.dexFiles = new ArrayList<>(containers.size()); for (DexFileProvider.DexContainer<? extends DexFile> container : containers) { this.dexFiles.add(container.getBase()); } } catch (IOException e) { throw new CompilationDeathException("IOException during dex parsing", e); } } /** * Allow custom implementations to use different class loading strategies. Do not remove this method. * * @return */ protected DexClassLoader createDexClassLoader() { return new DexClassLoader(); } public void initialize() {<FILL_FUNCTION_BODY>
// resolve classes in dex files for (DexEntry<? extends DexFile> dexEntry : dexFiles) { final DexFile dexFile = dexEntry.getDexFile(); for (ClassDef defItem : dexFile.getClasses()) { String forClassName = Util.dottedClassName(defItem.getType()); classesToDefItems.put(forClassName, new ClassInformation(dexEntry, defItem)); } } // It is important to first resolve the classes, otherwise we will // produce an error during type resolution. for (DexEntry<? extends DexFile> dexEntry : dexFiles) { final DexFile dexFile = dexEntry.getDexFile(); if (dexFile instanceof DexBackedDexFile) { for (DexBackedTypeReference typeRef : ((DexBackedDexFile) dexFile).getTypeReferences()) { String t = typeRef.getType(); Type st = DexType.toSoot(t); if (st instanceof ArrayType) { st = ((ArrayType) st).baseType; } String sootTypeName = st.toString(); if (!Scene.v().containsClass(sootTypeName)) { if (st instanceof PrimType || st instanceof VoidType || systemAnnotationNames.contains(sootTypeName)) { // dex files contain references to the Type IDs of void // primitive types - we obviously do not want them // to be resolved /* * dex files contain references to the Type IDs of the system annotations. They are only visible to the Dalvik * VM (for reflection, see vm/reflect/Annotations.cpp), and not to the user - so we do not want them to be * resolved. */ continue; } SootResolver.v().makeClassRef(sootTypeName); } SootResolver.v().resolveClass(sootTypeName, SootClass.SIGNATURES); } } }
397
513
910
<no_super_class>