12-17-2015, 12:06 PM
(This post was last modified: 12-17-2015, 02:08 PM by Dank Vader.)
(12-17-2015, 02:10 AM)Bibl Wrote: You need to change method parameters and field types. are you doing that?
Method parameters and field types are correct.
The jar itself is in the last post but here's what's run to rename everything.
Code:
@SuppressWarnings("rawtypes")
public void rename(Map<String, MappedClass> renamemap) {
// rename the class
MappedClass classmapping = renamemap.get(name);
name = classmapping.getRenamed();
outerClass = StringUtil.fixDesc(outerClass, renamemap.values());
signature = StringUtil.fixDesc(signature, renamemap.values());
superName = StringUtil.fixDesc(superName, renamemap.values());
sourceDebug = "Nope";
sourceFile = "Nope";
// rename fields and update descriptions
for (int i = 0; i < fields.size(); i++) {
FieldNode fn = (FieldNode) fields.get(i);
fn.desc = StringUtil.fixDesc(fn.desc, renamemap.values());
fn.signature = StringUtil.fixDesc(fn.signature, renamemap.values());
MappedField mf = classmapping.getFields().get(fn.name);
if (mf == null) {
continue;
}
String newName = mf.getRenamed();
fn.name = newName;
}
// rename methods and local variables
for (int i = 0; i < methods.size(); i++) {
MethodNode mn = (MethodNode) methods.get(i);
mn.desc = StringUtil.fixDesc(mn.desc, renamemap.values());
mn.signature = StringUtil.fixDesc(mn.signature, renamemap.values());
if (mn.name.equals("main")) {
MappingGen.setMain(name);
}
MappedMethod mm = classmapping.getMethods().get(mn.name);
if (mm != null) {
mn.name = mm.getRenamed();
}
InsnList instructionList = mn.instructions;
List localVars = mn.localVariables;
if (localVars != null) {
for (Object o : localVars) {
LocalVariableNode lvn = (LocalVariableNode) o;
// TODO: Local variable renaming
lvn.desc = StringUtil.fixDesc(lvn.desc, renamemap.values());
lvn.signature = StringUtil.fixDesc(lvn.signature, renamemap.values());
}
}
if (instructionList != null) {
Iterator instructIter = instructionList.iterator();
while (instructIter.hasNext()) {
Object o = instructIter.next();
if (o instanceof AnnotationNode) {
AnnotationNode an = ((AnnotationNode) o);
an.desc = StringUtil.fixDesc(an.desc, renamemap.values());
} else if (o instanceof FieldInsnNode) {
FieldInsnNode fin = ((FieldInsnNode) o);
fin.desc = StringUtil.fixDesc(fin.desc, renamemap.values());
fin.name = StringUtil.fixField(fin.name, renamemap.get(fin.owner));
fin.owner = StringUtil.fixDesc(fin.owner, renamemap.values());
} else if (o instanceof InvokeDynamicInsnNode) {
// I don't think this is ever called
// Multiple test cases and this is never called
InvokeDynamicInsnNode idn = ((InvokeDynamicInsnNode) o);
idn.desc = StringUtil.fixDesc(idn.desc, renamemap.values());
idn.desc = StringUtil.fixMethod(idn.name, renamemap.get(idn.bsm.getOwner()));
// TODO: Is this even required?
int tag = 0;
String owner = "dank";
String name = "dank";
String desc = "dank";
idn.bsm = new Handle(tag, owner, name, desc);
} else if (o instanceof MethodInsnNode) {
MethodInsnNode min = ((MethodInsnNode) o);
min.desc = StringUtil.fixDesc(min.desc, renamemap.values());
min.owner = StringUtil.fixDesc(min.owner, renamemap.values());
min.name = StringUtil.fixMethod(min.name, renamemap.get(min.owner));
} else if (o instanceof MultiANewArrayInsnNode) {
MultiANewArrayInsnNode manain = ((MultiANewArrayInsnNode) o);
manain.desc = StringUtil.fixDesc(manain.desc, renamemap.values());
} else if (o instanceof TypeInsnNode) {
TypeInsnNode tin = ((TypeInsnNode) o);
tin.desc = StringUtil.fixDesc(tin.desc, renamemap.values());
}
}
}
}
}