Make injected-client maven dependency

This commit is contained in:
Lucas
2019-06-22 02:46:39 +02:00
parent a27cf7d415
commit 3977f9ca61
5 changed files with 66 additions and 265 deletions

View File

@@ -37,23 +37,11 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>net.runelite</groupId> <groupId>net.runelite.rs</groupId>
<artifactId>client</artifactId> <artifactId>rs-client</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<optional>true</optional> <!-- to prevent the dependency on this from runelite-client --> <optional>true</optional> <!-- to prevent the dependency on this from runelite-client -->
</dependency> </dependency>
<dependency>
<groupId>net.runelite.rs</groupId>
<artifactId>runescape-api</artifactId>
<version>${project.version}</version>
<optional>false</optional> <!-- to prevent the dependency on this from runelite-client -->
</dependency>
<dependency>
<groupId>net.runelite</groupId>
<artifactId>runelite-api</artifactId>
<version>${project.version}</version>
<optional>false</optional> <!-- to prevent the dependency on this from runelite-client -->
</dependency>
<dependency> <dependency>
<groupId>net.runelite.rs</groupId> <groupId>net.runelite.rs</groupId>
<artifactId>vanilla</artifactId> <artifactId>vanilla</artifactId>

View File

@@ -209,11 +209,12 @@
<groupId>net.runelite.rs</groupId> <groupId>net.runelite.rs</groupId>
<artifactId>runescape-api</artifactId> <artifactId>runescape-api</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.runelit</groupId> <groupId>net.runelite</groupId>
<artifactId>client-patch</artifactId> <artifactId>injected-client</artifactId>
<version>1.5.26.2</version> <version>${project.version}</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -334,8 +335,8 @@
<filters> <filters>
<!-- include runtime apis --> <!-- include runtime apis -->
<filter> <filter>
<!-- net.runelite:client-patch and net.runelite:api --> <!-- net.runelite:injected-client and net.runelite:api -->
<artifact>net.runelite:api</artifact> <artifact>net.runelite:*</artifact>
<includes> <includes>
<include>**</include> <include>**</include>
</includes> </includes>
@@ -346,13 +347,6 @@
<include>**</include> <include>**</include>
</includes> </includes>
</filter> </filter>
<filter>
<!-- net.runelit:client-patch -->
<artifact>net.runelit:client-patch</artifact>
<includes>
<include>**</include>
</includes>
</filter>
<filter> <filter>
<artifact>net.runelite.pushingpixels:*</artifact> <artifact>net.runelite.pushingpixels:*</artifact>
<includes> <includes>

View File

@@ -26,47 +26,19 @@
*/ */
package net.runelite.client.rs; package net.runelite.client.rs;
import net.runelite.api.Client; import java.net.URLClassLoader;
import java.applet.Applet; import java.applet.Applet;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import static net.runelite.client.RuneLite.RUNELITE_DIR;
import static net.runelite.client.rs.ClientUpdateCheckMode.AUTO;
import static net.runelite.client.rs.ClientUpdateCheckMode.CUSTOM;
import static net.runelite.client.rs.ClientUpdateCheckMode.VANILLA;
import net.runelite.http.api.RuneLiteAPI;
import okhttp3.Request;
import okhttp3.Response;
@Slf4j @Slf4j
@Singleton @Singleton
public class ClientLoader public class ClientLoader
{ {
private static final File LOCAL_INJECTED_CLIENT = new File("./injected-client/target/injected-client-" + RuneLiteAPI.getVersion() + ".jar");
private static final File INJECTED_CLIENT = new File(RUNELITE_DIR + "/injected-client.jar");
private final ClientConfigLoader clientConfigLoader; private final ClientConfigLoader clientConfigLoader;
private ClientUpdateCheckMode updateCheckMode; private ClientUpdateCheckMode updateCheckMode;
public static boolean useLocalInjected = false; public static boolean useLocalInjected = false;
@@ -84,125 +56,26 @@ public class ClientLoader
{ {
try try
{ {
Manifest manifest = new Manifest(); final RSConfig config = clientConfigLoader.fetch();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
RSConfig config = clientConfigLoader.fetch();
Map<String, byte[]> zipFile = new HashMap<>(); switch (updateCheckMode)
if (updateCheckMode == VANILLA)
{ {
Certificate[] jagexCertificateChain = getJagexCertificateChain(); case AUTO:
String codebase = config.getCodeBase(); case CUSTOM:
String initialJar = config.getInitialJar(); return loadRLPlus(config);
URL url = new URL(codebase + initialJar); default:
Request request = new Request.Builder() case VANILLA:
.url(url) return loadVanilla(config);
.build(); case NONE:
return null;
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
{
JarInputStream jis;
jis = new JarInputStream(response.body().byteStream());
byte[] tmp = new byte[4096];
ByteArrayOutputStream buffer = new ByteArrayOutputStream(756 * 1024);
for (; ; )
{
JarEntry metadata = jis.getNextJarEntry();
if (metadata == null)
{
break;
}
buffer.reset();
for (; ; )
{
int n = jis.read(tmp);
if (n <= -1)
{
break;
}
buffer.write(tmp, 0, n);
}
if (!Arrays.equals(metadata.getCertificates(), jagexCertificateChain))
{
if (metadata.getName().startsWith("META-INF/"))
{
// META-INF/JAGEXLTD.SF and META-INF/JAGEXLTD.RSA are not signed, but we don't need
// anything in META-INF anyway.
continue;
}
else
{
throw new VerificationException("Unable to verify jar entry: " + metadata.getName());
} }
} }
catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e)
zipFile.put(metadata.getName(), buffer.toByteArray());
}
}
}
else if (updateCheckMode == CUSTOM || useLocalInjected)
{
log.info("Loading injected client from {}", LOCAL_INJECTED_CLIENT.getAbsolutePath());
loadJar(zipFile, LOCAL_INJECTED_CLIENT);
}
else if (updateCheckMode == AUTO)
{
URL url = new URL("https://raw.githubusercontent.com/runelite-extended/maven-repo/master/live/injected-client.jar");
ReadableByteChannel readableByteChannel = Channels.newChannel(url.openStream());
INJECTED_CLIENT.mkdirs();
if (!INJECTED_CLIENT.exists() || getFileSize(INJECTED_CLIENT.toURI().toURL()) != getFileSize(url))
{
log.info("{} injected client", INJECTED_CLIENT.exists() ? "Updating" : "Initializing");
INJECTED_CLIENT.delete();
INJECTED_CLIENT.createNewFile();
updateInjectedClient(readableByteChannel);
}
log.info("Loading injected client from {}", INJECTED_CLIENT.getAbsolutePath());
loadJar(zipFile, INJECTED_CLIENT);
}
String initialClass = config.getInitialClass();
ClassLoader rsClassLoader = new ClassLoader(ClientLoader.class.getClassLoader())
{
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException
{
String path = name.replace('.', '/').concat(".class");
byte[] data = zipFile.get(path);
if (data == null)
{
throw new ClassNotFoundException(name);
}
return defineClass(name, data, 0, data.length);
}
};
Class<?> clientClass = rsClassLoader.loadClass(initialClass);
Applet rs = (Applet) clientClass.newInstance();
rs.setStub(new RSAppletStub(config));
if (rs instanceof Client)
{
log.info("client-patch 420 blaze it RL pricks");
}
return rs;
}
catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | SecurityException | VerificationException | CertificateException e)
{ {
if (e instanceof ClassNotFoundException) if (e instanceof ClassNotFoundException)
{ {
log.error("Unable to load client - class not found. This means you" log.error("Unable to load client - class not found. This means you"
+ " are not running RuneLite with Maven as the client patch" + " are not running RuneLite with Maven as the injected client"
+ " is not in your classpath."); + " is not in your classpath.");
} }
@@ -211,66 +84,31 @@ public class ClientLoader
} }
} }
private static int getFileSize(URL url) throws IOException private static Applet loadRLPlus(final RSConfig config) throws ClassNotFoundException, InstantiationException, IllegalAccessException
{ {
URLConnection conn = null; // the injected client is a runtime scoped dependency
try final Class<?> clientClass = ClientLoader.class.getClassLoader().loadClass(config.getInitialClass());
{ return loadFromClass(config, clientClass);
conn = url.openConnection();
if (conn instanceof HttpURLConnection)
{
((HttpURLConnection) conn).setRequestMethod("HEAD");
}
conn.getInputStream();
return conn.getContentLength();
}
finally
{
if (conn instanceof HttpURLConnection)
{
((HttpURLConnection) conn).disconnect();
}
}
} }
private void updateInjectedClient(ReadableByteChannel readableByteChannel) throws IOException private static Applet loadVanilla(final RSConfig config) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
{ {
FileOutputStream fileOutputStream = new FileOutputStream(INJECTED_CLIENT); final String codebase = config.getCodeBase();
fileOutputStream.getChannel() final String initialJar = config.getInitialJar();
.transferFrom(readableByteChannel, 0, Integer.MAX_VALUE); final String initialClass = config.getInitialClass();
final URL url = new URL(codebase + initialJar);
// Must set parent classloader to null, or it will pull from
// this class's classloader first
final URLClassLoader classloader = new URLClassLoader(new URL[]{url}, null);
final Class<?> clientClass = classloader.loadClass(initialClass);
return loadFromClass(config, clientClass);
} }
private static Certificate[] getJagexCertificateChain() throws CertificateException private static Applet loadFromClass(final RSConfig config, final Class<?> clientClass) throws IllegalAccessException, InstantiationException
{ {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); final Applet rs = (Applet) clientClass.newInstance();
Collection<? extends Certificate> certificates = certificateFactory.generateCertificates(ClientLoader.class.getResourceAsStream("jagex.crt")); rs.setStub(new RSAppletStub(config));
return certificates.toArray(new Certificate[0]); return rs;
}
private static void loadJar(Map<String, byte[]> toMap, File fromFile) throws IOException
{
JarInputStream fis = new JarInputStream(new FileInputStream(fromFile));
byte[] tmp = new byte[4096];
ByteArrayOutputStream buffer = new ByteArrayOutputStream(756 * 1024);
for (; ; )
{
JarEntry metadata = fis.getNextJarEntry();
if (metadata == null)
{
break;
}
buffer.reset();
for (; ; )
{
int n = fis.read(tmp);
if (n <= -1)
{
break;
}
buffer.write(tmp, 0, n);
}
toMap.put(metadata.getName(), buffer.toByteArray());
}
} }
} }

View File

@@ -1,9 +0,0 @@
package net.runelite.client.util.bootstrap;
public class Artifact
{
String hash;
String name;
String path;
String size;
}

View File

@@ -14,9 +14,16 @@ import net.runelite.http.api.RuneLiteAPI;
public class Bootstrap public class Bootstrap
{ {
class Artifact
{
String hash;
String name;
String path;
String size;
}
String buildCommit = "c554ab2400dc04a619b36695da2107648c9c87b3"; String buildCommit = "c554ab2400dc04a619b36695da2107648c9c87b3";
Artifact[] artifacts = getArtifacts(); private Artifact[] artifacts = getArtifacts();
Client client = new Client(); Client client = new Client();
String[] clientJvm9Arguments = new String[]{ String[] clientJvm9Arguments = new String[]{
"-XX:+DisableAttachMechanism", "-XX:+DisableAttachMechanism",
@@ -46,54 +53,32 @@ public class Bootstrap
"-XX:+UseParNewGC", "-XX:+UseParNewGC",
"-Djna.nosys=true"}; "-Djna.nosys=true"};
public Bootstrap() Bootstrap()
{ {
} }
public static String getChecksumObject(Serializable object) throws IOException, NoSuchAlgorithmException public static String getChecksumObject(Serializable object) throws IOException, NoSuchAlgorithmException
{ {
ByteArrayOutputStream baos = null; try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos))
ObjectOutputStream oos = null;
try
{ {
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(object); oos.writeObject(object);
MessageDigest md = MessageDigest.getInstance("MD5"); MessageDigest md = MessageDigest.getInstance("MD5");
byte[] thedigest = md.digest(baos.toByteArray()); byte[] thedigest = md.digest(baos.toByteArray());
return DatatypeConverter.printHexBinary(thedigest); return DatatypeConverter.printHexBinary(thedigest);
} }
finally
{
oos.close();
baos.close();
}
} }
private static String getChecksumFile(String filepath) throws IOException private static String getChecksumFile(String filepath) throws IOException, NoSuchAlgorithmException
{ {
System.out.println("Generating Hash for " + filepath); System.out.println("Generating Hash for " + filepath);
MessageDigest md = null; MessageDigest md = MessageDigest.getInstance("SHA-256");
try
{
md = MessageDigest.getInstance("SHA-256");
}
catch (Exception e)
{
e.printStackTrace();
}
try (DigestInputStream dis = new DigestInputStream(new FileInputStream(filepath), md)) try (DigestInputStream dis = new DigestInputStream(new FileInputStream(filepath), md))
{
while (dis.read() != -1)
{ {
//empty loop to clear the data //empty loop to clear the data
} while (dis.read() != -1);
md = dis.getMessageDigest(); md = dis.getMessageDigest();
} }
catch (Exception e)
{
e.printStackTrace();
}
return bytesToHex(md.digest()); return bytesToHex(md.digest());
@@ -111,11 +96,11 @@ public class Bootstrap
} }
public Artifact[] getArtifacts() private Artifact[] getArtifacts()
{ {
try try
{ {
artifacts = new Artifact[42]; artifacts = new Artifact[43];
//Static artifacts //Static artifacts
artifacts[0] = new Artifact(); artifacts[0] = new Artifact();
@@ -330,8 +315,13 @@ public class Bootstrap
artifacts[37].hash = getChecksumFile("./http-api/target/" + artifacts[37].name); artifacts[37].hash = getChecksumFile("./http-api/target/" + artifacts[37].name);
artifacts[37].path = "https://raw.githubusercontent.com/runelite-extended/maven-repo/master/live/" + artifacts[37].name; artifacts[37].path = "https://raw.githubusercontent.com/runelite-extended/maven-repo/master/live/" + artifacts[37].name;
artifacts[37].size = Long.toString(getFileSize("./http-api/target/" + artifacts[37].name)); artifacts[37].size = Long.toString(getFileSize("./http-api/target/" + artifacts[37].name));
artifacts[42] = new Artifact();
artifacts[42].name = "injected-client-" + RuneLiteAPI.getVersion() + ".jar";
artifacts[42].hash = getChecksumFile("./injected-client/target/" + artifacts[42].name);
artifacts[42].path = "https://raw.githubusercontent.com/runelite-extended/maven-repo/master/live/" + artifacts[42].name;
artifacts[42].size = Long.toString(getFileSize("./injected-client/target/" + artifacts[42].name));
} }
catch (IOException e) catch (IOException | NoSuchAlgorithmException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }