From 49062d17a5d73278a07293c8839991bbf7eef52c Mon Sep 17 00:00:00 2001 From: FengMing <83573615+3093FengMing@users.noreply.github.com> Date: Sat, 30 Sep 2023 19:04:02 +0800 Subject: [PATCH] 1.3.2 b4 --- .../vaultpatcher_asm/config/DebugMode.java | 3 ++ .../vaultpatcher_asm/config/Pairs.java | 2 + .../vaultpatcher_asm/config/PatchInfo.java | 7 ++- .../config/TargetClassInfo.java | 13 +++++- .../config/TranslationInfo.java | 8 +++- .../config/VaultPatcherConfig.java | 16 +++---- .../core/VPClassTransformer.java | 44 +++++++++++-------- 7 files changed, 63 insertions(+), 30 deletions(-) diff --git a/src/main/java/me/fengming/vaultpatcher_asm/config/DebugMode.java b/src/main/java/me/fengming/vaultpatcher_asm/config/DebugMode.java index 1a8ecea..62659fe 100644 --- a/src/main/java/me/fengming/vaultpatcher_asm/config/DebugMode.java +++ b/src/main/java/me/fengming/vaultpatcher_asm/config/DebugMode.java @@ -43,12 +43,15 @@ public void readJson(JsonReader reader) throws IOException { reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT) { switch (reader.nextName()) { + case "e": case "is_enable": setEnable(reader.nextBoolean()); break; + case "f": case "output_format": setOutputFormat(reader.nextString()); break; + case "m": case "output_mode": setOutputMode(reader.nextInt()); break; diff --git a/src/main/java/me/fengming/vaultpatcher_asm/config/Pairs.java b/src/main/java/me/fengming/vaultpatcher_asm/config/Pairs.java index 16488e8..ff00f28 100644 --- a/src/main/java/me/fengming/vaultpatcher_asm/config/Pairs.java +++ b/src/main/java/me/fengming/vaultpatcher_asm/config/Pairs.java @@ -26,10 +26,12 @@ public void readJson(JsonReader reader) throws IOException { reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT) { switch (reader.nextName()) { + case "k": case "key": { setKey(reader.nextString()); break; } + case "v": case "value": { setValue(reader.nextString()); break; diff --git a/src/main/java/me/fengming/vaultpatcher_asm/config/PatchInfo.java b/src/main/java/me/fengming/vaultpatcher_asm/config/PatchInfo.java index de6932d..2c87b40 100644 --- a/src/main/java/me/fengming/vaultpatcher_asm/config/PatchInfo.java +++ b/src/main/java/me/fengming/vaultpatcher_asm/config/PatchInfo.java @@ -58,20 +58,25 @@ public void readJson(JsonReader reader) throws IOException { reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT) { switch (reader.nextName()) { + case "n": case "name": setName(reader.nextString()); break; + case "d": case "desc": setDesc(reader.nextString()); break; + case "m": case "mods": setMods(reader.nextString()); break; + case "a": case "authors": setAuthors(reader.nextString()); break; - case "dynamic": + case "e": case "dyn": + case "dynamic": setDynamic(reader.nextBoolean()); break; default: diff --git a/src/main/java/me/fengming/vaultpatcher_asm/config/TargetClassInfo.java b/src/main/java/me/fengming/vaultpatcher_asm/config/TargetClassInfo.java index 9ebfefd..642f802 100644 --- a/src/main/java/me/fengming/vaultpatcher_asm/config/TargetClassInfo.java +++ b/src/main/java/me/fengming/vaultpatcher_asm/config/TargetClassInfo.java @@ -3,6 +3,7 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; +import me.fengming.vaultpatcher_asm.Utils; import java.io.IOException; @@ -11,6 +12,7 @@ public class TargetClassInfo { private String method = ""; private String local = ""; private byte matchMode = 0; + private boolean isLocal = false; public void readJson(JsonReader reader) throws IOException { reader.beginObject(); @@ -76,13 +78,22 @@ public String getLocal() { } public void setLocal(String local) { - this.local = local; + if (Utils.isBlank(local)) { + this.local = local; + } else { + isLocal = local.charAt(0) == 'V'; + this.local = local.substring(1); + } } public byte getMatchMode() { return matchMode; } + public boolean isLocal() { + return isLocal; + } + @Override public String toString() { return "TargetClassInfo{" + diff --git a/src/main/java/me/fengming/vaultpatcher_asm/config/TranslationInfo.java b/src/main/java/me/fengming/vaultpatcher_asm/config/TranslationInfo.java index 7a55a07..2889f21 100644 --- a/src/main/java/me/fengming/vaultpatcher_asm/config/TranslationInfo.java +++ b/src/main/java/me/fengming/vaultpatcher_asm/config/TranslationInfo.java @@ -13,19 +13,23 @@ public void readJson(JsonReader reader) throws IOException { reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT) { switch (reader.nextName()) { - case "target_class": - case "target": { + case "t": + case "target": + case "target_class": { getTargetClassInfo().readJson(reader); break; } + case "k": case "key": { setKey(reader.nextString()); break; } + case "v": case "value": { setValue(reader.nextString()); break; } + case "p": case "pairs": { getPairs().readJson(reader); break; diff --git a/src/main/java/me/fengming/vaultpatcher_asm/config/VaultPatcherConfig.java b/src/main/java/me/fengming/vaultpatcher_asm/config/VaultPatcherConfig.java index 8100426..d52bf77 100644 --- a/src/main/java/me/fengming/vaultpatcher_asm/config/VaultPatcherConfig.java +++ b/src/main/java/me/fengming/vaultpatcher_asm/config/VaultPatcherConfig.java @@ -82,30 +82,30 @@ public static void readConfig(Path path) throws IOException { jr.beginObject(); while (jr.peek() != JsonToken.END_OBJECT) { switch (jr.nextName()) { - case "debug_mode": { + case "d": + case "debug_mode": if (jr.peek() == JsonToken.BEGIN_OBJECT) { debug.readJson(jr); } break; - } - case "mods": { + case "m": + case "mods": if (jr.peek() == JsonToken.BEGIN_ARRAY) { mods = GSON.fromJson(jr, new TypeToken>() {}.getType()); } break; - } - case "classes": { + case "c": + case "classes": if (jr.peek() == JsonToken.BEGIN_ARRAY) { classes = GSON.fromJson(jr, new TypeToken>() {}.getType()); } break; - } - case "apply_mods": { + case "a": + case "apply_mods": if (jr.peek() == JsonToken.BEGIN_ARRAY) { applyMods = GSON.fromJson(jr, new TypeToken>() {}.getType()); } break; - } default: { jr.skipValue(); break; diff --git a/src/main/java/me/fengming/vaultpatcher_asm/core/VPClassTransformer.java b/src/main/java/me/fengming/vaultpatcher_asm/core/VPClassTransformer.java index 06c91fa..f6a637d 100644 --- a/src/main/java/me/fengming/vaultpatcher_asm/core/VPClassTransformer.java +++ b/src/main/java/me/fengming/vaultpatcher_asm/core/VPClassTransformer.java @@ -2,10 +2,7 @@ import me.fengming.vaultpatcher_asm.Utils; import me.fengming.vaultpatcher_asm.VaultPatcher; -import me.fengming.vaultpatcher_asm.config.DebugMode; -import me.fengming.vaultpatcher_asm.config.Pairs; -import me.fengming.vaultpatcher_asm.config.TranslationInfo; -import me.fengming.vaultpatcher_asm.config.VaultPatcherConfig; +import me.fengming.vaultpatcher_asm.config.*; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.*; @@ -65,7 +62,7 @@ else if (instruction.getType() == AbstractInsnNode.INVOKE_DYNAMIC_INSN) { parts[j] = Utils.matchPairs(pairs, parts[j], false); } String v = String.join("\u0001", parts); - Utils.printDebugInfo(str.replace("\u0001", "

"), "ASMTransformMethod-InvokeDynamic", v.replace("\u0001", "

"), input.name, info); + Utils.printDebugInfo(str.replace("\u0001", "

"), "ASMTransformMethod-StringConcat", v.replace("\u0001", "

"), input.name, info); invokeDynamicInsnNode.bsmArgs[i] = v; } } @@ -78,19 +75,30 @@ else if (instruction.getType() == AbstractInsnNode.METHOD_INSN) { if (methodInsnNode.desc.endsWith(")Ljava/lang/String;") && !methodInsnNode.name.equals("__replaceMethod") && matchLocal(info, methodInsnNode.name, true)) { - insertPairs(info, method, methodInsnNode); - Utils.printDebugInfo("Runtime Determination", "ASMTransformMethod-InsertMethodCalled", "Runtime Determination", input.name, info); + insertReplace(info, method, methodInsnNode); + Utils.printDebugInfo("Runtime Determination", "ASMTransformMethod-InsertMethodReturn", "Runtime Determination", input.name, info); } } // For any local variable of String else if (localVarEnable && instruction.getType() == AbstractInsnNode.VAR_INSN) { VarInsnNode varInsnNode = (VarInsnNode) instruction; - if (varInsnNode.getOpcode() == Opcodes.ASTORE + + // Local Variable + if ((varInsnNode.getOpcode() == Opcodes.ASTORE || varInsnNode.getOpcode() == Opcodes.ALOAD) && matchLocal(info, localVariableMap.getOrDefault(varInsnNode.var, null), false)) { - insertPairs(info, method, varInsnNode); - Utils.printDebugInfo("Runtime Determination", "ASMTransformMethod-InsertLocalVariableStore", "Runtime Determination", input.name, info); + insertReplace(info, method, varInsnNode); + Utils.printDebugInfo("Runtime Determination", "ASMTransformMethod-InsertLocalVariableStore/Load", "Runtime Determination", input.name, info); } + +// // Parameters +// method.parameters.forEach(p -> { +// if (p.name.equals(localVariableMap.getOrDefault(varInsnNode.var, null))) { +// insertReplace(info, method, varInsnNode); +// Utils.printDebugInfo("Runtime Determination", "ASMTransformMethod-InsertLocalVariableLoad", "Runtime Determination", input.name, info); +// } +// }); +// } } } @@ -109,7 +117,7 @@ private static void fieldReplace(ClassNode input, TranslationInfo info) { } } - private static void insertPairs(TranslationInfo info, MethodNode method, AbstractInsnNode nodePosition) { + private static void insertReplace(TranslationInfo info, MethodNode method, AbstractInsnNode nodePosition) { InsnList list = new InsnList(); // array list.add(__makeNewArray(info.getPairs().getPairs().entrySet())); @@ -160,10 +168,10 @@ private static AbstractInsnNode __index(int i) { public static boolean matchLocal(TranslationInfo info, String name, boolean isMethod) { if (name == null) return false; - String l = info.getTargetClassInfo().getLocal(); - if (Utils.isBlank(l)) return false; - if ((l.charAt(0) == 'M' && isMethod) || (l.charAt(0) == 'V' && !isMethod)) { - return l.substring(1).equals(name); + TargetClassInfo i = info.getTargetClassInfo(); + if (Utils.isBlank(i.getLocal())) return false; + if ((!i.isLocal() && isMethod) || (i.isLocal() && !isMethod)) { + return i.getLocal().equals(name); } return false; } @@ -173,9 +181,9 @@ public static boolean matchLocal(TranslationInfo info, String name, boolean isMe public void accept(ClassNode input) { if (this.translationInfo == null) { for (TranslationInfo info : Utils.translationInfos) { - if (Utils.isBlank(this.translationInfo.getTargetClassInfo().getName()) || input.name.equals(Utils.rawPackage(this.translationInfo.getTargetClassInfo().getName()))) { - methodReplace(input, this.translationInfo); - fieldReplace(input, this.translationInfo); + if (Utils.isBlank(info.getTargetClassInfo().getName()) || input.name.equals(Utils.rawPackage(info.getTargetClassInfo().getName()))) { + methodReplace(input, info); + fieldReplace(input, info); } } } else if (Utils.isBlank(this.translationInfo.getTargetClassInfo().getName()) || input.name.equals(Utils.rawPackage(this.translationInfo.getTargetClassInfo().getName()))) {