diff --git a/package.json b/package.json index 096ade4..9b3ed39 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,10 @@ { "command": "apklab.quarkReport", "title": "APKLab: Show Quark analysis report" + }, + { + "command": "apklab.decompileSmali", + "title": "APKLab: Convert this Smali file to Java" } ], "menus": { @@ -91,6 +95,10 @@ { "command": "apklab.quarkReport", "when": "false" + }, + { + "command": "apklab.decompileSmali", + "when": "false" } ], "editor/context": [ @@ -108,6 +116,11 @@ "command": "apklab.quarkReport", "when": "resourceFilename == quarkReport.json", "group": "navigation" + }, + { + "command": "apklab.decompileSmali", + "when": "resourceExtname == .smali", + "group": "navigation" } ], "editor/title": [ @@ -144,6 +157,11 @@ "command": "apklab.quarkReport", "when": "resourceFilename == quarkReport.json", "group": "navigation" + }, + { + "command": "apklab.decompileSmali", + "when": "resourceExtname == .smali", + "group": "navigation" } ] }, diff --git a/src/extension.ts b/src/extension.ts index 113b9a1..f77839f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -87,13 +87,22 @@ export function activate(context: vscode.ExtensionContext): void { } ); + // command to show quark analysis report as web view + const decompileSmaliCommand = vscode.commands.registerCommand( + "apklab.decompileSmali", + (uri: vscode.Uri) => { + console.log(uri.fsPath); + } + ); + context.subscriptions.push( openApkFileCommand, rebuildAPkFileCommand, installAPkFileCommand, patchApkForHttpsCommand, emptyFrameworkDirCommand, - quarkReportCommand + quarkReportCommand, + decompileSmaliCommand ); // check if open folder contains `quarkReport.json` file diff --git a/src/tools/jadx.ts b/src/tools/jadx.ts index b969ae1..564879b 100644 --- a/src/tools/jadx.ts +++ b/src/tools/jadx.ts @@ -37,4 +37,31 @@ export namespace jadx { shouldExist: apkDecompileDir, }); } + export async function decompileSmaliFile( + smaliFilePath: string, + projectDir: string, + jadxArgs: string[] + ): Promise { + const extensionConfig = + vscode.workspace.getConfiguration(extensionConfigName); + const jadxDirPath = extensionConfig.get("jadxDirPath"); + const jadxExeName = `jadx${ + process.platform.startsWith("win") ? ".bat" : "" + }`; + const jadxPath = path.join(String(jadxDirPath), "bin", jadxExeName); + const apkDecompileDir = path.join(projectDir, "java_src"); + const apkFileName = path.basename(smaliFilePath); + const report = `Decompiling ${apkFileName} into ${apkDecompileDir}`; + let args = ["-r", "-q", "-v", "-ds", apkDecompileDir, smaliFilePath]; + if (jadxArgs && jadxArgs.length > 0) { + args = jadxArgs.concat(args); + } + await executeProcess({ + name: "Decompiling", + report: report, + command: jadxPath, + args: args, + shouldExist: apkDecompileDir, + }); + } }