Make updatemappings parameter renamer work, add importmappings parameter renamer, more refactoring
This commit is contained in:
@@ -24,9 +24,12 @@
|
||||
*/
|
||||
package net.runelite.deob.updater;
|
||||
|
||||
import java.util.List;
|
||||
import net.runelite.asm.ClassFile;
|
||||
import net.runelite.asm.ClassGroup;
|
||||
import net.runelite.asm.Method;
|
||||
import net.runelite.asm.attributes.code.LocalVariable;
|
||||
import net.runelite.asm.attributes.code.Parameter;
|
||||
import net.runelite.deob.deobfuscators.mapping.ParallelExecutorMapping;
|
||||
|
||||
public class ParameterRenamer
|
||||
@@ -49,9 +52,39 @@ public class ParameterRenamer
|
||||
for (Method sourceM : sourceCF.getMethods())
|
||||
{
|
||||
Method destM = (Method) mapping.get(sourceM);
|
||||
if (destM != null)
|
||||
if (sourceM.getParameters() != null && !sourceM.getParameters().isEmpty() && destM.getParameters().size() >= 1)
|
||||
{
|
||||
destM.setParameters(sourceM.getParameters());
|
||||
List<Parameter> oldParams = destM.getParameters();
|
||||
for (int i = 0; i < sourceM.getParameters().size(); i++)
|
||||
{
|
||||
String name = sourceM.getParameters().get(i).getName();
|
||||
if (name.matches("arg[0-9]") || name.length() <= 2 && (name.charAt(0) != 'x' || name.charAt(0) != 'y'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Parameter oldParam = oldParams.get(i);
|
||||
LocalVariable oldVar = oldParam.getLocalVariable();
|
||||
|
||||
Parameter newParam = new Parameter(name, oldParam.getAccess());
|
||||
oldParams.set(i, newParam);
|
||||
|
||||
if (oldVar == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
LocalVariable newVar = new LocalVariable(
|
||||
name,
|
||||
oldVar.getDesc(),
|
||||
oldVar.getSignature(),
|
||||
oldVar.getStart(),
|
||||
oldVar.getEnd(),
|
||||
oldVar.getIndex()
|
||||
);
|
||||
|
||||
newParam.setLocalVariable(newVar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ public class HookClass
|
||||
@SerializedName("class")
|
||||
String clazz;
|
||||
String name;
|
||||
int access;
|
||||
List<HookField> fields;
|
||||
List<HookMethod> methods;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ public class HookField
|
||||
String field;
|
||||
String owner;
|
||||
String name;
|
||||
int access;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
|
||||
@@ -39,6 +39,8 @@ import net.runelite.asm.Type;
|
||||
import net.runelite.asm.attributes.Annotations;
|
||||
import net.runelite.asm.attributes.annotation.Annotation;
|
||||
import net.runelite.asm.attributes.annotation.Element;
|
||||
import net.runelite.asm.attributes.code.LocalVariable;
|
||||
import net.runelite.asm.attributes.code.Parameter;
|
||||
import net.runelite.asm.signature.Signature;
|
||||
import net.runelite.asm.signature.util.VirtualMethods;
|
||||
import static net.runelite.deob.DeobAnnotations.EXPORT;
|
||||
@@ -97,7 +99,7 @@ public class HookImporter
|
||||
@Ignore
|
||||
public void importHooks()
|
||||
{
|
||||
int classes = 0, fields = 0, methods = 0, access = 0;
|
||||
int classes = 0, fields = 0, methods = 0, params = 0;
|
||||
NameMappings mappings = new NameMappings();
|
||||
|
||||
for (HookClass hc : hooks)
|
||||
@@ -107,12 +109,6 @@ public class HookImporter
|
||||
|
||||
assert cf != null;
|
||||
|
||||
if (cf.getAccess() != hc.access)
|
||||
{
|
||||
cf.setAccess(hc.access);
|
||||
++access;
|
||||
}
|
||||
|
||||
String implementsName = getAnnotation(cf.getAnnotations(), IMPLEMENTS);
|
||||
if (implementsName.isEmpty())
|
||||
{
|
||||
@@ -122,23 +118,28 @@ public class HookImporter
|
||||
++classes;
|
||||
}
|
||||
|
||||
if (!implementsName.isEmpty() && !implementsName.equals(hc.clazz))
|
||||
{
|
||||
logger.info("Runestar calls class {} {}, while we call it {}", hc.name, hc.clazz, implementsName);
|
||||
}
|
||||
|
||||
for (HookField fh : hc.fields)
|
||||
{
|
||||
if (fh.field.startsWith("__"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ClassFile cf2 = findClassWithObfuscatedName(fh.owner);
|
||||
assert cf2 != null;
|
||||
|
||||
Field f = findFieldWithObfuscatedName(cf2, fh.name);
|
||||
if (f == null)
|
||||
{
|
||||
logger.warn("Missing field {}", fh); // inlined constant maybe?
|
||||
continue;
|
||||
}
|
||||
|
||||
if (f.getAccessFlags() != fh.access)
|
||||
{
|
||||
f.setAccessFlags(fh.access);
|
||||
++access;
|
||||
}
|
||||
|
||||
String exportedName = getAnnotation(f.getAnnotations(), EXPORT);
|
||||
if (exportedName.isEmpty())
|
||||
{
|
||||
@@ -155,11 +156,20 @@ public class HookImporter
|
||||
mappings.map(f.getPoolField(), deobfuscatedFieldName);
|
||||
++fields;
|
||||
}
|
||||
|
||||
if (!exportedName.isEmpty() && !exportedName.equals(fh.field))
|
||||
{
|
||||
logger.info("Runestar calls field {}.{} {}, while we call it {}", fh.owner, fh.name, fh.field, exportedName);
|
||||
}
|
||||
}
|
||||
|
||||
outer:
|
||||
for (HookMethod hm : hc.methods)
|
||||
{
|
||||
if (hm.method.startsWith("__"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ClassFile cf2 = findClassWithObfuscatedName(hm.owner);
|
||||
assert cf2 != null;
|
||||
@@ -171,10 +181,40 @@ public class HookImporter
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m.getAccessFlags() != hm.access)
|
||||
if (hm.parameters != null && !hm.parameters.isEmpty() && m.getParameters().size() >= 1)
|
||||
{
|
||||
m.setAccessFlags(hm.access);
|
||||
++access;
|
||||
List<Parameter> oldParams = m.getParameters();
|
||||
for (int i = 0; i < hm.parameters.size(); i++)
|
||||
{
|
||||
String name = hm.parameters.get(i);
|
||||
if (name.matches("arg[0-9]") || name.length() <= 2 && (name.charAt(0) != 'x' || name.charAt(0) != 'y'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Parameter oldParam = oldParams.get(i);
|
||||
LocalVariable oldVar = oldParam.getLocalVariable();
|
||||
|
||||
Parameter newParam = new Parameter(name, oldParam.getAccess());
|
||||
oldParams.set(i, newParam);
|
||||
params++;
|
||||
|
||||
if (oldVar == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
LocalVariable newVar = new LocalVariable(
|
||||
name,
|
||||
oldVar.getDesc(),
|
||||
oldVar.getSignature(),
|
||||
oldVar.getStart(),
|
||||
oldVar.getEnd(),
|
||||
oldVar.getIndex()
|
||||
);
|
||||
|
||||
newParam.setLocalVariable(newVar);
|
||||
}
|
||||
}
|
||||
|
||||
// maybe only the base class method is exported
|
||||
@@ -184,6 +224,10 @@ public class HookImporter
|
||||
String exportedName = getAnnotation(method.getAnnotations(), EXPORT);
|
||||
if (!exportedName.isEmpty())
|
||||
{
|
||||
if (!exportedName.equals(hm.method))
|
||||
{
|
||||
logger.info("Runestar calls {}.{} {}, while we call it {}", hm.owner, hm.name, hm.method, exportedName);
|
||||
}
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
@@ -198,7 +242,7 @@ public class HookImporter
|
||||
Renamer renamer = new Renamer(mappings);
|
||||
renamer.run(group);
|
||||
|
||||
logger.info("Imported {} classes, {} fields, {} methods, {} access levels", classes, fields, methods, access);
|
||||
logger.info("Imported {} classes, {} fields, {} methods, {} params", classes, fields, methods, params);
|
||||
}
|
||||
|
||||
private ClassFile findClassWithObfuscatedName(String name)
|
||||
@@ -259,8 +303,7 @@ public class HookImporter
|
||||
{
|
||||
for (Element e : a.getElements())
|
||||
{
|
||||
String str = (String) e.getValue();
|
||||
return str;
|
||||
return (String) e.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,13 +313,13 @@ public class HookImporter
|
||||
private Signature getObfuscatedMethodSignature(Method method)
|
||||
{
|
||||
String sig = getAnnotation(method.getAnnotations(), OBFUSCATED_SIGNATURE);
|
||||
if (sig.isEmpty() == false)
|
||||
{
|
||||
return new Signature(sig); // if it is annotated, use that
|
||||
}
|
||||
else
|
||||
if (sig.isEmpty())
|
||||
{
|
||||
return method.getDescriptor();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Signature(sig); // if it is annotated, use that
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package net.runelite.runesuite;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HookMethod
|
||||
{
|
||||
String method;
|
||||
String owner;
|
||||
String name;
|
||||
int access;
|
||||
String[] parameters;
|
||||
List<String> parameters;
|
||||
String descriptor;
|
||||
|
||||
@Override
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user