mirror of
https://github.com/SuspiciousActivity/ProGuard-Unmapper.git
synced 2026-08-13 18:17:44 +00:00
Update
Updated ASM & some more fixes and options
This commit is contained in:
1 parent
33830fc015
commit
964e264bdb
2 files changed
+22
-48
No files matched your search
@@ -1,6 +1,5 @@
|
||||
package me.Unmapper;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -43,6 +42,8 @@ public class ClassNodeRemapper {
|
||||
cn.name = getOldClassName(cn.name);
|
||||
cn.superName = getOldClassName(cn.superName);
|
||||
cn.signature = getOldSignature(cn.signature);
|
||||
if (Main.fakeJava8)
|
||||
cn.version = 52;
|
||||
if (!cn.interfaces.isEmpty()) {
|
||||
List<String> newInterfaces = new ArrayList<String>();
|
||||
for (String s : cn.interfaces) {
|
||||
@@ -65,8 +66,6 @@ public class ClassNodeRemapper {
|
||||
}
|
||||
}
|
||||
|
||||
private static final int ACC_STATIC = 0x0008;
|
||||
|
||||
private void remapMethods(ClassNode cn) {
|
||||
if (cn.methods == null)
|
||||
return;
|
||||
@@ -84,21 +83,17 @@ public class ClassNodeRemapper {
|
||||
mn.exceptions = newExceptions;
|
||||
}
|
||||
if (mn.localVariables != null && !mn.localVariables.isEmpty()) {
|
||||
if (Main.removeLocals) {
|
||||
mn.localVariables.clear();
|
||||
} else {
|
||||
Iterator<LocalVariableNode> lvns = mn.localVariables.iterator();
|
||||
while (lvns.hasNext()) {
|
||||
LocalVariableNode lvn = lvns.next();
|
||||
if (Main.removeLocals) {
|
||||
if ((mn.access & ACC_STATIC) == 0 && lvn.index == 0) { // "this" for non-static methods
|
||||
lvn.name = "this"; // should always be "this"
|
||||
} else if (!isAscii(lvn.name)) {
|
||||
lvns.remove();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
lvn.desc = getOldMemberFieldDesc(lvn.desc);
|
||||
lvn.signature = getOldSignature(lvn.signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mn.tryCatchBlocks != null && !mn.tryCatchBlocks.isEmpty()) {
|
||||
for (TryCatchBlockNode tcbn : mn.tryCatchBlocks) {
|
||||
tcbn.type = getOldClassName(tcbn.type);
|
||||
@@ -122,14 +117,6 @@ public class ClassNodeRemapper {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAscii(String s) {
|
||||
for (char c : s.toCharArray()) {
|
||||
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getOldClassName(String name) {
|
||||
if (name == null)
|
||||
return null;
|
||||
@@ -337,20 +324,7 @@ public class ClassNodeRemapper {
|
||||
Object o = node.bsmArgs[i];
|
||||
if (o instanceof Type) {
|
||||
Type type = (Type) o;
|
||||
try {
|
||||
Field f_off = Type.class.getDeclaredField("off");
|
||||
f_off.setAccessible(true);
|
||||
Field f_len = Type.class.getDeclaredField("len");
|
||||
f_len.setAccessible(true);
|
||||
Field f_buf = Type.class.getDeclaredField("buf");
|
||||
f_buf.setAccessible(true);
|
||||
String buf = new String((char[]) f_buf.get(type));
|
||||
String oldBuf = getOldClassName(buf);
|
||||
f_buf.set(type, oldBuf.toCharArray());
|
||||
f_len.set(type, oldBuf.length());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
node.bsmArgs[i] = Type.getType(getOldSignature(type.getDescriptor()));
|
||||
} else if (o instanceof Handle) {
|
||||
Handle h = (Handle) o;
|
||||
node.bsmArgs[i] = new Handle(h.getTag(), getOldClassName(h.getOwner()),
|
||||
@@ -373,20 +347,7 @@ public class ClassNodeRemapper {
|
||||
LdcInsnNode node = (LdcInsnNode) n;
|
||||
if (node.cst instanceof Type) {
|
||||
Type type = (Type) node.cst;
|
||||
try {
|
||||
Field f_off = Type.class.getDeclaredField("off");
|
||||
f_off.setAccessible(true);
|
||||
Field f_len = Type.class.getDeclaredField("len");
|
||||
f_len.setAccessible(true);
|
||||
Field f_buf = Type.class.getDeclaredField("buf");
|
||||
f_buf.setAccessible(true);
|
||||
String buf = new String((char[]) f_buf.get(type));
|
||||
String oldBuf = getOldClassName(buf);
|
||||
f_buf.set(type, oldBuf.toCharArray());
|
||||
f_len.set(type, oldBuf.length());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
node.cst = Type.getType(getOldSignature(type.getDescriptor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-1
@@ -23,17 +23,30 @@ public class Main implements Opcodes {
|
||||
private static MappingReader mapping;
|
||||
|
||||
public static boolean removeLocals = false;
|
||||
public static boolean fakeJava8 = false;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length < 3) {
|
||||
System.out.println("Syntax: input.jar mapping.txt output.jar (-l)");
|
||||
System.out.println("\t-l\tRemoves local variables which are not ASCII");
|
||||
System.out.println("\t\t\t(let the decompilers generate better names)");
|
||||
System.out.println("\t-j\tFake Java 8 class version");
|
||||
System.out.println("\t\t\t(JDGUI doesn't really work without this)");
|
||||
System.exit(1);
|
||||
}
|
||||
if (args.length > 3) {
|
||||
removeLocals = args[3].equalsIgnoreCase("-l");
|
||||
for (int i = 3; i < args.length; i++) {
|
||||
switch (args[i].toLowerCase()) {
|
||||
case "-l":
|
||||
removeLocals = true;
|
||||
System.out.println("Enabled local variable removal.");
|
||||
break;
|
||||
case "-j":
|
||||
fakeJava8 = true;
|
||||
System.out.println("Enabled fake Java 8.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
load(new File(args[0]));
|
||||
map(new File(args[1]));
|
||||
|
||||
Reference in new issue
Block a user