-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
decompiler action with context menu and notifications
- Loading branch information
Showing
9 changed files
with
329 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/org/move/bytecode/DecompileAptosMvFileAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.move.bytecode | ||
|
||
import com.intellij.notification.NotificationType.ERROR | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.CommonDataKeys | ||
import com.intellij.openapi.progress.ProgressManager | ||
import com.intellij.openapi.project.DumbAwareAction | ||
import org.move.bytecode.AptosBytecodeNotificationProvider.DecompilationModalTask | ||
import org.move.cli.settings.getAptosCli | ||
import org.move.ide.MoveIcons | ||
import org.move.ide.notifications.showBalloon | ||
import org.move.openapiext.openFile | ||
import org.move.stdext.unwrapOrElse | ||
import java.util.* | ||
|
||
class DecompileAptosMvFileAction: DumbAwareAction("Decompile .mv File", null, MoveIcons.APTOS_LOGO) { | ||
override fun actionPerformed(e: AnActionEvent) { | ||
val project = e.project ?: return | ||
val file = e.getData(CommonDataKeys.PSI_FILE)?.virtualFile ?: return | ||
val decompilationTask = DecompilationModalTask(project, file) | ||
val decompiledFile = ProgressManager.getInstance().run(decompilationTask) | ||
.unwrapOrElse { | ||
project.showBalloon("Error with decompilation process", it, ERROR) | ||
return | ||
} | ||
project.openFile(decompiledFile) | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
val file = e.getData(CommonDataKeys.PSI_FILE) | ||
val presentation = e.presentation | ||
val enabled = | ||
(file != null | ||
&& Objects.nonNull(file.virtualFile) && !(file.virtualFile.fileSystem.isReadOnly) | ||
&& file.fileType == AptosBytecodeFileType | ||
&& e.getData(CommonDataKeys.PROJECT)?.getAptosCli() != null) | ||
presentation.isEnabledAndVisible = enabled | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/org/move/bytecode/FetchAptosPackageAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.move.bytecode | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import org.move.cli.runConfigurations.aptos.RunAptosCommandActionBase | ||
|
||
class FetchAptosPackageAction: RunAptosCommandActionBase("Fetch on-chain package") { | ||
override fun actionPerformed(e: AnActionEvent) { | ||
val project = e.project ?: return | ||
|
||
val parametersDialog = FetchAptosPackageDialog(project) | ||
parametersDialog.show() | ||
} | ||
|
||
} |
113 changes: 113 additions & 0 deletions
113
src/main/kotlin/org/move/bytecode/FetchAptosPackageDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package org.move.bytecode | ||
|
||
import com.intellij.execution.process.ProcessOutput | ||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory | ||
import com.intellij.openapi.progress.ProgressIndicator | ||
import com.intellij.openapi.progress.ProgressManager | ||
import com.intellij.openapi.progress.Task | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.ui.DialogWrapper | ||
import com.intellij.openapi.ui.ValidationInfo | ||
import com.intellij.ui.components.JBCheckBox | ||
import com.intellij.ui.components.JBTextField | ||
import com.intellij.ui.dsl.builder.AlignX | ||
import com.intellij.ui.dsl.builder.panel | ||
import org.move.cli.settings.getAptosCli | ||
import org.move.openapiext.RsProcessResult | ||
import org.move.openapiext.pathField | ||
import org.move.stdext.unwrapOrElse | ||
import javax.swing.JComponent | ||
import kotlin.io.path.Path | ||
|
||
class FetchAptosPackageDialog(val project: Project): DialogWrapper(project, true) { | ||
|
||
val addressTextField = JBTextField() | ||
val packageTextField = JBTextField() | ||
val outputDirField = pathField( | ||
FileChooserDescriptorFactory.createSingleFolderDescriptor(), | ||
this.disposable, | ||
"Output Directory" | ||
) | ||
val decompileCheckbox = JBCheckBox("Decompile afterwards") | ||
|
||
val profileField = JBTextField("default") | ||
val nodeApiKey = JBTextField() | ||
val connectionTimeout = JBTextField() | ||
|
||
init { | ||
title = "Aptos Decompiler" | ||
setSize(600, 400) | ||
|
||
outputDirField.text = project.basePath.orEmpty() | ||
decompileCheckbox.isSelected = true | ||
init() | ||
} | ||
|
||
override fun createCenterPanel(): JComponent { | ||
return panel { | ||
row("Address:") { cell(addressTextField).align(AlignX.FILL) } | ||
row("Package:") { cell(packageTextField).align(AlignX.FILL) } | ||
row("Output directory:") { cell(outputDirField).align(AlignX.FILL) } | ||
row { cell(decompileCheckbox) } | ||
|
||
val parametersGroup = collapsibleGroup("Connection Parameters") { | ||
row("Profile:") { cell(profileField) } | ||
row("Node API Key:") { cell(nodeApiKey) } | ||
row("Connection timeout:") { cell(connectionTimeout) } | ||
} | ||
parametersGroup.expanded = false | ||
|
||
} | ||
} | ||
|
||
override fun doOKAction() { | ||
val accountAddress = this.addressTextField.text | ||
val packageName = this.packageTextField.text | ||
// val profile = this.profileField.text | ||
val outputDir = this.outputDirField.text | ||
val decompile = this.decompileCheckbox.isSelected | ||
val aptos = project.getAptosCli(this.disposable) ?: return | ||
|
||
val downloadTask = object: Task.WithResult<RsProcessResult<ProcessOutput>, Exception>( | ||
project, | ||
"Downloading $accountAddress::$packageName...", | ||
true | ||
) { | ||
override fun compute(indicator: ProgressIndicator): RsProcessResult<ProcessOutput> { | ||
return aptos.downloadPackage(project, accountAddress, packageName, outputDir, | ||
runner = { runProcessWithProgressIndicator(indicator) }) | ||
} | ||
} | ||
ProgressManager.getInstance().run(downloadTask) | ||
.unwrapOrElse { | ||
this.setErrorText(it.message) | ||
return | ||
} | ||
|
||
if (decompile) { | ||
val decompileTask = object: Task.WithResult<RsProcessResult<ProcessOutput>, Exception>( | ||
project, | ||
"Decompiling $accountAddress::$packageName...", | ||
true | ||
) { | ||
override fun compute(indicator: ProgressIndicator): RsProcessResult<ProcessOutput> { | ||
val downloadedPath = Path(outputDir).resolve(packageName) | ||
return aptos.decompileDownloadedPackage(downloadedPath) | ||
} | ||
} | ||
ProgressManager.getInstance().run(decompileTask) | ||
.unwrapOrElse { | ||
this.setErrorText(it.message) | ||
return | ||
} | ||
} | ||
|
||
super.doOKAction() | ||
} | ||
|
||
override fun getPreferredFocusedComponent(): JComponent = addressTextField | ||
|
||
override fun doValidate(): ValidationInfo? { | ||
return super.doValidate() | ||
} | ||
} |
Oops, something went wrong.