|
1 | 1 | package the.bytecode.club.bytecodeviewer;
|
2 | 2 |
|
3 |
| -import java.io.File; |
4 |
| - |
5 | 3 | import org.apache.commons.io.FileUtils;
|
| 4 | +import org.zeroturnaround.zip.ZipUtil; |
| 5 | + |
| 6 | +import java.io.File; |
| 7 | +import java.nio.file.Files; |
| 8 | +import java.nio.file.Path; |
6 | 9 |
|
7 | 10 | /***************************************************************************
|
8 | 11 | * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
9 | 12 | * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
|
10 |
| - * * |
| 13 | + * * |
11 | 14 | * This program is free software: you can redistribute it and/or modify *
|
12 |
| - * it under the terms of the GNU General Public License as published by * |
13 |
| - * the Free Software Foundation, either version 3 of the License, or * |
14 |
| - * (at your option) any later version. * |
15 |
| - * * |
16 |
| - * This program is distributed in the hope that it will be useful, * |
17 |
| - * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
18 |
| - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
19 |
| - * GNU General Public License for more details. * |
20 |
| - * * |
21 |
| - * You should have received a copy of the GNU General Public License * |
22 |
| - * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 15 | + * it under the terms of the GNU General Public License as published by * |
| 16 | + * the Free Software Foundation, either version 3 of the License, or * |
| 17 | + * (at your option) any later version. * |
| 18 | + * * |
| 19 | + * This program is distributed in the hope that it will be useful, * |
| 20 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 21 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 22 | + * GNU General Public License for more details. * |
| 23 | + * * |
| 24 | + * You should have received a copy of the GNU General Public License * |
| 25 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
23 | 26 | ***************************************************************************/
|
24 | 27 |
|
25 | 28 | public class APKTool {
|
26 |
| - |
27 |
| - public static synchronized void decodeResources(File input, File output) { |
28 |
| - try { |
29 |
| - File dir = new File(BytecodeViewer.tempDirectory+BytecodeViewer.fs+"Decoded Resources"); |
30 |
| - FileUtils.deleteDirectory(dir); |
31 |
| - brut.apktool.Main.main(new String[]{"-s", "-f", "-o", dir.getAbsolutePath(), "decode", input.getAbsolutePath()}); |
32 |
| - File original = new File(dir.getAbsolutePath() + BytecodeViewer.fs + "original"); |
33 |
| - FileUtils.deleteDirectory(original); |
34 |
| - File classes = new File(dir.getAbsolutePath() + BytecodeViewer.fs + "classes.dex"); |
35 |
| - classes.delete(); |
36 |
| - File apktool = new File(dir.getAbsolutePath() + BytecodeViewer.fs + "apktool.yml"); |
37 |
| - apktool.delete(); |
38 |
| - File zip = new File(BytecodeViewer.tempDirectory+BytecodeViewer.fs+MiscUtils.randomString(12)+".zip"); |
39 |
| - ZipUtils.zipFolder(dir.getAbsolutePath(), zip.getAbsolutePath(), null); |
40 |
| - if(zip.exists()) |
41 |
| - zip.renameTo(output); |
42 |
| - FileUtils.deleteDirectory(dir); |
43 |
| - } catch(Exception e) { |
44 |
| - new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); |
45 |
| - } |
46 |
| - } |
| 29 | + public static synchronized void decodeResources(File input, File output) { |
| 30 | + try { |
| 31 | + Path temporaryDirectory = Files.createTempDirectory("apkresources"); |
| 32 | + Files.delete(temporaryDirectory); |
| 33 | + brut.apktool.Main.main(new String[]{"-s", "-f", "-o", temporaryDirectory.toAbsolutePath().toString(), "decode", input.getAbsolutePath()}); |
| 34 | + File directory = temporaryDirectory.toFile(); |
| 35 | + File original = new File(directory, "original"); |
| 36 | + FileUtils.deleteDirectory(original); |
| 37 | + File classes = new File(directory, "classes.dex"); |
| 38 | + classes.delete(); |
| 39 | + File apktool = new File(directory, "apktool.yml"); |
| 40 | + apktool.delete(); |
| 41 | + ZipUtil.pack(directory, output); |
| 42 | + FileUtils.deleteDirectory(directory); |
| 43 | + } catch (Exception e) { |
| 44 | + new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); |
| 45 | + } |
| 46 | + } |
47 | 47 | }
|
0 commit comments