summaryrefslogtreecommitdiff
path: root/src/test/java/cuchaz/enigma/TestDeobfuscator.java
blob: 5b9611cc1f50a5b70efda9673084a308291ae3f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*******************************************************************************
 * Copyright (c) 2015 Jeff Martin.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public
 * License v3.0 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * Contributors:
 *     Jeff Martin - initial API and implementation
 ******************************************************************************/

package cuchaz.enigma;

import com.google.common.collect.Lists;
import cuchaz.enigma.translation.representation.entry.ClassEntry;
import org.junit.Test;

import java.io.IOException;
import java.util.List;
import java.util.jar.JarFile;

import static org.junit.Assert.assertEquals;

public class TestDeobfuscator {

	private Enigma getDeobfuscator()
		throws IOException {
		return new Enigma(new JarFile("build/test-obf/loneClass.jar"));
	}

	@Test
	public void loadJar()
		throws Exception {
		getDeobfuscator();
	}

	@Test
	public void getClasses()
		throws Exception {
		Enigma enigma = getDeobfuscator();
		List<ClassEntry> obfClasses = Lists.newArrayList();
		List<ClassEntry> deobfClasses = Lists.newArrayList();
		enigma.getSeparatedClasses(obfClasses, deobfClasses);
		assertEquals(1, obfClasses.size());
		assertEquals("a", obfClasses.get(0).getName());
		assertEquals(1, deobfClasses.size());
		assertEquals("cuchaz/enigma/inputs/Keep", deobfClasses.get(0).getName());
	}

	@Test
	public void decompileClass()
		throws Exception {
		Enigma enigma = getDeobfuscator();
		SourceProvider sourceProvider = enigma.getObfSourceProvider();
		sourceProvider.writeSourceToString(sourceProvider.getSources("a"));
	}
}