Skip to content

Commit bc20724

Browse files
committed
Improve ui and fix bugs
1 parent cd7a690 commit bc20724

File tree

8 files changed

+50
-37
lines changed

8 files changed

+50
-37
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ Smali2Java is a vscode extension that allows you to decompile a single `smali` f
66

77
## Usage
88

9-
1. Configure the path to the `jadx` executable in `smali2java.jadxPath`.
9+
1. Configure the path to the `jadx` executable in `smali2java.decompiler.jadx.path`.
1010

1111
> [Jadx](https://github.com/skylot/jadx) is an excellent Java bytecode decompiler. Smali2Java uses it for decompilation. More decompilation tools will be supported in future releases.
1212
13-
Download [Jadx](https://github.com/skylot/jadx), unzip it somewhere, and modify the configuration item `smali2java.jadxPath` to point to the path of the Jadx executable (not jadx-gui).
13+
Download [Jadx](https://github.com/skylot/jadx), unzip it somewhere, and modify the configuration item `smali2java.decompiler.jadx.path` to point to the path of the Jadx executable (not jadx-gui).
1414
- example: C:/Program Files/jadx/bin/jadx.bat
1515

16-
2. Open a smali file using vscode.Then select `Decompile to Java` from the editor context menu. Or just click the `Decompile` in the editor title bar.
16+
2. Open a smali file using vscode.Then select `Decompile This File` from the editor context menu. Or just click the `Decompile` in the editor title bar.
1717

1818
![Usage](./res/snapshot/usage.gif)
1919

2020
## Extension Settings
2121

22-
* `smali2java.jadxPath`: Specifies the jadx executable path which use to decompile smali.
23-
* `smali2java.jadxOptions`: Specifies additional command line arguments required for decompilation
22+
* `smali2java.decompiler.jadx.path`: Path to jadx (or jadx.bat for windows).
23+
* `smali2java.decompiler.jadx.options`: Options used to run jadx decompilation command (will be appended directly to the end of the command).

README_CN.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ https://marketplace.visualstudio.com/items?itemName=ooooonly.smali2java
77

88
## 使用方法
99

10-
1.`smali2java.jadxPath`配置项设置为`jadx`可执行文件路径。
10+
1.`smali2java.decompiler.jadx.path`配置项设置为`jadx`可执行文件路径。
1111

1212
> [jadx](https://github.com/skylot/jadx) 是一个优秀的反编译工具。 Smali2Java 使用它完成反编译工作。后续将会支持调用更多反编译工具。
1313
14-
下载 [jadx](https://github.com/skylot/jadx), 解压至某处, 修改配置项 `smali2java.jadxPath` 为你的jadx可执行文件路径 (不是 jadx-gui)。
14+
下载 [jadx](https://github.com/skylot/jadx), 解压至某处, 修改配置项 `smali2java.decompiler.jadx.path` 为你的jadx可执行文件路径 (不是 jadx-gui)。
1515
- 比如: C:/Program Files/jadx/bin/jadx.bat
1616

1717
2. 使用vscode打开smali文件。在右键菜单中选择 `Decompile to Java` 。或者直接点击标题栏上的 `Decompile` 按钮.
@@ -20,5 +20,5 @@ https://marketplace.visualstudio.com/items?itemName=ooooonly.smali2java
2020

2121
## 插件设置
2222

23-
* `smali2java.jadxPath`: 设置jadx可执行文件路径
24-
* `smali2java.jadxOptions`: 设置jadx命令行额外参数
23+
* `smali2java.decompiler.jadx.path`: jadx可执行文件路径
24+
* `smali2java.decompiler.jadx.options`: jadx命令行参数

package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"author": "ooooonly",
44
"publisher": "ooooonly",
55
"displayName": "Smali2Java",
6-
"description": "Decompile single smali file quickly",
7-
"version": "1.0.1",
6+
"description": "Decompile single smali file instantly",
7+
"version": "1.1.0",
88
"license": "SEE LICENSE IN LICENSE",
99
"icon": "res/icon.png",
1010
"engines": {
@@ -14,9 +14,7 @@
1414
"Other"
1515
],
1616
"activationEvents": [
17-
"onLanguage:smali",
18-
"onCommand:smali2java.decompileCurrentSmaliToJava",
19-
"onCommand:smali2java.clearCache"
17+
"onLanguage:smali"
2018
],
2119
"keywords": [
2220
"smali",
@@ -37,11 +35,15 @@
3735
"contributes": {
3836
"commands": [
3937
{
40-
"command": "smali2java.decompileCurrentSmaliToJava",
41-
"title": "Decompile to Java",
38+
"command": "smali2java.decompileThisFile",
39+
"title": "Decompile This File",
4240
"shortTitle": "Decompile",
4341
"category": "Smali",
44-
"enablement": "true"
42+
"enablement": "true",
43+
"icon": {
44+
"dark": "./res/dark/decompile.svg",
45+
"light": "./res/light/decompile.svg"
46+
}
4547
},
4648
{
4749
"command": "smali2java.clearCache",
@@ -54,14 +56,14 @@
5456
"menus": {
5557
"editor/title": [
5658
{
57-
"command": "smali2java.decompileCurrentSmaliToJava",
59+
"command": "smali2java.decompileThisFile",
5860
"when": "resourceExtname == .smali || editorLangId == smali",
5961
"group": "navigation"
6062
}
6163
],
6264
"editor/context": [
6365
{
64-
"command": "smali2java.decompileCurrentSmaliToJava",
66+
"command": "smali2java.decompileThisFile",
6567
"when": "resourceExtname == .smali || editorLangId == smali",
6668
"group": "navigation"
6769
}
@@ -70,15 +72,15 @@
7072
"configuration": {
7173
"title": "Smali2Java",
7274
"properties": {
73-
"smali2java.jadxPath": {
75+
"smali2java.decompiler.jadx.path": {
7476
"type": "string",
7577
"default": null,
76-
"description": "Specifies the jadx executable path which use to decompile smali."
78+
"description": "Path to jadx (or jadx.bat for windows)."
7779
},
78-
"smali2java.jadxOptions": {
80+
"smali2java.decompiler.jadx.options": {
7981
"type": "string",
8082
"default": "",
81-
"description": "Specifies additional command line arguments required for decompilation."
83+
"description": "Options used to run jadx decompilation command (will be appended directly to the end of the command)."
8284
}
8385
}
8486
}

res/dark/decompile.svg

Lines changed: 1 addition & 0 deletions
Loading

res/light/decompile.svg

Lines changed: 1 addition & 0 deletions
Loading

src/decompiler/impl/JadxDecompiler.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,38 @@ import { getSmaliDocumentClassNameFromUri } from "../../util/smali-util";
99

1010
const execAsync = promisify(exec)
1111

12+
interface JadxConfig {
13+
path?: string,
14+
options?: string
15+
}
16+
1217
export class JadxDecompiler implements SmaliDecompiler {
1318
constructor(
1419
public sourceOutputDir: string,
1520
public outputChannel: OutputChannel,
1621
) {
17-
1822
}
1923

2024
private getOutputFilePath(smaliClassName: string) {
2125
return join(this.sourceOutputDir, (smaliClassName.includes("/") ? "" : "defpackage/") + smaliClassName + ".java")
2226
}
2327

24-
private async getJadxPath(): Promise<string> {
25-
const jadxPath: string | undefined = workspace.getConfiguration("smali2java").get("jadxPath")
26-
if (!jadxPath) throw new DecompileError("The jadx executable path has not been configured")
27-
if (!(await fsAsync.stat(jadxPath)).isFile()) throw new DecompileError("Illegal jadx executable path")
28-
return jadxPath
28+
private async loadConfig(): Promise<JadxConfig> {
29+
const config = workspace.getConfiguration("smali2java.decompiler.jadx")
30+
return {
31+
path: config.get("path"),
32+
options: config.get("options")
33+
}
2934
}
3035

31-
async decompile(smaliFileUri: Uri, options?: any): Promise<Uri> {
36+
async decompile(smaliFileUri: Uri): Promise<Uri> {
3237
const smaliClassName = await getSmaliDocumentClassNameFromUri(smaliFileUri)
3338
if (!smaliClassName) throw new DecompileError("Illegal smali file")
39+
const config = await this.loadConfig()
40+
if (!config.path) throw new DecompileError("The jadx executable path has not been configured")
41+
if (!(await fsAsync.stat(config.path)).isFile()) throw new DecompileError("Illegal jadx executable path")
3442
const outputFilePath = this.getOutputFilePath(smaliClassName)
35-
const { stdout, stderr } = await execAsync(`${await this.getJadxPath()} "${smaliFileUri.fsPath}" -ds "${this.sourceOutputDir}" ${options ?? ""}`)
43+
const { stdout, stderr } = await execAsync(`${await config.path} "${smaliFileUri.fsPath}" -ds "${this.sourceOutputDir}" ${config.options ?? ""}`)
3644
this.outputChannel.append(stdout)
3745
if (stderr && stderr.length > 0) {
3846
this.outputChannel.show()
@@ -41,8 +49,8 @@ export class JadxDecompiler implements SmaliDecompiler {
4149
}
4250
try {
4351
await fsAsync.stat(outputFilePath)
44-
} catch {
45-
throw new DecompileError("The compiled file is not found")
52+
} catch(e) {
53+
throw new DecompileError(`Error is caught when reading ${outputFilePath}: ${e}`)
4654
}
4755
return Uri.from({
4856
scheme: JavaCodeProvider.scheme,

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import DecompileCommand from './command/decompile';
44
import clearCacheCommand from './command/clear-cache';
55

66
export function activate(context: ExtensionContext) {
7-
const provider = new JavaCodeProvider()
7+
const provider = new JavaCodeProvider();
88
context.subscriptions.push(
99
workspace.registerTextDocumentContentProvider(JavaCodeProvider.scheme, provider),
10-
commands.registerCommand("smali2java.decompileCurrentSmaliToJava", DecompileCommand(context, provider)),
10+
commands.registerCommand("smali2java.decompileThisFile", DecompileCommand(context, provider)),
1111
commands.registerCommand("smali2java.clearCache", clearCacheCommand(context))
1212
);
1313
}

0 commit comments

Comments
 (0)