) mIterator.next();
74 | String javaPath = entry.getKey();
75 | String classPath = entry.getValue();
76 | String content = mDecompiler.decompile(mJarPath.toString(), classPath.toString());
77 | return new DecomplieEntry(javaPath, content);
78 | }
79 |
80 | return null;
81 | }
82 |
83 | public int getCount() {
84 | return mJavaToClassPathMap.size();
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/jd/ide/intellij/JavaDecompiler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Deapk - A tools for "APK -> Android Project"
3 | * Copyright (c) 2013-2014 Jiongxuan Zhang
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package jd.ide.intellij;
19 |
20 | import i.am.jiongxuan.deapk.ArchUtils;
21 |
22 | import java.io.File;
23 | import java.io.UnsupportedEncodingException;
24 |
25 | import org.apache.commons.lang3.SystemUtils;
26 |
27 | /**
28 | * Java Decompiler tool, use native libs to achieve decompilation.
29 | *
30 | *
31 | * Identify the native lib full path through IntelliJ helpers in {@link SystemInfo}.
32 | *
33 | */
34 | public class JavaDecompiler {
35 |
36 | public static String JD_LIB_RELATIVE_PATH = "lib" + File.separator + "jd-core" + File.separator + osIdentifier()
37 | + File.separator + architecture() + File.separator + libFileName();
38 |
39 | public JavaDecompiler() {
40 | String pluginPath = JavaDecompiler.class.getProtectionDomain().getCodeSource().getLocation().getPath();
41 | try {
42 | pluginPath = java.net.URLDecoder.decode(pluginPath, "UTF-8");
43 | } catch (UnsupportedEncodingException e) {
44 | e.printStackTrace();
45 | }
46 | pluginPath = new File(pluginPath).getParent();
47 |
48 | String libPath = pluginPath + File.separator + JD_LIB_RELATIVE_PATH;
49 | loadLibrary(pluginPath, libPath);
50 | }
51 |
52 | private void loadLibrary(String pluginPath, String libPath) {
53 | try {
54 | System.load(libPath);
55 | } catch (Exception e) {
56 | throw new IllegalStateException("Something got wrong when loading the Java Decompiler native lib, "
57 | + "\nlookup path : " + libPath + "\nplugin path : " + pluginPath, e);
58 | }
59 | }
60 |
61 | /**
62 | * Library filename, depending on the OS identifier.
63 | *
64 | * @return lib filename.
65 | */
66 | private static String libFileName() {
67 | if (SystemUtils.IS_OS_MAC_OSX) {
68 | return "libjd-intellij.jnilib";
69 | } else if (SystemUtils.IS_OS_WINDOWS) {
70 | return "jd-intellij.dll";
71 | } else if (SystemUtils.IS_OS_LINUX) {
72 | return "libjd-intellij.so";
73 | }
74 | throw new IllegalStateException("OS not supported");
75 | }
76 |
77 | /**
78 | * Architecture, either 32bit or 64bit.
79 | *
80 | * @return x86 or x86_64 for respectively 32bit 64bit architecture.
81 | */
82 | private static String architecture() {
83 | if (ArchUtils.is32Bit()) {
84 | return "x86";
85 | } else if (ArchUtils.is64Bit()) {
86 | return "x86_64";
87 | }
88 | throw new IllegalStateException("Unsupported architecture, only x86 and x86_64 architectures are supported.");
89 | }
90 |
91 | /**
92 | * Identify the OS.
93 | *
94 | * @return Either macosx, win32, linux
95 | */
96 | private static String osIdentifier() {
97 | if (SystemUtils.IS_OS_MAC_OSX) {
98 | return "macosx";
99 | } else if (SystemUtils.IS_OS_WINDOWS) {
100 | return "win32";
101 | } else if (SystemUtils.IS_OS_LINUX) {
102 | return "linux";
103 | }
104 | throw new IllegalStateException("Unsupported OS, only windows, linux and mac OSes are supported.");
105 | }
106 |
107 | /**
108 | * Actual call to the native lib.
109 | *
110 | * @param basePath
111 | * Path to the root of the classpath, either a path to a
112 | * directory or a path to a jar file.
113 | * @param internalClassName
114 | * internal name of the class.
115 | * @return Decompiled class text.
116 | */
117 | public native String decompile(String basePath, String internalClassName);
118 | }
119 |
--------------------------------------------------------------------------------
/src/i/am/jiongxuan/deapk/MainApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Deapk - A tools for "APK -> Android Project"
3 | * Copyright (c) 2013-2014 Jiongxuan Zhang
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package i.am.jiongxuan.deapk;
19 |
20 | import java.io.BufferedReader;
21 | import java.io.IOException;
22 | import java.io.InputStreamReader;
23 | import java.util.ArrayList;
24 | import java.util.Date;
25 | import java.util.List;
26 |
27 | /**
28 | * @author Jiongxuan Zhang
29 | */
30 | public class MainApplication {
31 |
32 | public static void main(String[] args) {
33 | System.out.println();
34 | System.out.println("====================================================================");
35 | System.out.println();
36 | System.out
37 | .println(" Welcome to choose Deapk by Jiongxuan (Version: 2.0)");
38 | System.out.println(" The most convenient source decompiling tool by far.");
39 | System.out.println();
40 | System.out
41 | .println(" Decompile the APK files to Android project");
42 | System.out.println(" with only ONE STEP.");
43 | System.out.println();
44 | System.out.println("====================================================================");
45 |
46 | if (args.length < 1) {
47 | usage();
48 | return;
49 | }
50 |
51 | List vaildFileList = new ArrayList();
52 | for (String file : args) {
53 | if (file.endsWith(".apk")) {
54 | vaildFileList.add(file);
55 | }
56 | }
57 |
58 | if (vaildFileList.size() < 1) {
59 | usage();
60 | return;
61 | }
62 |
63 | boolean hasSucceed = false;
64 |
65 | for (int i = 0; i < vaildFileList.size(); i++) {
66 | System.out.println();
67 | System.out.println(">>> Starting Deapk now!" + "(" + (i + 1) + "/" + vaildFileList.size() + ")");
68 | System.out.println(" This may take a few seconds to complete.");
69 | System.out.println();
70 |
71 | String vaildFile = vaildFileList.get(i);
72 | Deapk deapk = new Deapk(vaildFile);
73 | if (deapkNow(deapk)) {
74 | System.out.println();
75 | System.out.println(">>> Deapked the " + deapk.getProjectNameIfExists() + " project complete!");
76 | hasSucceed = true;
77 | }
78 | }
79 |
80 | if (hasSucceed) {
81 | System.out.println();
82 | System.out.println("Congratulations!");
83 | System.out.println("You have successfully Deapked these projects, and now " +
84 | "you can open Eclipse and import it directly through the path \"File -> Import\".");
85 | System.out.println("Then you can enjoy the fun as a \"hacker\" to the full!");
86 | }
87 |
88 | help();
89 | waitFor();
90 | }
91 |
92 | private static boolean deapkNow(Deapk deapk) {
93 | if (!deapk.isApkExists()) {
94 | System.out.println("!!! ERROR: No such a file: " + deapk.getApkPath());
95 | return false;
96 | }
97 |
98 | if (deapk.isProjectExists()) {
99 | String date = "";
100 | long nowDays = new Date().getTime() / 1000 / 60 / 60 / 24;
101 | long projectDays = deapk.getLastDate().getTime() / 1000 / 60 / 60 / 24;
102 | long betweenDays = nowDays - projectDays;
103 | if (betweenDays <= 0) {
104 | date = "today";
105 | } else if (betweenDays == 1){
106 | date = "yesterday";
107 | } else if (betweenDays <= 100){
108 | date = betweenDays + " days before";
109 | } else {
110 | date = "a long time before";
111 | }
112 | System.out.println("??? Question for you: ");
113 | System.out.println("??? File path: " + deapk.getApkPath());
114 | System.out.println("???");
115 | System.out.println("??? This project has been Deapked " + date + ".");
116 | System.out.println("??? Please confirm whether it will be redone?");
117 | System.out.println("??? Press 'y' to restart, otherwise to ignore.");
118 |
119 | String response = "";
120 | BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
121 | try {
122 | response = strin.readLine();
123 | } catch (IOException e) {
124 | e.printStackTrace();
125 | }
126 |
127 | if (response.isEmpty()
128 | || response.substring(0, 1).compareToIgnoreCase("y") != 0) {
129 | return false;
130 | }
131 | }
132 |
133 | return deapk.start();
134 | }
135 |
136 | private static void help() {
137 | System.out.println();
138 | System.out
139 | .println("If you want to learn more exciting details and the latest developments about Deapk, please visit this site at any time:");
140 | System.out.println();
141 | System.out.println(" http://jiongxuan.github.io/deapk/");
142 | System.out.println();
143 | }
144 |
145 | public static void waitFor() {
146 | System.out.print("Press enter to exit...");
147 | try {
148 | System.in.read();
149 | } catch (IOException e) {
150 | e.printStackTrace();
151 | }
152 | }
153 |
154 | private static void usage() {
155 | System.out.println();
156 | System.out.println("Usage:");
157 | System.out.println(" deapk ");
158 | System.out.println();
159 | System.out.println("Support for multiple files to deapk. Just like:");
160 | System.out.println(" deapk <*.apk>...");
161 | System.out.println();
162 | System.out.println("i.e.");
163 | System.out.println(" deapk haoke.apk");
164 | System.out.println(" deapk sin.apk cos.apk tan.apk");
165 | System.out.println(" deapk *.apk");
166 | System.out.println();
167 | System.out.println("So easy, right?");
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/src/i/am/jiongxuan/deapk/GenerateProjectOperator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Deapk - A tools for "APK -> Android Project"
3 | * Copyright (c) 2013-2014 Jiongxuan Zhang
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package i.am.jiongxuan.deapk;
19 |
20 |
21 | import java.io.File;
22 | import java.io.FileNotFoundException;
23 | import java.io.FileOutputStream;
24 | import java.io.IOException;
25 | import java.io.UnsupportedEncodingException;
26 |
27 | import org.apache.commons.io.FileUtils;
28 | import org.dom4j.Document;
29 | import org.dom4j.DocumentException;
30 | import org.dom4j.DocumentHelper;
31 | import org.dom4j.Element;
32 | import org.dom4j.io.SAXReader;
33 | import org.dom4j.io.XMLWriter;
34 |
35 | /**
36 | * @author Jiongxuan Zhang
37 | */
38 | public class GenerateProjectOperator {
39 | private File mProjectFile;
40 | private String mProjectName;
41 |
42 | public GenerateProjectOperator(File projectFile) {
43 | mProjectFile = projectFile;
44 | }
45 |
46 | public void generateGenDir() {
47 | File genDir = new File(mProjectFile, "gen");
48 | if (!genDir.exists()) {
49 | genDir.mkdirs();
50 | }
51 | }
52 |
53 | public void genereateProjectPropertiesFile() {
54 | StringBuilder projectBuilder = new StringBuilder();
55 | projectBuilder.append("target=android-17");
56 | try {
57 | FileUtils.write(new File(mProjectFile, "project.properties"), projectBuilder.toString());
58 | } catch (FileNotFoundException e) {
59 | e.printStackTrace();
60 | } catch (IOException e) {
61 | e.printStackTrace();
62 | }
63 | }
64 |
65 | public void generateClassPathFile() {
66 | Document document = DocumentHelper.createDocument();
67 | Element classPathElement = document.addElement("classpath");
68 | classPathElement.addElement("classpathentry")
69 | .addAttribute("kind", "src").addAttribute("path", "src");
70 | classPathElement.addElement("classpathentry")
71 | .addAttribute("kind", "src").addAttribute("path", "gen");
72 | classPathElement
73 | .addElement("classpathentry")
74 | .addAttribute("kind", "con")
75 | .addAttribute("path",
76 | "com.android.ide.eclipse.adt.ANDROID_FRAMEWORK");
77 | classPathElement.addElement("classpathentry")
78 | .addAttribute("kind", "con")
79 | .addAttribute("path", "com.android.ide.eclipse.adt.LIBRARIES");
80 | classPathElement
81 | .addElement("classpathentry")
82 | .addAttribute("kind", "con")
83 | .addAttribute("path",
84 | "com.android.ide.eclipse.adt.DEPENDENCIES")
85 | .addAttribute("exported", "true");
86 | classPathElement.addElement("classpathentry")
87 | .addAttribute("kind", "output")
88 | .addAttribute("path", "bin/classes");
89 |
90 | try {
91 | XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(
92 | new File(mProjectFile, ".classpath")));
93 | xmlWriter.write(document);
94 | xmlWriter.close();
95 | } catch (UnsupportedEncodingException e) {
96 | e.printStackTrace();
97 | } catch (FileNotFoundException e) {
98 | e.printStackTrace();
99 | } catch (IOException e) {
100 | e.printStackTrace();
101 | }
102 | }
103 |
104 | public void generateProjectFile() {
105 | Document document = DocumentHelper.createDocument();
106 | Element projectDescriptionElement = document
107 | .addElement("projectDescription");
108 | projectDescriptionElement.addElement("name").addText(
109 | getProjectNameInManifestXml());
110 |
111 | Element buildSpecElement = projectDescriptionElement
112 | .addElement("buildSpec");
113 | buildSpecElement.addElement("buildCommand").addElement("name")
114 | .addText("com.android.ide.eclipse.adt.ResourceManagerBuilder");
115 | buildSpecElement.addElement("buildCommand").addElement("name")
116 | .addText("com.android.ide.eclipse.adt.PreCompilerBuilder");
117 | buildSpecElement.addElement("buildCommand").addElement("name")
118 | .addText("org.eclipse.jdt.core.javabuilder");
119 | buildSpecElement.addElement("buildCommand").addElement("name")
120 | .addText("com.android.ide.eclipse.adt.ApkBuilder");
121 |
122 | Element naturesElement = projectDescriptionElement
123 | .addElement("natures");
124 | naturesElement.addElement("nature").addText(
125 | "com.android.ide.eclipse.adt.AndroidNature");
126 | naturesElement.addElement("nature").addText(
127 | "org.eclipse.jdt.core.javanature");
128 |
129 | try {
130 | XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(
131 | new File(mProjectFile, ".project")));
132 | xmlWriter.write(document);
133 | xmlWriter.close();
134 | } catch (UnsupportedEncodingException e) {
135 | e.printStackTrace();
136 | } catch (FileNotFoundException e) {
137 | e.printStackTrace();
138 | } catch (IOException e) {
139 | e.printStackTrace();
140 | }
141 | }
142 |
143 | public String getProjectName() {
144 | return mProjectName;
145 | }
146 |
147 | public String getProjectNameInManifestXml() {
148 | if (mProjectName == null) {
149 | String packageName = "";
150 | String versionName = "";
151 | String versionCode = "";
152 |
153 | File inputXml = new File(mProjectFile, "AndroidManifest.xml");
154 | SAXReader saxReader = new SAXReader();
155 | try {
156 | Document document = saxReader.read(inputXml);
157 | Element manifestElement = document.getRootElement();
158 | packageName = manifestElement.attributeValue("package");
159 | versionName = manifestElement.attributeValue("versionName");
160 | versionCode = manifestElement.attributeValue("versionCode");
161 | } catch (DocumentException e) {
162 | e.printStackTrace();
163 | }
164 |
165 | mProjectName = packageName.substring(packageName.lastIndexOf('.') + 1) + "_"
166 | + versionName + "-" + versionCode;
167 | }
168 |
169 | return mProjectName;
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/src/i/am/jiongxuan/deapk/Deapk.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Deapk - A tools for "APK -> Android Project"
3 | * Copyright (c) 2013-2014 Jiongxuan Zhang
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package i.am.jiongxuan.deapk;
19 |
20 | import i.am.jiongxuan.deapk.jd.core.Decompiler;
21 | import i.am.jiongxuan.deapk.jd.core.DecomplieEntry;
22 | import i.am.jiongxuan.deapk.jd.core.DecomplieEnumeration;
23 |
24 | import java.io.File;
25 | import java.io.FileWriter;
26 | import java.io.IOException;
27 | import java.util.ArrayList;
28 | import java.util.Collections;
29 | import java.util.Date;
30 | import java.util.List;
31 | import java.util.Map;
32 | import java.util.logging.Level;
33 | import java.util.logging.Logger;
34 |
35 | import org.apache.commons.io.FileUtils;
36 | import org.apache.commons.io.FilenameUtils;
37 |
38 | import brut.androlib.Androlib;
39 | import brut.androlib.AndrolibException;
40 | import brut.androlib.ApkDecoder;
41 | import brut.androlib.res.AndrolibResources;
42 | import brut.androlib.res.util.ExtFile;
43 |
44 | import com.googlecode.dex2jar.Method;
45 | import com.googlecode.dex2jar.reader.DexFileReader;
46 | import com.googlecode.dex2jar.v3.Dex2jar;
47 | import com.googlecode.dex2jar.v3.DexExceptionHandlerImpl;
48 |
49 | /**
50 | * @author Jiongxuan Zhang
51 | */
52 | public class Deapk {
53 | private final File mApkDir;
54 | private final File mProjectDir;
55 | private final File mClassesDexFile;
56 | private final File mClassesJarFile;
57 | private final File mClassesJarErrorFile;
58 | private final File mErrorFile;
59 | private final File mSrcDir;
60 | private final File mSmaliDir;
61 |
62 | private final GenerateProjectOperator mGenerateProjectOperator;
63 |
64 | public Deapk(String apkPath) {
65 | mApkDir = new File(apkPath);
66 |
67 | String apkName = FilenameUtils.getName(apkPath);
68 | String projectName = apkName.substring(0, apkName.lastIndexOf('.'));
69 | mProjectDir = new File(mApkDir.getParentFile(), projectName + "_project");
70 |
71 | mClassesDexFile = new File(mProjectDir, "classes.dex");
72 | mClassesJarFile = new File(mProjectDir, "classes.jar");
73 | mClassesJarErrorFile = new File(mProjectDir, "classes-error.zip");
74 | mErrorFile = new File(mProjectDir, "error.txt");
75 | mSrcDir = new File(mProjectDir, "src");
76 | mSmaliDir = new File(mProjectDir, "smali");
77 |
78 | mGenerateProjectOperator = new GenerateProjectOperator(mProjectDir);
79 | }
80 |
81 | public File getApkPath() {
82 | return mApkDir;
83 | }
84 |
85 | public boolean isApkExists() {
86 | return mApkDir.exists();
87 | }
88 |
89 | public boolean isProjectExists() {
90 | return mProjectDir.exists();
91 | }
92 |
93 | public Date getLastDate() {
94 | return new Date(mProjectDir.lastModified());
95 | }
96 |
97 | public File getProjectPath() {
98 | return mProjectDir;
99 | }
100 |
101 | public String getProjectNameIfExists() {
102 | return mGenerateProjectOperator.getProjectName();
103 | }
104 |
105 | public boolean start() {
106 | if (isProjectExists()) {
107 | System.out.println(">>> (0/5) Cleaning...");
108 | try {
109 | FileUtils.deleteDirectory(getProjectPath());
110 | } catch (Exception e) {
111 | e.printStackTrace();
112 | return false;
113 | }
114 | }
115 |
116 | return decodeResources() && extractAll() && decodeToClassDex() && decodeToJavaCodes()
117 | && writeEclipseProjectFiles();
118 | }
119 |
120 | public boolean decodeResources() {
121 | System.out.println(">>> (1/5) Decompiling all resource files and smali files...");
122 |
123 | Logger.getLogger(AndrolibResources.class.getName()).setLevel(Level.OFF);
124 | Logger.getLogger(Androlib.class.getName()).setLevel(Level.OFF);
125 | ApkDecoder apkDecoder = new ApkDecoder();
126 | try {
127 | apkDecoder.setKeepBrokenResources(true);
128 | apkDecoder.setBaksmaliDebugMode(false);
129 | apkDecoder.setDebugMode(false);
130 | apkDecoder.setOutDir(mProjectDir);
131 | apkDecoder.setApkFile(mApkDir);
132 | apkDecoder.decode();
133 | } catch (AndrolibException e) {
134 | e.printStackTrace();
135 | return false;
136 | } catch (IOException e) {
137 | e.printStackTrace();
138 | return false;
139 | }
140 |
141 | if (mSmaliDir.exists()) {
142 | try {
143 | FileUtils.moveDirectory(mSmaliDir, mSrcDir);
144 | } catch (IOException e) {
145 | e.printStackTrace();
146 | // Rename the smali to src is not required, skip it if error.
147 | }
148 | }
149 |
150 | return true;
151 | }
152 |
153 | public boolean extractAll() {
154 | System.out.println(">>> (2/5) Extracting files...");
155 | try {
156 | ExtFile zipFile = new ExtFile(mApkDir);
157 | zipFile.getDirectory().copyToDir(mProjectDir);
158 | return true;
159 |
160 | } catch (Exception e) {
161 | e.printStackTrace();
162 | }
163 | return false;
164 | }
165 |
166 | public boolean decodeToClassDex() {
167 | System.out.print(">>> (3/5) Generating all Java Class files...");
168 |
169 | try {
170 | DexFileReader reader = new DexFileReader(mClassesDexFile);
171 |
172 | int count = reader.getClassSize();
173 | String remain = "(Estimate " + (count / 100) + " seconds)";
174 | System.out.print(remain);
175 |
176 | DexExceptionHandlerImpl handler = new DexExceptionHandlerImpl().skipDebug(true);
177 |
178 | Dex2jar.from(reader).withExceptionHandler(handler).reUseReg(true).topoLogicalSort(true).skipDebug(true)
179 | .optimizeSynchronized(true).printIR(false).verbose(false).to(mClassesJarFile.toString());
180 |
181 | if (handler != null) {
182 | Map exceptions = handler.getExceptions();
183 | if (exceptions != null && exceptions.size() > 0) {
184 | File errorFile = mClassesJarErrorFile;
185 | handler.dumpException(reader, errorFile);
186 | }
187 | }
188 |
189 | String remove = "";
190 | for (int i = 0; i < remain.length(); i++) {
191 | remove += "\b";
192 | }
193 | System.out.println(remove);
194 | return true;
195 | } catch (IOException e) {
196 | e.printStackTrace();
197 | }
198 |
199 | return false;
200 | }
201 |
202 | public boolean decodeToJavaCodes() {
203 | System.out.print(">>> (4/5) Generating all Java source code files...");
204 |
205 | Decompiler decompiler = new Decompiler(mClassesJarFile);
206 | ArrayList failureList = new ArrayList();
207 | DecomplieEnumeration enumeration;
208 | try {
209 | enumeration = decompiler.getEnumeration();
210 | } catch (IOException e) {
211 | e.printStackTrace();
212 | return false;
213 | }
214 |
215 | PercentWritter percentWritter = new PercentWritter();
216 | int count = enumeration.getCount();
217 | int current = 0;
218 | while (enumeration.hasMoreElements()) {
219 | percentWritter.print(current, count);
220 | try {
221 | DecomplieEntry entry = (DecomplieEntry) enumeration.nextElement();
222 | if (entry != null) {
223 | String relativePath = entry.getJavaPath();
224 | File saveFile = new File(mSrcDir, relativePath);
225 | File saveParentDir = saveFile.getParentFile();
226 | if (!saveParentDir.exists()) {
227 | saveParentDir.mkdirs();
228 | }
229 |
230 | String source = entry.getContent();
231 | if (source != null && source != "") {
232 | FileUtils.write(saveFile, source);
233 | } else {
234 | failureList.add(relativePath.toString());
235 | }
236 | }
237 | } catch (Exception e) {
238 | e.printStackTrace();
239 | }
240 |
241 | current++;
242 | }
243 | percentWritter.end(true);
244 |
245 | if (failureList.size() > 0) {
246 | Collections.sort(failureList);
247 | writeError("Unable to decompile these files:", failureList);
248 | }
249 |
250 | String printString = String.format(
251 | " Decompiled %d java source files, succeed %d files, error %d files", count, count
252 | - failureList.size(), failureList.size());
253 | System.out.println(printString);
254 |
255 | return true;
256 | }
257 |
258 | private void writeError(String errorTitle, List errors) {
259 | try {
260 | FileWriter errorWriter = new FileWriter(mErrorFile);
261 | errorWriter.write(errorTitle + "\r\n");
262 |
263 | for (String error : errors) {
264 | errorWriter.write(" " + error + "\r\n");
265 | }
266 |
267 | if (errorWriter != null) {
268 | errorWriter.close();
269 | }
270 | } catch (IOException e) {
271 | e.printStackTrace();
272 | }
273 | }
274 |
275 | private boolean writeEclipseProjectFiles() {
276 | System.out.println(">>> (5/5) Creating a new Android project...");
277 | mGenerateProjectOperator.generateGenDir();
278 | mGenerateProjectOperator.genereateProjectPropertiesFile();
279 | mGenerateProjectOperator.generateClassPathFile();
280 | mGenerateProjectOperator.generateProjectFile();
281 |
282 | return true;
283 | }
284 | }
285 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright (c) 2013-2014 Jiongxuan Zhang
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
204 |
--------------------------------------------------------------------------------