public class ReflectClass extends ReflectObject<java.lang.Class<?>>
Modifier and Type | Class and Description |
---|---|
static interface |
ReflectClass.OnClassReceiverListener |
static class |
ReflectClass.ReflectClassException |
Modifier and Type | Method and Description |
---|---|
ReflectClass |
bindInterface(IBinder binder) |
ReflectClass |
bindInterface(java.lang.String service) |
int |
bridge(MethodBridge callback)
Add a hook to all
Constructor 's of this class |
int |
bridge(java.lang.String methodName,
MethodBridge callback)
Add a hook to all
Method 's of this class with a specific name |
static java.lang.Class<?> |
findClass(java.lang.String className) |
static java.lang.Class<?> |
findClass(java.lang.String className,
java.lang.ClassLoader loader)
This is the same as using
Class.forName(String, boolean, ClassLoader) only that
this method handles a few issues that some times occurs when parsing a ClassLoader . |
static java.lang.ClassLoader |
findClassLoader()
Finds the best suited
ClassLoader . |
ReflectConstructor |
findConstructor(java.lang.Object... parameterTypes) |
ReflectConstructor |
findConstructor(ReflectMember.Match match,
java.lang.Object... parameterTypes)
Search for a
Constructor within this class. |
ReflectConstructor |
findConstructor(ReflectMember.Match match,
ReflectParameterTypes parameterTypes)
Search for a
Constructor within this class. |
ReflectField |
findField(java.lang.String fieldName) |
ReflectField |
findField(java.lang.String fieldName,
ReflectMember.Match match)
Search for a
Field within this class. |
ReflectMethod |
findMethod(java.lang.String methodName,
java.lang.Object... parameterTypes) |
ReflectMethod |
findMethod(java.lang.String methodName,
ReflectMember.Match match,
java.lang.Object... parameterTypes)
Search for a
Method within this class. |
ReflectMethod |
findMethod(java.lang.String methodName,
ReflectMember.Match match,
ReflectParameterTypes parameterTypes)
Search for a
Method within this class. |
static ReflectClass |
fromClass(java.lang.Class<?> clazz)
Attach a
Class to a new instance of ReflectClass |
static ReflectClass |
fromName(java.lang.String className) |
static ReflectClass |
fromName(java.lang.String className,
java.lang.ClassLoader loader)
Find a
Class based on class name and return a new ReflectClass instance with the located
Class attached to it |
static ReflectClass |
fromReceiver(java.lang.Object receiver)
Attach the
Class of a receiver to a new instance of ReflectClass and
add the receiver itself to be used with this instance whenever invoking members from it |
java.lang.Object |
getFieldValue(java.lang.String fieldName) |
java.lang.Object |
getFieldValue(java.lang.String fieldName,
ReflectMember.Match match)
This is a shortcut that will both search for and get the value from a
Field |
ReflectClass |
getNested(java.lang.String simpleName)
Returns a new
ReflectClass instance pointing at a nested class within the current class. |
java.lang.Class<?> |
getNestedClass(java.lang.String simpleName)
Locates a nested class based on it's simple name.
|
ReflectClass |
getNestedInstantiated(java.lang.String simpleName,
java.lang.Object... arguments)
This is the same as
getNested(String) only this one will also instantiate the nested class. |
java.lang.Class<?> |
getObject()
Returns the object
T attached to this object |
ReflectClass |
getParent()
This will return a new
ReflectClass of the parent class. |
java.lang.Class<?> |
getParentClass()
Returns the parent
Class or NULL if the current class
is not a nested class |
java.lang.Object |
getParentReceiver()
Returns the receiver of the parent class or
NULL if the current class does not have
a receiver or if the current class is not a nested instance. |
java.lang.Object |
getReceiver()
Returns the receiver accociated with this object
|
static ReflectClass |
instantiateClass(java.lang.Class<?> clazz,
java.lang.Object... arguments) |
static ReflectClass |
instantiateName(java.lang.String className,
java.lang.ClassLoader loader,
java.lang.Object... arguments)
This is the same as
fromName(String, ClassLoader) , only this method will also instantiate the class
using the constructor matching the parsed arguments. |
static ReflectClass |
instantiateName(java.lang.String className,
java.lang.Object... arguments) |
ReflectClass |
invokeConstructor(java.lang.Object... arguments) |
ReflectClass |
invokeConstructor(ReflectMember.Match match,
java.lang.Object... arguments)
This is a shortcut that will both search for and invoke a
Constructor based on
the arguments parsed. |
java.lang.Object |
invokeMethod(java.lang.String methodName,
java.lang.Object... arguments) |
java.lang.Object |
invokeMethod(java.lang.String methodName,
ReflectMember.Match match,
java.lang.Object... arguments)
This is a shortcut that will both search for and invoke a
Method based on
the arguments parsed. |
boolean |
isAbstract()
Whether or not the class was declared abstract
|
boolean |
isFinal()
Whether or not the class was declared final
|
boolean |
isInterface()
Whether or not the class is an interface
|
boolean |
isNested()
Whether or not the class is a nested class
|
boolean |
isPrivate()
Whether or not the class was declared private
|
boolean |
isProtected()
Whether or not the class was declared protected
|
boolean |
isPublic()
Whether or not the class was declared public
|
boolean |
isStatic()
Whether or not the class was declared static
|
void |
setFieldValue(java.lang.String fieldName,
java.lang.Object value) |
void |
setFieldValue(java.lang.String fieldName,
ReflectMember.Match match,
java.lang.Object value)
This is a shortcut that will both search for and change the value of a
Field |
void |
setReceiver(java.lang.Object receiver)
Set the receiver used when invoking members belonging to it
|
void |
setReceiverListener(ReflectClass.OnClassReceiverListener listener) |
public static java.lang.ClassLoader findClassLoader()
ClassLoader
.
This method also handles special cases in Android >= Lollipop where the Boot ClassLoader
cannot access specific internal packages.public static java.lang.Class<?> findClass(java.lang.String className) throws ReflectClass.ReflectClassException
ReflectClass.ReflectClassException
findClass(String, ClassLoader)
public static java.lang.Class<?> findClass(java.lang.String className, java.lang.ClassLoader loader) throws ReflectClass.ReflectClassException
Class.forName(String, boolean, ClassLoader)
only that
this method handles a few issues that some times occurs when parsing a ClassLoader
.
This method also stores an internal cache that speed things up if the same class is searched multiple times.className
- Full name of the class to findloader
- A ClassLoader
object. If this is NULL
then findClassLoader()
is used insteadReflectClass.ReflectClassException
- This is thrown if the class could not be locatedpublic static ReflectClass instantiateName(java.lang.String className, java.lang.Object... arguments) throws ReflectClass.ReflectClassException, ReflectMember.ReflectMemberException
public static ReflectClass instantiateName(java.lang.String className, java.lang.ClassLoader loader, java.lang.Object... arguments) throws ReflectClass.ReflectClassException, ReflectMember.ReflectMemberException
fromName(String, ClassLoader)
, only this method will also instantiate the class
using the constructor matching the parsed arguments. It will search for a constructor using ReflectMember.Match.BEST
based on the
Class
types of the arguments. It will then invoke the constructor and add the receiver to this class's receiver.
For more precise constructor search, manually invoke one using #findConstructor(Match, ReflectParameterTypes)
className
- Full name of the class to findloader
- A ClassLoader
object. If this is NULL
then findClassLoader()
is used insteadarguments
- Arguments that should be parsed to the constructor. The constructor will be found using the types of these arguments using a best match.ReflectClass.ReflectClassException
- Thrown if the class could not be foundReflectMember.ReflectMemberException
- Thrown if the constructor could not be found or failed when being invokedpublic static ReflectClass instantiateClass(java.lang.Class<?> clazz, java.lang.Object... arguments) throws ReflectClass.ReflectClassException, ReflectMember.ReflectMemberException
public static ReflectClass fromName(java.lang.String className) throws ReflectClass.ReflectClassException
ReflectClass.ReflectClassException
fromName(String, ClassLoader)
public static ReflectClass fromName(java.lang.String className, java.lang.ClassLoader loader) throws ReflectClass.ReflectClassException
Class
based on class name and return a new ReflectClass
instance with the located
Class
attached to itclassName
- Full name of the class to findloader
- A ClassLoader
object. If this is NULL
then findClassLoader()
is used insteadReflectClass.ReflectClassException
- This is thrown if the class could not be locatedpublic static ReflectClass fromClass(java.lang.Class<?> clazz) throws ReflectClass.ReflectClassException
Class
to a new instance of ReflectClass
clazz
- The Class
to attach to this instanceReflectClass.ReflectClassException
public static ReflectClass fromReceiver(java.lang.Object receiver) throws ReflectClass.ReflectClassException
Class
of a receiver to a new instance of ReflectClass
and
add the receiver itself to be used with this instance whenever invoking members from itreceiver
- A class instanceReflectClass.ReflectClassException
setReceiver(Object)
public void setReceiverListener(ReflectClass.OnClassReceiverListener listener)
public void setReceiver(java.lang.Object receiver)
receiver
- A class instance of this class objectpublic java.lang.Object getReceiver()
getReceiver
in class ReflectObject<java.lang.Class<?>>
public java.lang.Class<?> getObject()
T
attached to this objectgetObject
in class ReflectObject<java.lang.Class<?>>
public boolean isStatic()
public boolean isPrivate()
public boolean isProtected()
public boolean isPublic()
public boolean isAbstract()
public boolean isInterface()
public boolean isFinal()
public boolean isNested()
public ReflectClass getParent()
ReflectClass
of the parent class.
If this instance has a receiver then the parent receiver will be added as well. NULL
is returned if this is not a nested class.public ReflectClass getNested(java.lang.String simpleName)
ReflectClass
instance pointing at a nested class within the current class.
If the nested class is not declared as static, it will get a reference of the current receiver which will
allow you to instantiate it. NULL
is returned if no nested class was foundsimpleName
- The name of the nested class. This should be the simple namepublic ReflectClass getNestedInstantiated(java.lang.String simpleName, java.lang.Object... arguments) throws ReflectMember.ReflectMemberException
getNested(String)
only this one will also instantiate the nested class.
It will search for a constructor based on the parsed arguments using a best match. If the nested class
is not static, it will instantiate the class based on it's parent receiver.simpleName
- The name of the nested class. This should be the simple namearguments
- Arguments to be parsed to the constructorReflectMember.ReflectMemberException
- Thrown if a matching constructor could not be found or if it failed being invokedpublic java.lang.Object getParentReceiver()
NULL
if the current class does not have
a receiver or if the current class is not a nested instance.public java.lang.Class<?> getParentClass()
Class
or NULL
if the current class
is not a nested classpublic java.lang.Class<?> getNestedClass(java.lang.String simpleName)
NULL
if no nested class was found. public ReflectClass invokeConstructor(java.lang.Object... arguments) throws ReflectMember.ReflectMemberException, ReflectParameterTypes.ReflectParameterException
ReflectMember.ReflectMemberException
ReflectParameterTypes.ReflectParameterException
#invokeConstructor(Match, Object...)
public ReflectClass invokeConstructor(ReflectMember.Match match, java.lang.Object... arguments) throws ReflectMember.ReflectMemberException, ReflectParameterTypes.ReflectParameterException
Constructor
based on
the arguments parsed.match
- How deep to search for the Constructor
arguments
- Arguments that should be parsed to the Constructor
ReflectMember.ReflectMemberException
- Thrown if the Constructor
could not be found or invokedReflectParameterTypes.ReflectParameterException
- Thrown if an error occurs while getting the types of the arguments#findConstructor(Match, Object...)
,
ReflectConstructor#invoke(Result, Object...)
public ReflectConstructor findConstructor(java.lang.Object... parameterTypes) throws ReflectMember.ReflectMemberException, ReflectParameterTypes.ReflectParameterException
ReflectMember.ReflectMemberException
ReflectParameterTypes.ReflectParameterException
#findConstructor(Match, Object...)
public ReflectConstructor findConstructor(ReflectMember.Match match, java.lang.Object... parameterTypes) throws ReflectMember.ReflectMemberException, ReflectParameterTypes.ReflectParameterException
Constructor
within this class.match
- How deep to search for the Constructor
parameterTypes
- The Class
types of the arguments that should match the Constructor
.
This can also be String
representing the whole Class
path which will be converted into a Class
typeReflectMember.ReflectMemberException
- Thrown if the Constructor
could not be foundReflectParameterTypes.ReflectParameterException
- Thrown if an error occurs while converting String
types into Class
types#findConstructor(Match, ReflectParameterTypes)
public ReflectConstructor findConstructor(ReflectMember.Match match, ReflectParameterTypes parameterTypes) throws ReflectMember.ReflectMemberException
Constructor
within this class.match
- How deep to search for the Constructor
parameterTypes
- A ReflectParameterTypes
instance containing the parameter types that should match the Constructor
ReflectMember.ReflectMemberException
- Thrown if the Constructor
could not be found#findConstructor(Match, Object...)
public java.lang.Object invokeMethod(java.lang.String methodName, java.lang.Object... arguments) throws ReflectMember.ReflectMemberException, ReflectParameterTypes.ReflectParameterException
ReflectMember.ReflectMemberException
ReflectParameterTypes.ReflectParameterException
#invokeMethod(String, Match, Object...)
public java.lang.Object invokeMethod(java.lang.String methodName, ReflectMember.Match match, java.lang.Object... arguments) throws ReflectMember.ReflectMemberException, ReflectParameterTypes.ReflectParameterException
Method
based on
the arguments parsed.methodName
- The name of the Method
match
- How deep to search for the Method
arguments
- Arguments that should be parsed to the Method
ReflectMember.ReflectMemberException
- Thrown if the Method
could not be found or invokedReflectParameterTypes.ReflectParameterException
- Thrown if an error occurs while getting the types of the arguments#findMethod(String, Match, Object...)
,
ReflectMethod#invoke(Result, Object...)
public ReflectMethod findMethod(java.lang.String methodName, java.lang.Object... parameterTypes) throws ReflectMember.ReflectMemberException, ReflectParameterTypes.ReflectParameterException
ReflectMember.ReflectMemberException
ReflectParameterTypes.ReflectParameterException
#findMethod(String, Match, Object...)
public ReflectMethod findMethod(java.lang.String methodName, ReflectMember.Match match, java.lang.Object... parameterTypes) throws ReflectMember.ReflectMemberException, ReflectParameterTypes.ReflectParameterException
Method
within this class.methodName
- The name of the Method
match
- How deep to search for the Method
parameterTypes
- The Class
types of the arguments that should match the Method
.
This can also be String
representing the whole Class
path which will be converted into a Class
typeReflectMember.ReflectMemberException
- Thrown if the Method
could not be foundReflectParameterTypes.ReflectParameterException
- Thrown if an error occurs while converting String
types into Class
types#findMethod(String, Match, ReflectParameterTypes)
public ReflectMethod findMethod(java.lang.String methodName, ReflectMember.Match match, ReflectParameterTypes parameterTypes) throws ReflectMember.ReflectMemberException
Method
within this class.methodName
- The name of the Method
match
- How deep to search for the Method
parameterTypes
- A ReflectParameterTypes
instance containing the parameter types that should match the Method
ReflectMember.ReflectMemberException
- Thrown if the Method
could not be found#findMethod(String, Match, Object...)
public java.lang.Object getFieldValue(java.lang.String fieldName) throws ReflectMember.ReflectMemberException
ReflectMember.ReflectMemberException
#getFieldValue(String, Match)
public java.lang.Object getFieldValue(java.lang.String fieldName, ReflectMember.Match match) throws ReflectMember.ReflectMemberException
Field
fieldName
- Name of the Field
match
- How deep to search for the Field
ReflectMember.ReflectMemberException
- Thrown if the Field
could not be found or invoked#findField(String, Match)
,
ReflectField#getValue(Result)
public void setFieldValue(java.lang.String fieldName, java.lang.Object value) throws ReflectMember.ReflectMemberException
ReflectMember.ReflectMemberException
#setFieldValue(String, Match, Object)
public void setFieldValue(java.lang.String fieldName, ReflectMember.Match match, java.lang.Object value) throws ReflectMember.ReflectMemberException
Field
fieldName
- Name of the Field
match
- How deep to search for the Field
value
- The value to add to the fieldNameReflectMember.ReflectMemberException
- Thrown if the Field
could not be found or changed#findField(String, Match)
,
ReflectField.setValue(Object)
public ReflectField findField(java.lang.String fieldName) throws ReflectMember.ReflectMemberException
ReflectMember.ReflectMemberException
#findField(String, Match)
public ReflectField findField(java.lang.String fieldName, ReflectMember.Match match) throws ReflectMember.ReflectMemberException
Field
within this class.fieldName
- The name of the Field
match
- How deep to search for the Field
ReflectMember.ReflectMemberException
- Thrown if the Field
could not be foundpublic int bridge(MethodBridge callback) throws ReflectClass.ReflectClassException
Constructor
's of this classcallback
- A callback instance that will be called whenever someone calls one of the Constructor
'sConstructor
's that was affectedReflectClass.ReflectClassException
- Thrown if no Constructor
's could be found or if it was not possible to add the hook due to missing
injection systems, such as Xposed Framework and Cydia Substratepublic int bridge(java.lang.String methodName, MethodBridge callback) throws ReflectClass.ReflectClassException
Method
's of this class with a specific namemethodName
- The name of the Method
'scallback
- A callback instance that will be called whenever someone calls one of the Method
'sMethod
's that was affectedReflectClass.ReflectClassException
- Thrown if no Method
's could be found matching the name or if it was not possible to add the hook due to missing
injection systems, such as Xposed Framework and Cydia Substratepublic ReflectClass bindInterface(java.lang.String service) throws ReflectMember.ReflectMemberException, ReflectParameterTypes.ReflectParameterException
public ReflectClass bindInterface(IBinder binder) throws ReflectMember.ReflectMemberException, ReflectParameterTypes.ReflectParameterException
binder
- The IBinder
to bind to the interfaceIBinder
ReceiverReflectMember.ReflectMemberException
- Thrown if using an invalid interfaceReflectParameterTypes.ReflectParameterException
- Thrown if an IBinder
is NULL
bindInterface(String)