-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassDecompiler.java
More file actions
75 lines (65 loc) · 1.8 KB
/
Copy pathClassDecompiler.java
File metadata and controls
75 lines (65 loc) · 1.8 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Created on 29-10-2003 by jesper
* This class should
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import jode.decompiler.Decompiler;
import jode.decompiler.Options;
/**
* @author jesper
*/
public class ClassDecompiler {
static Decompiler d = new Decompiler();
public static StringBuffer decompile(String clazz, String [] paths){
if(clazz==null){
clazz="TestDecompiler";
}
d.setClassPath(paths);
//ArrayList buf = new ArrayList();
StringBuffer buf = new StringBuffer();
File f = null;
Writer out;
try {
f = File.createTempFile(clazz, "class");
out = new BufferedWriter(new FileWriter(f));
d.setOption("style","sun" );
d.setOption("pretty","1" );
//d.setOption("verbose","1" ); //for debugging
d.decompile( clazz,out,null);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Succesfully decompiled");
String NEWLINE = "\n";
try {
BufferedReader br = new BufferedReader(new FileReader(f));
String line ="";
int num = 0;
while ((line = br.readLine()) != null) {
if(num>2)
buf.append(line+NEWLINE);
num++;
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
return buf;
}
public static void setClassPath(String path){
d.setClassPath(path);
}
public static void setClassPath(String []paths){
d.setClassPath(paths);
}
}