Package soot
Class SootMethod
- java.lang.Object
-
- soot.tagkit.AbstractHost
-
- soot.SootMethod
-
- All Implemented Interfaces:
ClassMember,MethodOrMethodContext,SootMethodInterface,Host
public class SootMethod extends AbstractHost implements ClassMember, MethodOrMethodContext, SootMethodInterface
Soot representation of a Java method. Can be declared to belong to aSootClass. Does not contain the actual code, which belongs to aBody. ThegetActiveBody()method points to the currently-active body.
-
-
Field Summary
Fields Modifier and Type Field Description protected BodyactiveBodyActive body associated with this method.static StringconstructorNameprotected SootClassdeclaringClassHolds the class which declares thisSootClassmethod.protected List<SootClass>exceptionsDeclared exceptions thrown by this method.protected booleanisDeclaredTrue when someSootClassobject declares thisSootMethodobject.protected booleanisPhantomIs this method a phantom method?protected intmodifiersModifiers associated with thisSootMethod(e.g.protected MethodSourcemsTells this method how to find out where its body lives.protected StringnameName of the current method.protected Type[]parameterTypesAn array of parameter types taken by thisSootMethodobject, in declaration order.protected TypereturnTypeThe return type of this object.protected Stringsigstatic StringstaticInitializerNameprotected StringsubSigprotected NumberedStringsubsignature-
Fields inherited from class soot.tagkit.AbstractHost
col, line, mTagList
-
-
Constructor Summary
Constructors Constructor Description SootMethod(String name, List<Type> parameterTypes, Type returnType)Constructs aSootMethodwith the given name, parameter types and return type.SootMethod(String name, List<Type> parameterTypes, Type returnType, int modifiers)Constructs aSootMethodwith the given name, parameter types, return type and modifiers.SootMethod(String name, List<Type> parameterTypes, Type returnType, int modifiers, List<SootClass> thrownExceptions)Constructs aSootMethodwith the given name, parameter types, return type, and list of thrown exceptions.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddException(SootClass e)Adds the given exception to the list of exceptions thrown by this method.voidaddExceptionIfAbsent(SootClass e)Adds the given exception to the list of exceptions thrown by this method unless the exception is already in the list.Contextcontext()intequivHashCode()Returns a hash code for this method consistent with structural equality.BodygetActiveBody()Retrieves the active body for this method.StringgetBytecodeParms()Returns the parameters part of the signature in the format in which it appears in bytecode.StringgetBytecodeSignature()Returns the signature of this method in the format in which it appears in bytecode (eg.StringgetDavaDeclaration()StringgetDeclaration()Returns the declaration of this method, as used at the top of textual body representations (before the {}'s containing the code for representation.)SootClassgetDeclaringClass()Returns the class which declares the currentSootMethod.List<SootClass>getExceptions()Returns a backed list of the exceptions thrown by this method.List<SootClass>getExceptionsUnsafe()intgetJavaSourceStartLineNumber()Returns the Java source line number if available.intgetModifiers()Gets the modifiers of this method.StringgetName()Returns the name of this method.NumberedStringgetNumberedSubSignature()intgetParameterCount()Returns the number of parameters taken by this method.TypegetParameterType(int n)Gets the type of the nth parameter of this method.List<Type>getParameterTypes()Returns a read-only list of the parameter types of this method.TypegetReturnType()Returns the return type of this method.StringgetSignature()Returns the Soot signature of this method.static StringgetSignature(SootClass cl, String subSignature)static StringgetSignature(SootClass cl, String name, List<Type> params, Type returnType)MethodSourcegetSource()Returns theMethodSourceof the currentSootMethod.StringgetSubSignature()Returns the Soot subsignature of this method.static StringgetSubSignature(String name, List<Type> params, Type returnType)booleanhasActiveBody()Returns true if this method has an active body.booleanisAbstract()Convenience method returning true if this method is abstract.booleanisConcrete()Returns true if this method is not phantom, abstract or native, i.e.booleanisConstructor()booleanisDeclared()Returns true when someSootClassobject declares thisSootMethodobject.booleanisEntryMethod()booleanisFinal()Convenience method returning true if this method is final.booleanisJavaLibraryMethod()We rely on the JDK class recognition to decide if a method is JDK method.booleanisMain()booleanisNative()Convenience method returning true if this method is native.booleanisPhantom()Returns true when thisSootMethodobject is phantom.booleanisPrivate()Convenience method returning true if this method is private.booleanisProtected()Convenience method returning true if this method is protected.booleanisPublic()Convenience method returning true if this method is public.booleanisStatic()Convenience method returning true if this method is static.booleanisStaticInitializer()booleanisSynchronized()Convenience method returning true if this method is synchronized.booleanisValidResolve(SootMethodRef ref)SootMethodRefmakeRef()SootMethodmethod()voidreleaseActiveBody()Releases the active body associated with this method.voidremoveException(SootClass e)Removes the given exception from the list of exceptions thrown by this method.BodyretrieveActiveBody()Returns the active body if present, else constructs an active body and returns that.BodyretrieveActiveBody(Consumer<Body> consumer)Returns the active body if present, else constructs an active body, calls the consumer and returns the body afterward.voidsetActiveBody(Body body)Sets the active body for this method.voidsetDeclared(boolean isDeclared)voidsetDeclaringClass(SootClass declClass)Sets the declaring classvoidsetExceptions(List<SootClass> exceptions)voidsetModifiers(int modifiers)Sets the modifiers of this method.voidsetName(String name)Sets the name of this method.voidsetParameterTypes(List<Type> l)Changes the set of parameter types of this method.voidsetPhantom(boolean value)Sets the phantom flag on this method.voidsetReturnType(Type t)Sets the return type of this method.voidsetSource(MethodSource ms)Sets theMethodSourceof the currentSootMethod.booleanthrowsException(SootClass e)Returns true if this method throws exceptione.StringtoString()Returns the signature of this method.-
Methods inherited from class soot.tagkit.AbstractHost
addAllTagsOf, addTag, getJavaSourceStartColumnNumber, getTag, getTags, hasTag, removeAllTags, removeTag
-
-
-
-
Field Detail
-
constructorName
public static final String constructorName
- See Also:
- Constant Field Values
-
staticInitializerName
public static final String staticInitializerName
- See Also:
- Constant Field Values
-
name
protected String name
Name of the current method.
-
parameterTypes
protected Type[] parameterTypes
An array of parameter types taken by thisSootMethodobject, in declaration order.
-
returnType
protected Type returnType
The return type of this object.
-
isDeclared
protected boolean isDeclared
True when someSootClassobject declares thisSootMethodobject.
-
declaringClass
protected SootClass declaringClass
Holds the class which declares thisSootClassmethod.
-
modifiers
protected int modifiers
Modifiers associated with thisSootMethod(e.g. private, protected, etc.)
-
isPhantom
protected boolean isPhantom
Is this method a phantom method?
-
exceptions
protected List<SootClass> exceptions
Declared exceptions thrown by this method. Created upon demand.
-
activeBody
protected volatile Body activeBody
Active body associated with this method.
-
ms
protected volatile MethodSource ms
Tells this method how to find out where its body lives.
-
sig
protected volatile String sig
-
subSig
protected volatile String subSig
-
subsignature
protected NumberedString subsignature
-
-
Constructor Detail
-
SootMethod
public SootMethod(String name, List<Type> parameterTypes, Type returnType)
Constructs aSootMethodwith the given name, parameter types and return type.
-
SootMethod
public SootMethod(String name, List<Type> parameterTypes, Type returnType, int modifiers)
Constructs aSootMethodwith the given name, parameter types, return type and modifiers.
-
-
Method Detail
-
equivHashCode
public int equivHashCode()
Returns a hash code for this method consistent with structural equality.
-
getName
public String getName()
Returns the name of this method.- Specified by:
getNamein interfaceSootMethodInterface- Returns:
- Name of the method
-
setName
public void setName(String name)
Sets the name of this method.
-
setDeclaringClass
public void setDeclaringClass(SootClass declClass)
Sets the declaring class
-
getDeclaringClass
public SootClass getDeclaringClass()
Returns the class which declares the currentSootMethod.- Specified by:
getDeclaringClassin interfaceClassMember- Specified by:
getDeclaringClassin interfaceSootMethodInterface- Returns:
- The class which declares the current
SootMethod/SootMethodRef
-
setDeclared
public void setDeclared(boolean isDeclared)
-
isDeclared
public boolean isDeclared()
Returns true when someSootClassobject declares thisSootMethodobject.- Specified by:
isDeclaredin interfaceClassMember
-
isPhantom
public boolean isPhantom()
Returns true when thisSootMethodobject is phantom.- Specified by:
isPhantomin interfaceClassMember
-
isConcrete
public boolean isConcrete()
Returns true if this method is not phantom, abstract or native, i.e. this method can have a body.
-
setPhantom
public void setPhantom(boolean value)
Sets the phantom flag on this method.- Specified by:
setPhantomin interfaceClassMember
-
getModifiers
public int getModifiers()
Gets the modifiers of this method.- Specified by:
getModifiersin interfaceClassMember- See Also:
Modifier
-
setModifiers
public void setModifiers(int modifiers)
Sets the modifiers of this method.- Specified by:
setModifiersin interfaceClassMember- See Also:
Modifier
-
getReturnType
public Type getReturnType()
Returns the return type of this method.- Specified by:
getReturnTypein interfaceSootMethodInterface
-
setReturnType
public void setReturnType(Type t)
Sets the return type of this method.
-
getParameterCount
public int getParameterCount()
Returns the number of parameters taken by this method.
-
getParameterType
public Type getParameterType(int n)
Gets the type of the nth parameter of this method.- Specified by:
getParameterTypein interfaceSootMethodInterface
-
getParameterTypes
public List<Type> getParameterTypes()
Returns a read-only list of the parameter types of this method.- Specified by:
getParameterTypesin interfaceSootMethodInterface
-
setParameterTypes
public void setParameterTypes(List<Type> l)
Changes the set of parameter types of this method.
-
getSource
public MethodSource getSource()
Returns theMethodSourceof the currentSootMethod.
-
setSource
public void setSource(MethodSource ms)
Sets theMethodSourceof the currentSootMethod.
-
getActiveBody
public Body getActiveBody()
Retrieves the active body for this method.
-
setActiveBody
public void setActiveBody(Body body)
Sets the active body for this method.
-
retrieveActiveBody
public Body retrieveActiveBody()
Returns the active body if present, else constructs an active body and returns that. If you called Scene.v().loadClassAndSupport() for a class yourself, it will not be an application class, so you cannot get retrieve its active body. Please callSootClass.setApplicationClass()on the relevant class.
-
retrieveActiveBody
public Body retrieveActiveBody(Consumer<Body> consumer)
Returns the active body if present, else constructs an active body, calls the consumer and returns the body afterward. If you called Scene.v().loadClassAndSupport() for a class yourself, it will not be an application class, so you cannot get retrieve its active body. Please callSootClass.setApplicationClass()on the relevant class.- Parameters:
consumer- Consumer that takes in the body of the method. The consumer is only invoked if the current invocation constructs a new body and is guaranteed to terminate before the body is available to other threads.- Returns:
- active body of the method
-
hasActiveBody
public boolean hasActiveBody()
Returns true if this method has an active body.
-
releaseActiveBody
public void releaseActiveBody()
Releases the active body associated with this method.
-
addExceptionIfAbsent
public void addExceptionIfAbsent(SootClass e)
Adds the given exception to the list of exceptions thrown by this method unless the exception is already in the list.
-
addException
public void addException(SootClass e)
Adds the given exception to the list of exceptions thrown by this method.
-
removeException
public void removeException(SootClass e)
Removes the given exception from the list of exceptions thrown by this method.
-
throwsException
public boolean throwsException(SootClass e)
Returns true if this method throws exceptione.
-
getExceptions
public List<SootClass> getExceptions()
Returns a backed list of the exceptions thrown by this method.
-
isStatic
public boolean isStatic()
Convenience method returning true if this method is static.- Specified by:
isStaticin interfaceClassMember- Specified by:
isStaticin interfaceSootMethodInterface
-
isPrivate
public boolean isPrivate()
Convenience method returning true if this method is private.- Specified by:
isPrivatein interfaceClassMember
-
isPublic
public boolean isPublic()
Convenience method returning true if this method is public.- Specified by:
isPublicin interfaceClassMember
-
isProtected
public boolean isProtected()
Convenience method returning true if this method is protected.- Specified by:
isProtectedin interfaceClassMember
-
isAbstract
public boolean isAbstract()
Convenience method returning true if this method is abstract.
-
isFinal
public boolean isFinal()
Convenience method returning true if this method is final.
-
isNative
public boolean isNative()
Convenience method returning true if this method is native.
-
isSynchronized
public boolean isSynchronized()
Convenience method returning true if this method is synchronized.
-
isMain
public boolean isMain()
- Returns:
- yes if this is the main method
-
isConstructor
public boolean isConstructor()
- Returns:
- yes, if this function is a constructor. Please not that
methods are not treated as constructors in this method.
-
isStaticInitializer
public boolean isStaticInitializer()
- Returns:
- yes, if this function is a static initializer.
-
isEntryMethod
public boolean isEntryMethod()
- Returns:
- yes, if this is a class initializer or main function.
-
isJavaLibraryMethod
public boolean isJavaLibraryMethod()
We rely on the JDK class recognition to decide if a method is JDK method.
-
getBytecodeParms
public String getBytecodeParms()
Returns the parameters part of the signature in the format in which it appears in bytecode.
-
getBytecodeSignature
public String getBytecodeSignature()
Returns the signature of this method in the format in which it appears in bytecode (eg. [Ljava/lang/Object instead of java.lang.Object[]).
-
getSignature
public String getSignature()
Returns the Soot signature of this method. Used to refer to methods unambiguously.- Specified by:
getSignaturein interfaceSootMethodInterface- Returns:
- The Soot signature of this method. Used to refer to methods unambiguously.
-
getSignature
public static String getSignature(SootClass cl, String name, List<Type> params, Type returnType)
-
getSubSignature
public String getSubSignature()
Returns the Soot subsignature of this method. Used to refer to methods unambiguously.
-
getSubSignature
public static String getSubSignature(String name, List<Type> params, Type returnType)
-
getNumberedSubSignature
public NumberedString getNumberedSubSignature()
-
toString
public String toString()
Returns the signature of this method.
-
getDavaDeclaration
public String getDavaDeclaration()
-
getDeclaration
public String getDeclaration()
Returns the declaration of this method, as used at the top of textual body representations (before the {}'s containing the code for representation.)
-
method
public SootMethod method()
- Specified by:
methodin interfaceMethodOrMethodContext
-
context
public Context context()
- Specified by:
contextin interfaceMethodOrMethodContext
-
makeRef
public SootMethodRef makeRef()
-
isValidResolve
public boolean isValidResolve(SootMethodRef ref)
-
getJavaSourceStartLineNumber
public int getJavaSourceStartLineNumber()
Description copied from interface:HostReturns the Java source line number if available. Returns -1 if not.- Specified by:
getJavaSourceStartLineNumberin interfaceHost- Overrides:
getJavaSourceStartLineNumberin classAbstractHost
-
-