-
-
Save lucko/6d2654ea6347698419cbcf67ea8d4db0 to your computer and use it in GitHub Desktop.
This file contains 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
import org.objectweb.asm.ClassReader; | |
import org.objectweb.asm.tree.AbstractInsnNode; | |
import org.objectweb.asm.tree.ClassNode; | |
import org.objectweb.asm.tree.LdcInsnNode; | |
import org.objectweb.asm.tree.MethodNode; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.util.AbstractMap.SimpleEntry; | |
import java.util.ArrayList; | |
import java.util.Enumeration; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.jar.JarEntry; | |
import java.util.jar.JarFile; | |
public class StringFinder { | |
public static void main(String[] args) throws IOException { | |
List<Map.Entry<String, String>> results = new ArrayList<>(); | |
try (JarFile in = new JarFile(new File("input.jar"))) { | |
for (Enumeration<JarEntry> entries = in.entries(); entries.hasMoreElements(); ) { | |
JarEntry entry = entries.nextElement(); | |
if (entry.isDirectory() || !entry.getName().endsWith(".class")) { | |
continue; | |
} | |
try (InputStream entryIn = in.getInputStream(entry)) { | |
ClassReader cr = new ClassReader(entryIn); | |
ClassNode classNode = new ClassNode(); | |
cr.accept(classNode, 0); | |
for (MethodNode methodNode : classNode.methods) { | |
Iterator<AbstractInsnNode> insnIterator = methodNode.instructions.iterator(); | |
while (insnIterator.hasNext()) { | |
AbstractInsnNode insnNode = insnIterator.next(); | |
if (insnNode.getType() != AbstractInsnNode.LDC_INSN) { | |
continue; | |
} | |
Object constant = ((LdcInsnNode) insnNode).cst; | |
if (constant instanceof String) { | |
String str = ((String) constant); | |
results.add(new SimpleEntry<>(classNode.name + "." + methodNode.name, str)); | |
} | |
} | |
} | |
} | |
} | |
} | |
System.out.println("Found " + results.size() + " results"); | |
for (Map.Entry<String, String> entry : results) { | |
System.out.println(entry.getKey() + ": '" + entry.getValue() + "'"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment