Add two methods for constructors

This commit is contained in:
LoveSy 2024-07-22 21:53:57 +08:00
parent 5458273031
commit 55efdf9d15
No known key found for this signature in database
8 changed files with 62 additions and 21 deletions

View File

@ -6,8 +6,8 @@ plugins {
android {
namespace = "io.github.libxposed.api"
compileSdk = 34
buildToolsVersion = "34.0.0"
compileSdk = 35
buildToolsVersion = "35.0.0"
defaultConfig {
minSdk = 24
@ -20,8 +20,8 @@ android {
}
compileOptions {
targetCompatibility = JavaVersion.VERSION_21
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}
publishing {

View File

@ -365,6 +365,17 @@ public interface XposedInterface {
@Nullable
Object invokeOrigin(@NonNull Method method, @Nullable Object thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException;
/**
* Basically the same as {@link Constructor#newInstance(Object...)}, but calls the original constructor
* as it was before the interception by Xposed.
* @param constructor The constructor to create and initialize a new instance
* @param thisObject The instance to be constructed
* @param args The arguments used for the construction
* @param <T> The type of the instance
* @see Constructor#newInstance(Object...)
*/
<T> void invokeOrigin(@NonNull Constructor<T> constructor, @NonNull T thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException;
/**
* Invokes a special (non-virtual) method on a given object instance, similar to the functionality of
* {@code CallNonVirtual<type>Method} in JNI, which invokes an instance (nonstatic) method on a Java
@ -382,6 +393,21 @@ public interface XposedInterface {
@Nullable
Object invokeSpecial(@NonNull Method method, @NonNull Object thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException;
/**
* Invokes a special (non-virtual) method on a given object instance, similar to the functionality of
* {@code CallNonVirtual<type>Method} in JNI, which invokes an instance (nonstatic) method on a Java
* object. This method is useful when you need to call a specific method on an object, bypassing any
* overridden methods in subclasses and directly invoking the method defined in the specified class.
*
* <p>This method is useful when you need to call {@code super.xxx()} in a hooked constructor.</p>
*
* @param constructor The constructor to create and initialize a new instance
* @param thisObject The instance to be constructed
* @param args The arguments used for the construction
* @see Constructor#newInstance(Object...)
*/
<T> void invokeSpecial(@NonNull Constructor<T> constructor, @NonNull T thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException;
/**
* Basically the same as {@link Constructor#newInstance(Object...)}, but calls the original constructor
* as it was before the interception by Xposed.

View File

@ -89,12 +89,22 @@ public class XposedInterfaceWrapper implements XposedInterface {
return mBase.invokeOrigin(method, thisObject, args);
}
@Override
public <T> void invokeOrigin(@NonNull Constructor<T> constructor, @NonNull T thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
mBase.invokeOrigin(constructor, thisObject, args);
}
@Nullable
@Override
public final Object invokeSpecial(@NonNull Method method, @NonNull Object thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
return mBase.invokeSpecial(method, thisObject, args);
}
@Override
public <T> void invokeSpecial(@NonNull Constructor<T> constructor, @NonNull T thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
mBase.invokeSpecial(constructor, thisObject, args);
}
@NonNull
@Override
public final <T> T newInstanceOrigin(@NonNull Constructor<T> constructor, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, InstantiationException {

View File

@ -1,8 +1,8 @@
[versions]
annotation = "1.7.1"
kotlin = "1.9.23"
lint = "31.3.2"
agp = "8.3.2"
annotation = "1.8.0"
kotlin = "2.0.0"
lint = "31.5.1"
agp = "8.5.1"
[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }

Binary file not shown.

View File

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

7
gradlew vendored
View File

@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

22
gradlew.bat vendored
View File

@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail