mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-19 14:33:04 +03:00
Merge remote-tracking branch 'origin/dev' into fix/asm
This commit is contained in:
commit
30c162c5a5
6 changed files with 41 additions and 131 deletions
|
@ -7,6 +7,7 @@
|
||||||
import ru.gravit.launchserver.socket.Client;
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.launchserver.websocket.WebSocketService;
|
import ru.gravit.launchserver.websocket.WebSocketService;
|
||||||
import ru.gravit.launchserver.websocket.json.JsonResponseInterface;
|
import ru.gravit.launchserver.websocket.json.JsonResponseInterface;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -28,7 +29,13 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
||||||
BatchProfileByUsernameRequestEvent result = new BatchProfileByUsernameRequestEvent();
|
BatchProfileByUsernameRequestEvent result = new BatchProfileByUsernameRequestEvent();
|
||||||
result.playerProfiles = new PlayerProfile[list.length];
|
result.playerProfiles = new PlayerProfile[list.length];
|
||||||
for (int i = 0; i < list.length; ++i) {
|
for (int i = 0; i < list.length; ++i) {
|
||||||
UUID uuid = client.auth.handler.usernameToUUID(list[i].username);
|
UUID uuid;
|
||||||
|
if(client.auth == null)
|
||||||
|
{
|
||||||
|
LogHelper.warning("Client auth is null. Using default.");
|
||||||
|
uuid = LaunchServer.server.config.getAuthProviderPair().handler.usernameToUUID(list[i].username);
|
||||||
|
}
|
||||||
|
else uuid = client.auth.handler.usernameToUUID(list[i].username);
|
||||||
result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, list[i].username, list[i].client, client.auth.textureProvider);
|
result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, list[i].username, list[i].client, client.auth.textureProvider);
|
||||||
}
|
}
|
||||||
service.sendObject(ctx, result);
|
service.sendObject(ctx, result);
|
||||||
|
|
|
@ -48,7 +48,13 @@ public String getType() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||||
String username = client.auth.handler.uuidToUsername(uuid);
|
String username;
|
||||||
|
if(client.auth == null)
|
||||||
|
{
|
||||||
|
LogHelper.warning("Client auth is null. Using default.");
|
||||||
|
username = LaunchServer.server.config.getAuthProviderPair().handler.uuidToUsername(uuid);
|
||||||
|
}
|
||||||
|
else username = client.auth.handler.uuidToUsername(uuid);
|
||||||
service.sendObject(ctx, new ProfileByUUIDRequestEvent(getProfile(LaunchServer.server, uuid, username, this.client, client.auth.textureProvider)));
|
service.sendObject(ctx, new ProfileByUUIDRequestEvent(getProfile(LaunchServer.server, uuid, username, this.client, client.auth.textureProvider)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
import ru.gravit.launchserver.socket.Client;
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.launchserver.websocket.WebSocketService;
|
import ru.gravit.launchserver.websocket.WebSocketService;
|
||||||
import ru.gravit.launchserver.websocket.json.JsonResponseInterface;
|
import ru.gravit.launchserver.websocket.json.JsonResponseInterface;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -22,7 +23,13 @@ public String getType() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||||
UUID uuid = client.auth.handler.usernameToUUID(username);
|
UUID uuid;
|
||||||
|
if(client.auth == null)
|
||||||
|
{
|
||||||
|
LogHelper.warning("Client auth is null. Using default.");
|
||||||
|
uuid = LaunchServer.server.config.getAuthProviderPair().handler.usernameToUUID(username);
|
||||||
|
}
|
||||||
|
else uuid = client.auth.handler.usernameToUUID(username);
|
||||||
service.sendObject(ctx, new ProfileByUsernameRequestEvent(getProfile(LaunchServer.server, uuid, username, this.client, client.auth.textureProvider)));
|
service.sendObject(ctx, new ProfileByUsernameRequestEvent(getProfile(LaunchServer.server, uuid, username, this.client, client.auth.textureProvider)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
dependencies {
|
dependencies {
|
||||||
pack project(':LauncherAPI') // Not error on obf.
|
pack project(':LauncherAPI') // Not error on obf.
|
||||||
bundle 'com.github.oshi:oshi-core:3.13.0'
|
bundle 'com.github.oshi:oshi-core:3.13.0'
|
||||||
|
bundle 'com.jfoenix:jfoenix:8.0.8'
|
||||||
pack 'org.ow2.asm:asm-tree:7.1'
|
pack 'org.ow2.asm:asm-tree:7.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,117 +43,9 @@ public static void premain(String agentArgument, Instrumentation instrumentation
|
||||||
if (trimmedArg.contains("r")) rt = false;
|
if (trimmedArg.contains("r")) rt = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rt || pb) replaceClasses(pb, rt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isStarted() {
|
public static boolean isStarted() {
|
||||||
return isAgentStarted;
|
return isAgentStarted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @author https://github.com/Konloch/JVM-Sandbox
|
|
||||||
* Replaces the Runtime class via instrumentation, transforms the class via ASM
|
|
||||||
*/
|
|
||||||
private static void replaceClasses(boolean pb, boolean rt) {
|
|
||||||
for(Class<?> c : inst.getAllLoadedClasses()) {
|
|
||||||
if(rt && c.getName().equals("java.lang.Runtime")) {
|
|
||||||
try {
|
|
||||||
inst.redefineClasses(new java.lang.instrument.ClassDefinition(java.lang.Runtime.class, transformClass(c.getName(), getClassFile(c))));
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(pb && c.getName().equals("java.lang.ProcessBuilder")) {
|
|
||||||
try {
|
|
||||||
inst.redefineClasses(new java.lang.instrument.ClassDefinition(java.lang.ProcessBuilder.class, transformClass(c.getName(), getClassFile(c))));
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(c.getName().equals("java.awt.Robot")) {
|
|
||||||
try {
|
|
||||||
inst.redefineClasses(new java.lang.instrument.ClassDefinition(java.lang.ProcessBuilder.class, transformClass(c.getName(), getClassFile(c))));
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author https://github.com/Konloch/JVM-Sandbox
|
|
||||||
* Use ASM to modify the byte array
|
|
||||||
*/
|
|
||||||
private static byte[] transformClass(String className, byte[] classBytes) {
|
|
||||||
if (className.equals("java.lang.Runtime")) {
|
|
||||||
ClassReader cr=new ClassReader(classBytes);
|
|
||||||
ClassNode cn=new ClassNode();
|
|
||||||
cr.accept(cn,ClassReader.EXPAND_FRAMES);
|
|
||||||
|
|
||||||
for (Object o : cn.methods.toArray()) {
|
|
||||||
MethodNode m = (MethodNode) o;
|
|
||||||
if(m.name.equals("exec")) {
|
|
||||||
m.instructions.insert(new InsnNode(ARETURN));
|
|
||||||
m.instructions.insert(new InsnNode(ACONST_NULL));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ClassWriter cw=new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
|
||||||
cn.accept(cw);
|
|
||||||
return cw.toByteArray();
|
|
||||||
} else if (className.equals("java.lang.ProcessBuilder")) {
|
|
||||||
ClassReader cr=new ClassReader(classBytes);
|
|
||||||
ClassNode cn=new ClassNode();
|
|
||||||
cr.accept(cn,ClassReader.EXPAND_FRAMES);
|
|
||||||
|
|
||||||
for (Object o : cn.methods.toArray()) {
|
|
||||||
MethodNode m = (MethodNode) o;
|
|
||||||
if(m.name.equals("start")) {
|
|
||||||
m.instructions.insert(new InsnNode(ARETURN));
|
|
||||||
m.instructions.insert(new InsnNode(ACONST_NULL));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ClassWriter cw=new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
|
||||||
cn.accept(cw);
|
|
||||||
return cw.toByteArray();
|
|
||||||
} else if (className.equals("java.awt.Robot")) {
|
|
||||||
ClassReader cr=new ClassReader(classBytes);
|
|
||||||
ClassNode cn=new ClassNode();
|
|
||||||
cr.accept(cn,ClassReader.EXPAND_FRAMES);
|
|
||||||
|
|
||||||
for (Object o : cn.methods.toArray()) {
|
|
||||||
MethodNode m = (MethodNode) o;
|
|
||||||
if( m.name.equals("createScreenCapture") || m.name.equals("getPixelColor") ||
|
|
||||||
m.name.equals("keyPress") || m.name.equals("keyRelease") ||
|
|
||||||
m.name.equals("mouseMove") || m.name.equals("mousePress") ||
|
|
||||||
m.name.equals("mouseWheel"))
|
|
||||||
{
|
|
||||||
m.instructions.insert(new InsnNode(ARETURN));
|
|
||||||
m.instructions.insert(new InsnNode(ACONST_NULL));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ClassWriter cw=new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
|
||||||
cn.accept(cw);
|
|
||||||
return cw.toByteArray();
|
|
||||||
}
|
|
||||||
return classBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author https://github.com/Konloch/JVM-Sandbox
|
|
||||||
* Do not remove this method. Do not to cause classloading!
|
|
||||||
* Grab the byte array from the loaded Class object
|
|
||||||
* @param clazz
|
|
||||||
* @return array, respending this class in bytecode.
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
private static byte[] getClassFile(Class<?> clazz) throws IOException {
|
|
||||||
InputStream is = clazz.getResourceAsStream( "/" + clazz.getName().replace('.', '/') + ".class");
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
int r = 0;
|
|
||||||
byte[] buffer = new byte[8192];
|
|
||||||
while((r=is.read(buffer))>=0) {
|
|
||||||
baos.write(buffer, 0, r);
|
|
||||||
}
|
|
||||||
return baos.toByteArray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -468,27 +468,24 @@ public static void main(String... args) throws Throwable {
|
||||||
// Start client with WatchService monitoring
|
// Start client with WatchService monitoring
|
||||||
boolean digest = !profile.isUpdateFastCheck();
|
boolean digest = !profile.isUpdateFastCheck();
|
||||||
LogHelper.debug("Restore sessions");
|
LogHelper.debug("Restore sessions");
|
||||||
if(Launcher.getConfig().isNettyEnabled)
|
RestoreSessionRequest request = new RestoreSessionRequest(Request.getSession());
|
||||||
|
request.request();
|
||||||
|
LegacyRequestBridge.service.reconnectCallback = () ->
|
||||||
{
|
{
|
||||||
RestoreSessionRequest request = new RestoreSessionRequest(Request.getSession());
|
LogHelper.debug("WebSocket connect closed. Try reconnect");
|
||||||
request.request();
|
try {
|
||||||
LegacyRequestBridge.service.reconnectCallback = () ->
|
if (!LegacyRequestBridge.service.reconnectBlocking()) LogHelper.error("Error connecting");
|
||||||
{
|
LogHelper.debug("Connect to %s", Launcher.getConfig().address);
|
||||||
LogHelper.debug("WebSocket connect closed. Try reconnect");
|
} catch (InterruptedException e) {
|
||||||
try {
|
e.printStackTrace();
|
||||||
if (!LegacyRequestBridge.service.reconnectBlocking()) LogHelper.error("Error connecting");
|
}
|
||||||
LogHelper.debug("Connect to %s", Launcher.getConfig().address);
|
try {
|
||||||
} catch (InterruptedException e) {
|
RestoreSessionRequest request1 = new RestoreSessionRequest(Request.getSession());
|
||||||
e.printStackTrace();
|
request1.request();
|
||||||
}
|
} catch (Exception e) {
|
||||||
try {
|
LogHelper.error(e);
|
||||||
RestoreSessionRequest request1 = new RestoreSessionRequest(Request.getSession());
|
}
|
||||||
request1.request();
|
};
|
||||||
} catch (Exception e) {
|
|
||||||
LogHelper.error(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
LogHelper.debug("Starting JVM and client WatchService");
|
LogHelper.debug("Starting JVM and client WatchService");
|
||||||
FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher();
|
FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher();
|
||||||
FileNameMatcher clientMatcher = profile.getClientUpdateMatcher();
|
FileNameMatcher clientMatcher = profile.getClientUpdateMatcher();
|
||||||
|
|
Loading…
Reference in a new issue