pascal.taie.analysis.pta.plugin.natives.DoPriviledgedModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tai-e Show documentation
Show all versions of tai-e Show documentation
An easy-to-learn/use static analysis framework for Java
The newest version!
/*
* Tai-e: A Static Analysis Framework for Java
*
* Copyright (C) 2022 Tian Tan
* Copyright (C) 2022 Yue Li
*
* This file is part of Tai-e.
*
* Tai-e 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
* of the License, or (at your option) any later version.
*
* Tai-e 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 Tai-e. If not, see .
*/
package pascal.taie.analysis.pta.plugin.natives;
import pascal.taie.analysis.graph.callgraph.Edge;
import pascal.taie.analysis.graph.callgraph.OtherEdge;
import pascal.taie.analysis.pta.core.cs.element.CSCallSite;
import pascal.taie.analysis.pta.core.cs.element.CSMethod;
import pascal.taie.analysis.pta.core.solver.Solver;
import pascal.taie.analysis.pta.plugin.util.IRModelPlugin;
import pascal.taie.analysis.pta.plugin.util.InvokeHandler;
import pascal.taie.ir.exp.InvokeInterface;
import pascal.taie.ir.proginfo.MethodRef;
import pascal.taie.ir.stmt.Invoke;
import pascal.taie.ir.stmt.Stmt;
import pascal.taie.util.collection.Maps;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class DoPriviledgedModel extends IRModelPlugin {
private final MethodRef privilegedActionRun;
private final MethodRef privilegedExceptionActionRun;
/**
* Map from artificial invocation of run() to corresponding
* invocation doPriviledged(...).
*/
private final Map run2DoPriv = Maps.newMap();
DoPriviledgedModel(Solver solver) {
super(solver);
privilegedActionRun = Objects.requireNonNull(
hierarchy.getJREMethod("")).getRef();
privilegedExceptionActionRun = Objects.requireNonNull(
hierarchy.getJREMethod("")).getRef();
}
@InvokeHandler(signature = {
"",
""})
public List doPrivilegedPA(Invoke invoke) {
return doPrivileged(invoke, privilegedActionRun);
}
@InvokeHandler(signature = {
"",
""})
public List doPrivilegedPEA(Invoke invoke) {
return doPrivileged(invoke, privilegedExceptionActionRun);
}
private List doPrivileged(Invoke invoke, MethodRef run) {
Invoke invokeRun = new Invoke(invoke.getContainer(),
new InvokeInterface(run, invoke.getInvokeExp().getArg(0), List.of()),
invoke.getResult());
run2DoPriv.put(invokeRun, invoke);
return List.of(invokeRun);
}
/**
* Connects doPrivileged(...) invocation to the corresponding run() method
* which is the callee of the corresponding run().
*/
@Override
public void onNewCallEdge(Edge edge) {
Invoke invoke = edge.getCallSite().getCallSite();
Invoke doPrivilegedInvoke = run2DoPriv.get(invoke);
if (doPrivilegedInvoke != null) {
CSCallSite csCallSite = csManager.getCSCallSite(
edge.getCallSite().getContext(), doPrivilegedInvoke);
solver.addCallEdge(new DoPrivilegedCallEdge(csCallSite, edge.getCallee()));
}
}
/**
* Represents call edge from AccessController.doPrivileged(...)
* to the privileged action.
*/
private static class DoPrivilegedCallEdge extends OtherEdge {
DoPrivilegedCallEdge(CSCallSite csCallSite, CSMethod callee) {
super(csCallSite, callee);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy