2 Commits
Author SHA1 Message Date
SuspiciousActivity 964e264bdb Update
Updated ASM & some more fixes and options
2021-06-09 12:14:02 +02:00
SuspiciousActivity 33830fc015 Fixed class members where the type is not yet read 2019-10-10 17:34:00 +02:00
3 changed files with 64 additions and 59 deletions

No files matched your search

+12 -51
View File
@@ -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,19 +83,15 @@ public class ClassNodeRemapper {
mn.exceptions = newExceptions;
}
if (mn.localVariables != null && !mn.localVariables.isEmpty()) {
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;
}
if (Main.removeLocals) {
mn.localVariables.clear();
} else {
Iterator<LocalVariableNode> lvns = mn.localVariables.iterator();
while (lvns.hasNext()) {
LocalVariableNode lvn = lvns.next();
lvn.desc = getOldMemberFieldDesc(lvn.desc);
lvn.signature = getOldSignature(lvn.signature);
}
lvn.desc = getOldMemberFieldDesc(lvn.desc);
lvn.signature = getOldSignature(lvn.signature);
}
}
if (mn.tryCatchBlocks != null && !mn.tryCatchBlocks.isEmpty()) {
@@ -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()));
}
}
}
+15 -2
View File
@@ -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");
System.out.println("Enabled local variable removal.");
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]));
+37 -6
View File
@@ -19,6 +19,23 @@ public class MappingReader {
}
public void load() throws IOException {
// Read all the class mappings
try (BufferedReader read = new BufferedReader(new FileReader(mappingFile))) {
String s;
while ((s = read.readLine()) != null) {
s = s.trim();
if (s.startsWith("#"))
continue;
if (s.endsWith(":")) {
parseClassMapping(s);
}
}
}
// Read member mappings in a second run, we first had to read ALL class mappings
// for this to work properly
try (BufferedReader read = new BufferedReader(new FileReader(mappingFile))) {
String className = null;
String s;
@@ -30,7 +47,7 @@ public class MappingReader {
continue;
if (s.endsWith(":")) {
className = parseClassMapping(s);
className = getClassMapping(s);
} else if (className != null) {
parseClassMemberMapping(className, s);
}
@@ -38,7 +55,25 @@ public class MappingReader {
}
}
private String parseClassMapping(String s) {
private void parseClassMapping(String s) {
int splitIdx = s.indexOf("->");
if (splitIdx < 0) {
return;
}
int colonIndex = s.indexOf(':', splitIdx + 2);
if (colonIndex < 0) {
return;
}
String originalName = s.substring(0, splitIdx).trim().replace('.', '/');
String obfuscatedName = s.substring(splitIdx + 2, colonIndex).trim().replace('.', '/');
classMappings.put(obfuscatedName, originalName);
internalReversedClassMappings.put(originalName, obfuscatedName);
}
private String getClassMapping(String s) {
int splitIdx = s.indexOf("->");
if (splitIdx < 0) {
return null;
@@ -50,10 +85,6 @@ public class MappingReader {
}
String originalName = s.substring(0, splitIdx).trim().replace('.', '/');
String obfuscatedName = s.substring(splitIdx + 2, colonIndex).trim().replace('.', '/');
classMappings.put(obfuscatedName, originalName);
internalReversedClassMappings.put(originalName, obfuscatedName);
return originalName;
}