<commit_before>package net.cazzar.util.glowingoctowookie.asm;

import net.cazzar.util.glowingoctowookie.MappingParser;
import net.cazzar.util.glowingoctowookie.internal.FieldInfo;
import net.cazzar.util.glowingoctowookie.internal.MethodInfo;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.*;
import org.objectweb.asm.util.CheckClassAdapter;

import java.io.PrintWriter;
import java.util.ListIterator;
import java.util.Map;

public class SrgDeobfMapper {
    public static byte[] remap(byte[] bytes) {
        ClassReader reader = new ClassReader(bytes);

        ClassNode node = new ClassNode();
        reader.accept(node, 0);

        Map<String, String> classSrgToMcp = MappingParser.getInstance().getClasses();

        //replace the proper superclass if need be.
        if (classSrgToMcp.containsKey(node.superName)) node.superName = classSrgToMcp.get(node.superName);

        final Map<MethodInfo, MethodInfo> methods = MappingParser.getInstance().getMethods().inverse();
        final Map<FieldInfo, FieldInfo> fields = MappingParser.getInstance().getFields().inverse();

        for (MethodNode method : node.methods) {
            InsnList insnList = new InsnList();
            final ListIterator<AbstractInsnNode> iterator = method.instructions.iterator();
            while (iterator.hasNext()) {
                AbstractInsnNode insnNode = iterator.next();

                if (insnNode instanceof MethodInsnNode) {
                    MethodInsnNode insn = (MethodInsnNode) insnNode;

                    MethodInfo info = new MethodInfo(insn.owner, insn.name, insn.desc);
                    System.out.println(info);
                    System.out.printf("desc = %s, name = %s, owner = %s", insn.desc, insn.name, insn.owner);
                    if (methods.containsKey(info)) {
                        info = methods.get(info);
                        System.out.println(info);

                        insn.desc = info.getSignature();
                        insn.name = info.getName();
                        insn.owner = info.getOwner();
                        System.out.printf("desc = %s, name = %s, owner = %s", insn.desc, insn.name, insn.owner);
                    }
                    insnList.add(insn);
                }
                else {
                    insnList.add(insnNode);
                }
            }
            method.instructions = insnList;
        }

        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
        node.accept(writer);

        CheckClassAdapter.verify(reader, true, new PrintWriter(System.err));

        return writer.toByteArray();
    }
}<commit_msg>Field name deobf now works.<commit_after>package net.cazzar.util.glowingoctowookie.asm;

import net.cazzar.util.glowingoctowookie.MappingParser;
import net.cazzar.util.glowingoctowookie.internal.FieldInfo;
import net.cazzar.util.glowingoctowookie.internal.MethodInfo;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.*;

import java.util.ListIterator;
import java.util.Map;

public class SrgDeobfMapper {
    public static byte[] remap(byte[] bytes) {
        ClassReader reader = new ClassReader(bytes);

        ClassNode node = new ClassNode();
        reader.accept(node, 0);

        Map<String, String> classSrgToMcp = MappingParser.getInstance().getClasses();

        //replace the proper superclass if need be.
        if (classSrgToMcp.containsKey(node.superName)) node.superName = classSrgToMcp.get(node.superName);

        final Map<MethodInfo, MethodInfo> methods = MappingParser.getInstance().getMethods().inverse();
        final Map<FieldInfo, FieldInfo> fields = MappingParser.getInstance().getFields().inverse();

        for (MethodNode method : node.methods) {
            InsnList insnList = new InsnList();
            final ListIterator<AbstractInsnNode> iterator = method.instructions.iterator();
            while (iterator.hasNext()) {
                AbstractInsnNode insnNode = iterator.next();

                if (insnNode instanceof MethodInsnNode) {
                    MethodInsnNode insn = (MethodInsnNode) insnNode;

                    MethodInfo info = new MethodInfo(insn.owner, insn.name, insn.desc);
//                    System.out.println(info);
//                    System.out.printf("desc = %s, name = %s, owner = %s", insn.desc, insn.name, insn.owner);
                    if (methods.containsKey(info)) {
                        info = methods.get(info);
//                        System.out.println(info);

                        insn.desc = info.getSignature();
                        insn.name = info.getName();
                        insn.owner = info.getOwner();
//                        System.out.printf("desc = %s, name = %s, owner = %s", insn.desc, insn.name, insn.owner);
                    }
                    insnList.add(insn);
                } else if (insnNode instanceof FieldInsnNode) {
                    FieldInsnNode insn = (FieldInsnNode) insnNode;
                    FieldInfo info = new FieldInfo(insn.owner, insn.name);

                    if (fields.containsKey(info)) {
                        info = fields.get(info);

                        insn.name = info.getName();
                        insn.owner = info.getOwner();
                    }
                    insnList.add(insn);
                }
                else {
                    insnList.add(insnNode);
                }
            }
            method.instructions = insnList;
        }

        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
        node.accept(writer);

//        CheckClassAdapter.verify(reader, true, new PrintWriter(System.err));

        return writer.toByteArray();
    }
}
{'fraction_non_alphanumeric': 0.10865874363327674, 'fraction_numerical': 0.00033955857385398983, 'mean_word_length': 2.0319094184251156, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4046197', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1609, 'n_words': 309}