fixed bugs, memory leaks, etc
This commit is contained in:
1 parent
aa4f6b6ddc
commit
c3f8f23c1d
124 files changed
+1060
-420
No files matched your search
@@ -8,6 +8,7 @@ import dev.zprestige.prestige.ui.mc.Entry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.ToIntBiFunction;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
@@ -22,6 +23,8 @@ import net.minecraft.client.MinecraftClient;
|
||||
*/
|
||||
public final class Bootstrap {
|
||||
private static boolean started;
|
||||
/** Class bytes as they were before the hooks, kept so self destruct can put the game classes back. */
|
||||
private static final Map<Class<?>, byte[]> ORIGINALS = new ConcurrentHashMap<>();
|
||||
|
||||
private Bootstrap() {}
|
||||
|
||||
@@ -85,6 +88,7 @@ public final class Bootstrap {
|
||||
for (byte[] helper : result.helpers().values()) Definer.define(helper);
|
||||
int code = redefine.applyAsInt(type, result.target());
|
||||
if (code != 0) throw new IllegalStateException("redefine returned JVMTI error " + code);
|
||||
ORIGINALS.put(type, current);
|
||||
report.redefined++;
|
||||
report.moved += result.movedMethods();
|
||||
} catch (Throwable t) {
|
||||
@@ -96,6 +100,31 @@ public final class Bootstrap {
|
||||
return report;
|
||||
}
|
||||
|
||||
/** True when this client was injected, i.e. hooks were applied through JVMTI and can be taken out again. */
|
||||
public static boolean isInjected() {
|
||||
return !ORIGINALS.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Self destruct, part 1: redefines every hooked class back to its original bytes so no game code references the client any
|
||||
* more. Returns the number of classes that could not be restored.
|
||||
*/
|
||||
public static int uninstall() {
|
||||
int failed = 0;
|
||||
for (Map.Entry<Class<?>, byte[]> entry : ORIGINALS.entrySet()) {
|
||||
try {
|
||||
int code = NativeBridge.redefine(entry.getKey(), entry.getValue());
|
||||
if (code != 0) throw new IllegalStateException("JVMTI error " + code);
|
||||
ORIGINALS.remove(entry.getKey());
|
||||
} catch (Throwable t) {
|
||||
failed++;
|
||||
log("could not restore " + entry.getKey().getName() + ": " + t);
|
||||
}
|
||||
}
|
||||
log("hooks removed" + (failed == 0 ? "" : ", " + failed + " classes could not be restored"));
|
||||
return failed;
|
||||
}
|
||||
|
||||
private static void initClient() {
|
||||
try {
|
||||
new Prestige().onInitialize();
|
||||
|
||||
@@ -10,6 +10,9 @@ public final class NativeBridge {
|
||||
/** Appends a line to prestige-native.log, which the injector tails to show progress. */
|
||||
public static native void log(String message);
|
||||
|
||||
/** Disables the class file load hook and unloads prestige_native.dll shortly afterwards; nothing may call the natives after this. */
|
||||
public static native void release();
|
||||
|
||||
/** JVMTI RedefineClasses for one class; returns the JVMTI error code, 0 on success. */
|
||||
public static native int redefine(Class<?> type, byte[] bytes);
|
||||
}
|
||||
Reference in new issue
Block a user