package alterrs.jbct.deob;

import static alterrs.asm.Opcodes.ACC_PRIVATE;
import static alterrs.asm.Opcodes.ACC_PROTECTED;
import static alterrs.asm.Opcodes.ACC_PUBLIC;

import org.slf4j.Logger;

import alterrs.asm.tree.ClassNode;
import alterrs.asm.tree.MethodNode;
import alterrs.commons.LoggingUtil;
import alterrs.jbct.utility.AbstractTransformer;

/**
 * @author Lazaro Brito
 */
public class PrivilegeDeobfuscator extends AbstractTransformer {
	public static Logger logger = LoggingUtil.log();

	private int count = 0;

	public PrivilegeDeobfuscator() {
		super(true);
	}

	@Override
	public void visitMethod(ClassNode c, MethodNode m) {
		if (m.name.equals("finalize") && ((m.access & ACC_PRIVATE) == 0)
				&& (m.access & ACC_PROTECTED) == 0) {
			m.access |= ACC_PUBLIC;

			count++;
		}
	}

	@Override
	public void onFinish() {
		logger.info("Repaired " + count + " method privileges!");
	}
}
