From 22cac8f1a25c7d34a94bc5e00c56c0532509071f Mon Sep 17 00:00:00 2001 From: Cuchaz Date: Mon, 30 Mar 2015 22:00:54 -0400 Subject: add publifier --- src/cuchaz/enigma/Deobfuscator.java | 75 +++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 37 deletions(-) (limited to 'src/cuchaz/enigma/Deobfuscator.java') diff --git a/src/cuchaz/enigma/Deobfuscator.java b/src/cuchaz/enigma/Deobfuscator.java index a7d8a67..d9ded87 100644 --- a/src/cuchaz/enigma/Deobfuscator.java +++ b/src/cuchaz/enigma/Deobfuscator.java @@ -46,6 +46,7 @@ import cuchaz.enigma.analysis.SourceIndex; import cuchaz.enigma.analysis.SourceIndexVisitor; import cuchaz.enigma.analysis.Token; import cuchaz.enigma.bytecode.ClassProtectifier; +import cuchaz.enigma.bytecode.ClassPublifier; import cuchaz.enigma.mapping.ArgumentEntry; import cuchaz.enigma.mapping.BehaviorEntry; import cuchaz.enigma.mapping.ClassEntry; @@ -321,48 +322,48 @@ public class Deobfuscator { } public void writeJar(File out, ProgressListener progress) { - try (JarOutputStream outJar = new JarOutputStream(new FileOutputStream(out))) { - if (progress != null) { - progress.init(JarClassIterator.getClassEntries(m_jar).size(), "Translating classes..."); + final TranslatingTypeLoader loader = new TranslatingTypeLoader( + m_jar, + m_jarIndex, + getTranslator(TranslationDirection.Obfuscating), + getTranslator(TranslationDirection.Deobfuscating) + ); + transformJar(out, progress, new ClassTransformer() { + + @Override + public CtClass transform(CtClass c) throws Exception { + return loader.transformClass(c); } - - // prep the loader - TranslatingTypeLoader loader = new TranslatingTypeLoader( - m_jar, - m_jarIndex, - getTranslator(TranslationDirection.Obfuscating), - getTranslator(TranslationDirection.Deobfuscating) - ); - - int i = 0; - for (CtClass c : JarClassIterator.classes(m_jar)) { - if (progress != null) { - progress.onProgress(i++, c.getName()); - } - - try { - c = loader.transformClass(c); - outJar.putNextEntry(new JarEntry(c.getName().replace('.', '/') + ".class")); - outJar.write(c.toBytecode()); - outJar.closeEntry(); - } catch (Throwable t) { - throw new Error("Unable to deobfuscate class " + c.getName(), t); - } + }); + } + + public void protectifyJar(File out, ProgressListener progress) { + transformJar(out, progress, new ClassTransformer() { + + @Override + public CtClass transform(CtClass c) throws Exception { + return ClassProtectifier.protectify(c); } - if (progress != null) { - progress.onProgress(i, "Done!"); + }); + } + + public void publifyJar(File out, ProgressListener progress) { + transformJar(out, progress, new ClassTransformer() { + + @Override + public CtClass transform(CtClass c) throws Exception { + return ClassPublifier.publify(c); } - - outJar.close(); - } catch (IOException ex) { - throw new Error("Unable to write to Jar file!"); - } + }); } - public void protectifyJar(File out, ProgressListener progress) { + private interface ClassTransformer { + public CtClass transform(CtClass c) throws Exception; + } + private void transformJar(File out, ProgressListener progress, ClassTransformer transformer) { try (JarOutputStream outJar = new JarOutputStream(new FileOutputStream(out))) { if (progress != null) { - progress.init(JarClassIterator.getClassEntries(m_jar).size(), "Protectifying classes..."); + progress.init(JarClassIterator.getClassEntries(m_jar).size(), "Transforming classes..."); } int i = 0; @@ -372,12 +373,12 @@ public class Deobfuscator { } try { - c = ClassProtectifier.protectify(c); + c = transformer.transform(c); outJar.putNextEntry(new JarEntry(c.getName().replace('.', '/') + ".class")); outJar.write(c.toBytecode()); outJar.closeEntry(); } catch (Throwable t) { - throw new Error("Unable to protectify class " + c.getName(), t); + throw new Error("Unable to transform class " + c.getName(), t); } } if (progress != null) { -- cgit v1.2.3