Search in sources :

Example 36 with ArrayType

use of soot.ArrayType in project soot by Sable.

the class FilledNewArrayRangeInstruction method isUsedAsFloatingPoint.

@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);
}
Also used : Instruction3rc(org.jf.dexlib2.iface.instruction.formats.Instruction3rc) ArrayType(soot.ArrayType) Type(soot.Type) DexType(soot.dexpler.DexType)

Example 37 with ArrayType

use of soot.ArrayType in project soot by Sable.

the class FillArrayDataInstruction method getArrayElement.

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 new registers
        for (int reg : usedRegisters) {
            int newRegister = i.movesToRegister(reg);
            if (newRegister != -1) {
                usedRegisters.add(newRegister);
                usedRegisters.remove(reg);
                // there can't be more than one new
                break;
            }
        }
    }
    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;
}
Also used : Instruction22c(org.jf.dexlib2.iface.instruction.formats.Instruction22c) LongType(soot.LongType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) FloatType(soot.FloatType) IntType(soot.IntType) ArrayType(soot.ArrayType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) ShortType(soot.ShortType) CharType(soot.CharType) LongType(soot.LongType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) ArrayType(soot.ArrayType) Type(soot.Type) DexType(soot.dexpler.DexType) NumericConstant(soot.jimple.NumericConstant) DoubleType(soot.DoubleType) IntConstant(soot.jimple.IntConstant) TypeReference(org.jf.dexlib2.iface.reference.TypeReference) CharType(soot.CharType) HashSet(java.util.HashSet)

Example 38 with ArrayType

use of soot.ArrayType in project soot by Sable.

the class FilledNewArrayInstruction method isUsedAsFloatingPoint.

@Override
boolean isUsedAsFloatingPoint(DexBody body, int register) {
    Instruction35c i = (Instruction35c) instruction;
    Type arrayType = DexType.toSoot((TypeReference) i.getReference());
    return isRegisterUsed(register) && isFloatLike(arrayType);
}
Also used : ArrayType(soot.ArrayType) Type(soot.Type) DexType(soot.dexpler.DexType) Instruction35c(org.jf.dexlib2.iface.instruction.formats.Instruction35c)

Example 39 with ArrayType

use of soot.ArrayType in project soot by Sable.

the class ClassRenamer method updateType.

private void updateType(Type type) {
    if (type instanceof RefType) {
        RefType rt = (RefType) type;
        if (!rt.getSootClass().isLibraryClass() && oldToNewClassNames.containsKey(rt.getClassName())) {
            rt.setSootClass(newNameToClass.get(oldToNewClassNames.get(rt.getClassName())));
            rt.setClassName(oldToNewClassNames.get(rt.getClassName()));
        }
    } else if (type instanceof ArrayType) {
        ArrayType at = (ArrayType) type;
        if (at.baseType instanceof RefType) {
            RefType rt = (RefType) at.baseType;
            if (!rt.getSootClass().isLibraryClass() && oldToNewClassNames.containsKey(rt.getClassName())) {
                rt.setSootClass(newNameToClass.get(oldToNewClassNames.get(rt.getClassName())));
            }
        }
    }
}
Also used : RefType(soot.RefType) ArrayType(soot.ArrayType)

Example 40 with ArrayType

use of soot.ArrayType in project soot by Sable.

the class EvalResults method test_1cfa_call_graph.

/**
 * We assess the quality of building the 1-cfa call graph with the geometric
 * points-to result.
 */
private void test_1cfa_call_graph(LocalVarNode vn, SootMethod caller, SootMethod callee_signature, Histogram ce_range) {
    long l, r;
    IVarAbstraction pn = ptsProvider.findInternalNode(vn);
    if (pn == null)
        return;
    pn = pn.getRepresentative();
    Set<SootMethod> tgts = new HashSet<SootMethod>();
    Set<AllocNode> set = pn.get_all_points_to_objects();
    LinkedList<CgEdge> list = ptsProvider.getCallEdgesInto(ptsProvider.getIDFromSootMethod(caller));
    FastHierarchy hierarchy = Scene.v().getOrMakeFastHierarchy();
    for (Iterator<CgEdge> it = list.iterator(); it.hasNext(); ) {
        CgEdge p = it.next();
        l = p.map_offset;
        r = l + ptsProvider.max_context_size_block[p.s];
        tgts.clear();
        for (AllocNode obj : set) {
            if (!pn.pointer_interval_points_to(l, r, obj))
                continue;
            Type t = obj.getType();
            if (t == null)
                continue;
            else if (t instanceof AnySubType)
                t = ((AnySubType) t).getBase();
            else if (t instanceof ArrayType)
                t = RefType.v("java.lang.Object");
            try {
                tgts.add(hierarchy.resolveConcreteDispatch(((RefType) t).getSootClass(), callee_signature));
            } catch (Exception e) {
            }
        }
        tgts.remove(null);
        ce_range.addNumber(tgts.size());
    }
}
Also used : CgEdge(soot.jimple.spark.geom.dataRep.CgEdge) ArrayType(soot.ArrayType) RefType(soot.RefType) FastHierarchy(soot.FastHierarchy) RefType(soot.RefType) AnySubType(soot.AnySubType) RefLikeType(soot.RefLikeType) ArrayType(soot.ArrayType) Type(soot.Type) AllocNode(soot.jimple.spark.pag.AllocNode) IVarAbstraction(soot.jimple.spark.geom.geomPA.IVarAbstraction) SootMethod(soot.SootMethod) AnySubType(soot.AnySubType) HashSet(java.util.HashSet)

Aggregations

ArrayType (soot.ArrayType)44 Type (soot.Type)34 RefType (soot.RefType)26 Local (soot.Local)19 Value (soot.Value)18 IntType (soot.IntType)17 BooleanType (soot.BooleanType)14 NewArrayExpr (soot.jimple.NewArrayExpr)13 ByteType (soot.ByteType)12 FloatType (soot.FloatType)12 NullType (soot.NullType)12 ShortType (soot.ShortType)12 ArrayRef (soot.jimple.ArrayRef)12 CharType (soot.CharType)11 DoubleType (soot.DoubleType)11 LongType (soot.LongType)11 AssignStmt (soot.jimple.AssignStmt)11 SootClass (soot.SootClass)10 InvokeExpr (soot.jimple.InvokeExpr)10 PrimType (soot.PrimType)9