wdnmd
This commit is contained in:
parent
ed4a857ae3
commit
abc1c843f0
10
build.gradle
10
build.gradle
@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'com.github.johnrengelman.shadow' version '8.1.1'
|
||||
}
|
||||
|
||||
group = 'com.yourdomain'
|
||||
@ -29,3 +30,12 @@ jar {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveBaseName.set('agent')
|
||||
archiveClassifier.set('')
|
||||
archiveVersion.set('1.0-SNAPSHOT')
|
||||
manifest {
|
||||
attributes 'Premain-Class': 'com.yourdomain.agent.CheckrpAgent'
|
||||
}
|
||||
}
|
@ -3,48 +3,57 @@ package com.yourdomain.agent;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.utility.JavaModule;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.time.LocalDateTime;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
public class CheckrpAgent {
|
||||
private static final String OUT_PATH = "D:/Minectaft/Milk/milk1/dev/packets.txt";
|
||||
|
||||
public static void premain(String agentArgs, Instrumentation inst) {
|
||||
System.out.println("[CheckrpAgent] Agent loaded: Logging sent packets to sent_packets.txt");
|
||||
try {
|
||||
File f = new File(OUT_PATH);
|
||||
f.getParentFile().mkdirs();
|
||||
if (!f.exists()) f.createNewFile();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
new AgentBuilder.Default()
|
||||
.type(ElementMatchers.nameEndsWith("ModLoadProcedure"))
|
||||
.transform((builder, typeDescription, classLoader, module, protectionDomain) ->
|
||||
builder.method(ElementMatchers.named("sendToServer"))
|
||||
.intercept(Advice.to(SendPacketLogger.class))
|
||||
.ignore(ElementMatchers.nameStartsWith("net.bytebuddy."))
|
||||
.ignore(ElementMatchers.nameStartsWith("java."))
|
||||
.type(ElementMatchers.named("net.minecraftforge.network.simple.SimpleChannel"))
|
||||
.transform((
|
||||
DynamicType.Builder<?> builder,
|
||||
TypeDescription typeDescription,
|
||||
ClassLoader classLoader,
|
||||
JavaModule module,
|
||||
ProtectionDomain pd
|
||||
) ->
|
||||
builder.visit(Advice.to(SendAdvice.class)
|
||||
.on(ElementMatchers.named("sendToServer")
|
||||
.and(ElementMatchers.takesArguments(1))
|
||||
)
|
||||
)
|
||||
)
|
||||
.installOn(inst);
|
||||
|
||||
}
|
||||
|
||||
public static class SendPacketLogger {
|
||||
|
||||
public static class SendAdvice {
|
||||
@Advice.OnMethodEnter
|
||||
public static void onEnter(@Advice.Argument(0) Object packet) {
|
||||
try (PrintWriter out = new PrintWriter(new FileWriter("sent_packets.txt", true))) {
|
||||
out.println("==== Packet Sent ====");
|
||||
out.println("Time: " + LocalDateTime.now());
|
||||
out.println("Class: " + packet.getClass().getName());
|
||||
for (Field field : packet.getClass().getDeclaredFields()) {
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
Object value = field.get(packet);
|
||||
out.printf(" %s = %s%n", field.getName(), value);
|
||||
} catch (IllegalAccessException e) {
|
||||
out.printf(" %s = <unreadable>%n", field.getName());
|
||||
}
|
||||
}
|
||||
out.println("=====================\n");
|
||||
String className = packet.getClass().getName();
|
||||
String line ="["+className +"] "+ (packet == null ? "null" : packet.toString()) + System.lineSeparator();
|
||||
try (BufferedWriter out = new BufferedWriter(new FileWriter(OUT_PATH, true))) {
|
||||
out.write(line);
|
||||
} catch (Exception e) {
|
||||
System.err.println("[CheckrpAgent] Failed to write packet info: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user