Skip to content

Commit

Permalink
Add Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
sotasan committed Jun 22, 2022
1 parent 601e94e commit 18d97f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ tasks {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest.attributes["Specification-Version"] = project.version
manifest.attributes["Main-Class"] = "${project.group}.${project.name.toLowerCase()}.Main"
manifest.attributes["Agent-Class"] = "${project.group}.${project.name.toLowerCase()}.Agent"
from(configurations.compileClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/dev/shota/decompiler/Agent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@file:JvmName("Agent")
package dev.shota.decompiler

import java.lang.instrument.Instrumentation

fun agentmain(args: String?, inst: Instrumentation) {
println("Hello World!")
}
18 changes: 13 additions & 5 deletions src/main/kotlin/dev/shota/decompiler/window/popup/Processes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,32 @@ import javafx.scene.control.Button
import javafx.scene.control.TableColumn
import javafx.scene.control.TableView
import javafx.scene.layout.VBox
import java.io.File
import java.lang.management.ManagementFactory

class Processes : Popup("file.openProcess") {

init {
val root = VBox()

val table = TableView<VirtualMachineDescriptor>()
root.children.add(table)
for (vm in VirtualMachine.list())
if (ManagementFactory.getRuntimeMXBean().pid != vm.id().toLong())
table.items.add(vm)

val id = TableColumn<VirtualMachineDescriptor, String>("ID")
val entry = TableColumn<VirtualMachineDescriptor, String>("Entry")
id.setCellValueFactory { SimpleStringProperty(it.value.id()) }
entry.setCellValueFactory { SimpleStringProperty(it.value.displayName().split(" ").first()) }
table.columns.addAll(id, entry)
root.children.add(table)

for (vm in VirtualMachine.list())
table.items.add(vm)

val button = Button("Open")
button.setOnAction {}
button.setOnAction {
val vm = VirtualMachine.attach(table.selectionModel.selectedItem)
vm.loadAgent(File(javaClass.protectionDomain.codeSource.location.path).path)
vm.detach()
}
root.children.add(button)

run(root)
Expand Down

0 comments on commit 18d97f2

Please sign in to comment.