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/dexpler/instructions/ConstClassInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.HashSet; import java.util.Set; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OneRegisterInstruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.instruction.formats.Instruction21c; import org.jf.dexlib2.iface.reference.TypeReference; import soot.Type; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.ClassConstant; import soot.jimple.Constant; import soot.jimple.Jimple; public class ConstClassInstruction extends DexlibAbstractInstruction { public ConstClassInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { if (!(instruction instanceof Instruction21c)) { throw new IllegalArgumentException("Expected Instruction21c but got: " + instruction.getClass()); } ReferenceInstruction constClass = (ReferenceInstruction) this.instruction; TypeReference tidi = (TypeReference) (constClass.getReference()); Constant cst = ClassConstant.v(tidi.getType()); int dest = ((OneRegisterInstruction) instruction).getRegisterA(); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cst); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { // DalvikTyper.v().captureAssign((JAssignStmt)assign, op); //TODO: // classtype could be null! DalvikTyper.v().setType(assign.getLeftOpBox(), cst.getType(), false); } } @Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } @Override public Set<Type> introducedTypes() { ReferenceInstruction i = (ReferenceInstruction) instruction; Set<Type> types = new HashSet<Type>(); types.add(DexType.toSoot((TypeReference) i.getReference())); return types; } }
3,124
31.894737
103
java
soot
soot-master/src/main/java/soot/dexpler/instructions/ConstInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.Opcode; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction; import org.jf.dexlib2.iface.instruction.OneRegisterInstruction; import org.jf.dexlib2.iface.instruction.WideLiteralInstruction; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.dexpler.typing.UntypedConstant; import soot.dexpler.typing.UntypedIntOrFloatConstant; import soot.dexpler.typing.UntypedLongOrDoubleConstant; import soot.jimple.AssignStmt; import soot.jimple.Constant; import soot.jimple.IntConstant; import soot.jimple.Jimple; import soot.jimple.LongConstant; public class ConstInstruction extends DexlibAbstractInstruction { public ConstInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { int dest = ((OneRegisterInstruction) instruction).getRegisterA(); Constant cst = getConstant(dest, body); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cst); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { if (cst instanceof UntypedConstant) { DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox()); } else { DalvikTyper.v().setType(assign.getLeftOpBox(), cst.getType(), false); } } } /** * Return the literal constant for this instruction. * * @param register * the register number to fill * @param body * the body containing the instruction */ private Constant getConstant(int dest, DexBody body) { long literal = 0; if (instruction instanceof WideLiteralInstruction) { literal = ((WideLiteralInstruction) instruction).getWideLiteral(); } else if (instruction instanceof NarrowLiteralInstruction) { literal = ((NarrowLiteralInstruction) instruction).getNarrowLiteral(); } else { throw new RuntimeException("literal error: expected narrow or wide literal."); } // floats are handled later in DexBody by calling DexNumtransformer Opcode opcode = instruction.getOpcode(); switch (opcode) { case CONST: case CONST_4: case CONST_16: if (IDalvikTyper.ENABLE_DVKTYPER) { return UntypedIntOrFloatConstant.v((int) literal); } else { return IntConstant.v((int) literal); } case CONST_HIGH16: if (IDalvikTyper.ENABLE_DVKTYPER) { // // return UntypedIntOrFloatConstant.v((int)literal<<16).toFloatConstant(); // seems that dexlib correctly puts the 16bits into the topmost bits. // return UntypedIntOrFloatConstant.v((int) literal);// .toFloatConstant(); } else { return IntConstant.v((int) literal); } case CONST_WIDE_HIGH16: if (IDalvikTyper.ENABLE_DVKTYPER) { // return UntypedLongOrDoubleConstant.v((long)literal<<48).toDoubleConstant(); // seems that dexlib correctly puts the 16bits into the topmost bits. // return UntypedLongOrDoubleConstant.v(literal);// .toDoubleConstant(); } else { return LongConstant.v(literal); } case CONST_WIDE: case CONST_WIDE_16: case CONST_WIDE_32: if (IDalvikTyper.ENABLE_DVKTYPER) { return UntypedLongOrDoubleConstant.v(literal); } else { return LongConstant.v(literal); } default: throw new IllegalArgumentException("Expected a const or a const-wide instruction, got neither."); } } @Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
4,905
32.60274
105
java
soot
soot-master/src/main/java/soot/dexpler/instructions/ConstStringInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OneRegisterInstruction; import org.jf.dexlib2.iface.instruction.formats.Instruction21c; import org.jf.dexlib2.iface.instruction.formats.Instruction31c; import org.jf.dexlib2.iface.reference.StringReference; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.Jimple; import soot.jimple.StringConstant; public class ConstStringInstruction extends DexlibAbstractInstruction { public ConstStringInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { int dest = ((OneRegisterInstruction) instruction).getRegisterA(); String s; if (instruction instanceof Instruction21c) { Instruction21c i = (Instruction21c) instruction; s = ((StringReference) (i.getReference())).getString(); } else if (instruction instanceof Instruction31c) { Instruction31c i = (Instruction31c) instruction; s = ((StringReference) (i.getReference())).getString(); } else { throw new IllegalArgumentException("Expected Instruction21c or Instruction31c but got neither."); } StringConstant sc = StringConstant.v(s); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), sc); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().setType(assign.getLeftOpBox(), sc.getType(), false); } } @Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
2,806
34.0875
103
java
soot
soot-master/src/main/java/soot/dexpler/instructions/DanglingInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.dexpler.DexBody; /** * Interface for instructions which behavior depends on the succeeding instruction. * * @author Michael Markert <michael.markert@googlemail.com> */ public interface DanglingInstruction { /** * Finalize this instruction taking the successor into consideration. * * @param body * to finalize into * @param successor * the direct successor of this instruction */ public void finalize(DexBody body, DexlibAbstractInstruction successor); }
1,525
30.791667
83
java
soot
soot-master/src/main/java/soot/dexpler/instructions/DeferableInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.dexpler.DexBody; /** * Interface for instructions that can/must be defered, i.e. executed after the rest of the DexBody has been converted to * Jimple * * @author Michael Markert <michael.markert@googlemail.com> */ public interface DeferableInstruction { /** * Jimplify this instruction with the guarantee that every other (non-deferred) instruction has been jimplified. * * @param body * to jimplify into */ public void deferredJimplify(DexBody body); }
1,510
30.479167
121
java
soot
soot-master/src/main/java/soot/dexpler/instructions/DexlibAbstractInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.Collections; import java.util.List; import java.util.Set; import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.RegisterRangeInstruction; import soot.Type; import soot.Unit; import soot.dexpler.DexBody; import soot.options.Options; import soot.tagkit.BytecodeOffsetTag; import soot.tagkit.Host; import soot.tagkit.LineNumberTag; import soot.tagkit.SourceLineNumberTag; /** * This class represents a wrapper around dexlib instruction. * */ public abstract class DexlibAbstractInstruction { protected int lineNumber = -1; protected final Instruction instruction; protected final int codeAddress; // protected Unit beginUnit; // protected Unit endUnit; protected Unit unit; public Instruction getInstruction() { return instruction; } /** * Jimplify this instruction. * * @param body * to jimplify into. */ public abstract void jimplify(DexBody body); /** * Return the target register that is a copy of the given register. For instruction such as v0 = v3 (v0 gets the content of * v3), movesRegister(3) returns 0 movesRegister(0) returns -1 * * Instructions should override this if they copy register content. * * @param register * the number of the register * @return the new register number or -1 if it does not move. */ int movesRegister(int register) { return -1; } /** * Return the source register that is moved to the given register. For instruction such as v0 = v3 (v0 gets the content of * v3), movesToRegister(3) returns -1 movesToRegister(0) returns 3 * * Instructions should override this if they copy register content. * * @param register * the number of the register * @return the source register number or -1 if it does not move. */ int movesToRegister(int register) { return -1; } /** * Return if the instruction overrides the value in the register. * * Instructions should override this if they modify the registers. * * @param register * the number of the register */ boolean overridesRegister(int register) { return false; } /** * Return if the value in the register is used as a floating point. * * Instructions that have this context information and may deal with integers or floating points should override this. * * @param register * the number of the register * @param body * the body containing the instruction */ boolean isUsedAsFloatingPoint(DexBody body, int register) { return false; } /** * Return the types that are be introduced by this instruction. * * Instructions that may introduce types should override this. */ public Set<Type> introducedTypes() { return Collections.emptySet(); } /** * @param instruction * the underlying dexlib instruction * @param codeAddress * the bytecode address of this instruction */ public DexlibAbstractInstruction(Instruction instruction, int codeAddress) { this.instruction = instruction; this.codeAddress = codeAddress; } public int getLineNumber() { return lineNumber; } public void setLineNumber(int lineNumber) { this.lineNumber = lineNumber; } /** * Tag the passed host with: - this instructions line number (if one is set) - the original bytecode offset * * @param host * the host to tag */ protected void addTags(Host host) { Options options = Options.v(); if (options.keep_line_number() && lineNumber != -1) { host.addTag(new LineNumberTag(lineNumber)); host.addTag(new SourceLineNumberTag(lineNumber)); } if (options.keep_offset()) { host.addTag(new BytecodeOffsetTag(codeAddress)); } } // /** // * Return the first of the jimple units that represent this instruction. // * // */ // public Unit getBeginUnit() { // return beginUnit; // } // // /** // * Return the last of the jimple units that represent this instruction. // * // */ // public Unit getEndUnit() { // return endUnit; // } public Unit getUnit() { return unit; } /** * Set the Jimple Unit, that comprises this instruction. * * Does not override already set units. */ protected void setUnit(Unit u) { unit = u; // defineBlock(stmt, stmt); } // /** // * Set the first and last Jimple Unit, that comprise this instruction. // * // * Does not override already set units. // */ // protected void defineBlock(Unit begin, Unit end) { // if (beginUnit == null) // beginUnit = begin; // if (endUnit == null) // endUnit = end; // } // FT // All uses for the array have been commented out. // Calling all v()s for all types make no sense if we do not use them /* * protected Type [] opUnType = { IntType.v(), // 0x7B neg-int vx, vy IntType.v(), // 0x7C LongType.v(), // 0x7D * LongType.v(), // 0x7E FloatType.v(), // 0x7F DoubleType.v(), // 0x80 IntType.v(), IntType.v(), IntType.v(), * LongType.v(), LongType.v(), LongType.v(), FloatType.v(), FloatType.v(), FloatType.v(), DoubleType.v(), DoubleType.v(), * DoubleType.v(), IntType.v(), IntType.v(), IntType.v() // 0x8F int-to-short vx, vy }; * * protected Type [] resUnType = { IntType.v(), // 0x7B IntType.v(), LongType.v(), LongType.v(), FloatType.v(), * DoubleType.v(), LongType.v(), FloatType.v(), DoubleType.v(), IntType.v(), FloatType.v(), DoubleType.v(), IntType.v(), * LongType.v(), DoubleType.v(), IntType.v(), LongType.v(), FloatType.v(), IntType.v(), IntType.v(), IntType.v() // 0x8F }; * * protected Type [] resBinType = { IntType.v(), IntType.v(), IntType.v(), IntType.v(), IntType.v(), IntType.v(), * IntType.v(), IntType.v(), IntType.v(), IntType.v(), IntType.v(), LongType.v(), LongType.v(), LongType.v(), LongType.v(), * LongType.v(), LongType.v(), LongType.v(), LongType.v(), LongType.v(), LongType.v(), LongType.v(), FloatType.v(), * FloatType.v(), FloatType.v(), FloatType.v(), FloatType.v(), DoubleType.v(), DoubleType.v(), DoubleType.v(), * DoubleType.v(), DoubleType.v() }; * * protected Type [] op1BinType = { IntType.v(), IntType.v(), IntType.v(), IntType.v(), IntType.v(), IntType.v(), * IntType.v(), IntType.v(), IntType.v(), IntType.v(), IntType.v(), LongType.v(), LongType.v(), LongType.v(), LongType.v(), * LongType.v(), LongType.v(), LongType.v(), LongType.v(), LongType.v(), LongType.v(), LongType.v(), FloatType.v(), * FloatType.v(), FloatType.v(), FloatType.v(), FloatType.v(), DoubleType.v(), DoubleType.v(), DoubleType.v(), * DoubleType.v(), DoubleType.v() }; * * protected Type [] op2BinType = { IntType.v(), IntType.v(), IntType.v(), IntType.v(), IntType.v(), IntType.v(), * IntType.v(), IntType.v(), IntType.v(), IntType.v(), IntType.v(), LongType.v(), LongType.v(), LongType.v(), LongType.v(), * LongType.v(), LongType.v(), LongType.v(), LongType.v(), IntType.v(), IntType.v(), IntType.v(), FloatType.v(), * FloatType.v(), FloatType.v(), FloatType.v(), FloatType.v(), DoubleType.v(), DoubleType.v(), DoubleType.v(), * DoubleType.v(), DoubleType.v() }; */ // public abstract void getConstraint(IDalvikTyper DalvikTyper.v()); /** * Return the indices used in the given instruction. * * @param instruction * a range invocation instruction * @return a list of register indices */ protected List<Integer> getUsedRegistersNums(RegisterRangeInstruction instruction) { List<Integer> regs = new ArrayList<Integer>(); int start = instruction.getStartRegister(); for (int i = start; i < start + instruction.getRegisterCount(); i++) { regs.add(i); } return regs; } /** * Return the indices used in the given instruction. * * @param instruction * a invocation instruction * @return a list of register indices */ protected List<Integer> getUsedRegistersNums(FiveRegisterInstruction instruction) { final int regCount = instruction.getRegisterCount(); int[] regs = { instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), }; List<Integer> l = new ArrayList<Integer>(); // We have at least one app with regCount=6, reg=35c. // App is "com.mobirix.gk2019.apk" from 2020 PlayStore data set for (int i = 0; i < Math.min(regCount, regs.length); i++) { l.add(regs[i]); } return l; } }
9,650
32.744755
125
java
soot
soot-master/src/main/java/soot/dexpler/instructions/ExecuteInlineInstruction.java
package soot.dexpler.instructions; /*- * #%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.List; import org.jf.dexlib2.AccessFlags; import org.jf.dexlib2.analysis.AnalyzedInstruction; import org.jf.dexlib2.analysis.ClassPath; import org.jf.dexlib2.analysis.InlineMethodResolver; import org.jf.dexlib2.analysis.MethodAnalyzer; import org.jf.dexlib2.dexbacked.DexBackedOdexFile; import org.jf.dexlib2.iface.DexFile; import org.jf.dexlib2.iface.Method; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.formats.Instruction35mi; import org.jf.dexlib2.iface.instruction.formats.Instruction3rmi; import soot.dexpler.DexBody; public class ExecuteInlineInstruction extends MethodInvocationInstruction implements OdexInstruction { private Method targetMethod = null; public ExecuteInlineInstruction(Instruction instruction, int codeAddress) { super(instruction, codeAddress); } @Override public void deOdex(DexFile parentFile, Method method, ClassPath cp) { if (!(parentFile instanceof DexBackedOdexFile)) { throw new RuntimeException("ODEX instruction in non-ODEX file"); } DexBackedOdexFile odexFile = (DexBackedOdexFile) parentFile; InlineMethodResolver inlineMethodResolver = InlineMethodResolver.createInlineMethodResolver(odexFile.getOdexVersion()); MethodAnalyzer analyzer = new MethodAnalyzer(cp, method, inlineMethodResolver, false); targetMethod = inlineMethodResolver.resolveExecuteInline(new AnalyzedInstruction(analyzer, instruction, -1, -1)); } @Override public void jimplify(DexBody body) { int acccessFlags = targetMethod.getAccessFlags(); if (AccessFlags.STATIC.isSet(acccessFlags)) { jimplifyStatic(body); } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) { jimplifySpecial(body); } else { jimplifyVirtual(body); } } /** * Return the indices used in this instruction. * * @return a list of register indices */ protected List<Integer> getUsedRegistersNums() { if (instruction instanceof Instruction35mi) { return getUsedRegistersNums((Instruction35mi) instruction); } else if (instruction instanceof Instruction3rmi) { return getUsedRegistersNums((Instruction3rmi) instruction); } throw new RuntimeException("Instruction is not an ExecuteInline"); } }
3,130
34.988506
123
java
soot
soot-master/src/main/java/soot/dexpler/instructions/FieldInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.dexpler.Util.dottedClassName; import static soot.dexpler.Util.isFloatLike; import java.util.HashSet; import java.util.Set; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.instruction.formats.Instruction21c; import org.jf.dexlib2.iface.instruction.formats.Instruction22c; import org.jf.dexlib2.iface.instruction.formats.Instruction23x; import org.jf.dexlib2.iface.reference.FieldReference; import soot.Local; import soot.Scene; import soot.SootClass; import soot.SootFieldRef; import soot.SootResolver; import soot.Type; import soot.UnknownType; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.jimple.AssignStmt; import soot.jimple.ConcreteRef; import soot.jimple.Jimple; public abstract class FieldInstruction extends DexlibAbstractInstruction { public FieldInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } /** * Return a static SootFieldRef for a dexlib FieldReference. * * @param item * the dexlib FieldReference. */ protected SootFieldRef getStaticSootFieldRef(FieldReference fref) { return getSootFieldRef(fref, true); } /** * Return a SootFieldRef for a dexlib FieldReference. * * @param item * the dexlib FieldReference. */ protected SootFieldRef getSootFieldRef(FieldReference fref) { return getSootFieldRef(fref, false); } /** * Return a SootFieldRef for a dexlib FieldReference. * * @param item * the dexlib FieldReference. * @param isStatic * if the FieldRef should be static */ private SootFieldRef getSootFieldRef(FieldReference fref, boolean isStatic) { String className = dottedClassName(fref.getDefiningClass()); SootClass sc = SootResolver.v().makeClassRef(className); return Scene.v().makeFieldRef(sc, fref.getName(), DexType.toSoot(fref.getType()), isStatic); } /** * Check if the field type equals the type of the value that will be stored in the field. A cast expression has to be * introduced for the unequal case. * * @return assignment statement which hold a cast or not depending on the types of the operation */ protected AssignStmt getAssignStmt(DexBody body, Local sourceValue, ConcreteRef instanceField) { AssignStmt assign; // Type targetType = getTargetType(body); // if(targetType != UnknownType.v() && targetType != sourceValue.getType() && ! (targetType instanceof RefType)) { // CastExpr castExpr = Jimple.v().newCastExpr(sourceValue, targetType); // Local local = body.generateLocal(targetType); // assign = Jimple.v().newAssignStmt(local, castExpr); // body.add(assign); // beginUnit = assign; // assign = Jimple.v().newAssignStmt(instanceField, local); // } // else { assign = Jimple.v().newAssignStmt(instanceField, sourceValue); // } return assign; } @Override boolean isUsedAsFloatingPoint(DexBody body, int register) { return sourceRegister() == register && isFloatLike(getTargetType(body)); } /** * Return the source register for this instruction. */ private int sourceRegister() { // I hate smali's API .. if (instruction instanceof Instruction23x) { return ((Instruction23x) instruction).getRegisterA(); } else if (instruction instanceof Instruction22c) { return ((Instruction22c) instruction).getRegisterA(); } else if (instruction instanceof Instruction21c) { return ((Instruction21c) instruction).getRegisterA(); } else { throw new RuntimeException("Instruction is not a instance, array or static op"); } } /** * Return the target type for put instructions. * * Putters should override this. * * @param body * the body containing this instruction */ protected Type getTargetType(DexBody body) { return UnknownType.v(); } @Override public Set<Type> introducedTypes() { Set<Type> types = new HashSet<Type>(); // Aput instructions don't have references if (!(instruction instanceof ReferenceInstruction)) { return types; } ReferenceInstruction i = (ReferenceInstruction) instruction; FieldReference field = (FieldReference) i.getReference(); types.add(DexType.toSoot(field.getType())); types.add(DexType.toSoot(field.getDefiningClass())); return types; } }
5,469
31.366864
119
java
soot
soot-master/src/main/java/soot/dexpler/instructions/FillArrayDataInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.HashSet; import java.util.List; import java.util.Set; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.formats.ArrayPayload; import org.jf.dexlib2.iface.instruction.formats.Instruction22c; import org.jf.dexlib2.iface.instruction.formats.Instruction31t; import org.jf.dexlib2.iface.reference.TypeReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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.ShortType; import soot.Type; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.jimple.ArrayRef; import soot.jimple.AssignStmt; import soot.jimple.DoubleConstant; import soot.jimple.FloatConstant; import soot.jimple.IntConstant; import soot.jimple.Jimple; import soot.jimple.LongConstant; import soot.jimple.NumericConstant; import soot.jimple.Stmt; public class FillArrayDataInstruction extends PseudoInstruction { private static final Logger logger = LoggerFactory.getLogger(FillArrayDataInstruction.class); public FillArrayDataInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { if (!(instruction instanceof Instruction31t)) { throw new IllegalArgumentException("Expected Instruction31t but got: " + instruction.getClass()); } Instruction31t fillArrayInstr = (Instruction31t) instruction; int destRegister = fillArrayInstr.getRegisterA(); int offset = fillArrayInstr.getCodeOffset(); int targetAddress = codeAddress + offset; Instruction referenceTable = body.instructionAtAddress(targetAddress).instruction; if (!(referenceTable instanceof ArrayPayload)) { throw new RuntimeException("Address " + targetAddress + "refers to an invalid PseudoInstruction."); } ArrayPayload arrayTable = (ArrayPayload) referenceTable; // NopStmt nopStmtBeginning = Jimple.v().newNopStmt(); // body.add(nopStmtBeginning); Local arrayReference = body.getRegisterLocal(destRegister); List<Number> elements = arrayTable.getArrayElements(); int numElements = elements.size(); Stmt firstAssign = null; for (int i = 0; i < numElements; i++) { ArrayRef arrayRef = Jimple.v().newArrayRef(arrayReference, IntConstant.v(i)); NumericConstant element = getArrayElement(elements.get(i), body, destRegister); if (element == null) { break; } AssignStmt assign = Jimple.v().newAssignStmt(arrayRef, element); addTags(assign); body.add(assign); if (i == 0) { firstAssign = assign; } } if (firstAssign == null) { // if numElements == 0. Is it possible? firstAssign = Jimple.v().newNopStmt(); body.add(firstAssign); } // NopStmt nopStmtEnd = Jimple.v().newNopStmt(); // body.add(nopStmtEnd); // defineBlock(nopStmtBeginning, nopStmtEnd); setUnit(firstAssign); } private NumericConstant getArrayElement(Number element, DexBody body, int arrayRegister) { List<DexlibAbstractInstruction> instructions = body.instructionsBefore(this); Set<Integer> usedRegisters = new HashSet<Integer>(); usedRegisters.add(arrayRegister); Type elementType = null; Outer: for (DexlibAbstractInstruction i : instructions) { if (usedRegisters.isEmpty()) { break; } for (int reg : usedRegisters) { if (i instanceof NewArrayInstruction) { NewArrayInstruction newArrayInstruction = (NewArrayInstruction) i; Instruction22c instruction22c = (Instruction22c) newArrayInstruction.instruction; if (instruction22c.getRegisterA() == reg) { ArrayType arrayType = (ArrayType) DexType.toSoot((TypeReference) instruction22c.getReference()); elementType = arrayType.getElementType(); break Outer; } } } // // look for obsolete registers // for (int reg : usedRegisters) { // if (i.overridesRegister(reg)) { // usedRegisters.remove(reg); // break; // there can't be more than one obsolete // } // } // look for new registers for (int reg : usedRegisters) { int newRegister = i.movesToRegister(reg); if (newRegister != -1) { usedRegisters.add(newRegister); usedRegisters.remove(reg); break; // there can't be more than one new } } } if (elementType == null) { // throw new InternalError("Unable to find array type to type array elements!"); logger.warn("Unable to find array type to type array elements! Array was not defined! (obfuscated bytecode?)"); return null; } NumericConstant value; if (elementType instanceof BooleanType) { value = IntConstant.v(element.intValue()); IntConstant ic = (IntConstant) value; if (ic.value != 0) { value = IntConstant.v(1); } } else if (elementType instanceof ByteType) { value = IntConstant.v(element.byteValue()); } else if (elementType instanceof CharType || elementType instanceof ShortType) { value = IntConstant.v(element.shortValue()); } else if (elementType instanceof DoubleType) { value = DoubleConstant.v(Double.longBitsToDouble(element.longValue())); } else if (elementType instanceof FloatType) { value = FloatConstant.v(Float.intBitsToFloat(element.intValue())); } else if (elementType instanceof IntType) { value = IntConstant.v(element.intValue()); } else if (elementType instanceof LongType) { value = LongConstant.v(element.longValue()); } else { throw new RuntimeException("Invalid Array Type occured in FillArrayDataInstruction: " + elementType); } return value; } @Override public void computeDataOffsets(DexBody body) { if (!(instruction instanceof Instruction31t)) { throw new IllegalArgumentException("Expected Instruction31t but got: " + instruction.getClass()); } Instruction31t fillArrayInstr = (Instruction31t) instruction; int offset = fillArrayInstr.getCodeOffset(); int targetAddress = codeAddress + offset; Instruction referenceTable = body.instructionAtAddress(targetAddress).instruction; if (!(referenceTable instanceof ArrayPayload)) { throw new RuntimeException("Address 0x" + Integer.toHexString(targetAddress) + " refers to an invalid PseudoInstruction (" + referenceTable.getClass() + ")."); } ArrayPayload arrayTable = (ArrayPayload) referenceTable; int numElements = arrayTable.getArrayElements().size(); int widthElement = arrayTable.getElementWidth(); int size = (widthElement * numElements) / 2; // addresses are on 16bits // From org.jf.dexlib.Code.Format.ArrayDataPseudoInstruction we learn // that there are 6 bytes after the magic number that we have to jump. // 6 bytes to jump = address + 3 // // out.writeByte(0x00); // magic // out.writeByte(0x03); // number // out.writeShort(elementWidth); // 2 bytes // out.writeInt(elementCount); // 4 bytes // out.write(encodedValues); // setDataFirstByte(targetAddress + 3); // address for 16 bits elements not 8 bits setDataLastByte(targetAddress + 3 + size);// - 1); setDataSize(size); // TODO: how to handle this with dexlib2 ? // ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(); // arrayTable.write(out, targetAddress); // // byte[] outa = out.getArray(); // byte[] data = new byte[outa.length-6]; // for (int i=6; i<outa.length; i++) { // data[i-6] = outa[i]; // } // setData (data); } }
8,824
34.159363
117
java
soot
soot-master/src/main/java/soot/dexpler/instructions/FilledArrayInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.HashSet; import java.util.Set; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.reference.TypeReference; import soot.Type; import soot.dexpler.DexBody; import soot.dexpler.DexType; public abstract class FilledArrayInstruction extends DexlibAbstractInstruction implements DanglingInstruction { public FilledArrayInstruction(Instruction instruction, int codeAddress) { super(instruction, codeAddress); } public void finalize(DexBody body, DexlibAbstractInstruction successor) { // // defer final jimplification to move result // if (successor instanceof MoveResultInstruction) { // MoveResultInstruction i = (MoveResultInstruction)successor; // i.setLocalToMove(arrayLocal); // if (lineNumber != -1) // i.setTag(new SourceLineNumberTag(lineNumber)); // } } @Override public Set<Type> introducedTypes() { ReferenceInstruction i = (ReferenceInstruction) instruction; Set<Type> types = new HashSet<Type>(); types.add(DexType.toSoot((TypeReference) i.getReference())); return types; } }
2,170
31.402985
111
java
soot
soot-master/src/main/java/soot/dexpler/instructions/FilledNewArrayInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.dexpler.Util.isFloatLike; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.formats.Instruction35c; import org.jf.dexlib2.iface.reference.TypeReference; import soot.ArrayType; import soot.Local; import soot.Type; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.ArrayRef; import soot.jimple.AssignStmt; import soot.jimple.IntConstant; import soot.jimple.Jimple; import soot.jimple.NewArrayExpr; public class FilledNewArrayInstruction extends FilledArrayInstruction { public FilledNewArrayInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { if (!(instruction instanceof Instruction35c)) { throw new IllegalArgumentException("Expected Instruction35c but got: " + instruction.getClass()); } Instruction35c filledNewArrayInstr = (Instruction35c) instruction; int[] regs = { filledNewArrayInstr.getRegisterC(), filledNewArrayInstr.getRegisterD(), filledNewArrayInstr.getRegisterE(), filledNewArrayInstr.getRegisterF(), filledNewArrayInstr.getRegisterG(), }; // NopStmt nopStmtBeginning = Jimple.v().newNopStmt(); // body.add(nopStmtBeginning); int usedRegister = filledNewArrayInstr.getRegisterCount(); Type t = DexType.toSoot((TypeReference) filledNewArrayInstr.getReference()); // NewArrayExpr needs the ElementType as it increases the array dimension by 1 Type arrayType = ((ArrayType) t).getElementType(); NewArrayExpr arrayExpr = Jimple.v().newNewArrayExpr(arrayType, IntConstant.v(usedRegister)); // new local generated intentional, will be moved to real register by MoveResult Local arrayLocal = body.getStoreResultLocal(); AssignStmt assign = Jimple.v().newAssignStmt(arrayLocal, arrayExpr); body.add(assign); for (int i = 0; i < usedRegister; i++) { ArrayRef arrayRef = Jimple.v().newArrayRef(arrayLocal, IntConstant.v(i)); AssignStmt assign2 = Jimple.v().newAssignStmt(arrayRef, body.getRegisterLocal(regs[i])); addTags(assign2); body.add(assign2); } // NopStmt nopStmtEnd = Jimple.v().newNopStmt(); // body.add(nopStmtEnd); // defineBlock(nopStmtBeginning, nopStmtEnd); setUnit(assign); // body.setDanglingInstruction(this); if (IDalvikTyper.ENABLE_DVKTYPER) { // Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign); DalvikTyper.v().setType(assign.getLeftOpBox(), arrayExpr.getType(), false); // DalvikTyper.v().setType(array, arrayType, isUse) // DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox()); } } @Override boolean isUsedAsFloatingPoint(DexBody body, int register) { Instruction35c i = (Instruction35c) instruction; Type arrayType = DexType.toSoot((TypeReference) i.getReference()); return isRegisterUsed(register) && isFloatLike(arrayType); } /** * Check if register is referenced by this instruction. * */ private boolean isRegisterUsed(int register) { Instruction35c i = (Instruction35c) instruction; return register == i.getRegisterD() || register == i.getRegisterE() || register == i.getRegisterF() || register == i.getRegisterG() || register == i.getRegisterC(); } }
4,411
36.389831
118
java
soot
soot-master/src/main/java/soot/dexpler/instructions/FilledNewArrayRangeInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.dexpler.Util.isFloatLike; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.formats.Instruction3rc; import org.jf.dexlib2.iface.reference.TypeReference; import soot.ArrayType; import soot.Local; import soot.Type; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.ArrayRef; import soot.jimple.AssignStmt; import soot.jimple.IntConstant; import soot.jimple.Jimple; import soot.jimple.NewArrayExpr; public class FilledNewArrayRangeInstruction extends FilledArrayInstruction { public FilledNewArrayRangeInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { if (!(instruction instanceof Instruction3rc)) { throw new IllegalArgumentException("Expected Instruction3rc but got: " + instruction.getClass()); } Instruction3rc filledNewArrayInstr = (Instruction3rc) instruction; // NopStmt nopStmtBeginning = Jimple.v().newNopStmt(); // body.add(nopStmtBeginning); int usedRegister = filledNewArrayInstr.getRegisterCount(); Type t = DexType.toSoot((TypeReference) filledNewArrayInstr.getReference()); // NewArrayExpr needs the ElementType as it increases the array dimension by 1 Type arrayType = ((ArrayType) t).getElementType(); NewArrayExpr arrayExpr = Jimple.v().newNewArrayExpr(arrayType, IntConstant.v(usedRegister)); Local arrayLocal = body.getStoreResultLocal(); AssignStmt assignStmt = Jimple.v().newAssignStmt(arrayLocal, arrayExpr); body.add(assignStmt); for (int i = 0; i < usedRegister; i++) { ArrayRef arrayRef = Jimple.v().newArrayRef(arrayLocal, IntConstant.v(i)); AssignStmt assign = Jimple.v().newAssignStmt(arrayRef, body.getRegisterLocal(i + filledNewArrayInstr.getStartRegister())); addTags(assign); body.add(assign); } // NopStmt nopStmtEnd = Jimple.v().newNopStmt(); // body.add(nopStmtEnd); // defineBlock(nopStmtBeginning,nopStmtEnd); setUnit(assignStmt); // body.setDanglingInstruction(this); if (IDalvikTyper.ENABLE_DVKTYPER) { // Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assignStmt); DalvikTyper.v().setType(assignStmt.getLeftOpBox(), arrayExpr.getType(), false); // DalvikTyper.v().addConstraint(assignStmt.getLeftOpBox(), assignStmt.getRightOpBox()); } } @Override boolean isUsedAsFloatingPoint(DexBody body, int register) { Instruction3rc i = (Instruction3rc) instruction; Type arrayType = DexType.toSoot((TypeReference) i.getReference()); int startRegister = i.getStartRegister(); int endRegister = startRegister + i.getRegisterCount(); return register >= startRegister && register <= endRegister && isFloatLike(arrayType); } }
3,915
34.6
114
java
soot
soot-master/src/main/java/soot/dexpler/instructions/GotoInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import soot.dexpler.DexBody; import soot.jimple.GotoStmt; import soot.jimple.Jimple; public class GotoInstruction extends JumpInstruction implements DeferableInstruction { public GotoInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } public void jimplify(DexBody body) { // check if target instruction has been jimplified if (getTargetInstruction(body).getUnit() != null) { body.add(gotoStatement()); return; } // set marker unit to swap real gotostmt with otherwise body.addDeferredJimplification(this); markerUnit = Jimple.v().newNopStmt(); addTags(markerUnit); unit = markerUnit; body.add(markerUnit); } public void deferredJimplify(DexBody body) { body.getBody().getUnits().insertAfter(gotoStatement(), markerUnit); } private GotoStmt gotoStatement() { GotoStmt go = Jimple.v().newGotoStmt(targetInstruction.getUnit()); setUnit(go); addTags(go); return go; } }
2,060
29.761194
86
java
soot
soot-master/src/main/java/soot/dexpler/instructions/IfTestInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.formats.Instruction22t; import soot.Local; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.BinopExpr; import soot.jimple.IfStmt; import soot.jimple.Jimple; public class IfTestInstruction extends ConditionalJumpInstruction { public IfTestInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override protected IfStmt ifStatement(DexBody body) { Instruction22t i = (Instruction22t) instruction; Local one = body.getRegisterLocal(i.getRegisterA()); Local other = body.getRegisterLocal(i.getRegisterB()); BinopExpr condition = getComparisonExpr(one, other); IfStmt jif = Jimple.v().newIfStmt(condition, targetInstruction.getUnit()); // setUnit() is called in ConditionalJumpInstruction addTags(jif); if (IDalvikTyper.ENABLE_DVKTYPER) { // Debug.printDbg(IDalvikTyper.DEBUG, "constraint if: "+ jif +" condition: "+ condition); DalvikTyper.v().addConstraint(condition.getOp1Box(), condition.getOp2Box()); } return jif; } }
2,204
32.409091
95
java
soot
soot-master/src/main/java/soot/dexpler/instructions/IfTestzInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.formats.Instruction21t; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.jimple.BinopExpr; import soot.jimple.IfStmt; import soot.jimple.Jimple; public class IfTestzInstruction extends ConditionalJumpInstruction { public IfTestzInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override protected IfStmt ifStatement(DexBody body) { Instruction21t i = (Instruction21t) instruction; BinopExpr condition = getComparisonExpr(body, i.getRegisterA()); IfStmt jif = Jimple.v().newIfStmt(condition, targetInstruction.getUnit()); // setUnit() is called in ConditionalJumpInstruction addTags(jif); if (IDalvikTyper.ENABLE_DVKTYPER) { // Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ jif); /* * int op = instruction.getOpcode().value; switch (op) { case 0x38: case 0x39: * //DalvikTyper.v().addConstraint(condition.getOp1Box(), condition.getOp2Box()); break; case 0x3a: case 0x3b: case * 0x3c: case 0x3d: DalvikTyper.v().setType(condition.getOp1Box(), BooleanType.v(), true); break; default: throw new * RuntimeException("error: unknown op: 0x"+ Integer.toHexString(op)); } */ } return jif; } }
2,356
34.179104
122
java
soot
soot-master/src/main/java/soot/dexpler/instructions/IgetInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction; import org.jf.dexlib2.iface.reference.FieldReference; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.InstanceFieldRef; import soot.jimple.Jimple; public class IgetInstruction extends FieldInstruction { public IgetInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { TwoRegisterInstruction i = (TwoRegisterInstruction) instruction; int dest = i.getRegisterA(); int object = i.getRegisterB(); FieldReference f = (FieldReference) ((ReferenceInstruction) instruction).getReference(); final Jimple jimple = Jimple.v(); InstanceFieldRef r = jimple.newInstanceFieldRef(body.getRegisterLocal(object), getSootFieldRef(f)); AssignStmt assign = jimple.newAssignStmt(body.getRegisterLocal(dest), r); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().setType(assign.getLeftOpBox(), r.getType(), false); } } @Override boolean overridesRegister(int register) { TwoRegisterInstruction i = (TwoRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
2,493
33.164384
103
java
soot
soot-master/src/main/java/soot/dexpler/instructions/InstanceOfInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.HashSet; import java.util.Set; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction; import org.jf.dexlib2.iface.instruction.formats.Instruction22c; import org.jf.dexlib2.iface.reference.TypeReference; import soot.Type; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.dexpler.IDalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.InstanceOfExpr; import soot.jimple.Jimple; public class InstanceOfInstruction extends DexlibAbstractInstruction { public InstanceOfInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { Instruction22c i = (Instruction22c) instruction; int dest = i.getRegisterA(); int source = i.getRegisterB(); Type t = DexType.toSoot((TypeReference) (i.getReference())); InstanceOfExpr e = Jimple.v().newInstanceOfExpr(body.getRegisterLocal(source), t); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), e); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { // DalvikTyper.v().? } } @Override boolean overridesRegister(int register) { TwoRegisterInstruction i = (TwoRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } @Override public Set<Type> introducedTypes() { ReferenceInstruction i = (ReferenceInstruction) instruction; Set<Type> types = new HashSet<Type>(); types.add(DexType.toSoot((TypeReference) i.getReference())); return types; } }
2,737
30.113636
86
java
soot
soot-master/src/main/java/soot/dexpler/instructions/InstructionFactory.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.Opcode; import org.jf.dexlib2.iface.instruction.Instruction; /** * Factory that returns an appropriate Instruction instances for given dexlib instructions and opcodes. * */ public class InstructionFactory { /** * Resolve an Instruction from a dexlib instruction. * * @param instruction * the corresponding dexlib instruction * @param codeAddress * the byte code address of the instruction */ public static DexlibAbstractInstruction fromInstruction(Instruction instruction, int codeAddress) { return fromOpcode(instruction.getOpcode(), instruction, codeAddress); } /** * Resolve an Instruction from an dex opcode. * * @param op * the opcode of the instruction * @param instruction * the corresponding dexlib instruction * @param codeAddress * the byte code address of the instruction */ public static DexlibAbstractInstruction fromOpcode(Opcode op, Instruction instruction, int codeAddress) { switch (op) { case SPARSE_SWITCH_PAYLOAD: case PACKED_SWITCH_PAYLOAD: case ARRAY_PAYLOAD: case NOP: // also includes // PackedSwitchDataPseudoInstruction, // SparseSwitchDataPseudoInstruction and // ArrayDataPseudoInstruction return new NopInstruction(instruction, codeAddress); case MOVE: case MOVE_FROM16: case MOVE_16: case MOVE_OBJECT: case MOVE_OBJECT_FROM16: case MOVE_OBJECT_16: case MOVE_WIDE: case MOVE_WIDE_FROM16: case MOVE_WIDE_16: return new MoveInstruction(instruction, codeAddress); case MOVE_RESULT: case MOVE_RESULT_OBJECT: case MOVE_RESULT_WIDE: return new MoveResultInstruction(instruction, codeAddress); case MOVE_EXCEPTION: return new MoveExceptionInstruction(instruction, codeAddress); case RETURN_VOID: return new ReturnVoidInstruction(instruction, codeAddress); case RETURN: case RETURN_OBJECT: case RETURN_WIDE: return new ReturnInstruction(instruction, codeAddress); case CONST: case CONST_4: case CONST_16: case CONST_HIGH16: case CONST_WIDE: case CONST_WIDE_16: case CONST_WIDE_32: case CONST_WIDE_HIGH16: return new ConstInstruction(instruction, codeAddress); case CONST_STRING: case CONST_STRING_JUMBO: return new ConstStringInstruction(instruction, codeAddress); case CONST_CLASS: return new ConstClassInstruction(instruction, codeAddress); case MONITOR_ENTER: return new MonitorEnterInstruction(instruction, codeAddress); case MONITOR_EXIT: return new MonitorExitInstruction(instruction, codeAddress); case CHECK_CAST: return new CheckCastInstruction(instruction, codeAddress); case INSTANCE_OF: return new InstanceOfInstruction(instruction, codeAddress); case ARRAY_LENGTH: return new ArrayLengthInstruction(instruction, codeAddress); case NEW_INSTANCE: return new NewInstanceInstruction(instruction, codeAddress); case NEW_ARRAY: return new NewArrayInstruction(instruction, codeAddress); case FILLED_NEW_ARRAY: return new FilledNewArrayInstruction(instruction, codeAddress); case FILLED_NEW_ARRAY_RANGE: return new FilledNewArrayRangeInstruction(instruction, codeAddress); case FILL_ARRAY_DATA: return new FillArrayDataInstruction(instruction, codeAddress); case THROW: return new ThrowInstruction(instruction, codeAddress); case GOTO: case GOTO_16: case GOTO_32: return new GotoInstruction(instruction, codeAddress); case PACKED_SWITCH: // case PACKED_SWITCH_PAYLOAD: return new PackedSwitchInstruction(instruction, codeAddress); case SPARSE_SWITCH: // case SPARSE_SWITCH_PAYLOAD: return new SparseSwitchInstruction(instruction, codeAddress); case CMPL_FLOAT: case CMPG_FLOAT: case CMPL_DOUBLE: case CMPG_DOUBLE: case CMP_LONG: return new CmpInstruction(instruction, codeAddress); case IF_EQ: case IF_NE: case IF_LT: case IF_GE: case IF_GT: case IF_LE: return new IfTestInstruction(instruction, codeAddress); case IF_EQZ: case IF_NEZ: case IF_LTZ: case IF_GEZ: case IF_GTZ: case IF_LEZ: return new IfTestzInstruction(instruction, codeAddress); case AGET: case AGET_OBJECT: case AGET_BOOLEAN: case AGET_BYTE: case AGET_CHAR: case AGET_SHORT: case AGET_WIDE: return new AgetInstruction(instruction, codeAddress); case APUT: case APUT_OBJECT: case APUT_BOOLEAN: case APUT_BYTE: case APUT_CHAR: case APUT_SHORT: case APUT_WIDE: return new AputInstruction(instruction, codeAddress); case IGET: case IGET_OBJECT: case IGET_BOOLEAN: case IGET_BYTE: case IGET_CHAR: case IGET_SHORT: case IGET_WIDE: return new IgetInstruction(instruction, codeAddress); case IPUT: case IPUT_OBJECT: case IPUT_BOOLEAN: case IPUT_BYTE: case IPUT_CHAR: case IPUT_SHORT: case IPUT_WIDE: return new IputInstruction(instruction, codeAddress); case SGET: case SGET_OBJECT: case SGET_BOOLEAN: case SGET_BYTE: case SGET_CHAR: case SGET_SHORT: case SGET_WIDE: return new SgetInstruction(instruction, codeAddress); case SPUT: case SPUT_OBJECT: case SPUT_BOOLEAN: case SPUT_BYTE: case SPUT_CHAR: case SPUT_SHORT: case SPUT_WIDE: return new SputInstruction(instruction, codeAddress); case INVOKE_VIRTUAL: case INVOKE_VIRTUAL_RANGE: return new InvokeVirtualInstruction(instruction, codeAddress); case INVOKE_INTERFACE: case INVOKE_INTERFACE_RANGE: return new InvokeInterfaceInstruction(instruction, codeAddress); case INVOKE_DIRECT: case INVOKE_DIRECT_RANGE: case INVOKE_SUPER: case INVOKE_SUPER_RANGE: return new InvokeSpecialInstruction(instruction, codeAddress); case INVOKE_STATIC: case INVOKE_STATIC_RANGE: return new InvokeStaticInstruction(instruction, codeAddress); case EXECUTE_INLINE: case EXECUTE_INLINE_RANGE: return new ExecuteInlineInstruction(instruction, codeAddress); case INVOKE_POLYMORPHIC: case INVOKE_POLYMORPHIC_RANGE: return new InvokePolymorphicInstruction(instruction, codeAddress); case INVOKE_CUSTOM: case INVOKE_CUSTOM_RANGE: return new InvokeCustomInstruction(instruction, codeAddress); case NEG_INT: case NOT_INT: case NEG_FLOAT: case NEG_LONG: case NOT_LONG: case NEG_DOUBLE: return new UnopInstruction(instruction, codeAddress); case INT_TO_LONG: case INT_TO_DOUBLE: case FLOAT_TO_LONG: case FLOAT_TO_DOUBLE: case LONG_TO_INT: case LONG_TO_FLOAT: case DOUBLE_TO_INT: case DOUBLE_TO_FLOAT: case LONG_TO_DOUBLE: case DOUBLE_TO_LONG: case INT_TO_FLOAT: case FLOAT_TO_INT: case INT_TO_BYTE: case INT_TO_CHAR: case INT_TO_SHORT: return new CastInstruction(instruction, codeAddress); case ADD_INT: case SUB_INT: case MUL_INT: case DIV_INT: case REM_INT: case AND_INT: case OR_INT: case XOR_INT: case SHL_INT: case SHR_INT: case USHR_INT: case ADD_FLOAT: case SUB_FLOAT: case MUL_FLOAT: case DIV_FLOAT: case REM_FLOAT: case ADD_LONG: case SUB_LONG: case MUL_LONG: case DIV_LONG: case REM_LONG: case AND_LONG: case OR_LONG: case XOR_LONG: case SHL_LONG: case SHR_LONG: case USHR_LONG: case ADD_DOUBLE: case SUB_DOUBLE: case MUL_DOUBLE: case DIV_DOUBLE: case REM_DOUBLE: return new BinopInstruction(instruction, codeAddress); case ADD_INT_2ADDR: case SUB_INT_2ADDR: case MUL_INT_2ADDR: case DIV_INT_2ADDR: case REM_INT_2ADDR: case AND_INT_2ADDR: case OR_INT_2ADDR: case XOR_INT_2ADDR: case SHL_INT_2ADDR: case SHR_INT_2ADDR: case USHR_INT_2ADDR: case ADD_FLOAT_2ADDR: case SUB_FLOAT_2ADDR: case MUL_FLOAT_2ADDR: case DIV_FLOAT_2ADDR: case REM_FLOAT_2ADDR: case ADD_LONG_2ADDR: case SUB_LONG_2ADDR: case MUL_LONG_2ADDR: case DIV_LONG_2ADDR: case REM_LONG_2ADDR: case AND_LONG_2ADDR: case OR_LONG_2ADDR: case XOR_LONG_2ADDR: case SHL_LONG_2ADDR: case SHR_LONG_2ADDR: case USHR_LONG_2ADDR: case ADD_DOUBLE_2ADDR: case SUB_DOUBLE_2ADDR: case MUL_DOUBLE_2ADDR: case DIV_DOUBLE_2ADDR: case REM_DOUBLE_2ADDR: return new Binop2addrInstruction(instruction, codeAddress); case ADD_INT_LIT16: case RSUB_INT: case MUL_INT_LIT16: case DIV_INT_LIT16: case REM_INT_LIT16: case AND_INT_LIT16: case OR_INT_LIT16: case XOR_INT_LIT16: case ADD_INT_LIT8: case RSUB_INT_LIT8: case MUL_INT_LIT8: case DIV_INT_LIT8: case REM_INT_LIT8: case AND_INT_LIT8: case OR_INT_LIT8: case XOR_INT_LIT8: case SHL_INT_LIT8: case SHR_INT_LIT8: case USHR_INT_LIT8: return new BinopLitInstruction(instruction, codeAddress); default: throw new IllegalArgumentException("Opcode: " + op + " @ 0x" + Integer.toHexString(codeAddress)); } } }
10,903
27.322078
107
java
soot
soot-master/src/main/java/soot/dexpler/instructions/InvokeCustomInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.MethodHandleType; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.reference.CallSiteReference; import org.jf.dexlib2.iface.reference.FieldReference; import org.jf.dexlib2.iface.reference.MethodHandleReference; import org.jf.dexlib2.iface.reference.MethodProtoReference; import org.jf.dexlib2.iface.reference.MethodReference; import org.jf.dexlib2.iface.reference.Reference; import org.jf.dexlib2.iface.value.BooleanEncodedValue; import org.jf.dexlib2.iface.value.ByteEncodedValue; import org.jf.dexlib2.iface.value.CharEncodedValue; import org.jf.dexlib2.iface.value.DoubleEncodedValue; import org.jf.dexlib2.iface.value.EncodedValue; import org.jf.dexlib2.iface.value.FloatEncodedValue; import org.jf.dexlib2.iface.value.IntEncodedValue; import org.jf.dexlib2.iface.value.LongEncodedValue; import org.jf.dexlib2.iface.value.MethodHandleEncodedValue; import org.jf.dexlib2.iface.value.MethodTypeEncodedValue; import org.jf.dexlib2.iface.value.NullEncodedValue; import org.jf.dexlib2.iface.value.ShortEncodedValue; import org.jf.dexlib2.iface.value.StringEncodedValue; import org.jf.dexlib2.iface.value.TypeEncodedValue; import soot.Local; import soot.Scene; import soot.SootClass; import soot.SootMethodRef; import soot.Value; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.jimple.ClassConstant; import soot.jimple.DoubleConstant; import soot.jimple.FloatConstant; import soot.jimple.IntConstant; import soot.jimple.Jimple; import soot.jimple.LongConstant; import soot.jimple.MethodHandle; import soot.jimple.MethodHandle.Kind; import soot.jimple.MethodType; import soot.jimple.NullConstant; import soot.jimple.StringConstant; public class InvokeCustomInstruction extends MethodInvocationInstruction { public InvokeCustomInstruction(Instruction instruction, int codeAddress) { super(instruction, codeAddress); } @Override public void jimplify(DexBody body) { CallSiteReference callSiteReference = (CallSiteReference) ((ReferenceInstruction) instruction).getReference(); Reference bootstrapRef = callSiteReference.getMethodHandle().getMemberReference(); // According to the specification there are two types of references for invoke-custom and method and field type if (bootstrapRef instanceof MethodReference) { SootMethodRef bootstrapMethodRef = getBootStrapSootMethodRef(); Kind bootStrapKind = dexToSootMethodHandleKind(callSiteReference.getMethodHandle().getMethodHandleType()); // The bootstrap method has three required dynamic arguments and the rest are optional but // must always be constants List<Value> bootstrapValues = constantEncodedValuesToValues(callSiteReference.getExtraArguments()); SootMethodRef methodRef = getCustomSootMethodRef(); // The method prototype only includes the method arguments and no invoking object so treat like static List<Local> methodArgs = buildParameters(body, callSiteReference.getMethodProto().getParameterTypes(), true); invocation = Jimple.v().newDynamicInvokeExpr(bootstrapMethodRef, bootstrapValues, methodRef, bootStrapKind.getValue(), methodArgs); body.setDanglingInstruction(this); } else if (bootstrapRef instanceof FieldReference) { // It should not be possible for the boot strap method to be a field reference type but I // include a separate check to alert us if this ever does occur. // To set/get a field using invoke-custom, a field MethodHandle must be passed into // the invoke custom as an extra argument and called using invoke-polymorphic inside the // boot strap method. throw new RuntimeException("Error: Unexpected FieldReference type for boot strap method."); } else { throw new RuntimeException("Error: Unhandled MethodHandleReference of type '" + callSiteReference.getMethodHandle().getMethodHandleType() + "'"); } } /** Convert a list of constant EncodedValues to a list of constant Values. This is used * to convert the extra bootstrap args (which are all constants) into Jimple Values. * * @param in A list of constant EncodedValues * @return A list of constant Values */ private List<Value> constantEncodedValuesToValues(List<? extends EncodedValue> in) { List<Value> out = new ArrayList<>(); for (EncodedValue ev : in) { if (ev instanceof BooleanEncodedValue) { out.add(IntConstant.v(((BooleanEncodedValue) ev).getValue() == true ? 1 : 0)); } else if (ev instanceof ByteEncodedValue) { out.add(IntConstant.v(((ByteEncodedValue) ev).getValue())); } else if (ev instanceof CharEncodedValue) { out.add(IntConstant.v(((CharEncodedValue) ev).getValue())); } else if (ev instanceof DoubleEncodedValue) { out.add(DoubleConstant.v(((DoubleEncodedValue) ev).getValue())); } else if (ev instanceof FloatEncodedValue) { out.add(FloatConstant.v(((FloatEncodedValue) ev).getValue())); } else if (ev instanceof IntEncodedValue) { out.add(IntConstant.v(((IntEncodedValue) ev).getValue())); } else if (ev instanceof LongEncodedValue) { out.add(LongConstant.v(((LongEncodedValue) ev).getValue())); } else if (ev instanceof ShortEncodedValue) { out.add(IntConstant.v(((ShortEncodedValue) ev).getValue())); } else if (ev instanceof StringEncodedValue) { out.add(StringConstant.v(((StringEncodedValue) ev).getValue())); } else if (ev instanceof NullEncodedValue) { out.add(NullConstant.v()); } else if (ev instanceof MethodTypeEncodedValue) { MethodProtoReference protRef = ((MethodTypeEncodedValue) ev).getValue(); out.add(MethodType.v(convertParameterTypes(protRef.getParameterTypes()), DexType.toSoot(protRef.getReturnType()))); } else if (ev instanceof TypeEncodedValue) { out.add(ClassConstant.v(((TypeEncodedValue) ev).getValue())); } else if (ev instanceof MethodHandleEncodedValue) { MethodHandleReference mh = ((MethodHandleEncodedValue) ev).getValue(); Reference ref = mh.getMemberReference(); Kind kind = dexToSootMethodHandleKind(mh.getMethodHandleType()); MethodHandle handle; if (ref instanceof MethodReference) { handle = MethodHandle.v(getSootMethodRef((MethodReference) ref, kind), kind.getValue()); } else if (ref instanceof FieldReference) { handle = MethodHandle.v(getSootFieldRef((FieldReference) ref, kind), kind.getValue()); } else { throw new RuntimeException("Error: Unhandled method reference type " + ref.getClass().toString() + "."); } out.add(handle); } else { throw new RuntimeException("Error: Unhandled constant type '" + ev.getClass().toString() + "' when parsing bootstrap arguments in the call site reference."); } } return out; } private Kind dexToSootMethodHandleKind(int kind) { switch (kind) { case MethodHandleType.INSTANCE_GET: return MethodHandle.Kind.REF_GET_FIELD; case MethodHandleType.STATIC_GET: return MethodHandle.Kind.REF_GET_FIELD_STATIC; case MethodHandleType.INSTANCE_PUT: return MethodHandle.Kind.REF_PUT_FIELD; case MethodHandleType.STATIC_PUT: return MethodHandle.Kind.REF_PUT_FIELD_STATIC; case MethodHandleType.INVOKE_INSTANCE: return MethodHandle.Kind.REF_INVOKE_VIRTUAL; case MethodHandleType.INVOKE_STATIC: return MethodHandle.Kind.REF_INVOKE_STATIC; case MethodHandleType.INVOKE_DIRECT: return MethodHandle.Kind.REF_INVOKE_SPECIAL; case MethodHandleType.INVOKE_CONSTRUCTOR: return MethodHandle.Kind.REF_INVOKE_CONSTRUCTOR; case MethodHandleType.INVOKE_INTERFACE: return MethodHandle.Kind.REF_INVOKE_INTERFACE; default: throw new RuntimeException("Error: Unknown kind '" + kind + "' for method handle"); } } /** Return a dummy SootMethodRef for the method invoked by a * invoke-custom instruction. */ protected SootMethodRef getCustomSootMethodRef() { CallSiteReference callSiteReference = (CallSiteReference) ((ReferenceInstruction) instruction).getReference(); SootClass dummyclass = Scene.v().getSootClass(SootClass.INVOKEDYNAMIC_DUMMY_CLASS_NAME); String methodName = callSiteReference.getMethodName(); MethodProtoReference methodRef = callSiteReference.getMethodProto(); // No reference kind stored in invoke custom instruction for the actual // method being invoked so default to static return getSootMethodRef(dummyclass, methodName, methodRef.getReturnType(), methodRef.getParameterTypes(), Kind.REF_INVOKE_STATIC); } /** Return a SootMethodRef for the bootstrap method of * an invoke-custom instruction. */ protected SootMethodRef getBootStrapSootMethodRef() { MethodHandleReference mh = ((CallSiteReference) ((ReferenceInstruction) instruction).getReference()).getMethodHandle(); return getSootMethodRef((MethodReference) mh.getMemberReference(), dexToSootMethodHandleKind(mh.getMethodHandleType())); } }
10,310
46.298165
124
java
soot
soot-master/src/main/java/soot/dexpler/instructions/InvokeInterfaceInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import soot.dexpler.DexBody; public class InvokeInterfaceInstruction extends MethodInvocationInstruction { public InvokeInterfaceInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } // use Nop as begin marker // NopStmt nop = Jimple.v().newNopStmt(); // defineBlock(nop); // tagWithLineNumber(nop); // body.add(nop); // beginUnit = nop; public void jimplify(DexBody body) { jimplifyInterface(body); } }
1,537
29.156863
78
java
soot
soot-master/src/main/java/soot/dexpler/instructions/InvokePolymorphicInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.Arrays; import java.util.List; import org.jf.dexlib2.iface.instruction.DualReferenceInstruction; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.reference.MethodProtoReference; import soot.ArrayType; import soot.Body; import soot.Local; import soot.PatchingChain; import soot.RefType; import soot.Scene; import soot.SootMethodRef; import soot.Unit; import soot.dexpler.DexBody; import soot.jimple.IntConstant; import soot.jimple.Jimple; import soot.jimple.internal.JArrayRef; import soot.jimple.internal.JAssignStmt; import soot.jimple.internal.JNewArrayExpr; import soot.jimple.internal.JimpleLocal; public class InvokePolymorphicInstruction extends MethodInvocationInstruction { public InvokePolymorphicInstruction(Instruction instruction, int codeAddress) { super(instruction, codeAddress); } /* Instruction Format for invoke-polymorphic * invoke-polymorphic MH.invoke, prototype, {mh, [args]} * - MH.invoke - a method handle (i.e. MethodReference in dexlib2) for either the method invoke or invokeExact * - prototype - a description of the types for the arguments being passed into invoke or invokeExact and their * return type * - {mh, [args]} - A list of one or more arguments included in the instruction. The first argument (mh) is always a * reference to the MethodHandle object that invoke or invokeExact is called on. The remaining arguments are * references to the objects passed into the call to invoke or invokeExact. This is similar to how * invoke-virtual functions. * * The invoke-polymorphic instruction behaves similar to how reflection functions from a coder standpoint it is just * faster. The actual function being called depends on how the mh object is constructed at runtime (i.e. the * method name, parameter types and number, return type, and calling object). The prototype included in * invoke-polymorphic reflects the types of the arguments passed into invoke or invokeExact and should match the * the types of the parameters of the actual method being invoked from a class hierarchy standpoint. However, they * are included mainly so the VM knows the types of the variables being passed into the invoke and invokeExact * method for sizing purposes (i.e. so the data can be read properly). The actual parameter types for the method * invoked is determined at runtime. * * From a static analysis standpoint there is no way to tell exactly what method is being called using * the invoke-polymorphic instruction. A more complex context sensitive analysis would be required to determine * the exact method being called. A less complex analysis could be performed to determine all possible methods * that could be invoked by this instruction. However, neither of these options should really be performed when * translating dex to bytecode. Instead, they should be performed later on a per-analysis basis. As there is no * equivalent instruction to invoke-polymorphic in normal Java bytecode, we simply translate the instruction to * a normal invoke-virtual instruction where invoke or invokeExact is the method being called, mh is the object * it is being called on, and args are the arguments for the method call if any. This decision does lose the * prototype data included in the instruction; however, as described above it does not really aid us in determining * the method being called and resolving the method being called can still be done using other data in the code. * * See https://www.pnfsoftware.com/blog/android-o-and-dex-version-38-new-dalvik-opcodes-to-support-dynamic-invocation/ * for more information on this instruction and the class lang/invoke/Transformers.java for examples of * invoke-polymorhpic instructions whose prototype will does not match the actual method being invoked. */ @Override public void jimplify(DexBody body) { SootMethodRef ref = getVirtualSootMethodRef(); if (ref.declaringClass().isInterface()) { ref = getInterfaceSootMethodRef(); } // The invoking object will always be included in the parameter types here List<Local> temp = buildParameters(body, ((MethodProtoReference) ((DualReferenceInstruction) instruction).getReference2()).getParameterTypes(), false); List<Local> parms = temp.subList(1, temp.size()); Local invoker = temp.get(0); // Only box the arguments into an array if there are arguments and if they are not // already in some kind of array if (parms.size() > 0 && !(parms.size() == 1 && parms.get(0) instanceof ArrayType)) { Body b = body.getBody(); PatchingChain<Unit> units = b.getUnits(); //Return type for invoke and invokeExact is Object and paramater type is Object[] RefType rf = Scene.v().getRefType("java.lang.Object"); Local newArrL = new JimpleLocal("$u" + (b.getLocalCount() + 1), ArrayType.v(rf, 1)); b.getLocals().add(newArrL); JAssignStmt newArr = new JAssignStmt(newArrL, new JNewArrayExpr(rf, IntConstant.v(parms.size()))); units.add(newArr); int i = 0; for (Local l : parms) { units.add(new JAssignStmt(new JArrayRef(newArrL, IntConstant.v(i)), l)); i++; } parms = Arrays.asList(newArrL); } if (ref.declaringClass().isInterface()) { invocation = Jimple.v().newInterfaceInvokeExpr(invoker, ref, parms); } else { invocation = Jimple.v().newVirtualInvokeExpr(invoker, ref, parms); } body.setDanglingInstruction(this); } }
6,700
48.272059
123
java
soot
soot-master/src/main/java/soot/dexpler/instructions/InvokeSpecialInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import soot.dexpler.DexBody; public class InvokeSpecialInstruction extends MethodInvocationInstruction { public InvokeSpecialInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } public void jimplify(DexBody body) { jimplifySpecial(body); } }
1,363
30
76
java
soot
soot-master/src/main/java/soot/dexpler/instructions/InvokeStaticInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import soot.dexpler.DexBody; public class InvokeStaticInstruction extends MethodInvocationInstruction { public InvokeStaticInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } // // use Nop as begin marker // NopStmt nop = Jimple.v().newNopStmt(); // defineBlock(nop); // tagWithLineNumber(nop); // body.add(nop); // beginUnit = nop; public void jimplify(DexBody body) { jimplifyStatic(body); } @Override boolean isUsedAsFloatingPoint(DexBody body, int register) { return isUsedAsFloatingPoint(body, register, true); } }
1,665
29.290909
75
java
soot
soot-master/src/main/java/soot/dexpler/instructions/InvokeVirtualInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import soot.dexpler.DexBody; public class InvokeVirtualInstruction extends MethodInvocationInstruction { public InvokeVirtualInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } // use Nop as begin marker // NopStmt nop = Jimple.v().newNopStmt(); // defineBlock(nop); // tagWithLineNumber(nop); // body.add(nop); // beginUnit = nop; public void jimplify(DexBody body) { jimplifyVirtual(body); } }
1,531
29.039216
76
java
soot
soot-master/src/main/java/soot/dexpler/instructions/IputInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction; import org.jf.dexlib2.iface.reference.FieldReference; import soot.Local; import soot.Type; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.InstanceFieldRef; import soot.jimple.Jimple; public class IputInstruction extends FieldInstruction { public IputInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { TwoRegisterInstruction i = (TwoRegisterInstruction) instruction; int source = i.getRegisterA(); int object = i.getRegisterB(); FieldReference f = (FieldReference) ((ReferenceInstruction) instruction).getReference(); InstanceFieldRef instanceField = Jimple.v().newInstanceFieldRef(body.getRegisterLocal(object), getSootFieldRef(f)); Local sourceValue = body.getRegisterLocal(source); AssignStmt assign = getAssignStmt(body, sourceValue, instanceField); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { // Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign); DalvikTyper.v().setType(assign.getRightOpBox(), instanceField.getType(), true); } } @Override protected Type getTargetType(DexBody body) { FieldReference f = (FieldReference) ((ReferenceInstruction) instruction).getReference(); return DexType.toSoot(f.getType()); } }
2,673
34.184211
119
java
soot
soot-master/src/main/java/soot/dexpler/instructions/JumpInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OffsetInstruction; import soot.Unit; import soot.dexpler.DexBody; public abstract class JumpInstruction extends DexlibAbstractInstruction { protected DexlibAbstractInstruction targetInstruction; protected Unit markerUnit; public JumpInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } protected DexlibAbstractInstruction getTargetInstruction(DexBody body) { int offset = ((OffsetInstruction) instruction).getCodeOffset(); int targetAddress = codeAddress + offset; targetInstruction = body.instructionAtAddress(targetAddress); return targetInstruction; } }
1,732
32.980392
74
java
soot
soot-master/src/main/java/soot/dexpler/instructions/MethodInvocationInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.dexpler.Util.dottedClassName; import static soot.dexpler.Util.isFloatLike; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.instruction.formats.Instruction35c; import org.jf.dexlib2.iface.instruction.formats.Instruction3rc; import org.jf.dexlib2.iface.instruction.formats.Instruction45cc; import org.jf.dexlib2.iface.instruction.formats.Instruction4rcc; import org.jf.dexlib2.iface.reference.FieldReference; import org.jf.dexlib2.iface.reference.MethodReference; import soot.Local; import soot.Modifier; import soot.RefType; import soot.Scene; import soot.SootClass; import soot.SootFieldRef; import soot.SootMethodRef; import soot.SootResolver; import soot.Type; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.InstanceInvokeExpr; import soot.jimple.InvokeExpr; import soot.jimple.InvokeStmt; import soot.jimple.Jimple; import soot.jimple.MethodHandle.Kind; public abstract class MethodInvocationInstruction extends DexlibAbstractInstruction implements DanglingInstruction { // stores the dangling InvokeExpr protected InvokeExpr invocation; protected AssignStmt assign = null; public MethodInvocationInstruction(Instruction instruction, int codeAddress) { super(instruction, codeAddress); } @Override public void finalize(DexBody body, DexlibAbstractInstruction successor) { // defer final jimplification to move result if (successor instanceof MoveResultInstruction) { // MoveResultInstruction i = (MoveResultInstruction)successor; // i.setExpr(invocation); // if (lineNumber != -1) // i.setTag(new SourceLineNumberTag(lineNumber)); assign = Jimple.v().newAssignStmt(body.getStoreResultLocal(), invocation); setUnit(assign); addTags(assign); body.add(assign); unit = assign; // this is a invoke statement (the MoveResult had to be the direct successor for an expression) } else { InvokeStmt invoke = Jimple.v().newInvokeStmt(invocation); setUnit(invoke); addTags(invoke); body.add(invoke); unit = invoke; } if (IDalvikTyper.ENABLE_DVKTYPER) { // Debug.printDbg(IDalvikTyper.DEBUG, "constraint special invoke: "+ assign); if (invocation instanceof InstanceInvokeExpr) { Type t = invocation.getMethodRef().getDeclaringClass().getType(); DalvikTyper.v().setType(((InstanceInvokeExpr) invocation).getBaseBox(), t, true); // DalvikTyper.v().setObjectType(assign.getLeftOpBox()); } int i = 0; for (Type pt : invocation.getMethodRef().getParameterTypes()) { DalvikTyper.v().setType(invocation.getArgBox(i++), pt, true); } if (assign != null) { DalvikTyper.v().setType(assign.getLeftOpBox(), invocation.getType(), false); } } } @Override public Set<Type> introducedTypes() { Set<Type> types = new HashSet<Type>(); MethodReference method = (MethodReference) (((ReferenceInstruction) instruction).getReference()); types.add(DexType.toSoot(method.getDefiningClass())); types.add(DexType.toSoot(method.getReturnType())); List<? extends CharSequence> paramTypes = method.getParameterTypes(); if (paramTypes != null) { for (CharSequence type : paramTypes) { types.add(DexType.toSoot(type.toString())); } } return types; } // overriden in InvokeStaticInstruction @Override boolean isUsedAsFloatingPoint(DexBody body, int register) { return isUsedAsFloatingPoint(body, register, false); } /** * Determine if register is used as floating point. * * Abstraction for static and non-static methods. Non-static methods need to ignore the first parameter (this) * * @param isStatic * if this method is static */ protected boolean isUsedAsFloatingPoint(DexBody body, int register, boolean isStatic) { MethodReference item = (MethodReference) ((ReferenceInstruction) instruction).getReference(); List<? extends CharSequence> paramTypes = item.getParameterTypes(); List<Integer> regs = getUsedRegistersNums(); if (paramTypes == null) { return false; } for (int i = 0, j = 0; i < regs.size(); i++, j++) { if (!isStatic && i == 0) { j--; continue; } if (regs.get(i) == register && isFloatLike(DexType.toSoot(paramTypes.get(j).toString()))) { return true; } if (DexType.isWide(paramTypes.get(j).toString())) { i++; } } return false; } /** * Determine if register is used as object. * * Abstraction for static and non-static methods. Non-static methods need to ignore the first parameter (this) * * @param isStatic * if this method is static */ protected boolean isUsedAsObject(DexBody body, int register, boolean isStatic) { MethodReference item = (MethodReference) ((ReferenceInstruction) instruction).getReference(); List<? extends CharSequence> paramTypes = item.getParameterTypes(); List<Integer> regs = getUsedRegistersNums(); if (paramTypes == null) { return false; } // we call a method on the register if (!isStatic && regs.get(0) == register) { return true; } // we call a method with register as a reftype paramter for (int i = 0, j = 0; i < regs.size(); i++, j++) { if (!isStatic && i == 0) { j--; continue; } if (regs.get(i) == register && (DexType.toSoot(paramTypes.get(j).toString()) instanceof RefType)) { return true; } if (DexType.isWide(paramTypes.get(j).toString())) { i++; } } return false; } /** * Return the virtual SootMethodRef for the invoked method. * */ protected SootMethodRef getVirtualSootMethodRef() { return getNormalSootMethodRef(Kind.REF_INVOKE_VIRTUAL); } /** * Return the static SootMethodRef for the invoked method. * */ protected SootMethodRef getStaticSootMethodRef() { return getNormalSootMethodRef(Kind.REF_INVOKE_STATIC); } /** * Return the static SootMethodRef for the invoked method. * */ protected SootMethodRef getInterfaceSootMethodRef() { return getNormalSootMethodRef(Kind.REF_INVOKE_INTERFACE); } /** * Return the SootMethodRef for the invoked method. * * @param kind * The type of the invocation in terms of MethodHandle.Kind */ protected SootMethodRef getNormalSootMethodRef(Kind kind) { return getSootMethodRef((MethodReference) ((ReferenceInstruction) instruction).getReference(), kind); } /** * Return a SootMethodRef for the given MethodReference dependent on the InvocationType passed in. * * @param mItem * The MethodReference included in the invoke instruction * @param kind * The type of the invocation in terms of MethodHandle.Kind * @return A SootMethodRef */ protected SootMethodRef getSootMethodRef(MethodReference mItem, Kind kind) { return getSootMethodRef(convertClassName(mItem.getDefiningClass(), kind), mItem.getName(), mItem.getReturnType(), mItem.getParameterTypes(), kind); } /** * Return a SootMethodRef for the given data. * * @param sc * The SootClass that the method is declared in * @param name * The name of the method being invoked * @param returnType * The return type of the method being invoked * @param paramTypes * The parameter types of the method being invoked * @param kind * The type of the invocation in terms of MethodHandle.Kind * @return A SootMethodRef */ protected SootMethodRef getSootMethodRef(SootClass sc, String name, String returnType, List<? extends CharSequence> paramTypes, Kind kind) { return Scene.v().makeMethodRef(sc, name, convertParameterTypes(paramTypes), DexType.toSoot(returnType), kind == Kind.REF_INVOKE_STATIC); } /** * Return a SootFieldRef for the given data. * * @param mItem * The FieldReference included in the invoke instruction * @param kind * The type of the field access in terms of MethodHandle.Kind * @return A SootFieldRef */ protected SootFieldRef getSootFieldRef(FieldReference mItem, Kind kind) { return getSootFieldRef(convertClassName(mItem.getDefiningClass(), kind), mItem.getName(), mItem.getType(), kind); } /** * Return a SootFieldRef for the given data. * * @param sc * The SootClass that the field is declared in * @param name * The name of the field * @param type * The type of the field * @param kind * The type of the field access in terms of MethodHandle.Kind * @return A SootFieldRef */ protected SootFieldRef getSootFieldRef(SootClass sc, String name, String type, Kind kind) { return Scene.v().makeFieldRef(sc, name, DexType.toSoot(type), kind == Kind.REF_GET_FIELD_STATIC || kind == Kind.REF_PUT_FIELD_STATIC); } /** * Converts a list of dex string parameter types to soot types. * * @param paramTypes * The dex parameter types * @return The soot parameter types */ protected List<Type> convertParameterTypes(List<? extends CharSequence> paramTypes) { List<Type> parameterTypes = new ArrayList<Type>(); if (paramTypes != null) { for (CharSequence type : paramTypes) { parameterTypes.add(DexType.toSoot(type.toString())); } } return parameterTypes; } /** * Converts a given string class name into a SootClass. * * @param name * The dex string representation of the class * @param kind * The MethodHandle.Kind of the MethodHandle this class is coming from * @return */ protected SootClass convertClassName(String name, Kind kind) { if (name.startsWith("[")) { name = "java.lang.Object"; } else { name = dottedClassName(name); } SootClass sc = SootResolver.v().makeClassRef(name); if (kind == Kind.REF_INVOKE_INTERFACE && sc.isPhantom()) { sc.setModifiers(sc.getModifiers() | Modifier.INTERFACE); } return sc; } /** * Build the local parameters of the invocation. If a method is not static then its first register value is the invoking * object and will be skipped when constructing the local parameters. * * @param body * the body to build for and into * @param paramTypes * the parameter types as strings * @param isStatic * if the method is static * @return the converted parameters */ protected List<Local> buildParameters(DexBody body, List<? extends CharSequence> paramTypes, boolean isStatic) { List<Local> parameters = new ArrayList<Local>(); List<Integer> regs = getUsedRegistersNums(); // i: index for register // j: index for parameter type for (int i = 0, j = 0; i < regs.size(); i++, j++) { parameters.add(body.getRegisterLocal(regs.get(i))); // if method is non-static the first parameter is the instance // pointer and has no corresponding parameter type if (!isStatic && i == 0) { j--; continue; } // If current parameter is wide ignore the next register. // No need to increment j as there is one parameter type // for those two registers. if (paramTypes != null && DexType.isWide(paramTypes.get(j).toString())) { i++; } } return parameters; } /** * Return the indices used in this instruction. * * @return a list of register indices */ protected List<Integer> getUsedRegistersNums() { if (instruction instanceof Instruction35c) { return getUsedRegistersNums((Instruction35c) instruction); } else if (instruction instanceof Instruction3rc) { return getUsedRegistersNums((Instruction3rc) instruction); } else if (instruction instanceof Instruction45cc) { return getUsedRegistersNums((Instruction45cc) instruction); } else if (instruction instanceof Instruction4rcc) { return getUsedRegistersNums((Instruction4rcc) instruction); } throw new RuntimeException("Instruction is neither a InvokeInstruction nor a InvokeRangeInstruction"); } /** * Executes the "jimplify" operation for a virtual invocation */ protected void jimplifyVirtual(DexBody body) { // In some applications, InterfaceInvokes are disguised as VirtualInvokes. // We fix this silently SootMethodRef ref = getVirtualSootMethodRef(); if (ref.getDeclaringClass().isInterface()) { jimplifyInterface(body); return; } // This is actually a VirtualInvoke MethodReference item = (MethodReference) ((ReferenceInstruction) instruction).getReference(); List<Local> parameters = buildParameters(body, item.getParameterTypes(), false); invocation = Jimple.v().newVirtualInvokeExpr(parameters.get(0), ref, parameters.subList(1, parameters.size())); body.setDanglingInstruction(this); } /** * Executes the "jimplify" operation for an interface invocation */ protected void jimplifyInterface(DexBody body) { // In some applications, VirtualInvokes are disguised as InterfaceInvokes. // We fix this silently SootMethodRef ref = getInterfaceSootMethodRef(); if (!ref.getDeclaringClass().isInterface()) { jimplifyVirtual(body); return; } MethodReference item = (MethodReference) ((ReferenceInstruction) instruction).getReference(); List<Local> parameters = buildParameters(body, item.getParameterTypes(), false); invocation = Jimple.v().newInterfaceInvokeExpr(parameters.get(0), ref, parameters.subList(1, parameters.size())); body.setDanglingInstruction(this); } /** * Executes the "jimplify" operation for a special invocation */ protected void jimplifySpecial(DexBody body) { MethodReference item = (MethodReference) ((ReferenceInstruction) instruction).getReference(); List<Local> parameters = buildParameters(body, item.getParameterTypes(), false); invocation = Jimple.v().newSpecialInvokeExpr(parameters.get(0), getVirtualSootMethodRef(), parameters.subList(1, parameters.size())); body.setDanglingInstruction(this); } /** * Executes the "jimplify" operation for a static invocation */ protected void jimplifyStatic(DexBody body) { MethodReference item = (MethodReference) ((ReferenceInstruction) instruction).getReference(); invocation = Jimple.v().newStaticInvokeExpr(getStaticSootMethodRef(), buildParameters(body, item.getParameterTypes(), true)); body.setDanglingInstruction(this); } }
15,981
33.443966
122
java
soot
soot-master/src/main/java/soot/dexpler/instructions/MonitorEnterInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OneRegisterInstruction; import soot.Local; import soot.RefType; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.EnterMonitorStmt; import soot.jimple.Jimple; public class MonitorEnterInstruction extends DexlibAbstractInstruction { public MonitorEnterInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { int reg = ((OneRegisterInstruction) instruction).getRegisterA(); Local object = body.getRegisterLocal(reg); EnterMonitorStmt enterMonitorStmt = Jimple.v().newEnterMonitorStmt(object); setUnit(enterMonitorStmt); addTags(enterMonitorStmt); body.add(enterMonitorStmt); if (IDalvikTyper.ENABLE_DVKTYPER) { // Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ enterMonitorStmt); DalvikTyper.v().setType(enterMonitorStmt.getOpBox(), RefType.v("java.lang.Object"), true); } } }
2,097
32.83871
96
java
soot
soot-master/src/main/java/soot/dexpler/instructions/MonitorExitInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OneRegisterInstruction; import soot.Local; import soot.RefType; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.ExitMonitorStmt; import soot.jimple.Jimple; public class MonitorExitInstruction extends DexlibAbstractInstruction { public MonitorExitInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { int reg = ((OneRegisterInstruction) instruction).getRegisterA(); Local object = body.getRegisterLocal(reg); ExitMonitorStmt exitMonitorStmt = Jimple.v().newExitMonitorStmt(object); setUnit(exitMonitorStmt); addTags(exitMonitorStmt); body.add(exitMonitorStmt); if (IDalvikTyper.ENABLE_DVKTYPER) { // Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ exitMonitorStmt); DalvikTyper.v().setType(exitMonitorStmt.getOpBox(), RefType.v("java.lang.Object"), true); } } }
2,086
32.66129
95
java
soot
soot-master/src/main/java/soot/dexpler/instructions/MoveExceptionInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OneRegisterInstruction; import soot.Body; import soot.Local; import soot.RefType; import soot.Type; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.IdentityStmt; import soot.jimple.Jimple; public class MoveExceptionInstruction extends DexlibAbstractInstruction implements RetypeableInstruction { protected Type realType; protected IdentityStmt stmtToRetype; public MoveExceptionInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { int dest = ((OneRegisterInstruction) instruction).getRegisterA(); Local l = body.getRegisterLocal(dest); stmtToRetype = Jimple.v().newIdentityStmt(l, Jimple.v().newCaughtExceptionRef()); setUnit(stmtToRetype); addTags(stmtToRetype); body.add(stmtToRetype); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().setType(stmtToRetype.getLeftOpBox(), RefType.v("java.lang.Throwable"), false); } } @Override public void setRealType(DexBody body, Type t) { realType = t; body.addRetype(this); } @Override public void retype(Body body) { if (realType == null) { throw new RuntimeException("Real type of this instruction has not been set or was already retyped: " + this); } if (body.getUnits().contains(stmtToRetype)) { Local l = (Local) (stmtToRetype.getLeftOp()); l.setType(realType); realType = null; } } @Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
2,810
29.554348
115
java
soot
soot-master/src/main/java/soot/dexpler/instructions/MoveInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.Jimple; public class MoveInstruction extends DexlibAbstractInstruction { public MoveInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { TwoRegisterInstruction i = (TwoRegisterInstruction) instruction; int dest = i.getRegisterA(); int source = i.getRegisterB(); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), body.getRegisterLocal(source)); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox()); } } @Override int movesRegister(int register) { TwoRegisterInstruction i = (TwoRegisterInstruction) instruction; int dest = i.getRegisterA(); int source = i.getRegisterB(); if (register == source) { return dest; } return -1; } @Override int movesToRegister(int register) { TwoRegisterInstruction i = (TwoRegisterInstruction) instruction; int dest = i.getRegisterA(); int source = i.getRegisterB(); if (register == dest) { return source; } return -1; } @Override boolean overridesRegister(int register) { TwoRegisterInstruction i = (TwoRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
2,680
28.461538
109
java
soot
soot-master/src/main/java/soot/dexpler/instructions/MoveResultInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OneRegisterInstruction; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.Jimple; import soot.jimple.internal.JAssignStmt; public class MoveResultInstruction extends DexlibAbstractInstruction { // private Local local; // private Expr expr; public MoveResultInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { // if (local != null && expr != null) // throw new RuntimeException("Both local and expr are set to move."); int dest = ((OneRegisterInstruction) instruction).getRegisterA(); // if (local != null) // assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), local); // else if (expr != null) // assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr); // else // throw new RuntimeException("Neither local and expr are set to move."); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), body.getStoreResultLocal()); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { JAssignStmt jassign = (JAssignStmt) assign; DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox()); } } // public void setLocalToMove(Local l) { // local = l; // } // public void setExpr(Expr e) { // expr = e; // } @Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
2,783
31.372093
106
java
soot
soot-master/src/main/java/soot/dexpler/instructions/NewArrayInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.HashSet; import java.util.Set; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction; import org.jf.dexlib2.iface.instruction.formats.Instruction22c; import org.jf.dexlib2.iface.reference.TypeReference; import soot.ArrayType; import soot.IntType; import soot.Local; import soot.Type; import soot.Value; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.Jimple; import soot.jimple.NewArrayExpr; public class NewArrayInstruction extends DexlibAbstractInstruction { public NewArrayInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { if (!(instruction instanceof Instruction22c)) { throw new IllegalArgumentException("Expected Instruction22c but got: " + instruction.getClass()); } Instruction22c newArray = (Instruction22c) instruction; int dest = newArray.getRegisterA(); Value size = body.getRegisterLocal(newArray.getRegisterB()); Type t = DexType.toSoot((TypeReference) newArray.getReference()); // NewArrayExpr needs the ElementType as it increases the array dimension by 1 Type arrayType = ((ArrayType) t).getElementType(); NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(arrayType, size); Local l = body.getRegisterLocal(dest); AssignStmt assign = Jimple.v().newAssignStmt(l, newArrayExpr); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().setType(newArrayExpr.getSizeBox(), IntType.v(), true); DalvikTyper.v().setType(assign.getLeftOpBox(), newArrayExpr.getType(), false); } } @Override boolean overridesRegister(int register) { TwoRegisterInstruction i = (TwoRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } @Override public Set<Type> introducedTypes() { ReferenceInstruction i = (ReferenceInstruction) instruction; Set<Type> types = new HashSet<Type>(); types.add(DexType.toSoot((TypeReference) i.getReference())); return types; } }
3,360
31.009524
103
java
soot
soot-master/src/main/java/soot/dexpler/instructions/NewInstanceInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.dexpler.Util.dottedClassName; import java.util.HashSet; import java.util.Set; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OneRegisterInstruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.instruction.formats.Instruction21c; import org.jf.dexlib2.iface.reference.TypeReference; import soot.RefType; import soot.Type; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.Jimple; import soot.jimple.NewExpr; public class NewInstanceInstruction extends DexlibAbstractInstruction { public NewInstanceInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { Instruction21c i = (Instruction21c) instruction; int dest = i.getRegisterA(); String className = dottedClassName(((TypeReference) (i.getReference())).toString()); RefType type = RefType.v(className); NewExpr n = Jimple.v().newNewExpr(type); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), n); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { // DalvikTyper.v().captureAssign((JAssignStmt)assign, op); // TODO: ref. type may be null! DalvikTyper.v().setType(assign.getLeftOpBox(), type, false); } } @Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } @Override public Set<Type> introducedTypes() { ReferenceInstruction i = (ReferenceInstruction) instruction; Set<Type> types = new HashSet<Type>(); types.add(DexType.toSoot((TypeReference) i.getReference())); return types; } }
2,966
31.604396
96
java
soot
soot-master/src/main/java/soot/dexpler/instructions/NopInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import soot.dexpler.DexBody; import soot.jimple.Jimple; import soot.jimple.NopStmt; public class NopInstruction extends DexlibAbstractInstruction { public NopInstruction(Instruction instruction, int codeAddress) { super(instruction, codeAddress); } public void jimplify(DexBody body) { NopStmt nop = Jimple.v().newNopStmt(); setUnit(nop); addTags(nop); body.add(nop); } }
1,468
28.38
71
java
soot
soot-master/src/main/java/soot/dexpler/instructions/OdexInstruction.java
package soot.dexpler.instructions; /*- * #%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 org.jf.dexlib2.analysis.ClassPath; import org.jf.dexlib2.iface.DexFile; import org.jf.dexlib2.iface.Method; /** * Interface for instructions that are only valid in optimized dex files (ODEX). These instructions require special handling * for de-odexing. * * @author Steven Arzt */ public interface OdexInstruction { /** * De-odexes the current instruction. * * @param parentFile * The parent file to which the current ODEX instruction belongs */ public void deOdex(DexFile parentFile, Method m, ClassPath cp); }
1,409
29.652174
124
java
soot
soot-master/src/main/java/soot/dexpler/instructions/PackedSwitchInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.SwitchElement; import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload; import soot.IntType; import soot.Local; import soot.Unit; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.IntConstant; import soot.jimple.Jimple; import soot.jimple.LookupSwitchStmt; import soot.jimple.Stmt; public class PackedSwitchInstruction extends SwitchInstruction { public PackedSwitchInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override protected Stmt switchStatement(DexBody body, Instruction targetData, Local key) { PackedSwitchPayload i = (PackedSwitchPayload) targetData; List<? extends SwitchElement> seList = i.getSwitchElements(); // the default target always follows the switch statement int defaultTargetAddress = codeAddress + instruction.getCodeUnits(); Unit defaultTarget = body.instructionAtAddress(defaultTargetAddress).getUnit(); List<IntConstant> lookupValues = new ArrayList<IntConstant>(); List<Unit> targets = new ArrayList<Unit>(); for (SwitchElement se : seList) { lookupValues.add(IntConstant.v(se.getKey())); int offset = se.getOffset(); targets.add(body.instructionAtAddress(codeAddress + offset).getUnit()); } LookupSwitchStmt switchStmt = Jimple.v().newLookupSwitchStmt(key, lookupValues, targets, defaultTarget); setUnit(switchStmt); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().setType(switchStmt.getKeyBox(), IntType.v(), true); } return switchStmt; } @Override public void computeDataOffsets(DexBody body) { } }
2,825
32.247059
108
java
soot
soot-master/src/main/java/soot/dexpler/instructions/PseudoInstruction.java
// // (c) 2012 University of Luxembourg - Interdisciplinary Centre for // Security Reliability and Trust (SnT) - All rights reserved // // Author: Alexandre Bartel // // 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // package soot.dexpler.instructions; /*- * #%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 org.jf.dexlib2.iface.instruction.Instruction; import soot.dexpler.DexBody; public abstract class PseudoInstruction extends DexlibAbstractInstruction { public PseudoInstruction(Instruction instruction, int codeAddress) { super(instruction, codeAddress); } protected int dataFirstByte = -1; protected int dataLastByte = -1; protected int dataSize = -1; protected byte[] data = null; protected boolean loaded = false; public boolean isLoaded() { return loaded; } public void setLoaded(boolean loaded) { this.loaded = loaded; } public byte[] getData() { return data; } protected void setData(byte[] data) { this.data = data; } public int getDataFirstByte() { if (dataFirstByte == -1) { throw new RuntimeException("Error: dataFirstByte was not set!"); } return dataFirstByte; } protected void setDataFirstByte(int dataFirstByte) { this.dataFirstByte = dataFirstByte; } public int getDataLastByte() { if (dataLastByte == -1) { throw new RuntimeException("Error: dataLastByte was not set!"); } return dataLastByte; } protected void setDataLastByte(int dataLastByte) { this.dataLastByte = dataLastByte; } public int getDataSize() { if (dataSize == -1) { throw new RuntimeException("Error: dataFirstByte was not set!"); } return dataSize; } protected void setDataSize(int dataSize) { this.dataSize = dataSize; } public abstract void computeDataOffsets(DexBody body); }
3,222
27.522124
78
java
soot
soot-master/src/main/java/soot/dexpler/instructions/ReturnInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.formats.Instruction11x; import soot.Local; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.Jimple; import soot.jimple.ReturnStmt; public class ReturnInstruction extends DexlibAbstractInstruction { public ReturnInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { Instruction11x returnInstruction = (Instruction11x) this.instruction; Local l = body.getRegisterLocal(returnInstruction.getRegisterA()); ReturnStmt returnStmt = Jimple.v().newReturnStmt(l); setUnit(returnStmt); addTags(returnStmt); body.add(returnStmt); if (IDalvikTyper.ENABLE_DVKTYPER) { // DalvikTyper.v().addConstraint(returnStmt.getOpBox(), new // ImmediateBox(Jimple.body.getBody().getMethod().getReturnType())); DalvikTyper.v().setType(returnStmt.getOpBox(), body.getBody().getMethod().getReturnType(), true); } } }
2,114
32.571429
103
java
soot
soot-master/src/main/java/soot/dexpler/instructions/ReturnVoidInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import soot.dexpler.DexBody; import soot.jimple.Jimple; import soot.jimple.ReturnVoidStmt; public class ReturnVoidInstruction extends DexlibAbstractInstruction { public ReturnVoidInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } public void jimplify(DexBody body) { ReturnVoidStmt returnStmt = Jimple.v().newReturnVoidStmt(); setUnit(returnStmt); addTags(returnStmt); body.add(returnStmt); } }
1,529
29.6
73
java
soot
soot-master/src/main/java/soot/dexpler/instructions/RetypeableInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.Body; import soot.Type; import soot.dexpler.DexBody; /** * Interface for instructions that can/must be retyped, i.e. instructions that assign to a local and have to retype it after * local splitting. * * @author Michael Markert <michael.markert@googlemail.com> */ public interface RetypeableInstruction { /** * Swap generic exception type with the given one. * * @param body * the body that contains the instruction * @param t * the real type. */ public void setRealType(DexBody body, Type t); /** * Do actual retype. * * Retyping is separated from setting the type, to make it possible to retype after local splitting. * * @param body * The body containing the processed statement */ public void retype(Body body); }
1,822
28.885246
124
java
soot
soot-master/src/main/java/soot/dexpler/instructions/SgetInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OneRegisterInstruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.reference.FieldReference; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.Jimple; import soot.jimple.StaticFieldRef; public class SgetInstruction extends FieldInstruction { public SgetInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { int dest = ((OneRegisterInstruction) instruction).getRegisterA(); FieldReference f = (FieldReference) ((ReferenceInstruction) instruction).getReference(); StaticFieldRef r = Jimple.v().newStaticFieldRef(getStaticSootFieldRef(f)); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), r); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().setType(assign.getLeftOpBox(), r.getType(), false); } } @Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
2,365
32.8
92
java
soot
soot-master/src/main/java/soot/dexpler/instructions/SparseSwitchInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.SwitchElement; import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload; import soot.IntType; import soot.Local; import soot.Unit; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.IntConstant; import soot.jimple.Jimple; import soot.jimple.LookupSwitchStmt; import soot.jimple.Stmt; public class SparseSwitchInstruction extends SwitchInstruction { public SparseSwitchInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override protected Stmt switchStatement(DexBody body, Instruction targetData, Local key) { SparseSwitchPayload i = (SparseSwitchPayload) targetData; List<? extends SwitchElement> seList = i.getSwitchElements(); // the default target always follows the switch statement int defaultTargetAddress = codeAddress + instruction.getCodeUnits(); Unit defaultTarget = body.instructionAtAddress(defaultTargetAddress).getUnit(); List<IntConstant> lookupValues = new ArrayList<IntConstant>(); List<Unit> targets = new ArrayList<Unit>(); for (SwitchElement se : seList) { lookupValues.add(IntConstant.v(se.getKey())); int offset = se.getOffset(); targets.add(body.instructionAtAddress(codeAddress + offset).getUnit()); } LookupSwitchStmt switchStmt = Jimple.v().newLookupSwitchStmt(key, lookupValues, targets, defaultTarget); setUnit(switchStmt); addTags(switchStmt); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().setType(switchStmt.getKeyBox(), IntType.v(), true); } return switchStmt; } @Override public void computeDataOffsets(DexBody body) { // System.out.println("class of instruction: "+ instruction.getClass()); // int offset = ((OffsetInstruction) instruction).getCodeOffset(); // int targetAddress = codeAddress + offset; // Instruction targetData = body.instructionAtAddress(targetAddress).instruction; // SparseSwitchPayload ssInst = (SparseSwitchPayload) targetData; // List<? extends SwitchElement> targetAddresses = ssInst.getSwitchElements(); // int size = targetAddresses.size() * 2; // @ are on 32bits // // // From org.jf.dexlib.Code.Format.SparseSwitchDataPseudoInstruction we learn // // that there are 2 bytes after the magic number that we have to jump. // // 2 bytes to jump = address + 1 // // // // out.writeByte(0x00); // magic // // out.writeByte(0x02); // number // // out.writeShort(targets.length); // 2 bytes // // out.writeInt(firstKey); // // setDataFirstByte (targetAddress + 1); // setDataLastByte (targetAddress + 1 + size - 1); // setDataSize (size); // // ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(); // ssInst.write(out, targetAddress); // // byte[] outa = out.getArray(); // byte[] data = new byte[outa.length-2]; // for (int i=2; i<outa.length; i++) { // data[i-2] = outa[i]; // } // setData (data); } }
4,183
35.068966
108
java
soot
soot-master/src/main/java/soot/dexpler/instructions/SputInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OneRegisterInstruction; import org.jf.dexlib2.iface.instruction.ReferenceInstruction; import org.jf.dexlib2.iface.reference.FieldReference; import soot.Local; import soot.Type; import soot.dexpler.DexBody; import soot.dexpler.DexType; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.AssignStmt; import soot.jimple.Jimple; import soot.jimple.StaticFieldRef; public class SputInstruction extends FieldInstruction { public SputInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { int source = ((OneRegisterInstruction) instruction).getRegisterA(); FieldReference f = (FieldReference) ((ReferenceInstruction) instruction).getReference(); StaticFieldRef instanceField = Jimple.v().newStaticFieldRef(getStaticSootFieldRef(f)); Local sourceValue = body.getRegisterLocal(source); AssignStmt assign = getAssignStmt(body, sourceValue, instanceField); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().setType(assign.getRightOpBox(), instanceField.getType(), true); } } @Override protected Type getTargetType(DexBody body) { FieldReference f = (FieldReference) ((ReferenceInstruction) instruction).getReference(); return DexType.toSoot(f.getType()); } }
2,506
33.342466
92
java
soot
soot-master/src/main/java/soot/dexpler/instructions/SwitchInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OffsetInstruction; import org.jf.dexlib2.iface.instruction.OneRegisterInstruction; import soot.Local; import soot.Unit; import soot.dexpler.DexBody; import soot.jimple.Jimple; import soot.jimple.Stmt; public abstract class SwitchInstruction extends PseudoInstruction implements DeferableInstruction { protected Unit markerUnit; public SwitchInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } /** * Return a switch statement based on given target data on the given key. * */ protected abstract Stmt switchStatement(DexBody body, Instruction targetData, Local key); public void jimplify(DexBody body) { markerUnit = Jimple.v().newNopStmt(); unit = markerUnit; body.add(markerUnit); body.addDeferredJimplification(this); } public void deferredJimplify(DexBody body) { int keyRegister = ((OneRegisterInstruction) instruction).getRegisterA(); int offset = ((OffsetInstruction) instruction).getCodeOffset(); Local key = body.getRegisterLocal(keyRegister); int targetAddress = codeAddress + offset; Instruction targetData = body.instructionAtAddress(targetAddress).instruction; Stmt stmt = switchStatement(body, targetData, key); body.getBody().getUnits().insertAfter(stmt, markerUnit); } }
2,407
32.915493
99
java
soot
soot-master/src/main/java/soot/dexpler/instructions/TaggedInstruction.java
// // (c) 2012 University of Luxembourg - Interdisciplinary Centre for // Security Reliability and Trust (SnT) - All rights reserved // // Author: Alexandre Bartel // // 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // package soot.dexpler.instructions; /*- * #%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 org.jf.dexlib2.iface.instruction.Instruction; import soot.tagkit.Tag; public abstract class TaggedInstruction extends DexlibAbstractInstruction { private Tag instructionTag = null; public TaggedInstruction(Instruction instruction, int codeAddress) { super(instruction, codeAddress); } public void setTag(Tag t) { instructionTag = t; } public Tag getTag() { if (instructionTag == null) { throw new RuntimeException( "Must tag instruction first! (0x" + Integer.toHexString(codeAddress) + ": " + instruction + ")"); } return instructionTag; } }
2,300
31.871429
107
java
soot
soot-master/src/main/java/soot/dexpler/instructions/ThrowInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.formats.Instruction11x; import soot.RefType; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.typing.DalvikTyper; import soot.jimple.Jimple; import soot.jimple.ThrowStmt; public class ThrowInstruction extends DexlibAbstractInstruction { public ThrowInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { Instruction11x throwInstruction = (Instruction11x) instruction; ThrowStmt throwStmt = Jimple.v().newThrowStmt(body.getRegisterLocal(throwInstruction.getRegisterA())); setUnit(throwStmt); addTags(throwStmt); body.add(throwStmt); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().setType(throwStmt.getOpBox(), RefType.v("java.lang.Throwable"), true); } } }
1,932
31.762712
106
java
soot
soot-master/src/main/java/soot/dexpler/instructions/UnopInstruction.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Michael Markert, Frank Hartmann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * 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.jf.dexlib2.Opcode; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction; import org.jf.dexlib2.iface.instruction.formats.Instruction12x; import soot.Local; import soot.Value; import soot.dexpler.DexBody; import soot.dexpler.IDalvikTyper; import soot.dexpler.tags.DoubleOpTag; import soot.dexpler.tags.FloatOpTag; import soot.dexpler.tags.IntOpTag; import soot.dexpler.tags.LongOpTag; import soot.jimple.AssignStmt; import soot.jimple.IntConstant; import soot.jimple.Jimple; import soot.jimple.LongConstant; public class UnopInstruction extends TaggedInstruction { public UnopInstruction(Instruction instruction, int codeAdress) { super(instruction, codeAdress); } @Override public void jimplify(DexBody body) { if (!(instruction instanceof Instruction12x)) { throw new IllegalArgumentException("Expected Instruction12x but got: " + instruction.getClass()); } Instruction12x cmpInstr = (Instruction12x) instruction; int dest = cmpInstr.getRegisterA(); Local source = body.getRegisterLocal(cmpInstr.getRegisterB()); Value expr = getExpression(source); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr); assign.addTag(getTag()); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { /* * int op = (int)instruction.getOpcode().value; //DalvikTyper.v().captureAssign((JAssignStmt)assign, op); JAssignStmt * jass = (JAssignStmt)assign; DalvikTyper.v().setType((expr instanceof JCastExpr) ? ((JCastExpr) expr).getOpBox() : * ((UnopExpr) expr).getOpBox(), opUnType[op - 0x7b], true); DalvikTyper.v().setType(jass.leftBox, resUnType[op - * 0x7b], false); */ } } /** * Return the appropriate Jimple Expression according to the OpCode */ private Value getExpression(Local source) { Opcode opcode = instruction.getOpcode(); switch (opcode) { case NEG_INT: setTag(new IntOpTag()); return Jimple.v().newNegExpr(source); case NEG_LONG: setTag(new LongOpTag()); return Jimple.v().newNegExpr(source); case NEG_FLOAT: setTag(new FloatOpTag()); return Jimple.v().newNegExpr(source); case NEG_DOUBLE: setTag(new DoubleOpTag()); return Jimple.v().newNegExpr(source); case NOT_LONG: setTag(new LongOpTag()); return getNotLongExpr(source); case NOT_INT: setTag(new IntOpTag()); return getNotIntExpr(source); default: throw new RuntimeException("Invalid Opcode: " + opcode); } } /** * returns bitwise negation of an integer * * @param source * @return */ private Value getNotIntExpr(Local source) { return Jimple.v().newXorExpr(source, IntConstant.v(-1)); } /** * returns bitwise negation of a long * * @param source * @return */ private Value getNotLongExpr(Local source) { return Jimple.v().newXorExpr(source, LongConstant.v(-1l)); } @Override boolean overridesRegister(int register) { TwoRegisterInstruction i = (TwoRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } @Override boolean isUsedAsFloatingPoint(DexBody body, int register) { int source = ((TwoRegisterInstruction) instruction).getRegisterB(); Opcode opcode = instruction.getOpcode(); switch (opcode) { case NEG_FLOAT: case NEG_DOUBLE: return source == register; default: return false; } } }
4,641
28.948387
123
java
soot
soot-master/src/main/java/soot/dexpler/tags/DoubleOpTag.java
// // (c) 2012 University of Luxembourg - Interdisciplinary Centre for // Security Reliability and Trust (SnT) - All rights reserved // // Author: Alexandre Bartel // // 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // package soot.dexpler.tags; /*- * #%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 soot.tagkit.Tag; public class DoubleOpTag implements Tag { public static final String NAME = "DoubleOpTag"; @Override public String getName() { return NAME; } @Override public byte[] getValue() { return new byte[1]; } }
1,942
30.852459
78
java
soot
soot-master/src/main/java/soot/dexpler/tags/FloatOpTag.java
// // (c) 2012 University of Luxembourg - Interdisciplinary Centre for // Security Reliability and Trust (SnT) - All rights reserved // // Author: Alexandre Bartel // // 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // package soot.dexpler.tags; /*- * #%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 soot.tagkit.Tag; public class FloatOpTag implements Tag { public static final String NAME = "FloatOpTag"; @Override public String getName() { return NAME; } @Override public byte[] getValue() { return new byte[1]; } }
1,940
30.819672
78
java
soot
soot-master/src/main/java/soot/dexpler/tags/IntOpTag.java
// // (c) 2012 University of Luxembourg - Interdisciplinary Centre for // Security Reliability and Trust (SnT) - All rights reserved // // Author: Alexandre Bartel // // 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // package soot.dexpler.tags; /*- * #%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 soot.tagkit.Tag; public class IntOpTag implements Tag { public static final String NAME = "IntOpTag"; @Override public String getName() { return NAME; } @Override public byte[] getValue() { return new byte[1]; } }
1,936
30.754098
78
java
soot
soot-master/src/main/java/soot/dexpler/tags/LongOpTag.java
// // (c) 2012 University of Luxembourg - Interdisciplinary Centre for // Security Reliability and Trust (SnT) - All rights reserved // // Author: Alexandre Bartel // // 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // package soot.dexpler.tags; /*- * #%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 soot.tagkit.Tag; public class LongOpTag implements Tag { public static final String NAME = "LongOpTag"; @Override public String getName() { return NAME; } @Override public byte[] getValue() { return new byte[1]; } }
1,938
30.786885
78
java
soot
soot-master/src/main/java/soot/dexpler/tags/NumOpTag.java
// // (c) 2012 University of Luxembourg - Interdisciplinary Centre for // Security Reliability and Trust (SnT) - All rights reserved // // Author: Alexandre Bartel // // 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // package soot.dexpler.tags; /*- * #%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 soot.tagkit.Tag; public class NumOpTag implements Tag { public static final String NAME = "NumOpTag"; @Override public String getName() { return NAME; } @Override public byte[] getValue() { return new byte[1]; } }
1,936
30.754098
78
java
soot
soot-master/src/main/java/soot/dexpler/tags/ObjectOpTag.java
// // (c) 2012 University of Luxembourg - Interdisciplinary Centre for // Security Reliability and Trust (SnT) - All rights reserved // // Author: Alexandre Bartel // // 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // package soot.dexpler.tags; /*- * #%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 soot.tagkit.Tag; public class ObjectOpTag implements Tag { public static final String NAME = "ObjectOpTag"; @Override public String getName() { return NAME; } @Override public byte[] getValue() { return new byte[1]; } }
1,942
30.852459
78
java
soot
soot-master/src/main/java/soot/dexpler/typing/DalvikTyper.java
// // (c) 2012 University of Luxembourg - Interdisciplinary Centre for // Security Reliability and Trust (SnT) - All rights reserved // // Author: Alexandre Bartel // // 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // package soot.dexpler.typing; /*- * #%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.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; 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.PrimType; import soot.RefType; import soot.ShortType; import soot.Type; import soot.Unit; import soot.UnknownType; import soot.Value; import soot.ValueBox; import soot.dexpler.IDalvikTyper; import soot.dexpler.tags.DoubleOpTag; import soot.dexpler.tags.FloatOpTag; import soot.dexpler.tags.IntOpTag; import soot.dexpler.tags.LongOpTag; import soot.jimple.ArrayRef; import soot.jimple.AssignStmt; import soot.jimple.BinopExpr; import soot.jimple.BreakpointStmt; import soot.jimple.CastExpr; import soot.jimple.Constant; import soot.jimple.DefinitionStmt; import soot.jimple.DivExpr; import soot.jimple.DynamicInvokeExpr; import soot.jimple.EnterMonitorStmt; import soot.jimple.ExitMonitorStmt; import soot.jimple.GotoStmt; import soot.jimple.IdentityStmt; import soot.jimple.IfStmt; import soot.jimple.InstanceInvokeExpr; import soot.jimple.InvokeExpr; import soot.jimple.InvokeStmt; import soot.jimple.LookupSwitchStmt; import soot.jimple.NewArrayExpr; import soot.jimple.NopStmt; import soot.jimple.NullConstant; import soot.jimple.RemExpr; import soot.jimple.RetStmt; import soot.jimple.ReturnStmt; import soot.jimple.ReturnVoidStmt; import soot.jimple.ShlExpr; import soot.jimple.ShrExpr; import soot.jimple.StaticInvokeExpr; import soot.jimple.StmtSwitch; import soot.jimple.TableSwitchStmt; import soot.jimple.ThrowStmt; import soot.jimple.UnopExpr; import soot.jimple.UshrExpr; import soot.tagkit.Tag; import soot.toolkits.graph.ExceptionalUnitGraphFactory; import soot.toolkits.graph.UnitGraph; import soot.toolkits.scalar.SimpleLocalDefs; import soot.toolkits.scalar.SimpleLocalUses; import soot.toolkits.scalar.UnitValueBoxPair; public class DalvikTyper implements IDalvikTyper { private static DalvikTyper dt = null; private Set<Constraint> constraints = new HashSet<Constraint>(); private Map<ValueBox, Type> typed = new HashMap<ValueBox, Type>(); private Map<Local, Type> localTyped = new HashMap<Local, Type>(); private Set<Local> localTemp = new HashSet<Local>(); private List<LocalObj> localObjList = new ArrayList<LocalObj>(); private Map<Local, List<LocalObj>> local2Obj = new HashMap<Local, List<LocalObj>>(); private DalvikTyper() { } public static DalvikTyper v() { if (dt == null) { dt = new DalvikTyper(); } return dt; } public void clear() { constraints.clear(); typed.clear(); localTyped.clear(); localTemp.clear(); localObjList.clear(); local2Obj.clear(); } @Override public void setType(ValueBox vb, Type t, boolean isUse) { if (IDalvikTyper.DEBUG) { if (t instanceof UnknownType) { throw new RuntimeException("error: expected concreted type. Got " + t); } } if (vb.getValue() instanceof Local) { LocalObj lb = new LocalObj(vb, t, isUse); localObjList.add(lb); Local k = (Local) vb.getValue(); if (!local2Obj.containsKey(k)) { local2Obj.put(k, new ArrayList<LocalObj>()); } local2Obj.get(k).add(lb); } else { // Debug.printDbg(IDalvikTyper.DEBUG, "not instance of local: vb: ", vb, " value: ", vb.getValue(), " class: ", // vb.getValue().getClass()); } } @Override public void addConstraint(ValueBox l, ValueBox r) { if (IDalvikTyper.DEBUG) { // Debug.printDbg(IDalvikTyper.DEBUG, " [addConstraint] ", l, " < ", r); constraints.add(new Constraint(l, r)); } } @Override public void assignType(final Body b) { // Debug.printDbg("assignTypes: before: \n", b); constraints.clear(); localObjList.clear(); final Set<Unit> todoUnits = new HashSet<Unit>(); // put constraints: for (Unit u : b.getUnits()) { StmtSwitch ss = new StmtSwitch() { @Override public void caseBreakpointStmt(BreakpointStmt stmt) { // nothing } @Override public void caseInvokeStmt(InvokeStmt stmt) { // add constraint DalvikTyper.v().setInvokeType(stmt.getInvokeExpr()); } @Override public void caseAssignStmt(AssignStmt stmt) { // add constraint Value l = stmt.getLeftOp(); Value r = stmt.getRightOp(); // size in new array expression is of tye integer if (r instanceof NewArrayExpr) { NewArrayExpr nae = (NewArrayExpr) r; ValueBox sb = nae.getSizeBox(); if (sb.getValue() instanceof Local) { DalvikTyper.v().setType(sb, IntType.v(), true); } } // array index is of type integer if (stmt.containsArrayRef()) { ArrayRef ar = stmt.getArrayRef(); ValueBox sb = ar.getIndexBox(); if (sb.getValue() instanceof Local) { DalvikTyper.v().setType(sb, IntType.v(), true); } } if (l instanceof Local && r instanceof Local) { DalvikTyper.v().addConstraint(stmt.getLeftOpBox(), stmt.getRightOpBox()); return; } if (stmt.containsInvokeExpr()) { DalvikTyper.v().setInvokeType(stmt.getInvokeExpr()); } if (r instanceof Local) { // l NOT local Type leftType = stmt.getLeftOp().getType(); if (l instanceof ArrayRef && leftType instanceof UnknownType) { // find type later todoUnits.add(stmt); return; } DalvikTyper.v().setType(stmt.getRightOpBox(), leftType, true); return; } if (l instanceof Local) { // r NOT local if (r instanceof UntypedConstant) { return; } for (Tag t : stmt.getTags()) { if (r instanceof CastExpr) { // do not check tag, since the tag is for the operand of the cast break; } // Debug.printDbg("assign stmt tag: ", stmt, t); if (t instanceof IntOpTag) { checkExpr(r, IntType.v()); DalvikTyper.v().setType(stmt.getLeftOpBox(), IntType.v(), false); return; } else if (t instanceof FloatOpTag) { checkExpr(r, FloatType.v()); DalvikTyper.v().setType(stmt.getLeftOpBox(), FloatType.v(), false); return; } else if (t instanceof DoubleOpTag) { checkExpr(r, DoubleType.v()); DalvikTyper.v().setType(stmt.getLeftOpBox(), DoubleType.v(), false); return; } else if (t instanceof LongOpTag) { checkExpr(r, LongType.v()); DalvikTyper.v().setType(stmt.getLeftOpBox(), LongType.v(), false); return; } } Type rightType = stmt.getRightOp().getType(); if (r instanceof ArrayRef && rightType instanceof UnknownType) { // find type later todoUnits.add(stmt); return; } else if (r instanceof CastExpr) { CastExpr ce = (CastExpr) r; Type castType = ce.getCastType(); if (castType instanceof PrimType) { // check incoming primitive type for (Tag t : stmt.getTags()) { // Debug.printDbg("assign primitive type from stmt tag: ", stmt, t); if (t instanceof IntOpTag) { DalvikTyper.v().setType(ce.getOpBox(), IntType.v(), false); return; } else if (t instanceof FloatOpTag) { DalvikTyper.v().setType(ce.getOpBox(), FloatType.v(), false); return; } else if (t instanceof DoubleOpTag) { DalvikTyper.v().setType(ce.getOpBox(), DoubleType.v(), false); return; } else if (t instanceof LongOpTag) { DalvikTyper.v().setType(ce.getOpBox(), LongType.v(), false); return; } } } else { // incoming type is object DalvikTyper.v().setType(ce.getOpBox(), RefType.v("java.lang.Object"), false); } } DalvikTyper.v().setType(stmt.getLeftOpBox(), rightType, false); return; } } @Override public void caseIdentityStmt(IdentityStmt stmt) { DalvikTyper.v().setType(stmt.getLeftOpBox(), stmt.getRightOp().getType(), false); } @Override public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { // add constraint DalvikTyper.v().setType(stmt.getOpBox(), RefType.v("java.lang.Object"), true); } @Override public void caseExitMonitorStmt(ExitMonitorStmt stmt) { // add constraint DalvikTyper.v().setType(stmt.getOpBox(), RefType.v("java.lang.Object"), true); } @Override public void caseGotoStmt(GotoStmt stmt) { // nothing } @Override public void caseIfStmt(IfStmt stmt) { // add constraint Value c = stmt.getCondition(); if (c instanceof BinopExpr) { BinopExpr bo = (BinopExpr) c; Value op1 = bo.getOp1(); Value op2 = bo.getOp2(); if (op1 instanceof Local && op2 instanceof Local) { DalvikTyper.v().addConstraint(bo.getOp1Box(), bo.getOp2Box()); } } } @Override public void caseLookupSwitchStmt(LookupSwitchStmt stmt) { // add constraint DalvikTyper.v().setType(stmt.getKeyBox(), IntType.v(), true); } @Override public void caseNopStmt(NopStmt stmt) { // nothing } @Override public void caseRetStmt(RetStmt stmt) { // nothing } @Override public void caseReturnStmt(ReturnStmt stmt) { // add constraint DalvikTyper.v().setType(stmt.getOpBox(), b.getMethod().getReturnType(), true); } @Override public void caseReturnVoidStmt(ReturnVoidStmt stmt) { // nothing } @Override public void caseTableSwitchStmt(TableSwitchStmt stmt) { // add constraint DalvikTyper.v().setType(stmt.getKeyBox(), IntType.v(), true); } @Override public void caseThrowStmt(ThrowStmt stmt) { // add constraint DalvikTyper.v().setType(stmt.getOpBox(), RefType.v("java.lang.Object"), true); } @Override public void defaultCase(Object obj) { throw new RuntimeException("error: unknown statement: " + obj); } }; u.apply(ss); } // print todo list: // <com.admob.android.ads.q: void a(android.os.Bundle,java.lang.String,java.lang.Object)> if (!todoUnits.isEmpty()) { // propagate array types UnitGraph ug = ExceptionalUnitGraphFactory.createExceptionalUnitGraph(b); SimpleLocalDefs sld = new SimpleLocalDefs(ug); SimpleLocalUses slu = new SimpleLocalUses(b, sld); for (Unit u : b.getUnits()) { if (u instanceof DefinitionStmt) { // Debug.printDbg("U: ", u); DefinitionStmt ass = (DefinitionStmt) u; Value r = ass.getRightOp(); if (r instanceof UntypedConstant) { continue; } Type rType = r.getType(); if (rType instanceof ArrayType && ass.getLeftOp() instanceof Local) { // Debug.printDbg("propagate-array: checking ", u); // propagate array type through aliases Set<Unit> done = new HashSet<Unit>(); Set<DefinitionStmt> toDo = new HashSet<DefinitionStmt>(); toDo.add(ass); while (!toDo.isEmpty()) { DefinitionStmt currentUnit = toDo.iterator().next(); if (done.contains(currentUnit)) { toDo.remove(currentUnit); continue; } done.add(currentUnit); for (UnitValueBoxPair uvbp : slu.getUsesOf(currentUnit)) { Unit use = uvbp.unit; Value l2 = null; Value r2 = null; if (use instanceof AssignStmt) { AssignStmt ass2 = (AssignStmt) use; l2 = ass2.getLeftOp(); r2 = ass2.getRightOp(); if (!(l2 instanceof Local) || !(r2 instanceof Local || r2 instanceof ArrayRef)) { // Debug.printDbg("propagate-array: skipping ", use); continue; } Type newType = null; if (r2 instanceof Local) { List<LocalObj> lobjs = local2Obj.get(r2); newType = lobjs.get(0).t; } else if (r2 instanceof ArrayRef) { ArrayRef ar = (ArrayRef) r2; // skip if use is in index if (ar.getIndex() == currentUnit.getLeftOp()) { // Debug.printDbg("skipping since local is used as index..."); continue; } Local arBase = (Local) ar.getBase(); List<LocalObj> lobjs = local2Obj.get(arBase); Type baseT = lobjs.get(0).t; if (baseT.toString().equals(("java.lang.Object"))) { // look for an array type, because an TTT[] is also an Object... ArrayType aTypeOtherThanObject = null; for (LocalObj lo : local2Obj.get(arBase)) { if (lo.t instanceof ArrayType) { aTypeOtherThanObject = (ArrayType) lo.t; } } if (aTypeOtherThanObject == null) { throw new RuntimeException( "error: did not found array type for base " + arBase + " " + local2Obj.get(arBase) + " \n " + b); } baseT = aTypeOtherThanObject; } ArrayType at = (ArrayType) baseT; newType = at.getElementType(); } else { throw new RuntimeException("error: expected Local or ArrayRef. Got " + r2); } toDo.add((DefinitionStmt) use); DalvikTyper.v().setType(ass2.getLeftOpBox(), newType, true); } } } } } } for (Unit u : todoUnits) { // Debug.printDbg("todo unit: ", u); } while (!todoUnits.isEmpty()) { Unit u = todoUnits.iterator().next(); if (!(u instanceof AssignStmt)) { throw new RuntimeException("error: expecting assign stmt. Got " + u); } AssignStmt ass = (AssignStmt) u; Value l = ass.getLeftOp(); Value r = ass.getRightOp(); ArrayRef ar = null; Local loc = null; if (l instanceof ArrayRef) { ar = (ArrayRef) l; loc = (Local) r; } else if (r instanceof ArrayRef) { ar = (ArrayRef) r; loc = (Local) l; } else { throw new RuntimeException("error: expecting an array ref. Got " + u); } Local baselocal = (Local) ar.getBase(); if (!local2Obj.containsKey(baselocal)) { // Debug.printDbg("oups no baselocal! for ", u); // Debug.printDbg("b: ", b.getMethod(), " \n", b); throw new RuntimeException("oups"); } Type baseT = local2Obj.get(baselocal).get(0).t; if (baseT.toString().equals(("java.lang.Object"))) { // look for an array type, because an TTT[] is also an Object... ArrayType aTypeOtherThanObject = null; for (LocalObj lo : local2Obj.get(baselocal)) { if (lo.t instanceof ArrayType) { aTypeOtherThanObject = (ArrayType) lo.t; } } if (aTypeOtherThanObject == null) { throw new RuntimeException( "did not found array type for base " + baselocal + " " + local2Obj.get(baselocal) + " \n " + b); } baseT = aTypeOtherThanObject; } ArrayType basetype = (ArrayType) baseT; // Debug.printDbg("v: ", ar, " base:", ar.getBase(), " base type: ", basetype, " type: ", ar.getType()); Type t = basetype.getElementType(); if (t instanceof UnknownType) { todoUnits.add(u); continue; } else { DalvikTyper.v().setType(ar == l ? ass.getRightOpBox() : ass.getLeftOpBox(), t, true); todoUnits.remove(u); } } // throw new RuntimeException("ouppppp"); } // Debug.printDbg(IDalvikTyper.DEBUG, "list of constraints:"); List<ValueBox> vbList = b.getUseAndDefBoxes(); // clear constraints after local splitting and dead code eliminator List<Constraint> toRemove = new ArrayList<Constraint>(); for (Constraint c : constraints) { if (!vbList.contains(c.l)) { // Debug.printDbg(IDalvikTyper.DEBUG, "warning: ", c.l, " not in locals! removing..."); toRemove.add(c); continue; } if (!vbList.contains(c.r)) { // Debug.printDbg(IDalvikTyper.DEBUG, "warning: ", c.r, " not in locals! removing..."); toRemove.add(c); continue; } } for (Constraint c : toRemove) { constraints.remove(c); } // keep only valid locals for (LocalObj lo : localObjList) { if (!vbList.contains(lo.vb)) { // Debug.printDbg(IDalvikTyper.DEBUG, " -- removing vb: ", lo.vb, " with type ", lo.t); continue; } Local l = lo.getLocal(); Type t = lo.t; if (localTemp.contains(l) && lo.isUse) { // Debug.printDbg(IDalvikTyper.DEBUG, " /!\\ def already added for local ", l, "! for vb: ", lo.vb); } else { // Debug.printDbg(IDalvikTyper.DEBUG, " * add type ", t, " to local ", l, " for vb: ", lo.vb); localTemp.add(l); typed.put(lo.vb, t); } } for (ValueBox vb : typed.keySet()) { if (vb.getValue() instanceof Local) { Local l = (Local) vb.getValue(); localTyped.put(l, typed.get(vb)); } } for (Constraint c : constraints) { // Debug.printDbg(IDalvikTyper.DEBUG, " -> constraint: ", c); for (ValueBox vb : typed.keySet()) { // Debug.printDbg(IDalvikTyper.DEBUG, " typed: ", vb, " -> ", typed.get(vb)); } } for (Local l : localTyped.keySet()) { // Debug.printDbg(IDalvikTyper.DEBUG, " localTyped: ", l, " -> ", localTyped.get(l)); } while (!constraints.isEmpty()) { boolean update = false; for (Constraint c : constraints) { // Debug.printDbg(IDalvikTyper.DEBUG, "current constraint: ", c); Value l = c.l.getValue(); Value r = c.r.getValue(); if (l instanceof Local && r instanceof Constant) { Constant cst = (Constant) r; if (!localTyped.containsKey(l)) { continue; } Type lt = localTyped.get(l); // Debug.printDbg(IDalvikTyper.DEBUG, "would like to set type ", lt, " to constant: ", c); Value newValue = null; if (lt instanceof IntType || lt instanceof BooleanType || lt instanceof ShortType || lt instanceof CharType || lt instanceof ByteType) { UntypedIntOrFloatConstant uf = (UntypedIntOrFloatConstant) cst; newValue = uf.toIntConstant(); } else if (lt instanceof FloatType) { UntypedIntOrFloatConstant uf = (UntypedIntOrFloatConstant) cst; newValue = uf.toFloatConstant(); } else if (lt instanceof DoubleType) { UntypedLongOrDoubleConstant ud = (UntypedLongOrDoubleConstant) cst; newValue = ud.toDoubleConstant(); } else if (lt instanceof LongType) { UntypedLongOrDoubleConstant ud = (UntypedLongOrDoubleConstant) cst; newValue = ud.toLongConstant(); } else { if (cst instanceof UntypedIntOrFloatConstant && ((UntypedIntOrFloatConstant) cst).value == 0) { newValue = NullConstant.v(); // Debug.printDbg("new null constant for constraint ", c, " with l type: ", localTyped.get(l)); } else { throw new RuntimeException("unknow type for constance: " + lt); } } c.r.setValue(newValue); // Debug.printDbg(IDalvikTyper.DEBUG, "remove constraint: ", c); constraints.remove(c); update = true; break; } else if (l instanceof Local && r instanceof Local) { Local leftLocal = (Local) l; Local rightLocal = (Local) r; if (localTyped.containsKey(leftLocal)) { Type leftLocalType = localTyped.get(leftLocal); if (!localTyped.containsKey(rightLocal)) { // Debug.printDbg(IDalvikTyper.DEBUG, "set type ", leftLocalType, " to local ", rightLocal); rightLocal.setType(leftLocalType); setLocalTyped(rightLocal, leftLocalType); } // Debug.printDbg(IDalvikTyper.DEBUG, "remove constraint: ", c); constraints.remove(c); update = true; break; } else if (localTyped.containsKey(rightLocal)) { Type rightLocalType = localTyped.get(rightLocal); if (!localTyped.containsKey(leftLocal)) { // Debug.printDbg(IDalvikTyper.DEBUG, "set type ", rightLocalType, " to local ", leftLocal); leftLocal.setType(rightLocalType); setLocalTyped(leftLocal, rightLocalType); } // Debug.printDbg(IDalvikTyper.DEBUG, "remove constraint: ", c); constraints.remove(c); update = true; break; } } else if (l instanceof ArrayRef && r instanceof Local) { Local rightLocal = (Local) r; ArrayRef ar = (ArrayRef) l; Local base = (Local) ar.getBase(); // Debug.printDbg(IDalvikTyper.DEBUG, "base: ", base); // Debug.printDbg(IDalvikTyper.DEBUG, "index: ", ar.getIndex()); if (localTyped.containsKey(base)) { Type t = localTyped.get(base); // Debug.printDbg(IDalvikTyper.DEBUG, "type of local1: ", t, " ", t.getClass()); Type elementType = null; if (t instanceof ArrayType) { ArrayType at = (ArrayType) t; elementType = at.getArrayElementType(); } else { continue; } if (!localTyped.containsKey(rightLocal)) { // Debug.printDbg(IDalvikTyper.DEBUG, "set type ", elementType, " to local ", r); rightLocal.setType(elementType); setLocalTyped(rightLocal, elementType); } // Debug.printDbg(IDalvikTyper.DEBUG, "remove constraint: ", c); constraints.remove(c); update = true; break; } } else if (l instanceof Local && r instanceof ArrayRef) { Local leftLocal = (Local) l; ArrayRef ar = (ArrayRef) r; Local base = (Local) ar.getBase(); if (localTyped.containsKey(base)) { Type t = localTyped.get(base); // Debug.printDbg(IDalvikTyper.DEBUG, "type of local2: ", t, " ", t.getClass()); Type elementType = null; if (t instanceof ArrayType) { ArrayType at = (ArrayType) t; elementType = at.getArrayElementType(); } else { continue; } if (!localTyped.containsKey(leftLocal)) { // Debug.printDbg(IDalvikTyper.DEBUG, "set type ", elementType, " to local ", l); leftLocal.setType(elementType); setLocalTyped(leftLocal, elementType); } // Debug.printDbg(IDalvikTyper.DEBUG, "remove constraint: ", c); constraints.remove(c); update = true; break; } } else { throw new RuntimeException("error: do not handling this kind of constraint: " + c); } } if (!update) { break; } } for (Unit u : b.getUnits()) { if (!(u instanceof AssignStmt)) { continue; } AssignStmt ass = (AssignStmt) u; if (!(ass.getLeftOp() instanceof Local)) { continue; } if (!(ass.getRightOp() instanceof UntypedConstant)) { continue; } UntypedConstant uc = (UntypedConstant) ass.getRightOp(); ass.setRightOp(uc.defineType(localTyped.get(ass.getLeftOp()))); } // At this point some constants may be untyped. // (for instance if it is only use in a if condition). // We assume type in integer. // for (Constraint c : constraints) { // Debug.printDbg(IDalvikTyper.DEBUG, "current constraint: ", c); Value l = c.l.getValue(); Value r = c.r.getValue(); if (l instanceof Local && r instanceof Constant) { if (r instanceof UntypedIntOrFloatConstant) { UntypedIntOrFloatConstant cst = (UntypedIntOrFloatConstant) r; Value newValue = null; if (cst.value != 0) { // Debug.printDbg(IDalvikTyper.DEBUG, "[untyped constaints] set type int to non zero constant: ", c, " = ", // cst.value); newValue = cst.toIntConstant(); } else { // check if used in cast, just in case... for (Unit u : b.getUnits()) { for (ValueBox vb1 : u.getUseBoxes()) { Value v1 = vb1.getValue(); if (v1 == l) { // Debug.printDbg("local used in ", u); if (u instanceof AssignStmt) { AssignStmt a = (AssignStmt) u; Value right = a.getRightOp(); if (right instanceof CastExpr) { newValue = NullConstant.v(); } else { newValue = cst.toIntConstant(); } } else if (u instanceof IfStmt) { newValue = cst.toIntConstant();// TODO check this better } } } } } if (newValue == null) { throw new RuntimeException("error: no type found for local: " + l); } c.r.setValue(newValue); } else if (r instanceof UntypedLongOrDoubleConstant) { // Debug.printDbg(IDalvikTyper.DEBUG, "[untyped constaints] set type long to constant: ", c); Value newValue = ((UntypedLongOrDoubleConstant) r).toLongConstant(); c.r.setValue(newValue); } } } // fix untypedconstants which have flown to an array index for (Unit u : b.getUnits()) { StmtSwitch sw = new StmtSwitch() { @Override public void caseBreakpointStmt(BreakpointStmt stmt) { // TODO Auto-generated method stub } @Override public void caseInvokeStmt(InvokeStmt stmt) { changeUntypedConstantsInInvoke(stmt.getInvokeExpr()); } @Override public void caseAssignStmt(AssignStmt stmt) { if (stmt.getRightOp() instanceof NewArrayExpr) { NewArrayExpr nae = (NewArrayExpr) stmt.getRightOp(); if (nae.getSize() instanceof UntypedConstant) { UntypedIntOrFloatConstant uc = (UntypedIntOrFloatConstant) nae.getSize(); nae.setSize(uc.defineType(IntType.v())); } } else if (stmt.getRightOp() instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) stmt.getRightOp(); Value l = stmt.getLeftOp(); Type lType = null; if (l instanceof ArrayRef) { ArrayRef ar = (ArrayRef) l; Local baseLocal = (Local) ar.getBase(); ArrayType arrayType = (ArrayType) localTyped.get(baseLocal); lType = arrayType.getElementType(); } else { lType = l.getType(); } stmt.setRightOp(uc.defineType(lType)); } else if (stmt.getRightOp() instanceof InvokeExpr) { changeUntypedConstantsInInvoke((InvokeExpr) stmt.getRightOp()); } if (!stmt.containsArrayRef()) { return; } ArrayRef ar = stmt.getArrayRef(); if ((ar.getIndex() instanceof UntypedConstant)) { UntypedIntOrFloatConstant uc = (UntypedIntOrFloatConstant) ar.getIndex(); ar.setIndex(uc.toIntConstant()); } if (stmt.getLeftOp() instanceof ArrayRef && stmt.getRightOp() instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) stmt.getRightOp(); Local baseLocal = (Local) stmt.getArrayRef().getBase(); ArrayType lType = (ArrayType) localTyped.get(baseLocal); Type elemType = lType.getElementType(); stmt.setRightOp(uc.defineType(elemType)); } } @Override public void caseIdentityStmt(IdentityStmt stmt) { // TODO Auto-generated method stub } @Override public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { // TODO Auto-generated method stub } @Override public void caseExitMonitorStmt(ExitMonitorStmt stmt) { // TODO Auto-generated method stub } @Override public void caseGotoStmt(GotoStmt stmt) { // TODO Auto-generated method stub } @Override public void caseIfStmt(IfStmt stmt) { Value c = stmt.getCondition(); if (c instanceof BinopExpr) { BinopExpr be = (BinopExpr) c; Value op1 = be.getOp1(); Value op2 = be.getOp2(); if (op1 instanceof UntypedConstant || op2 instanceof UntypedConstant) { // Debug.printDbg("if to handle: ", stmt); if (op1 instanceof Local) { Type t = localTyped.get(op1); // Debug.printDbg("if op1 type: ", t); UntypedConstant uc = (UntypedConstant) op2; be.setOp2(uc.defineType(t)); } else if (op2 instanceof Local) { Type t = localTyped.get(op2); // Debug.printDbg("if op2 type: ", t); UntypedConstant uc = (UntypedConstant) op1; be.setOp1(uc.defineType(t)); } else if (op1 instanceof UntypedConstant && op2 instanceof UntypedConstant) { if (op1 instanceof UntypedIntOrFloatConstant && op2 instanceof UntypedIntOrFloatConstant) { UntypedIntOrFloatConstant uc1 = (UntypedIntOrFloatConstant) op1; UntypedIntOrFloatConstant uc2 = (UntypedIntOrFloatConstant) op2; be.setOp1(uc1.toIntConstant()); // to int or float, it does not matter be.setOp2(uc2.toIntConstant()); } else if (op1 instanceof UntypedLongOrDoubleConstant && op2 instanceof UntypedLongOrDoubleConstant) { UntypedLongOrDoubleConstant uc1 = (UntypedLongOrDoubleConstant) op1; UntypedLongOrDoubleConstant uc2 = (UntypedLongOrDoubleConstant) op2; be.setOp1(uc1.toLongConstant()); // to long or double, it does not matter be.setOp2(uc2.toLongConstant()); } else { throw new RuntimeException("error: expected same type of untyped constants. Got " + stmt); } } else if (op1 instanceof UntypedConstant || op2 instanceof UntypedConstant) { if (op1 instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) op1; be.setOp1(uc.defineType(op2.getType())); } else if (op2 instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) op2; be.setOp2(uc.defineType(op1.getType())); } } else { throw new RuntimeException("error: expected local/untyped untyped/local or untyped/untyped. Got " + stmt); } } } else if (c instanceof UnopExpr) { } else { throw new RuntimeException("error: expected binop or unop. Got " + stmt); } } @Override public void caseLookupSwitchStmt(LookupSwitchStmt stmt) { // TODO Auto-generated method stub } @Override public void caseNopStmt(NopStmt stmt) { // TODO Auto-generated method stub } @Override public void caseRetStmt(RetStmt stmt) { // TODO Auto-generated method stub } @Override public void caseReturnStmt(ReturnStmt stmt) { if (stmt.getOp() instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) stmt.getOp(); Type type = b.getMethod().getReturnType(); stmt.setOp(uc.defineType(type)); } } @Override public void caseReturnVoidStmt(ReturnVoidStmt stmt) { // TODO Auto-generated method stub } @Override public void caseTableSwitchStmt(TableSwitchStmt stmt) { // TODO Auto-generated method stub } @Override public void caseThrowStmt(ThrowStmt stmt) { // TODO Auto-generated method stub } @Override public void defaultCase(Object obj) { // TODO Auto-generated method stub } }; u.apply(sw); } // fix untyped constants remaining // Debug.printDbg("assignTypes: after: \n", b); } private void changeUntypedConstantsInInvoke(InvokeExpr invokeExpr) { for (int i = 0; i < invokeExpr.getArgCount(); i++) { Value v = invokeExpr.getArg(i); if (!(v instanceof UntypedConstant)) { continue; } Type t = invokeExpr.getMethodRef().parameterType(i); UntypedConstant uc = (UntypedConstant) v; invokeExpr.setArg(i, uc.defineType(t)); } } protected void checkExpr(Value v, Type t) { for (ValueBox vb : v.getUseBoxes()) { Value value = vb.getValue(); if (value instanceof Local) { // special case where the second operand is always of type integer if ((v instanceof ShrExpr || v instanceof ShlExpr || v instanceof UshrExpr) && ((BinopExpr) v).getOp2() == value) { // Debug.printDbg("setting type of operand two of shift expression to integer", value); DalvikTyper.v().setType(vb, IntType.v(), true); continue; } DalvikTyper.v().setType(vb, t, true); } else if (value instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) value; // special case where the second operand is always of type integer if ((v instanceof ShrExpr || v instanceof ShlExpr || v instanceof UshrExpr) && ((BinopExpr) v).getOp2() == value) { UntypedIntOrFloatConstant ui = (UntypedIntOrFloatConstant) uc; vb.setValue(ui.toIntConstant()); continue; } vb.setValue(uc.defineType(t)); } } } protected void setInvokeType(InvokeExpr invokeExpr) { for (int i = 0; i < invokeExpr.getArgCount(); i++) { Value v = invokeExpr.getArg(i); if (!(v instanceof Local)) { continue; } Type t = invokeExpr.getMethodRef().parameterType(i); DalvikTyper.v().setType(invokeExpr.getArgBox(i), t, true); } if (invokeExpr instanceof StaticInvokeExpr) { // nothing to do } else if (invokeExpr instanceof InstanceInvokeExpr) { InstanceInvokeExpr iie = (InstanceInvokeExpr) invokeExpr; DalvikTyper.v().setType(iie.getBaseBox(), RefType.v("java.lang.Object"), true); } else if (invokeExpr instanceof DynamicInvokeExpr) { DynamicInvokeExpr die = (DynamicInvokeExpr) invokeExpr; // ? } else { throw new RuntimeException("error: unhandled invoke expression: " + invokeExpr + " " + invokeExpr.getClass()); } } private void setLocalTyped(Local l, Type t) { localTyped.put(l, t); } class LocalObj { ValueBox vb; Type t; // private Local l; boolean isUse; public LocalObj(ValueBox vb, Type t, boolean isUse) { this.vb = vb; // this.l = (Local)vb.getValue(); this.t = t; this.isUse = isUse; } public Local getLocal() { return (Local) vb.getValue(); } } class Constraint { ValueBox l; ValueBox r; public Constraint(ValueBox l, ValueBox r) { this.l = l; this.r = r; } @Override public String toString() { return l + " < " + r; } } // this is needed because UnuesedStatementTransformer checks types in the div expressions public void typeUntypedConstrantInDiv(final Body b) { for (Unit u : b.getUnits()) { StmtSwitch sw = new StmtSwitch() { @Override public void caseBreakpointStmt(BreakpointStmt stmt) { // TODO Auto-generated method stub } @Override public void caseInvokeStmt(InvokeStmt stmt) { changeUntypedConstantsInInvoke(stmt.getInvokeExpr()); } @Override public void caseAssignStmt(AssignStmt stmt) { if (stmt.getRightOp() instanceof NewArrayExpr) { NewArrayExpr nae = (NewArrayExpr) stmt.getRightOp(); if (nae.getSize() instanceof UntypedConstant) { UntypedIntOrFloatConstant uc = (UntypedIntOrFloatConstant) nae.getSize(); nae.setSize(uc.defineType(IntType.v())); } } else if (stmt.getRightOp() instanceof InvokeExpr) { changeUntypedConstantsInInvoke((InvokeExpr) stmt.getRightOp()); } else if (stmt.getRightOp() instanceof CastExpr) { CastExpr ce = (CastExpr) stmt.getRightOp(); if (ce.getOp() instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) ce.getOp(); // check incoming primitive type for (Tag t : stmt.getTags()) { // Debug.printDbg("assign primitive type from stmt tag: ", stmt, t); if (t instanceof IntOpTag) { ce.setOp(uc.defineType(IntType.v())); return; } else if (t instanceof FloatOpTag) { ce.setOp(uc.defineType(FloatType.v())); return; } else if (t instanceof DoubleOpTag) { ce.setOp(uc.defineType(DoubleType.v())); return; } else if (t instanceof LongOpTag) { ce.setOp(uc.defineType(LongType.v())); return; } } // 0 -> null ce.setOp(uc.defineType(RefType.v("java.lang.Object"))); } } if (stmt.containsArrayRef()) { ArrayRef ar = stmt.getArrayRef(); if ((ar.getIndex() instanceof UntypedConstant)) { UntypedIntOrFloatConstant uc = (UntypedIntOrFloatConstant) ar.getIndex(); ar.setIndex(uc.toIntConstant()); } } Value r = stmt.getRightOp(); if (r instanceof DivExpr || r instanceof RemExpr) { // DivExpr de = (DivExpr) r; for (Tag t : stmt.getTags()) { // Debug.printDbg("div stmt tag: ", stmt, t); if (t instanceof IntOpTag) { checkExpr(r, IntType.v()); return; } else if (t instanceof FloatOpTag) { checkExpr(r, FloatType.v()); return; } else if (t instanceof DoubleOpTag) { checkExpr(r, DoubleType.v()); return; } else if (t instanceof LongOpTag) { checkExpr(r, LongType.v()); return; } } } } @Override public void caseIdentityStmt(IdentityStmt stmt) { // TODO Auto-generated method stub } @Override public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { // TODO Auto-generated method stub } @Override public void caseExitMonitorStmt(ExitMonitorStmt stmt) { // TODO Auto-generated method stub } @Override public void caseGotoStmt(GotoStmt stmt) { // TODO Auto-generated method stub } @Override public void caseIfStmt(IfStmt stmt) { // TODO Auto-generated method stub } @Override public void caseLookupSwitchStmt(LookupSwitchStmt stmt) { // TODO Auto-generated method stub } @Override public void caseNopStmt(NopStmt stmt) { // TODO Auto-generated method stub } @Override public void caseRetStmt(RetStmt stmt) { // TODO Auto-generated method stub } @Override public void caseReturnStmt(ReturnStmt stmt) { if (stmt.getOp() instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) stmt.getOp(); Type type = b.getMethod().getReturnType(); stmt.setOp(uc.defineType(type)); } } @Override public void caseReturnVoidStmt(ReturnVoidStmt stmt) { // TODO Auto-generated method stub } @Override public void caseTableSwitchStmt(TableSwitchStmt stmt) { // TODO Auto-generated method stub } @Override public void caseThrowStmt(ThrowStmt stmt) { if (stmt.getOp() instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) stmt.getOp(); stmt.setOp(uc.defineType(RefType.v("java.lang.Object"))); } } @Override public void defaultCase(Object obj) { // TODO Auto-generated method stub } }; u.apply(sw); } } }
44,585
33.323326
125
java
soot
soot-master/src/main/java/soot/dexpler/typing/UntypedConstant.java
package soot.dexpler.typing; /*- * #%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 soot.Type; import soot.Value; import soot.jimple.Constant; import soot.util.Switch; public abstract class UntypedConstant extends Constant { /** * */ private static final long serialVersionUID = -742448859930407635L; @Override public Type getType() { throw new RuntimeException("no type yet!"); } @Override public void apply(Switch sw) { } public abstract Value defineType(Type type); }
1,273
26.106383
71
java
soot
soot-master/src/main/java/soot/dexpler/typing/UntypedIntOrFloatConstant.java
package soot.dexpler.typing; /*- * #%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 soot.BooleanType; import soot.ByteType; import soot.CharType; import soot.FloatType; import soot.IntType; import soot.RefLikeType; import soot.ShortType; import soot.Type; import soot.Value; import soot.jimple.FloatConstant; import soot.jimple.IntConstant; import soot.jimple.NullConstant; public class UntypedIntOrFloatConstant extends UntypedConstant { /** * */ private static final long serialVersionUID = 4413439694269487822L; public final int value; private UntypedIntOrFloatConstant(int value) { this.value = value; } public static UntypedIntOrFloatConstant v(int value) { return new UntypedIntOrFloatConstant(value); } @Override public boolean equals(Object c) { return c instanceof UntypedIntOrFloatConstant && ((UntypedIntOrFloatConstant) c).value == this.value; } /** Returns a hash code for this DoubleConstant object. */ @Override public int hashCode() { return (int) (value ^ (value >>> 32)); } public FloatConstant toFloatConstant() { return FloatConstant.v(Float.intBitsToFloat((int) value)); } public IntConstant toIntConstant() { return IntConstant.v(value); } @Override public Value defineType(Type t) { if (t instanceof FloatType) { return this.toFloatConstant(); } else if (t instanceof IntType || t instanceof CharType || t instanceof BooleanType || t instanceof ByteType || t instanceof ShortType) { return this.toIntConstant(); } else { if (value == 0 && t instanceof RefLikeType) { return NullConstant.v(); } // if the value is only used in a if to compare against another integer, then use default type of integer if (t == null) { return this.toIntConstant(); } throw new RuntimeException("error: expected Float type or Int-like type. Got " + t); } } }
2,700
28.358696
113
java
soot
soot-master/src/main/java/soot/dexpler/typing/UntypedLongOrDoubleConstant.java
package soot.dexpler.typing; /*- * #%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 soot.DoubleType; import soot.LongType; import soot.Type; import soot.Value; import soot.jimple.DoubleConstant; import soot.jimple.LongConstant; public class UntypedLongOrDoubleConstant extends UntypedConstant { /** * */ private static final long serialVersionUID = -3970057807907204253L; public final long value; private UntypedLongOrDoubleConstant(long value) { this.value = value; } public static UntypedLongOrDoubleConstant v(long value) { return new UntypedLongOrDoubleConstant(value); } @Override public boolean equals(Object c) { return c instanceof UntypedLongOrDoubleConstant && ((UntypedLongOrDoubleConstant) c).value == this.value; } /** Returns a hash code for this DoubleConstant object. */ @Override public int hashCode() { return (int) (value ^ (value >>> 32)); } public DoubleConstant toDoubleConstant() { return DoubleConstant.v(Double.longBitsToDouble(value)); } public LongConstant toLongConstant() { return LongConstant.v(value); } @Override public Value defineType(Type t) { if (t instanceof DoubleType) { return this.toDoubleConstant(); } else if (t instanceof LongType) { return this.toLongConstant(); } else { throw new RuntimeException("error: expected Double type or Long type. Got " + t); } } }
2,190
27.089744
109
java
soot
soot-master/src/main/java/soot/dexpler/typing/Validate.java
package soot.dexpler.typing; /*- * #%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.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import soot.ArrayType; import soot.Body; import soot.G; import soot.Local; import soot.RefType; import soot.Scene; import soot.SootClass; import soot.SootMethodRef; import soot.SootResolver; import soot.Type; import soot.Unit; import soot.Value; import soot.ValueBox; import soot.VoidType; import soot.jimple.ArrayRef; import soot.jimple.AssignStmt; import soot.jimple.CastExpr; import soot.jimple.Constant; import soot.jimple.DefinitionStmt; import soot.jimple.FieldRef; import soot.jimple.IdentityRef; import soot.jimple.IdentityStmt; import soot.jimple.InvokeExpr; import soot.jimple.Jimple; import soot.jimple.NewArrayExpr; import soot.jimple.StringConstant; import soot.jimple.toolkits.scalar.DeadAssignmentEliminator; import soot.jimple.toolkits.scalar.NopEliminator; import soot.jimple.toolkits.scalar.UnreachableCodeEliminator; import soot.toolkits.scalar.LocalDefs; import soot.toolkits.scalar.UnusedLocalEliminator; public class Validate { public static void validateArrays(Body b) { Set<DefinitionStmt> definitions = new HashSet<DefinitionStmt>(); Set<Unit> unitWithArrayRef = new HashSet<Unit>(); for (Unit u : b.getUnits()) { if (u instanceof DefinitionStmt) { DefinitionStmt s = (DefinitionStmt) u; definitions.add(s); } List<ValueBox> uses = u.getUseBoxes(); for (ValueBox vb : uses) { Value v = vb.getValue(); if (v instanceof ArrayRef) { unitWithArrayRef.add(u); } } } final LocalDefs localDefs = G.v().soot_toolkits_scalar_LocalDefsFactory().newLocalDefs(b, true); Set<Unit> toReplace = new HashSet<Unit>(); for (Unit u : unitWithArrayRef) { boolean ok = false; List<ValueBox> uses = u.getUseBoxes(); for (ValueBox vb : uses) { Value v = vb.getValue(); if (v instanceof ArrayRef) { ArrayRef ar = (ArrayRef) v; Local base = (Local) ar.getBase(); List<Unit> defs = localDefs.getDefsOfAt(base, u); // add aliases Set<Unit> alreadyHandled = new HashSet<Unit>(); while (true) { boolean isMore = false; for (Unit d : defs) { if (alreadyHandled.contains(d)) { continue; } if (d instanceof AssignStmt) { AssignStmt ass = (AssignStmt) d; Value r = ass.getRightOp(); if (r instanceof Local) { defs.addAll(localDefs.getDefsOfAt((Local) r, d)); alreadyHandled.add(d); isMore = true; break; } else if (r instanceof ArrayRef) { ArrayRef arrayRef = (ArrayRef) r; Local l = (Local) arrayRef.getBase(); defs.addAll(localDefs.getDefsOfAt(l, d)); alreadyHandled.add(d); isMore = true; break; } } } if (!isMore) { break; } } // System.out.println("def size "+ defs.size()); for (Unit def : defs) { // System.out.println("def u "+ def); Value r = null; if (def instanceof IdentityStmt) { IdentityStmt idstmt = (IdentityStmt) def; r = idstmt.getRightOp(); } else if (def instanceof AssignStmt) { AssignStmt assStmt = (AssignStmt) def; r = assStmt.getRightOp(); } else { throw new RuntimeException("error: definition statement not an IdentityStmt nor an AssignStmt! " + def); } Type t = null; if (r instanceof InvokeExpr) { InvokeExpr ie = (InvokeExpr) r; t = ie.getType(); // System.out.println("ie type: "+ t +" "+ t.getClass()); if (t instanceof ArrayType) { ok = true; } } else if (r instanceof FieldRef) { FieldRef ref = (FieldRef) r; t = ref.getType(); // System.out.println("fr type: "+ t +" "+ t.getClass()); if (t instanceof ArrayType) { ok = true; } } else if (r instanceof IdentityRef) { IdentityRef ir = (IdentityRef) r; t = ir.getType(); if (t instanceof ArrayType) { ok = true; } } else if (r instanceof CastExpr) { CastExpr c = (CastExpr) r; t = c.getType(); if (t instanceof ArrayType) { ok = true; } } else if (r instanceof ArrayRef) { // we also check that this arrayref is correctly defined } else if (r instanceof NewArrayExpr) { ok = true; } else if (r instanceof Local) { } else if (r instanceof Constant) { } else { throw new RuntimeException("error: unknown right hand side of definition stmt " + def); } if (ok) { break; } } if (ok) { break; } } } if (!ok) { toReplace.add(u); } } int i = 0; for (Unit u : toReplace) { System.out.println("warning: incorrect array def, replacing unit " + u); // new object RefType throwableType = RefType.v("java.lang.Throwable"); Local ttt = Jimple.v().newLocal("ttt_" + ++i, throwableType); b.getLocals().add(ttt); Value r = Jimple.v().newNewExpr(throwableType); Unit initLocalUnit = Jimple.v().newAssignStmt(ttt, r); // call <init> method with a string parameter for message List<String> pTypes = new ArrayList<String>(); pTypes.add("java.lang.String"); boolean isStatic = false; SootMethodRef mRef = Validate.makeMethodRef("java.lang.Throwable", "<init>", "", pTypes, isStatic); List<Value> parameters = new ArrayList<Value>(); parameters.add(StringConstant.v("Soot updated this instruction")); InvokeExpr ie = Jimple.v().newSpecialInvokeExpr(ttt, mRef, parameters); Unit initMethod = Jimple.v().newInvokeStmt(ie); // throw exception Unit newUnit = Jimple.v().newThrowStmt(ttt); // change instruction in body b.getUnits().swapWith(u, newUnit); b.getUnits().insertBefore(initMethod, newUnit); b.getUnits().insertBefore(initLocalUnit, initMethod); // Exception a = throw new Exception(); } DeadAssignmentEliminator.v().transform(b); UnusedLocalEliminator.v().transform(b); NopEliminator.v().transform(b); UnreachableCodeEliminator.v().transform(b); } public static SootMethodRef makeMethodRef(String cName, String mName, String rType, List<String> pTypes, boolean isStatic) { SootClass sc = SootResolver.v().makeClassRef(cName); Type returnType = null; if (rType == "") { returnType = VoidType.v(); } else { returnType = RefType.v(rType); } List<Type> parameterTypes = new ArrayList<Type>(); for (String p : pTypes) { parameterTypes.add(RefType.v(p)); } return Scene.v().makeMethodRef(sc, mName, parameterTypes, returnType, isStatic); } }
8,287
32.01992
118
java
soot
soot-master/src/main/java/soot/grimp/AbstractGrimpValueSwitch.java
package soot.grimp; /*- * #%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.jimple.AbstractJimpleValueSwitch; public abstract class AbstractGrimpValueSwitch<T> extends AbstractJimpleValueSwitch<T> implements GrimpValueSwitch { @Override public void caseNewInvokeExpr(NewInvokeExpr e) { defaultCase(e); } }
1,081
31.787879
116
java
soot
soot-master/src/main/java/soot/grimp/Grimp.java
package soot.grimp; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam * 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.ArrayList; import java.util.List; import soot.ArrayType; import soot.Body; import soot.G; import soot.Local; import soot.RefType; import soot.Singletons; 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.Value; import soot.ValueBox; import soot.grimp.internal.ExprBox; import soot.grimp.internal.GAddExpr; import soot.grimp.internal.GAndExpr; import soot.grimp.internal.GArrayRef; import soot.grimp.internal.GAssignStmt; import soot.grimp.internal.GCastExpr; import soot.grimp.internal.GCmpExpr; import soot.grimp.internal.GCmpgExpr; import soot.grimp.internal.GCmplExpr; import soot.grimp.internal.GDivExpr; import soot.grimp.internal.GDynamicInvokeExpr; import soot.grimp.internal.GEnterMonitorStmt; import soot.grimp.internal.GEqExpr; import soot.grimp.internal.GExitMonitorStmt; import soot.grimp.internal.GGeExpr; import soot.grimp.internal.GGtExpr; import soot.grimp.internal.GIdentityStmt; import soot.grimp.internal.GIfStmt; import soot.grimp.internal.GInstanceFieldRef; import soot.grimp.internal.GInstanceOfExpr; import soot.grimp.internal.GInterfaceInvokeExpr; import soot.grimp.internal.GInvokeStmt; import soot.grimp.internal.GLeExpr; import soot.grimp.internal.GLengthExpr; import soot.grimp.internal.GLookupSwitchStmt; import soot.grimp.internal.GLtExpr; import soot.grimp.internal.GMulExpr; import soot.grimp.internal.GNeExpr; import soot.grimp.internal.GNegExpr; import soot.grimp.internal.GNewArrayExpr; import soot.grimp.internal.GNewInvokeExpr; import soot.grimp.internal.GNewMultiArrayExpr; import soot.grimp.internal.GOrExpr; import soot.grimp.internal.GRValueBox; import soot.grimp.internal.GRemExpr; import soot.grimp.internal.GReturnStmt; import soot.grimp.internal.GShlExpr; import soot.grimp.internal.GShrExpr; import soot.grimp.internal.GSpecialInvokeExpr; import soot.grimp.internal.GStaticInvokeExpr; import soot.grimp.internal.GSubExpr; import soot.grimp.internal.GTableSwitchStmt; import soot.grimp.internal.GThrowStmt; import soot.grimp.internal.GTrap; import soot.grimp.internal.GUshrExpr; import soot.grimp.internal.GVirtualInvokeExpr; import soot.grimp.internal.GXorExpr; import soot.grimp.internal.ObjExprBox; import soot.jimple.AbstractExprSwitch; import soot.jimple.AddExpr; import soot.jimple.AndExpr; import soot.jimple.ArrayRef; import soot.jimple.AssignStmt; import soot.jimple.BreakpointStmt; import soot.jimple.CastExpr; import soot.jimple.CaughtExceptionRef; import soot.jimple.CmpExpr; import soot.jimple.CmpgExpr; import soot.jimple.CmplExpr; import soot.jimple.Constant; import soot.jimple.DivExpr; import soot.jimple.DynamicInvokeExpr; import soot.jimple.EnterMonitorStmt; import soot.jimple.EqExpr; import soot.jimple.ExitMonitorStmt; import soot.jimple.Expr; import soot.jimple.GeExpr; import soot.jimple.GotoStmt; import soot.jimple.GtExpr; import soot.jimple.IdentityStmt; import soot.jimple.IfStmt; import soot.jimple.InstanceFieldRef; import soot.jimple.InstanceOfExpr; import soot.jimple.IntConstant; import soot.jimple.InterfaceInvokeExpr; import soot.jimple.InvokeStmt; import soot.jimple.Jimple; import soot.jimple.LeExpr; import soot.jimple.LengthExpr; import soot.jimple.LookupSwitchStmt; import soot.jimple.LtExpr; import soot.jimple.MulExpr; import soot.jimple.NeExpr; import soot.jimple.NegExpr; import soot.jimple.NewArrayExpr; import soot.jimple.NewExpr; import soot.jimple.NewMultiArrayExpr; import soot.jimple.NopStmt; import soot.jimple.OrExpr; import soot.jimple.ParameterRef; import soot.jimple.RemExpr; import soot.jimple.ReturnStmt; import soot.jimple.ReturnVoidStmt; import soot.jimple.ShlExpr; import soot.jimple.ShrExpr; import soot.jimple.SpecialInvokeExpr; import soot.jimple.StaticFieldRef; import soot.jimple.StaticInvokeExpr; import soot.jimple.SubExpr; import soot.jimple.TableSwitchStmt; import soot.jimple.ThisRef; import soot.jimple.ThrowStmt; import soot.jimple.UshrExpr; import soot.jimple.VirtualInvokeExpr; import soot.jimple.XorExpr; /** * The Grimp class contains all the constructors for the components of the Grimp grammar for the Grimp body. <br> * <br> * * Immediate -> Local | Constant <br> * RValue -> Local | Constant | ConcreteRef | Expr<br> * Variable -> Local | ArrayRef | InstanceFieldRef | StaticFieldRef <br> */ public class Grimp { public Grimp(Singletons.Global g) { } public static Grimp v() { return G.v().soot_grimp_Grimp(); } /** * Constructs a XorExpr(Expr, Expr) grammar chunk. */ public XorExpr newXorExpr(Value op1, Value op2) { return new GXorExpr(op1, op2); } /** * Constructs a UshrExpr(Expr, Expr) grammar chunk. */ public UshrExpr newUshrExpr(Value op1, Value op2) { return new GUshrExpr(op1, op2); } /** * Constructs a SubExpr(Expr, Expr) grammar chunk. */ public SubExpr newSubExpr(Value op1, Value op2) { return new GSubExpr(op1, op2); } /** * Constructs a ShrExpr(Expr, Expr) grammar chunk. */ public ShrExpr newShrExpr(Value op1, Value op2) { return new GShrExpr(op1, op2); } /** * Constructs a ShlExpr(Expr, Expr) grammar chunk. */ public ShlExpr newShlExpr(Value op1, Value op2) { return new GShlExpr(op1, op2); } /** * Constructs a RemExpr(Expr, Expr) grammar chunk. */ public RemExpr newRemExpr(Value op1, Value op2) { return new GRemExpr(op1, op2); } /** * Constructs a OrExpr(Expr, Expr) grammar chunk. */ public OrExpr newOrExpr(Value op1, Value op2) { return new GOrExpr(op1, op2); } /** * Constructs a NeExpr(Expr, Expr) grammar chunk. */ public NeExpr newNeExpr(Value op1, Value op2) { return new GNeExpr(op1, op2); } /** * Constructs a MulExpr(Expr, Expr) grammar chunk. */ public MulExpr newMulExpr(Value op1, Value op2) { return new GMulExpr(op1, op2); } /** * Constructs a LeExpr(Expr, Expr) grammar chunk. */ public LeExpr newLeExpr(Value op1, Value op2) { return new GLeExpr(op1, op2); } /** * Constructs a GeExpr(Expr, Expr) grammar chunk. */ public GeExpr newGeExpr(Value op1, Value op2) { return new GGeExpr(op1, op2); } /** * Constructs a EqExpr(Expr, Expr) grammar chunk. */ public EqExpr newEqExpr(Value op1, Value op2) { return new GEqExpr(op1, op2); } /** * Constructs a DivExpr(Expr, Expr) grammar chunk. */ public DivExpr newDivExpr(Value op1, Value op2) { return new GDivExpr(op1, op2); } /** * Constructs a CmplExpr(Expr, Expr) grammar chunk. */ public CmplExpr newCmplExpr(Value op1, Value op2) { return new GCmplExpr(op1, op2); } /** * Constructs a CmpgExpr(Expr, Expr) grammar chunk. */ public CmpgExpr newCmpgExpr(Value op1, Value op2) { return new GCmpgExpr(op1, op2); } /** * Constructs a CmpExpr(Expr, Expr) grammar chunk. */ public CmpExpr newCmpExpr(Value op1, Value op2) { return new GCmpExpr(op1, op2); } /** * Constructs a GtExpr(Expr, Expr) grammar chunk. */ public GtExpr newGtExpr(Value op1, Value op2) { return new GGtExpr(op1, op2); } /** * Constructs a LtExpr(Expr, Expr) grammar chunk. */ public LtExpr newLtExpr(Value op1, Value op2) { return new GLtExpr(op1, op2); } /** * Constructs a AddExpr(Expr, Expr) grammar chunk. */ public AddExpr newAddExpr(Value op1, Value op2) { return new GAddExpr(op1, op2); } /** * Constructs a AndExpr(Expr, Expr) grammar chunk. */ public AndExpr newAndExpr(Value op1, Value op2) { return new GAndExpr(op1, op2); } /** * Constructs a NegExpr(Expr, Expr) grammar chunk. */ public NegExpr newNegExpr(Value op) { return new GNegExpr(op); } /** * Constructs a LengthExpr(Expr) grammar chunk. */ public LengthExpr newLengthExpr(Value op) { return new GLengthExpr(op); } /** * Constructs a CastExpr(Expr, Type) grammar chunk. */ public CastExpr newCastExpr(Value op1, Type t) { return new GCastExpr(op1, t); } /** * Constructs a InstanceOfExpr(Expr, Type) grammar chunk. */ public InstanceOfExpr newInstanceOfExpr(Value op1, Type t) { return new GInstanceOfExpr(op1, t); } /** * Constructs a NewExpr(RefType) grammar chunk. */ NewExpr newNewExpr(RefType type) { return Jimple.v().newNewExpr(type); } /** * Constructs a NewArrayExpr(Type, Expr) grammar chunk. */ public NewArrayExpr newNewArrayExpr(Type type, Value size) { return new GNewArrayExpr(type, size); } /** * Constructs a NewMultiArrayExpr(ArrayType, List of Expr) grammar chunk. */ public NewMultiArrayExpr newNewMultiArrayExpr(ArrayType type, List sizes) { return new GNewMultiArrayExpr(type, sizes); } /** * Constructs a NewInvokeExpr(Local base, List of Expr) grammar chunk. */ public NewInvokeExpr newNewInvokeExpr(RefType base, SootMethodRef method, List args) { return new GNewInvokeExpr(base, method, args); } /** * Constructs a StaticInvokeExpr(ArrayType, List of Expr) grammar chunk. */ public StaticInvokeExpr newStaticInvokeExpr(SootMethodRef method, List args) { return new GStaticInvokeExpr(method, args); } /** * Constructs a SpecialInvokeExpr(Local base, SootMethodRef method, List of Expr) grammar chunk. */ public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethodRef method, List args) { return new GSpecialInvokeExpr(base, method, args); } /** * Constructs a VirtualInvokeExpr(Local base, SootMethodRef method, List of Expr) grammar chunk. */ public VirtualInvokeExpr newVirtualInvokeExpr(Local base, SootMethodRef method, List args) { return new GVirtualInvokeExpr(base, method, args); } /** * Constructs a new DynamicInvokeExpr grammar chunk. */ public DynamicInvokeExpr newDynamicInvokeExpr(SootMethodRef bootstrapMethodRef, List<Value> bootstrapArgs, SootMethodRef methodRef, int tag, List args) { return new GDynamicInvokeExpr(bootstrapMethodRef, bootstrapArgs, methodRef, tag, args); } /** * Constructs a InterfaceInvokeExpr(Local base, SootMethodRef method, List of Expr) grammar chunk. */ public InterfaceInvokeExpr newInterfaceInvokeExpr(Local base, SootMethodRef method, List args) { return new GInterfaceInvokeExpr(base, method, args); } /** * Constructs a ThrowStmt(Expr) grammar chunk. */ public ThrowStmt newThrowStmt(Value op) { return new GThrowStmt(op); } public ThrowStmt newThrowStmt(ThrowStmt s) { return new GThrowStmt(s.getOp()); } /** * Constructs a ExitMonitorStmt(Expr) grammar chunk */ public ExitMonitorStmt newExitMonitorStmt(Value op) { return new GExitMonitorStmt(op); } public ExitMonitorStmt newExitMonitorStmt(ExitMonitorStmt s) { return new GExitMonitorStmt(s.getOp()); } /** * Constructs a EnterMonitorStmt(Expr) grammar chunk. */ public EnterMonitorStmt newEnterMonitorStmt(Value op) { return new GEnterMonitorStmt(op); } public EnterMonitorStmt newEnterMonitorStmt(EnterMonitorStmt s) { return new GEnterMonitorStmt(s.getOp()); } /** * Constructs a BreakpointStmt() grammar chunk. */ public BreakpointStmt newBreakpointStmt() { return Jimple.v().newBreakpointStmt(); } public BreakpointStmt newBreakpointStmt(BreakpointStmt s) { return Jimple.v().newBreakpointStmt(); } /** * Constructs a GotoStmt(Stmt) grammar chunk. */ public GotoStmt newGotoStmt(Unit target) { return Jimple.v().newGotoStmt(target); } public GotoStmt newGotoStmt(GotoStmt s) { return Jimple.v().newGotoStmt(s.getTarget()); } /** * Constructs a NopStmt() grammar chunk. */ public NopStmt newNopStmt() { return Jimple.v().newNopStmt(); } public NopStmt newNopStmt(NopStmt s) { return Jimple.v().newNopStmt(); } /** * Constructs a ReturnVoidStmt() grammar chunk. */ public ReturnVoidStmt newReturnVoidStmt() { return Jimple.v().newReturnVoidStmt(); } public ReturnVoidStmt newReturnVoidStmt(ReturnVoidStmt s) { return Jimple.v().newReturnVoidStmt(); } /** * Constructs a ReturnStmt(Expr) grammar chunk. */ public ReturnStmt newReturnStmt(Value op) { return new GReturnStmt(op); } public ReturnStmt newReturnStmt(ReturnStmt s) { return new GReturnStmt(s.getOp()); } /** * Constructs a IfStmt(Condition, Stmt) grammar chunk. */ public IfStmt newIfStmt(Value condition, Unit target) { return new GIfStmt(condition, target); } public IfStmt newIfStmt(IfStmt s) { return new GIfStmt(s.getCondition(), s.getTarget()); } /** * Constructs a IdentityStmt(Local, IdentityRef) grammar chunk. */ public IdentityStmt newIdentityStmt(Value local, Value identityRef) { return new GIdentityStmt(local, identityRef); } public IdentityStmt newIdentityStmt(IdentityStmt s) { return new GIdentityStmt(s.getLeftOp(), s.getRightOp()); } /** * Constructs a AssignStmt(Variable, RValue) grammar chunk. */ public AssignStmt newAssignStmt(Value variable, Value rvalue) { return new GAssignStmt(variable, rvalue); } public AssignStmt newAssignStmt(AssignStmt s) { return new GAssignStmt(s.getLeftOp(), s.getRightOp()); } /** * Constructs a InvokeStmt(InvokeExpr) grammar chunk. */ public InvokeStmt newInvokeStmt(Value op) { return new GInvokeStmt(op); } public InvokeStmt newInvokeStmt(InvokeStmt s) { return new GInvokeStmt(s.getInvokeExpr()); } /** * Constructs a TableSwitchStmt(Expr, int, int, List of Unit, Stmt) grammar chunk. */ public TableSwitchStmt newTableSwitchStmt(Value key, int lowIndex, int highIndex, List targets, Unit defaultTarget) { return new GTableSwitchStmt(key, lowIndex, highIndex, targets, defaultTarget); } public TableSwitchStmt newTableSwitchStmt(TableSwitchStmt s) { return new GTableSwitchStmt(s.getKey(), s.getLowIndex(), s.getHighIndex(), s.getTargets(), s.getDefaultTarget()); } /** * Constructs a LookupSwitchStmt(Expr, List of Expr, List of Unit, Stmt) grammar chunk. */ public LookupSwitchStmt newLookupSwitchStmt(Value key, List lookupValues, List targets, Unit defaultTarget) { return new GLookupSwitchStmt(key, lookupValues, targets, defaultTarget); } public LookupSwitchStmt newLookupSwitchStmt(LookupSwitchStmt s) { return new GLookupSwitchStmt(s.getKey(), s.getLookupValues(), s.getTargets(), s.getDefaultTarget()); } /** * Constructs a Local with the given name and type. */ public Local newLocal(String name, Type t) { return Jimple.v().newLocal(name, t); } /** * Constructs a new Trap for the given exception on the given Stmt range with the given Stmt handler. */ public Trap newTrap(SootClass exception, Unit beginStmt, Unit endStmt, Unit handlerStmt) { return new GTrap(exception, beginStmt, endStmt, handlerStmt); } public Trap newTrap(Trap trap) { return new GTrap(trap.getException(), trap.getBeginUnit(), trap.getEndUnit(), trap.getHandlerUnit()); } /** * Constructs a StaticFieldRef(SootFieldRef) grammar chunk. */ public StaticFieldRef newStaticFieldRef(SootFieldRef f) { return Jimple.v().newStaticFieldRef(f); } /** * Constructs a ThisRef(RefType) grammar chunk. */ public ThisRef newThisRef(RefType t) { return Jimple.v().newThisRef(t); } /** * Constructs a ParameterRef(SootMethod, int) grammar chunk. */ public ParameterRef newParameterRef(Type paramType, int number) { return Jimple.v().newParameterRef(paramType, number); } /** * Constructs a InstanceFieldRef(Value, SootFieldRef) grammar chunk. */ public InstanceFieldRef newInstanceFieldRef(Value base, SootFieldRef f) { return new GInstanceFieldRef(base, f); } /** * Constructs a CaughtExceptionRef() grammar chunk. */ public CaughtExceptionRef newCaughtExceptionRef() { return Jimple.v().newCaughtExceptionRef(); } /** * Constructs a ArrayRef(Local, Expr) grammar chunk. */ public ArrayRef newArrayRef(Value base, Value index) { return new GArrayRef(base, index); } public ValueBox newVariableBox(Value value) { return Jimple.v().newVariableBox(value); } public ValueBox newLocalBox(Value value) { return Jimple.v().newLocalBox(value); } public ValueBox newRValueBox(Value value) { return new GRValueBox(value); } public ValueBox newImmediateBox(Value value) { return Jimple.v().newImmediateBox(value); } public ValueBox newExprBox(Value value) { return new ExprBox(value); } public ValueBox newArgBox(Value value) { return new ExprBox(value); } public ValueBox newObjExprBox(Value value) { return new ObjExprBox(value); } public ValueBox newIdentityRefBox(Value value) { return Jimple.v().newIdentityRefBox(value); } public ValueBox newConditionExprBox(Value value) { return Jimple.v().newConditionExprBox(value); } public ValueBox newInvokeExprBox(Value value) { return Jimple.v().newInvokeExprBox(value); } public UnitBox newStmtBox(Unit unit) { return Jimple.v().newStmtBox(unit); } /** Carries out the mapping from other Value's to Grimp Value's */ public Value newExpr(Value value) { if (value instanceof Expr) { final ExprBox returnedExpr = new ExprBox(IntConstant.v(0)); ((Expr) value).apply(new AbstractExprSwitch() { public void caseAddExpr(AddExpr v) { returnedExpr.setValue(newAddExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseAndExpr(AndExpr v) { returnedExpr.setValue(newAndExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseCmpExpr(CmpExpr v) { returnedExpr.setValue(newCmpExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseCmpgExpr(CmpgExpr v) { returnedExpr.setValue(newCmpgExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseCmplExpr(CmplExpr v) { returnedExpr.setValue(newCmplExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseDivExpr(DivExpr v) { returnedExpr.setValue(newDivExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseEqExpr(EqExpr v) { returnedExpr.setValue(newEqExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseNeExpr(NeExpr v) { returnedExpr.setValue(newNeExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseGeExpr(GeExpr v) { returnedExpr.setValue(newGeExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseGtExpr(GtExpr v) { returnedExpr.setValue(newGtExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseLeExpr(LeExpr v) { returnedExpr.setValue(newLeExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseLtExpr(LtExpr v) { returnedExpr.setValue(newLtExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseMulExpr(MulExpr v) { returnedExpr.setValue(newMulExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseOrExpr(OrExpr v) { returnedExpr.setValue(newOrExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseRemExpr(RemExpr v) { returnedExpr.setValue(newRemExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseShlExpr(ShlExpr v) { returnedExpr.setValue(newShlExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseShrExpr(ShrExpr v) { returnedExpr.setValue(newShrExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseUshrExpr(UshrExpr v) { returnedExpr.setValue(newUshrExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseSubExpr(SubExpr v) { returnedExpr.setValue(newSubExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseXorExpr(XorExpr v) { returnedExpr.setValue(newXorExpr(newExpr(v.getOp1()), newExpr(v.getOp2()))); } public void caseInterfaceInvokeExpr(InterfaceInvokeExpr v) { ArrayList newArgList = new ArrayList(); for (int i = 0; i < v.getArgCount(); i++) { newArgList.add(newExpr(v.getArg(i))); } returnedExpr.setValue(newInterfaceInvokeExpr((Local) (v.getBase()), v.getMethodRef(), newArgList)); } public void caseSpecialInvokeExpr(SpecialInvokeExpr v) { ArrayList newArgList = new ArrayList(); for (int i = 0; i < v.getArgCount(); i++) { newArgList.add(newExpr(v.getArg(i))); } returnedExpr.setValue(newSpecialInvokeExpr((Local) (v.getBase()), v.getMethodRef(), newArgList)); } public void caseStaticInvokeExpr(StaticInvokeExpr v) { ArrayList newArgList = new ArrayList(); for (int i = 0; i < v.getArgCount(); i++) { newArgList.add(newExpr(v.getArg(i))); } returnedExpr.setValue(newStaticInvokeExpr(v.getMethodRef(), newArgList)); } public void caseVirtualInvokeExpr(VirtualInvokeExpr v) { ArrayList newArgList = new ArrayList(); for (int i = 0; i < v.getArgCount(); i++) { newArgList.add(newExpr(v.getArg(i))); } returnedExpr.setValue(newVirtualInvokeExpr((Local) (v.getBase()), v.getMethodRef(), newArgList)); } public void caseDynamicInvokeExpr(DynamicInvokeExpr v) { ArrayList newArgList = new ArrayList(); for (int i = 0; i < v.getArgCount(); i++) { newArgList.add(newExpr(v.getArg(i))); } returnedExpr.setValue(newDynamicInvokeExpr(v.getBootstrapMethodRef(), v.getBootstrapArgs(), v.getMethodRef(), v.getHandleTag(), newArgList)); } public void caseCastExpr(CastExpr v) { returnedExpr.setValue(newCastExpr(newExpr(v.getOp()), v.getType())); } public void caseInstanceOfExpr(InstanceOfExpr v) { returnedExpr.setValue(newInstanceOfExpr(newExpr(v.getOp()), v.getCheckType())); } public void caseNewArrayExpr(NewArrayExpr v) { returnedExpr.setValue(newNewArrayExpr(v.getBaseType(), v.getSize())); } public void caseNewMultiArrayExpr(NewMultiArrayExpr v) { returnedExpr.setValue(newNewMultiArrayExpr(v.getBaseType(), v.getSizes())); } public void caseNewExpr(NewExpr v) { returnedExpr.setValue(newNewExpr(v.getBaseType())); } public void caseLengthExpr(LengthExpr v) { returnedExpr.setValue(newLengthExpr(newExpr(v.getOp()))); } public void caseNegExpr(NegExpr v) { returnedExpr.setValue(newNegExpr(newExpr(v.getOp()))); } public void defaultCase(Object v) { returnedExpr.setValue((Expr) v); } }); return returnedExpr.getValue(); } else { if (value instanceof ArrayRef) { return newArrayRef(((ArrayRef) value).getBase(), newExpr(((ArrayRef) value).getIndex())); } if (value instanceof InstanceFieldRef) { return newInstanceFieldRef(newExpr((((InstanceFieldRef) value).getBase())), ((InstanceFieldRef) value).getFieldRef()); } /* have Ref/Value, which is fine -- not Jimple-specific. */ return value; } } /** Returns an empty GrimpBody associated with method m. */ public GrimpBody newBody(SootMethod m) { return new GrimpBody(m); } /** Returns a GrimpBody constructed from b. */ public GrimpBody newBody(Body b, String phase) { return new GrimpBody(b); } public static Value cloneIfNecessary(Value val) { if (val instanceof Local || val instanceof Constant) { return val; } else { return (Value) val.clone(); } } }
25,059
26.782705
119
java
soot
soot-master/src/main/java/soot/grimp/GrimpBody.java
package soot.grimp; /*- * #%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% */ import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import soot.Body; import soot.Local; import soot.PackManager; import soot.SootMethod; import soot.Trap; import soot.Unit; import soot.ValueBox; import soot.jimple.AbstractStmtSwitch; import soot.jimple.AssignStmt; import soot.jimple.BreakpointStmt; import soot.jimple.EnterMonitorStmt; import soot.jimple.ExitMonitorStmt; import soot.jimple.GotoStmt; import soot.jimple.IdentityStmt; import soot.jimple.IfStmt; import soot.jimple.InvokeStmt; import soot.jimple.JimpleBody; import soot.jimple.LookupSwitchStmt; import soot.jimple.NopStmt; import soot.jimple.ReturnStmt; import soot.jimple.ReturnVoidStmt; import soot.jimple.Stmt; import soot.jimple.StmtBody; import soot.jimple.TableSwitchStmt; import soot.jimple.ThrowStmt; import soot.jimple.internal.StmtBox; import soot.options.Options; import soot.tagkit.LineNumberTag; import soot.tagkit.SourceLnPosTag; import soot.tagkit.Tag; import soot.util.Chain; /** * Implementation of the Body class for the Grimp IR. */ public class GrimpBody extends StmtBody { private static final Logger logger = LoggerFactory.getLogger(GrimpBody.class); /** * Construct an empty GrimpBody */ GrimpBody(SootMethod m) { super(m); } @Override public Object clone() { Body b = Grimp.v().newBody(getMethodUnsafe()); b.importBodyContentsFrom(this); return b; } /** * Constructs a GrimpBody from the given Body. */ GrimpBody(Body body) { super(body.getMethod()); if (Options.v().verbose()) { logger.debug("[" + getMethod().getName() + "] Constructing GrimpBody..."); } if (!(body instanceof JimpleBody)) { throw new RuntimeException("Can only construct GrimpBody's from JimpleBody's (for now)"); } final JimpleBody jBody = (JimpleBody) body; { final Chain<Local> thisLocals = this.getLocals(); for (Local loc : jBody.getLocals()) { thisLocals.add(loc); // thisLocals.add((Local)loc.clone()); } } final Grimp grimp = Grimp.v(); final Chain<Unit> thisUnits = getUnits(); final HashMap<Stmt, Stmt> oldToNew = new HashMap<Stmt, Stmt>(thisUnits.size() * 2 + 1, 0.7f); final ArrayList<Unit> updates = new ArrayList<Unit>(); /* we should Grimpify the Stmt's here... */ for (Unit u : jBody.getUnits()) { Stmt oldStmt = (Stmt) u; final StmtBox newStmtBox = (StmtBox) grimp.newStmtBox(null); final StmtBox updateStmtBox = (StmtBox) grimp.newStmtBox(null); /* we can't have a general StmtSwapper on Grimp.v() */ /* because we need to collect a list of updates */ oldStmt.apply(new AbstractStmtSwitch() { @Override public void caseAssignStmt(AssignStmt s) { newStmtBox.setUnit(grimp.newAssignStmt(s)); } @Override public void caseIdentityStmt(IdentityStmt s) { newStmtBox.setUnit(grimp.newIdentityStmt(s)); } @Override public void caseBreakpointStmt(BreakpointStmt s) { newStmtBox.setUnit(grimp.newBreakpointStmt(s)); } @Override public void caseInvokeStmt(InvokeStmt s) { newStmtBox.setUnit(grimp.newInvokeStmt(s)); } @Override public void caseEnterMonitorStmt(EnterMonitorStmt s) { newStmtBox.setUnit(grimp.newEnterMonitorStmt(s)); } @Override public void caseExitMonitorStmt(ExitMonitorStmt s) { newStmtBox.setUnit(grimp.newExitMonitorStmt(s)); } @Override public void caseGotoStmt(GotoStmt s) { newStmtBox.setUnit(grimp.newGotoStmt(s)); updateStmtBox.setUnit(s); } @Override public void caseIfStmt(IfStmt s) { newStmtBox.setUnit(grimp.newIfStmt(s)); updateStmtBox.setUnit(s); } @Override public void caseLookupSwitchStmt(LookupSwitchStmt s) { newStmtBox.setUnit(grimp.newLookupSwitchStmt(s)); updateStmtBox.setUnit(s); } @Override public void caseNopStmt(NopStmt s) { newStmtBox.setUnit(grimp.newNopStmt(s)); } @Override public void caseReturnStmt(ReturnStmt s) { newStmtBox.setUnit(grimp.newReturnStmt(s)); } @Override public void caseReturnVoidStmt(ReturnVoidStmt s) { newStmtBox.setUnit(grimp.newReturnVoidStmt(s)); } @Override public void caseTableSwitchStmt(TableSwitchStmt s) { newStmtBox.setUnit(grimp.newTableSwitchStmt(s)); updateStmtBox.setUnit(s); } @Override public void caseThrowStmt(ThrowStmt s) { newStmtBox.setUnit(grimp.newThrowStmt(s)); } }); /* map old Expr's to new Expr's. */ Stmt newStmt = (Stmt) newStmtBox.getUnit(); for (ValueBox box : newStmt.getUseBoxes()) { box.setValue(grimp.newExpr(box.getValue())); } for (ValueBox box : newStmt.getDefBoxes()) { box.setValue(grimp.newExpr(box.getValue())); } thisUnits.add(newStmt); oldToNew.put(oldStmt, newStmt); if (updateStmtBox.getUnit() != null) { updates.add(updateStmtBox.getUnit()); } final Tag lnTag = oldStmt.getTag(LineNumberTag.NAME); if (lnTag != null) { newStmt.addTag(lnTag); } final Tag slpTag = oldStmt.getTag(SourceLnPosTag.NAME); if (slpTag != null) { newStmt.addTag(slpTag); } } /* fixup stmt's which have had moved targets */ { final AbstractStmtSwitch tgtUpdateSwitch = new AbstractStmtSwitch() { @Override public void caseGotoStmt(GotoStmt s) { GotoStmt newStmt = (GotoStmt) oldToNew.get(s); newStmt.setTarget(oldToNew.get((Stmt) newStmt.getTarget())); } @Override public void caseIfStmt(IfStmt s) { IfStmt newStmt = (IfStmt) oldToNew.get(s); newStmt.setTarget(oldToNew.get(newStmt.getTarget())); } @Override public void caseLookupSwitchStmt(LookupSwitchStmt s) { LookupSwitchStmt newStmt = (LookupSwitchStmt) oldToNew.get(s); newStmt.setDefaultTarget(oldToNew.get((Stmt) newStmt.getDefaultTarget())); Unit[] newTargList = new Unit[newStmt.getTargetCount()]; for (int i = 0; i < newTargList.length; i++) { newTargList[i] = oldToNew.get((Stmt) newStmt.getTarget(i)); } newStmt.setTargets(newTargList); } @Override public void caseTableSwitchStmt(TableSwitchStmt s) { TableSwitchStmt newStmt = (TableSwitchStmt) oldToNew.get(s); newStmt.setDefaultTarget(oldToNew.get((Stmt) newStmt.getDefaultTarget())); int tc = newStmt.getHighIndex() - newStmt.getLowIndex() + 1; LinkedList<Unit> newTargList = new LinkedList<Unit>(); for (int i = 0; i < tc; i++) { newTargList.add(oldToNew.get((Stmt) newStmt.getTarget(i))); } newStmt.setTargets(newTargList); } }; for (Unit u : updates) { u.apply(tgtUpdateSwitch); } } { final Chain<Trap> thisTraps = getTraps(); for (Trap oldTrap : jBody.getTraps()) { thisTraps.add(grimp.newTrap(oldTrap.getException(), oldToNew.get((Stmt) oldTrap.getBeginUnit()), oldToNew.get((Stmt) oldTrap.getEndUnit()), oldToNew.get((Stmt) oldTrap.getHandlerUnit()))); } } PackManager.v().getPack("gb").apply(this); } }
8,461
29.883212
104
java
soot
soot-master/src/main/java/soot/grimp/GrimpExprSwitch.java
package soot.grimp; /*- * #%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% */ import soot.jimple.ExprSwitch; public interface GrimpExprSwitch extends ExprSwitch { public abstract void caseNewInvokeExpr(NewInvokeExpr v); }
965
30.16129
71
java
soot
soot-master/src/main/java/soot/grimp/GrimpValueSwitch.java
package soot.grimp; /*- * #%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.jimple.JimpleValueSwitch; public interface GrimpValueSwitch extends JimpleValueSwitch { public abstract void caseNewInvokeExpr(NewInvokeExpr e); }
991
31
71
java
soot
soot-master/src/main/java/soot/grimp/NewInvokeExpr.java
package soot.grimp; /*- * #%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.RefType; import soot.jimple.StaticInvokeExpr; public interface NewInvokeExpr extends StaticInvokeExpr { public RefType getBaseType(); public void setBaseType(RefType type); }
1,021
29.969697
71
java
soot
soot-master/src/main/java/soot/grimp/Precedence.java
package soot.grimp; /*- * #%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% */ public interface Precedence { public abstract int getPrecedence(); }
888
30.75
71
java
soot
soot-master/src/main/java/soot/grimp/PrecedenceTest.java
package soot.grimp; /*- * #%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.Value; import soot.ValueBox; /** * Provides static helper methods to indicate if parenthesization is required. * * If your sub-expression has strictly higher precedence than you, then no brackets are required: 2 + (4 * 5) = 2 + 4 * 5 is * unambiguous, because * has precedence 800 and + has precedence 700. * * If your subexpression has lower precedence than you, then brackets are required; otherwise you will bind to your * grandchild instead of the subexpression. 2 * (4 + 5) without brackets would mean (2 * 4) + 5. * * For a binary operation, if your left sub-expression has the same precedence as you, no brackets are needed, since binary * operations are all left-associative. If your right sub-expression has the same precedence than you, then brackets are * needed to reproduce the parse tree (otherwise, parsing will give e.g. (2 + 4) + 5 instead of the 2 + (4 + 5) that you had * to start with.) This is OK for integer addition and subtraction, but not OK for floating point multiplication. To be safe, * let's put the brackets on. * * For the high-precedence operations, I've assigned precedences of 950 to field reads and invoke expressions (.), as well as * array reads ([]). I've assigned 850 to cast, newarray and newinvoke. * * The Dava DCmp?Expr precedences look fishy to me; I've assigned DLengthExpr a precedence of 950, because it looks like it * should parse like a field read to me. * * Basically, the only time I can see that brackets should be required seems to occur when a cast or a newarray occurs as a * subexpression of an invoke or field read; hence 850 and 950. -PL */ public class PrecedenceTest { public static boolean needsBrackets(ValueBox subExprBox, Value expr) { Value sub = subExprBox.getValue(); if (!(sub instanceof Precedence)) { return false; } Precedence subP = (Precedence) sub; Precedence exprP = (Precedence) expr; return subP.getPrecedence() < exprP.getPrecedence(); } public static boolean needsBracketsRight(ValueBox subExprBox, Value expr) { Value sub = subExprBox.getValue(); if (!(sub instanceof Precedence)) { return false; } Precedence subP = (Precedence) sub; Precedence exprP = (Precedence) expr; return subP.getPrecedence() <= exprP.getPrecedence(); } }
3,137
41.986301
125
java
soot
soot-master/src/main/java/soot/grimp/internal/AbstractGrimpFloatBinopExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.ValueBox; import soot.grimp.Grimp; import soot.grimp.Precedence; import soot.jimple.DivExpr; import soot.jimple.SubExpr; import soot.jimple.internal.AbstractFloatBinopExpr; public abstract class AbstractGrimpFloatBinopExpr extends AbstractFloatBinopExpr implements Precedence { AbstractGrimpFloatBinopExpr(Value op1, Value op2) { this(Grimp.v().newArgBox(op1), Grimp.v().newArgBox(op2)); } protected AbstractGrimpFloatBinopExpr(ValueBox op1Box, ValueBox op2Box) { super(op1Box, op2Box); } @Override public abstract int getPrecedence(); @Override public String toString() { final Value op1 = op1Box.getValue(); String leftOp = op1.toString(); if (op1 instanceof Precedence && ((Precedence) op1).getPrecedence() < getPrecedence()) { leftOp = "(" + leftOp + ")"; } final Value op2 = op2Box.getValue(); String rightOp = op2.toString(); if (op2 instanceof Precedence) { int opPrec = ((Precedence) op2).getPrecedence(), myPrec = getPrecedence(); if ((opPrec < myPrec) || ((opPrec == myPrec) && ((this instanceof SubExpr) || (this instanceof DivExpr)))) { rightOp = "(" + rightOp + ")"; } } return leftOp + getSymbol() + rightOp; } }
2,085
30.606061
114
java
soot
soot-master/src/main/java/soot/grimp/internal/AbstractGrimpIntBinopExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.ValueBox; import soot.dava.internal.javaRep.DCmpExpr; import soot.dava.internal.javaRep.DCmpgExpr; import soot.dava.internal.javaRep.DCmplExpr; import soot.grimp.Grimp; import soot.grimp.Precedence; import soot.jimple.DivExpr; import soot.jimple.SubExpr; import soot.jimple.internal.AbstractIntBinopExpr; public abstract class AbstractGrimpIntBinopExpr extends AbstractIntBinopExpr implements Precedence { public AbstractGrimpIntBinopExpr(Value op1, Value op2) { this(Grimp.v().newArgBox(op1), Grimp.v().newArgBox(op2)); } protected AbstractGrimpIntBinopExpr(ValueBox op1Box, ValueBox op2Box) { super(op1Box, op2Box); } @Override public abstract int getPrecedence(); @Override public String toString() { final Value op1 = op1Box.getValue(); String leftOp = op1.toString(); if (op1 instanceof Precedence && ((Precedence) op1).getPrecedence() < getPrecedence()) { leftOp = "(" + leftOp + ")"; } final Value op2 = op2Box.getValue(); String rightOp = op2.toString(); if (op2 instanceof Precedence) { int opPrec = ((Precedence) op2).getPrecedence(), myPrec = getPrecedence(); if ((opPrec < myPrec) || ((opPrec == myPrec) && ((this instanceof SubExpr) || (this instanceof DivExpr) || (this instanceof DCmpExpr) || (this instanceof DCmpgExpr) || (this instanceof DCmplExpr)))) { rightOp = "(" + rightOp + ")"; } } return leftOp + getSymbol() + rightOp; } }
2,318
32.128571
109
java
soot
soot-master/src/main/java/soot/grimp/internal/AbstractGrimpIntLongBinopExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.ValueBox; import soot.grimp.Grimp; import soot.grimp.Precedence; import soot.jimple.DivExpr; import soot.jimple.SubExpr; import soot.jimple.internal.AbstractIntLongBinopExpr; public abstract class AbstractGrimpIntLongBinopExpr extends AbstractIntLongBinopExpr implements Precedence { AbstractGrimpIntLongBinopExpr(Value op1, Value op2) { this(Grimp.v().newArgBox(op1), Grimp.v().newArgBox(op2)); } protected AbstractGrimpIntLongBinopExpr(ValueBox op1Box, ValueBox op2Box) { super(op1Box, op2Box); } @Override public abstract int getPrecedence(); @Override public String toString() { final Value op1 = op1Box.getValue(); String leftOp = op1.toString(); if (op1 instanceof Precedence && ((Precedence) op1).getPrecedence() < getPrecedence()) { leftOp = "(" + leftOp + ")"; } final Value op2 = op2Box.getValue(); String rightOp = op2.toString(); if (op2 instanceof Precedence) { int opPrec = ((Precedence) op2).getPrecedence(), myPrec = getPrecedence(); if ((opPrec < myPrec) || ((opPrec == myPrec) && ((this instanceof SubExpr) || (this instanceof DivExpr)))) { rightOp = "(" + rightOp + ")"; } } return leftOp + getSymbol() + rightOp; } }
2,095
30.757576
114
java
soot
soot-master/src/main/java/soot/grimp/internal/ExprBox.java
package soot.grimp.internal; /*- * #%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% */ import soot.AbstractValueBox; import soot.Local; import soot.Value; import soot.jimple.ConcreteRef; import soot.jimple.Constant; import soot.jimple.Expr; public class ExprBox extends AbstractValueBox { public ExprBox(Value value) { setValue(value); } @Override public boolean canContainValue(Value value) { return value instanceof Local || value instanceof Constant || value instanceof Expr || value instanceof ConcreteRef; } }
1,275
28.674419
120
java
soot
soot-master/src/main/java/soot/grimp/internal/GAddExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.AddExpr; import soot.jimple.ExprSwitch; import soot.util.Switch; public class GAddExpr extends AbstractGrimpFloatBinopExpr implements AddExpr { public GAddExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " + "; } @Override public final int getPrecedence() { return 700; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseAddExpr(this); } @Override public Object clone() { return new GAddExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,472
24.842105
92
java
soot
soot-master/src/main/java/soot/grimp/internal/GAndExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.AndExpr; import soot.jimple.ExprSwitch; import soot.util.Switch; public class GAndExpr extends AbstractGrimpIntLongBinopExpr implements AndExpr { public GAndExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " & "; } @Override public final int getPrecedence() { return 500; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseAndExpr(this); } @Override public Object clone() { return new GAndExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,474
24.877193
92
java
soot
soot-master/src/main/java/soot/grimp/internal/GArrayRef.java
package soot.grimp.internal; /*- * #%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% */ import soot.UnitPrinter; import soot.Value; import soot.grimp.Grimp; import soot.grimp.Precedence; import soot.grimp.PrecedenceTest; import soot.jimple.internal.JArrayRef; public class GArrayRef extends JArrayRef implements Precedence { public GArrayRef(Value base, Value index) { super(Grimp.v().newObjExprBox(base), Grimp.v().newExprBox(index)); } @Override public int getPrecedence() { return 950; } @Override public void toString(UnitPrinter up) { final boolean needsBrackets = PrecedenceTest.needsBrackets(baseBox, this); if (needsBrackets) { up.literal("("); } baseBox.toString(up); if (needsBrackets) { up.literal(")"); } up.literal("["); indexBox.toString(up); up.literal("]"); } @Override public String toString() { final Value op1 = getBase(); String leftOp = op1.toString(); if (op1 instanceof Precedence && ((Precedence) op1).getPrecedence() < getPrecedence()) { leftOp = "(" + leftOp + ")"; } return leftOp + "[" + getIndex().toString() + "]"; } @Override public Object clone() { return new GArrayRef(Grimp.cloneIfNecessary(getBase()), Grimp.cloneIfNecessary(getIndex())); } }
2,036
26.90411
96
java
soot
soot-master/src/main/java/soot/grimp/internal/GAssignStmt.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.internal.JAssignStmt; public class GAssignStmt extends JAssignStmt { public GAssignStmt(Value variable, Value rvalue) { super(Grimp.v().newVariableBox(variable), Grimp.v().newRValueBox(rvalue)); } @Override public Object clone() { return new GAssignStmt(Grimp.cloneIfNecessary(getLeftOp()), Grimp.cloneIfNecessary(getRightOp())); } }
1,244
30.125
102
java
soot
soot-master/src/main/java/soot/grimp/internal/GCastExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Type; import soot.Value; import soot.grimp.Grimp; import soot.grimp.Precedence; import soot.jimple.internal.AbstractCastExpr; public class GCastExpr extends AbstractCastExpr implements Precedence { public GCastExpr(Value op, Type type) { super(Grimp.v().newExprBox(op), type); } @Override public int getPrecedence() { return 850; } @Override public String toString() { final Value op = getOp(); String opString = op.toString(); if (op instanceof Precedence && ((Precedence) op).getPrecedence() < getPrecedence()) { opString = "(" + opString + ")"; } return "(" + getCastType().toString() + ") " + opString; } @Override public Object clone() { return new GCastExpr(Grimp.cloneIfNecessary(getOp()), getCastType()); } }
1,620
27.438596
90
java
soot
soot-master/src/main/java/soot/grimp/internal/GCmpExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.CmpExpr; import soot.jimple.ExprSwitch; import soot.util.Switch; public class GCmpExpr extends AbstractGrimpIntBinopExpr implements CmpExpr { public GCmpExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " cmp "; } @Override public final int getPrecedence() { return 550; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseCmpExpr(this); } @Override public Object clone() { return new GCmpExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,472
24.842105
92
java
soot
soot-master/src/main/java/soot/grimp/internal/GCmpgExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.CmpgExpr; import soot.jimple.ExprSwitch; import soot.util.Switch; public class GCmpgExpr extends AbstractGrimpIntBinopExpr implements CmpgExpr { public GCmpgExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " cmpg "; } @Override public final int getPrecedence() { return 600; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseCmpgExpr(this); } @Override public Object clone() { return new GCmpgExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,479
24.964912
93
java
soot
soot-master/src/main/java/soot/grimp/internal/GCmplExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.CmplExpr; import soot.jimple.ExprSwitch; import soot.util.Switch; public class GCmplExpr extends AbstractGrimpIntBinopExpr implements CmplExpr { public GCmplExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " cmpl "; } @Override public final int getPrecedence() { return 600; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseCmplExpr(this); } @Override public Object clone() { return new GCmplExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,479
24.964912
93
java
soot
soot-master/src/main/java/soot/grimp/internal/GDivExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.DivExpr; import soot.jimple.ExprSwitch; import soot.util.Switch; public class GDivExpr extends AbstractGrimpFloatBinopExpr implements DivExpr { public GDivExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " / "; } @Override public final int getPrecedence() { return 800; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseDivExpr(this); } @Override public Object clone() { return new GDivExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,472
24.842105
92
java
soot
soot-master/src/main/java/soot/grimp/internal/GDynamicInvokeExpr.java
package soot.grimp.internal; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam * 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.ArrayList; import java.util.List; import java.util.ListIterator; import soot.SootMethod; import soot.SootMethodRef; import soot.UnitPrinter; import soot.Value; import soot.ValueBox; import soot.grimp.Grimp; import soot.jimple.DynamicInvokeExpr; import soot.jimple.ExprSwitch; import soot.jimple.Jimple; import soot.jimple.internal.AbstractInvokeExpr; import soot.util.Switch; @SuppressWarnings("serial") public class GDynamicInvokeExpr extends AbstractInvokeExpr implements DynamicInvokeExpr { protected final SootMethodRef bsmRef; protected final ValueBox[] bsmArgBoxes; protected final int tag; public GDynamicInvokeExpr(SootMethodRef bootStrapMethodRef, List<? extends Value> bootstrapArgs, SootMethodRef methodRef, int tag, List<? extends Value> methodArgs) { super(methodRef, new ValueBox[methodArgs.size()]); this.bsmRef = bootStrapMethodRef; this.bsmArgBoxes = new ValueBox[bootstrapArgs.size()]; this.tag = tag; final Grimp grmp = Grimp.v(); for (ListIterator<? extends Value> it = bootstrapArgs.listIterator(); it.hasNext();) { Value v = it.next(); this.bsmArgBoxes[it.previousIndex()] = grmp.newExprBox(v); } for (ListIterator<? extends Value> it = methodArgs.listIterator(); it.hasNext();) { Value v = it.next(); this.argBoxes[it.previousIndex()] = grmp.newExprBox(v); } } @Override public Object clone() { List<Value> clonedBsmArgs = new ArrayList<Value>(bsmArgBoxes.length); for (ValueBox box : bsmArgBoxes) { clonedBsmArgs.add(box.getValue()); } final int count = getArgCount(); List<Value> clonedArgs = new ArrayList<Value>(count); for (int i = 0; i < count; i++) { clonedArgs.add(Grimp.cloneIfNecessary(getArg(i))); } return new GDynamicInvokeExpr(bsmRef, clonedBsmArgs, methodRef, tag, clonedArgs); } @Override public int getBootstrapArgCount() { return bsmArgBoxes.length; } @Override public Value getBootstrapArg(int i) { return bsmArgBoxes[i].getValue(); } @Override public List<Value> getBootstrapArgs() { List<Value> l = new ArrayList<Value>(); for (ValueBox element : bsmArgBoxes) { l.add(element.getValue()); } return l; } @Override public SootMethodRef getBootstrapMethodRef() { return bsmRef; } public SootMethod getBootstrapMethod() { return bsmRef.resolve(); } @Override public int getHandleTag() { return tag; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseDynamicInvokeExpr(this); } @Override public boolean equivTo(Object o) { if (o instanceof GDynamicInvokeExpr) { GDynamicInvokeExpr ie = (GDynamicInvokeExpr) o; if ((this.argBoxes == null ? 0 : this.argBoxes.length) != (ie.argBoxes == null ? 0 : ie.argBoxes.length) || this.bsmArgBoxes.length != ie.bsmArgBoxes.length || !this.getMethod().equals(ie.getMethod()) || !this.methodRef.equals(ie.methodRef) || !this.bsmRef.equals(ie.bsmRef)) { return false; } int i = 0; for (ValueBox element : this.bsmArgBoxes) { if (!element.getValue().equivTo(ie.getBootstrapArg(i))) { return false; } i++; } if (this.argBoxes != null) { i = 0; for (ValueBox element : this.argBoxes) { if (!element.getValue().equivTo(ie.getArg(i))) { return false; } i++; } } return true; } return false; } @Override public int equivHashCode() { return getBootstrapMethod().equivHashCode() * getMethod().equivHashCode() * 17; } @Override public String toString() { StringBuilder buf = new StringBuilder(Jimple.DYNAMICINVOKE + " \""); buf.append(methodRef.name()); // quoted method name (can be any UTF8 string) buf.append("\" <"); buf.append(SootMethod.getSubSignature(""/* no method name here */, methodRef.parameterTypes(), methodRef.returnType())); buf.append(">("); if (argBoxes != null) { for (int i = 0, e = argBoxes.length; i < e; i++) { if (i != 0) { buf.append(", "); } buf.append(argBoxes[i].getValue().toString()); } } buf.append(") "); buf.append(bsmRef.getSignature()); buf.append('('); for (int i = 0, e = bsmArgBoxes.length; i < e; i++) { if (i != 0) { buf.append(", "); } buf.append(bsmArgBoxes[i].getValue().toString()); } buf.append(')'); return buf.toString(); } @Override public void toString(UnitPrinter up) { up.literal(Jimple.DYNAMICINVOKE + " \"" + methodRef.name() + "\" <" + SootMethod.getSubSignature(""/* no method name here */, methodRef.parameterTypes(), methodRef.returnType()) + ">("); if (argBoxes != null) { for (int i = 0, e = argBoxes.length; i < e; i++) { if (i != 0) { up.literal(", "); } argBoxes[i].toString(up); } } up.literal(") "); up.methodRef(bsmRef); up.literal("("); for (int i = 0, e = bsmArgBoxes.length; i < e; i++) { if (i != 0) { up.literal(", "); } bsmArgBoxes[i].toString(up); } up.literal(")"); } }
6,113
27.305556
124
java
soot
soot-master/src/main/java/soot/grimp/internal/GEnterMonitorStmt.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.internal.JEnterMonitorStmt; public class GEnterMonitorStmt extends JEnterMonitorStmt { public GEnterMonitorStmt(Value op) { super(Grimp.v().newExprBox(op)); } @Override public Object clone() { return new GEnterMonitorStmt(Grimp.cloneIfNecessary(getOp())); } }
1,170
28.275
71
java
soot
soot-master/src/main/java/soot/grimp/internal/GEqExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.EqExpr; import soot.jimple.ExprSwitch; import soot.util.Switch; public class GEqExpr extends AbstractGrimpIntBinopExpr implements EqExpr { public GEqExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " == "; } @Override public final int getPrecedence() { return 550; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseEqExpr(this); } @Override public Object clone() { return new GEqExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,465
24.719298
91
java
soot
soot-master/src/main/java/soot/grimp/internal/GExitMonitorStmt.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.internal.JExitMonitorStmt; public class GExitMonitorStmt extends JExitMonitorStmt { public GExitMonitorStmt(Value op) { super(((Grimp.v())).newExprBox(op)); } @Override public Object clone() { return new GExitMonitorStmt(Grimp.cloneIfNecessary(getOp())); } }
1,169
28.25
71
java
soot
soot-master/src/main/java/soot/grimp/internal/GGeExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.ExprSwitch; import soot.jimple.GeExpr; import soot.util.Switch; public class GGeExpr extends AbstractGrimpIntBinopExpr implements GeExpr { public GGeExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " >= "; } @Override public final int getPrecedence() { return 600; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseGeExpr(this); } @Override public Object clone() { return new GGeExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,465
24.719298
91
java
soot
soot-master/src/main/java/soot/grimp/internal/GGtExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.ExprSwitch; import soot.jimple.GtExpr; import soot.util.Switch; public class GGtExpr extends AbstractGrimpIntBinopExpr implements GtExpr { public GGtExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " > "; } @Override public final int getPrecedence() { return 600; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseGtExpr(this); } @Override public Object clone() { return new GGtExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,464
24.701754
91
java
soot
soot-master/src/main/java/soot/grimp/internal/GIdentityStmt.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.internal.JIdentityStmt; public class GIdentityStmt extends JIdentityStmt { public GIdentityStmt(Value local, Value identityValue) { super(Grimp.v().newLocalBox(local), Grimp.v().newIdentityRefBox(identityValue)); } @Override public Object clone() { return new GIdentityStmt(Grimp.cloneIfNecessary(getLeftOp()), Grimp.cloneIfNecessary(getRightOp())); } }
1,264
30.625
104
java
soot
soot-master/src/main/java/soot/grimp/internal/GIfStmt.java
package soot.grimp.internal; /*- * #%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% */ import soot.Unit; import soot.Value; import soot.grimp.Grimp; import soot.jimple.internal.JIfStmt; public class GIfStmt extends JIfStmt { public GIfStmt(Value condition, Unit target) { super(Grimp.v().newConditionExprBox(condition), Grimp.v().newStmtBox(target)); } @Override public Object clone() { return new GIfStmt(Grimp.cloneIfNecessary(getCondition()), getTarget()); } }
1,224
28.878049
82
java
soot
soot-master/src/main/java/soot/grimp/internal/GInstanceFieldRef.java
package soot.grimp.internal; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam * 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.SootFieldRef; import soot.Value; import soot.grimp.Grimp; import soot.grimp.Precedence; import soot.jimple.internal.AbstractInstanceFieldRef; public class GInstanceFieldRef extends AbstractInstanceFieldRef implements Precedence { public GInstanceFieldRef(Value base, SootFieldRef fieldRef) { super(Grimp.v().newObjExprBox(base), fieldRef); } private String toString(Value op, String opString, String rightString) { String leftOp = opString; if (op instanceof Precedence && ((Precedence) op).getPrecedence() < getPrecedence()) { leftOp = "(" + leftOp + ")"; } return leftOp + rightString; } public String toString() { return toString(getBase(), getBase().toString(), "." + fieldRef.getSignature()); } public int getPrecedence() { return 950; } public Object clone() { return new GInstanceFieldRef(Grimp.cloneIfNecessary(getBase()), fieldRef); } }
1,785
29.271186
90
java
soot
soot-master/src/main/java/soot/grimp/internal/GInstanceOfExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Type; import soot.Value; import soot.grimp.Grimp; import soot.jimple.internal.AbstractInstanceOfExpr; public class GInstanceOfExpr extends AbstractInstanceOfExpr { public GInstanceOfExpr(Value op, Type checkType) { super(Grimp.v().newObjExprBox(op), checkType); } @Override public Object clone() { return new GInstanceOfExpr(Grimp.cloneIfNecessary(getOp()), getCheckType()); } }
1,238
29.219512
80
java
soot
soot-master/src/main/java/soot/grimp/internal/GInterfaceInvokeExpr.java
package soot.grimp.internal; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1999 Patrick Lam * 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.ArrayList; import java.util.List; import java.util.ListIterator; import soot.SootMethodRef; import soot.UnitPrinter; import soot.Value; import soot.ValueBox; import soot.grimp.Grimp; import soot.grimp.Precedence; import soot.grimp.PrecedenceTest; import soot.jimple.internal.AbstractInterfaceInvokeExpr; public class GInterfaceInvokeExpr extends AbstractInterfaceInvokeExpr implements Precedence { public GInterfaceInvokeExpr(Value base, SootMethodRef methodRef, List<? extends Value> args) { super(Grimp.v().newObjExprBox(base), methodRef, new ValueBox[args.size()]); final Grimp grmp = Grimp.v(); for (ListIterator<? extends Value> it = args.listIterator(); it.hasNext();) { Value v = it.next(); this.argBoxes[it.previousIndex()] = grmp.newExprBox(v); } } @Override public int getPrecedence() { return 950; } @Override public String toString() { final Value base = getBase(); String baseString = base.toString(); if (base instanceof Precedence && ((Precedence) base).getPrecedence() < getPrecedence()) { baseString = "(" + baseString + ")"; } StringBuilder buf = new StringBuilder(baseString); buf.append('.').append(methodRef.getSignature()).append('('); if (argBoxes != null) { for (int i = 0, e = argBoxes.length; i < e; i++) { if (i != 0) { buf.append(", "); } buf.append(argBoxes[i].getValue().toString()); } } buf.append(')'); return buf.toString(); } @Override public void toString(UnitPrinter up) { final boolean needsBrackets = PrecedenceTest.needsBrackets(baseBox, this); if (needsBrackets) { up.literal("("); } baseBox.toString(up); if (needsBrackets) { up.literal(")"); } up.literal("."); up.methodRef(methodRef); up.literal("("); if (argBoxes != null) { for (int i = 0, e = argBoxes.length; i < e; i++) { if (i != 0) { up.literal(", "); } argBoxes[i].toString(up); } } up.literal(")"); } @Override public Object clone() { final int count = getArgCount(); List<Value> clonedArgs = new ArrayList<Value>(count); for (int i = 0; i < count; i++) { clonedArgs.add(Grimp.cloneIfNecessary(getArg(i))); } return new GInterfaceInvokeExpr(Grimp.cloneIfNecessary(getBase()), methodRef, clonedArgs); } }
3,280
27.780702
96
java
soot
soot-master/src/main/java/soot/grimp/internal/GInvokeStmt.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.internal.JInvokeStmt; public class GInvokeStmt extends JInvokeStmt { public GInvokeStmt(Value c) { super(Grimp.v().newInvokeExprBox(c)); } @Override public Object clone() { return new GInvokeStmt(Grimp.cloneIfNecessary(getInvokeExpr())); } }
1,152
27.825
71
java
soot
soot-master/src/main/java/soot/grimp/internal/GLeExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.ExprSwitch; import soot.jimple.LeExpr; import soot.util.Switch; public class GLeExpr extends AbstractGrimpIntBinopExpr implements LeExpr { public GLeExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " <= "; } @Override public final int getPrecedence() { return 600; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseLeExpr(this); } @Override public Object clone() { return new GLeExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,465
24.719298
91
java
soot
soot-master/src/main/java/soot/grimp/internal/GLengthExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.internal.AbstractLengthExpr; public class GLengthExpr extends AbstractLengthExpr { public GLengthExpr(Value op) { super(Grimp.v().newObjExprBox(op)); } @Override public Object clone() { return new GLengthExpr(Grimp.cloneIfNecessary(getOp())); } }
1,157
27.95
71
java
soot
soot-master/src/main/java/soot/grimp/internal/GLookupSwitchStmt.java
package soot.grimp.internal; /*- * #%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% */ import java.util.ArrayList; import java.util.List; import soot.Unit; import soot.Value; import soot.grimp.Grimp; import soot.jimple.IntConstant; import soot.jimple.internal.JLookupSwitchStmt; public class GLookupSwitchStmt extends JLookupSwitchStmt { public GLookupSwitchStmt(Value key, List<IntConstant> lookupValues, List<? extends Unit> targets, Unit defaultTarget) { super(Grimp.v().newExprBox(key), lookupValues, getTargetBoxesArray(targets, Grimp.v()::newStmtBox), Grimp.v().newStmtBox(defaultTarget)); } @Override public Object clone() { List<IntConstant> clonedLookupValues = new ArrayList<IntConstant>(lookupValues.size()); for (IntConstant c : lookupValues) { clonedLookupValues.add(IntConstant.v(c.value)); } return new GLookupSwitchStmt(Grimp.cloneIfNecessary(getKey()), clonedLookupValues, getTargets(), getDefaultTarget()); } }
1,716
33.34
121
java
soot
soot-master/src/main/java/soot/grimp/internal/GLtExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.ExprSwitch; import soot.jimple.LtExpr; import soot.util.Switch; public class GLtExpr extends AbstractGrimpIntBinopExpr implements LtExpr { public GLtExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " < "; } @Override public final int getPrecedence() { return 600; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseLtExpr(this); } @Override public Object clone() { return new GLtExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,464
24.701754
91
java
soot
soot-master/src/main/java/soot/grimp/internal/GMulExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.ExprSwitch; import soot.jimple.MulExpr; import soot.util.Switch; public class GMulExpr extends AbstractGrimpFloatBinopExpr implements MulExpr { public GMulExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " * "; } @Override public final int getPrecedence() { return 800; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseMulExpr(this); } @Override public Object clone() { return new GMulExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,472
24.842105
92
java
soot
soot-master/src/main/java/soot/grimp/internal/GNeExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.ExprSwitch; import soot.jimple.NeExpr; import soot.util.Switch; public class GNeExpr extends AbstractGrimpIntBinopExpr implements NeExpr { public GNeExpr(Value op1, Value op2) { super(op1, op2); } @Override public final String getSymbol() { return " != "; } @Override public final int getPrecedence() { return 550; } @Override public void apply(Switch sw) { ((ExprSwitch) sw).caseNeExpr(this); } @Override public Object clone() { return new GNeExpr(Grimp.cloneIfNecessary(getOp1()), Grimp.cloneIfNecessary(getOp2())); } }
1,465
24.719298
91
java
soot
soot-master/src/main/java/soot/grimp/internal/GNegExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Value; import soot.grimp.Grimp; import soot.jimple.internal.AbstractNegExpr; public class GNegExpr extends AbstractNegExpr { public GNegExpr(Value op) { super(Grimp.v().newExprBox(op)); } @Override public Object clone() { return new GNegExpr(Grimp.cloneIfNecessary(getOp())); } }
1,139
27.5
71
java
soot
soot-master/src/main/java/soot/grimp/internal/GNewArrayExpr.java
package soot.grimp.internal; /*- * #%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% */ import soot.Type; import soot.Value; import soot.grimp.Grimp; import soot.grimp.Precedence; import soot.jimple.internal.AbstractNewArrayExpr; public class GNewArrayExpr extends AbstractNewArrayExpr implements Precedence { public GNewArrayExpr(Type type, Value size) { super(type, Grimp.v().newExprBox(size)); } @Override public int getPrecedence() { return 850; } @Override public Object clone() { return new GNewArrayExpr(getBaseType(), Grimp.cloneIfNecessary(getSize())); } }
1,336
27.446809
79
java