| 24 | } |
| 25 | } |
| 26 | public static void main(String[] args) throws Exception { |
| 27 | |
| 28 | int flag = 0; |
| 29 | while (true) { |
| 30 | List<VirtualMachineDescriptor> list = VirtualMachine.list(); |
| 31 | |
| 32 | for (VirtualMachineDescriptor desc : list) { |
| 33 | if ("CrackLicenseTest".equals(desc.displayName())) { |
| 34 | System.out.println("获取到注入进程ID:" + desc.id() + ",进程名称:" + desc.displayName()); |
| 35 | VirtualMachine vm = VirtualMachine.attach(desc.id()); |
| 36 | String agentPath = "E:\\LicenceCrack\\target\\LicenceCrack-1.0-SNAPSHOT.jar"; |
| 37 | // 注入Agent到目标JVM |
| 38 | vm.loadAgent(agentPath); |
| 39 | vm.detach(); |
| 40 | flag = 1; |
| 41 | break; |
| 42 | } |
| 43 | } |
| 44 | if (flag==1){ |
| 45 | break; |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |