Skip to content

Commit

Permalink
1.3.2 b4
Browse files Browse the repository at this point in the history
  • Loading branch information
3093FengMing committed Sep 30, 2023
1 parent 30ccd2d commit 49062d1
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/fengming/vaultpatcher_asm/config/Pairs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -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{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<String>>() {}.getType());
}
break;
}
case "classes": {
case "c":
case "classes":
if (jr.peek() == JsonToken.BEGIN_ARRAY) {
classes = GSON.fromJson(jr, new TypeToken<List<String>>() {}.getType());
}
break;
}
case "apply_mods": {
case "a":
case "apply_mods":
if (jr.peek() == JsonToken.BEGIN_ARRAY) {
applyMods = GSON.fromJson(jr, new TypeToken<List<String>>() {}.getType());
}
break;
}
default: {
jr.skipValue();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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", "<p>"), "ASMTransformMethod-InvokeDynamic", v.replace("\u0001", "<p>"), input.name, info);
Utils.printDebugInfo(str.replace("\u0001", "<p>"), "ASMTransformMethod-StringConcat", v.replace("\u0001", "<p>"), input.name, info);
invokeDynamicInsnNode.bsmArgs[i] = v;
}
}
Expand All @@ -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);
// }
// });
//
}
}
}
Expand All @@ -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()));
Expand Down Expand Up @@ -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;
}
Expand All @@ -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()))) {
Expand Down

0 comments on commit 49062d1

Please sign in to comment.