MCPcopy Create free account
hub / github.com/Y4tacker/JavaSec / MyTransformer

Class MyTransformer

6.JavaAgent/LicenceCrack/src/main/java/MyTransformer.java:13–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11import java.security.ProtectionDomain;
12
13public class MyTransformer implements ClassFileTransformer {
14 public String HookPath;
15
16 public MyTransformer(String hookPath) {
17 HookPath = hookPath;
18 }
19
20 public static byte[] getFileBytes(String filename) throws Exception{
21 FileInputStream fileInputStream = new FileInputStream(new File(filename));
22 byte[] bytes = new byte[1024];
23 int read;
24 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
25 while ((read =fileInputStream.read(bytes))!=-1){
26 outputStream.write(bytes,0,read);
27 }
28 return outputStream.toByteArray();
29 }
30 @Override
31 public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
32 if (!className.equals("CrackLicenseTest")){
33 return null;
34 }else {
35 try {
36 ClassPool aDefault = ClassPool.getDefault();
37
38 byte[] bytes = getFileBytes("E:\\LicenceCrack\\target\\classes\\CrackLicenseTest.class");
39 CtClass ctClass = aDefault.makeClass(new ByteArrayInputStream(bytes));
40 CtMethod ctMethod = ctClass.getDeclaredMethod(
41 "checkExpiry", new CtClass[]{aDefault.getCtClass("java.lang.String")}
42 );
43 ctMethod.insertBefore("return false;");
44 ctMethod.insertBefore("System.out.println(\"License到期时间:\" + $1);");
45 bytes = ctClass.toBytecode();
46 return bytes;
47 } catch (Exception e) {
48 return null;
49 }
50 }
51 }
52
53 public static void main(String[] args) throws Exception{
54 getFileBytes("E:\\LicenceCrack\\target\\classes\\CrackLicenseTest.class");
55 }
56}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected