-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathAPKTool.java
More file actions
95 lines (80 loc) · 3.66 KB
/
APKTool.java
File metadata and controls
95 lines (80 loc) · 3.66 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
package the.bytecode.club.bytecodeviewer.util;
import org.apache.commons.io.FileUtils;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
import java.io.File;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* @author Konloch
*/
public class APKTool
{
public static final String DECODED_RESOURCES = "Decoded Resources";
public static synchronized void decodeResources(File input, ResourceContainer container)
{
try
{
File dir = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS + DECODED_RESOURCES);
dir.mkdirs();
File tempAPKPath = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(12));
tempAPKPath.mkdirs();
brut.apktool.Main.main(new String[] {
"r",
"--frame-path", tempAPKPath.getAbsolutePath(),
"d", input.getAbsolutePath(),
"-o", dir.getAbsolutePath(),
"-f",
"-jobs",
String.valueOf(Runtime.getRuntime().availableProcessors())
});
container.APKToolContents = dir;
tempAPKPath.delete();
}
catch (Exception e)
{
BytecodeViewer.handleException(e);
}
}
public static synchronized void buildAPK(File output, ResourceContainer container)
{
String temp = TEMP_DIRECTORY + FS;
File tempDir = new File(temp + FS + MiscUtils.getRandomizedName() + FS);
tempDir.mkdirs();
File tempAPKPath = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(12));
tempAPKPath.mkdirs();
try
{
File smaliFolder = new File(container.APKToolContents.getAbsolutePath() + FS + "smali");
FileUtils.deleteDirectory(smaliFolder);
//save entire jar as smali files
System.out.println("Building!");
brut.apktool.Main.main(new String[]{"b", container.APKToolContents.getAbsolutePath(),
"--frame-path", tempAPKPath.getAbsolutePath(),
"-o", output.getAbsolutePath()});
//cleanup
tempAPKPath.delete();
}
catch (Exception e)
{
BytecodeViewer.handleException(e);
}
}
}