Created
July 17, 2019 20:01
-
-
Save MiniDigger/677eacaa5671a69de3759910642677c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package me.minidigger.dumpa; | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.lang.instrument.ClassFileTransformer; | |
import java.lang.instrument.IllegalClassFormatException; | |
import java.lang.instrument.Instrumentation; | |
import java.security.ProtectionDomain; | |
import java.util.Arrays; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
public class dumper { | |
public static void premain(String agentArgs, Instrumentation inst) { | |
System.out.println("agent loaded"); | |
inst.addTransformer(new transformer()); | |
} | |
} | |
class transformer implements ClassFileTransformer { | |
public byte[] transform(ClassLoader loader, String className, | |
Class<?> classBeingRedefined, ProtectionDomain protectionDomain, | |
byte[] classfileBuffer) throws IllegalClassFormatException { | |
try { | |
if (className != null) { | |
// Skip all system classes | |
if (!className.startsWith("java") && | |
!className.startsWith("sun") && | |
!className.startsWith("javax") && !className.contains("jetbrains") && !className.contains("intellij") && | |
// !className.startsWith("com") && | |
!className.startsWith("jdk")) { | |
// !className.startsWith("org")) { | |
// normalize file name and create folder | |
String newName = className.replaceAll("[^a-zA-Z0-9-/]", "_") + ".class"; | |
String[] segments = newName.split("/"); | |
String fileName = segments[segments.length - 1]; | |
segments = Arrays.copyOf(segments, segments.length - 1); | |
String folderName = Stream.of(segments).map(s -> s.length() > 248 ? s.substring(248) : s).collect(Collectors.joining("/")); | |
File folder = new File(new File("D:\\IntellijProjects\\deobfuscator\\dump"), folderName); | |
folder.mkdirs(); | |
File file = new File(folder, fileName); | |
System.out.println("Dumping: " + file); | |
try { | |
// dumpa! | |
FileOutputStream fos = new FileOutputStream(file); | |
fos.write(classfileBuffer); | |
fos.close(); | |
} catch (Exception ex) { | |
System.out.println("Exception while writing: " + file); | |
ex.printStackTrace(); | |
} | |
} | |
} | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
} | |
return classfileBuffer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment