repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
soot
soot-master/src/main/java/soot/Unit.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 1999 Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.io.Serializable; import java.util.List; import soot.tagkit.Host; import soot.util.Chain; import soot.util.Switchable; /** * A code fragment (eg Stmt or Inst), used within Body classes. Intermediate representations must use an implementation of * Unit for their code. In general, a unit denotes some sort of unit for execution. */ public interface Unit extends Switchable, Host, Serializable, Context { /** Returns a list of Boxes containing Values used in this Unit. */ public List<ValueBox> getUseBoxes(); /** Returns a list of Boxes containing Values defined in this Unit. */ public List<ValueBox> getDefBoxes(); /** * Returns a list of Boxes containing Units defined in this Unit; typically branch targets. */ public List<UnitBox> getUnitBoxes(); /** Returns a list of Boxes pointing to this Unit. */ public List<UnitBox> getBoxesPointingToThis(); /** Adds a box to the list returned by getBoxesPointingToThis. */ public void addBoxPointingToThis(UnitBox b); /** Removes a box from the list returned by getBoxesPointingToThis. */ public void removeBoxPointingToThis(UnitBox b); /** Clears any pointers to and from this Unit's UnitBoxes. */ public void clearUnitBoxes(); /** * Returns a list of Boxes containing any Value either used or defined in this Unit. */ public List<ValueBox> getUseAndDefBoxes(); public Object clone(); /** * Returns true if execution after this statement may continue at the following statement. GotoStmt will return false but * IfStmt will return true. */ public boolean fallsThrough(); /** * Returns true if execution after this statement does not necessarily continue at the following statement. GotoStmt and * IfStmt will both return true. */ public boolean branches(); public void toString(UnitPrinter up); /** * Redirects jumps to this Unit to newLocation. In general, you shouldn't have to use this directly. * * @see PatchingChain#getNonPatchingChain() * @see soot.shimple.Shimple#redirectToPreds(Chain, Unit) * @see soot.shimple.Shimple#redirectPointers(Unit, Unit) **/ public void redirectJumpsToThisTo(Unit newLocation); }
3,009
32.444444
123
java
soot
soot-master/src/main/java/soot/UnitBox.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 1999 Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.io.Serializable; /** * A box which can contain units. * * @see Unit */ public interface UnitBox extends Serializable { /** Sets this box to contain the given unit. Subject to canContainValue() checks. */ public void setUnit(Unit u); /** Returns the unit contained within this box. */ public Unit getUnit(); /** Returns true if this box can contain the given Unit. */ public boolean canContainUnit(Unit u); /** * Returns true if the UnitBox is holding a Unit that is the target of a branch (ie a Unit at the beginning of a CFG * block). This is the default case. * * <p> * Returns false if the UnitBox is holding a Unit that indicates the end of a CFG block and may require specialised * processing for SSA. **/ public boolean isBranchTarget(); public void toString(UnitPrinter up); }
1,666
29.87037
118
java
soot
soot-master/src/main/java/soot/UnitBoxOwner.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2003 Navindra Umanee <navindra@cs.mcgill.ca> * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.List; /** * An implementor of this interface indicates that it may contain UnitBoxes. * * <p> * Currently this is implemented by soot.shimple.PhiExpr and used by soot.jimple.internal.JAssignStmt. * * @author Navindra Umanee */ public interface UnitBoxOwner { public List<UnitBox> getUnitBoxes(); public void clearUnitBoxes(); }
1,199
28.268293
102
java
soot
soot-master/src/main/java/soot/UnitPatchingChain.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 1999 Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.Collection; import java.util.Collections; import java.util.List; import soot.jimple.GotoStmt; import soot.jimple.Jimple; import soot.util.Chain; /** * Although the Patching Chain is meant to only work for units, it can also work with certain subclasses of units. However, * for insertOnEdge and similar operations, new Jimple statements have to be generated. As such, it might be the case that a * {@code PatchingChain<X extends Unit>} is not allowed to contain such new statements, since they are not a subclass of X. * Therefore, we decided to create a chain specifically for units, where we can be certain that they are allowed to contain * all kind of units. Feel free to go and grab a beer. */ @SuppressWarnings("serial") public class UnitPatchingChain extends PatchingChain<Unit> { public UnitPatchingChain(Chain<Unit> aChain) { super(aChain); } /** * Inserts instrumentation in a manner such that the resulting control flow graph (CFG) of the program will contain * <code>toInsert</code> on an edge that is defined by <code>point_source</code> and <code>point_target</code>. * * @param toInsert * instrumentation to be added in the Chain * @param point_src * the source point of an edge in CFG * @param point_tgt * the target point of an edge */ public void insertOnEdge(Collection<? extends Unit> toInsert, Unit point_src, Unit point_tgt) { if (toInsert == null) { throw new RuntimeException("Tried to insert a null Collection into the Chain!"); } // Throw an exception if both source and target are null if (point_src == null && point_tgt == null) { throw new RuntimeException("insertOnEdge failed! Both source unit and target points are null."); } // Nothing to do if it's empty if (toInsert.isEmpty()) { return; } // Insert 'toInsert' before 'target' point in chain if the source point is null if (point_src == null) { assert (point_tgt != null); Unit firstInserted = toInsert.iterator().next(); point_tgt.redirectJumpsToThisTo(firstInserted); innerChain.insertBefore(toInsert, point_tgt); return; } // Insert 'toInsert' after 'source' point in chain if the target point is null if (point_tgt == null) { assert (point_src != null); innerChain.insertAfter(toInsert, point_src); return; } // If target is right after the source in the Chain // 1- Redirect all jumps (if any) from 'source' to 'target', to 'toInsert[0]' // (source->target) ==> (source->toInsert[0]) // 2- Insert 'toInsert' after 'source' in Chain if (getSuccOf(point_src) == point_tgt) { Unit firstInserted = toInsert.iterator().next(); for (UnitBox box : point_src.getUnitBoxes()) { if (box.getUnit() == point_tgt) { box.setUnit(firstInserted); } } innerChain.insertAfter(toInsert, point_src); return; } // If the target is not right after the source in chain then, // 1- Redirect all jumps (if any) from 'source' to 'target', to 'toInsert[0]' // (source->target) ==> (source->toInsert[0]) // 1.1- if there are no jumps from source to target, then such an edge // does not exist. Throw an exception. // 2- Insert 'toInsert' before 'target' in Chain // 3- If required, add a 'goto target' statement so that no other edge // executes 'toInsert' final Unit firstInserted = toInsert.iterator().next(); boolean validEdgeFound = false; Unit originalPred = this.getPredOf(point_tgt); for (UnitBox box : point_src.getUnitBoxes()) { if (box.getUnit() == point_tgt) { if (point_src instanceof GotoStmt) { box.setUnit(firstInserted); innerChain.insertAfter(toInsert, point_src); Unit goto_unit = Jimple.v().newGotoStmt(point_tgt); if (toInsert instanceof List) { List<? extends Unit> l = (List<? extends Unit>) toInsert; innerChain.insertAfter(goto_unit, l.get(l.size() - 1)); } else { innerChain.insertAfter(goto_unit, (Unit) toInsert.toArray()[toInsert.size() - 1]); } return; } box.setUnit(firstInserted); validEdgeFound = true; } } if (validEdgeFound) { innerChain.insertBefore(toInsert, point_tgt); if (originalPred != point_src) { if (originalPred instanceof GotoStmt) { return; } Unit goto_unit = Jimple.v().newGotoStmt(point_tgt); innerChain.insertBefore(Collections.singletonList(goto_unit), firstInserted); } return; } // In certain scenarios, the above code can add extra 'goto' units on a // different edge // So, an edge [src --> tgt] becomes [src -> goto tgt -> tgt]. // When this happens, the original edge [src -> tgt] ceases to exist. // The following code handles such scenarios. final Unit succ = getSuccOf(point_src); if (succ instanceof GotoStmt) { if (succ.getUnitBoxes().get(0).getUnit() == point_tgt) { succ.redirectJumpsToThisTo(firstInserted); innerChain.insertBefore(toInsert, succ); return; } } // If the control reaches this point, it means that an edge [src -> tgt] // as specified by user does not exist so throw an exception. throw new RuntimeException( "insertOnEdge failed! No such edge found. The edge on which you want to insert an instrumentation is invalid."); } /** * Inserts instrumentation in a manner such that the resulting control flow graph (CFG) of the program will contain * <code>toInsert</code> on an edge that is defined by <code>point_source</code> and <code>point_target</code>. * * @param toInsert * instrumentation to be added in the Chain * @param point_src * the source point of an edge in CFG * @param point_tgt * the target point of an edge */ public void insertOnEdge(List<Unit> toInsert, Unit point_src, Unit point_tgt) { insertOnEdge((Collection<Unit>) toInsert, point_src, point_tgt); } /** * Inserts instrumentation in a manner such that the resulting control flow graph (CFG) of the program will contain * <code>toInsert</code> on an edge that is defined by <code>point_source</code> and <code>point_target</code>. * * @param toInsert * instrumentation to be added in the Chain * @param point_src * the source point of an edge in CFG * @param point_tgt * the target point of an edge */ public void insertOnEdge(Chain<Unit> toInsert, Unit point_src, Unit point_tgt) { insertOnEdge((Collection<Unit>) toInsert, point_src, point_tgt); } /** * Inserts instrumentation in a manner such that the resulting control flow graph (CFG) of the program will contain * <code>toInsert</code> on an edge that is defined by <code>point_source</code> and <code>point_target</code>. * * @param toInsert * the instrumentation to be added in the Chain * @param point_src * the source point of an edge in CFG * @param point_tgt * the target point of an edge */ public void insertOnEdge(Unit toInsert, Unit point_src, Unit point_tgt) { insertOnEdge(Collections.singleton(toInsert), point_src, point_tgt); } }
8,215
37.754717
124
java
soot
soot-master/src/main/java/soot/UnitPrinter.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2003 Ondrej Lhotak * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.jimple.Constant; import soot.jimple.IdentityRef; /** * Interface for different methods of printing out a Unit. */ public interface UnitPrinter { public void startUnit(Unit u); public void endUnit(Unit u); public void startUnitBox(UnitBox u); public void endUnitBox(UnitBox u); public void startValueBox(ValueBox u); public void endValueBox(ValueBox u); public void incIndent(); public void decIndent(); public void noIndent(); public void setIndent(String newIndent); public String getIndent(); public void literal(String s); public void newline(); public void local(Local l); public void type(Type t); public void methodRef(SootMethodRef m); public void constant(Constant c); public void fieldRef(SootFieldRef f); public void unitRef(Unit u, boolean branchTarget); public void identityRef(IdentityRef r); public void setPositionTagger(AttributesUnitPrinter pt); public AttributesUnitPrinter getPositionTagger(); public StringBuffer output(); }
1,842
22.329114
71
java
soot
soot-master/src/main/java/soot/UnknownMethodSource.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ /** * A MethodSource for methods that don't know where to get Body's from. * * @see soot.jimple.JimpleMethodSource * @see soot.coffi.CoffiMethodSource */ public class UnknownMethodSource implements MethodSource { UnknownMethodSource() { } public Body getBody(SootMethod m, String phaseName) { // 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()); } }
1,741
30.107143
90
java
soot
soot-master/src/main/java/soot/UnknownType.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 1999 Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.util.Switch; /** * Soot representation used for not-yet-typed objects. Implemented as a singleton. */ @SuppressWarnings("serial") public class UnknownType extends Type { public UnknownType(Singletons.Global g) { } public static UnknownType v() { return G.v().soot_UnknownType(); } @Override public int hashCode() { return 0x5CAE5357; } @Override public boolean equals(Object t) { return this == t; } @Override public String toString() { return "unknown"; } @Override public void apply(Switch sw) { ((TypeSwitch) sw).caseUnknownType(this); } /** * Returns the least common superclass of this type and other. */ @Override public Type merge(Type other, Scene cm) { if (other instanceof RefType) { return other; } throw new RuntimeException("illegal type merge: " + this + " and " + other); } }
1,719
23.225352
82
java
soot
soot-master/src/main/java/soot/Value.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 1999 Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.io.Serializable; import java.util.List; import soot.util.Switchable; /** * Data used as, for instance, arguments to instructions; typical implementations are constants or expressions. * * Values are typed, clonable and must declare which other Values they use (contain). */ public interface Value extends Switchable, EquivTo, Serializable { /** * Returns a List of boxes corresponding to Values which are used by (ie contained within) this Value. */ public List<ValueBox> getUseBoxes(); /** * Returns the Soot type of this Value. */ public Type getType(); /** * Returns a clone of this Value. */ public Object clone(); public void toString(UnitPrinter up); }
1,535
27.444444
111
java
soot
soot-master/src/main/java/soot/ValueBox.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 1999 Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.io.Serializable; import soot.tagkit.Host; /** * A box which can contain values. * * @see Value */ public interface ValueBox extends Host, Serializable { /** Sets the value contained in this box as given. Subject to canContainValue() checks. */ public void setValue(Value value); /** Returns the value contained in this box. */ public Value getValue(); /** Returns true if the given Value fits in this box. */ public boolean canContainValue(Value value); public void toString(UnitPrinter up); }
1,352
27.787234
92
java
soot
soot-master/src/main/java/soot/VoidType.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 1999 Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.util.Switch; /** * Represents the Java void type. */ @SuppressWarnings("serial") public class VoidType extends Type { public VoidType(Singletons.Global g) { } public static VoidType v() { return G.v().soot_VoidType(); } @Override public int hashCode() { return 0x3A8C1035; } @Override public boolean equals(Object t) { return this == t; } @Override public String toString() { return "void"; } @Override public void apply(Switch sw) { ((TypeSwitch) sw).caseVoidType(this); } @Override public boolean isAllowedInFinalCode() { return true; } }
1,447
21.276923
71
java
soot
soot-master/src/main/java/soot/XMLAttributesPrinter.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2003 Jennifer Lhotak * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public 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() { 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()); } } 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; } }
3,900
25.537415
91
java
soot
soot-master/src/main/java/soot/asm/AnnotationElemBuilder.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.ArrayList; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import soot.tagkit.AnnotationAnnotationElem; import soot.tagkit.AnnotationArrayElem; import soot.tagkit.AnnotationClassElem; import soot.tagkit.AnnotationDoubleElem; import soot.tagkit.AnnotationElem; import soot.tagkit.AnnotationEnumElem; import soot.tagkit.AnnotationFloatElem; import soot.tagkit.AnnotationIntElem; import soot.tagkit.AnnotationLongElem; import soot.tagkit.AnnotationStringElem; import soot.tagkit.AnnotationTag; /** * Annotation element builder. * * @author Aaloan Miftah */ abstract 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) { 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); } @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(); }
6,198
35.040698
101
java
soot
soot-master/src/main/java/soot/asm/AsmClassProvider.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.ClassProvider; import soot.ClassSource; import soot.FoundFile; import soot.SourceLocator; /** * Objectweb ASM class provider. * * @author Aaloan Miftah */ public class AsmClassProvider implements ClassProvider { @Override public ClassSource find(String cls) { String clsFile = cls.replace('.', '/') + ".class"; FoundFile file = SourceLocator.v().lookupInClassPath(clsFile); return file == null ? null : new AsmClassSource(cls, file); } }
1,312
28.840909
71
java
soot
soot-master/src/main/java/soot/asm/AsmClassSource.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.io.IOException; import java.io.InputStream; import org.objectweb.asm.ClassReader; import soot.ClassSource; import soot.FoundFile; import soot.SootClass; import soot.SootResolver; import soot.javaToJimple.IInitialResolver.Dependencies; /** * ASM class source implementation. * * @author Aaloan Miftah */ public class AsmClassSource extends ClassSource { protected FoundFile foundFile; /** * Constructs a new ASM class source. * * @param cls * fully qualified name of the class. * @param foundFile * foundfile pointing to the data for class. */ protected AsmClassSource(String cls, FoundFile foundFile) { super(cls); if (foundFile == null) { throw new IllegalStateException("Error: The FoundFile must not be null."); } this.foundFile = foundFile; } @Override public Dependencies resolve(SootClass sc) { InputStream d = null; try { d = foundFile.inputStream(); ClassReader clsr = new ClassReader(d); SootClassBuilder scb = new SootClassBuilder(sc); clsr.accept(scb, ClassReader.SKIP_FRAMES); Dependencies deps = new Dependencies(); deps.typesToSignature.addAll(scb.deps); // add the outer class information, could not be called in the builder, since sc needs to be // resolved - before calling setOuterClass() if (!sc.hasOuterClass() && className.contains("$")) { String outerClassName; if (className.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. */ outerClassName = className.substring(0, className.indexOf("$-")); } else { outerClassName = className.substring(0, className.lastIndexOf('$')); } sc.setOuterClass(SootResolver.v().makeClassRef(outerClassName)); } return deps; } catch (IOException e) { throw new RuntimeException("Error: Failed to create class reader from class source.", e); } finally { try { if (d != null) { d.close(); d = null; } } catch (IOException e) { throw new RuntimeException("Error: Failed to close source input stream.", e); } finally { close(); } } } @Override public void close() { if (foundFile != null) { foundFile.close(); foundFile = null; } } }
3,589
31.636364
122
java
soot
soot-master/src/main/java/soot/asm/AsmJava9ClassProvider.java
/*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ package soot.asm; import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.FileSystemNotFoundException; import java.nio.file.Files; import java.nio.file.Path; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import soot.ClassProvider; import soot.ClassSource; import soot.FoundFile; import soot.ModulePathSourceLocator; /** * Objectweb ASM class provider. * * @author Andreas Dann */ public class AsmJava9ClassProvider implements ClassProvider { private static final Logger logger = LoggerFactory.getLogger(AsmJava9ClassProvider.class); @Override public ClassSource find(String cls) { final String clsFile = cls.replace('.', '/') + ".class"; // here we go through all modules, since we are in classpath mode FoundFile 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); } }
2,263
31.811594
104
java
soot
soot-master/src/main/java/soot/asm/AsmMethodSource.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import static org.objectweb.asm.Opcodes.ACONST_NULL; import static org.objectweb.asm.Opcodes.ALOAD; import static org.objectweb.asm.Opcodes.ANEWARRAY; import static org.objectweb.asm.Opcodes.ARETURN; import static org.objectweb.asm.Opcodes.ARRAYLENGTH; import static org.objectweb.asm.Opcodes.ASTORE; import static org.objectweb.asm.Opcodes.ATHROW; import static org.objectweb.asm.Opcodes.BIPUSH; import static org.objectweb.asm.Opcodes.CHECKCAST; import static org.objectweb.asm.Opcodes.D2F; import static org.objectweb.asm.Opcodes.D2I; import static org.objectweb.asm.Opcodes.D2L; import static org.objectweb.asm.Opcodes.DADD; import static org.objectweb.asm.Opcodes.DALOAD; import static org.objectweb.asm.Opcodes.DASTORE; import static org.objectweb.asm.Opcodes.DCMPG; import static org.objectweb.asm.Opcodes.DCMPL; import static org.objectweb.asm.Opcodes.DCONST_0; import static org.objectweb.asm.Opcodes.DCONST_1; import static org.objectweb.asm.Opcodes.DDIV; import static org.objectweb.asm.Opcodes.DLOAD; import static org.objectweb.asm.Opcodes.DMUL; import static org.objectweb.asm.Opcodes.DNEG; import static org.objectweb.asm.Opcodes.DREM; import static org.objectweb.asm.Opcodes.DRETURN; import static org.objectweb.asm.Opcodes.DSTORE; import static org.objectweb.asm.Opcodes.DSUB; import static org.objectweb.asm.Opcodes.DUP; import static org.objectweb.asm.Opcodes.DUP2; import static org.objectweb.asm.Opcodes.DUP2_X1; import static org.objectweb.asm.Opcodes.DUP2_X2; import static org.objectweb.asm.Opcodes.DUP_X1; import static org.objectweb.asm.Opcodes.DUP_X2; import static org.objectweb.asm.Opcodes.F2D; import static org.objectweb.asm.Opcodes.F2I; import static org.objectweb.asm.Opcodes.F2L; import static org.objectweb.asm.Opcodes.FCMPG; import static org.objectweb.asm.Opcodes.FCMPL; import static org.objectweb.asm.Opcodes.FCONST_0; import static org.objectweb.asm.Opcodes.FCONST_2; import static org.objectweb.asm.Opcodes.GETFIELD; import static org.objectweb.asm.Opcodes.GETSTATIC; import static org.objectweb.asm.Opcodes.GOTO; import static org.objectweb.asm.Opcodes.I2B; import static org.objectweb.asm.Opcodes.I2C; import static org.objectweb.asm.Opcodes.I2D; import static org.objectweb.asm.Opcodes.I2F; import static org.objectweb.asm.Opcodes.I2L; import static org.objectweb.asm.Opcodes.I2S; import static org.objectweb.asm.Opcodes.IADD; import static org.objectweb.asm.Opcodes.IALOAD; import static org.objectweb.asm.Opcodes.IAND; import static org.objectweb.asm.Opcodes.IASTORE; import static org.objectweb.asm.Opcodes.ICONST_0; import static org.objectweb.asm.Opcodes.ICONST_5; import static org.objectweb.asm.Opcodes.ICONST_M1; import static org.objectweb.asm.Opcodes.IDIV; import static org.objectweb.asm.Opcodes.IFEQ; import static org.objectweb.asm.Opcodes.IFGE; import static org.objectweb.asm.Opcodes.IFGT; import static org.objectweb.asm.Opcodes.IFLE; import static org.objectweb.asm.Opcodes.IFLT; import static org.objectweb.asm.Opcodes.IFNE; import static org.objectweb.asm.Opcodes.IFNONNULL; import static org.objectweb.asm.Opcodes.IFNULL; import static org.objectweb.asm.Opcodes.IF_ACMPEQ; import static org.objectweb.asm.Opcodes.IF_ACMPNE; import static org.objectweb.asm.Opcodes.IF_ICMPEQ; import static org.objectweb.asm.Opcodes.IF_ICMPGE; import static org.objectweb.asm.Opcodes.IF_ICMPGT; import static org.objectweb.asm.Opcodes.IF_ICMPLE; import static org.objectweb.asm.Opcodes.IF_ICMPLT; import static org.objectweb.asm.Opcodes.IF_ICMPNE; import static org.objectweb.asm.Opcodes.ILOAD; import static org.objectweb.asm.Opcodes.IMUL; import static org.objectweb.asm.Opcodes.INEG; import static org.objectweb.asm.Opcodes.INSTANCEOF; import static org.objectweb.asm.Opcodes.INVOKEINTERFACE; import static org.objectweb.asm.Opcodes.INVOKESPECIAL; import static org.objectweb.asm.Opcodes.INVOKESTATIC; import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; import static org.objectweb.asm.Opcodes.IOR; import static org.objectweb.asm.Opcodes.IREM; import static org.objectweb.asm.Opcodes.IRETURN; import static org.objectweb.asm.Opcodes.ISHL; import static org.objectweb.asm.Opcodes.ISHR; import static org.objectweb.asm.Opcodes.ISTORE; import static org.objectweb.asm.Opcodes.ISUB; import static org.objectweb.asm.Opcodes.IUSHR; import static org.objectweb.asm.Opcodes.IXOR; import static org.objectweb.asm.Opcodes.JSR; import static org.objectweb.asm.Opcodes.L2D; import static org.objectweb.asm.Opcodes.L2F; import static org.objectweb.asm.Opcodes.L2I; import static org.objectweb.asm.Opcodes.LADD; import static org.objectweb.asm.Opcodes.LALOAD; import static org.objectweb.asm.Opcodes.LAND; import static org.objectweb.asm.Opcodes.LASTORE; import static org.objectweb.asm.Opcodes.LCMP; import static org.objectweb.asm.Opcodes.LCONST_0; import static org.objectweb.asm.Opcodes.LCONST_1; import static org.objectweb.asm.Opcodes.LDIV; import static org.objectweb.asm.Opcodes.LLOAD; import static org.objectweb.asm.Opcodes.LMUL; import static org.objectweb.asm.Opcodes.LNEG; import static org.objectweb.asm.Opcodes.LOR; import static org.objectweb.asm.Opcodes.LREM; import static org.objectweb.asm.Opcodes.LRETURN; import static org.objectweb.asm.Opcodes.LSHL; import static org.objectweb.asm.Opcodes.LSHR; import static org.objectweb.asm.Opcodes.LSTORE; import static org.objectweb.asm.Opcodes.LSUB; import static org.objectweb.asm.Opcodes.LUSHR; import static org.objectweb.asm.Opcodes.LXOR; import static org.objectweb.asm.Opcodes.MONITORENTER; import static org.objectweb.asm.Opcodes.MONITOREXIT; import static org.objectweb.asm.Opcodes.NEW; import static org.objectweb.asm.Opcodes.NEWARRAY; import static org.objectweb.asm.Opcodes.NOP; import static org.objectweb.asm.Opcodes.POP; import static org.objectweb.asm.Opcodes.POP2; import static org.objectweb.asm.Opcodes.PUTFIELD; import static org.objectweb.asm.Opcodes.RET; import static org.objectweb.asm.Opcodes.RETURN; import static org.objectweb.asm.Opcodes.SALOAD; import static org.objectweb.asm.Opcodes.SASTORE; import static org.objectweb.asm.Opcodes.SIPUSH; import static org.objectweb.asm.Opcodes.SWAP; import static org.objectweb.asm.Opcodes.T_BOOLEAN; import static org.objectweb.asm.Opcodes.T_BYTE; import static org.objectweb.asm.Opcodes.T_CHAR; import static org.objectweb.asm.Opcodes.T_DOUBLE; import static org.objectweb.asm.Opcodes.T_FLOAT; import static org.objectweb.asm.Opcodes.T_INT; import static org.objectweb.asm.Opcodes.T_LONG; import static org.objectweb.asm.Opcodes.T_SHORT; import static org.objectweb.asm.tree.AbstractInsnNode.FIELD_INSN; import static org.objectweb.asm.tree.AbstractInsnNode.FRAME; import static org.objectweb.asm.tree.AbstractInsnNode.IINC_INSN; import static org.objectweb.asm.tree.AbstractInsnNode.INSN; import static org.objectweb.asm.tree.AbstractInsnNode.INT_INSN; import static org.objectweb.asm.tree.AbstractInsnNode.INVOKE_DYNAMIC_INSN; import static org.objectweb.asm.tree.AbstractInsnNode.JUMP_INSN; import static org.objectweb.asm.tree.AbstractInsnNode.LABEL; import static org.objectweb.asm.tree.AbstractInsnNode.LDC_INSN; import static org.objectweb.asm.tree.AbstractInsnNode.LINE; import static org.objectweb.asm.tree.AbstractInsnNode.LOOKUPSWITCH_INSN; import static org.objectweb.asm.tree.AbstractInsnNode.METHOD_INSN; import static org.objectweb.asm.tree.AbstractInsnNode.MULTIANEWARRAY_INSN; import static org.objectweb.asm.tree.AbstractInsnNode.TABLESWITCH_INSN; import static org.objectweb.asm.tree.AbstractInsnNode.TYPE_INSN; import static org.objectweb.asm.tree.AbstractInsnNode.VAR_INSN; import com.google.common.base.Optional; import com.google.common.collect.HashBasedTable; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Table; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Stack; import org.objectweb.asm.Handle; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.FieldInsnNode; import org.objectweb.asm.tree.IincInsnNode; import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.InsnNode; import org.objectweb.asm.tree.IntInsnNode; import org.objectweb.asm.tree.InvokeDynamicInsnNode; import org.objectweb.asm.tree.JumpInsnNode; import org.objectweb.asm.tree.LabelNode; import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.LineNumberNode; import org.objectweb.asm.tree.LocalVariableNode; import org.objectweb.asm.tree.LookupSwitchInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MultiANewArrayInsnNode; import org.objectweb.asm.tree.TableSwitchInsnNode; import org.objectweb.asm.tree.TryCatchBlockNode; import org.objectweb.asm.tree.TypeInsnNode; import org.objectweb.asm.tree.VarInsnNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import soot.ArrayType; import soot.Body; import soot.BooleanType; import soot.ByteType; import soot.CharType; import soot.DoubleType; import soot.FloatType; import soot.IntType; import soot.LambdaMetaFactory; import soot.Local; import soot.LongType; import soot.MethodSource; import soot.Modifier; import soot.ModuleScene; import soot.ModuleUtil; import soot.PackManager; import soot.PhaseOptions; import soot.RefType; import soot.Scene; import soot.ShortType; import soot.SootClass; import soot.SootFieldRef; import soot.SootMethod; import soot.SootMethodRef; import soot.Trap; import soot.Type; import soot.Unit; import soot.UnitBox; import soot.UnitPatchingChain; import soot.UnknownType; import soot.Value; import soot.ValueBox; import soot.VoidType; import soot.coffi.Util; import soot.jimple.AddExpr; import soot.jimple.ArrayRef; import soot.jimple.AssignStmt; import soot.jimple.BinopExpr; import soot.jimple.CastExpr; import soot.jimple.CaughtExceptionRef; import soot.jimple.ClassConstant; import soot.jimple.ConditionExpr; import soot.jimple.Constant; import soot.jimple.DefinitionStmt; import soot.jimple.DoubleConstant; import soot.jimple.FieldRef; import soot.jimple.FloatConstant; import soot.jimple.GotoStmt; import soot.jimple.IdentityStmt; import soot.jimple.InstanceFieldRef; import soot.jimple.InstanceInvokeExpr; import soot.jimple.InstanceOfExpr; import soot.jimple.IntConstant; import soot.jimple.InvokeExpr; import soot.jimple.Jimple; import soot.jimple.JimpleBody; import soot.jimple.LongConstant; import soot.jimple.LookupSwitchStmt; import soot.jimple.MethodHandle; import soot.jimple.MethodType; import soot.jimple.MonitorStmt; import soot.jimple.NewArrayExpr; import soot.jimple.NewMultiArrayExpr; import soot.jimple.NopStmt; import soot.jimple.NullConstant; import soot.jimple.ReturnStmt; import soot.jimple.StringConstant; import soot.jimple.TableSwitchStmt; import soot.jimple.ThrowStmt; import soot.jimple.UnopExpr; import soot.options.Options; import soot.tagkit.LineNumberTag; import soot.tagkit.Tag; import soot.util.Chain; /** * Generates Jimple bodies from bytecode. * * @author Aaloan Miftah */ public class AsmMethodSource implements MethodSource { private static final Logger logger = LoggerFactory.getLogger(AsmMethodSource.class); private static final Operand DWORD_DUMMY = new Operand(null, null); private static final String METAFACTORY_SIGNATURE = "<java.lang.invoke.LambdaMetafactory: java.lang.invoke.CallSite " + "metafactory(java.lang.invoke.MethodHandles$Lookup,java.lang.String,java.lang.invoke.MethodType," + "java.lang.invoke.MethodType,java.lang.invoke.MethodHandle,java.lang.invoke.MethodType)>"; private static final String ALT_METAFACTORY_SIGNATURE = "<java.lang.invoke.LambdaMetafactory: java.lang.invoke.CallSite " + "altMetafactory(java.lang.invoke.MethodHandles$Lookup," + "java.lang.String,java.lang.invoke.MethodType,java.lang.Object[])>"; /* -const fields- */ private final String module; private final int maxLocals; private final InsnList instructions; private final List<LocalVariableNode> localVars; private final List<TryCatchBlockNode> tryCatchBlocks; private final Set<LabelNode> inlineExceptionLabels = new LinkedHashSet<LabelNode>(); private final Map<LabelNode, Unit> inlineExceptionHandlers = new LinkedHashMap<LabelNode, Unit>(); private final CastAndReturnInliner castAndReturnInliner = new CastAndReturnInliner(); /* -state fields- */ protected int nextLocal; protected Map<Integer, Local> locals; private Multimap<LabelNode, UnitBox> labels; private Map<AbstractInsnNode, Unit> units; private ArrayList<Operand> stack; private Map<AbstractInsnNode, StackFrame> frames; private Multimap<LabelNode, UnitBox> trapHandlers; private JimpleBody body; private int lastLineNumber = -1; private Table<AbstractInsnNode, AbstractInsnNode, Edge> edges; private ArrayDeque<Edge> conversionWorklist; public AsmMethodSource(int maxLocals, InsnList insns, List<LocalVariableNode> localVars, List<TryCatchBlockNode> tryCatchBlocks, String module) { this.maxLocals = maxLocals; this.instructions = insns; this.localVars = localVars; this.tryCatchBlocks = tryCatchBlocks; this.module = module; } private StackFrame getFrame(AbstractInsnNode insn) { StackFrame frame = frames.get(insn); if (frame == null) { frame = new StackFrame(this); frames.put(insn, frame); } return frame; } private SootClass getClassFromScene(String className) { SootClass result; if (ModuleUtil.module_mode()) { result = ModuleScene.v().getSootClassUnsafe(className, Optional.fromNullable(this.module)); } else { result = Scene.v().getSootClassUnsafe(className); } if (result == null) { String msg = String.format("%s was not found on classpath.", className); if (Options.v().allow_phantom_refs()) { RefType ref = RefType.v(className); // make sure nobody else creates the same class synchronized (ref) { logger.warn(msg); result = Scene.v().makeSootClass(className, Modifier.PUBLIC); Scene.v().addClass(result); result.setPhantomClass(); return ref.getSootClass(); } } else { throw new RuntimeException(msg); } } return result; } private Local getLocal(int idx) { if (idx >= maxLocals) { throw new IllegalArgumentException("Invalid local index: " + idx); } Integer i = idx; Local l = locals.get(i); if (l == null) { String name = getLocalName(idx); l = Jimple.v().newLocal(name, UnknownType.v()); locals.put(i, l); } return l; } protected String getLocalName(int idx) { String name; if (localVars != null) { name = null; for (LocalVariableNode lvn : localVars) { // Ignore LocalVariableNode which don't cover any real units if (lvn.index == idx && lvn.start != lvn.end) { name = lvn.name; break; } } /* normally for try-catch blocks */ if (name == null) { name = "l" + idx; } } else { name = "l" + idx; } return name; } private void push(Operand opr) { stack.add(opr); } private void pushDual(Operand opr) { stack.add(DWORD_DUMMY); stack.add(opr); } private Operand peek() { return stack.get(stack.size() - 1); } private void push(Type t, Operand opr) { if (AsmUtil.isDWord(t)) { pushDual(opr); } else { push(opr); } } private Operand pop() { if (stack.isEmpty()) { throw new RuntimeException("Stack underrun"); } return stack.remove(stack.size() - 1); } private Operand popDual() { Operand o = pop(); Operand o2 = pop(); if (o2 != DWORD_DUMMY && o2 != o) { throw new AssertionError("Not dummy operand, " + o2.value + " -- " + o.value); } return o; } private Operand pop(Type t) { return AsmUtil.isDWord(t) ? popDual() : pop(); } private Operand popLocal(Operand o) { Value v = o.value; Local l = o.stack; if (l == null && !(v instanceof Local)) { l = o.stack = newStackLocal(); setUnit(o.insn, Jimple.v().newAssignStmt(l, v)); o.updateBoxes(); } return o; } private Operand popImmediate(Operand o) { Value v = o.value; Local l = o.stack; if (l == null && !(v instanceof Local) && !(v instanceof Constant)) { l = o.stack = newStackLocal(); setUnit(o.insn, Jimple.v().newAssignStmt(l, v)); o.updateBoxes(); } return o; } private Operand popStackConst(Operand o) { Value v = o.value; Local l = o.stack; if (l == null && !(v instanceof Constant)) { l = o.stack = newStackLocal(); setUnit(o.insn, Jimple.v().newAssignStmt(l, v)); o.updateBoxes(); } return o; } private Operand popLocal() { return popLocal(pop()); } private Operand popLocalDual() { return popLocal(popDual()); } @SuppressWarnings("unused") private Operand popLocal(Type t) { return AsmUtil.isDWord(t) ? popLocalDual() : popLocal(); } private Operand popImmediate() { return popImmediate(pop()); } private Operand popImmediateDual() { return popImmediate(popDual()); } private Operand popImmediate(Type t) { return AsmUtil.isDWord(t) ? popImmediateDual() : popImmediate(); } private Operand popStackConst() { return popStackConst(pop()); } private Operand popStackConstDual() { return popStackConst(popDual()); } @SuppressWarnings("unused") private Operand popStackConst(Type t) { return AsmUtil.isDWord(t) ? popStackConstDual() : popStackConst(); } void setUnit(AbstractInsnNode insn, Unit u) { if (Options.v().keep_line_number() && lastLineNumber >= 0) { Tag lineTag = u.getTag(LineNumberTag.NAME); if (lineTag == null) { lineTag = new LineNumberTag(lastLineNumber); u.addTag(lineTag); } else if (((LineNumberTag) lineTag).getLineNumber() != lastLineNumber) { throw new RuntimeException("Line tag mismatch"); } } Unit o = units.put(insn, u); if (o != null) { throw new AssertionError(insn.getOpcode() + " already has a unit, " + o); } } void mergeUnits(AbstractInsnNode insn, Unit u) { Unit prev = units.put(insn, u); if (prev != null) { Unit merged = new UnitContainer(prev, u); units.put(insn, merged); } } protected Local newStackLocal() { Integer idx = nextLocal++; Local l = Jimple.v().newLocal("$stack" + idx, UnknownType.v()); locals.put(idx, l); return l; } @SuppressWarnings("unchecked") <A extends Unit> A getUnit(AbstractInsnNode insn) { return (A) units.get(insn); } private void assignReadOps(Local l) { if (stack.isEmpty()) { return; } for (Operand opr : stack) { if (opr == DWORD_DUMMY || opr.stack != null || (l == null && opr.value instanceof Local)) { continue; } if (l != null && !opr.value.equivTo(l)) { List<ValueBox> uses = opr.value.getUseBoxes(); boolean noref = true; for (ValueBox use : uses) { Value val = use.getValue(); if (val.equivTo(l)) { noref = false; break; } } if (noref) { continue; } } int op = opr.insn.getOpcode(); if (l == null && op != GETFIELD && op != GETSTATIC && (op < IALOAD && op > SALOAD)) { continue; } Local stack = newStackLocal(); opr.stack = stack; AssignStmt as = Jimple.v().newAssignStmt(stack, opr.value); opr.updateBoxes(); setUnit(opr.insn, as); } } private void convertGetFieldInsn(FieldInsnNode insn) { StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; Type type; if (out == null) { SootClass declClass = this.getClassFromScene(AsmUtil.toQualifiedName(insn.owner)); type = AsmUtil.toJimpleType(insn.desc, Optional.fromNullable(this.body.getMethod().getDeclaringClass().moduleName)); Value val; SootFieldRef ref; if (insn.getOpcode() == GETSTATIC) { ref = Scene.v().makeFieldRef(declClass, insn.name, type, true); val = Jimple.v().newStaticFieldRef(ref); } else { Operand base = popLocal(); ref = Scene.v().makeFieldRef(declClass, insn.name, type, false); InstanceFieldRef ifr = Jimple.v().newInstanceFieldRef(base.stackOrValue(), ref); val = ifr; base.addBox(ifr.getBaseBox()); frame.in(base); frame.boxes(ifr.getBaseBox()); } opr = new Operand(insn, val); frame.out(opr); } else { opr = out[0]; type = opr.<FieldRef>value().getFieldRef().type(); if (insn.getOpcode() == GETFIELD) { frame.mergeIn(pop()); } } push(type, opr); } private void convertPutFieldInsn(FieldInsnNode insn) { boolean instance = insn.getOpcode() == PUTFIELD; StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr, rvalue; Type type; if (out == null) { SootClass declClass = this.getClassFromScene(AsmUtil.toQualifiedName(insn.owner)); type = AsmUtil.toJimpleType(insn.desc, Optional.fromNullable(this.body.getMethod().getDeclaringClass().moduleName)); Value val; SootFieldRef ref; rvalue = popImmediate(type); if (!instance) { ref = Scene.v().makeFieldRef(declClass, insn.name, type, true); val = Jimple.v().newStaticFieldRef(ref); frame.in(rvalue); } else { Operand base = popLocal(); ref = Scene.v().makeFieldRef(declClass, insn.name, type, false); InstanceFieldRef ifr = Jimple.v().newInstanceFieldRef(base.stackOrValue(), ref); val = ifr; base.addBox(ifr.getBaseBox()); frame.in(rvalue, base); } opr = new Operand(insn, val); frame.out(opr); AssignStmt as = Jimple.v().newAssignStmt(val, rvalue.stackOrValue()); rvalue.addBox(as.getRightOpBox()); if (!instance) { frame.boxes(as.getRightOpBox()); } else { frame.boxes(as.getRightOpBox(), ((InstanceFieldRef) val).getBaseBox()); } setUnit(insn, as); } else { opr = out[0]; type = opr.<FieldRef>value().getFieldRef().type(); rvalue = pop(type); if (!instance) { /* PUTSTATIC only needs one operand on the stack, the rvalue */ frame.mergeIn(rvalue); } else { /* PUTFIELD has a rvalue and a base */ frame.mergeIn(rvalue, pop()); } } /* * in case any static field or array is read from, and the static constructor or the field this instruction writes to, * modifies that field, write out any previous read from field/array */ assignReadOps(null); } private void convertFieldInsn(FieldInsnNode insn) { int op = insn.getOpcode(); if (op == GETSTATIC || op == GETFIELD) { convertGetFieldInsn(insn); } else { convertPutFieldInsn(insn); } } private void convertIincInsn(IincInsnNode insn) { Local local = getLocal(insn.var); assignReadOps(local); if (!units.containsKey(insn)) { AddExpr add = Jimple.v().newAddExpr(local, IntConstant.v(insn.incr)); setUnit(insn, Jimple.v().newAssignStmt(local, add)); } } private void convertConstInsn(InsnNode insn) { int op = insn.getOpcode(); StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { Value v; if (op == ACONST_NULL) { v = NullConstant.v(); } else if (op >= ICONST_M1 && op <= ICONST_5) { v = IntConstant.v(op - ICONST_0); } else if (op == LCONST_0 || op == LCONST_1) { v = LongConstant.v(op - LCONST_0); } else if (op >= FCONST_0 && op <= FCONST_2) { v = FloatConstant.v(op - FCONST_0); } else if (op == DCONST_0 || op == DCONST_1) { v = DoubleConstant.v(op - DCONST_0); } else { throw new AssertionError("Unknown constant opcode: " + op); } opr = new Operand(insn, v); frame.out(opr); } else { opr = out[0]; } if (op == LCONST_0 || op == LCONST_1 || op == DCONST_0 || op == DCONST_1) { pushDual(opr); } else { push(opr); } } /* * Following version is more complex, using stack frames as opposed to simply swapping */ /* * StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand dup, dup2 = null, dupd, dupd2 = null; if (out == * null) { dupd = popImmediate(); dup = new Operand(insn, dupd.stackOrValue()); if (dword) { dupd2 = peek(); if (dupd2 == * DWORD_DUMMY) { pop(); dupd2 = dupd; } else { dupd2 = popImmediate(); } dup2 = new Operand(insn, dupd2.stackOrValue()); * frame.out(dup, dup2); frame.in(dupd, dupd2); } else { frame.out(dup); frame.in(dupd); } } else { dupd = pop(); dup = * out[0]; if (dword) { dupd2 = pop(); if (dupd2 == DWORD_DUMMY) dupd2 = dupd; dup2 = out[1]; frame.mergeIn(dupd, dupd2); } * else { frame.mergeIn(dupd); } } */ private void convertArrayLoadInsn(InsnNode insn) { StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { Operand indx = popImmediate(); Operand base = popImmediate(); // We have a sample of totally broken code with a reference to a null array // x = null[i] // We silently fix this issue and return a null value if (base.value == NullConstant.v()) { opr = new Operand(insn, NullConstant.v()); frame.in(indx, base); frame.out(opr); } else { ArrayRef ar = Jimple.v().newArrayRef(base.stackOrValue(), indx.stackOrValue()); indx.addBox(ar.getIndexBox()); base.addBox(ar.getBaseBox()); opr = new Operand(insn, ar); frame.in(indx, base); frame.boxes(ar.getIndexBox(), ar.getBaseBox()); frame.out(opr); } } else { opr = out[0]; frame.mergeIn(pop(), pop()); } int op = insn.getOpcode(); if (op == DALOAD || op == LALOAD) { pushDual(opr); } else { push(opr); } } private void convertArrayStoreInsn(InsnNode insn) { int op = insn.getOpcode(); boolean dword = op == LASTORE || op == DASTORE; StackFrame frame = getFrame(insn); if (!units.containsKey(insn)) { Operand valu = dword ? popImmediateDual() : popImmediate(); Operand indx = popImmediate(); Operand base = popLocal(); ArrayRef ar = Jimple.v().newArrayRef(base.stackOrValue(), indx.stackOrValue()); indx.addBox(ar.getIndexBox()); base.addBox(ar.getBaseBox()); AssignStmt as = Jimple.v().newAssignStmt(ar, valu.stackOrValue()); valu.addBox(as.getRightOpBox()); frame.in(valu, indx, base); frame.boxes(as.getRightOpBox(), ar.getIndexBox(), ar.getBaseBox()); setUnit(insn, as); } else { frame.mergeIn(dword ? popDual() : pop(), pop(), pop()); } } private void convertDupInsn(InsnNode insn) { int op = insn.getOpcode(); // Get the top stack value which we need in either case Operand dupd = popImmediate(); Operand dupd2 = null; // Some instructions allow operands that take two registers boolean dword = op == DUP2 || op == DUP2_X1 || op == DUP2_X2; if (dword) { if (peek() == DWORD_DUMMY) { pop(); dupd2 = dupd; } else { dupd2 = popImmediate(); } } switch (op) { case DUP: { // val -> val, val push(dupd); push(dupd); break; } case DUP_X1: { // val2, val1 -> val1, val2, val1 // value1, value2 must not be of type double or long Operand o2 = popImmediate(); push(dupd); push(o2); push(dupd); break; } case DUP_X2: { // value3, value2, value1 -> value1, value3, value2, value1 Operand o2 = popImmediate(); Operand o3 = peek() == DWORD_DUMMY ? pop() : popImmediate(); push(dupd); push(o3); push(o2); push(dupd); break; } case DUP2: { // value2, value1 -> value2, value1, value2, value1 push(dupd2); push(dupd); push(dupd2); push(dupd); break; } case DUP2_X1: { // value3, value2, value1 -> value2, value1, value3, value2, value1 // Attention: value2 may be Operand o2 = popImmediate(); push(dupd2); push(dupd); push(o2); push(dupd2); push(dupd); break; } case DUP2_X2: { // (value4, value3), (value2, value1) -> (value2, value1), (value4, value3), (value2, value1) Operand o2 = popImmediate(); Operand o2h = peek() == DWORD_DUMMY ? pop() : popImmediate(); push(dupd2); push(dupd); push(o2h); push(o2); push(dupd2); push(dupd); break; } default: break; } } private void convertBinopInsn(InsnNode insn) { int op = insn.getOpcode(); boolean dword = op == DADD || op == LADD || op == DSUB || op == LSUB || op == DMUL || op == LMUL || op == DDIV || op == LDIV || op == DREM || op == LREM || op == LSHL || op == LSHR || op == LUSHR || op == LAND || op == LOR || op == LXOR || op == LCMP || op == DCMPL || op == DCMPG; StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { Operand op2 = (dword && op != LSHL && op != LSHR && op != LUSHR) ? popImmediateDual() : popImmediate(); Operand op1 = dword ? popImmediateDual() : popImmediate(); Value v1 = op1.stackOrValue(); Value v2 = op2.stackOrValue(); BinopExpr binop; if (op >= IADD && op <= DADD) { binop = Jimple.v().newAddExpr(v1, v2); } else if (op >= ISUB && op <= DSUB) { binop = Jimple.v().newSubExpr(v1, v2); } else if (op >= IMUL && op <= DMUL) { binop = Jimple.v().newMulExpr(v1, v2); } else if (op >= IDIV && op <= DDIV) { binop = Jimple.v().newDivExpr(v1, v2); } else if (op >= IREM && op <= DREM) { binop = Jimple.v().newRemExpr(v1, v2); } else if (op >= ISHL && op <= LSHL) { binop = Jimple.v().newShlExpr(v1, v2); } else if (op >= ISHR && op <= LSHR) { binop = Jimple.v().newShrExpr(v1, v2); } else if (op >= IUSHR && op <= LUSHR) { binop = Jimple.v().newUshrExpr(v1, v2); } else if (op >= IAND && op <= LAND) { binop = Jimple.v().newAndExpr(v1, v2); } else if (op >= IOR && op <= LOR) { binop = Jimple.v().newOrExpr(v1, v2); } else if (op >= IXOR && op <= LXOR) { binop = Jimple.v().newXorExpr(v1, v2); } else if (op == LCMP) { binop = Jimple.v().newCmpExpr(v1, v2); } else if (op == FCMPL || op == DCMPL) { binop = Jimple.v().newCmplExpr(v1, v2); } else if (op == FCMPG || op == DCMPG) { binop = Jimple.v().newCmpgExpr(v1, v2); } else { throw new AssertionError("Unknown binop: " + op); } op1.addBox(binop.getOp1Box()); op2.addBox(binop.getOp2Box()); opr = new Operand(insn, binop); frame.in(op2, op1); frame.boxes(binop.getOp2Box(), binop.getOp1Box()); frame.out(opr); } else { opr = out[0]; if (dword) { if (op != LSHL && op != LSHR && op != LUSHR) { frame.mergeIn(popDual(), popDual()); } else { frame.mergeIn(pop(), popDual()); } } else { frame.mergeIn(pop(), pop()); } } if (dword && (op < LCMP || op > DCMPG)) { pushDual(opr); } else { push(opr); } } private void convertUnopInsn(InsnNode insn) { int op = insn.getOpcode(); boolean dword = op == LNEG || op == DNEG; StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { Operand op1 = dword ? popImmediateDual() : popImmediate(); Value v1 = op1.stackOrValue(); UnopExpr unop; if (op >= INEG && op <= DNEG) { unop = Jimple.v().newNegExpr(v1); } else if (op == ARRAYLENGTH) { unop = Jimple.v().newLengthExpr(v1); } else { throw new AssertionError("Unknown unop: " + op); } op1.addBox(unop.getOpBox()); opr = new Operand(insn, unop); frame.in(op1); frame.boxes(unop.getOpBox()); frame.out(opr); } else { opr = out[0]; frame.mergeIn(dword ? popDual() : pop()); } if (dword) { pushDual(opr); } else { push(opr); } } private void convertPrimCastInsn(InsnNode insn) { int op = insn.getOpcode(); boolean tod = op == I2L || op == I2D || op == F2L || op == F2D || op == D2L || op == L2D; boolean fromd = op == D2L || op == L2D || op == D2I || op == L2I || op == D2F || op == L2F; StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { Type totype; switch (op) { case I2L: case F2L: case D2L: totype = LongType.v(); break; case L2I: case F2I: case D2I: totype = IntType.v(); break; case I2F: case L2F: case D2F: totype = FloatType.v(); break; case I2D: case L2D: case F2D: totype = DoubleType.v(); break; case I2B: totype = ByteType.v(); break; case I2S: totype = ShortType.v(); break; case I2C: totype = CharType.v(); break; default: throw new AssertionError("Unknonw prim cast op: " + op); } Operand val = fromd ? popImmediateDual() : popImmediate(); CastExpr cast = Jimple.v().newCastExpr(val.stackOrValue(), totype); opr = new Operand(insn, cast); val.addBox(cast.getOpBox()); frame.in(val); frame.boxes(cast.getOpBox()); frame.out(opr); } else { opr = out[0]; frame.mergeIn(fromd ? popDual() : pop()); } if (tod) { pushDual(opr); } else { push(opr); } } private void convertReturnInsn(InsnNode insn) { int op = insn.getOpcode(); boolean dword = op == LRETURN || op == DRETURN; StackFrame frame = getFrame(insn); if (!units.containsKey(insn)) { Operand val = dword ? popImmediateDual() : popImmediate(); ReturnStmt ret = Jimple.v().newReturnStmt(val.stackOrValue()); val.addBox(ret.getOpBox()); frame.in(val); frame.boxes(ret.getOpBox()); setUnit(insn, ret); } else { frame.mergeIn(dword ? popDual() : pop()); } } private void convertInsn(InsnNode insn) { int op = insn.getOpcode(); if (op == NOP) { /* * We can ignore NOP instructions, but for completeness, we handle them */ if (!units.containsKey(insn)) { units.put(insn, Jimple.v().newNopStmt()); } } else if (op >= ACONST_NULL && op <= DCONST_1) { convertConstInsn(insn); } else if (op >= IALOAD && op <= SALOAD) { convertArrayLoadInsn(insn); } else if (op >= IASTORE && op <= SASTORE) { convertArrayStoreInsn(insn); } else if (op == POP) { popImmediate(); } else if (op == POP2) { popImmediate(); if (peek() == DWORD_DUMMY) { pop(); } else { popImmediate(); } } else if (op >= DUP && op <= DUP2_X2) { convertDupInsn(insn); } else if (op == SWAP) { Operand o1 = popImmediate(); Operand o2 = popImmediate(); push(o1); push(o2); } else if ((op >= IADD && op <= DREM) || (op >= ISHL && op <= LXOR) || (op >= LCMP && op <= DCMPG)) { convertBinopInsn(insn); } else if ((op >= INEG && op <= DNEG) || op == ARRAYLENGTH) { convertUnopInsn(insn); } else if (op >= I2L && op <= I2S) { convertPrimCastInsn(insn); } else if (op >= IRETURN && op <= ARETURN) { convertReturnInsn(insn); } else if (op == RETURN) { if (!units.containsKey(insn)) { setUnit(insn, Jimple.v().newReturnVoidStmt()); } } else if (op == ATHROW) { StackFrame frame = getFrame(insn); Operand opr; if (!units.containsKey(insn)) { opr = popImmediate(); ThrowStmt ts = Jimple.v().newThrowStmt(opr.stackOrValue()); opr.addBox(ts.getOpBox()); frame.in(opr); frame.out(opr); frame.boxes(ts.getOpBox()); setUnit(insn, ts); } else { opr = pop(); frame.mergeIn(opr); } push(opr); } else if (op == MONITORENTER || op == MONITOREXIT) { StackFrame frame = getFrame(insn); if (!units.containsKey(insn)) { Operand opr = popStackConst(); MonitorStmt ts = op == MONITORENTER ? Jimple.v().newEnterMonitorStmt(opr.stackOrValue()) : Jimple.v().newExitMonitorStmt(opr.stackOrValue()); opr.addBox(ts.getOpBox()); frame.in(opr); frame.boxes(ts.getOpBox()); setUnit(insn, ts); } else { frame.mergeIn(pop()); } } else { throw new AssertionError("Unknown insn op: " + op); } } private void convertIntInsn(IntInsnNode insn) { int op = insn.getOpcode(); StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { Value v; if (op == BIPUSH || op == SIPUSH) { v = IntConstant.v(insn.operand); } else { Type type; switch (insn.operand) { case T_BOOLEAN: type = BooleanType.v(); break; case T_CHAR: type = CharType.v(); break; case T_FLOAT: type = FloatType.v(); break; case T_DOUBLE: type = DoubleType.v(); break; case T_BYTE: type = ByteType.v(); break; case T_SHORT: type = ShortType.v(); break; case T_INT: type = IntType.v(); break; case T_LONG: type = LongType.v(); break; default: throw new AssertionError("Unknown NEWARRAY type!"); } Operand size = popImmediate(); NewArrayExpr anew = Jimple.v().newNewArrayExpr(type, size.stackOrValue()); size.addBox(anew.getSizeBox()); frame.in(size); frame.boxes(anew.getSizeBox()); v = anew; } opr = new Operand(insn, v); frame.out(opr); } else { opr = out[0]; if (op == NEWARRAY) { frame.mergeIn(pop()); } } push(opr); } private void convertJumpInsn(JumpInsnNode insn) { int op = insn.getOpcode(); if (op == GOTO) { if (!units.containsKey(insn)) { UnitBox box = Jimple.v().newStmtBox(null); labels.put(insn.label, box); setUnit(insn, Jimple.v().newGotoStmt(box)); } return; } /* must be ifX insn */ StackFrame frame = getFrame(insn); if (!units.containsKey(insn)) { Operand val = popImmediate(); Value v = val.stackOrValue(); ConditionExpr cond; if (op >= IF_ICMPEQ && op <= IF_ACMPNE) { Operand val1 = popImmediate(); Value v1 = val1.stackOrValue(); switch (op) { case IF_ICMPEQ: cond = Jimple.v().newEqExpr(v1, v); break; case IF_ICMPNE: cond = Jimple.v().newNeExpr(v1, v); break; case IF_ICMPLT: cond = Jimple.v().newLtExpr(v1, v); break; case IF_ICMPGE: cond = Jimple.v().newGeExpr(v1, v); break; case IF_ICMPGT: cond = Jimple.v().newGtExpr(v1, v); break; case IF_ICMPLE: cond = Jimple.v().newLeExpr(v1, v); break; case IF_ACMPEQ: cond = Jimple.v().newEqExpr(v1, v); break; case IF_ACMPNE: cond = Jimple.v().newNeExpr(v1, v); break; default: throw new AssertionError("Unknown if op: " + op); } val1.addBox(cond.getOp1Box()); val.addBox(cond.getOp2Box()); frame.boxes(cond.getOp2Box(), cond.getOp1Box()); frame.in(val, val1); } else { switch (op) { case IFEQ: cond = Jimple.v().newEqExpr(v, IntConstant.v(0)); break; case IFNE: cond = Jimple.v().newNeExpr(v, IntConstant.v(0)); break; case IFLT: cond = Jimple.v().newLtExpr(v, IntConstant.v(0)); break; case IFGE: cond = Jimple.v().newGeExpr(v, IntConstant.v(0)); break; case IFGT: cond = Jimple.v().newGtExpr(v, IntConstant.v(0)); break; case IFLE: cond = Jimple.v().newLeExpr(v, IntConstant.v(0)); break; case IFNULL: cond = Jimple.v().newEqExpr(v, NullConstant.v()); break; case IFNONNULL: cond = Jimple.v().newNeExpr(v, NullConstant.v()); break; default: throw new AssertionError("Unknown if op: " + op); } val.addBox(cond.getOp1Box()); frame.boxes(cond.getOp1Box()); frame.in(val); } UnitBox box = Jimple.v().newStmtBox(null); labels.put(insn.label, box); setUnit(insn, Jimple.v().newIfStmt(cond, box)); } else { if (op >= IF_ICMPEQ && op <= IF_ACMPNE) { frame.mergeIn(pop(), pop()); } else { frame.mergeIn(pop()); } } } private void convertLdcInsn(LdcInsnNode insn) { Object val = insn.cst; boolean dword = val instanceof Long || val instanceof Double; StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { Value v = toSootValue(val); opr = new Operand(insn, v); frame.out(opr); } else { opr = out[0]; } if (dword) { pushDual(opr); } else { push(opr); } } private Value toSootValue(Object val) throws AssertionError { Value v; if (val instanceof Integer) { v = IntConstant.v((Integer) val); } else if (val instanceof Float) { v = FloatConstant.v((Float) val); } else if (val instanceof Long) { v = LongConstant.v((Long) val); } else if (val instanceof Double) { v = DoubleConstant.v((Double) val); } else if (val instanceof String) { v = StringConstant.v(val.toString()); } else if (val instanceof org.objectweb.asm.Type) { org.objectweb.asm.Type t = (org.objectweb.asm.Type) val; if (t.getSort() == org.objectweb.asm.Type.METHOD) { List<Type> paramTypes = AsmUtil.toJimpleDesc(((org.objectweb.asm.Type) val).getDescriptor(), Optional.fromNullable(this.body.getMethod().getDeclaringClass().moduleName)); Type returnType = paramTypes.remove(paramTypes.size() - 1); v = MethodType.v(paramTypes, returnType); } else { v = ClassConstant.v(((org.objectweb.asm.Type) val).getDescriptor()); } } else if (val instanceof Handle) { Handle h = (Handle) val; if (MethodHandle.isMethodRef(h.getTag())) { v = MethodHandle.v(toSootMethodRef((Handle) val), ((Handle) val).getTag()); } else { v = MethodHandle.v(toSootFieldRef((Handle) val), ((Handle) val).getTag()); } } else { throw new AssertionError("Unknown constant type: " + val.getClass()); } return v; } private void convertLookupSwitchInsn(LookupSwitchInsnNode insn) { StackFrame frame = getFrame(insn); if (units.containsKey(insn)) { frame.mergeIn(pop()); return; } Operand key = popImmediate(); UnitBox dflt = Jimple.v().newStmtBox(null); List<UnitBox> targets = new ArrayList<UnitBox>(insn.labels.size()); labels.put(insn.dflt, dflt); for (LabelNode ln : insn.labels) { UnitBox box = Jimple.v().newStmtBox(null); targets.add(box); labels.put(ln, box); } List<IntConstant> keys = new ArrayList<IntConstant>(insn.keys.size()); for (Integer i : insn.keys) { keys.add(IntConstant.v(i)); } LookupSwitchStmt lss = Jimple.v().newLookupSwitchStmt(key.stackOrValue(), keys, targets, dflt); key.addBox(lss.getKeyBox()); frame.in(key); frame.boxes(lss.getKeyBox()); setUnit(insn, lss); } private void convertMethodInsn(MethodInsnNode insn) { int op = insn.getOpcode(); boolean instance = op != INVOKESTATIC; StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; Type returnType; if (out == null) { String clsName = AsmUtil.toQualifiedName(insn.owner); if (clsName.charAt(0) == '[') { clsName = "java.lang.Object"; } List<Type> sigTypes = AsmUtil.toJimpleDesc(insn.desc, Optional.fromNullable(this.body.getMethod().getDeclaringClass().moduleName)); returnType = sigTypes.remove(sigTypes.size() - 1); SootMethodRef ref = Scene.v().makeMethodRef(this.getClassFromScene(clsName), insn.name, sigTypes, returnType, !instance); int nrArgs = sigTypes.size(); final Operand[] args; List<Value> argList = Collections.emptyList(); if (!instance) { args = nrArgs == 0 ? null : new Operand[nrArgs]; if (args != null) { argList = new ArrayList<Value>(nrArgs); } } else { args = new Operand[nrArgs + 1]; if (nrArgs != 0) { argList = new ArrayList<Value>(nrArgs); } } while (nrArgs-- != 0) { args[nrArgs] = popImmediate(sigTypes.get(nrArgs)); argList.add(args[nrArgs].stackOrValue()); } if (argList.size() > 1) { Collections.reverse(argList); } if (instance) { args[args.length - 1] = popLocal(); } ValueBox[] boxes = args == null ? null : new ValueBox[args.length]; InvokeExpr invoke; if (!instance) { invoke = Jimple.v().newStaticInvokeExpr(ref, argList); } else { Local base = (Local) args[args.length - 1].stackOrValue(); InstanceInvokeExpr iinvoke; switch (op) { case INVOKESPECIAL: iinvoke = Jimple.v().newSpecialInvokeExpr(base, ref, argList); break; case INVOKEVIRTUAL: iinvoke = Jimple.v().newVirtualInvokeExpr(base, ref, argList); break; case INVOKEINTERFACE: iinvoke = Jimple.v().newInterfaceInvokeExpr(base, ref, argList); break; default: throw new AssertionError("Unknown invoke op:" + op); } boxes[boxes.length - 1] = iinvoke.getBaseBox(); args[args.length - 1].addBox(boxes[boxes.length - 1]); invoke = iinvoke; } if (boxes != null) { for (int i = 0; i != sigTypes.size(); i++) { boxes[i] = invoke.getArgBox(i); args[i].addBox(boxes[i]); } frame.boxes(boxes); frame.in(args); } opr = new Operand(insn, invoke); frame.out(opr); } else { opr = out[0]; InvokeExpr expr = (InvokeExpr) opr.value; List<Type> types = expr.getMethodRef().getParameterTypes(); Operand[] oprs; int nrArgs = types.size(); if (expr.getMethodRef().isStatic()) { oprs = nrArgs == 0 ? null : new Operand[nrArgs]; } else { oprs = new Operand[nrArgs + 1]; } if (oprs != null) { while (nrArgs-- != 0) { oprs[nrArgs] = pop(types.get(nrArgs)); } if (!expr.getMethodRef().isStatic()) { oprs[oprs.length - 1] = pop(); } frame.mergeIn(oprs); nrArgs = types.size(); } returnType = expr.getMethodRef().getReturnType(); } if (AsmUtil.isDWord(returnType)) { pushDual(opr); } else if (!(returnType instanceof VoidType)) { push(opr); } else if (!units.containsKey(insn)) { setUnit(insn, Jimple.v().newInvokeStmt(opr.value)); } /* * assign all read ops in case the method modifies any of the fields */ assignReadOps(null); } private void convertInvokeDynamicInsn(InvokeDynamicInsnNode insn) { StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; Type returnType; if (out == null) { // convert info on bootstrap method SootMethodRef bsmMethodRef = toSootMethodRef(insn.bsm); List<Value> bsmMethodArgs = new ArrayList<Value>(insn.bsmArgs.length); for (Object bsmArg : insn.bsmArgs) { bsmMethodArgs.add(toSootValue(bsmArg)); } // create ref to actual method // Generate parameters & returnType & parameterTypes Type[] types = Util.v().jimpleTypesOfFieldOrMethodDescriptor(insn.desc); int nrArgs = types.length - 1; List<Type> parameterTypes = new ArrayList<Type>(nrArgs); List<Value> methodArgs = new ArrayList<Value>(nrArgs); Operand[] args = new Operand[nrArgs]; ValueBox[] boxes = new ValueBox[nrArgs]; // Beware: Call stack is FIFO, Jimple is linear while (nrArgs-- != 0) { parameterTypes.add(types[nrArgs]); args[nrArgs] = popImmediate(types[nrArgs]); methodArgs.add(args[nrArgs].stackOrValue()); } if (methodArgs.size() > 1) { Collections.reverse(methodArgs); // Call stack is FIFO, Jimple is linear Collections.reverse(parameterTypes); } returnType = types[types.length - 1]; SootMethodRef bootstrap_model = null; if (PhaseOptions.getBoolean(PhaseOptions.v().getPhaseOptions("jb"), "model-lambdametafactory")) { String bsmMethodRefStr = bsmMethodRef.toString(); if (bsmMethodRefStr.equals(METAFACTORY_SIGNATURE) || bsmMethodRefStr.equals(ALT_METAFACTORY_SIGNATURE)) { SootClass enclosingClass = body.getMethod().getDeclaringClass(); bootstrap_model = LambdaMetaFactory.v().makeLambdaHelper(bsmMethodArgs, insn.bsm.getTag(), insn.name, types, enclosingClass); } } InvokeExpr indy; if (bootstrap_model != null) { indy = Jimple.v().newStaticInvokeExpr(bootstrap_model, methodArgs); } else { // if not mimicking the LambdaMetaFactory, we model invokeDynamic method refs as static // method references of methods on the type SootClass.INVOKEDYNAMIC_DUMMY_CLASS_NAME SootClass bclass = Scene.v().getSootClass(SootClass.INVOKEDYNAMIC_DUMMY_CLASS_NAME); SootMethodRef methodRef = Scene.v().makeMethodRef(bclass, insn.name, parameterTypes, returnType, true); indy = Jimple.v().newDynamicInvokeExpr(bsmMethodRef, bsmMethodArgs, methodRef, insn.bsm.getTag(), methodArgs); } if (boxes != null) { for (int i = 0; i < types.length - 1; i++) { boxes[i] = indy.getArgBox(i); args[i].addBox(boxes[i]); } frame.boxes(boxes); frame.in(args); } opr = new Operand(insn, indy); frame.out(opr); } else { opr = out[0]; InvokeExpr expr = (InvokeExpr) opr.value; List<Type> types = expr.getMethodRef().getParameterTypes(); Operand[] oprs; int nrArgs = types.size(); if (expr.getMethodRef().isStatic()) { oprs = nrArgs == 0 ? null : new Operand[nrArgs]; } else { oprs = new Operand[nrArgs + 1]; } if (oprs != null) { while (nrArgs-- != 0) { oprs[nrArgs] = pop(types.get(nrArgs)); } if (!expr.getMethodRef().isStatic()) { oprs[oprs.length - 1] = pop(); } frame.mergeIn(oprs); nrArgs = types.size(); } returnType = expr.getMethodRef().getReturnType(); } if (AsmUtil.isDWord(returnType)) { pushDual(opr); } else if (!(returnType instanceof VoidType)) { push(opr); } else if (!units.containsKey(insn)) { setUnit(insn, Jimple.v().newInvokeStmt(opr.value)); } /* * assign all read ops in case the method modifies any of the fields */ assignReadOps(null); } private SootMethodRef toSootMethodRef(Handle methodHandle) { String bsmClsName = AsmUtil.toQualifiedName(methodHandle.getOwner()); SootClass bsmCls = this.getClassFromScene(bsmClsName); List<Type> bsmSigTypes = AsmUtil.toJimpleDesc(methodHandle.getDesc(), Optional.fromNullable(this.body.getMethod().getDeclaringClass().moduleName)); Type returnType = bsmSigTypes.remove(bsmSigTypes.size() - 1); return Scene.v().makeMethodRef(bsmCls, methodHandle.getName(), bsmSigTypes, returnType, methodHandle.getTag() == MethodHandle.Kind.REF_INVOKE_STATIC.getValue()); } private SootFieldRef toSootFieldRef(Handle methodHandle) { String bsmClsName = AsmUtil.toQualifiedName(methodHandle.getOwner()); SootClass bsmCls = Scene.v().getSootClass(bsmClsName); Type t = AsmUtil .toJimpleDesc(methodHandle.getDesc(), Optional.fromNullable(this.body.getMethod().getDeclaringClass().moduleName)) .get(0); int kind = methodHandle.getTag(); return Scene.v().makeFieldRef(bsmCls, methodHandle.getName(), t, kind == MethodHandle.Kind.REF_GET_FIELD_STATIC.getValue() || kind == MethodHandle.Kind.REF_PUT_FIELD_STATIC.getValue()); } private void convertMultiANewArrayInsn(MultiANewArrayInsnNode insn) { StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { ArrayType t = (ArrayType) AsmUtil.toJimpleType(insn.desc, Optional.fromNullable(this.body.getMethod().getDeclaringClass().moduleName)); int dims = insn.dims; Operand[] sizes = new Operand[dims]; Value[] sizeVals = new Value[dims]; ValueBox[] boxes = new ValueBox[dims]; while (dims-- != 0) { sizes[dims] = popImmediate(); sizeVals[dims] = sizes[dims].stackOrValue(); } NewMultiArrayExpr nm = Jimple.v().newNewMultiArrayExpr(t, Arrays.asList(sizeVals)); for (int i = 0; i != boxes.length; i++) { ValueBox vb = nm.getSizeBox(i); sizes[i].addBox(vb); boxes[i] = vb; } frame.boxes(boxes); frame.in(sizes); opr = new Operand(insn, nm); frame.out(opr); } else { opr = out[0]; int dims = insn.dims; Operand[] sizes = new Operand[dims]; while (dims-- != 0) { sizes[dims] = pop(); } frame.mergeIn(sizes); } push(opr); } private void convertTableSwitchInsn(TableSwitchInsnNode insn) { StackFrame frame = getFrame(insn); if (units.containsKey(insn)) { frame.mergeIn(pop()); return; } Operand key = popImmediate(); UnitBox dflt = Jimple.v().newStmtBox(null); List<UnitBox> targets = new ArrayList<UnitBox>(insn.labels.size()); labels.put(insn.dflt, dflt); for (LabelNode ln : insn.labels) { UnitBox box = Jimple.v().newStmtBox(null); targets.add(box); labels.put(ln, box); } TableSwitchStmt tss = Jimple.v().newTableSwitchStmt(key.stackOrValue(), insn.min, insn.max, targets, dflt); key.addBox(tss.getKeyBox()); frame.in(key); frame.boxes(tss.getKeyBox()); setUnit(insn, tss); } private void convertTypeInsn(TypeInsnNode insn) { int op = insn.getOpcode(); StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { Optional<String> module = Optional.fromNullable(this.body.getMethod().getDeclaringClass().moduleName); Type t = AsmUtil.toJimpleRefType(insn.desc, module); Value val; if (op == NEW) { val = Jimple.v().newNewExpr((RefType) t); } else { Operand op1 = popImmediate(); Value v1 = op1.stackOrValue(); ValueBox vb; switch (op) { case ANEWARRAY: { NewArrayExpr expr = Jimple.v().newNewArrayExpr(t, v1); vb = expr.getSizeBox(); val = expr; break; } case CHECKCAST: { CastExpr expr = Jimple.v().newCastExpr(v1, t); vb = expr.getOpBox(); val = expr; break; } case INSTANCEOF: { InstanceOfExpr expr = Jimple.v().newInstanceOfExpr(v1, t); vb = expr.getOpBox(); val = expr; break; } default: throw new AssertionError("Unknown type op: " + op); } op1.addBox(vb); frame.in(op1); frame.boxes(vb); } opr = new Operand(insn, val); frame.out(opr); } else { opr = out[0]; if (op != NEW) { frame.mergeIn(pop()); } } push(opr); } private void convertVarLoadInsn(VarInsnNode insn) { int op = insn.getOpcode(); boolean dword = op == LLOAD || op == DLOAD; StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { opr = new Operand(insn, getLocal(insn.var)); frame.out(opr); } else { opr = out[0]; } if (dword) { pushDual(opr); } else { push(opr); } } private void convertVarStoreInsn(VarInsnNode insn) { int op = insn.getOpcode(); boolean dword = op == LSTORE || op == DSTORE; StackFrame frame = getFrame(insn); Operand opr = dword ? popDual() : pop(); Local local = getLocal(insn.var); if (!units.containsKey(insn)) { DefinitionStmt as = Jimple.v().newAssignStmt(local, opr.stackOrValue()); opr.addBox(as.getRightOpBox()); frame.boxes(as.getRightOpBox()); frame.in(opr); setUnit(insn, as); } else { frame.mergeIn(opr); } assignReadOps(local); } private void convertVarInsn(VarInsnNode insn) { int op = insn.getOpcode(); if (op >= ILOAD && op <= ALOAD) { convertVarLoadInsn(insn); } else if (op >= ISTORE && op <= ASTORE) { convertVarStoreInsn(insn); } else if (op == RET) { /* we handle it, even thought it should be removed */ if (!units.containsKey(insn)) { setUnit(insn, Jimple.v().newRetStmt(getLocal(insn.var))); } } else { throw new AssertionError("Unknown var op: " + op); } } /* Conversion */ private void convertLabel(LabelNode ln) { if (!trapHandlers.containsKey(ln)) { return; } // We create a nop statement as a placeholder so that we can jump // somewhere from the real exception handler in case this is inline // code if (inlineExceptionLabels.contains(ln)) { if (!units.containsKey(ln)) { NopStmt nop = Jimple.v().newNopStmt(); setUnit(ln, nop); } return; } StackFrame frame = getFrame(ln); Operand[] out = frame.out(); Operand opr; if (out == null) { CaughtExceptionRef ref = Jimple.v().newCaughtExceptionRef(); Local stack = newStackLocal(); DefinitionStmt as = Jimple.v().newIdentityStmt(stack, ref); opr = new Operand(ln, ref); opr.stack = stack; frame.out(opr); setUnit(ln, as); } else { opr = out[0]; } push(opr); } private void convertLine(LineNumberNode ln) { lastLineNumber = ln.line; } private void addEdges(AbstractInsnNode cur, AbstractInsnNode tgt1, List<LabelNode> tgts) { int lastIdx = tgts == null ? -1 : tgts.size() - 1; Operand[] stackss = stack.toArray(new Operand[stack.size()]); List<Operand> stackssL = Arrays.asList(stackss); AbstractInsnNode tgt = tgt1; int i = 0; tgt_loop: do { Edge edge = edges.get(cur, tgt); if (edge == null) { // make sure to store last line number to stay sound if the branch that comes later in // bytecode is processed first edge = new Edge(tgt, lastLineNumber); edge.prevStacks.add(stackssL); edges.put(cur, tgt, edge); conversionWorklist.add(edge); continue; } if (edge.stack != null) { ArrayList<Operand> stackTemp = edge.stack; if (stackTemp.size() != stackss.length) { throw new AssertionError("Multiple un-equal stacks!"); } for (int j = 0; j != stackss.length; j++) { Operand tempOp = stackTemp.get(j); Operand stackOp = stackss[j]; if (!tempOp.equivTo(stackOp)) { // We need to merge the two operands. We have a join point, where the two paths have stacks of the same size, but // with different locals. Since the execution contains on the same statements after the join point, we must make // sure that they can operate on the same locals, regardless of which path the execution came from. merge(tempOp, stackOp); } } continue; } if (!edge.prevStacks.add(stackssL)) { continue tgt_loop; } edge.stack = new ArrayList<Operand>(stack); conversionWorklist.add(edge); } while (i <= lastIdx && (tgt = tgts.get(i++)) != null); } /** * Merges the given operands, i.e., the second operand will receive assignments to the stack locals of the first operand so * that both operands become compatible. * * @param firstOp */ private void merge(Operand firstOp, Operand secondOp) { if (secondOp.stack != null) { if (firstOp.stack == null) { Local stack = secondOp.stack; firstOp.stack = stack; AssignStmt as = Jimple.v().newAssignStmt(stack, firstOp.stackOrValue()); setUnit(firstOp.insn, as); } else { // Both operands have a stack local. We need to create an assignment to a temporary variable. Local stack = firstOp.stack; AssignStmt as = Jimple.v().newAssignStmt(stack, secondOp.stackOrValue()); mergeUnits(secondOp.insn, as); secondOp.addBox(as.getRightOpBox()); secondOp.stack = stack; } } else { if (firstOp.stack != null) { Local stack = firstOp.stack; secondOp.stack = stack; AssignStmt as = Jimple.v().newAssignStmt(stack, secondOp.stackOrValue()); setUnit(secondOp.insn, as); } else { throw new RuntimeException("Cannot merge operands, since neither has a stack local. Bummer."); } } } private void convert() { if (instructions == null || instructions.size() == 0) { return; } ArrayDeque<Edge> worklist = new ArrayDeque<Edge>(); for (LabelNode ln : trapHandlers.keySet()) { if (checkInlineExceptionHandler(ln)) { handleInlineExceptionHandler(ln, worklist); } else { worklist.add(new Edge(ln, new ArrayList<Operand>())); } } worklist.add(new Edge(instructions.getFirst(), new ArrayList<Operand>())); conversionWorklist = worklist; edges = HashBasedTable.create(instructions.size(), 1); do { Edge edge = worklist.pollLast(); AbstractInsnNode insn = edge.insn; stack = edge.stack; // restore line. this is important since we might have traversed the edge that leads to // bytecode far away from the branch statement first and are now processing the statement // right after the branch which should start with the lastLineNumber as it was for the branch // statement lastLineNumber = edge.lastLineNumber == -1 ? lastLineNumber : edge.lastLineNumber; edge.stack = null; insnLoop: do { int type = insn.getType(); switch (type) { case FIELD_INSN: convertFieldInsn((FieldInsnNode) insn); continue; case IINC_INSN: convertIincInsn((IincInsnNode) insn); continue; case INSN: convertInsn((InsnNode) insn); int op = insn.getOpcode(); if ((op >= IRETURN && op <= RETURN) || op == ATHROW) { break insnLoop; } continue; case INT_INSN: convertIntInsn((IntInsnNode) insn); continue; case LDC_INSN: convertLdcInsn((LdcInsnNode) insn); continue; case JUMP_INSN: JumpInsnNode jmp = (JumpInsnNode) insn; convertJumpInsn(jmp); op = jmp.getOpcode(); if (op == JSR) { throw new UnsupportedOperationException("JSR!"); } if (op != GOTO) { /* ifX opcode, i.e. two successors */ AbstractInsnNode next = insn.getNext(); addEdges(insn, next, Collections.singletonList(jmp.label)); } else { addEdges(insn, jmp.label, null); } break insnLoop; case LOOKUPSWITCH_INSN: LookupSwitchInsnNode swtch = (LookupSwitchInsnNode) insn; convertLookupSwitchInsn(swtch); LabelNode dflt = swtch.dflt; addEdges(insn, dflt, swtch.labels); break insnLoop; case METHOD_INSN: convertMethodInsn((MethodInsnNode) insn); continue; case INVOKE_DYNAMIC_INSN: convertInvokeDynamicInsn((InvokeDynamicInsnNode) insn); continue; case MULTIANEWARRAY_INSN: convertMultiANewArrayInsn((MultiANewArrayInsnNode) insn); continue; case TABLESWITCH_INSN: TableSwitchInsnNode tswtch = (TableSwitchInsnNode) insn; convertTableSwitchInsn(tswtch); LabelNode ldflt = tswtch.dflt; addEdges(insn, ldflt, tswtch.labels); break insnLoop; case TYPE_INSN: convertTypeInsn((TypeInsnNode) insn); continue; case VAR_INSN: if (insn.getOpcode() == RET) { throw new UnsupportedOperationException("RET!"); } convertVarInsn((VarInsnNode) insn); continue; case LABEL: convertLabel((LabelNode) insn); continue; case LINE: convertLine((LineNumberNode) insn); continue; case FRAME: // we can ignore it continue; default: throw new RuntimeException("Unknown instruction type: " + type); } } while ((insn = insn.getNext()) != null); } while (!worklist.isEmpty()); conversionWorklist = null; edges = null; } private void handleInlineExceptionHandler(LabelNode ln, ArrayDeque<Edge> worklist) { // Catch the exception CaughtExceptionRef ref = Jimple.v().newCaughtExceptionRef(); Local local = newStackLocal(); DefinitionStmt as = Jimple.v().newIdentityStmt(local, ref); Operand opr = new Operand(ln, ref); opr.stack = local; ArrayList<Operand> stack = new ArrayList<Operand>(); stack.add(opr); worklist.add(new Edge(ln, stack)); // Save the statements inlineExceptionHandlers.put(ln, as); } private boolean checkInlineExceptionHandler(LabelNode ln) { // If this label is reachable through an exception and through normal // code, we have to split the exceptional case (with the exception on the // stack) from the normal fall-through case without anything on the stack. for (AbstractInsnNode node : instructions) { if (node instanceof JumpInsnNode) { if (((JumpInsnNode) node).label == ln) { inlineExceptionLabels.add(ln); return true; } } else if (node instanceof LookupSwitchInsnNode) { if (((LookupSwitchInsnNode) node).labels.contains(ln)) { inlineExceptionLabels.add(ln); return true; } } else if (node instanceof TableSwitchInsnNode) { if (((TableSwitchInsnNode) node).labels.contains(ln)) { inlineExceptionLabels.add(ln); return true; } } } return false; } private void emitLocals() { JimpleBody jb = body; SootMethod m = jb.getMethod(); Collection<Local> jbl = jb.getLocals(); Collection<Unit> jbu = jb.getUnits(); int iloc = 0; if (!m.isStatic()) { Local l = getLocal(iloc++); jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newThisRef(m.getDeclaringClass().getType()))); } int nrp = 0; for (Object ot : m.getParameterTypes()) { Type t = (Type) ot; Local l = getLocal(iloc); jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newParameterRef(t, nrp++))); if (AsmUtil.isDWord(t)) { iloc += 2; } else { iloc++; } } for (Local l : locals.values()) { jbl.add(l); } } private void emitTraps() { Chain<Trap> traps = body.getTraps(); SootClass throwable = Scene.v().getSootClass("java.lang.Throwable"); Map<LabelNode, Iterator<UnitBox>> handlers = new LinkedHashMap<LabelNode, Iterator<UnitBox>>(tryCatchBlocks.size()); for (TryCatchBlockNode tc : tryCatchBlocks) { UnitBox start = Jimple.v().newStmtBox(null); UnitBox end = Jimple.v().newStmtBox(null); Iterator<UnitBox> hitr = handlers.get(tc.handler); if (hitr == null) { hitr = trapHandlers.get(tc.handler).iterator(); handlers.put(tc.handler, hitr); } UnitBox handler = hitr.next(); SootClass cls = tc.type == null ? throwable : getClassFromScene(AsmUtil.toQualifiedName(tc.type)); Trap trap = Jimple.v().newTrap(cls, start, end, handler); traps.add(trap); labels.put(tc.start, start); labels.put(tc.end, end); } } private static class UnitContainerWorklistElement { UnitContainer u; int position; public UnitContainerWorklistElement(UnitContainer u) { this.u = u; } } static void emitUnits(Unit u, UnitPatchingChain chain) { if (u instanceof UnitContainer) { Stack<UnitContainerWorklistElement> stack = new Stack<>(); stack.push(new UnitContainerWorklistElement((UnitContainer) u)); processStack: while (!stack.isEmpty()) { UnitContainerWorklistElement r = stack.peek(); for (int i = r.position; i < r.u.units.length; i++) { r.position = i + 1; Unit e = r.u.units[i]; if (e instanceof UnitContainer) { stack.push(new UnitContainerWorklistElement((UnitContainer) e)); continue processStack; } else { chain.add(e); } } if (stack.pop() != r) { throw new AssertionError("Not expected element"); } } } else { chain.add(u); } } private void emitUnits() { AbstractInsnNode insn = instructions.getFirst(); ArrayDeque<LabelNode> labls = new ArrayDeque<LabelNode>(); while (insn != null) { // Save the label to assign it to the next real unit if (insn instanceof LabelNode) { labls.add((LabelNode) insn); } // Get the unit associated with the current instruction Unit u = units.get(insn); if (u == null) { insn = insn.getNext(); continue; } emitUnits(u, body.getUnits()); // If this is an exception handler, register the starting unit for it { IdentityStmt caughtEx = null; if (u instanceof IdentityStmt) { caughtEx = (IdentityStmt) u; } else if (u instanceof UnitContainer) { caughtEx = getIdentityRefFromContrainer((UnitContainer) u); } if (insn instanceof LabelNode && caughtEx != null && caughtEx.getRightOp() instanceof CaughtExceptionRef) { // We directly place this label Collection<UnitBox> traps = trapHandlers.get((LabelNode) insn); for (UnitBox ub : traps) { ub.setUnit(caughtEx); } } } // Register this unit for all targets of the labels ending up at it while (!labls.isEmpty()) { LabelNode ln = labls.poll(); Collection<UnitBox> boxes = labels.get(ln); if (boxes != null) { for (UnitBox box : boxes) { box.setUnit(u instanceof UnitContainer ? ((UnitContainer) u).getFirstUnit() : u); } } } insn = insn.getNext(); } // Emit the inline exception handlers for (LabelNode ln : this.inlineExceptionHandlers.keySet()) { Unit handler = this.inlineExceptionHandlers.get(ln); emitUnits(handler, body.getUnits()); Collection<UnitBox> traps = trapHandlers.get(ln); for (UnitBox ub : traps) { ub.setUnit(handler); } // We need to jump to the original implementation Unit targetUnit = units.get(ln); GotoStmt gotoImpl = Jimple.v().newGotoStmt(targetUnit); body.getUnits().add(gotoImpl); } /* set remaining labels & boxes to last unit of chain */ if (labls.isEmpty()) { return; } Unit end = Jimple.v().newNopStmt(); body.getUnits().add(end); while (!labls.isEmpty()) { LabelNode ln = labls.poll(); Collection<UnitBox> boxes = labels.get(ln); if (boxes != null) { for (UnitBox box : boxes) { box.setUnit(end); } } } } private IdentityStmt getIdentityRefFromContrainer(UnitContainer u) { for (Unit uu : u.units) { if (uu instanceof IdentityStmt) { return (IdentityStmt) uu; } else if (uu instanceof UnitContainer) { return getIdentityRefFromContrainer((UnitContainer) uu); } } return null; } @Override public Body getBody(SootMethod m, String phaseName) { if (!m.isConcrete() || instructions == null || instructions.size() == 0) { return null; } final Jimple jimp = Jimple.v(); final JimpleBody jb = jimp.newBody(m); /* initialize */ int nrInsn = instructions.size(); nextLocal = maxLocals; locals = new LinkedHashMap<Integer, Local>(maxLocals + (maxLocals / 2)); labels = LinkedListMultimap.create(4); units = new LinkedHashMap<AbstractInsnNode, Unit>(nrInsn); frames = new LinkedHashMap<AbstractInsnNode, StackFrame>(nrInsn); trapHandlers = LinkedListMultimap.create(tryCatchBlocks.size()); body = jb; /* retrieve all trap handlers */ for (TryCatchBlockNode tc : tryCatchBlocks) { trapHandlers.put(tc.handler, jimp.newStmtBox(null)); } /* convert instructions */ try { convert(); } catch (Throwable t) { throw new RuntimeException("Failed to convert " + m, t); } /* build body (add units, locals, traps, etc.) */ emitLocals(); emitTraps(); emitUnits(); if (PhaseOptions.getBoolean(PhaseOptions.v().getPhaseOptions("jb"), "use-original-names")) { tryCorrectingLocalNames(jimp, jb); } /* clean up */ locals = null; labels = null; units = null; stack = null; frames = null; body = null; // Make sure to inline patterns of the form to enable proper variable // splitting and type assignment: // a = new A(); // goto l0; // l0: // b = (B) a; // return b; castAndReturnInliner.transform(jb); try { PackManager.v().getPack("jb").apply(jb); } catch (Throwable t) { throw new RuntimeException("Failed to apply jb to " + m, t); } return jb; } /** * When preserving original names, try to use the local variable table for guidance. The LocalVariableTable from the input * bytecode may contain two weird cases which can cause the loss of original local names, or worse, the appearance of the * '#' character in local names in the output LocalVariableTable (some JVM implementations will give an error when trying * to execute a method whose LocalVariableTable contains names with the '#' character). * <ol> * <li>When the LocalVariableTable associates different names with the same local variable index at different points in the * method body, the "locals" Map would end up preserving only one of those names as the designated local name for that * index. This leaves it up to the SharedInitializationLocalSplitter and LocalSplitter to then split that single Local back * into distinct Locals, but at that time, information about the other original name(s) has been ignored (and the * LocalVariableTable which contains that information is no longer available) so the best it can do is append "#x" (where x * is a unique integer) to the end of the current name. In the end, those locals may be combined back into a single Local * by the LocalPacker using whichever name was originally chosen by the "locals" Map here. In the worst case however, the * LocalPacker cannot combine them back into a single Local (see the "Icky fix" in LocalPacker) and ends up keeping the '#' * character in the Local name which leads to a problem if the "write-local-annotations" Soot option is also because the * names containing a '#' character will end up in the output bytecode.</li> * <li>When the LocalVariableTable associates different indices with the same name at the same code location, we end up * again with a case where the LocalPacker cannot remove the '#' character from local names.</li> * </ol> * * Thus, this method checks for these ambiguous cases while the LocalVariableTable is still available, and assigns a unique * name to each local that is based on the original name from the LocalVariableTable and does not use the '#' character. */ protected void tryCorrectingLocalNames(final Jimple jimp, final JimpleBody jb) { final Chain<Local> jbLocals = jb.getLocals(); final int sizeLVT = this.localVars.size(); if (sizeLVT > 0) { // Group LocalVariableNode by index to find any that are associated with // different names at different points in the method. For each such // occurrence, determine which name was chosen via "locals.get(i)" and, // in the range of Units specified for all other names, replace that // chosen Local with a new Local. Multimap<Integer, LocalVariableNode> groups = LinkedListMultimap.create(sizeLVT); for (LocalVariableNode lvn : this.localVars) { if (lvn.start != lvn.end) { // these are ignored by getLocal(int) groups.put(lvn.index, lvn); } } // NOTE: When creating new variables, group by both name and index because // the LocalVariableTable allows multiple local variable indices to // have the same name simultaneously but they must be distinguished here. final Chain<Unit> jbUnits = jb.getUnits(); Table<Integer, String, Local> newLocals = null; for (Map.Entry<Integer, Collection<LocalVariableNode>> e : groups.asMap().entrySet()) { Collection<LocalVariableNode> lvns = e.getValue(); if (lvns.size() > 1) { final Integer localNum = e.getKey(); final Local chosen = this.locals.get(localNum); final String chosenName = chosen.getName(); final Type chosenType = chosen.getType(); // Detect inconsistencies in the LocalVariableTable. // 1. If there exists any use of local variable 'chosen' outside of a // range defined by one of the LocalVariableNode in 'vals', then it is // not safe to make any replacements of 'chosen' because it is not // clear which actual variable should be used at a location outside of // the defined ranges (unless a use-def analysis is applied but that // is left for future implementation). // 2. If any of the LocalVariableNode in 'vals' cover any of the same // units, then they are ambiguous and cannot be used. // // To implement these checks, first collect all ValueBoxes in the body // that reference the chosen Local. Then, as each LocalVariableNode is // processed, map each ValueBox to the new Local that it should hold. // If any ValueBox is found more than once or not found at all, then // one of the inconsistency cases mentioned above exists and thus no // changes should be made. IdentityHashMap<ValueBox, Local> boxToNewLoc = new IdentityHashMap<>(); for (Unit u : jbUnits) { for (ValueBox box : u.getUseAndDefBoxes()) { Value val = box.getValue(); if (val == chosen) { Local old = boxToNewLoc.put(box, null); assert (old == null);// each box appears only once } } } boolean isConsistent = true; LV_LOOP: for (LocalVariableNode lvn : lvns) { final String name = lvn.name; if (!chosenName.equals(name)) { // Get the next real instruction after 'start' // NOTE: Although it seems obvious to use lvn.start.getNext() as // the initial instruction to check, the bytecode generated by // some compilers has the start PC one instruction late it seems. Unit uStart; for (AbstractInsnNode i = lvn.start.getPrevious(); (uStart = units.get(i)) == null;) { i = i.getNext(); } // Get the previous real instruction before 'end' Unit uEnd; for (AbstractInsnNode i = lvn.end.getPrevious(); (uEnd = units.get(i)) == null;) { i = i.getPrevious(); } if (newLocals == null) { newLocals = HashBasedTable.create(this.maxLocals, 1); } Local newLocal = newLocals.get(localNum, name); if (newLocal == null) { newLocal = jimp.newLocal(name, chosenType); Local old = newLocals.put(localNum, name, newLocal); assert (old == null); } for (Iterator<Unit> it = jbUnits.iterator(uStart, uEnd); it.hasNext();) { Unit u = it.next(); for (ValueBox box : u.getUseAndDefBoxes()) { Value val = box.getValue(); if (val == chosen) { assert (boxToNewLoc.containsKey(box));// it was found at the start Local conflict = boxToNewLoc.put(box, newLocal); if (conflict != null) { isConsistent = false; break LV_LOOP; } } } } } } // Finally, replace the locals only if both consistency conditions pass. HashSet<Local> newLocalSet = new HashSet<>(boxToNewLoc.values()); if (isConsistent && !newLocalSet.contains(null)) { jbLocals.addAll(newLocalSet); for (Map.Entry<ValueBox, Local> r : boxToNewLoc.entrySet()) { r.getKey().setValue(r.getValue()); } } } } } // In the end, ensure the names of locals (not just from those that were newly added) are unique. ensureUniqueNames(jbLocals); } /** * If any locals have the same name, append a unique id so that each is different. */ private void ensureUniqueNames(Chain<Local> jbLocals) { Multimap<String, Local> nameToLocal = LinkedListMultimap.create(jbLocals.size()); for (Local l : jbLocals) { nameToLocal.put(l.getName(), l); } for (Collection<Local> locs : nameToLocal.asMap().values()) { if (locs.size() > 1) { int num = 0; for (Local l : locs) { l.setName(l.getName() + '_' + (++num)); } } } } private final class Edge { /* edge endpoint */ final AbstractInsnNode insn; /* previous stacks at edge */ final Set<List<Operand>> prevStacks; private int lastLineNumber = -1; /* current stack at edge */ ArrayList<Operand> stack; Edge(AbstractInsnNode insn, ArrayList<Operand> stack) { this.insn = insn; this.prevStacks = new HashSet<List<Operand>>(); this.stack = stack; } Edge(AbstractInsnNode insn, int lastLineNumber) { this(insn, new ArrayList<Operand>(AsmMethodSource.this.stack)); this.lastLineNumber = lastLineNumber; } } }
85,558
33.780081
125
java
soot
soot-master/src/main/java/soot/asm/AsmModuleClassProvider.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.io.IOException; import java.io.InputStream; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ModuleVisitor; import org.objectweb.asm.Opcodes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import soot.ClassProvider; import soot.ClassSource; import soot.FoundFile; import soot.ModulePathSourceLocator; /** * Objectweb ASM class provider. * * @author Andreas Dann */ public class AsmModuleClassProvider implements ClassProvider { private static final Logger logger = LoggerFactory.getLogger(AsmModuleClassProvider.class); @Override public ClassSource find(String cls) { final int idx = cls.lastIndexOf(':') + 1; String clsFile = cls.substring(0, idx) + cls.substring(idx).replace('.', '/') + ".class"; FoundFile file = ModulePathSourceLocator.v().lookUpInModulePath(clsFile); return file == null ? null : new AsmClassSource(cls, file); } public String getModuleName(FoundFile file) { final String[] moduleName = { null }; ClassVisitor visitor = new ClassVisitor(Opcodes.ASM8) { @Override public ModuleVisitor visitModule(String name, int access, String version) { moduleName[0] = name; return null; } }; try (InputStream d = file.inputStream()) { new ClassReader(d).accept(visitor, ClassReader.SKIP_FRAMES); return moduleName[0]; } catch (IOException e) { logger.debug(e.getMessage(), e); } finally { file.close(); } return null; } }
2,371
29.410256
93
java
soot
soot-master/src/main/java/soot/asm/AsmUtil.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import com.google.common.base.Optional; import java.util.ArrayList; import java.util.List; import org.objectweb.asm.Opcodes; import soot.ArrayType; import soot.BooleanType; import soot.ByteType; import soot.CharType; import soot.DoubleType; import soot.FloatType; import soot.IntType; import soot.LongType; import soot.ModuleRefType; import soot.ModuleUtil; import soot.RefLikeType; import soot.RefType; import soot.ShortType; import soot.SootClass; import soot.Type; import soot.Unit; import soot.VoidType; import soot.jimple.AssignStmt; import soot.options.Options; /** * Contains static utility methods. * * @author Aaloan Miftah */ /** @author eric */ public class AsmUtil { private static RefType makeRefType(String className, Optional<String> moduleName) { if (ModuleUtil.module_mode()) { return ModuleRefType.v(className, moduleName); } return RefType.v(className); } /** * Determines if a type is a dword type. * * @param type * the type to check. * @return {@code true} if its a dword type. */ public static boolean isDWord(Type type) { return type instanceof LongType || type instanceof DoubleType; } /** * Converts an internal class name to a Type. * * @param internal * internal name. * @return type */ public static Type toBaseType(String internal, Optional<String> moduleName) { if (internal.charAt(0) == '[') { /* [Ljava/lang/Object; */ internal = internal.substring(internal.lastIndexOf('[') + 1); /* Ljava/lang/Object */ } if (internal.charAt(internal.length() - 1) == ';') { internal = internal.substring(0, internal.length() - 1); // we need to have this guarded by a ; check as you can have a situation // were a call is called Lxxxxx with now leading package name. Rare, but it // happens. However, you need to strip the leading L it will always be // followed by a ; per // http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html if (internal.charAt(0) == 'L') { internal = internal.substring(1); } internal = toQualifiedName(internal); return makeRefType(internal, moduleName); } switch (internal.charAt(0)) { case 'Z': return BooleanType.v(); case 'B': return ByteType.v(); case 'C': return CharType.v(); case 'S': return ShortType.v(); case 'I': return IntType.v(); case 'F': return FloatType.v(); case 'J': return LongType.v(); case 'D': return DoubleType.v(); default: internal = toQualifiedName(internal); return makeRefType(internal, moduleName); } } /** * Converts an internal class name to a fully qualified name. * * @param internal * internal name. * @return fully qualified name. */ public static String toQualifiedName(String internal) { return internal.replace('/', '.'); } /** * Converts a fully qualified class name to an internal name. * * @param qual * fully qualified class name. * @return internal name. */ public static String toInternalName(String qual) { return qual.replace('.', '/'); } /** * Determines and returns the internal name of a class. * * @param cls * the class. * @return corresponding internal name. */ public static String toInternalName(SootClass cls) { return toInternalName(cls.getName()); } /** * Converts a type descriptor to a Jimple reference type. * * @param desc * the descriptor. * @return the reference type. */ public static Type toJimpleRefType(String desc, Optional<String> moduleName) { return desc.charAt(0) == '[' ? toJimpleType(desc, moduleName) : makeRefType(toQualifiedName(desc), moduleName); } /** * Converts a type descriptor to a Jimple type. * * @param desc * the descriptor. * @return equivalent Jimple type. */ public static Type toJimpleType(String desc, Optional<String> moduleName) { int idx = desc.lastIndexOf('['); int nrDims = idx + 1; if (nrDims > 0) { if (desc.charAt(0) != '[') { throw new AssertionError("Invalid array descriptor: " + desc); } desc = desc.substring(idx + 1); } Type baseType; switch (desc.charAt(0)) { case 'Z': baseType = BooleanType.v(); break; case 'B': baseType = ByteType.v(); break; case 'C': baseType = CharType.v(); break; case 'S': baseType = ShortType.v(); break; case 'I': baseType = IntType.v(); break; case 'F': baseType = FloatType.v(); break; case 'J': baseType = LongType.v(); break; case 'D': baseType = DoubleType.v(); break; case 'L': if (desc.charAt(desc.length() - 1) != ';') { throw new AssertionError("Invalid reference descriptor: " + desc); } String name = desc.substring(1, desc.length() - 1); name = toQualifiedName(name); baseType = makeRefType(name, moduleName); break; default: throw new AssertionError("Unknown descriptor: " + desc); } if (!(baseType instanceof RefLikeType) && desc.length() > 1) { throw new AssertionError("Invalid primitive type descriptor: " + desc); } return nrDims > 0 ? ArrayType.v(baseType, nrDims) : baseType; } /** * Converts a method signature to a list of types, with the last entry in the returned list denoting the return type. * * @param desc * method signature. * @return list of types. */ public static List<Type> toJimpleDesc(String desc, Optional<String> moduleName) { ArrayList<Type> types = new ArrayList<Type>(2); int len = desc.length(); int idx = 0; all: while (idx != len) { int nrDims = 0; Type baseType = null; this_type: while (idx != len) { char c = desc.charAt(idx++); switch (c) { case '(': case ')': continue all; case '[': ++nrDims; continue this_type; case 'Z': baseType = BooleanType.v(); break this_type; case 'B': baseType = ByteType.v(); break this_type; case 'C': baseType = CharType.v(); break this_type; case 'S': baseType = ShortType.v(); break this_type; case 'I': baseType = IntType.v(); break this_type; case 'F': baseType = FloatType.v(); break this_type; case 'J': baseType = LongType.v(); break this_type; case 'D': baseType = DoubleType.v(); break this_type; case 'V': baseType = VoidType.v(); break this_type; case 'L': int begin = idx; while (desc.charAt(++idx) != ';') { } String cls = desc.substring(begin, idx++); baseType = makeRefType(toQualifiedName(cls), moduleName); break this_type; default: throw new AssertionError("Unknown type: " + c); } } if (baseType != null && nrDims > 0) { types.add(ArrayType.v(baseType, nrDims)); } else { types.add(baseType); } } return types; } /** strips suffix for indicating an array type */ public static String baseTypeName(String s) { int index = s.indexOf("["); if (index < 0) { return s; } else { return s.substring(0, index); } } private AsmUtil() { } public static int byteCodeToJavaVersion(int bytecodeVersion) { int javaVersion; switch (bytecodeVersion) { case (Opcodes.V1_5): javaVersion = Options.java_version_5; break; case (Opcodes.V1_6): javaVersion = Options.java_version_6; break; case (Opcodes.V1_7): javaVersion = Options.java_version_7; break; case (Opcodes.V1_8): javaVersion = Options.java_version_8; break; case (Opcodes.V9): javaVersion = Options.java_version_9; break; case (Opcodes.V10): javaVersion = Options.java_version_10; break; case (Opcodes.V11): javaVersion = Options.java_version_11; break; case (Opcodes.V12): javaVersion = Options.java_version_12; break; default: // we return 0 if we cannot determine the version to indicate that javaVersion = Options.java_version_default; } return javaVersion; } public static int javaToBytecodeVersion(int javaVersion) { int bytecodeVersion; switch (javaVersion) { case (Options.java_version_1): bytecodeVersion = Opcodes.V1_1; break; case (Options.java_version_2): bytecodeVersion = Opcodes.V1_2; break; case (Options.java_version_3): bytecodeVersion = Opcodes.V1_3; break; case (Options.java_version_4): bytecodeVersion = Opcodes.V1_4; break; case (Options.java_version_5): bytecodeVersion = Opcodes.V1_5; break; case (Options.java_version_6): bytecodeVersion = Opcodes.V1_6; break; case (Options.java_version_7): bytecodeVersion = Opcodes.V1_7; break; case (Options.java_version_8): bytecodeVersion = Opcodes.V1_8; break; case (Options.java_version_9): bytecodeVersion = Opcodes.V9; break; case (Options.java_version_10): bytecodeVersion = Opcodes.V10; break; case (Options.java_version_11): bytecodeVersion = Opcodes.V11; break; case (Options.java_version_12): bytecodeVersion = Opcodes.V12; break; default: bytecodeVersion = Opcodes.V1_7; } return bytecodeVersion; } static boolean alreadyExists(Unit prev, Object left, Object right) { if (prev instanceof AssignStmt) { AssignStmt prevAsign = (AssignStmt) prev; if (prevAsign.getLeftOp().equivTo(left) && prevAsign.getRightOp().equivTo(right)) { return true; } } return false; } }
11,284
26.727273
119
java
soot
soot-master/src/main/java/soot/asm/CastAndReturnInliner.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.Iterator; import java.util.List; import java.util.Map; import soot.Body; import soot.BodyTransformer; import soot.Local; import soot.Trap; import soot.Unit; import soot.UnitBox; import soot.UnitPatchingChain; import soot.jimple.AssignStmt; import soot.jimple.CastExpr; import soot.jimple.GotoStmt; import soot.jimple.Jimple; import soot.jimple.ReturnStmt; /** * Transformers that inlines returns that cast and return an object. We take a = .. goto l0; * * l0: b = (B) a; return b; * * and transform it into a = .. return a; * * This makes it easier for the local splitter to split distinct uses of the same variable. Imagine that "a" can come from * different parts of the code and have different types. To be able to find a valid typing at all, we must break apart the * uses of "a". * * @author Steven Arzt */ public class CastAndReturnInliner extends BodyTransformer { @Override protected void internalTransform(Body body, String phaseName, Map<String, String> options) { 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); } } } } } } } }
3,673
33.660377
122
java
soot
soot-master/src/main/java/soot/asm/FieldBuilder.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Attribute; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Opcodes; import soot.SootField; /** * Soot field builder. * * @author Aaloan Miftah */ final 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() { TagBuilder t = tb; if (t == null) { t = tb = new TagBuilder(field, scb); } return t; } @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { return getTagBuilder().visitAnnotation(desc, visible); } @Override public void visitAttribute(Attribute attr) { getTagBuilder().visitAttribute(attr); } }
1,758
26.061538
74
java
soot
soot-master/src/main/java/soot/asm/MethodBuilder.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import com.google.common.base.Optional; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Attribute; import org.objectweb.asm.Handle; import org.objectweb.asm.Label; import org.objectweb.asm.Opcodes; import org.objectweb.asm.TypePath; import org.objectweb.asm.commons.JSRInlinerAdapter; import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.LocalVariableNode; import org.objectweb.asm.tree.TryCatchBlockNode; import soot.ArrayType; import soot.MethodSource; import soot.RefType; import soot.SootMethod; import soot.Type; import soot.tagkit.AnnotationConstants; import soot.tagkit.AnnotationDefaultTag; import soot.tagkit.AnnotationTag; import soot.tagkit.ParamNamesTag; import soot.tagkit.VisibilityAnnotationTag; import soot.tagkit.VisibilityLocalVariableAnnotationTag; import soot.tagkit.VisibilityParameterAnnotationTag; /** * Soot method builder. * * @author Aaloan Miftah */ public class MethodBuilder extends JSRInlinerAdapter { private TagBuilder tb; private VisibilityAnnotationTag[] visibleParamAnnotations; private VisibilityAnnotationTag[] invisibleParamAnnotations; private List<VisibilityAnnotationTag> visibleLocalVarAnnotations; private List<VisibilityAnnotationTag> invisibleLocalVarAnnotations; private final SootMethod method; private final SootClassBuilder scb; private final String[] parameterNames; private final Map<Integer, Integer> slotToParameter; public MethodBuilder(SootMethod method, SootClassBuilder scb, String desc, String[] ex) { super(Opcodes.ASM6, null, method.getModifiers(), method.getName(), desc, null, ex); this.method = method; this.scb = scb; this.parameterNames = new String[method.getParameterCount()]; this.slotToParameter = createSlotToParameterMap(); } private Map<Integer, Integer> createSlotToParameterMap() { final int paramCount = method.getParameterCount(); Map<Integer, Integer> slotMap = new HashMap<>(paramCount); int curSlot = method.isStatic() ? 0 : 1; for (int i = 0; i < paramCount; i++) { slotMap.put(curSlot, i); curSlot++; if (AsmUtil.isDWord(method.getParameterType(i))) { curSlot++; } } return slotMap; } private TagBuilder getTagBuilder() { TagBuilder t = tb; if (t == null) { t = tb = new TagBuilder(method, scb); } return t; } @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { return getTagBuilder().visitAnnotation(desc, visible); } @Override public AnnotationVisitor visitAnnotationDefault() { return new AnnotationElemBuilder(1) { @Override public void visitEnd() { method.addTag(new AnnotationDefaultTag(elems.get(0))); } }; } @Override public void visitAttribute(Attribute attr) { getTagBuilder().visitAttribute(attr); } @Override public void visitLocalVariable(String name, String descriptor, String signature, Label start, Label end, int index) { super.visitLocalVariable(name, descriptor, signature, start, end, index); if (name != null && !name.isEmpty() && index > 0) { Integer paramIdx = slotToParameter.get(index); if (paramIdx != null) { parameterNames[paramIdx] = name; } } } @Override public AnnotationVisitor visitLocalVariableAnnotation(final int typeRef, final TypePath typePath, final Label[] start, final Label[] end, final int[] index, final String descriptor, final boolean visible) { final VisibilityAnnotationTag vat = new VisibilityAnnotationTag(visible ? AnnotationConstants.RUNTIME_VISIBLE : AnnotationConstants.RUNTIME_INVISIBLE); if (visible) { if (visibleLocalVarAnnotations == null) { visibleLocalVarAnnotations = new ArrayList<VisibilityAnnotationTag>(2); } visibleLocalVarAnnotations.add(vat); } else { if (invisibleLocalVarAnnotations == null) { invisibleLocalVarAnnotations = new ArrayList<VisibilityAnnotationTag>(2); } invisibleLocalVarAnnotations.add(vat); } return new AnnotationElemBuilder() { @Override public void visitEnd() { AnnotationTag annotTag = new AnnotationTag(desc, elems); vat.addAnnotation(annotTag); } }; } @Override public AnnotationVisitor visitParameterAnnotation(int parameter, final String desc, boolean visible) { VisibilityAnnotationTag vat; VisibilityAnnotationTag[] vats; if (visible) { vats = visibleParamAnnotations; if (vats == null) { vats = new VisibilityAnnotationTag[method.getParameterCount()]; visibleParamAnnotations = vats; } vat = vats[parameter]; if (vat == null) { vat = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_VISIBLE); vats[parameter] = vat; } } else { vats = invisibleParamAnnotations; if (vats == null) { vats = new VisibilityAnnotationTag[method.getParameterCount()]; invisibleParamAnnotations = vats; } vat = vats[parameter]; if (vat == null) { vat = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_INVISIBLE); vats[parameter] = vat; } } final VisibilityAnnotationTag _vat = vat; return new AnnotationElemBuilder() { @Override public void visitEnd() { AnnotationTag annotTag = new AnnotationTag(desc, elems); _vat.addAnnotation(annotTag); } }; } @Override public void visitTypeInsn(int op, String t) { super.visitTypeInsn(op, t); Type rt = AsmUtil.toJimpleRefType(t, Optional.fromNullable(this.scb.getKlass().moduleName)); if (rt instanceof ArrayType) { scb.addDep(((ArrayType) rt).baseType); } else { scb.addDep(rt); } } @Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { super.visitFieldInsn(opcode, owner, name, desc); for (Type t : AsmUtil.toJimpleDesc(desc, Optional.fromNullable(this.scb.getKlass().moduleName))) { if (t instanceof RefType) { scb.addDep(t); } } scb.addDep(AsmUtil.toQualifiedName(owner)); } @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean isInterf) { super.visitMethodInsn(opcode, owner, name, desc, isInterf); for (Type t : AsmUtil.toJimpleDesc(desc, Optional.fromNullable(this.scb.getKlass().moduleName))) { addDeps(t); } scb.addDep(AsmUtil.toJimpleRefType(owner, Optional.fromNullable(this.scb.getKlass().moduleName))); } @Override public void visitLdcInsn(Object cst) { super.visitLdcInsn(cst); if (cst instanceof Handle) { Handle methodHandle = (Handle) cst; scb.addDep(AsmUtil.toBaseType(methodHandle.getOwner(), Optional.fromNullable(this.scb.getKlass().moduleName))); } } private void addDeps(Type t) { if (t instanceof RefType) { scb.addDep(t); } else if (t instanceof ArrayType) { ArrayType at = (ArrayType) t; addDeps(at.getElementType()); } } @Override public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { super.visitTryCatchBlock(start, end, handler, type); if (type != null) { scb.addDep(AsmUtil.toQualifiedName(type)); } } @Override public void visitEnd() { super.visitEnd(); if (visibleParamAnnotations != null) { VisibilityParameterAnnotationTag tag = new VisibilityParameterAnnotationTag(visibleParamAnnotations.length, AnnotationConstants.RUNTIME_VISIBLE); for (VisibilityAnnotationTag vat : visibleParamAnnotations) { tag.addVisibilityAnnotation(vat); } method.addTag(tag); } if (invisibleParamAnnotations != null) { VisibilityParameterAnnotationTag tag = new VisibilityParameterAnnotationTag(invisibleParamAnnotations.length, AnnotationConstants.RUNTIME_INVISIBLE); for (VisibilityAnnotationTag vat : invisibleParamAnnotations) { tag.addVisibilityAnnotation(vat); } method.addTag(tag); } if (visibleLocalVarAnnotations != null) { VisibilityLocalVariableAnnotationTag tag = new VisibilityLocalVariableAnnotationTag(visibleLocalVarAnnotations.size(), AnnotationConstants.RUNTIME_VISIBLE); for (VisibilityAnnotationTag vat : visibleLocalVarAnnotations) { tag.addVisibilityAnnotation(vat); } method.addTag(tag); } if (invisibleLocalVarAnnotations != null) { VisibilityLocalVariableAnnotationTag tag = new VisibilityLocalVariableAnnotationTag( invisibleLocalVarAnnotations.size(), AnnotationConstants.RUNTIME_INVISIBLE); for (VisibilityAnnotationTag vat : invisibleLocalVarAnnotations) { tag.addVisibilityAnnotation(vat); } method.addTag(tag); } if (!isFullyEmpty(parameterNames)) { method.addTag(new ParamNamesTag(parameterNames)); } if (method.isConcrete()) { method.setSource( createAsmMethodSource(maxLocals, instructions, localVariables, tryCatchBlocks, scb.getKlass().moduleName)); } } protected MethodSource createAsmMethodSource(int maxLocals, InsnList instructions, List<LocalVariableNode> localVariables, List<TryCatchBlockNode> tryCatchBlocks, String moduleName) { return new AsmMethodSource(maxLocals, instructions, localVariables, tryCatchBlocks, moduleName); } /** * Gets whether the given array is fully empty, i.e., contains only <code>null</code> values * * @param array * The array to check * @return True if the given arry contains only <code>null</code> values, false otherwise */ private boolean isFullyEmpty(String[] array) { for (int i = 0; i < array.length; i++) { if (array[i] != null && !array[i].isEmpty()) { return false; } } return true; } @Override public String toString() { return method.toString(); } }
10,911
32.268293
125
java
soot
soot-master/src/main/java/soot/asm/Operand.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.ArrayList; import java.util.List; import org.objectweb.asm.tree.AbstractInsnNode; import soot.Local; import soot.Value; import soot.ValueBox; /** * Stack operand. * * @author Aaloan Miftah */ final class Operand { final AbstractInsnNode insn; final Value value; Local stack; private Object boxes; /** * Constructs a new stack operand. * * @param insn * the instruction that produced this operand. * @param value * the generated value. */ Operand(AbstractInsnNode insn, Value value) { this.insn = insn; this.value = value; } /** * Removes a value box from this operand. * * @param vb * the value box. */ @SuppressWarnings("unchecked") void removeBox(ValueBox vb) { if (vb == null) { return; } if (boxes == vb) { boxes = null; } else if (boxes instanceof List) { List<ValueBox> list = (List<ValueBox>) boxes; list.remove(vb); } } /** * Adds a value box to this operand. * * @param vb * the value box. */ @SuppressWarnings("unchecked") void addBox(ValueBox vb) { if (boxes instanceof List) { List<ValueBox> list = (List<ValueBox>) boxes; list.add(vb); } else if (boxes instanceof ValueBox) { ValueBox ovb = (ValueBox) boxes; List<ValueBox> list = new ArrayList<ValueBox>(); list.add(ovb); list.add(vb); boxes = list; } else { boxes = vb; } } /** * Updates all value boxes registered to this operand. */ @SuppressWarnings("unchecked") void updateBoxes() { Value val = stackOrValue(); if (boxes instanceof List) { for (ValueBox vb : (List<ValueBox>) boxes) { vb.setValue(val); } } else if (boxes instanceof ValueBox) { ((ValueBox) boxes).setValue(val); } } /** * @param <A> * type of value to cast to. * @return the value. */ @SuppressWarnings("unchecked") <A> A value() { return (A) value; } /** * @return either the stack local allocated for this operand, or its value. */ Value stackOrValue() { Local s = stack; return s == null ? value : s; } /** * Determines if this operand is equal to another operand. * * @param other * the other operand. * @return {@code true} if this operand is equal to another operand, {@code false} otherwise. */ boolean equivTo(Operand other) { if (other.value == null && value == null) { return true; } return stackOrValue().equivTo(other.stackOrValue()); } @Override public boolean equals(Object other) { return other instanceof Operand && equivTo((Operand) other); } @Override public String toString() { StringBuilder sb = new StringBuilder(); boolean hasStack = false; if (stack != null) { sb.append(stack.toString()); hasStack = true; } if (value != null) { if (hasStack) { sb.append(" - "); sb.append(value.toString()); } } return sb.toString(); } }
3,935
22.289941
95
java
soot
soot-master/src/main/java/soot/asm/SootClassBuilder.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import com.google.common.base.Optional; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Attribute; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.ModuleVisitor; import org.objectweb.asm.Opcodes; import soot.Modifier; import soot.ModuleRefType; import soot.ModuleUtil; import soot.RefType; import soot.Scene; import soot.SootClass; import soot.SootField; import soot.SootMethod; import soot.SootModuleInfo; import soot.SootModuleResolver; import soot.SootResolver; import soot.Type; import soot.options.Options; import soot.tagkit.DoubleConstantValueTag; import soot.tagkit.EnclosingMethodTag; import soot.tagkit.FloatConstantValueTag; import soot.tagkit.InnerClassTag; import soot.tagkit.IntegerConstantValueTag; import soot.tagkit.LongConstantValueTag; import soot.tagkit.SignatureTag; import soot.tagkit.SourceFileTag; import soot.tagkit.StringConstantValueTag; import soot.tagkit.Tag; /** * Constructs a Soot class from a visited class. * * @author Aaloan Miftah */ public class SootClassBuilder extends ClassVisitor { protected final SootClass klass; protected final Set<Type> deps; protected TagBuilder tb; /** * Constructs a new builder for the given {@link SootClass}. * * @param klass * Soot class to build. */ protected SootClassBuilder(SootClass klass) { super(Opcodes.ASM9); this.klass = klass; this.deps = new HashSet<>(); } private TagBuilder getTagBuilder() { TagBuilder t = tb; if (t == null) { t = tb = new TagBuilder(klass, this); } return t; } protected SootClass getKlass() { return klass; } protected void addDep(String s) { addDep(makeRefType(AsmUtil.baseTypeName(s))); } /** * Adds a dependency of the target class. * * @param s * name, or type of class. */ protected void addDep(Type s) { deps.add(s); } @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { setJavaVersion(version); /* * check if class is a module-info, if not add the module information to it */ if (access != Opcodes.ACC_MODULE) { // if we are in module mode if (ModuleUtil.module_mode()) { SootModuleInfo moduleInfo = (SootModuleInfo) SootModuleResolver.v().makeClassRef(SootModuleInfo.MODULE_INFO, Optional.fromNullable(this.klass.moduleName)); klass.setModuleInformation(moduleInfo); } } name = AsmUtil.toQualifiedName(name); if (!name.equals(klass.getName()) && Options.v().verbose()) { System.err.println("Class names not equal! " + name + " != " + klass.getName()); } // FIXME: ad -- throw excpetion again // throw new RuntimeException("Class names not equal! "+name+" != "+klass.getName()); klass.setModifiers(filterASMFlags(access) & ~Opcodes.ACC_SUPER); if (superName != null) { superName = AsmUtil.toQualifiedName(superName); addDep(makeRefType(superName)); SootClass superClass = makeClassRef(superName); klass.setSuperclass(superClass); } for (String intrf : interfaces) { intrf = AsmUtil.toQualifiedName(intrf); addDep(makeRefType(intrf)); SootClass interfaceClass = makeClassRef(intrf); interfaceClass.setModifiers(interfaceClass.getModifiers() | Modifier.INTERFACE); klass.addInterface(interfaceClass); } if (signature != null) { klass.addTag(new SignatureTag(signature)); } } private void setJavaVersion(int version) { final Options opts = Options.v(); if (opts.derive_java_version()) { opts.set_java_version(Math.max(opts.java_version(), AsmUtil.byteCodeToJavaVersion(version))); } } @Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { Type type = AsmUtil.toJimpleType(desc, Optional.fromNullable(this.klass.moduleName)); addDep(type); SootField field = Scene.v().makeSootField(name, type, filterASMFlags(access)); Tag tag; if (value instanceof Integer) { tag = new IntegerConstantValueTag((Integer) value); } else if (value instanceof Float) { tag = new FloatConstantValueTag((Float) value); } else if (value instanceof Long) { tag = new LongConstantValueTag((Long) value); } else if (value instanceof Double) { tag = new DoubleConstantValueTag((Double) value); } else if (value instanceof String) { tag = new StringConstantValueTag(value.toString()); } else { tag = null; } if (tag != null) { field.addTag(tag); } if (signature != null) { field.addTag(new SignatureTag(signature)); } return new FieldBuilder(klass.getOrAddField(field), this); } public static int filterASMFlags(int access) { return access & ~Opcodes.ACC_DEPRECATED & ~Opcodes.ACC_RECORD; } @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { List<SootClass> thrownExceptions; if (exceptions == null || exceptions.length == 0) { thrownExceptions = Collections.emptyList(); } else { int len = exceptions.length; thrownExceptions = new ArrayList<>(len); for (int i = 0; i != len; i++) { String ex = AsmUtil.toQualifiedName(exceptions[i]); addDep(makeRefType(ex)); thrownExceptions.add(makeClassRef(ex)); } } List<Type> sigTypes = AsmUtil.toJimpleDesc(desc, Optional.fromNullable(this.klass.moduleName)); for (Type type : sigTypes) { addDep(type); } SootMethod method = Scene.v().makeSootMethod(name, sigTypes, sigTypes.remove(sigTypes.size() - 1), filterASMFlags(access), thrownExceptions); if (signature != null) { method.addTag(new SignatureTag(signature)); } return createMethodBuilder(klass.getOrAddMethod(method), desc, exceptions); } protected MethodVisitor createMethodBuilder(SootMethod sootMethod, String desc, String[] exceptions) { return new MethodBuilder(sootMethod, this, desc, exceptions); } @Override public void visitSource(String source, String debug) { if (source != null) { klass.addTag(new SourceFileTag(source)); } } @Override public void visitInnerClass(String name, String outerName, String innerName, int access) { klass.addTag(new InnerClassTag(name, outerName, innerName, access)); // soot does not resolve all inner classes, e.g., java.util.stream.FindOps$FindSink$... is not // resolved if (!(this.klass instanceof SootModuleInfo)) { deps.add(makeRefType(AsmUtil.toQualifiedName(name))); } } @Override public void visitOuterClass(String owner, String name, String desc) { if (name != null) { klass.addTag(new EnclosingMethodTag(owner, name, desc)); } owner = AsmUtil.toQualifiedName(owner); deps.add(makeRefType(owner)); klass.setOuterClass(makeClassRef(owner)); } @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { return getTagBuilder().visitAnnotation(desc, visible); } @Override public void visitAttribute(Attribute attr) { getTagBuilder().visitAttribute(attr); } @Override public ModuleVisitor visitModule(String name, int access, String version) { return new SootModuleInfoBuilder(name, (SootModuleInfo) this.klass, this); } private SootClass makeClassRef(String className) { if (ModuleUtil.module_mode()) { return SootModuleResolver.v().makeClassRef(className, Optional.fromNullable(this.klass.moduleName)); } else { return SootResolver.v().makeClassRef(className); } } private RefType makeRefType(String className) { if (ModuleUtil.module_mode()) { return ModuleRefType.v(className, Optional.fromNullable(this.klass.moduleName)); } else { return RefType.v(className); } } }
8,998
30.798587
116
java
soot
soot-master/src/main/java/soot/asm/SootModuleInfoBuilder.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import com.google.common.base.Optional; import org.objectweb.asm.ModuleVisitor; import org.objectweb.asm.Opcodes; import soot.RefType; import soot.SootClass; import soot.SootModuleInfo; import soot.SootModuleResolver; /** * Builds Soot's representation for a module-info class. * * @author Andreas Dann */ public class SootModuleInfoBuilder extends ModuleVisitor { private final SootClassBuilder scb; private final SootModuleInfo klass; private final String name; public SootModuleInfoBuilder(String name, SootModuleInfo klass, SootClassBuilder scb) { super(Opcodes.ASM8); this.klass = klass; this.name = name; this.scb = scb; } @Override public void visitRequire(String module, int access, String version) { SootClass moduleInfo = SootModuleResolver.v().makeClassRef(SootModuleInfo.MODULE_INFO, Optional.of(module)); klass.getRequiredModules().put((SootModuleInfo) moduleInfo, access); scb.addDep(RefType.v(moduleInfo)); } @Override public void visitExport(String packaze, int access, String... modules) { if (packaze != null) { klass.addExportedPackage(packaze, modules); } } @Override public void visitOpen(String packaze, int access, String... modules) { if (packaze != null) { klass.addOpenedPackage(packaze, modules); } } }
2,162
28.22973
112
java
soot
soot-master/src/main/java/soot/asm/StackFrame.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.ArrayList; import soot.Local; import soot.Unit; import soot.ValueBox; import soot.jimple.AssignStmt; import soot.jimple.DefinitionStmt; import soot.jimple.Jimple; /** * Frame of stack for an instruction. * * @author Aaloan Miftah */ final class StackFrame { private Operand[] out; private Local[] inStackLocals; private ValueBox[] boxes; private ArrayList<Operand[]> in; private final AsmMethodSource src; /** * Constructs a new stack frame. * * @param src * source the frame belongs to. */ StackFrame(AsmMethodSource src) { this.src = src; } /** * @return operands produced by this frame. */ Operand[] out() { return out; } /** * Sets the operands used by this frame. * * @param oprs * the operands. */ void in(Operand... oprs) { ArrayList<Operand[]> in = this.in; if (in == null) { in = this.in = new ArrayList<Operand[]>(1); } else { in.clear(); } in.add(oprs); inStackLocals = new Local[oprs.length]; } /** * Sets the value boxes corresponding to the operands used by this frame. * * @param boxes * the boxes. */ void boxes(ValueBox... boxes) { this.boxes = boxes; } /** * Sets the operands produced by this frame. * * @param oprs * the operands. */ void out(Operand... oprs) { out = oprs; } /** * Merges the specified operands with the operands used by this frame. * * @param oprs * the new operands. * @throws IllegalArgumentException * if the number of new operands is not equal to the number of old operands. */ void mergeIn(Operand... oprs) { ArrayList<Operand[]> in = this.in; if (in.get(0).length != oprs.length) { throw new IllegalArgumentException("Invalid in operands length!"); } int nrIn = in.size(); boolean diff = false; for (int i = 0; i != oprs.length; i++) { Operand newOp = oprs[i]; diff = true; /* merge, since prevOp != newOp */ Local stack = inStackLocals[i]; if (stack != null) { if (newOp.stack == null) { newOp.stack = stack; AssignStmt as = Jimple.v().newAssignStmt(stack, newOp.value); src.setUnit(newOp.insn, as); newOp.updateBoxes(); } else { Unit prev = src.getUnit(newOp.insn); boolean merge = true; if (prev instanceof UnitContainer) { for (Unit t : ((UnitContainer) prev).units) { if (AsmUtil.alreadyExists(t, stack, newOp.stackOrValue())) { merge = false; break; } } } else if (AsmUtil.alreadyExists(prev, stack, newOp.stackOrValue())) { merge = false; } if (merge) { AssignStmt as = Jimple.v().newAssignStmt(stack, newOp.stackOrValue()); src.mergeUnits(newOp.insn, as); newOp.addBox(as.getRightOpBox()); } } } else { for (int j = 0; j != nrIn; j++) { stack = in.get(j)[i].stack; if (stack != null) { break; } } if (stack == null) { stack = newOp.stack; if (stack == null) { stack = src.newStackLocal(); } } /* add assign statement for prevOp */ ValueBox box = boxes == null ? null : boxes[i]; for (int j = 0; j != nrIn; j++) { Operand prevOp = in.get(j)[i]; if (prevOp.stack == stack) { continue; } prevOp.removeBox(box); if (prevOp.stack == null) { prevOp.stack = stack; AssignStmt as = Jimple.v().newAssignStmt(stack, prevOp.value); src.setUnit(prevOp.insn, as); } else { Unit u = src.getUnit(prevOp.insn); DefinitionStmt as = (DefinitionStmt) (u instanceof UnitContainer ? ((UnitContainer) u).getFirstUnit() : u); ValueBox lvb = as.getLeftOpBox(); assert lvb.getValue() == prevOp.stack : "Invalid stack local!"; lvb.setValue(stack); prevOp.stack = stack; } prevOp.updateBoxes(); } if (newOp.stack != stack) { if (newOp.stack == null) { newOp.stack = stack; AssignStmt as = Jimple.v().newAssignStmt(stack, newOp.value); src.setUnit(newOp.insn, as); } else { Unit u = src.getUnit(newOp.insn); DefinitionStmt as = (DefinitionStmt) (u instanceof UnitContainer ? ((UnitContainer) u).getFirstUnit() : u); ValueBox lvb = as.getLeftOpBox(); assert lvb.getValue() == newOp.stack : "Invalid stack local!"; lvb.setValue(stack); newOp.stack = stack; } newOp.updateBoxes(); } if (box != null) { box.setValue(stack); } inStackLocals[i] = stack; } /* * this version uses allocates local if it finds both operands have stack locals allocated already */ /* * if (stack == null) { if (in.size() != 1) throw new AssertionError("Local h " + in.size()); stack = * src.newStackLocal(); inStackLocals[i] = stack; ValueBox box = boxes == null ? null : boxes[i]; /* add assign * statement for prevOp * for (int j = 0; j != nrIn; j++) { Operand prevOp = in.get(j)[i]; prevOp.removeBox(box); if * (prevOp.stack == null) { prevOp.stack = stack; as = Jimple.v().newAssignStmt(stack, prevOp.value); * src.setUnit(prevOp.insn, as); prevOp.updateBoxes(); } else { as = Jimple.v().newAssignStmt(stack, * prevOp.stackOrValue()); src.mergeUnits(prevOp.insn, as); } prevOp.addBox(as.getRightOpBox()); } if (box != null) * box.setValue(stack); } if (newOp.stack == null) { newOp.stack = stack; as = Jimple.v().newAssignStmt(stack, * newOp.value); src.setUnit(newOp.insn, as); newOp.updateBoxes(); } else { as = Jimple.v().newAssignStmt(stack, * newOp.stackOrValue()); src.mergeUnits(newOp.insn, as); } newOp.addBox(as.getRightOpBox()); */ } if (diff) { in.add(oprs); } } }
7,085
30.633929
122
java
soot
soot-master/src/main/java/soot/asm/TagBuilder.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.lang.reflect.Field; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Attribute; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import soot.tagkit.AnnotationConstants; import soot.tagkit.AnnotationTag; import soot.tagkit.GenericAttribute; import soot.tagkit.Host; import soot.tagkit.VisibilityAnnotationTag; /** * Tag builder. * * @author Aaloan Miftah */ final class TagBuilder { private VisibilityAnnotationTag invisibleTag, visibleTag; private final Host host; private final SootClassBuilder scb; TagBuilder(Host host, SootClassBuilder scb) { this.host = host; this.scb = scb; } /** * @see FieldVisitor#visitAnnotation(String, boolean) * @see MethodVisitor#visitAnnotation(String, boolean) * @see ClassVisitor#visitAnnotation(String, boolean) */ public AnnotationVisitor visitAnnotation(final String desc, boolean visible) { VisibilityAnnotationTag tag; if (visible) { tag = visibleTag; if (tag == null) { visibleTag = tag = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_VISIBLE); host.addTag(tag); } } else { tag = invisibleTag; if (tag == null) { invisibleTag = tag = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_INVISIBLE); host.addTag(tag); } } scb.addDep(AsmUtil.toQualifiedName(desc.substring(1, desc.length() - 1))); final VisibilityAnnotationTag _tag = tag; return new AnnotationElemBuilder() { @Override public void visitEnd() { _tag.addAnnotation(new AnnotationTag(desc, elems)); } }; } /** * @see FieldVisitor#visitAttribute(Attribute) * @see MethodVisitor#visitAttribute(Attribute) * @see ClassVisitor#visitAttribute(Attribute) */ public void visitAttribute(Attribute attr) { // SA, 2017-07-21: As of ASM 5.1, there is no better way to obtain attribute values. // TH, 2021-07-14: As of ASM 8.0.1, there is still no better way, but the field name changed. byte[] value = null; try { Field fld = Attribute.class.getDeclaredField("content"); fld.setAccessible(true); value = (byte[]) fld.get(attr); } catch (Exception ex) { // Just carry on } host.addTag(new GenericAttribute(attr.type, value)); } }
3,213
30.821782
97
java
soot
soot-master/src/main/java/soot/asm/UnitContainer.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.List; import soot.Unit; import soot.UnitBox; import soot.UnitPrinter; import soot.ValueBox; import soot.tagkit.Host; import soot.tagkit.Tag; import soot.util.Switch; /** * A psuedo unit containing different units. * * @author Aaloan Miftah */ @SuppressWarnings("serial") class UnitContainer implements Unit { final Unit[] units; UnitContainer(Unit... units) { this.units = units; } /** * Searches the depth of the UnitContainer until the actual first Unit represented is found. * * @return */ Unit getFirstUnit() { Unit ret = units[0]; while (ret instanceof UnitContainer) { ret = ((UnitContainer) ret).units[0]; } return ret; } @Override public Object clone() { throw new UnsupportedOperationException(); } public void apply(Switch sw) { throw new UnsupportedOperationException(); } public List<Tag> getTags() { throw new UnsupportedOperationException(); } public Tag getTag(String aName) { throw new UnsupportedOperationException(); } public void addTag(Tag t) { throw new UnsupportedOperationException(); } public void removeTag(String name) { throw new UnsupportedOperationException(); } public boolean hasTag(String aName) { throw new UnsupportedOperationException(); } public void removeAllTags() { throw new UnsupportedOperationException(); } public void addAllTagsOf(Host h) { throw new UnsupportedOperationException(); } public List<ValueBox> getUseBoxes() { throw new UnsupportedOperationException(); } public List<ValueBox> getDefBoxes() { throw new UnsupportedOperationException(); } public List<UnitBox> getUnitBoxes() { throw new UnsupportedOperationException(); } public List<UnitBox> getBoxesPointingToThis() { throw new UnsupportedOperationException(); } public void addBoxPointingToThis(UnitBox b) { throw new UnsupportedOperationException(); } public void removeBoxPointingToThis(UnitBox b) { throw new UnsupportedOperationException(); } public void clearUnitBoxes() { throw new UnsupportedOperationException(); } public List<ValueBox> getUseAndDefBoxes() { throw new UnsupportedOperationException(); } public boolean fallsThrough() { throw new UnsupportedOperationException(); } public boolean branches() { throw new UnsupportedOperationException(); } public void toString(UnitPrinter up) { throw new UnsupportedOperationException(); } public void redirectJumpsToThisTo(Unit newLocation) { throw new UnsupportedOperationException(); } @Override public int getJavaSourceStartLineNumber() { throw new UnsupportedOperationException(); } @Override public int getJavaSourceStartColumnNumber() { throw new UnsupportedOperationException(); } }
3,682
22.76129
94
java
soot
soot-master/src/main/java/soot/baf/AddInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface AddInst extends OpTypeArgInst { }
906
32.592593
73
java
soot
soot-master/src/main/java/soot/baf/AndInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface AndInst extends OpTypeArgInst { }
906
32.592593
73
java
soot
soot-master/src/main/java/soot/baf/ArrayLengthInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface ArrayLengthInst extends NoArgInst { }
910
32.740741
73
java
soot
soot-master/src/main/java/soot/baf/ArrayReadInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface ArrayReadInst extends OpTypeArgInst { }
912
32.814815
73
java
soot
soot-master/src/main/java/soot/baf/ArrayWriteInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface ArrayWriteInst extends OpTypeArgInst { }
913
32.851852
73
java
soot
soot-master/src/main/java/soot/baf/Baf.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * Copyright (C) 2004 Ondrej Lhotak * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.Collections; import java.util.List; import java.util.Map; import soot.ArrayType; import soot.BooleanType; import soot.ByteType; import soot.CharType; import soot.DoubleType; import soot.FloatType; import soot.G; import soot.IntType; import soot.Local; import soot.LongType; import soot.NullType; import soot.PhaseOptions; import soot.RefType; import soot.ShortType; import soot.Singletons; import soot.SootClass; import soot.SootFieldRef; import soot.SootMethod; import soot.SootMethodRef; import soot.Trap; import soot.Type; import soot.TypeSwitch; import soot.Unit; import soot.UnitBox; import soot.Value; import soot.ValueBox; import soot.baf.internal.BAddInst; import soot.baf.internal.BAndInst; import soot.baf.internal.BArrayLengthInst; import soot.baf.internal.BArrayReadInst; import soot.baf.internal.BArrayWriteInst; import soot.baf.internal.BCmpInst; import soot.baf.internal.BCmpgInst; import soot.baf.internal.BCmplInst; import soot.baf.internal.BDivInst; import soot.baf.internal.BDup1Inst; import soot.baf.internal.BDup1_x1Inst; import soot.baf.internal.BDup1_x2Inst; import soot.baf.internal.BDup2Inst; import soot.baf.internal.BDup2_x1Inst; import soot.baf.internal.BDup2_x2Inst; import soot.baf.internal.BDynamicInvokeInst; import soot.baf.internal.BEnterMonitorInst; import soot.baf.internal.BExitMonitorInst; import soot.baf.internal.BFieldGetInst; import soot.baf.internal.BFieldPutInst; import soot.baf.internal.BGotoInst; import soot.baf.internal.BIdentityInst; import soot.baf.internal.BIfCmpEqInst; import soot.baf.internal.BIfCmpGeInst; import soot.baf.internal.BIfCmpGtInst; import soot.baf.internal.BIfCmpLeInst; import soot.baf.internal.BIfCmpLtInst; import soot.baf.internal.BIfCmpNeInst; import soot.baf.internal.BIfEqInst; import soot.baf.internal.BIfGeInst; import soot.baf.internal.BIfGtInst; import soot.baf.internal.BIfLeInst; import soot.baf.internal.BIfLtInst; import soot.baf.internal.BIfNeInst; import soot.baf.internal.BIfNonNullInst; import soot.baf.internal.BIfNullInst; import soot.baf.internal.BIncInst; import soot.baf.internal.BInstanceCastInst; import soot.baf.internal.BInstanceOfInst; import soot.baf.internal.BInterfaceInvokeInst; import soot.baf.internal.BJSRInst; import soot.baf.internal.BLoadInst; import soot.baf.internal.BLookupSwitchInst; import soot.baf.internal.BMulInst; import soot.baf.internal.BNegInst; import soot.baf.internal.BNewArrayInst; import soot.baf.internal.BNewInst; import soot.baf.internal.BNewMultiArrayInst; import soot.baf.internal.BNopInst; import soot.baf.internal.BOrInst; import soot.baf.internal.BPopInst; import soot.baf.internal.BPrimitiveCastInst; import soot.baf.internal.BPushInst; import soot.baf.internal.BRemInst; import soot.baf.internal.BReturnInst; import soot.baf.internal.BReturnVoidInst; import soot.baf.internal.BShlInst; import soot.baf.internal.BShrInst; import soot.baf.internal.BSpecialInvokeInst; import soot.baf.internal.BStaticGetInst; import soot.baf.internal.BStaticInvokeInst; import soot.baf.internal.BStaticPutInst; import soot.baf.internal.BStoreInst; import soot.baf.internal.BSubInst; import soot.baf.internal.BSwapInst; import soot.baf.internal.BTableSwitchInst; import soot.baf.internal.BThrowInst; import soot.baf.internal.BTrap; import soot.baf.internal.BUshrInst; import soot.baf.internal.BVirtualInvokeInst; import soot.baf.internal.BXorInst; import soot.baf.internal.BafLocal; import soot.baf.internal.BafLocalBox; import soot.jimple.Constant; import soot.jimple.IntConstant; import soot.jimple.JimpleBody; import soot.jimple.ParameterRef; import soot.jimple.ThisRef; import soot.jimple.internal.IdentityRefBox; public class Baf { public Baf(Singletons.Global g) { } public static Baf v() { return G.v().soot_baf_Baf(); } public static Type getDescriptorTypeOf(Type opType) { if (opType instanceof NullType || opType instanceof ArrayType || opType instanceof RefType) { return RefType.v(); } else { return opType; } } /** * Constructs a Local with the given name and type. */ public Local newLocal(String name, Type t) { return new BafLocal(name, t); } /** * Constructs a new BTrap for the given exception on the given Unit range with the given Unit handler. */ public Trap newTrap(SootClass exception, Unit beginUnit, Unit endUnit, Unit handlerUnit) { return new BTrap(exception, beginUnit, endUnit, handlerUnit); } /** * Constructs a ExitMonitorInst() grammar chunk */ public ExitMonitorInst newExitMonitorInst() { return new BExitMonitorInst(); } /** * Constructs a EnterMonitorInst() grammar chunk. */ public EnterMonitorInst newEnterMonitorInst() { return new BEnterMonitorInst(); } public ReturnVoidInst newReturnVoidInst() { return new BReturnVoidInst(); } public NopInst newNopInst() { return new BNopInst(); } public GotoInst newGotoInst(Unit unit) { return new BGotoInst(unit); } public JSRInst newJSRInst(Unit unit) { return new BJSRInst(unit); } public PlaceholderInst newPlaceholderInst(Unit source) { return new PlaceholderInst(source); } public UnitBox newInstBox(Unit unit) { return new InstBox((Inst) unit); } public PushInst newPushInst(Constant c) { return new BPushInst(c); } public IdentityInst newIdentityInst(Value local, Value identityRef) { return new BIdentityInst(local, identityRef); } public ValueBox newLocalBox(Value value) { return new BafLocalBox(value); } public ValueBox newIdentityRefBox(Value value) { return new IdentityRefBox(value); } /** * Constructs a ThisRef(RefType) grammar chunk. */ public ThisRef newThisRef(RefType t) { return new ThisRef(t); } /** * Constructs a ParameterRef(SootMethod, int) grammar chunk. */ public ParameterRef newParameterRef(Type paramType, int number) { return new ParameterRef(paramType, number); } public StoreInst newStoreInst(Type opType, Local l) { return new BStoreInst(opType, l); } public LoadInst newLoadInst(Type opType, Local l) { return new BLoadInst(opType, l); } public ArrayWriteInst newArrayWriteInst(Type opType) { return new BArrayWriteInst(opType); } public ArrayReadInst newArrayReadInst(Type opType) { return new BArrayReadInst(opType); } public StaticGetInst newStaticGetInst(SootFieldRef fieldRef) { return new BStaticGetInst(fieldRef); } public StaticPutInst newStaticPutInst(SootFieldRef fieldRef) { return new BStaticPutInst(fieldRef); } public FieldGetInst newFieldGetInst(SootFieldRef fieldRef) { return new BFieldGetInst(fieldRef); } public FieldPutInst newFieldPutInst(SootFieldRef fieldRef) { return new BFieldPutInst(fieldRef); } public AddInst newAddInst(Type opType) { return new BAddInst(opType); } public PopInst newPopInst(Type aType) { return new BPopInst(aType); } public SubInst newSubInst(Type opType) { return new BSubInst(opType); } public MulInst newMulInst(Type opType) { return new BMulInst(opType); } public DivInst newDivInst(Type opType) { return new BDivInst(opType); } public AndInst newAndInst(Type opType) { return new BAndInst(opType); } public ArrayLengthInst newArrayLengthInst() { return new BArrayLengthInst(); } public NegInst newNegInst(Type opType) { return new BNegInst(opType); } public OrInst newOrInst(Type opType) { return new BOrInst(opType); } public RemInst newRemInst(Type opType) { return new BRemInst(opType); } public ShlInst newShlInst(Type opType) { return new BShlInst(opType); } public ShrInst newShrInst(Type opType) { return new BShrInst(opType); } public UshrInst newUshrInst(Type opType) { return new BUshrInst(opType); } public XorInst newXorInst(Type opType) { return new BXorInst(opType); } public InstanceCastInst newInstanceCastInst(Type opType) { return new BInstanceCastInst(opType); } public InstanceOfInst newInstanceOfInst(Type opType) { return new BInstanceOfInst(opType); } public PrimitiveCastInst newPrimitiveCastInst(Type fromType, Type toType) { return new BPrimitiveCastInst(fromType, toType); } public NewInst newNewInst(RefType opType) { return new BNewInst(opType); } public NewArrayInst newNewArrayInst(Type opType) { return new BNewArrayInst(opType); } public NewMultiArrayInst newNewMultiArrayInst(ArrayType opType, int dimensions) { return new BNewMultiArrayInst(opType, dimensions); } public DynamicInvokeInst newDynamicInvokeInst(SootMethodRef bsmMethodRef, List<Value> bsmArgs, SootMethodRef methodRef, int tag) { return new BDynamicInvokeInst(bsmMethodRef, bsmArgs, methodRef, tag); } public StaticInvokeInst newStaticInvokeInst(SootMethodRef methodRef) { return new BStaticInvokeInst(methodRef); } public SpecialInvokeInst newSpecialInvokeInst(SootMethodRef methodRef) { return new BSpecialInvokeInst(methodRef); } public VirtualInvokeInst newVirtualInvokeInst(SootMethodRef methodRef) { return new BVirtualInvokeInst(methodRef); } public InterfaceInvokeInst newInterfaceInvokeInst(SootMethodRef methodRef, int argCount) { return new BInterfaceInvokeInst(methodRef, argCount); } public ReturnInst newReturnInst(Type opType) { return new BReturnInst(opType); } public IfCmpEqInst newIfCmpEqInst(Type opType, Unit unit) { return new BIfCmpEqInst(opType, unit); } public IfCmpGeInst newIfCmpGeInst(Type opType, Unit unit) { return new BIfCmpGeInst(opType, unit); } public IfCmpGtInst newIfCmpGtInst(Type opType, Unit unit) { return new BIfCmpGtInst(opType, unit); } public IfCmpLeInst newIfCmpLeInst(Type opType, Unit unit) { return new BIfCmpLeInst(opType, unit); } public IfCmpLtInst newIfCmpLtInst(Type opType, Unit unit) { return new BIfCmpLtInst(opType, unit); } public IfCmpNeInst newIfCmpNeInst(Type opType, Unit unit) { return new BIfCmpNeInst(opType, unit); } public CmpInst newCmpInst(Type opType) { return new BCmpInst(opType); } public CmpgInst newCmpgInst(Type opType) { return new BCmpgInst(opType); } public CmplInst newCmplInst(Type opType) { return new BCmplInst(opType); } public IfEqInst newIfEqInst(Unit unit) { return new BIfEqInst(unit); } public IfGeInst newIfGeInst(Unit unit) { return new BIfGeInst(unit); } public IfGtInst newIfGtInst(Unit unit) { return new BIfGtInst(unit); } public IfLeInst newIfLeInst(Unit unit) { return new BIfLeInst(unit); } public IfLtInst newIfLtInst(Unit unit) { return new BIfLtInst(unit); } public IfNeInst newIfNeInst(Unit unit) { return new BIfNeInst(unit); } public IfNullInst newIfNullInst(Unit unit) { return new BIfNullInst(unit); } public IfNonNullInst newIfNonNullInst(Unit unit) { return new BIfNonNullInst(unit); } public ThrowInst newThrowInst() { return new BThrowInst(); } public SwapInst newSwapInst(Type fromType, Type toType) { return new BSwapInst(fromType, toType); } /* * public DupInst newDupInst(Type type) { return new BDupInst(new ArrayList(), Arrays.asList(new Type[] {type})); } */ public Dup1Inst newDup1Inst(Type type) { return new BDup1Inst(type); } public Dup2Inst newDup2Inst(Type aOp1Type, Type aOp2Type) { return new BDup2Inst(aOp1Type, aOp2Type); } public Dup1_x1Inst newDup1_x1Inst(Type aOpType, Type aUnderType) { return new BDup1_x1Inst(aOpType, aUnderType); } public Dup1_x2Inst newDup1_x2Inst(Type aOpType, Type aUnder1Type, Type aUnder2Type) { return new BDup1_x2Inst(aOpType, aUnder1Type, aUnder2Type); } public Dup2_x1Inst newDup2_x1Inst(Type aOp1Type, Type aOp2Type, Type aUnderType) { return new BDup2_x1Inst(aOp1Type, aOp2Type, aUnderType); } public Dup2_x2Inst newDup2_x2Inst(Type aOp1Type, Type aOp2Type, Type aUnder1Type, Type aUnder2Type) { return new BDup2_x2Inst(aOp1Type, aOp2Type, aUnder1Type, aUnder2Type); } public IncInst newIncInst(Local aLocal, Constant aConstant) { return new BIncInst(aLocal, aConstant); } public LookupSwitchInst newLookupSwitchInst(Unit defaultTarget, List<IntConstant> lookupValues, List<? extends Unit> targets) { return new BLookupSwitchInst(defaultTarget, lookupValues, targets); } public TableSwitchInst newTableSwitchInst(Unit defaultTarget, int lowIndex, int highIndex, List<? extends Unit> targets) { return new BTableSwitchInst(defaultTarget, lowIndex, highIndex, targets); } public static String bafDescriptorOf(Type type) { TypeSwitch<String> sw = new TypeSwitch<String>() { @Override public void caseBooleanType(BooleanType t) { setResult("b"); } @Override public void caseByteType(ByteType t) { setResult("b"); } @Override public void caseCharType(CharType t) { setResult("c"); } @Override public void caseDoubleType(DoubleType t) { setResult("d"); } @Override public void caseFloatType(FloatType t) { setResult("f"); } @Override public void caseIntType(IntType t) { setResult("i"); } @Override public void caseLongType(LongType t) { setResult("l"); } @Override public void caseShortType(ShortType t) { setResult("s"); } @Override public void caseRefType(RefType t) { setResult("r"); } @Override public void defaultCase(Type t) { throw new RuntimeException("Invalid type: " + t); } }; type.apply(sw); return sw.getResult(); } /** * Returns an empty BafBody associated with method m. */ public BafBody newBody(SootMethod m) { return new BafBody(m); } /** * Returns a BafBody constructed from b. */ public BafBody newBody(JimpleBody b) { return new BafBody(b, Collections.<String, String>emptyMap()); } /** * Returns a BafBody constructed from b. */ public BafBody newBody(JimpleBody b, String phase) { Map<String, String> options = PhaseOptions.v().getPhaseOptions(phase); return new BafBody(b, options); } }
15,224
25.804577
124
java
soot
soot-master/src/main/java/soot/baf/BafASMBackend.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import static soot.util.backend.ASMBackendUtils.sizeOfType; import static soot.util.backend.ASMBackendUtils.slashify; import static soot.util.backend.ASMBackendUtils.toTypeDesc; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.objectweb.asm.Handle; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; import soot.AbstractASMBackend; import soot.ArrayType; import soot.BooleanType; import soot.ByteType; import soot.CharType; import soot.DoubleType; import soot.FloatType; import soot.IntType; import soot.Local; import soot.LongType; import soot.NullType; import soot.PolymorphicMethodRef; import soot.RefType; import soot.ShortType; import soot.SootClass; import soot.SootFieldRef; import soot.SootMethod; import soot.SootMethodRef; import soot.StmtAddressType; import soot.Trap; import soot.Type; import soot.TypeSwitch; import soot.Unit; import soot.UnitBox; import soot.Value; import soot.baf.internal.BafLocal; import soot.jimple.CaughtExceptionRef; import soot.jimple.ClassConstant; import soot.jimple.Constant; import soot.jimple.ConstantSwitch; import soot.jimple.DoubleConstant; import soot.jimple.FloatConstant; import soot.jimple.IdentityRef; import soot.jimple.IntConstant; import soot.jimple.LongConstant; import soot.jimple.MethodHandle; import soot.jimple.MethodType; import soot.jimple.NullConstant; import soot.jimple.ParameterRef; import soot.jimple.StringConstant; import soot.jimple.ThisRef; import soot.options.Options; import soot.tagkit.LineNumberTag; import soot.util.Chain; /** * Concrete ASM based bytecode generation backend for the BAF intermediate representation * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer, Alex Bertram, Andreas Dann */ public class BafASMBackend extends AbstractASMBackend { // Contains one Label for every Unit that is the target of a branch or jump protected final Map<Unit, Label> branchTargetLabels = new HashMap<Unit, Label>(); // Contains a mapping of local variables to indices in the local variable stack protected final Map<Local, Integer> localToSlot = new HashMap<Local, Integer>(); /** * Returns the ASM Label for a given Unit that is the target of a branch or jump * * @param target * The unit that is the branch target * @return The Label that specifies this unit */ protected Label getBranchTargetLabel(Unit target) { return branchTargetLabels.get(target); } /** * Creates a new BafASMBackend with a given enforced java version * * @param sc * The SootClass the bytecode is to be generated for * @param javaVersion * A particular Java version enforced by the user, may be 0 for automatic detection, must not be lower than * necessary for all features used */ public BafASMBackend(SootClass sc, int javaVersion) { super(sc, javaVersion); } /* * (non-Javadoc) * * @see soot.AbstractASMBackend#getMinJavaVersion(soot.SootMethod) */ @Override protected int getMinJavaVersion(SootMethod method) { final BafBody body = getBafBody(method); int minVersion = Options.java_version_1_1; // http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/87ee5ee27509/src/share/vm/classfile/classFileParser.cpp if (method.getDeclaringClass().isInterface()) { if (!method.isAbstract()) { // any non-abstract method in an interface requires 1.8 minVersion = Math.max(minVersion, Options.java_version_1_8); } } for (Unit u : body.getUnits()) { if (minVersion == Options.java_version_1_9) { return minVersion; } if (u instanceof DynamicInvokeInst) { minVersion = Math.max(minVersion, Options.java_version_1_7); } if (u instanceof PushInst) { Constant constant = ((PushInst) u).getConstant(); if (constant instanceof ClassConstant) { minVersion = Math.max(minVersion, Options.java_version_1_5); } String typeString = constant.getType().toQuotedString(); if (PolymorphicMethodRef.METHODHANDLE_SIGNATURE.equals(typeString)) { minVersion = Math.max(minVersion, Options.java_version_1_7); } if (PolymorphicMethodRef.VARHANDLE_SIGNATURE.equals(typeString)) { minVersion = Math.max(minVersion, Options.java_version_1_9); } } } return minVersion; } /* * (non-Javadoc) * * @see soot.AbstractASMBackend#generateMethodBody(org.objectweb.asm. MethodVisitor, soot.SootMethod) */ @Override protected void generateMethodBody(MethodVisitor mv, SootMethod method) { final BafBody body = getBafBody(method); /* * Create a label for each instruction that is the target of some branch */ for (UnitBox box : body.getUnitBoxes(true)) { Unit u = box.getUnit(); if (!branchTargetLabels.containsKey(u)) { branchTargetLabels.put(u, new Label()); } } Label startLabel = null; if (Options.v().write_local_annotations()) { startLabel = new Label(); mv.visitLabel(startLabel); } /* * Handle all TRY-CATCH-blocks */ for (Trap trap : body.getTraps()) { // Check if the try-block contains any statement if (trap.getBeginUnit() != trap.getEndUnit()) { Label start = branchTargetLabels.get(trap.getBeginUnit()); Label end = branchTargetLabels.get(trap.getEndUnit()); Label handler = branchTargetLabels.get(trap.getHandlerUnit()); String type = slashify(trap.getException().getName()); mv.visitTryCatchBlock(start, end, handler, type); } } /* * Handle local variable slots for the "this"-local and the parameters. For non-static methods the first parameters and * zero-slot is the "this"-local. */ int localCount = method.isStatic() ? 0 : 1; int[] paramSlots = new int[method.getParameterCount()]; for (int i = 0, e = paramSlots.length; i < e; ++i) { paramSlots[i] = localCount; localCount += sizeOfType(method.getParameterType(i)); } Set<Local> assignedLocals = new HashSet<Local>(); Chain<Unit> instructions = body.getUnits(); for (Unit u : instructions) { if (u instanceof IdentityInst) { Value leftOp = ((IdentityInst) u).getLeftOp(); if (leftOp instanceof Local) { int slot = 0; IdentityRef identity = (IdentityRef) ((IdentityInst) u).getRightOp(); if (identity instanceof ThisRef) { if (method.isStatic()) { throw new RuntimeException("Attempting to use 'this' in static method"); } } else if (identity instanceof ParameterRef) { slot = paramSlots[((ParameterRef) identity).getIndex()]; } else { // Exception ref. Skip over this continue; } Local l = (Local) leftOp; localToSlot.put(l, slot); assignedLocals.add(l); } } } for (Local local : body.getLocals()) { if (assignedLocals.add(local)) { localToSlot.put(local, localCount); localCount += sizeOfType(local.getType()); } } // Generate the code for (Unit u : instructions) { if (branchTargetLabels.containsKey(u)) { mv.visitLabel(branchTargetLabels.get(u)); } generateTagsForUnit(mv, u); generateInstruction(mv, (Inst) u); } // Generate the local annotations if (Options.v().write_local_annotations()) { Label endLabel = new Label(); mv.visitLabel(endLabel); for (Local local : body.getLocals()) { Integer slot = localToSlot.get(local); if (slot != null) { BafLocal l = (BafLocal) local; Local jimpleLocal = l.getOriginalLocal(); if (jimpleLocal != null) { mv.visitLocalVariable(jimpleLocal.getName(), toTypeDesc(jimpleLocal.getType()), null, startLabel, endLabel, slot); } } } } } /** * Writes out the information stored in tags associated with the given unit * * @param mv * The method visitor for writing out the bytecode * @param u * The unit for which to write out the tags */ protected void generateTagsForUnit(MethodVisitor mv, Unit u) { LineNumberTag lnt = (LineNumberTag) u.getTag(LineNumberTag.NAME); if (lnt != null) { Label l; if (branchTargetLabels.containsKey(u)) { l = branchTargetLabels.get(u); } else { l = new Label(); mv.visitLabel(l); } mv.visitLineNumber(lnt.getLineNumber(), l); } } /** * Emits the bytecode for a single Baf instruction * * @param mv * The ASM MethodVisitor the bytecode is to be emitted to * @param inst * The Baf instruction to be converted into bytecode */ protected void generateInstruction(final MethodVisitor mv, Inst inst) { inst.apply(new InstSwitch() { @Override public void caseReturnVoidInst(ReturnVoidInst i) { mv.visitInsn(Opcodes.RETURN); } @Override public void caseReturnInst(ReturnInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseArrayType(ArrayType t) { mv.visitInsn(Opcodes.ARETURN); } @Override public void caseBooleanType(BooleanType t) { mv.visitInsn(Opcodes.IRETURN); } @Override public void caseByteType(ByteType t) { mv.visitInsn(Opcodes.IRETURN); } @Override public void caseCharType(CharType t) { mv.visitInsn(Opcodes.IRETURN); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DRETURN); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FRETURN); } @Override public void caseIntType(IntType t) { mv.visitInsn(Opcodes.IRETURN); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LRETURN); } @Override public void caseRefType(RefType t) { mv.visitInsn(Opcodes.ARETURN); } @Override public void caseShortType(ShortType t) { mv.visitInsn(Opcodes.IRETURN); } @Override public void caseNullType(NullType t) { mv.visitInsn(Opcodes.ARETURN); } @Override public void defaultCase(Type t) { throw new RuntimeException("Invalid return type " + t.toString()); } }); } @Override public void caseNopInst(NopInst i) { mv.visitInsn(Opcodes.NOP); } @Override public void caseJSRInst(JSRInst i) { mv.visitJumpInsn(Opcodes.JSR, getBranchTargetLabel(i.getTarget())); } @Override public void casePushInst(PushInst i) { Constant c = i.getConstant(); if (c instanceof IntConstant) { int v = ((IntConstant) c).value; switch (v) { case -1: mv.visitInsn(Opcodes.ICONST_M1); break; case 0: mv.visitInsn(Opcodes.ICONST_0); break; case 1: mv.visitInsn(Opcodes.ICONST_1); break; case 2: mv.visitInsn(Opcodes.ICONST_2); break; case 3: mv.visitInsn(Opcodes.ICONST_3); break; case 4: mv.visitInsn(Opcodes.ICONST_4); break; case 5: mv.visitInsn(Opcodes.ICONST_5); break; default: if (v >= Byte.MIN_VALUE && v <= Byte.MAX_VALUE) { mv.visitIntInsn(Opcodes.BIPUSH, v); } else if (v >= Short.MIN_VALUE && v <= Short.MAX_VALUE) { mv.visitIntInsn(Opcodes.SIPUSH, v); } else { mv.visitLdcInsn(v); } } } else if (c instanceof StringConstant) { mv.visitLdcInsn(((StringConstant) c).value); } else if (c instanceof ClassConstant) { mv.visitLdcInsn(org.objectweb.asm.Type.getType(((ClassConstant) c).getValue())); } else if (c instanceof DoubleConstant) { double v = ((DoubleConstant) c).value; /* * Do not emit a DCONST_0 for negative zero, therefore we need the following check. */ if (new Double(v).equals(0.0)) { mv.visitInsn(Opcodes.DCONST_0); } else if (v == 1) { mv.visitInsn(Opcodes.DCONST_1); } else { mv.visitLdcInsn(v); } } else if (c instanceof FloatConstant) { float v = ((FloatConstant) c).value; /* * Do not emit a FCONST_0 for negative zero, therefore we need the following check. */ if (new Float(v).equals(0.0f)) { mv.visitInsn(Opcodes.FCONST_0); } else if (v == 1) { mv.visitInsn(Opcodes.FCONST_1); } else if (v == 2) { mv.visitInsn(Opcodes.FCONST_2); } else { mv.visitLdcInsn(v); } } else if (c instanceof LongConstant) { long v = ((LongConstant) c).value; if (v == 0) { mv.visitInsn(Opcodes.LCONST_0); } else if (v == 1) { mv.visitInsn(Opcodes.LCONST_1); } else { mv.visitLdcInsn(v); } } else if (c instanceof NullConstant) { mv.visitInsn(Opcodes.ACONST_NULL); } else if (c instanceof MethodHandle) { Handle handle; if (((MethodHandle) c).isMethodRef()) { SootMethodRef methodRef = ((MethodHandle) c).getMethodRef(); handle = new Handle(((MethodHandle) c).getKind(), slashify(methodRef.declaringClass().getName()), methodRef.name(), toTypeDesc(methodRef), methodRef.declaringClass().isInterface()); } else { SootFieldRef fieldRef = ((MethodHandle) c).getFieldRef(); handle = new Handle(((MethodHandle) c).getKind(), slashify(fieldRef.declaringClass().getName()), fieldRef.name(), toTypeDesc(fieldRef.type()), fieldRef.declaringClass().isInterface()); } mv.visitLdcInsn(handle); } else { throw new RuntimeException("unsupported opcode"); } } @Override public void casePopInst(PopInst i) { if (i.getWordCount() == 2) { mv.visitInsn(Opcodes.POP2); } else { mv.visitInsn(Opcodes.POP); } } @Override public void caseIdentityInst(IdentityInst i) { Value l = i.getLeftOp(); Value r = i.getRightOp(); if (r instanceof CaughtExceptionRef && l instanceof Local) { mv.visitVarInsn(Opcodes.ASTORE, localToSlot.get((Local) l)); // asm handles constant opcodes automatically here } } @Override public void caseStoreInst(StoreInst i) { final int slot = localToSlot.get(i.getLocal()); i.getOpType().apply(new TypeSwitch() { @Override public void caseArrayType(ArrayType t) { mv.visitVarInsn(Opcodes.ASTORE, slot); } @Override public void caseBooleanType(BooleanType t) { mv.visitVarInsn(Opcodes.ISTORE, slot); } @Override public void caseByteType(ByteType t) { mv.visitVarInsn(Opcodes.ISTORE, slot); } @Override public void caseCharType(CharType t) { mv.visitVarInsn(Opcodes.ISTORE, slot); } @Override public void caseDoubleType(DoubleType t) { mv.visitVarInsn(Opcodes.DSTORE, slot); } @Override public void caseFloatType(FloatType t) { mv.visitVarInsn(Opcodes.FSTORE, slot); } @Override public void caseIntType(IntType t) { mv.visitVarInsn(Opcodes.ISTORE, slot); } @Override public void caseLongType(LongType t) { mv.visitVarInsn(Opcodes.LSTORE, slot); } @Override public void caseRefType(RefType t) { mv.visitVarInsn(Opcodes.ASTORE, slot); } @Override public void caseShortType(ShortType t) { mv.visitVarInsn(Opcodes.ISTORE, slot); } @Override public void caseStmtAddressType(StmtAddressType t) { throw new RuntimeException("JSR not supported, use recent Java compiler!"); } @Override public void caseNullType(NullType t) { mv.visitVarInsn(Opcodes.ASTORE, slot); } @Override public void defaultCase(Type t) { throw new RuntimeException("Invalid local type: " + t); } }); } @Override public void caseGotoInst(GotoInst i) { mv.visitJumpInsn(Opcodes.GOTO, getBranchTargetLabel(i.getTarget())); } @Override public void caseLoadInst(LoadInst i) { final int slot = localToSlot.get(i.getLocal()); i.getOpType().apply(new TypeSwitch() { @Override public void caseArrayType(ArrayType t) { mv.visitVarInsn(Opcodes.ALOAD, slot); } @Override public void caseBooleanType(BooleanType t) { mv.visitVarInsn(Opcodes.ILOAD, slot); } @Override public void caseByteType(ByteType t) { mv.visitVarInsn(Opcodes.ILOAD, slot); } @Override public void caseCharType(CharType t) { mv.visitVarInsn(Opcodes.ILOAD, slot); } @Override public void caseDoubleType(DoubleType t) { mv.visitVarInsn(Opcodes.DLOAD, slot); } @Override public void caseFloatType(FloatType t) { mv.visitVarInsn(Opcodes.FLOAD, slot); } @Override public void caseIntType(IntType t) { mv.visitVarInsn(Opcodes.ILOAD, slot); } @Override public void caseLongType(LongType t) { mv.visitVarInsn(Opcodes.LLOAD, slot); } @Override public void caseRefType(RefType t) { mv.visitVarInsn(Opcodes.ALOAD, slot); } @Override public void caseShortType(ShortType t) { mv.visitVarInsn(Opcodes.ILOAD, slot); } @Override public void caseNullType(NullType t) { mv.visitVarInsn(Opcodes.ALOAD, slot); } @Override public void defaultCase(Type t) { throw new RuntimeException("Invalid local type: " + t); } }); } @Override public void caseArrayWriteInst(ArrayWriteInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseArrayType(ArrayType t) { mv.visitInsn(Opcodes.AASTORE); } @Override public void caseBooleanType(BooleanType t) { mv.visitInsn(Opcodes.BASTORE); } @Override public void caseByteType(ByteType t) { mv.visitInsn(Opcodes.BASTORE); } @Override public void caseCharType(CharType t) { mv.visitInsn(Opcodes.CASTORE); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DASTORE); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FASTORE); } @Override public void caseIntType(IntType t) { mv.visitInsn(Opcodes.IASTORE); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LASTORE); } @Override public void caseRefType(RefType t) { mv.visitInsn(Opcodes.AASTORE); } @Override public void caseShortType(ShortType t) { mv.visitInsn(Opcodes.SASTORE); } @Override public void defaultCase(Type t) { throw new RuntimeException("Invalid type: " + t); } }); } @Override public void caseArrayReadInst(ArrayReadInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseArrayType(ArrayType t) { mv.visitInsn(Opcodes.AALOAD); } @Override public void caseBooleanType(BooleanType t) { mv.visitInsn(Opcodes.BALOAD); } @Override public void caseByteType(ByteType t) { mv.visitInsn(Opcodes.BALOAD); } @Override public void caseCharType(CharType t) { mv.visitInsn(Opcodes.CALOAD); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DALOAD); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FALOAD); } @Override public void caseIntType(IntType t) { mv.visitInsn(Opcodes.IALOAD); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LALOAD); } @Override public void caseRefType(RefType t) { mv.visitInsn(Opcodes.AALOAD); } @Override public void caseShortType(ShortType t) { mv.visitInsn(Opcodes.SALOAD); } @Override public void caseNullType(NullType t) { mv.visitInsn(Opcodes.AALOAD); } @Override public void defaultCase(Type t) { throw new RuntimeException("Invalid type: " + t); } }); } @Override public void caseIfNullInst(IfNullInst i) { mv.visitJumpInsn(Opcodes.IFNULL, getBranchTargetLabel(i.getTarget())); } @Override public void caseIfNonNullInst(IfNonNullInst i) { mv.visitJumpInsn(Opcodes.IFNONNULL, getBranchTargetLabel(i.getTarget())); } @Override public void caseIfEqInst(IfEqInst i) { mv.visitJumpInsn(Opcodes.IFEQ, getBranchTargetLabel(i.getTarget())); } @Override public void caseIfNeInst(IfNeInst i) { mv.visitJumpInsn(Opcodes.IFNE, getBranchTargetLabel(i.getTarget())); } @Override public void caseIfGtInst(IfGtInst i) { mv.visitJumpInsn(Opcodes.IFGT, getBranchTargetLabel(i.getTarget())); } @Override public void caseIfGeInst(IfGeInst i) { mv.visitJumpInsn(Opcodes.IFGE, getBranchTargetLabel(i.getTarget())); } @Override public void caseIfLtInst(IfLtInst i) { mv.visitJumpInsn(Opcodes.IFLT, getBranchTargetLabel(i.getTarget())); } @Override public void caseIfLeInst(IfLeInst i) { mv.visitJumpInsn(Opcodes.IFLE, getBranchTargetLabel(i.getTarget())); } @Override public void caseIfCmpEqInst(final IfCmpEqInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseArrayType(ArrayType t) { mv.visitJumpInsn(Opcodes.IF_ACMPEQ, getBranchTargetLabel(i.getTarget())); } @Override public void caseBooleanType(BooleanType t) { mv.visitJumpInsn(Opcodes.IF_ICMPEQ, getBranchTargetLabel(i.getTarget())); } @Override public void caseByteType(ByteType t) { mv.visitJumpInsn(Opcodes.IF_ICMPEQ, getBranchTargetLabel(i.getTarget())); } @Override public void caseCharType(CharType t) { mv.visitJumpInsn(Opcodes.IF_ICMPEQ, getBranchTargetLabel(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DCMPG); mv.visitJumpInsn(Opcodes.IFEQ, getBranchTargetLabel(i.getTarget())); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FCMPG); mv.visitJumpInsn(Opcodes.IFEQ, getBranchTargetLabel(i.getTarget())); } @Override public void caseIntType(IntType t) { mv.visitJumpInsn(Opcodes.IF_ICMPEQ, getBranchTargetLabel(i.getTarget())); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LCMP); mv.visitJumpInsn(Opcodes.IFEQ, getBranchTargetLabel(i.getTarget())); } @Override public void caseRefType(RefType t) { mv.visitJumpInsn(Opcodes.IF_ACMPEQ, getBranchTargetLabel(i.getTarget())); } @Override public void caseShortType(ShortType t) { mv.visitJumpInsn(Opcodes.IF_ICMPEQ, getBranchTargetLabel(i.getTarget())); } @Override public void caseNullType(NullType t) { mv.visitJumpInsn(Opcodes.IF_ACMPEQ, getBranchTargetLabel(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseIfCmpNeInst(final IfCmpNeInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseArrayType(ArrayType t) { mv.visitJumpInsn(Opcodes.IF_ACMPNE, getBranchTargetLabel(i.getTarget())); } @Override public void caseBooleanType(BooleanType t) { mv.visitJumpInsn(Opcodes.IF_ICMPNE, getBranchTargetLabel(i.getTarget())); } @Override public void caseByteType(ByteType t) { mv.visitJumpInsn(Opcodes.IF_ICMPNE, getBranchTargetLabel(i.getTarget())); } @Override public void caseCharType(CharType t) { mv.visitJumpInsn(Opcodes.IF_ICMPNE, getBranchTargetLabel(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DCMPG); mv.visitJumpInsn(Opcodes.IFNE, getBranchTargetLabel(i.getTarget())); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FCMPG); mv.visitJumpInsn(Opcodes.IFNE, getBranchTargetLabel(i.getTarget())); } @Override public void caseIntType(IntType t) { mv.visitJumpInsn(Opcodes.IF_ICMPNE, getBranchTargetLabel(i.getTarget())); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LCMP); mv.visitJumpInsn(Opcodes.IFNE, getBranchTargetLabel(i.getTarget())); } @Override public void caseRefType(RefType t) { mv.visitJumpInsn(Opcodes.IF_ACMPNE, getBranchTargetLabel(i.getTarget())); } @Override public void caseShortType(ShortType t) { mv.visitJumpInsn(Opcodes.IF_ICMPNE, getBranchTargetLabel(i.getTarget())); } @Override public void caseNullType(NullType t) { mv.visitJumpInsn(Opcodes.IF_ACMPNE, getBranchTargetLabel(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseIfCmpGtInst(final IfCmpGtInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseBooleanType(BooleanType t) { mv.visitJumpInsn(Opcodes.IF_ICMPGT, getBranchTargetLabel(i.getTarget())); } @Override public void caseByteType(ByteType t) { mv.visitJumpInsn(Opcodes.IF_ICMPGT, getBranchTargetLabel(i.getTarget())); } @Override public void caseCharType(CharType t) { mv.visitJumpInsn(Opcodes.IF_ICMPGT, getBranchTargetLabel(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DCMPG); mv.visitJumpInsn(Opcodes.IFGT, getBranchTargetLabel(i.getTarget())); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FCMPG); mv.visitJumpInsn(Opcodes.IFGT, getBranchTargetLabel(i.getTarget())); } @Override public void caseIntType(IntType t) { mv.visitJumpInsn(Opcodes.IF_ICMPGT, getBranchTargetLabel(i.getTarget())); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LCMP); mv.visitJumpInsn(Opcodes.IFGT, getBranchTargetLabel(i.getTarget())); } @Override public void caseShortType(ShortType t) { mv.visitJumpInsn(Opcodes.IF_ICMPGT, getBranchTargetLabel(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseIfCmpGeInst(final IfCmpGeInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseBooleanType(BooleanType t) { mv.visitJumpInsn(Opcodes.IF_ICMPGE, getBranchTargetLabel(i.getTarget())); } @Override public void caseByteType(ByteType t) { mv.visitJumpInsn(Opcodes.IF_ICMPGE, getBranchTargetLabel(i.getTarget())); } @Override public void caseCharType(CharType t) { mv.visitJumpInsn(Opcodes.IF_ICMPGE, getBranchTargetLabel(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DCMPG); mv.visitJumpInsn(Opcodes.IFGE, getBranchTargetLabel(i.getTarget())); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FCMPG); mv.visitJumpInsn(Opcodes.IFGE, getBranchTargetLabel(i.getTarget())); } @Override public void caseIntType(IntType t) { mv.visitJumpInsn(Opcodes.IF_ICMPGE, getBranchTargetLabel(i.getTarget())); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LCMP); mv.visitJumpInsn(Opcodes.IFGE, getBranchTargetLabel(i.getTarget())); } @Override public void caseShortType(ShortType t) { mv.visitJumpInsn(Opcodes.IF_ICMPGE, getBranchTargetLabel(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseIfCmpLtInst(final IfCmpLtInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseBooleanType(BooleanType t) { mv.visitJumpInsn(Opcodes.IF_ICMPLT, getBranchTargetLabel(i.getTarget())); } @Override public void caseByteType(ByteType t) { mv.visitJumpInsn(Opcodes.IF_ICMPLT, getBranchTargetLabel(i.getTarget())); } @Override public void caseCharType(CharType t) { mv.visitJumpInsn(Opcodes.IF_ICMPLT, getBranchTargetLabel(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DCMPG); mv.visitJumpInsn(Opcodes.IFLT, getBranchTargetLabel(i.getTarget())); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FCMPG); mv.visitJumpInsn(Opcodes.IFLT, getBranchTargetLabel(i.getTarget())); } @Override public void caseIntType(IntType t) { mv.visitJumpInsn(Opcodes.IF_ICMPLT, getBranchTargetLabel(i.getTarget())); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LCMP); mv.visitJumpInsn(Opcodes.IFLT, getBranchTargetLabel(i.getTarget())); } @Override public void caseShortType(ShortType t) { mv.visitJumpInsn(Opcodes.IF_ICMPLT, getBranchTargetLabel(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseIfCmpLeInst(final IfCmpLeInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseBooleanType(BooleanType t) { mv.visitJumpInsn(Opcodes.IF_ICMPLE, getBranchTargetLabel(i.getTarget())); } @Override public void caseByteType(ByteType t) { mv.visitJumpInsn(Opcodes.IF_ICMPLE, getBranchTargetLabel(i.getTarget())); } @Override public void caseCharType(CharType t) { mv.visitJumpInsn(Opcodes.IF_ICMPLE, getBranchTargetLabel(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DCMPG); mv.visitJumpInsn(Opcodes.IFLE, getBranchTargetLabel(i.getTarget())); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FCMPG); mv.visitJumpInsn(Opcodes.IFLE, getBranchTargetLabel(i.getTarget())); } @Override public void caseIntType(IntType t) { mv.visitJumpInsn(Opcodes.IF_ICMPLE, getBranchTargetLabel(i.getTarget())); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LCMP); mv.visitJumpInsn(Opcodes.IFLE, getBranchTargetLabel(i.getTarget())); } @Override public void caseShortType(ShortType t) { mv.visitJumpInsn(Opcodes.IF_ICMPLE, getBranchTargetLabel(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseStaticGetInst(StaticGetInst i) { SootFieldRef field = i.getFieldRef(); mv.visitFieldInsn(Opcodes.GETSTATIC, slashify(field.declaringClass().getName()), field.name(), toTypeDesc(field.type())); } @Override public void caseStaticPutInst(StaticPutInst i) { SootFieldRef field = i.getFieldRef(); mv.visitFieldInsn(Opcodes.PUTSTATIC, slashify(field.declaringClass().getName()), field.name(), toTypeDesc(field.type())); } @Override public void caseFieldGetInst(FieldGetInst i) { SootFieldRef field = i.getFieldRef(); mv.visitFieldInsn(Opcodes.GETFIELD, slashify(field.declaringClass().getName()), field.name(), toTypeDesc(field.type())); } @Override public void caseFieldPutInst(FieldPutInst i) { SootFieldRef field = i.getFieldRef(); mv.visitFieldInsn(Opcodes.PUTFIELD, slashify(field.declaringClass().getName()), field.name(), toTypeDesc(field.type())); } @Override public void caseInstanceCastInst(InstanceCastInst i) { Type castType = i.getCastType(); if (castType instanceof RefType) { mv.visitTypeInsn(Opcodes.CHECKCAST, slashify(((RefType) castType).getClassName())); } else if (castType instanceof ArrayType) { mv.visitTypeInsn(Opcodes.CHECKCAST, toTypeDesc(castType)); } } @Override public void caseInstanceOfInst(InstanceOfInst i) { Type checkType = i.getCheckType(); if (checkType instanceof RefType) { mv.visitTypeInsn(Opcodes.INSTANCEOF, slashify(((RefType) checkType).getClassName())); } else if (checkType instanceof ArrayType) { mv.visitTypeInsn(Opcodes.INSTANCEOF, toTypeDesc(checkType)); } } @Override public void casePrimitiveCastInst(PrimitiveCastInst i) { final Type to = i.getToType(); i.getFromType().apply(new TypeSwitch() { @Override public void caseBooleanType(BooleanType t) { emitIntToTypeCast(); } @Override public void caseByteType(ByteType t) { emitIntToTypeCast(); } @Override public void caseCharType(CharType t) { emitIntToTypeCast(); } @Override public void caseDoubleType(DoubleType t) { if (IntType.v().equals(to)) { mv.visitInsn(Opcodes.D2I); } else if (LongType.v().equals(to)) { mv.visitInsn(Opcodes.D2L); } else if (FloatType.v().equals(to)) { mv.visitInsn(Opcodes.D2F); } else { throw new RuntimeException("invalid to-type from double"); } } @Override public void caseFloatType(FloatType t) { if (IntType.v().equals(to)) { mv.visitInsn(Opcodes.F2I); } else if (LongType.v().equals(to)) { mv.visitInsn(Opcodes.F2L); } else if (DoubleType.v().equals(to)) { mv.visitInsn(Opcodes.F2D); } else { throw new RuntimeException("invalid to-type from float"); } } @Override public void caseIntType(IntType t) { emitIntToTypeCast(); } @Override public void caseLongType(LongType t) { if (IntType.v().equals(to)) { mv.visitInsn(Opcodes.L2I); } else if (FloatType.v().equals(to)) { mv.visitInsn(Opcodes.L2F); } else if (DoubleType.v().equals(to)) { mv.visitInsn(Opcodes.L2D); } else { throw new RuntimeException("invalid to-type from long"); } } @Override public void caseShortType(ShortType t) { emitIntToTypeCast(); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid from-type: " + t); } private void emitIntToTypeCast() { if (ByteType.v().equals(to)) { mv.visitInsn(Opcodes.I2B); } else if (CharType.v().equals(to)) { mv.visitInsn(Opcodes.I2C); } else if (ShortType.v().equals(to)) { mv.visitInsn(Opcodes.I2S); } else if (FloatType.v().equals(to)) { mv.visitInsn(Opcodes.I2F); } else if (LongType.v().equals(to)) { mv.visitInsn(Opcodes.I2L); } else if (DoubleType.v().equals(to)) { mv.visitInsn(Opcodes.I2D); } else if (IntType.v().equals(to)) { } else if (BooleanType.v().equals(to)) { } else { throw new RuntimeException("invalid to-type from int"); } } }); } @Override public void caseDynamicInvokeInst(DynamicInvokeInst i) { List<Value> args = i.getBootstrapArgs(); final Object[] argsArray = new Object[args.size()]; int index = 0; for (Value v : args) { final int j = index; v.apply(new ConstantSwitch() { @Override public void defaultCase(Object object) { throw new RuntimeException("Unexpected constant type!"); } @Override public void caseStringConstant(StringConstant v) { argsArray[j] = v.value; } @Override public void caseNullConstant(NullConstant v) { /* * The Jasmin-backend throws an exception for the null-type. */ throw new RuntimeException("Unexpected NullType as argument-type in invokedynamic!"); } @Override public void caseMethodHandle(MethodHandle handle) { if (handle.isMethodRef()) { SootMethodRef methodRef = handle.getMethodRef(); argsArray[j] = new Handle(handle.getKind(), slashify(methodRef.declaringClass().getName()), methodRef.name(), toTypeDesc(methodRef), methodRef.declaringClass().isInterface()); } else { SootFieldRef fieldRef = handle.getFieldRef(); argsArray[j] = new Handle(handle.getKind(), slashify(fieldRef.declaringClass().getName()), fieldRef.name(), toTypeDesc(fieldRef.type()), fieldRef.declaringClass().isInterface()); } } @Override public void caseMethodType(MethodType type) { argsArray[j] = org.objectweb.asm.Type.getType(toTypeDesc(type.getParameterTypes(), type.getReturnType())); } @Override public void caseLongConstant(LongConstant v) { argsArray[j] = v.value; } @Override public void caseIntConstant(IntConstant v) { argsArray[j] = v.value; } @Override public void caseFloatConstant(FloatConstant v) { argsArray[j] = v.value; } @Override public void caseDoubleConstant(DoubleConstant v) { argsArray[j] = v.value; } @Override public void caseClassConstant(ClassConstant v) { argsArray[j] = org.objectweb.asm.Type.getType(v.getValue()); } }); ++index; } SootMethodRef m = i.getMethodRef(); SootMethodRef bsm = i.getBootstrapMethodRef(); mv.visitInvokeDynamicInsn(m.name(), toTypeDesc(m), new Handle(i.getHandleTag(), slashify(bsm.declaringClass().getName()), bsm.name(), toTypeDesc(bsm), bsm.declaringClass().isInterface()), argsArray); } @Override public void caseStaticInvokeInst(StaticInvokeInst i) { SootMethodRef m = i.getMethodRef(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, slashify(m.declaringClass().getName()), m.name(), toTypeDesc(m), m.declaringClass().isInterface() && !m.isStatic()); } @Override public void caseVirtualInvokeInst(VirtualInvokeInst i) { SootMethodRef m = i.getMethodRef(); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, slashify(m.declaringClass().getName()), m.name(), toTypeDesc(m), m.declaringClass().isInterface()); } @Override public void caseInterfaceInvokeInst(InterfaceInvokeInst i) { SootMethodRef m = i.getMethodRef(); SootClass declaration = m.declaringClass(); boolean isInterface = true; if (!declaration.isPhantom() && !declaration.isInterface()) { /* * If the declaring class of a method called via invokeinterface is a phantom class we assume the declaring class * to be an interface. This might not be true in general, but as of today Soot can not evaluate isInterface() for * phantom classes correctly. */ isInterface = false; } mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, slashify(declaration.getName()), m.name(), toTypeDesc(m), isInterface); } @Override public void caseSpecialInvokeInst(SpecialInvokeInst i) { SootMethodRef m = i.getMethodRef(); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, slashify(m.declaringClass().getName()), m.name(), toTypeDesc(m), m.declaringClass().isInterface()); } @Override public void caseThrowInst(ThrowInst i) { mv.visitInsn(Opcodes.ATHROW); } @Override public void caseAddInst(AddInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseBooleanType(BooleanType t) { mv.visitInsn(Opcodes.IADD); } @Override public void caseByteType(ByteType t) { mv.visitInsn(Opcodes.IADD); } @Override public void caseCharType(CharType t) { mv.visitInsn(Opcodes.IADD); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DADD); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FADD); } @Override public void caseIntType(IntType t) { mv.visitInsn(Opcodes.IADD); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LADD); } @Override public void caseShortType(ShortType t) { mv.visitInsn(Opcodes.IADD); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseAndInst(AndInst i) { if (i.getOpType().equals(LongType.v())) { mv.visitInsn(Opcodes.LAND); } else { mv.visitInsn(Opcodes.IAND); } } @Override public void caseOrInst(OrInst i) { if (i.getOpType().equals(LongType.v())) { mv.visitInsn(Opcodes.LOR); } else { mv.visitInsn(Opcodes.IOR); } } @Override public void caseXorInst(XorInst i) { if (i.getOpType().equals(LongType.v())) { mv.visitInsn(Opcodes.LXOR); } else { mv.visitInsn(Opcodes.IXOR); } } @Override public void caseArrayLengthInst(ArrayLengthInst i) { mv.visitInsn(Opcodes.ARRAYLENGTH); } @Override public void caseCmpInst(CmpInst i) { mv.visitInsn(Opcodes.LCMP); } @Override public void caseCmpgInst(CmpgInst i) { if (i.getOpType().equals(FloatType.v())) { mv.visitInsn(Opcodes.FCMPG); } else { mv.visitInsn(Opcodes.DCMPG); } } @Override public void caseCmplInst(CmplInst i) { if (i.getOpType().equals(FloatType.v())) { mv.visitInsn(Opcodes.FCMPL); } else { mv.visitInsn(Opcodes.DCMPL); } } @Override public void caseDivInst(DivInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseBooleanType(BooleanType t) { mv.visitInsn(Opcodes.IDIV); } @Override public void caseByteType(ByteType t) { mv.visitInsn(Opcodes.IDIV); } @Override public void caseCharType(CharType t) { mv.visitInsn(Opcodes.IDIV); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DDIV); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FDIV); } @Override public void caseIntType(IntType t) { mv.visitInsn(Opcodes.IDIV); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LDIV); } @Override public void caseShortType(ShortType t) { mv.visitInsn(Opcodes.IDIV); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseIncInst(IncInst i) { if (i.getUseBoxes().get(0).getValue() != i.getDefBoxes().get(0).getValue()) { throw new RuntimeException("iinc def and use boxes don't match"); } if (i.getConstant() instanceof IntConstant) { mv.visitIincInsn(localToSlot.get(i.getLocal()), ((IntConstant) i.getConstant()).value); } else { throw new RuntimeException("Wrong constant type for increment!"); } } @Override public void caseMulInst(MulInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseBooleanType(BooleanType t) { mv.visitInsn(Opcodes.IMUL); } @Override public void caseByteType(ByteType t) { mv.visitInsn(Opcodes.IMUL); } @Override public void caseCharType(CharType t) { mv.visitInsn(Opcodes.IMUL); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DMUL); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FMUL); } @Override public void caseIntType(IntType t) { mv.visitInsn(Opcodes.IMUL); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LMUL); } @Override public void caseShortType(ShortType t) { mv.visitInsn(Opcodes.IMUL); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseRemInst(RemInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseBooleanType(BooleanType t) { mv.visitInsn(Opcodes.IREM); } @Override public void caseByteType(ByteType t) { mv.visitInsn(Opcodes.IREM); } @Override public void caseCharType(CharType t) { mv.visitInsn(Opcodes.IREM); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DREM); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FREM); } @Override public void caseIntType(IntType t) { mv.visitInsn(Opcodes.IREM); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LREM); } @Override public void caseShortType(ShortType t) { mv.visitInsn(Opcodes.IREM); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseSubInst(SubInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseBooleanType(BooleanType t) { mv.visitInsn(Opcodes.ISUB); } @Override public void caseByteType(ByteType t) { mv.visitInsn(Opcodes.ISUB); } @Override public void caseCharType(CharType t) { mv.visitInsn(Opcodes.ISUB); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DSUB); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FSUB); } @Override public void caseIntType(IntType t) { mv.visitInsn(Opcodes.ISUB); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LSUB); } @Override public void caseShortType(ShortType t) { mv.visitInsn(Opcodes.ISUB); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseShlInst(ShlInst i) { if (i.getOpType().equals(LongType.v())) { mv.visitInsn(Opcodes.LSHL); } else { mv.visitInsn(Opcodes.ISHL); } } @Override public void caseShrInst(ShrInst i) { if (i.getOpType().equals(LongType.v())) { mv.visitInsn(Opcodes.LSHR); } else { mv.visitInsn(Opcodes.ISHR); } } @Override public void caseUshrInst(UshrInst i) { if (i.getOpType().equals(LongType.v())) { mv.visitInsn(Opcodes.LUSHR); } else { mv.visitInsn(Opcodes.IUSHR); } } @Override public void caseNewInst(NewInst i) { mv.visitTypeInsn(Opcodes.NEW, slashify(i.getBaseType().getClassName())); } @Override public void caseNegInst(NegInst i) { i.getOpType().apply(new TypeSwitch() { @Override public void caseBooleanType(BooleanType t) { mv.visitInsn(Opcodes.INEG); } @Override public void caseByteType(ByteType t) { mv.visitInsn(Opcodes.INEG); } @Override public void caseCharType(CharType t) { mv.visitInsn(Opcodes.INEG); } @Override public void caseDoubleType(DoubleType t) { mv.visitInsn(Opcodes.DNEG); } @Override public void caseFloatType(FloatType t) { mv.visitInsn(Opcodes.FNEG); } @Override public void caseIntType(IntType t) { mv.visitInsn(Opcodes.INEG); } @Override public void caseLongType(LongType t) { mv.visitInsn(Opcodes.LNEG); } @Override public void caseShortType(ShortType t) { mv.visitInsn(Opcodes.INEG); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseSwapInst(SwapInst i) { mv.visitInsn(Opcodes.SWAP); } @Override public void caseDup1Inst(Dup1Inst i) { if (sizeOfType(i.getOp1Type()) == 2) { mv.visitInsn(Opcodes.DUP2); } else { mv.visitInsn(Opcodes.DUP); } } @Override public void caseDup2Inst(Dup2Inst i) { Type firstOpType = i.getOp1Type(); Type secondOpType = i.getOp2Type(); // The first two cases have no real bytecode equivalents. // Use a pair of instructions to simulate them. if (sizeOfType(firstOpType) == 2) { mv.visitInsn(Opcodes.DUP2); if (sizeOfType(secondOpType) == 2) { mv.visitInsn(Opcodes.DUP2); } else { mv.visitInsn(Opcodes.DUP); } } else if (sizeOfType(secondOpType) == 2) { mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.DUP2); } else { mv.visitInsn(Opcodes.DUP2); } } @Override public void caseDup1_x1Inst(Dup1_x1Inst i) { Type opType = i.getOp1Type(); Type underType = i.getUnder1Type(); if (sizeOfType(opType) == 2) { if (sizeOfType(underType) == 2) { mv.visitInsn(Opcodes.DUP2_X2); } else { mv.visitInsn(Opcodes.DUP2_X1); } } else { if (sizeOfType(underType) == 2) { mv.visitInsn(Opcodes.DUP_X2); } else { mv.visitInsn(Opcodes.DUP_X1); } } } @Override public void caseDup1_x2Inst(Dup1_x2Inst i) { int toSkip = sizeOfType(i.getUnder1Type()) + sizeOfType(i.getUnder2Type()); if (sizeOfType(i.getOp1Type()) == 2) { if (toSkip == 2) { mv.visitInsn(Opcodes.DUP2_X2); } else { throw new RuntimeException("magic not implemented yet"); } } else { if (toSkip == 2) { mv.visitInsn(Opcodes.DUP_X2); } else { throw new RuntimeException("magic not implemented yet"); } } } @Override public void caseDup2_x1Inst(Dup2_x1Inst i) { int toDup = sizeOfType(i.getOp1Type()) + sizeOfType(i.getOp2Type()); if (toDup == 2) { if (sizeOfType(i.getUnder1Type()) == 2) { mv.visitInsn(Opcodes.DUP2_X2); } else { mv.visitInsn(Opcodes.DUP2_X1); } } else { throw new RuntimeException("magic not implemented yet"); } } @Override public void caseDup2_x2Inst(Dup2_x2Inst i) { int toDup = sizeOfType(i.getOp1Type()) + sizeOfType(i.getOp2Type()); int toSkip = sizeOfType(i.getUnder1Type()) + sizeOfType(i.getUnder2Type()); if (toDup > 2 || toSkip > 2) { throw new RuntimeException("magic not implemented yet"); } if (toDup == 2 && toSkip == 2) { mv.visitInsn(Opcodes.DUP2_X2); } else { throw new RuntimeException("VoidType not allowed in Dup2_x2 Instruction"); } } @Override public void caseNewArrayInst(NewArrayInst i) { Type t = i.getBaseType(); if (t instanceof RefType) { mv.visitTypeInsn(Opcodes.ANEWARRAY, slashify(((RefType) t).getClassName())); } else if (t instanceof ArrayType) { mv.visitTypeInsn(Opcodes.ANEWARRAY, toTypeDesc(t)); } else { int type; if (BooleanType.v().equals(t)) { type = Opcodes.T_BOOLEAN; } else if (CharType.v().equals(t)) { type = Opcodes.T_CHAR; } else if (FloatType.v().equals(t)) { type = Opcodes.T_FLOAT; } else if (DoubleType.v().equals(t)) { type = Opcodes.T_DOUBLE; } else if (ByteType.v().equals(t)) { type = Opcodes.T_BYTE; } else if (ShortType.v().equals(t)) { type = Opcodes.T_SHORT; } else if (IntType.v().equals(t)) { type = Opcodes.T_INT; } else if (LongType.v().equals(t)) { type = Opcodes.T_LONG; } else { throw new RuntimeException("invalid type"); } mv.visitIntInsn(Opcodes.NEWARRAY, type); } } @Override public void caseNewMultiArrayInst(NewMultiArrayInst i) { mv.visitMultiANewArrayInsn(toTypeDesc(i.getBaseType()), i.getDimensionCount()); } @Override public void caseLookupSwitchInst(LookupSwitchInst i) { List<IntConstant> values = i.getLookupValues(); List<Unit> targets = i.getTargets(); final int size = values.size(); int[] keys = new int[size]; Label[] labels = new Label[size]; for (int j = 0; j < size; j++) { keys[j] = values.get(j).value; labels[j] = branchTargetLabels.get(targets.get(j)); } mv.visitLookupSwitchInsn(branchTargetLabels.get(i.getDefaultTarget()), keys, labels); } @Override public void caseTableSwitchInst(TableSwitchInst i) { List<Unit> targets = i.getTargets(); final int size = targets.size(); Label[] labels = new Label[size]; for (int j = 0; j < size; j++) { labels[j] = branchTargetLabels.get(targets.get(j)); } mv.visitTableSwitchInsn(i.getLowIndex(), i.getHighIndex(), branchTargetLabels.get(i.getDefaultTarget()), labels); } @Override public void caseEnterMonitorInst(EnterMonitorInst i) { mv.visitInsn(Opcodes.MONITORENTER); } @Override public void caseExitMonitorInst(ExitMonitorInst i) { mv.visitInsn(Opcodes.MONITOREXIT); } }); } }
61,523
29.457426
125
java
soot
soot-master/src/main/java/soot/baf/BafBody.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import soot.Body; import soot.DoubleType; import soot.Local; import soot.LongType; import soot.PackManager; import soot.SootMethod; import soot.Trap; import soot.Type; import soot.Unit; import soot.UnitBox; import soot.baf.internal.BafLocal; import soot.jimple.ConvertToBaf; import soot.jimple.JimpleBody; import soot.jimple.JimpleToBafContext; import soot.options.Options; public class BafBody extends Body { private static final Logger logger = LoggerFactory.getLogger(BafBody.class); private final JimpleToBafContext jimpleToBafContext; public BafBody(JimpleBody jimpleBody, Map<String, String> options) { super(jimpleBody.getMethod()); if (Options.v().verbose()) { logger.debug("[" + getMethod().getName() + "] Constructing BafBody..."); } JimpleToBafContext context = new JimpleToBafContext(jimpleBody.getLocalCount()); this.jimpleToBafContext = context; // Convert all locals for (Local l : jimpleBody.getLocals()) { Type t = l.getType(); t = (DoubleType.v().equals(t) || LongType.v().equals(t)) ? DoubleWordType.v() : WordType.v(); BafLocal newLocal = (BafLocal) Baf.v().newLocal(l.getName(), t); context.setBafLocalOfJimpleLocal(l, newLocal); // We cannot use the context for the purpose of saving the old Jimple locals, because // some transformers in the bb-pack, which is called at the end of the method // copy the locals, thus invalidating the information in a map. newLocal.setOriginalLocal(l); getLocals().add(newLocal); } assert (getLocals().size() == jimpleBody.getLocalCount()); Map<Unit, Unit> origToFirstConverted = new HashMap<Unit, Unit>(); // Convert all jimple instructions for (Unit u : jimpleBody.getUnits()) { List<Unit> conversionList = new ArrayList<Unit>(); context.setCurrentUnit(u); ((ConvertToBaf) u).convertToBaf(context, conversionList); origToFirstConverted.put(u, conversionList.get(0)); getUnits().addAll(conversionList); } // Change all place holders for (UnitBox box : getAllUnitBoxes()) { Unit unit = box.getUnit(); if (unit instanceof PlaceholderInst) { Unit source = ((PlaceholderInst) unit).getSource(); box.setUnit(origToFirstConverted.get(source)); } } // Convert all traps for (Trap trap : jimpleBody.getTraps()) { getTraps().add(Baf.v().newTrap(trap.getException(), origToFirstConverted.get(trap.getBeginUnit()), origToFirstConverted.get(trap.getEndUnit()), origToFirstConverted.get(trap.getHandlerUnit()))); } PackManager.v().getPack("bb").apply(this); } // clone constructor BafBody(SootMethod m) { super(m); this.jimpleToBafContext = null; } public JimpleToBafContext getContext() { return this.jimpleToBafContext; } @Override public Object clone() { Body b = new BafBody(getMethodUnsafe()); b.importBodyContentsFrom(this); return b; } }
3,987
30.401575
105
java
soot
soot-master/src/main/java/soot/baf/CmpInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface CmpInst extends OpTypeArgInst { }
906
32.592593
73
java
soot
soot-master/src/main/java/soot/baf/CmpgInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface CmpgInst extends OpTypeArgInst { }
907
32.62963
73
java
soot
soot-master/src/main/java/soot/baf/CmplInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface CmplInst extends OpTypeArgInst { }
907
32.62963
73
java
soot
soot-master/src/main/java/soot/baf/DivInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface DivInst extends OpTypeArgInst { }
906
32.592593
73
java
soot
soot-master/src/main/java/soot/baf/DoubleWordType.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.G; import soot.Singletons; import soot.Type; import soot.util.Switch; public class DoubleWordType extends Type { public DoubleWordType(Singletons.Global g) { } public static DoubleWordType v() { return G.v().soot_baf_DoubleWordType(); } @Override public boolean equals(Object t) { return this == t; } @Override public int hashCode() { return 0xA247839F; } @Override public String toString() { return "dword"; } @Override public void apply(Switch sw) { throw new RuntimeException("invalid switch case"); } }
1,433
23.305085
73
java
soot
soot-master/src/main/java/soot/baf/Dup1Inst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Type; public interface Dup1Inst extends DupInst { public Type getOp1Type(); }
948
30.633333
73
java
soot
soot-master/src/main/java/soot/baf/Dup1_x1Inst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Type; public interface Dup1_x1Inst extends DupInst { public Type getOp1Type(); public Type getUnder1Type(); }
983
29.75
73
java
soot
soot-master/src/main/java/soot/baf/Dup1_x2Inst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Type; public interface Dup1_x2Inst extends DupInst { public Type getOp1Type(); public Type getUnder1Type(); public Type getUnder2Type(); }
1,015
28.882353
73
java
soot
soot-master/src/main/java/soot/baf/Dup2Inst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Type; public interface Dup2Inst extends DupInst { public Type getOp1Type(); public Type getOp2Type(); }
977
29.5625
73
java
soot
soot-master/src/main/java/soot/baf/Dup2_x1Inst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Type; public interface Dup2_x1Inst extends DupInst { public Type getOp1Type(); public Type getOp2Type(); public Type getUnder1Type(); }
1,012
28.794118
73
java
soot
soot-master/src/main/java/soot/baf/Dup2_x2Inst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Type; public interface Dup2_x2Inst extends DupInst { public Type getOp1Type(); public Type getOp2Type(); public Type getUnder1Type(); public Type getUnder2Type(); }
1,044
28.027778
73
java
soot
soot-master/src/main/java/soot/baf/DupInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.List; import soot.Type; public interface DupInst extends Inst { public List<Type> getOpTypes(); public List<Type> getUnderTypes(); }
1,013
27.971429
73
java
soot
soot-master/src/main/java/soot/baf/DynamicInvokeInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.List; import soot.SootMethodRef; import soot.Value; public interface DynamicInvokeInst extends MethodArgInst { public SootMethodRef getBootstrapMethodRef(); public List<Value> getBootstrapArgs(); /** * Tag of the method handle, see JVM-spec. 5.4.3.5. */ public int getHandleTag(); }
1,174
27.658537
73
java
soot
soot-master/src/main/java/soot/baf/EnterMonitorInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface EnterMonitorInst extends NoArgInst { }
911
32.777778
73
java
soot
soot-master/src/main/java/soot/baf/ExitMonitorInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface ExitMonitorInst extends NoArgInst { }
910
32.740741
73
java
soot
soot-master/src/main/java/soot/baf/FieldArgInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * Copyright (C) 2004 Ondrej Lhotak * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.SootField; import soot.SootFieldRef; public interface FieldArgInst extends Inst { public SootFieldRef getFieldRef(); public SootField getField(); }
1,057
30.117647
73
java
soot
soot-master/src/main/java/soot/baf/FieldGetInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface FieldGetInst extends FieldArgInst { }
910
32.740741
73
java
soot
soot-master/src/main/java/soot/baf/FieldPutInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface FieldPutInst extends FieldArgInst { }
910
32.740741
73
java
soot
soot-master/src/main/java/soot/baf/GotoInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface GotoInst extends TargetArgInst { }
907
32.62963
73
java
soot
soot-master/src/main/java/soot/baf/IdentityInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.IdentityUnit; import soot.Value; public interface IdentityInst extends Inst, IdentityUnit { public void setLeftOp(Value variable); public void setRightOp(Value rvalue); }
1,045
29.764706
73
java
soot
soot-master/src/main/java/soot/baf/IfCmpEqInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfCmpEqInst extends TargetArgInst, OpTypeArgInst { }
925
33.296296
73
java
soot
soot-master/src/main/java/soot/baf/IfCmpGeInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfCmpGeInst extends TargetArgInst, OpTypeArgInst { }
925
33.296296
73
java
soot
soot-master/src/main/java/soot/baf/IfCmpGtInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfCmpGtInst extends TargetArgInst, OpTypeArgInst { }
925
33.296296
73
java
soot
soot-master/src/main/java/soot/baf/IfCmpLeInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfCmpLeInst extends TargetArgInst, OpTypeArgInst { }
925
33.296296
73
java
soot
soot-master/src/main/java/soot/baf/IfCmpLtInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfCmpLtInst extends TargetArgInst, OpTypeArgInst { }
925
33.296296
73
java
soot
soot-master/src/main/java/soot/baf/IfCmpNeInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfCmpNeInst extends TargetArgInst, OpTypeArgInst { }
925
33.296296
73
java
soot
soot-master/src/main/java/soot/baf/IfEqInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfEqInst extends TargetArgInst { }
907
32.62963
73
java
soot
soot-master/src/main/java/soot/baf/IfGeInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfGeInst extends TargetArgInst { }
907
32.62963
73
java
soot
soot-master/src/main/java/soot/baf/IfGtInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfGtInst extends TargetArgInst { }
907
32.62963
73
java
soot
soot-master/src/main/java/soot/baf/IfLeInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfLeInst extends TargetArgInst { }
907
32.62963
73
java
soot
soot-master/src/main/java/soot/baf/IfLtInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfLtInst extends TargetArgInst { }
907
32.62963
73
java
soot
soot-master/src/main/java/soot/baf/IfNeInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfNeInst extends TargetArgInst { }
907
32.62963
73
java
soot
soot-master/src/main/java/soot/baf/IfNonNullInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfNonNullInst extends TargetArgInst { }
912
32.814815
73
java
soot
soot-master/src/main/java/soot/baf/IfNullInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface IfNullInst extends TargetArgInst { }
909
32.703704
73
java
soot
soot-master/src/main/java/soot/baf/IncInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Local; import soot.jimple.Constant; public interface IncInst extends Inst { Constant getConstant(); void setConstant(Constant aConstant); void setLocal(Local l); Local getLocal(); }
1,063
26.282051
73
java
soot
soot-master/src/main/java/soot/baf/Inst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Unit; public interface Inst extends Unit { public int getInCount(); public int getOutCount(); public int getNetCount(); public int getInMachineCount(); public int getOutMachineCount(); public int getNetMachineCount(); public boolean containsInvokeExpr(); public boolean containsFieldRef(); public boolean containsArrayRef(); public boolean containsNewExpr(); }
1,258
25.229167
73
java
soot
soot-master/src/main/java/soot/baf/InstBox.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.AbstractUnitBox; import soot.Unit; class InstBox extends AbstractUnitBox { InstBox(Inst s) { setUnit(s); } @Override public boolean canContainUnit(Unit u) { return u == null || u instanceof Inst; } }
1,088
26.923077
73
java
soot
soot-master/src/main/java/soot/baf/InstSwitch.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.util.Switch; public interface InstSwitch extends Switch { public void caseReturnVoidInst(ReturnVoidInst i); public void caseReturnInst(ReturnInst i); public void caseNopInst(NopInst i); public void caseGotoInst(GotoInst i); public void caseJSRInst(JSRInst i); public void casePushInst(PushInst i); public void casePopInst(PopInst i); public void caseIdentityInst(IdentityInst i); public void caseStoreInst(StoreInst i); public void caseLoadInst(LoadInst i); public void caseArrayWriteInst(ArrayWriteInst i); public void caseArrayReadInst(ArrayReadInst i); public void caseIfNullInst(IfNullInst i); public void caseIfNonNullInst(IfNonNullInst i); public void caseIfEqInst(IfEqInst i); public void caseIfNeInst(IfNeInst i); public void caseIfGtInst(IfGtInst i); public void caseIfGeInst(IfGeInst i); public void caseIfLtInst(IfLtInst i); public void caseIfLeInst(IfLeInst i); public void caseIfCmpEqInst(IfCmpEqInst i); public void caseIfCmpNeInst(IfCmpNeInst i); public void caseIfCmpGtInst(IfCmpGtInst i); public void caseIfCmpGeInst(IfCmpGeInst i); public void caseIfCmpLtInst(IfCmpLtInst i); public void caseIfCmpLeInst(IfCmpLeInst i); public void caseStaticGetInst(StaticGetInst i); public void caseStaticPutInst(StaticPutInst i); public void caseFieldGetInst(FieldGetInst i); public void caseFieldPutInst(FieldPutInst i); public void caseInstanceCastInst(InstanceCastInst i); public void caseInstanceOfInst(InstanceOfInst i); public void casePrimitiveCastInst(PrimitiveCastInst i); public void caseDynamicInvokeInst(DynamicInvokeInst i); public void caseStaticInvokeInst(StaticInvokeInst i); public void caseVirtualInvokeInst(VirtualInvokeInst i); public void caseInterfaceInvokeInst(InterfaceInvokeInst i); public void caseSpecialInvokeInst(SpecialInvokeInst i); public void caseThrowInst(ThrowInst i); public void caseAddInst(AddInst i); public void caseAndInst(AndInst i); public void caseOrInst(OrInst i); public void caseXorInst(XorInst i); public void caseArrayLengthInst(ArrayLengthInst i); public void caseCmpInst(CmpInst i); public void caseCmpgInst(CmpgInst i); public void caseCmplInst(CmplInst i); public void caseDivInst(DivInst i); public void caseIncInst(IncInst i); public void caseMulInst(MulInst i); public void caseRemInst(RemInst i); public void caseSubInst(SubInst i); public void caseShlInst(ShlInst i); public void caseShrInst(ShrInst i); public void caseUshrInst(UshrInst i); public void caseNewInst(NewInst i); public void caseNegInst(NegInst i); public void caseSwapInst(SwapInst i); public void caseDup1Inst(Dup1Inst i); public void caseDup2Inst(Dup2Inst i); public void caseDup1_x1Inst(Dup1_x1Inst i); public void caseDup1_x2Inst(Dup1_x2Inst i); public void caseDup2_x1Inst(Dup2_x1Inst i); public void caseDup2_x2Inst(Dup2_x2Inst i); public void caseNewArrayInst(NewArrayInst i); public void caseNewMultiArrayInst(NewMultiArrayInst i); public void caseLookupSwitchInst(LookupSwitchInst i); public void caseTableSwitchInst(TableSwitchInst i); public void caseEnterMonitorInst(EnterMonitorInst i); public void caseExitMonitorInst(ExitMonitorInst i); }
4,159
23.761905
73
java
soot
soot-master/src/main/java/soot/baf/InstanceCastInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Type; public interface InstanceCastInst extends Inst { public Type getCastType(); public void setCastType(Type type); }
993
30.0625
73
java
soot
soot-master/src/main/java/soot/baf/InstanceOfInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Type; public interface InstanceOfInst extends Inst { public Type getCheckType(); public void setCheckType(Type type); }
993
30.0625
73
java
soot
soot-master/src/main/java/soot/baf/InterfaceInvokeInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface InterfaceInvokeInst extends MethodArgInst { public int getArgCount(); public void setArgCount(int x); }
981
31.733333
73
java
soot
soot-master/src/main/java/soot/baf/JSRInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 1999 Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ /** * @author Michael Batchelder * * Created on 22-Mar-2006 */ public interface JSRInst extends TargetArgInst { }
952
29.741935
71
java
soot
soot-master/src/main/java/soot/baf/JasminClass.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import soot.AbstractJasminClass; import soot.ArrayType; import soot.Body; import soot.BooleanType; import soot.ByteType; import soot.CharType; import soot.DoubleType; import soot.FloatType; import soot.IntType; import soot.Local; import soot.LongType; import soot.Modifier; import soot.NullType; import soot.PackManager; import soot.RefType; import soot.ShortType; import soot.SootClass; import soot.SootFieldRef; import soot.SootMethod; import soot.SootMethodRef; import soot.StmtAddressType; import soot.Timers; import soot.Trap; import soot.Type; import soot.TypeSwitch; import soot.Unit; import soot.UnitBox; import soot.Value; import soot.jimple.CaughtExceptionRef; import soot.jimple.ClassConstant; import soot.jimple.Constant; import soot.jimple.DoubleConstant; import soot.jimple.FloatConstant; import soot.jimple.IdentityRef; import soot.jimple.IntConstant; import soot.jimple.JimpleBody; import soot.jimple.LongConstant; import soot.jimple.MethodHandle; import soot.jimple.NullConstant; import soot.jimple.ParameterRef; import soot.jimple.StringConstant; import soot.jimple.ThisRef; import soot.options.Options; import soot.tagkit.JasminAttribute; import soot.tagkit.LineNumberTag; import soot.tagkit.Tag; import soot.toolkits.graph.Block; import soot.toolkits.graph.BlockGraph; import soot.toolkits.graph.BriefBlockGraph; import soot.util.ArraySet; import soot.util.Chain; public class JasminClass extends AbstractJasminClass { private static final Logger logger = LoggerFactory.getLogger(JasminClass.class); public JasminClass(SootClass sootClass) { super(sootClass); } @Override protected void assignColorsToLocals(Body body) { super.assignColorsToLocals(body); if (Options.v().time()) { Timers.v().packTimer.end(); } } @Override protected void emitMethodBody(SootMethod method) { if (Options.v().time()) { Timers.v().buildJasminTimer.end(); } Body activeBody = method.getActiveBody(); if (!(activeBody instanceof BafBody)) { if (activeBody instanceof JimpleBody) { if (Options.v().verbose()) { logger.debug( "Was expecting Baf body for " + method + " but found a Jimple body. Will convert body to Baf on the fly."); } activeBody = PackManager.v().convertJimpleBodyToBaf(method); } else { throw new RuntimeException("method: " + method.getName() + " has an invalid active body!"); } } BafBody body = (BafBody) activeBody; if (body == null) { throw new RuntimeException("method: " + method.getName() + " has no active body!"); } if (Options.v().time()) { Timers.v().buildJasminTimer.start(); } Chain<Unit> instList = body.getUnits(); int stackLimitIndex = -1; subroutineToReturnAddressSlot = new HashMap<Unit, Integer>(10, 0.7f); // Determine the unitToLabel map { unitToLabel = new HashMap<Unit, String>(instList.size() * 2 + 1, 0.7f); labelCount = 0; for (UnitBox uBox : body.getUnitBoxes(true)) { // Assign a label for each statement reference { InstBox box = (InstBox) uBox; if (!unitToLabel.containsKey(box.getUnit())) { unitToLabel.put(box.getUnit(), "label" + labelCount++); } } } } // Emit the exceptions, recording the Units at the beginning // of handlers so that later on we can recognize blocks that // begin with an exception on the stack. Set<Unit> handlerUnits = new ArraySet<Unit>(body.getTraps().size()); for (Trap trap : body.getTraps()) { handlerUnits.add(trap.getHandlerUnit()); if (trap.getBeginUnit() != trap.getEndUnit()) { emit(".catch " + slashify(trap.getException().getName()) + " from " + unitToLabel.get(trap.getBeginUnit()) + " to " + unitToLabel.get(trap.getEndUnit()) + " using " + unitToLabel.get(trap.getHandlerUnit())); } } // Determine where the locals go { int localCount = 0; int[] paramSlots = new int[method.getParameterCount()]; int thisSlot = 0; Set<Local> assignedLocals = new HashSet<Local>(); localToSlot = new HashMap<Local, Integer>(body.getLocalCount() * 2 + 1, 0.7f); // assignColorsToLocals(body); // Determine slots for 'this' and parameters { if (!method.isStatic()) { thisSlot = 0; localCount++; } for (int i = 0; i < method.getParameterCount(); i++) { paramSlots[i] = localCount; localCount += sizeOfType(method.getParameterType(i)); } } // Handle identity statements for (Unit u : instList) { Inst s = (Inst) u; if (s instanceof IdentityInst) { IdentityInst is = (IdentityInst) s; Value lhs = is.getLeftOp(); if (lhs instanceof Local) { int slot = 0; IdentityRef identity = (IdentityRef) is.getRightOp(); if (identity instanceof ThisRef) { if (method.isStatic()) { throw new RuntimeException("Attempting to use 'this' in static method"); } slot = thisSlot; } else if (identity instanceof ParameterRef) { slot = paramSlots[((ParameterRef) identity).getIndex()]; } else { // Exception ref. Skip over this continue; } Local l = (Local) lhs; localToSlot.put(l, slot); assignedLocals.add(l); } } } // Assign the rest of the locals { for (Local local : body.getLocals()) { if (assignedLocals.add(local)) { localToSlot.put(local, localCount); localCount += sizeOfType(local.getType()); } } int modifiers = method.getModifiers(); if (!Modifier.isNative(modifiers) && !Modifier.isAbstract(modifiers)) { emit(" .limit stack ?"); stackLimitIndex = code.size() - 1; emit(" .limit locals " + localCount); } } } // Emit code in one pass { isEmittingMethodCode = true; maxStackHeight = 0; isNextGotoAJsr = false; for (Unit u : instList) { Inst s = (Inst) u; if (unitToLabel.containsKey(s)) { emit(unitToLabel.get(s) + ":"); } // emit this statement emitInst(s); } isEmittingMethodCode = false; // calculate max stack height { maxStackHeight = 0; if (!activeBody.getUnits().isEmpty()) { BlockGraph blockGraph = new BriefBlockGraph(activeBody); if (!blockGraph.getBlocks().isEmpty()) { // set the stack height of the entry points List<Block> entryPoints = blockGraph.getHeads(); for (Block entryBlock : entryPoints) { Integer initialHeight; if (handlerUnits.contains(entryBlock.getHead())) { initialHeight = 1; } else { initialHeight = 0; } if (blockToStackHeight == null) { blockToStackHeight = new HashMap<Block, Integer>(); } blockToStackHeight.put(entryBlock, initialHeight); if (blockToLogicalStackHeight == null) { blockToLogicalStackHeight = new HashMap<Block, Integer>(); } blockToLogicalStackHeight.put(entryBlock, initialHeight); } // dfs the block graph using the blocks in the // entryPoints list as roots for (Block nextBlock : entryPoints) { calculateStackHeight(nextBlock); calculateLogicalStackHeightCheck(nextBlock); } } } } int modifiers = method.getModifiers(); if (!Modifier.isNative(modifiers) && !Modifier.isAbstract(modifiers)) { code.set(stackLimitIndex, " .limit stack " + maxStackHeight); } } // emit code attributes for (Tag t : body.getTags()) { if (t instanceof JasminAttribute) { emit(".code_attribute " + t.getName() + " \"" + ((JasminAttribute) t).getJasminValue(unitToLabel) + "\""); } } } void emitInst(Inst inst) { LineNumberTag lnTag = (LineNumberTag) inst.getTag(LineNumberTag.NAME); if (lnTag != null) { emit(".line " + lnTag.getLineNumber()); } inst.apply(new InstSwitch() { @Override public void caseReturnVoidInst(ReturnVoidInst i) { emit("return"); } @Override public void caseReturnInst(ReturnInst i) { i.getOpType().apply(new TypeSwitch<Object>() { @Override public void defaultCase(Type t) { throw new RuntimeException("invalid return type " + t.toString()); } @Override public void caseDoubleType(DoubleType t) { emit("dreturn"); } @Override public void caseFloatType(FloatType t) { emit("freturn"); } @Override public void caseIntType(IntType t) { emit("ireturn"); } @Override public void caseByteType(ByteType t) { emit("ireturn"); } @Override public void caseShortType(ShortType t) { emit("ireturn"); } @Override public void caseCharType(CharType t) { emit("ireturn"); } @Override public void caseBooleanType(BooleanType t) { emit("ireturn"); } @Override public void caseLongType(LongType t) { emit("lreturn"); } @Override public void caseArrayType(ArrayType t) { emit("areturn"); } @Override public void caseRefType(RefType t) { emit("areturn"); } @Override public void caseNullType(NullType t) { emit("areturn"); } }); } @Override public void caseNopInst(NopInst i) { emit("nop"); } @Override public void caseEnterMonitorInst(EnterMonitorInst i) { emit("monitorenter"); } @Override public void casePopInst(PopInst i) { if (i.getWordCount() == 2) { emit("pop2"); } else { emit("pop"); } } @Override public void caseExitMonitorInst(ExitMonitorInst i) { emit("monitorexit"); } @Override public void caseGotoInst(GotoInst i) { emit("goto " + unitToLabel.get(i.getTarget())); } @Override public void caseJSRInst(JSRInst i) { emit("jsr " + unitToLabel.get(i.getTarget())); } @Override public void casePushInst(PushInst i) { final Constant constant = i.getConstant(); if (constant instanceof IntConstant) { IntConstant v = (IntConstant) constant; int val = v.value; if (val == -1) { emit("iconst_m1"); } else if (val >= 0 && val <= 5) { emit("iconst_" + val); } else if (val >= Byte.MIN_VALUE && val <= Byte.MAX_VALUE) { emit("bipush " + val); } else if (val >= Short.MIN_VALUE && val <= Short.MAX_VALUE) { emit("sipush " + val); } else { emit("ldc " + v.toString()); } } else if (constant instanceof StringConstant) { emit("ldc " + constant.toString()); } else if (constant instanceof ClassConstant) { emit("ldc " + ((ClassConstant) constant).toInternalString()); } else if (constant instanceof DoubleConstant) { DoubleConstant v = (DoubleConstant) constant; double val = v.value; if ((val == 0) && ((1.0 / val) > 0.0)) { emit("dconst_0"); } else if (val == 1) { emit("dconst_1"); } else { emit("ldc2_w " + doubleToString(v)); } } else if (constant instanceof FloatConstant) { FloatConstant v = (FloatConstant) constant; float val = v.value; if ((val == 0) && ((1.0f / val) > 1.0f)) { emit("fconst_0"); } else if (val == 1) { emit("fconst_1"); } else if (val == 2) { emit("fconst_2"); } else { emit("ldc " + floatToString(v)); } } else if (constant instanceof LongConstant) { LongConstant v = (LongConstant) constant; long val = v.value; if (val == 0) { emit("lconst_0"); } else if (val == 1) { emit("lconst_1"); } else { emit("ldc2_w " + v.toString()); } } else if (constant instanceof NullConstant) { emit("aconst_null"); } else if (constant instanceof MethodHandle) { throw new RuntimeException("MethodHandle constants not supported by Jasmin. Please use -asm-backend."); } else { throw new RuntimeException("unsupported opcode"); } } @Override public void caseIdentityInst(IdentityInst i) { if (i.getRightOp() instanceof CaughtExceptionRef) { Value leftOp = i.getLeftOp(); if (leftOp instanceof Local) { int slot = localToSlot.get((Local) leftOp); if (slot >= 0 && slot <= 3) { emit("astore_" + slot); } else { emit("astore " + slot); } } } } @Override public void caseStoreInst(StoreInst i) { final int slot = localToSlot.get(i.getLocal()); i.getOpType().apply(new TypeSwitch<Object>() { @Override public void caseArrayType(ArrayType t) { if (slot >= 0 && slot <= 3) { emit("astore_" + slot); } else { emit("astore " + slot); } } @Override public void caseDoubleType(DoubleType t) { if (slot >= 0 && slot <= 3) { emit("dstore_" + slot); } else { emit("dstore " + slot); } } @Override public void caseFloatType(FloatType t) { if (slot >= 0 && slot <= 3) { emit("fstore_" + slot); } else { emit("fstore " + slot); } } @Override public void caseIntType(IntType t) { if (slot >= 0 && slot <= 3) { emit("istore_" + slot); } else { emit("istore " + slot); } } @Override public void caseByteType(ByteType t) { if (slot >= 0 && slot <= 3) { emit("istore_" + slot); } else { emit("istore " + slot); } } @Override public void caseShortType(ShortType t) { if (slot >= 0 && slot <= 3) { emit("istore_" + slot); } else { emit("istore " + slot); } } @Override public void caseCharType(CharType t) { if (slot >= 0 && slot <= 3) { emit("istore_" + slot); } else { emit("istore " + slot); } } @Override public void caseBooleanType(BooleanType t) { if (slot >= 0 && slot <= 3) { emit("istore_" + slot); } else { emit("istore " + slot); } } @Override public void caseLongType(LongType t) { if (slot >= 0 && slot <= 3) { emit("lstore_" + slot); } else { emit("lstore " + slot); } } @Override public void caseRefType(RefType t) { if (slot >= 0 && slot <= 3) { emit("astore_" + slot); } else { emit("astore " + slot); } } @Override public void caseStmtAddressType(StmtAddressType t) { isNextGotoAJsr = true; returnAddressSlot = slot; /* * if ( slot >= 0 && slot <= 3) emit("astore_" + slot, ); else emit("astore " + slot, ); */ } @Override public void caseNullType(NullType t) { if (slot >= 0 && slot <= 3) { emit("astore_" + slot); } else { emit("astore " + slot); } } @Override public void defaultCase(Type t) { throw new RuntimeException("Invalid local type:" + t); } }); } @Override public void caseLoadInst(LoadInst i) { final int slot = localToSlot.get(i.getLocal()); i.getOpType().apply(new TypeSwitch<Object>() { @Override public void caseArrayType(ArrayType t) { if (slot >= 0 && slot <= 3) { emit("aload_" + slot); } else { emit("aload " + slot); } } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid local type to load" + t); } @Override public void caseDoubleType(DoubleType t) { if (slot >= 0 && slot <= 3) { emit("dload_" + slot); } else { emit("dload " + slot); } } @Override public void caseFloatType(FloatType t) { if (slot >= 0 && slot <= 3) { emit("fload_" + slot); } else { emit("fload " + slot); } } @Override public void caseIntType(IntType t) { if (slot >= 0 && slot <= 3) { emit("iload_" + slot); } else { emit("iload " + slot); } } @Override public void caseByteType(ByteType t) { if (slot >= 0 && slot <= 3) { emit("iload_" + slot); } else { emit("iload " + slot); } } @Override public void caseShortType(ShortType t) { if (slot >= 0 && slot <= 3) { emit("iload_" + slot); } else { emit("iload " + slot); } } @Override public void caseCharType(CharType t) { if (slot >= 0 && slot <= 3) { emit("iload_" + slot); } else { emit("iload " + slot); } } @Override public void caseBooleanType(BooleanType t) { if (slot >= 0 && slot <= 3) { emit("iload_" + slot); } else { emit("iload " + slot); } } @Override public void caseLongType(LongType t) { if (slot >= 0 && slot <= 3) { emit("lload_" + slot); } else { emit("lload " + slot); } } @Override public void caseRefType(RefType t) { if (slot >= 0 && slot <= 3) { emit("aload_" + slot); } else { emit("aload " + slot); } } @Override public void caseNullType(NullType t) { if (slot >= 0 && slot <= 3) { emit("aload_" + slot); } else { emit("aload " + slot); } } }); } @Override public void caseArrayWriteInst(ArrayWriteInst i) { i.getOpType().apply(new TypeSwitch<Object>() { @Override public void caseArrayType(ArrayType t) { emit("aastore"); } @Override public void caseDoubleType(DoubleType t) { emit("dastore"); } @Override public void caseFloatType(FloatType t) { emit("fastore"); } @Override public void caseIntType(IntType t) { emit("iastore"); } @Override public void caseLongType(LongType t) { emit("lastore"); } @Override public void caseRefType(RefType t) { emit("aastore"); } @Override public void caseByteType(ByteType t) { emit("bastore"); } @Override public void caseBooleanType(BooleanType t) { emit("bastore"); } @Override public void caseCharType(CharType t) { emit("castore"); } @Override public void caseShortType(ShortType t) { emit("sastore"); } @Override public void defaultCase(Type t) { throw new RuntimeException("Invalid type: " + t); } }); } @Override public void caseArrayReadInst(ArrayReadInst i) { i.getOpType().apply(new TypeSwitch<Object>() { @Override public void caseArrayType(ArrayType ty) { emit("aaload"); } @Override public void caseBooleanType(BooleanType ty) { emit("baload"); } @Override public void caseByteType(ByteType ty) { emit("baload"); } @Override public void caseCharType(CharType ty) { emit("caload"); } @Override public void defaultCase(Type ty) { throw new RuntimeException("invalid base type"); } @Override public void caseDoubleType(DoubleType ty) { emit("daload"); } @Override public void caseFloatType(FloatType ty) { emit("faload"); } @Override public void caseIntType(IntType ty) { emit("iaload"); } @Override public void caseLongType(LongType ty) { emit("laload"); } @Override public void caseNullType(NullType ty) { emit("aaload"); } @Override public void caseRefType(RefType ty) { emit("aaload"); } @Override public void caseShortType(ShortType ty) { emit("saload"); } }); } @Override public void caseIfNullInst(IfNullInst i) { emit("ifnull " + unitToLabel.get(i.getTarget())); } @Override public void caseIfNonNullInst(IfNonNullInst i) { emit("ifnonnull " + unitToLabel.get(i.getTarget())); } @Override public void caseIfEqInst(IfEqInst i) { emit("ifeq " + unitToLabel.get(i.getTarget())); } @Override public void caseIfNeInst(IfNeInst i) { emit("ifne " + unitToLabel.get(i.getTarget())); } @Override public void caseIfGtInst(IfGtInst i) { emit("ifgt " + unitToLabel.get(i.getTarget())); } @Override public void caseIfGeInst(IfGeInst i) { emit("ifge " + unitToLabel.get(i.getTarget())); } @Override public void caseIfLtInst(IfLtInst i) { emit("iflt " + unitToLabel.get(i.getTarget())); } @Override public void caseIfLeInst(IfLeInst i) { emit("ifle " + unitToLabel.get(i.getTarget())); } @Override public void caseIfCmpEqInst(final IfCmpEqInst i) { i.getOpType().apply(new TypeSwitch<Object>() { @Override public void caseIntType(IntType t) { emit("if_icmpeq " + unitToLabel.get(i.getTarget())); } @Override public void caseBooleanType(BooleanType t) { emit("if_icmpeq " + unitToLabel.get(i.getTarget())); } @Override public void caseShortType(ShortType t) { emit("if_icmpeq " + unitToLabel.get(i.getTarget())); } @Override public void caseCharType(CharType t) { emit("if_icmpeq " + unitToLabel.get(i.getTarget())); } @Override public void caseByteType(ByteType t) { emit("if_icmpeq " + unitToLabel.get(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { emit("dcmpg"); emit("ifeq " + unitToLabel.get(i.getTarget())); } @Override public void caseLongType(LongType t) { emit("lcmp"); emit("ifeq " + unitToLabel.get(i.getTarget())); } @Override public void caseFloatType(FloatType t) { emit("fcmpg"); emit("ifeq " + unitToLabel.get(i.getTarget())); } @Override public void caseArrayType(ArrayType t) { emit("if_acmpeq " + unitToLabel.get(i.getTarget())); } @Override public void caseRefType(RefType t) { emit("if_acmpeq " + unitToLabel.get(i.getTarget())); } @Override public void caseNullType(NullType t) { emit("if_acmpeq " + unitToLabel.get(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseIfCmpNeInst(final IfCmpNeInst i) { i.getOpType().apply(new TypeSwitch<Object>() { @Override public void caseIntType(IntType t) { emit("if_icmpne " + unitToLabel.get(i.getTarget())); } @Override public void caseBooleanType(BooleanType t) { emit("if_icmpne " + unitToLabel.get(i.getTarget())); } @Override public void caseShortType(ShortType t) { emit("if_icmpne " + unitToLabel.get(i.getTarget())); } @Override public void caseCharType(CharType t) { emit("if_icmpne " + unitToLabel.get(i.getTarget())); } @Override public void caseByteType(ByteType t) { emit("if_icmpne " + unitToLabel.get(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { emit("dcmpg"); emit("ifne " + unitToLabel.get(i.getTarget())); } @Override public void caseLongType(LongType t) { emit("lcmp"); emit("ifne " + unitToLabel.get(i.getTarget())); } @Override public void caseFloatType(FloatType t) { emit("fcmpg"); emit("ifne " + unitToLabel.get(i.getTarget())); } @Override public void caseArrayType(ArrayType t) { emit("if_acmpne " + unitToLabel.get(i.getTarget())); } @Override public void caseRefType(RefType t) { emit("if_acmpne " + unitToLabel.get(i.getTarget())); } @Override public void caseNullType(NullType t) { emit("if_acmpne " + unitToLabel.get(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseIfCmpGtInst(final IfCmpGtInst i) { i.getOpType().apply(new TypeSwitch<Object>() { @Override public void caseIntType(IntType t) { emit("if_icmpgt " + unitToLabel.get(i.getTarget())); } @Override public void caseBooleanType(BooleanType t) { emit("if_icmpgt " + unitToLabel.get(i.getTarget())); } @Override public void caseShortType(ShortType t) { emit("if_icmpgt " + unitToLabel.get(i.getTarget())); } @Override public void caseCharType(CharType t) { emit("if_icmpgt " + unitToLabel.get(i.getTarget())); } @Override public void caseByteType(ByteType t) { emit("if_icmpgt " + unitToLabel.get(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { emit("dcmpg"); emit("ifgt " + unitToLabel.get(i.getTarget())); } @Override public void caseLongType(LongType t) { emit("lcmp"); emit("ifgt " + unitToLabel.get(i.getTarget())); } @Override public void caseFloatType(FloatType t) { emit("fcmpg"); emit("ifgt " + unitToLabel.get(i.getTarget())); } @Override public void caseArrayType(ArrayType t) { emit("if_acmpgt " + unitToLabel.get(i.getTarget())); } @Override public void caseRefType(RefType t) { emit("if_acmpgt " + unitToLabel.get(i.getTarget())); } @Override public void caseNullType(NullType t) { emit("if_acmpgt " + unitToLabel.get(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseIfCmpGeInst(final IfCmpGeInst i) { i.getOpType().apply(new TypeSwitch<Object>() { @Override public void caseIntType(IntType t) { emit("if_icmpge " + unitToLabel.get(i.getTarget())); } @Override public void caseBooleanType(BooleanType t) { emit("if_icmpge " + unitToLabel.get(i.getTarget())); } @Override public void caseShortType(ShortType t) { emit("if_icmpge " + unitToLabel.get(i.getTarget())); } @Override public void caseCharType(CharType t) { emit("if_icmpge " + unitToLabel.get(i.getTarget())); } @Override public void caseByteType(ByteType t) { emit("if_icmpge " + unitToLabel.get(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { emit("dcmpg"); emit("ifge " + unitToLabel.get(i.getTarget())); } @Override public void caseLongType(LongType t) { emit("lcmp"); emit("ifge " + unitToLabel.get(i.getTarget())); } @Override public void caseFloatType(FloatType t) { emit("fcmpg"); emit("ifge " + unitToLabel.get(i.getTarget())); } @Override public void caseArrayType(ArrayType t) { emit("if_acmpge " + unitToLabel.get(i.getTarget())); } @Override public void caseRefType(RefType t) { emit("if_acmpge " + unitToLabel.get(i.getTarget())); } @Override public void caseNullType(NullType t) { emit("if_acmpge " + unitToLabel.get(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseIfCmpLtInst(final IfCmpLtInst i) { i.getOpType().apply(new TypeSwitch<Object>() { @Override public void caseIntType(IntType t) { emit("if_icmplt " + unitToLabel.get(i.getTarget())); } @Override public void caseBooleanType(BooleanType t) { emit("if_icmplt " + unitToLabel.get(i.getTarget())); } @Override public void caseShortType(ShortType t) { emit("if_icmplt " + unitToLabel.get(i.getTarget())); } @Override public void caseCharType(CharType t) { emit("if_icmplt " + unitToLabel.get(i.getTarget())); } @Override public void caseByteType(ByteType t) { emit("if_icmplt " + unitToLabel.get(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { emit("dcmpg"); emit("iflt " + unitToLabel.get(i.getTarget())); } @Override public void caseLongType(LongType t) { emit("lcmp"); emit("iflt " + unitToLabel.get(i.getTarget())); } @Override public void caseFloatType(FloatType t) { emit("fcmpg"); emit("iflt " + unitToLabel.get(i.getTarget())); } @Override public void caseArrayType(ArrayType t) { emit("if_acmplt " + unitToLabel.get(i.getTarget())); } @Override public void caseRefType(RefType t) { emit("if_acmplt " + unitToLabel.get(i.getTarget())); } @Override public void caseNullType(NullType t) { emit("if_acmplt " + unitToLabel.get(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseIfCmpLeInst(final IfCmpLeInst i) { i.getOpType().apply(new TypeSwitch<Object>() { @Override public void caseIntType(IntType t) { emit("if_icmple " + unitToLabel.get(i.getTarget())); } @Override public void caseBooleanType(BooleanType t) { emit("if_icmple " + unitToLabel.get(i.getTarget())); } @Override public void caseShortType(ShortType t) { emit("if_icmple " + unitToLabel.get(i.getTarget())); } @Override public void caseCharType(CharType t) { emit("if_icmple " + unitToLabel.get(i.getTarget())); } @Override public void caseByteType(ByteType t) { emit("if_icmple " + unitToLabel.get(i.getTarget())); } @Override public void caseDoubleType(DoubleType t) { emit("dcmpg"); emit("ifle " + unitToLabel.get(i.getTarget())); } @Override public void caseLongType(LongType t) { emit("lcmp"); emit("ifle " + unitToLabel.get(i.getTarget())); } @Override public void caseFloatType(FloatType t) { emit("fcmpg"); emit("ifle " + unitToLabel.get(i.getTarget())); } @Override public void caseArrayType(ArrayType t) { emit("if_acmple " + unitToLabel.get(i.getTarget())); } @Override public void caseRefType(RefType t) { emit("if_acmple " + unitToLabel.get(i.getTarget())); } @Override public void caseNullType(NullType t) { emit("if_acmple " + unitToLabel.get(i.getTarget())); } @Override public void defaultCase(Type t) { throw new RuntimeException("invalid type"); } }); } @Override public void caseStaticGetInst(StaticGetInst i) { SootFieldRef field = i.getFieldRef(); emit("getstatic " + slashify(field.declaringClass().getName()) + "/" + field.name() + " " + jasminDescriptorOf(field.type())); } @Override public void caseStaticPutInst(StaticPutInst i) { SootFieldRef field = i.getFieldRef(); emit("putstatic " + slashify(field.declaringClass().getName()) + "/" + field.name() + " " + jasminDescriptorOf(field.type())); } @Override public void caseFieldGetInst(FieldGetInst i) { SootFieldRef field = i.getFieldRef(); emit("getfield " + slashify(field.declaringClass().getName()) + "/" + field.name() + " " + jasminDescriptorOf(field.type())); } @Override public void caseFieldPutInst(FieldPutInst i) { SootFieldRef field = i.getFieldRef(); emit("putfield " + slashify(field.declaringClass().getName()) + "/" + field.name() + " " + jasminDescriptorOf(field.type())); } @Override public void caseInstanceCastInst(InstanceCastInst i) { Type castType = i.getCastType(); if (castType instanceof RefType) { emit("checkcast " + slashify(((RefType) castType).getClassName())); } else if (castType instanceof ArrayType) { emit("checkcast " + jasminDescriptorOf(castType)); } } @Override public void caseInstanceOfInst(InstanceOfInst i) { Type checkType = i.getCheckType(); if (checkType instanceof RefType) { emit("instanceof " + slashify(checkType.toString())); } else if (checkType instanceof ArrayType) { emit("instanceof " + jasminDescriptorOf(checkType)); } } @Override public void caseNewInst(NewInst i) { emit("new " + slashify(i.getBaseType().getClassName())); } @Override public void casePrimitiveCastInst(PrimitiveCastInst i) { emit(i.toString()); } @Override public void caseDynamicInvokeInst(DynamicInvokeInst i) { StringBuilder str = new StringBuilder(); SootMethodRef m = i.getMethodRef(); str.append("invokedynamic \"").append(m.name()).append("\" ").append(jasminDescriptorOf(m)).append(' '); SootMethodRef bsm = i.getBootstrapMethodRef(); str.append(slashify(bsm.declaringClass().getName())).append('/').append(bsm.name()).append(jasminDescriptorOf(bsm)); str.append('('); for (Iterator<Value> iterator = i.getBootstrapArgs().iterator(); iterator.hasNext();) { Value val = iterator.next(); str.append('(').append(jasminDescriptorOf(val.getType())).append(')'); str.append(escape(val.toString())); if (iterator.hasNext()) { str.append(','); } } str.append(')'); emit(str.toString()); } private String escape(String bsmArgString) { return bsmArgString.replace(",", "\\comma").replace(" ", "\\blank").replace("\t", "\\tab").replace("\n", "\\newline"); } @Override public void caseStaticInvokeInst(StaticInvokeInst i) { SootMethodRef m = i.getMethodRef(); emit("invokestatic " + slashify(m.declaringClass().getName()) + "/" + m.name() + jasminDescriptorOf(m)); } @Override public void caseVirtualInvokeInst(VirtualInvokeInst i) { SootMethodRef m = i.getMethodRef(); emit("invokevirtual " + slashify(m.declaringClass().getName()) + "/" + m.name() + jasminDescriptorOf(m)); } @Override public void caseInterfaceInvokeInst(InterfaceInvokeInst i) { SootMethodRef m = i.getMethodRef(); emit("invokeinterface " + slashify(m.declaringClass().getName()) + "/" + m.name() + jasminDescriptorOf(m) + " " + (argCountOf(m) + 1)); } @Override public void caseSpecialInvokeInst(SpecialInvokeInst i) { SootMethodRef m = i.getMethodRef(); emit("invokespecial " + slashify(m.declaringClass().getName()) + "/" + m.name() + jasminDescriptorOf(m)); } @Override public void caseThrowInst(ThrowInst i) { emit("athrow"); } @Override public void caseCmpInst(CmpInst i) { emit("lcmp"); } @Override public void caseCmplInst(CmplInst i) { if (i.getOpType().equals(FloatType.v())) { emit("fcmpl"); } else { emit("dcmpl"); } } @Override public void caseCmpgInst(CmpgInst i) { if (i.getOpType().equals(FloatType.v())) { emit("fcmpg"); } else { emit("dcmpg"); } } private void emitOpTypeInst(final String s, final OpTypeArgInst i) { i.getOpType().apply(new TypeSwitch<Object>() { private void handleIntCase() { emit("i" + s); } @Override public void caseIntType(IntType t) { handleIntCase(); } @Override public void caseBooleanType(BooleanType t) { handleIntCase(); } @Override public void caseShortType(ShortType t) { handleIntCase(); } @Override public void caseCharType(CharType t) { handleIntCase(); } @Override public void caseByteType(ByteType t) { handleIntCase(); } @Override public void caseLongType(LongType t) { emit("l" + s); } @Override public void caseDoubleType(DoubleType t) { emit("d" + s); } @Override public void caseFloatType(FloatType t) { emit("f" + s); } @Override public void defaultCase(Type t) { throw new RuntimeException("Invalid argument type for div"); } }); } @Override public void caseAddInst(AddInst i) { emitOpTypeInst("add", i); } @Override public void caseDivInst(DivInst i) { emitOpTypeInst("div", i); } @Override public void caseSubInst(SubInst i) { emitOpTypeInst("sub", i); } @Override public void caseMulInst(MulInst i) { emitOpTypeInst("mul", i); } @Override public void caseRemInst(RemInst i) { emitOpTypeInst("rem", i); } @Override public void caseShlInst(ShlInst i) { emitOpTypeInst("shl", i); } @Override public void caseAndInst(AndInst i) { emitOpTypeInst("and", i); } @Override public void caseOrInst(OrInst i) { emitOpTypeInst("or", i); } @Override public void caseXorInst(XorInst i) { emitOpTypeInst("xor", i); } @Override public void caseShrInst(ShrInst i) { emitOpTypeInst("shr", i); } @Override public void caseUshrInst(UshrInst i) { emitOpTypeInst("ushr", i); } @Override public void caseIncInst(IncInst i) { if (i.getUseBoxes().get(0).getValue() != i.getDefBoxes().get(0).getValue()) { throw new RuntimeException("iinc def and use boxes don't match"); } emit("iinc " + localToSlot.get(i.getLocal()) + " " + i.getConstant()); } @Override public void caseArrayLengthInst(ArrayLengthInst i) { emit("arraylength"); } @Override public void caseNegInst(NegInst i) { emitOpTypeInst("neg", i); } @Override public void caseNewArrayInst(NewArrayInst i) { if (i.getBaseType() instanceof RefType) { emit("anewarray " + slashify(((RefType) i.getBaseType()).getClassName())); } else if (i.getBaseType() instanceof ArrayType) { emit("anewarray " + jasminDescriptorOf(i.getBaseType())); } else { emit("newarray " + i.getBaseType().toString()); } } @Override public void caseNewMultiArrayInst(NewMultiArrayInst i) { emit("multianewarray " + jasminDescriptorOf(i.getBaseType()) + " " + i.getDimensionCount()); } @Override public void caseLookupSwitchInst(LookupSwitchInst i) { emit("lookupswitch"); List<Unit> targets = i.getTargets(); List<IntConstant> lookupValues = i.getLookupValues(); for (int j = 0; j < lookupValues.size(); j++) { emit(" " + lookupValues.get(j) + " : " + unitToLabel.get(targets.get(j))); } emit(" default : " + unitToLabel.get(i.getDefaultTarget())); } @Override public void caseTableSwitchInst(TableSwitchInst i) { emit("tableswitch " + i.getLowIndex() + " ; high = " + i.getHighIndex()); for (Unit t : i.getTargets()) { emit(" " + unitToLabel.get(t)); } emit("default : " + unitToLabel.get(i.getDefaultTarget())); } private boolean isDwordType(Type t) { return t instanceof LongType || t instanceof DoubleType || t instanceof DoubleWordType; } @Override public void caseDup1Inst(Dup1Inst i) { Type firstOpType = i.getOp1Type(); if (isDwordType(firstOpType)) { emit("dup2"); // (form 2) } else { emit("dup"); } } @Override public void caseDup2Inst(Dup2Inst i) { Type firstOpType = i.getOp1Type(); Type secondOpType = i.getOp2Type(); // The first two cases have no real bytecode equivalents. // Use a pair of insts to simulate them. if (isDwordType(firstOpType)) { emit("dup2"); // (form 2) if (isDwordType(secondOpType)) { emit("dup2"); // (form 2 -- by simulation) } else { emit("dup"); // also a simulation } } else if (isDwordType(secondOpType)) { if (isDwordType(firstOpType)) { emit("dup2"); // (form 2) } else { emit("dup"); } emit("dup2"); // (form 2 -- complete the simulation) } else { emit("dup2"); // form 1 } } @Override public void caseDup1_x1Inst(Dup1_x1Inst i) { Type opType = i.getOp1Type(); Type underType = i.getUnder1Type(); if (isDwordType(opType)) { if (isDwordType(underType)) { emit("dup2_x2"); // (form 4) } else { emit("dup2_x1"); // (form 2) } } else { if (isDwordType(underType)) { emit("dup_x2"); // (form 2) } else { emit("dup_x1"); // (only one form) } } } @Override public void caseDup1_x2Inst(Dup1_x2Inst i) { Type opType = i.getOp1Type(); Type under1Type = i.getUnder1Type(); Type under2Type = i.getUnder2Type(); // 07-20-2006 Michael Batchelder // NOW handling all types of dup1_x2 /* * From VM Spec: cat1 = category 1 (word type) cat2 = category 2 (doubleword) * * Form 1: [..., cat1_value3, cat1_value2, cat1_value1]->[..., cat1_value2, cat1_value1, cat1_value3, cat1_value2, * cat1_value1] Form 2: [..., cat1_value2, cat2_value1]->[..., cat2_value1, cat1_value2, cat2_value1] */ if (isDwordType(opType)) { if (!isDwordType(under1Type) && !isDwordType(under2Type)) { emit("dup2_x2"); // (form 2) } else { throw new RuntimeException("magic not implemented yet"); } } else { if (isDwordType(under1Type) || isDwordType(under2Type)) { throw new RuntimeException("magic not implemented yet"); } } emit("dup_x2"); // (form 1) } @Override public void caseDup2_x1Inst(Dup2_x1Inst i) { Type op1Type = i.getOp1Type(); Type op2Type = i.getOp2Type(); Type under1Type = i.getUnder1Type(); // 07-20-2006 Michael Batchelder // NOW handling all types of dup2_x1 /* * From VM Spec: cat1 = category 1 (word type) cat2 = category 2 (doubleword) * * Form 1: [..., cat1_value3, cat1_value2, cat1_value1]->[..., cat1_value2, cat1_value1, cat1_value3, cat1_value2, * cat1_value1] Form 2: [..., cat1_value2, cat2_value1]->[..., cat2_value1, cat1_value2, cat2_value1] */ if (isDwordType(under1Type)) { if (!isDwordType(op1Type) && !isDwordType(op2Type)) { throw new RuntimeException("magic not implemented yet"); } else { emit("dup2_x2"); // (form 3) } } else { if ((isDwordType(op1Type) && op2Type != null) || isDwordType(op2Type)) { throw new RuntimeException("magic not implemented yet"); } } emit("dup2_x1"); // (form 1) } @Override public void caseDup2_x2Inst(Dup2_x2Inst i) { Type op1Type = i.getOp1Type(); Type op2Type = i.getOp2Type(); Type under1Type = i.getUnder1Type(); Type under2Type = i.getUnder2Type(); // 07-20-2006 Michael Batchelder // NOW handling all types of dup2_x2 /* * From VM Spec: cat1 = category 1 (word type) cat2 = category 2 (doubleword) Form 1: [..., cat1_value4, cat1_value3, * cat1_value2, cat1_value1]->[..., cat1_value2, cat1_value1, cat1_value4, cat1_value3, cat1_value2, cat1_value1] * Form 2: [..., cat1_value3, cat1_value2, cat2_value1]->[ ..., cat2_value1, cat1_value3, cat1_value2, cat2_value1] * Form 3: [..., cat2_value3, cat1_value2, cat1_value1]->[..., cat1_value2, cat1_value1, cat2_value3, cat1_value2, * cat1_value1] Form 4: [..., cat2_value2, cat2_value1]->[..., cat2_value1, cat2_value2, cat2_value1] */ boolean malformed = true; if (isDwordType(op1Type)) { if (op2Type == null && under1Type != null) { if ((under2Type == null && isDwordType(under1Type)) || (!isDwordType(under1Type) && under2Type != null && !isDwordType(under2Type))) { malformed = false; } } } else if (op1Type != null && op2Type != null && !isDwordType(op2Type)) { if ((under2Type == null && isDwordType(under1Type)) || (under1Type != null && !isDwordType(under1Type) && under2Type != null && !isDwordType(under2Type))) { malformed = false; } } if (malformed) { throw new RuntimeException("magic not implemented yet"); } emit("dup2_x2"); // (form 1) } @Override public void caseSwapInst(SwapInst i) { emit("swap"); } }); } private void calculateStackHeight(Block aBlock) { int blockHeight = blockToStackHeight.get(aBlock); if (blockHeight > maxStackHeight) { maxStackHeight = blockHeight; } for (Unit u : aBlock) { Inst nInst = (Inst) u; blockHeight -= nInst.getInMachineCount(); if (blockHeight < 0) { throw new RuntimeException( "Negative Stack height has been attained in :" + aBlock.getBody().getMethod().getSignature() + " \n" + "StackHeight: " + blockHeight + "\n" + "At instruction:" + nInst + "\n" + "Block:\n" + aBlock + "\n\nMethod: " + aBlock.getBody().getMethod().getName() + "\n" + aBlock.getBody().getMethod()); } blockHeight += nInst.getOutMachineCount(); if (blockHeight > maxStackHeight) { maxStackHeight = blockHeight; } // logger.debug(">>> " + nInst + " " + blockHeight); } for (Block b : aBlock.getSuccs()) { Integer i = blockToStackHeight.get(b); if (i != null) { if (i != blockHeight) { throw new RuntimeException( aBlock.getBody().getMethod().getSignature() + ": incoherent stack height at block merge point " + b + aBlock + "\ncomputed blockHeight == " + blockHeight + " recorded blockHeight = " + i); } } else { blockToStackHeight.put(b, blockHeight); calculateStackHeight(b); } } } private void calculateLogicalStackHeightCheck(Block aBlock) { int blockHeight = blockToLogicalStackHeight.get(aBlock); for (Unit u : aBlock) { Inst nInst = (Inst) u; blockHeight -= nInst.getInCount(); if (blockHeight < 0) { throw new RuntimeException("Negative Stack Logical height has been attained: \n" + "StackHeight: " + blockHeight + "\nAt instruction:" + nInst + "\nBlock:\n" + aBlock + "\n\nMethod: " + aBlock.getBody().getMethod().getName() + "\n" + aBlock.getBody().getMethod()); } blockHeight += nInst.getOutCount(); // logger.debug(">>> " + nInst + " " + blockHeight); } for (Block b : aBlock.getSuccs()) { Integer i = blockToLogicalStackHeight.get(b); if (i != null) { if (i != blockHeight) { throw new RuntimeException("incoherent logical stack height at block merge point " + b + aBlock); } } else { blockToLogicalStackHeight.put(b, blockHeight); calculateLogicalStackHeightCheck(b); } } } }
54,140
28.456474
125
java
soot
soot-master/src/main/java/soot/baf/LoadInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Local; import soot.Type; public interface LoadInst extends Inst { public Type getOpType(); public void setOpType(Type opType); public Local getLocal(); public void setLocal(Local l); }
1,064
27.783784
73
java
soot
soot-master/src/main/java/soot/baf/LookupSwitchInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.List; import soot.jimple.IntConstant; public interface LookupSwitchInst extends SwitchInst { public void setLookupValue(int index, int value); public int getLookupValue(int index); public List<IntConstant> getLookupValues(); public void setLookupValues(List<IntConstant> values); }
1,168
28.974359
73
java
soot
soot-master/src/main/java/soot/baf/MethodArgInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.SootMethod; import soot.SootMethodRef; public interface MethodArgInst extends Inst { public SootMethodRef getMethodRef(); public SootMethod getMethod(); }
1,028
30.181818
73
java
soot
soot-master/src/main/java/soot/baf/MulInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface MulInst extends OpTypeArgInst { }
906
32.592593
73
java
soot
soot-master/src/main/java/soot/baf/NegInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface NegInst extends OpTypeArgInst { }
906
32.592593
73
java
soot
soot-master/src/main/java/soot/baf/NewArrayInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Type; public interface NewArrayInst extends Inst { public Type getBaseType(); public void setBaseType(Type type); }
989
29.9375
73
java
soot
soot-master/src/main/java/soot/baf/NewInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.RefType; public interface NewInst extends Inst { public RefType getBaseType(); public void setBaseType(RefType type); }
993
30.0625
73
java
soot
soot-master/src/main/java/soot/baf/NewMultiArrayInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.ArrayType; public interface NewMultiArrayInst extends Inst { public ArrayType getBaseType(); public void setBaseType(ArrayType type); public int getDimensionCount(); public void setDimensionCount(int count); }
1,089
29.277778
73
java
soot
soot-master/src/main/java/soot/baf/NoArgInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface NoArgInst extends Inst { }
899
32.333333
73
java
soot
soot-master/src/main/java/soot/baf/NopInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.NopUnit; public interface NopInst extends NopUnit, NoArgInst { }
932
32.321429
73
java
soot
soot-master/src/main/java/soot/baf/OpTypeArgInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Type; public interface OpTypeArgInst extends Inst { public Type getOpType(); public void setOpType(Type t); }
983
29.75
73
java
soot
soot-master/src/main/java/soot/baf/OrInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface OrInst extends OpTypeArgInst { }
905
32.555556
73
java
soot
soot-master/src/main/java/soot/baf/PlaceholderInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Unit; import soot.baf.internal.AbstractInst; public class PlaceholderInst extends AbstractInst { private final Unit source; PlaceholderInst(Unit source) { this.source = source; } @Override public Object clone() { return new PlaceholderInst(getSource()); } public Unit getSource() { return source; } @Override public final String getName() { return "<placeholder>"; } @Override public String toString() { return "<placeholder: " + source.toString() + ">"; } }
1,381
24.127273
73
java
soot
soot-master/src/main/java/soot/baf/PopInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface PopInst extends Inst { public int getWordCount(); public void setWordCount(int count); }
966
31.233333
73
java
soot
soot-master/src/main/java/soot/baf/PrimitiveCastInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.Type; public interface PrimitiveCastInst extends Inst { public Type getFromType(); public void setFromType(Type t); public Type getToType(); public void setToType(Type t); }
1,053
28.277778
73
java
soot
soot-master/src/main/java/soot/baf/PushInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import soot.jimple.Constant; public interface PushInst extends Inst { public Constant getConstant(); public void setConstant(Constant c); }
1,001
30.3125
73
java
soot
soot-master/src/main/java/soot/baf/RemInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface RemInst extends OpTypeArgInst { }
906
32.592593
73
java
soot
soot-master/src/main/java/soot/baf/RetInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface RetInst extends Inst { public int getIndex(); public void setIndex(int index); }
958
30.966667
73
java
soot
soot-master/src/main/java/soot/baf/ReturnInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface ReturnInst extends OpTypeArgInst { }
909
32.703704
73
java
soot
soot-master/src/main/java/soot/baf/ReturnVoidInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface ReturnVoidInst extends NoArgInst { }
909
32.703704
73
java
soot
soot-master/src/main/java/soot/baf/ShlInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface ShlInst extends OpTypeArgInst { }
906
32.592593
73
java
soot
soot-master/src/main/java/soot/baf/ShrInst.java
package soot.baf; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface ShrInst extends OpTypeArgInst { }
906
32.592593
73
java