summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/Deobfuscator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuchaz/enigma/Deobfuscator.java')
-rw-r--r--src/cuchaz/enigma/Deobfuscator.java75
1 files changed, 38 insertions, 37 deletions
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;
46import cuchaz.enigma.analysis.SourceIndexVisitor; 46import cuchaz.enigma.analysis.SourceIndexVisitor;
47import cuchaz.enigma.analysis.Token; 47import cuchaz.enigma.analysis.Token;
48import cuchaz.enigma.bytecode.ClassProtectifier; 48import cuchaz.enigma.bytecode.ClassProtectifier;
49import cuchaz.enigma.bytecode.ClassPublifier;
49import cuchaz.enigma.mapping.ArgumentEntry; 50import cuchaz.enigma.mapping.ArgumentEntry;
50import cuchaz.enigma.mapping.BehaviorEntry; 51import cuchaz.enigma.mapping.BehaviorEntry;
51import cuchaz.enigma.mapping.ClassEntry; 52import cuchaz.enigma.mapping.ClassEntry;
@@ -321,48 +322,48 @@ public class Deobfuscator {
321 } 322 }
322 323
323 public void writeJar(File out, ProgressListener progress) { 324 public void writeJar(File out, ProgressListener progress) {
324 try (JarOutputStream outJar = new JarOutputStream(new FileOutputStream(out))) { 325 final TranslatingTypeLoader loader = new TranslatingTypeLoader(
325 if (progress != null) { 326 m_jar,
326 progress.init(JarClassIterator.getClassEntries(m_jar).size(), "Translating classes..."); 327 m_jarIndex,
328 getTranslator(TranslationDirection.Obfuscating),
329 getTranslator(TranslationDirection.Deobfuscating)
330 );
331 transformJar(out, progress, new ClassTransformer() {
332
333 @Override
334 public CtClass transform(CtClass c) throws Exception {
335 return loader.transformClass(c);
327 } 336 }
328 337 });
329 // prep the loader 338 }
330 TranslatingTypeLoader loader = new TranslatingTypeLoader( 339
331 m_jar, 340 public void protectifyJar(File out, ProgressListener progress) {
332 m_jarIndex, 341 transformJar(out, progress, new ClassTransformer() {
333 getTranslator(TranslationDirection.Obfuscating), 342
334 getTranslator(TranslationDirection.Deobfuscating) 343 @Override
335 ); 344 public CtClass transform(CtClass c) throws Exception {
336 345 return ClassProtectifier.protectify(c);
337 int i = 0;
338 for (CtClass c : JarClassIterator.classes(m_jar)) {
339 if (progress != null) {
340 progress.onProgress(i++, c.getName());
341 }
342
343 try {
344 c = loader.transformClass(c);
345 outJar.putNextEntry(new JarEntry(c.getName().replace('.', '/') + ".class"));
346 outJar.write(c.toBytecode());
347 outJar.closeEntry();
348 } catch (Throwable t) {
349 throw new Error("Unable to deobfuscate class " + c.getName(), t);
350 }
351 } 346 }
352 if (progress != null) { 347 });
353 progress.onProgress(i, "Done!"); 348 }
349
350 public void publifyJar(File out, ProgressListener progress) {
351 transformJar(out, progress, new ClassTransformer() {
352
353 @Override
354 public CtClass transform(CtClass c) throws Exception {
355 return ClassPublifier.publify(c);
354 } 356 }
355 357 });
356 outJar.close();
357 } catch (IOException ex) {
358 throw new Error("Unable to write to Jar file!");
359 }
360 } 358 }
361 359
362 public void protectifyJar(File out, ProgressListener progress) { 360 private interface ClassTransformer {
361 public CtClass transform(CtClass c) throws Exception;
362 }
363 private void transformJar(File out, ProgressListener progress, ClassTransformer transformer) {
363 try (JarOutputStream outJar = new JarOutputStream(new FileOutputStream(out))) { 364 try (JarOutputStream outJar = new JarOutputStream(new FileOutputStream(out))) {
364 if (progress != null) { 365 if (progress != null) {
365 progress.init(JarClassIterator.getClassEntries(m_jar).size(), "Protectifying classes..."); 366 progress.init(JarClassIterator.getClassEntries(m_jar).size(), "Transforming classes...");
366 } 367 }
367 368
368 int i = 0; 369 int i = 0;
@@ -372,12 +373,12 @@ public class Deobfuscator {
372 } 373 }
373 374
374 try { 375 try {
375 c = ClassProtectifier.protectify(c); 376 c = transformer.transform(c);
376 outJar.putNextEntry(new JarEntry(c.getName().replace('.', '/') + ".class")); 377 outJar.putNextEntry(new JarEntry(c.getName().replace('.', '/') + ".class"));
377 outJar.write(c.toBytecode()); 378 outJar.write(c.toBytecode());
378 outJar.closeEntry(); 379 outJar.closeEntry();
379 } catch (Throwable t) { 380 } catch (Throwable t) {
380 throw new Error("Unable to protectify class " + c.getName(), t); 381 throw new Error("Unable to transform class " + c.getName(), t);
381 } 382 }
382 } 383 }
383 if (progress != null) { 384 if (progress != null) {