use of soot.ArrayType in project soot by Sable.
the class Renamer method arraysGetTypeArray.
/*
* if there is an array int[] x. then if no other heuristic matches give it the name intArray
*/
private void arraysGetTypeArray() {
Iterator<Local> it = heuristics.getLocalsIterator();
while (it.hasNext()) {
Local tempLocal = it.next();
if (alreadyChanged(tempLocal)) {
continue;
}
debug("arraysGetTypeArray", "checking " + tempLocal);
Type type = tempLocal.getType();
if (type instanceof ArrayType) {
debug("arraysGetTypeArray", "Local:" + tempLocal + " is an Array Type: " + type.toString());
String tempClassName = type.toString();
// remember that a toString of an array gives you the square brackets
if (tempClassName.indexOf('[') >= 0)
tempClassName = tempClassName.substring(0, tempClassName.indexOf('['));
// debug("arraysGetTypeArray","type of object is"+tempClassName);
if (tempClassName.indexOf('.') != -1) {
// contains a dot have to remove that
tempClassName = tempClassName.substring(tempClassName.lastIndexOf('.') + 1);
}
String newName = tempClassName.toLowerCase();
newName = newName + "Array";
int count = 0;
newName += count;
count++;
while (!isUniqueName(newName)) {
newName = newName.substring(0, newName.length() - 1) + count;
count++;
}
setName(tempLocal, newName);
}
}
}
use of soot.ArrayType in project soot by Sable.
the class DexAnnotation method handleClassAnnotation.
/**
* Converts Class annotations from Dexlib to Jimple.
*
* @param h
* @param classDef
*/
// .annotation "Ldalvik/annotation/AnnotationDefault;"
// .annotation "Ldalvik/annotation/EnclosingClass;"
// .annotation "Ldalvik/annotation/EnclosingMethod;"
// .annotation "Ldalvik/annotation/InnerClass;"
// .annotation "Ldalvik/annotation/MemberClasses;"
// .annotation "Ldalvik/annotation/Signature;"
// .annotation "Ldalvik/annotation/Throws;"
public void handleClassAnnotation(ClassDef classDef) {
Set<? extends Annotation> aSet = classDef.getAnnotations();
if (aSet == null || aSet.isEmpty())
return;
List<Tag> tags = handleAnnotation(aSet, classDef.getType());
if (tags == null)
return;
InnerClassAttribute ica = null;
for (Tag t : tags) if (t != null) {
if (t instanceof InnerClassTag) {
if (ica == null) {
// Do we already have an InnerClassAttribute?
ica = (InnerClassAttribute) clazz.getTag("InnerClassAttribute");
// If not, create one
if (ica == null) {
ica = new InnerClassAttribute();
clazz.addTag(ica);
}
}
ica.add((InnerClassTag) t);
} else if (t instanceof VisibilityAnnotationTag) {
// If a dalvik/annotation/AnnotationDefault tag is present
// in a class, its AnnotationElements must be propagated
// to methods through the creation of new
// AnnotationDefaultTag.
VisibilityAnnotationTag vt = (VisibilityAnnotationTag) t;
for (AnnotationTag a : vt.getAnnotations()) {
if (a.getType().equals("Ldalvik/annotation/AnnotationDefault;")) {
for (AnnotationElem ae : a.getElems()) {
if (ae instanceof AnnotationAnnotationElem) {
AnnotationAnnotationElem aae = (AnnotationAnnotationElem) ae;
AnnotationTag at = aae.getValue();
// extract default elements
Map<String, AnnotationElem> defaults = new HashMap<String, AnnotationElem>();
for (AnnotationElem aelem : at.getElems()) {
defaults.put(aelem.getName(), aelem);
}
// and add tags on methods
for (SootMethod sm : clazz.getMethods()) {
String methodName = sm.getName();
if (defaults.containsKey(methodName)) {
AnnotationElem e = defaults.get(methodName);
// Okay, the name is the same, but
// is it actually the same type?
Type annotationType = getSootType(e);
boolean isCorrectType = false;
if (annotationType == null) {
// we do not know the type of
// the annotation, so we guess
// it's the correct type.
isCorrectType = true;
} else {
if (annotationType.equals(sm.getReturnType())) {
isCorrectType = true;
} else if (annotationType.equals(ARRAY_TYPE)) {
if (sm.getReturnType() instanceof ArrayType)
isCorrectType = true;
}
}
if (isCorrectType && sm.getParameterCount() == 0) {
e.setName("default");
AnnotationDefaultTag d = new AnnotationDefaultTag(e);
sm.addTag(d);
// In case there is more than
// one matching method, we only
// use the first one
defaults.remove(sm.getName());
}
}
}
for (Entry<String, AnnotationElem> leftOverEntry : defaults.entrySet()) {
// We were not able to find a matching
// method for the tag, because the
// return signature
// does not match
SootMethod found = clazz.getMethodByNameUnsafe(leftOverEntry.getKey());
AnnotationElem element = leftOverEntry.getValue();
if (found != null) {
element.setName("default");
AnnotationDefaultTag d = new AnnotationDefaultTag(element);
found.addTag(d);
}
}
}
}
}
}
if (!(vt.getVisibility() == AnnotationConstants.RUNTIME_INVISIBLE))
clazz.addTag(vt);
} else {
clazz.addTag(t);
}
}
}
use of soot.ArrayType in project soot by Sable.
the class Util method emptyBody.
/**
* Remove all statements except from IdentityStatements for parameters.
* Return default value (null or zero or nothing depending on the return
* type).
*
* @param jBody
*/
public static void emptyBody(Body jBody) {
// identity statements
List<Unit> idStmts = new ArrayList<Unit>();
List<Local> idLocals = new ArrayList<Local>();
for (Unit u : jBody.getUnits()) {
if (u instanceof IdentityStmt) {
IdentityStmt i = (IdentityStmt) u;
if (i.getRightOp() instanceof ParameterRef || i.getRightOp() instanceof ThisRef) {
idStmts.add(u);
idLocals.add((Local) i.getLeftOp());
}
}
}
jBody.getUnits().clear();
jBody.getLocals().clear();
jBody.getTraps().clear();
final LocalGenerator lg = new LocalGenerator(jBody);
for (Unit u : idStmts) jBody.getUnits().add(u);
for (Local l : idLocals) jBody.getLocals().add(l);
Type rType = jBody.getMethod().getReturnType();
jBody.getUnits().add(Jimple.v().newNopStmt());
if (rType instanceof VoidType) {
jBody.getUnits().add(Jimple.v().newReturnVoidStmt());
} else {
Type t = jBody.getMethod().getReturnType();
Local l = lg.generateLocal(t);
AssignStmt ass = null;
if (t instanceof RefType || t instanceof ArrayType) {
ass = Jimple.v().newAssignStmt(l, NullConstant.v());
} else if (t instanceof LongType) {
ass = Jimple.v().newAssignStmt(l, LongConstant.v(0));
} else if (t instanceof FloatType) {
ass = Jimple.v().newAssignStmt(l, FloatConstant.v(0.0f));
} else if (t instanceof IntType) {
ass = Jimple.v().newAssignStmt(l, IntConstant.v(0));
} else if (t instanceof DoubleType) {
ass = Jimple.v().newAssignStmt(l, DoubleConstant.v(0));
} else if (t instanceof BooleanType || t instanceof ByteType || t instanceof CharType || t instanceof ShortType) {
ass = Jimple.v().newAssignStmt(l, IntConstant.v(0));
} else {
throw new RuntimeException("error: return type unknown: " + t + " class: " + t.getClass());
}
jBody.getUnits().add(ass);
jBody.getUnits().add(Jimple.v().newReturnStmt(l));
}
}
use of soot.ArrayType in project soot by Sable.
the class AputInstruction method getTargetType.
@Override
protected Type getTargetType(DexBody body) {
Instruction23x aPutInstr = (Instruction23x) instruction;
Type t = body.getRegisterLocal(aPutInstr.getRegisterB()).getType();
if (t instanceof ArrayType)
return ((ArrayType) t).getElementType();
else
return UnknownType.v();
}
use of soot.ArrayType in project soot by Sable.
the class FilledNewArrayRangeInstruction method jimplify.
@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);
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());
}
}
Aggregations