| 6 | import java.util.List; |
| 7 | |
| 8 | public class MyAgent { |
| 9 | public static void agentmain(String agentArgs, Instrumentation inst){ |
| 10 | inst.addTransformer(new MyTransformer("E:\\LicenceCrack\\target\\classes\\CrackLicenseTest.class"),true); |
| 11 | Class[] loadedClass = inst.getAllLoadedClasses(); |
| 12 | for (Class clazz : loadedClass){ |
| 13 | String className = clazz.getName(); |
| 14 | if (inst.isModifiableClass(clazz)){ |
| 15 | if (className.equals("CrackLicenseTest")){ |
| 16 | try { |
| 17 | inst.retransformClasses(clazz); |
| 18 | } catch (UnmodifiableClassException e) { |
| 19 | e.printStackTrace(); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | } |
| 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected