-
Notifications
You must be signed in to change notification settings - Fork 335
Expand file tree
/
Copy pathinterface.ts
More file actions
143 lines (134 loc) · 5.44 KB
/
Copy pathinterface.ts
File metadata and controls
143 lines (134 loc) · 5.44 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import * as path from "path";
import * as fs from "fs";
import { commands, QuickPickItem, Uri, window } from "vscode";
import { outputChannel } from "./data/constants";
import { quickPickUtil } from "./utils/quick-picks";
import { Quark } from "./tools/quark-engine";
import { apktool } from "./tools/apktool";
import { git } from "./tools/git";
import { jadx } from "./tools/jadx";
export namespace UI {
/**
* Show a QuickPick with multiple items.
* @param items QuickPickItems to show in the QuickPick.
* @param placeHolder Place holder text in the box under QuickPick.
* @returns string[] of the label for selected QuickPickItem[].
*/
export async function showArgsQuickPick(
items: QuickPickItem[],
placeHolder: string
): Promise<QuickPickItem[] | undefined> {
return await window.showQuickPick(items, {
placeHolder: placeHolder,
canPickMany: true,
matchOnDetail: true,
matchOnDescription: true,
ignoreFocusOut: true,
});
}
/**
* Show a APK file chooser window and decompile that APK.
*/
export async function openApkFile(): Promise<void> {
// browse for an APK file
const result = await window.showOpenDialog({
canSelectFolders: false,
filters: {
APK: ["apk"],
},
openLabel: "Select an APK file",
});
if (result && result.length === 1) {
const quickPickItems = await showArgsQuickPick(
quickPickUtil.getQuickPickItems("decodeQuickPickItems"),
"Additional features & Apktool/Jadx arguments"
);
if (quickPickItems) {
const args = quickPickItems.map<string>((item) => item.label);
const argDescriptions = quickPickItems.map<string | undefined>(
(item) => item.description
);
const decompileJavaIndex =
argDescriptions.indexOf("[Use Jadx]");
const quarkAnalysisIndex =
argDescriptions.indexOf("[Use Quark-Engine]");
const jadxOptionsIndex = argDescriptions.indexOf("jadx");
const jadxOptionsNumber = argDescriptions.filter(
(item) => item === "jadx"
).length;
let decompileJava = false;
let quarkAnalysis = false;
let jadxArgs: string[] = [];
if (jadxOptionsIndex > -1) {
jadxArgs = args.splice(jadxOptionsIndex, jadxOptionsNumber);
}
if (decompileJavaIndex > -1) {
decompileJava = true;
args.splice(decompileJavaIndex, 1);
}
if (quarkAnalysisIndex > -1) {
quarkAnalysis = true;
args.splice(quarkAnalysisIndex, 1);
if (!Quark.checkQuarkInstalled()) {
quarkAnalysis = false;
window.showErrorMessage(
"APKLab: Quark command not found, \
please make sure you have installed python3 and Quark-Engine. \
Check here to install Quark-Engine: \
https://github.com/quark-engine/quark-engine"
);
return;
}
}
// project directory name
const apkFilePath = result[0].fsPath;
let projectDir = path.join(
path.dirname(apkFilePath),
path.parse(apkFilePath).name
);
// don't delete the existing dir if it already exists
while (fs.existsSync(projectDir)) {
projectDir = projectDir + "1";
}
// decode APK
await apktool.decodeAPK(apkFilePath, projectDir, args);
// decompile APK
if (decompileJava) {
await jadx.decompileAPK(apkFilePath, projectDir, jadxArgs);
}
// quark analysis
if (quarkAnalysis) {
await Quark.analyzeAPK(apkFilePath, projectDir);
}
// Initialize project dir as git repo
await git.initGitDir(projectDir, "Initial APKLab project");
// open project dir in a new window
if (!process.env["TEST"]) {
await commands.executeCommand(
"vscode.openFolder",
Uri.file(projectDir),
true
);
}
}
} else {
outputChannel.appendLine("APKLAB: no APK file was chosen");
}
}
/**
* Show a QuickPick with extra args and build the APK.
* @param apktoolYmlPath path of the `apktool.yml` file.
*/
export async function rebuildAPK(apktoolYmlPath: string): Promise<void> {
const quickPickItems = await showArgsQuickPick(
quickPickUtil.getQuickPickItems("rebuildQuickPickItems"),
"Additional Apktool arguments"
);
const args = quickPickItems
? quickPickItems.map<string>((item) => item.label)
: undefined;
if (args) {
await apktool.rebuildAPK(apktoolYmlPath, args);
}
}
}