Dank Vader   11-30-2015, 06:14 PM
#1
Bibl   12-07-2015, 08:04 AM
#2
to be honest, i havent really used asm's remapper. instead i made my own which iterates through all of the classes/fields/methods and then renames stuff that way. i would recommend you do that as well.
Dank Vader   12-13-2015, 03:33 PM
#3
(12-07-2015, 08:04 AM)Bibl Wrote: to be honest, i havent really used asm's remapper. instead i made my own which iterates through all of the classes/fields/methods and then renames stuff that way. i would recommend you do that as well.

I've switched to this and can't seem to figure out how to update class names. Everything else is working though.

Edit: Nevermind. I had the classreaders/writers in the wrong order. Thanks for the tip! Currently stuck at updating the references to the renamed objects/classes. I can't get all the method calls from variables to be renamed and classes keep trying to refer to their original names despite signatures and descriptions being updated.

Here's an example jar so that you can look for yourselves. Text and screens can only do so much: http://b.1339.cf/cladyky.zip
Bibl   12-17-2015, 02:10 AM
#4
You need to change method parameters and field types. are you doing that?
Dank Vader   12-17-2015, 12:06 PM
#5
(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.

[Image: YIFV6BG.png]

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());
                    }
                }
            }
        }
    }
Bibl   12-20-2015, 05:13 AM
#6
can you show the java and the bytecode of a method that isn't being transformed properly.
Dank Vader   12-23-2015, 02:50 PM
#7
(12-20-2015, 05:13 AM)Bibl Wrote: can you show the java and the bytecode of a method that isn't being transformed properly.

They are transformed though. That's what I've run into. If you look at the jars I provided the bytecode references all have been updated. The class names/definitions, the methods (declarations and references, parameters), field types, method local variables. It's all updated. But at runtime it just flips out and tries to use the old names.
  
Users browsing this thread: 1 Guest(s)
Konloch Software - Bytecode Viewer - Reverse Engineering Forum
Copyright © 2014-2026 The Bytecode Club. Powered By MyBB.
CC0 Unless Specified Otherwise.