diff --git a/src/main/java/org/spongepowered/asm/launch/platform/MainAttributes.java b/src/main/java/org/spongepowered/asm/launch/platform/MainAttributes.java index 3e58cab6..b1b86c66 100644 --- a/src/main/java/org/spongepowered/asm/launch/platform/MainAttributes.java +++ b/src/main/java/org/spongepowered/asm/launch/platform/MainAttributes.java @@ -33,6 +33,8 @@ import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; +import org.apache.commons.io.IOUtils; + /** * "Main" attribute cache for a URI container, mainly to avoid constantly * opening jar files just to read odd values out of the manifest. @@ -76,13 +78,7 @@ final class MainAttributes { } catch (IOException ex) { // be quiet checkstyle } finally { - if (jarFile != null) { - try { - jarFile.close(); - } catch (IOException ex) { - // this could be an issue later on :( - } - } + IOUtils.closeQuietly(jarFile); } return new Attributes(); } diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/Inject.java b/src/main/java/org/spongepowered/asm/mixin/injection/Inject.java index 196651ac..16c8f056 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/Inject.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/Inject.java @@ -183,6 +183,32 @@ public @interface Inject { */ public int expect() default 1; + /** + * Injection points are in general expected to match every candidate + * instruction in the target method or slice, except in cases where options + * such as {@link At#ordinal} are specified which naturally limit the number + * of results. + * + *
This option allows for sanity-checking to be performed on the results + * of an injection point by specifying a maximum allowed number of matches, + * similar to that afforded by {@link Group#max}. For example if your + * injection is expected to match 4 invocations of a target method, but + * instead matches 5, this can become a detectable tamper condition by + * setting this value to 4. + * + *
Setting any value 1 or greater is allowed. Values less than 1 or less + * than {@link #require} are ignored. {@link #require} supercedes this + * argument such that if allow is less than require the + * value of require is always used.
+ * + *Note that this option is not a limit on the query behaviour of + * this injection point. It is only a sanity check used to ensure that the + * number of matches is not too high + * + * @return Maximum allowed number of injections for this + */ + public int allow() default -1; + /** * Returns constraints which must be validated for this injector to * succeed. See {@link Constraint} for details of constraint formats. diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArg.java b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArg.java index 4851332a..4e47d099 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArg.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArg.java @@ -164,6 +164,32 @@ public @interface ModifyArg { */ public int expect() default 1; + /** + * Injection points are in general expected to match every candidate + * instruction in the target method or slice, except in cases where options + * such as {@link At#ordinal} are specified which naturally limit the number + * of results. + * + *
This option allows for sanity-checking to be performed on the results + * of an injection point by specifying a maximum allowed number of matches, + * similar to that afforded by {@link Group#max}. For example if your + * injection is expected to match 4 invocations of a target method, but + * instead matches 5, this can become a detectable tamper condition by + * setting this value to 4. + * + *
Setting any value 1 or greater is allowed. Values less than 1 or less + * than {@link #require} are ignored. {@link #require} supercedes this + * argument such that if allow is less than require the + * value of require is always used.
+ * + *Note that this option is not a limit on the query behaviour of + * this injection point. It is only a sanity check used to ensure that the + * number of matches is not too high + * + * @return Maximum allowed number of injections for this + */ + public int allow() default -1; + /** * Returns constraints which must be validated for this injector to * succeed. See {@link Constraint} for details of constraint formats. diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArgs.java b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArgs.java index f968cc1d..316e3a05 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArgs.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArgs.java @@ -155,6 +155,32 @@ public @interface ModifyArgs { */ public int expect() default 1; + /** + * Injection points are in general expected to match every candidate + * instruction in the target method or slice, except in cases where options + * such as {@link At#ordinal} are specified which naturally limit the number + * of results. + * + *
This option allows for sanity-checking to be performed on the results + * of an injection point by specifying a maximum allowed number of matches, + * similar to that afforded by {@link Group#max}. For example if your + * injection is expected to match 4 invocations of a target method, but + * instead matches 5, this can become a detectable tamper condition by + * setting this value to 4. + * + *
Setting any value 1 or greater is allowed. Values less than 1 or less + * than {@link #require} are ignored. {@link #require} supercedes this + * argument such that if allow is less than require the + * value of require is always used.
+ * + *Note that this option is not a limit on the query behaviour of + * this injection point. It is only a sanity check used to ensure that the + * number of matches is not too high + * + * @return Maximum allowed number of injections for this + */ + public int allow() default -1; + /** * Returns constraints which must be validated for this injector to * succeed. See {@link Constraint} for details of constraint formats. diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyConstant.java b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyConstant.java index d4e3936e..06b87f8d 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyConstant.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyConstant.java @@ -136,6 +136,32 @@ public @interface ModifyConstant { */ public int expect() default 1; + /** + * Injection points are in general expected to match every candidate + * instruction in the target method or slice, except in cases where options + * such as {@link At#ordinal} are specified which naturally limit the number + * of results. + * + *
This option allows for sanity-checking to be performed on the results + * of an injection point by specifying a maximum allowed number of matches, + * similar to that afforded by {@link Group#max}. For example if your + * injection is expected to match 4 invocations of a target method, but + * instead matches 5, this can become a detectable tamper condition by + * setting this value to 4. + * + *
Setting any value 1 or greater is allowed. Values less than 1 or less + * than {@link #require} are ignored. {@link #require} supercedes this + * argument such that if allow is less than require the + * value of require is always used.
+ * + *Note that this option is not a limit on the query behaviour of + * this injection point. It is only a sanity check used to ensure that the + * number of matches is not too high + * + * @return Maximum allowed number of injections for this + */ + public int allow() default -1; + /** * Returns constraints which must be validated for this injector to * succeed. See {@link Constraint} for details of constraint formats. diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyVariable.java b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyVariable.java index 9f912900..65388982 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyVariable.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyVariable.java @@ -195,6 +195,32 @@ public @interface ModifyVariable { */ public int expect() default 1; + /** + * Injection points are in general expected to match every candidate + * instruction in the target method or slice, except in cases where options + * such as {@link At#ordinal} are specified which naturally limit the number + * of results. + * + *
This option allows for sanity-checking to be performed on the results + * of an injection point by specifying a maximum allowed number of matches, + * similar to that afforded by {@link Group#max}. For example if your + * injection is expected to match 4 invocations of a target method, but + * instead matches 5, this can become a detectable tamper condition by + * setting this value to 4. + * + *
Setting any value 1 or greater is allowed. Values less than 1 or less + * than {@link #require} are ignored. {@link #require} supercedes this + * argument such that if allow is less than require the + * value of require is always used.
+ * + *Note that this option is not a limit on the query behaviour of + * this injection point. It is only a sanity check used to ensure that the + * number of matches is not too high + * + * @return Maximum allowed number of injections for this + */ + public int allow() default -1; + /** * Returns constraints which must be validated for this injector to * succeed. See {@link Constraint} for details of constraint formats. diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/Redirect.java b/src/main/java/org/spongepowered/asm/mixin/injection/Redirect.java index 20a640a8..5cb286eb 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/Redirect.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/Redirect.java @@ -304,6 +304,32 @@ public @interface Redirect { */ public int expect() default 1; + /** + * Injection points are in general expected to match every candidate + * instruction in the target method or slice, except in cases where options + * such as {@link At#ordinal} are specified which naturally limit the number + * of results. + * + *
This option allows for sanity-checking to be performed on the results + * of an injection point by specifying a maximum allowed number of matches, + * similar to that afforded by {@link Group#max}. For example if your + * injection is expected to match 4 invocations of a target method, but + * instead matches 5, this can become a detectable tamper condition by + * setting this value to 4. + * + *
Setting any value 1 or greater is allowed. Values less than 1 or less + * than {@link #require} are ignored. {@link #require} supercedes this + * argument such that if allow is less than require the + * value of require is always used.
+ * + *Note that this option is not a limit on the query behaviour of
+ * this injection point. It is only a sanity check used to ensure that the
+ * number of matches is not too high
+ *
+ * @return Maximum allowed number of injections for this
+ */
+ public int allow() default -1;
+
/**
* Returns constraints which must be validated for this injector to
* succeed. See {@link Constraint} for details of constraint formats.
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java
index 9feb7251..cd55b591 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java
@@ -128,6 +128,11 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
*/
private int requiredCallbackCount = 0;
+ /**
+ * Maximum number of callbacks allowed to be injected
+ */
+ private int maxCallbackCount = Integer.MAX_VALUE;
+
/**
* Actual number of injected callbacks
*/
@@ -217,6 +222,11 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
} else if (this.group.isDefault()) {
this.requiredCallbackCount = this.mixin.getDefaultRequiredInjections();
}
+
+ Integer allow = Annotations.