use of soot.jimple.spark.internal.SparkLibraryHelper in project soot by Sable.
the class MethodNodeFactory method handleStmt.
/**
* Adds the edges required for this statement to the graph.
*/
public final void handleStmt(Stmt s) {
// We only consider reflective class creation when it is enabled
if (s.containsInvokeExpr()) {
if (!pag.getCGOpts().types_for_invoke())
return;
InvokeExpr iexpr = s.getInvokeExpr();
if (iexpr instanceof VirtualInvokeExpr) {
if (!isReflectionNewInstance(iexpr))
return;
} else if (!(iexpr instanceof StaticInvokeExpr))
return;
}
s.apply(new AbstractStmtSwitch() {
@Override
public final void caseAssignStmt(AssignStmt as) {
Value l = as.getLeftOp();
Value r = as.getRightOp();
if (!(l.getType() instanceof RefLikeType))
return;
assert r.getType() instanceof RefLikeType : "Type mismatch in assignment " + as + " in method " + method.getSignature();
l.apply(MethodNodeFactory.this);
Node dest = getNode();
r.apply(MethodNodeFactory.this);
Node src = getNode();
if (l instanceof InstanceFieldRef) {
((InstanceFieldRef) l).getBase().apply(MethodNodeFactory.this);
pag.addDereference((VarNode) getNode());
}
if (r instanceof InstanceFieldRef) {
((InstanceFieldRef) r).getBase().apply(MethodNodeFactory.this);
pag.addDereference((VarNode) getNode());
} else if (r instanceof StaticFieldRef) {
StaticFieldRef sfr = (StaticFieldRef) r;
SootFieldRef s = sfr.getFieldRef();
if (pag.getOpts().empties_as_allocs()) {
if (s.declaringClass().getName().equals("java.util.Collections")) {
if (s.name().equals("EMPTY_SET")) {
src = pag.makeAllocNode(RefType.v("java.util.HashSet"), RefType.v("java.util.HashSet"), method);
} else if (s.name().equals("EMPTY_MAP")) {
src = pag.makeAllocNode(RefType.v("java.util.HashMap"), RefType.v("java.util.HashMap"), method);
} else if (s.name().equals("EMPTY_LIST")) {
src = pag.makeAllocNode(RefType.v("java.util.LinkedList"), RefType.v("java.util.LinkedList"), method);
}
} else if (s.declaringClass().getName().equals("java.util.Hashtable")) {
if (s.name().equals("emptyIterator")) {
src = pag.makeAllocNode(RefType.v("java.util.Hashtable$EmptyIterator"), RefType.v("java.util.Hashtable$EmptyIterator"), method);
} else if (s.name().equals("emptyEnumerator")) {
src = pag.makeAllocNode(RefType.v("java.util.Hashtable$EmptyEnumerator"), RefType.v("java.util.Hashtable$EmptyEnumerator"), method);
}
}
}
}
mpag.addInternalEdge(src, dest);
}
@Override
public final void caseReturnStmt(ReturnStmt rs) {
if (!(rs.getOp().getType() instanceof RefLikeType))
return;
rs.getOp().apply(MethodNodeFactory.this);
Node retNode = getNode();
mpag.addInternalEdge(retNode, caseRet());
}
@Override
public final void caseIdentityStmt(IdentityStmt is) {
if (!(is.getLeftOp().getType() instanceof RefLikeType))
return;
Value leftOp = is.getLeftOp();
Value rightOp = is.getRightOp();
leftOp.apply(MethodNodeFactory.this);
Node dest = getNode();
rightOp.apply(MethodNodeFactory.this);
Node src = getNode();
mpag.addInternalEdge(src, dest);
// in case library mode is activated add allocations to any
// possible type of this local and
// parameters of accessible methods
int libOption = pag.getCGOpts().library();
if (libOption != CGOptions.library_disabled && (accessibilityOracle.isAccessible(method))) {
if (rightOp instanceof IdentityRef) {
Type rt = rightOp.getType();
rt.apply(new SparkLibraryHelper(pag, src, method));
}
}
}
@Override
public final void caseThrowStmt(ThrowStmt ts) {
ts.getOp().apply(MethodNodeFactory.this);
mpag.addOutEdge(getNode(), pag.nodeFactory().caseThrow());
}
});
}
use of soot.jimple.spark.internal.SparkLibraryHelper in project soot by Sable.
the class PAG method makeGlobalVarNode.
/**
* Finds or creates the GlobalVarNode for the variable value, of type type.
*/
public GlobalVarNode makeGlobalVarNode(Object value, Type type) {
if (opts.rta()) {
value = null;
type = RefType.v("java.lang.Object");
}
GlobalVarNode ret = valToGlobalVarNode.get(value);
if (ret == null) {
valToGlobalVarNode.put(value, ret = new GlobalVarNode(this, value, type));
// type to accessible fields
if (cgOpts.library() != CGOptions.library_disabled) {
if (value instanceof SootField) {
SootField sf = (SootField) value;
if (accessibilityOracle.isAccessible(sf)) {
type.apply(new SparkLibraryHelper(this, ret, null));
}
}
}
addNodeTag(ret, null);
} else if (!(ret.getType().equals(type))) {
throw new RuntimeException("Value " + value + " of type " + type + " previously had type " + ret.getType());
}
return ret;
}
use of soot.jimple.spark.internal.SparkLibraryHelper in project soot by Sable.
the class PAG method makeLocalFieldRefNode.
/**
* Finds or creates the FieldRefNode for base variable baseValue and field
* field, of type type.
*/
public FieldRefNode makeLocalFieldRefNode(Object baseValue, Type baseType, SparkField field, SootMethod method) {
VarNode base = makeLocalVarNode(baseValue, baseType, method);
FieldRefNode ret = makeFieldRefNode(base, field);
// to accessible fields
if (cgOpts.library() != CGOptions.library_disabled) {
if (field instanceof SootField) {
SootField sf = (SootField) field;
Type type = sf.getType();
if (accessibilityOracle.isAccessible(sf)) {
type.apply(new SparkLibraryHelper(this, ret, method));
}
}
}
return ret;
}
use of soot.jimple.spark.internal.SparkLibraryHelper in project soot by Sable.
the class MethodPAG method buildNative.
protected void buildNative() {
ValNode thisNode = null;
ValNode retNode = null;
if (!method.isStatic()) {
thisNode = (ValNode) nodeFactory.caseThis();
}
if (method.getReturnType() instanceof RefLikeType) {
retNode = (ValNode) nodeFactory.caseRet();
// be anything matching to the declared type.
if (pag.getCGOpts().library() != CGOptions.library_disabled) {
Type retType = method.getReturnType();
retType.apply(new SparkLibraryHelper(pag, retNode, method));
}
}
ValNode[] args = new ValNode[method.getParameterCount()];
for (int i = 0; i < method.getParameterCount(); i++) {
if (!(method.getParameterType(i) instanceof RefLikeType))
continue;
args[i] = (ValNode) nodeFactory.caseParm(i);
}
pag.nativeMethodDriver.process(method, thisNode, retNode, args);
}
Aggregations