Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* Qilin - a Java Pointer Analysis Framework
* Copyright (C) 2021-2030 Qilin developers
*
* 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 3.0 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
* .
*/
package qilin.core.builder;
import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
import javax.annotation.Nonnull;
import qilin.CoreConfig;
import qilin.core.PTAScene;
import qilin.core.PointsToAnalysis;
import qilin.core.pag.*;
import qilin.core.pag.Field;
import qilin.util.PTAUtils;
import qilin.util.queue.UniqueQueue;
import sootup.core.jimple.basic.Immediate;
import sootup.core.jimple.basic.Local;
import sootup.core.jimple.basic.NoPositionInformation;
import sootup.core.jimple.basic.Value;
import sootup.core.jimple.common.constant.ClassConstant;
import sootup.core.jimple.common.constant.IntConstant;
import sootup.core.jimple.common.constant.NullConstant;
import sootup.core.jimple.common.constant.StringConstant;
import sootup.core.jimple.common.expr.AbstractInstanceInvokeExpr;
import sootup.core.jimple.common.expr.AbstractInvokeExpr;
import sootup.core.jimple.common.expr.JCastExpr;
import sootup.core.jimple.common.expr.JNewArrayExpr;
import sootup.core.jimple.common.expr.JNewExpr;
import sootup.core.jimple.common.expr.JNewMultiArrayExpr;
import sootup.core.jimple.common.ref.JArrayRef;
import sootup.core.jimple.common.ref.JCaughtExceptionRef;
import sootup.core.jimple.common.ref.JInstanceFieldRef;
import sootup.core.jimple.common.ref.JParameterRef;
import sootup.core.jimple.common.ref.JStaticFieldRef;
import sootup.core.jimple.common.ref.JThisRef;
import sootup.core.jimple.common.stmt.JAssignStmt;
import sootup.core.jimple.common.stmt.JIdentityStmt;
import sootup.core.jimple.common.stmt.JReturnStmt;
import sootup.core.jimple.common.stmt.JThrowStmt;
import sootup.core.jimple.common.stmt.Stmt;
import sootup.core.jimple.javabytecode.stmt.JExitMonitorStmt;
import sootup.core.jimple.visitor.AbstractStmtVisitor;
import sootup.core.model.*;
import sootup.core.signatures.FieldSignature;
import sootup.core.signatures.MethodSubSignature;
import sootup.core.types.ArrayType;
import sootup.core.types.ClassType;
import sootup.core.types.ReferenceType;
import sootup.core.types.Type;
import sootup.java.core.JavaIdentifierFactory;
import sootup.java.core.language.JavaJimple;
/** @author Ondrej Lhotak */
public class MethodNodeFactory {
protected PAG pag;
protected MethodPAG mpag;
protected SootMethod method;
private final PTAScene scene;
public MethodNodeFactory(PAG pag, MethodPAG mpag) {
this.pag = pag;
this.mpag = mpag;
method = mpag.getMethod();
this.scene = pag.getPta().getScene();
}
public Node getNode(Value v) {
if (v instanceof Local) {
Local l = (Local) v;
return caseLocal(l);
} else if (v instanceof JCastExpr) {
JCastExpr castExpr = (JCastExpr) v;
return caseCastExpr(castExpr);
} else if (v instanceof JNewExpr) {
JNewExpr ne = (JNewExpr) v;
return caseNewExpr(ne);
} else if (v instanceof JStaticFieldRef) {
JStaticFieldRef sfr = (JStaticFieldRef) v;
return caseStaticFieldRef(sfr);
} else if (v instanceof JNewArrayExpr) {
JNewArrayExpr nae = (JNewArrayExpr) v;
return caseNewArrayExpr(nae);
} else if (v instanceof JArrayRef) {
JArrayRef ar = (JArrayRef) v;
return caseArrayRef(ar);
} else if (v instanceof ClassConstant) {
ClassConstant cc = (ClassConstant) v;
return caseClassConstant(cc);
} else if (v instanceof StringConstant) {
StringConstant sc = (StringConstant) v;
return caseStringConstant(sc);
} else if (v instanceof JCaughtExceptionRef) {
JCaughtExceptionRef cef = (JCaughtExceptionRef) v;
return caseCaughtExceptionRef(cef);
} else if (v instanceof JParameterRef) {
JParameterRef pr = (JParameterRef) v;
return caseParameterRef(pr);
} else if (v instanceof NullConstant) {
NullConstant nc = (NullConstant) v;
return caseNullConstant(nc);
} else if (v instanceof JInstanceFieldRef) {
JInstanceFieldRef ifr = (JInstanceFieldRef) v;
return caseInstanceFieldRef(ifr);
} else if (v instanceof JThisRef) {
return caseThis();
} else if (v instanceof JNewMultiArrayExpr) {
JNewMultiArrayExpr nmae = (JNewMultiArrayExpr) v;
return caseNewMultiArrayExpr(nmae);
}
System.out.println(v + ";;" + v.getClass());
return null;
}
/** Adds the edges required for this statement to the graph. */
public final void handleStmt(Stmt s) {
if (s.containsInvokeExpr()) {
mpag.addCallStmt(s);
handleInvokeStmt(s);
} else {
handleIntraStmt(s);
}
}
/**
* Adds the edges required for this statement to the graph. Add throw stmt if the invoke method
* throws an Exception.
*/
protected void handleInvokeStmt(Stmt s) {
AbstractInvokeExpr ie = s.getInvokeExpr();
int numArgs = ie.getArgCount();
for (int i = 0; i < numArgs; i++) {
Value arg = ie.getArg(i);
if (!(arg.getType() instanceof ReferenceType) || arg instanceof NullConstant) {
continue;
}
getNode(arg);
}
if (s instanceof JAssignStmt) {
JAssignStmt assignStmt = (JAssignStmt) s;
Value l = assignStmt.getLeftOp();
if ((l.getType() instanceof ReferenceType)) {
getNode(l);
}
}
if (ie instanceof AbstractInstanceInvokeExpr) {
AbstractInstanceInvokeExpr aie = (AbstractInstanceInvokeExpr) ie;
getNode(aie.getBase());
}
}
private void resolveClinit(JStaticFieldRef staticFieldRef) {
FieldSignature fieldSig = staticFieldRef.getFieldSignature();
ClassType classType = fieldSig.getDeclClassType();
if (PTAUtils.isFakeMainClass(classType)) { // skip FakeMain
return;
}
SootClass sootClass = scene.getView().getClass(classType).get();
clinitsOf(sootClass).forEach(mpag::addTriggeredClinit);
}
/** Adds the edges required for this statement to the graph. */
private void handleIntraStmt(Stmt s) {
s.accept(
new AbstractStmtVisitor