Add asm client version reader
This commit is contained in:
44
src/main/java/net/runelite/deob/clientver/ClientVersion.java
Normal file
44
src/main/java/net/runelite/deob/clientver/ClientVersion.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package net.runelite.deob.clientver;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
|
||||
public class ClientVersion
|
||||
{
|
||||
private File jar;
|
||||
|
||||
public ClientVersion(File jar)
|
||||
{
|
||||
this.jar = jar;
|
||||
}
|
||||
|
||||
public int getVersion() throws IOException
|
||||
{
|
||||
try (JarFile jar = new JarFile(this.jar))
|
||||
{
|
||||
for (Enumeration<JarEntry> it = jar.entries(); it.hasMoreElements();)
|
||||
{
|
||||
JarEntry entry = it.nextElement();
|
||||
|
||||
if (!entry.getName().equals("client.class"))
|
||||
continue;
|
||||
|
||||
InputStream in = jar.getInputStream(entry);
|
||||
|
||||
ClassReader reader = new ClassReader(in);
|
||||
VersionClassVisitor v = new VersionClassVisitor();
|
||||
reader.accept(v, 0);
|
||||
return v.getVersion();
|
||||
//entries.put(entry.getName(), entry);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.runelite.deob.clientver;
|
||||
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
public class VersionClassVisitor extends ClassVisitor
|
||||
{
|
||||
private VersionMethodVisitor vmv = new VersionMethodVisitor();
|
||||
|
||||
public VersionClassVisitor()
|
||||
{
|
||||
super(Opcodes.ASM5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access,
|
||||
String name,
|
||||
String desc,
|
||||
String signature,
|
||||
String[] exceptions)
|
||||
{
|
||||
if (!name.equals("init"))
|
||||
return null;
|
||||
|
||||
return vmv;
|
||||
}
|
||||
|
||||
public int getVersion()
|
||||
{
|
||||
return vmv.getVersion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package net.runelite.deob.clientver;
|
||||
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
public class VersionMethodVisitor extends MethodVisitor
|
||||
{
|
||||
private int state = 0;
|
||||
private int version = -1;
|
||||
|
||||
VersionMethodVisitor()
|
||||
{
|
||||
super(Opcodes.ASM5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitIntInsn(int opcode, int operand)
|
||||
{
|
||||
if (state == 2)
|
||||
{
|
||||
version = operand;
|
||||
++state;
|
||||
}
|
||||
|
||||
if (operand == 765 || operand == 503)
|
||||
{
|
||||
++state;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public int getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.runelite.deob.clientver;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ClientVersionTest
|
||||
{
|
||||
@Test
|
||||
public void test() throws IOException, URISyntaxException
|
||||
{
|
||||
File f = new File(ClientVersionTest.class.getResource("/gamepack_v21.jar").toURI());
|
||||
ClientVersion ver = new ClientVersion(f);
|
||||
System.out.println(ver.getVersion());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user